mirror of
https://github.com/areteruhiro/LIME-beta-hiro.git
synced 2025-02-06 05:21:37 +09:00
コードの修正
This commit is contained in:
parent
841fe49287
commit
4dfeee7e75
@ -9,8 +9,8 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdk 28
|
minSdk 28
|
||||||
targetSdk 35
|
targetSdk 35
|
||||||
versionCode 116156
|
versionCode 116157
|
||||||
versionName "1.16.15e"
|
versionName "1.16.15as"
|
||||||
multiDexEnabled false
|
multiDexEnabled false
|
||||||
proguardFiles += 'proguard-rules.pro'
|
proguardFiles += 'proguard-rules.pro'
|
||||||
buildConfigField 'String', 'HOOK_TARGET_VERSION', '"141910383"'
|
buildConfigField 'String', 'HOOK_TARGET_VERSION', '"141910383"'
|
||||||
|
@ -4,10 +4,8 @@ import android.app.AndroidAppHelper;
|
|||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.MediaPlayer;
|
import android.media.MediaPlayer;
|
||||||
import android.media.RingtoneManager;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -23,9 +21,9 @@ import de.robv.android.xposed.callbacks.XC_LoadPackage;
|
|||||||
import io.github.hiro.lime.LimeOptions;
|
import io.github.hiro.lime.LimeOptions;
|
||||||
|
|
||||||
public class RingTone implements IHook {
|
public class RingTone implements IHook {
|
||||||
private android.media.Ringtone ringtone = null;
|
private MediaPlayer mediaPlayer = null;
|
||||||
private boolean isPlaying = false;
|
private boolean isPlaying = false;
|
||||||
MediaPlayer mediaPlayer = null;
|
|
||||||
@Override
|
@Override
|
||||||
public void hook(LimeOptions limeOptions, XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
|
public void hook(LimeOptions limeOptions, XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
|
||||||
if (!limeOptions.callTone.checked) return;
|
if (!limeOptions.callTone.checked) return;
|
||||||
@ -43,7 +41,6 @@ public class RingTone implements IHook {
|
|||||||
Constants.RESPONSE_HOOK.methodName,
|
Constants.RESPONSE_HOOK.methodName,
|
||||||
new XC_MethodHook() {
|
new XC_MethodHook() {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
|
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
|
||||||
String paramValue = param.args[1].toString();
|
String paramValue = param.args[1].toString();
|
||||||
@ -69,43 +66,21 @@ public class RingTone implements IHook {
|
|||||||
out.write(buffer, 0, length);
|
out.write(buffer, 0, length);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
// エラーが発生しても何もしない
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paramValue.contains("type:NOTIFIED_RECEIVED_CALL,") && !isPlaying) {
|
if (paramValue.contains("type:NOTIFIED_RECEIVED_CALL,") && !isPlaying) {
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
if (mediaPlayer != null) {
|
prepareAndPlayMedia(context, destFile);
|
||||||
if (mediaPlayer.isPlaying()) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
mediaPlayer.release();
|
|
||||||
mediaPlayer = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Uri ringtoneUri = Uri.fromFile(destFile);
|
if (paramValue.contains("RESULT=REJECTED,")) {
|
||||||
mediaPlayer = MediaPlayer.create(context, ringtoneUri);
|
stopMediaPlayer();
|
||||||
mediaPlayer.setLooping(true);
|
}
|
||||||
|
}
|
||||||
if (mediaPlayer != null) {
|
|
||||||
mediaPlayer.start();
|
|
||||||
isPlaying = true;
|
|
||||||
|
|
||||||
mediaPlayer.setOnCompletionListener(mp -> {
|
|
||||||
isPlaying = false;
|
|
||||||
mp.seekTo(0);
|
|
||||||
mp.start();
|
|
||||||
isPlaying = true;
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
Class<?> targetClass = loadPackageParam.classLoader.loadClass("com.linecorp.andromeda.audio.AudioManager");
|
Class<?> targetClass = loadPackageParam.classLoader.loadClass("com.linecorp.andromeda.audio.AudioManager");
|
||||||
Method[] methods = targetClass.getDeclaredMethods();
|
Method[] methods = targetClass.getDeclaredMethods();
|
||||||
@ -115,25 +90,8 @@ public class RingTone implements IHook {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
|
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
|
||||||
|
if (method.getName().equals("setServerConfig") || method.getName().equals("stop")) {
|
||||||
if (method.getName().equals("setServerConfig")) {
|
stopMediaPlayer();
|
||||||
if (mediaPlayer != null) {
|
|
||||||
if (mediaPlayer.isPlaying()) {
|
|
||||||
mediaPlayer.stop();
|
|
||||||
}
|
|
||||||
mediaPlayer.release();
|
|
||||||
mediaPlayer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (method.getName().equals("stop")) {
|
|
||||||
if (mediaPlayer != null) {
|
|
||||||
if (mediaPlayer.isPlaying()) {
|
|
||||||
mediaPlayer.stop();
|
|
||||||
}
|
|
||||||
mediaPlayer.release();
|
|
||||||
mediaPlayer = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method.getName().equals("processToneEvent")) {
|
if (method.getName().equals("processToneEvent")) {
|
||||||
@ -145,15 +103,71 @@ public class RingTone implements IHook {
|
|||||||
|
|
||||||
if (arg0.toString().contains("START")) {
|
if (arg0.toString().contains("START")) {
|
||||||
if (appContext != null) {
|
if (appContext != null) {
|
||||||
if (mediaPlayer != null && mediaPlayer.isPlaying()) {
|
if (mediaPlayer == null || !mediaPlayer.isPlaying()) {
|
||||||
return;
|
playDialTone(appContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Context moduleContext = AndroidAppHelper.currentApplication().createPackageContext(
|
if (limeOptions.MuteTone.checked && method.getName().equals("setTonePlayer")) {
|
||||||
"io.github.hiro.lime", Context.CONTEXT_IGNORE_SECURITY);
|
param.setResult(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method.getName().equals("ACTIVATED") && param.args != null && param.args.length > 0) {
|
||||||
|
Object arg0 = param.args[0];
|
||||||
|
if ("ACTIVATED".equals(arg0)) {
|
||||||
|
stopMediaPlayer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void prepareAndPlayMedia(Context context, File destFile) {
|
||||||
|
if (mediaPlayer != null) {
|
||||||
|
stopMediaPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
Uri ringtoneUri = Uri.fromFile(destFile);
|
||||||
|
mediaPlayer = MediaPlayer.create(context, ringtoneUri);
|
||||||
|
mediaPlayer.setLooping(true);
|
||||||
|
|
||||||
|
if (mediaPlayer != null) {
|
||||||
|
mediaPlayer.start();
|
||||||
|
isPlaying = true;
|
||||||
|
|
||||||
|
mediaPlayer.setOnCompletionListener(mp -> {
|
||||||
|
mp.seekTo(0);
|
||||||
|
mp.start();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopMediaPlayer() {
|
||||||
|
if (mediaPlayer != null) {
|
||||||
|
try {
|
||||||
|
if (mediaPlayer.isPlaying()) {
|
||||||
|
mediaPlayer.stop();
|
||||||
|
}
|
||||||
|
} catch (IllegalStateException ignored) {
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
mediaPlayer.release();
|
||||||
|
} catch (IllegalStateException ignored) {
|
||||||
|
} finally {
|
||||||
|
mediaPlayer = null;
|
||||||
|
isPlaying = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void playDialTone(Context appContext) {
|
||||||
String resourceNameA = "dial_tone";
|
String resourceNameA = "dial_tone";
|
||||||
int resourceIdA = moduleContext.getResources().getIdentifier(resourceNameA, "raw", "io.github.hiro.lime");
|
int resourceIdA = appContext.getResources().getIdentifier(resourceNameA, "raw", "io.github.hiro.lime");
|
||||||
|
|
||||||
File ringtoneDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "LimeBackup");
|
File ringtoneDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "LimeBackup");
|
||||||
if (!ringtoneDir.exists()) {
|
if (!ringtoneDir.exists()) {
|
||||||
@ -162,7 +176,7 @@ public class RingTone implements IHook {
|
|||||||
File destFile = new File(ringtoneDir, resourceNameA + ".wav");
|
File destFile = new File(ringtoneDir, resourceNameA + ".wav");
|
||||||
|
|
||||||
if (!destFile.exists()) {
|
if (!destFile.exists()) {
|
||||||
try (InputStream in = moduleContext.getResources().openRawResource(resourceIdA);
|
try (InputStream in = appContext.getResources().openRawResource(resourceIdA);
|
||||||
OutputStream out = new FileOutputStream(destFile)) {
|
OutputStream out = new FileOutputStream(destFile)) {
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
int length;
|
int length;
|
||||||
@ -170,50 +184,10 @@ public class RingTone implements IHook {
|
|||||||
out.write(buffer, 0, length);
|
out.write(buffer, 0, length);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Uri ringtoneUri = Uri.fromFile(destFile);
|
|
||||||
mediaPlayer = MediaPlayer.create(appContext, ringtoneUri);
|
|
||||||
mediaPlayer.setLooping(true);
|
|
||||||
|
|
||||||
if (mediaPlayer != null) {
|
|
||||||
mediaPlayer.start();
|
|
||||||
|
|
||||||
mediaPlayer.setOnCompletionListener(mp -> {
|
|
||||||
mp.seekTo(0);
|
|
||||||
mp.start();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (limeOptions.MuteTone.checked) {
|
|
||||||
if (method.getName().equals("setTonePlayer")) {
|
|
||||||
param.setResult(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (method.getName().equals("ACTIVATED") && param.args != null && param.args.length > 0) {
|
|
||||||
Object arg0 = param.args[0];
|
|
||||||
if ("ACTIVATED".equals(arg0)) {
|
|
||||||
if (mediaPlayer != null) {
|
|
||||||
if (mediaPlayer.isPlaying()) {
|
|
||||||
mediaPlayer.stop();
|
|
||||||
}
|
|
||||||
mediaPlayer.release();
|
|
||||||
mediaPlayer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
prepareAndPlayMedia(appContext, destFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user