diff --git a/app/src/main/java/io/github/chipppppppppp/lime/hooks/test.java b/app/src/main/java/io/github/chipppppppppp/lime/hooks/test.java index c4a1d0a0..bf5b27a9 100644 --- a/app/src/main/java/io/github/chipppppppppp/lime/hooks/test.java +++ b/app/src/main/java/io/github/chipppppppppp/lime/hooks/test.java @@ -13,7 +13,7 @@ public class test implements IHook { private Ringtone ringtone = null; - private boolean isPlaying = false; + private boolean isPlaying = false; // 着信音が再生中かどうかを管理するフラグ @Override public void hook(LimeOptions limeOptions, XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable { @@ -21,42 +21,49 @@ public void hook(LimeOptions limeOptions, XC_LoadPackage.LoadPackageParam loadPa loadPackageParam.classLoader.loadClass(Constants.RESPONSE_HOOK.className), Constants.RESPONSE_HOOK.methodName, new XC_MethodHook() { + @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { String paramValue = param.args[1].toString(); + + // 着信音を再生する条件 if (paramValue.contains("type:NOTIFIED_RECEIVED_CALL,") && !isPlaying) { try { + // アプリケーションのコンテキストを取得 Context context = AndroidAppHelper.currentApplication().getApplicationContext(); if (context != null) { Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); ringtone = RingtoneManager.getRingtone(context, ringtoneUri); - ringtone.play(); - isPlaying = true; - + ringtone.play(); // 着信音を再生 + isPlaying = true; // 再生中フラグをセット + XposedBridge.log("Ringtone is playing."); // デバッグログ } } catch (Exception e) { XposedBridge.log(e); } } - - if (paramValue.contains("type:RESULT=REJECTED,") || - paramValue.contains("type:RESULT=CANCELED,")) { + + // 着信音を停止する条件 + if (paramValue.contains("RESULT=REJECTED,") || + paramValue.contains("RESULT=REJECTED,")) { if (ringtone != null && ringtone.isPlaying()) { - ringtone.stop(); - isPlaying = false; - + ringtone.stop(); // 着信音を停止 + isPlaying = false; // 再生中フラグをリセット + XposedBridge.log("Ringtone has been stopped."); // デバッグログ } } } }); Class voIPBaseFragmentClass = loadPackageParam.classLoader.loadClass("com.linecorp.voip2.common.base.VoIPBaseFragment"); + XposedBridge.hookAllMethods(voIPBaseFragmentClass, "onCreate", new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { if (ringtone != null && ringtone.isPlaying()) { - ringtone.stop(); - isPlaying = false; + ringtone.stop(); // フラグがリセットされる前に着信音を停止 + isPlaying = false; // 再生中フラグをリセット + XposedBridge.log("Ringtone has been stopped in onCreate."); // デバッグログ } } });