Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSPatch 時の着信音が鳴らない問題を修正 #194

Merged
merged 9 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public Option(String name, int id, boolean checked) {
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 calltone = new Option("calltone", R.string.calltone, false);

public Option[] options = {
removeVoom,
Expand All @@ -56,6 +57,7 @@ public Option(String name, int id, boolean checked) {
removeKeepUnread,
blockTracking,
stopVersionCheck,
outputCommunication
outputCommunication,
calltone
s1204IT marked this conversation as resolved.
Show resolved Hide resolved
};
}
3 changes: 2 additions & 1 deletion app/src/main/java/io/github/chipppppppppp/lime/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public class Main implements IXposedHookLoadPackage, IXposedHookInitPackageResou
new BlockTracking(),
new ModifyResponse(),
new OutputRequest(),
new Archived()
new Archived(),
new Ringtone(),
};

public void handleLoadPackage(@NonNull XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
Expand Down
63 changes: 63 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,63 @@
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 @@ -43,7 +43,7 @@
<string name="modify_response">レスポンスを改変</string>
<string name="button_copy">コピー</string>
<string name="button_paste">ペースト</string>

<string name="calltone">LsPatch用 着信音を鳴らす</string>
<!-- Menu -->
<string name="switch_keep_unread">未読のまま閲覧</string>
</resources>
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 @@ -43,7 +43,7 @@
<string name="modify_response">Modify responses</string>
<string name="button_copy">Copy</string>
<string name="button_paste">Paste</string>

<string name="calltone">Notify ringtone for LsPatch</string>
<!-- Menu -->
<string name="switch_keep_unread">Keep unread</string>
</resources>