1
0
mirror of https://github.com/areteruhiro/LIME-beta-hiro.git synced 2025-02-05 21:11:39 +09:00

コードの修正

This commit is contained in:
areteruhiro 2025-02-02 16:31:55 +09:00
parent 841fe49287
commit 4dfeee7e75
2 changed files with 82 additions and 108 deletions

View File

@ -9,8 +9,8 @@ android {
defaultConfig {
minSdk 28
targetSdk 35
versionCode 116156
versionName "1.16.15e"
versionCode 116157
versionName "1.16.15as"
multiDexEnabled false
proguardFiles += 'proguard-rules.pro'
buildConfigField 'String', 'HOOK_TARGET_VERSION', '"141910383"'

View File

@ -4,10 +4,8 @@ import android.app.AndroidAppHelper;
import android.app.Application;
import android.content.Context;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
@ -23,9 +21,9 @@ import de.robv.android.xposed.callbacks.XC_LoadPackage;
import io.github.hiro.lime.LimeOptions;
public class RingTone implements IHook {
private android.media.Ringtone ringtone = null;
private MediaPlayer mediaPlayer = null;
private boolean isPlaying = false;
MediaPlayer mediaPlayer = null;
@Override
public void hook(LimeOptions limeOptions, XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
if (!limeOptions.callTone.checked) return;
@ -43,7 +41,6 @@ public class RingTone implements IHook {
Constants.RESPONSE_HOOK.methodName,
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
String paramValue = param.args[1].toString();
@ -69,43 +66,21 @@ public class RingTone implements IHook {
out.write(buffer, 0, length);
}
} catch (IOException e) {
e.printStackTrace();
// エラーが発生しても何もしない
}
}
if (paramValue.contains("type:NOTIFIED_RECEIVED_CALL,") && !isPlaying) {
if (context != null) {
if (mediaPlayer != null) {
if (mediaPlayer.isPlaying()) {
return;
} else {
mediaPlayer.release();
mediaPlayer = null;
prepareAndPlayMedia(context, destFile);
}
}
Uri ringtoneUri = Uri.fromFile(destFile);
mediaPlayer = MediaPlayer.create(context, ringtoneUri);
mediaPlayer.setLooping(true);
if (mediaPlayer != null) {
mediaPlayer.start();
isPlaying = true;
mediaPlayer.setOnCompletionListener(mp -> {
isPlaying = false;
mp.seekTo(0);
mp.start();
isPlaying = true;
if (paramValue.contains("RESULT=REJECTED,")) {
stopMediaPlayer();
}
}
});
}
}
}
}
}
);
Class<?> targetClass = loadPackageParam.classLoader.loadClass("com.linecorp.andromeda.audio.AudioManager");
Method[] methods = targetClass.getDeclaredMethods();
@ -115,25 +90,8 @@ public class RingTone implements IHook {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (method.getName().equals("setServerConfig")) {
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("setServerConfig") || method.getName().equals("stop")) {
stopMediaPlayer();
}
if (method.getName().equals("processToneEvent")) {
@ -145,15 +103,71 @@ public class RingTone implements IHook {
if (arg0.toString().contains("START")) {
if (appContext != null) {
if (mediaPlayer != null && mediaPlayer.isPlaying()) {
return;
if (mediaPlayer == null || !mediaPlayer.isPlaying()) {
playDialTone(appContext);
}
}
}
}
Context moduleContext = AndroidAppHelper.currentApplication().createPackageContext(
"io.github.hiro.lime", Context.CONTEXT_IGNORE_SECURITY);
if (limeOptions.MuteTone.checked && 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)) {
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";
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");
if (!ringtoneDir.exists()) {
@ -162,7 +176,7 @@ public class RingTone implements IHook {
File destFile = new File(ringtoneDir, resourceNameA + ".wav");
if (!destFile.exists()) {
try (InputStream in = moduleContext.getResources().openRawResource(resourceIdA);
try (InputStream in = appContext.getResources().openRawResource(resourceIdA);
OutputStream out = new FileOutputStream(destFile)) {
byte[] buffer = new byte[1024];
int length;
@ -170,50 +184,10 @@ public class RingTone implements IHook {
out.write(buffer, 0, length);
}
} 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);
}
}