Skip to content

Commit

Permalink
LSPatch 時の着信音が鳴らない問題を修正 (#194)
Browse files Browse the repository at this point in the history
Co-authored-by: Syuugo <[email protected]>
  • Loading branch information
areteruhiro and s1204IT authored Oct 26, 2024
1 parent 225d1a1 commit 789b412
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public Option(String name, int id, boolean checked) {
public Option blockTracking = new Option("block_tracking", R.string.switch_block_tracking, false);
public Option stopVersionCheck = new Option("stop_version_check", R.string.switch_stop_version_check, false);
public Option outputCommunication = new Option("output_communication", R.string.switch_output_communication, false);
public Option Archived = new Option("Archived_message", R.string.switch_archived, false);
public Option archived = new Option("archived_message", R.string.switch_archived, false);
public Option callTone = new Option("call_tone", R.string.call_tone, false);

public Option[] options = {
removeVoom,
Expand All @@ -51,11 +52,12 @@ public Option(String name, int id, boolean checked) {
openInBrowser,
preventMarkAsRead,
preventUnsendMessage,
Archived,
archived,
sendMuteMessage,
removeKeepUnread,
blockTracking,
stopVersionCheck,
outputCommunication
outputCommunication,
callTone
};
}
6 changes: 4 additions & 2 deletions app/src/main/java/io/github/chipppppppppp/lime/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.github.chipppppppppp.lime.hooks.RemoveIconLabels;
import io.github.chipppppppppp.lime.hooks.RemoveIcons;
import io.github.chipppppppppp.lime.hooks.RemoveReplyMute;
import io.github.chipppppppppp.lime.hooks.Ringtone;
import io.github.chipppppppppp.lime.hooks.SendMuteMessage;
import io.github.chipppppppppp.lime.hooks.SpoofAndroidId;
import io.github.chipppppppppp.lime.hooks.SpoofUserAgent;
Expand Down Expand Up @@ -64,8 +65,9 @@ public class Main implements IXposedHookLoadPackage, IXposedHookInitPackageResou
new BlockTracking(),
new ModifyResponse(),
new OutputRequest(),
new UnsentCap(),
new Archived()
new Archived(),
new Ringtone(),
new UnsentCap()
};

public void handleLoadPackage(@NonNull XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Archived implements IHook {

@Override
public void hook(LimeOptions limeOptions, XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
if (!limeOptions.Archived.checked) return;
if (!limeOptions.archived.checked) return;

XposedBridge.hookAllMethods(Application.class, "onCreate", new XC_MethodHook() {
@Override
Expand All @@ -50,7 +50,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
}

private void hookMessageDeletion(XC_LoadPackage.LoadPackageParam loadPackageParam, Context context, SQLiteDatabase db, Context moduleContext) {
if (!limeOptions.Archived.checked) return;
if (!limeOptions.archived.checked) return;

try {
XposedBridge.hookAllMethods(
Expand Down
61 changes: 61 additions & 0 deletions app/src/main/java/io/github/chipppppppppp/lime/hooks/Ringtone.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.github.chipppppppppp.lime.hooks;

import android.app.AndroidAppHelper;
import android.content.Context;
import android.media.RingtoneManager;
import android.net.Uri;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import io.github.chipppppppppp.lime.LimeOptions;

public class Ringtone implements IHook {
private android.media.Ringtone ringtone = null;
private boolean isPlaying = false;
@Override
public void hook(LimeOptions limeOptions, XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {

if (!limeOptions.callTone.checked) return;

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) {
Context context = AndroidAppHelper.currentApplication().getApplicationContext();
if (context != null) {
Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
ringtone = RingtoneManager.getRingtone(context, ringtoneUri);
ringtone.play();
isPlaying = true;
}

if (paramValue.contains("RESULT=REJECTED,") ||
paramValue.contains("RESULT=REJECTED,")) {
if (ringtone != null && ringtone.isPlaying()) {
ringtone.stop();
isPlaying = false;
}
}
}
}
});

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;
}
}
});
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<string name="modify_response">レスポンスを改変</string>
<string name="button_copy">コピー</string>
<string name="button_paste">ペースト</string>

<string name="call_tone">着信音を鳴らす(LSPatch用)</string>
<!-- Menu -->
<string name="switch_keep_unread">未読のまま閲覧</string>

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<string name="modify_response">Modify responses</string>
<string name="button_copy">Copy</string>
<string name="button_paste">Paste</string>

<string name="call_tone">Notify ringtone of LSPatch</string>
<!-- Menu -->
<string name="switch_keep_unread">Keep unread</string>

Expand Down

0 comments on commit 789b412

Please sign in to comment.