Skip to content

Commit

Permalink
Update test.java
Browse files Browse the repository at this point in the history
  • Loading branch information
areteruhiro authored Oct 18, 2024
1 parent ab2d84f commit 33ae7cf
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions app/src/main/java/io/github/chipppppppppp/lime/hooks/test.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,57 @@

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 {
XposedBridge.hookAllMethods(
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."); // デバッグログ
}
}
});
Expand Down

0 comments on commit 33ae7cf

Please sign in to comment.