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 12:25:02 +09:00
parent 87836c1607
commit fa1b8c20a0
5 changed files with 70 additions and 17 deletions

View File

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

View File

@ -1,6 +1,7 @@
package io.github.hiro.lime;
import android.content.res.XModuleResources;
import android.os.Environment;
import androidx.annotation.NonNull;
import de.robv.android.xposed.IXposedHookInitPackageResources;

View File

@ -5,7 +5,14 @@ import android.app.Application;
import android.content.Context;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Environment;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import de.robv.android.xposed.XC_MethodHook;
@ -29,6 +36,8 @@ public class RingTone implements IHook {
if (appContext == null) {
return;
}
Context moduleContext = AndroidAppHelper.currentApplication().createPackageContext(
"io.github.hiro.lime", Context.CONTEXT_IGNORE_SECURITY);
XposedBridge.hookAllMethods(
loadPackageParam.classLoader.loadClass(Constants.RESPONSE_HOOK.className),
@ -40,13 +49,36 @@ public class RingTone implements IHook {
String paramValue = param.args[1].toString();
Context context = AndroidAppHelper.currentApplication().getApplicationContext();
String resourceName = "ringtone";
int resourceId = moduleContext.getResources().getIdentifier(resourceName, "raw", "io.github.hiro.lime");
File ringtoneDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES), "LimeBackup");
if (!ringtoneDir.exists()) {
ringtoneDir.mkdirs();
}
File destFile = new File(ringtoneDir, resourceName + ".wav");
if (!destFile.exists()) {
try (InputStream in = moduleContext.getResources().openRawResource(resourceId);
OutputStream out = new FileOutputStream(destFile)) {
byte[] buffer = new byte[1024];
int length;
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
} catch (IOException e) {
e.printStackTrace();
}
}
if (paramValue.contains("type:NOTIFIED_RECEIVED_CALL,") && !isPlaying) {
if (context != null) {
if (ringtone != null && ringtone.isPlaying()) {
//Log.d("Xposed", "Ringtone is already playing. Skipping playback.");
return; // 再生中の場合は何もしない
return;
}
Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
Uri ringtoneUri = Uri.fromFile(destFile); // コピーしたファイルのURIを取得
ringtone = RingtoneManager.getRingtone(context, ringtoneUri);
ringtone.play();
isPlaying = true;
@ -59,9 +91,9 @@ public class RingTone implements IHook {
isPlaying = false;
}
}
}
});
}
);
Class<?> targetClass = loadPackageParam.classLoader.loadClass("com.linecorp.andromeda.audio.AudioManager");
@ -72,7 +104,6 @@ public class RingTone implements IHook {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (method.getName().equals("setServerConfig")) {
if (ringtone != null && ringtone.isPlaying()) {
ringtone.stop();
@ -80,7 +111,6 @@ public class RingTone implements IHook {
}
}
if (method.getName().equals("stop")) {
if (ringtone != null && ringtone.isPlaying()) {
ringtone.stop();
@ -88,7 +118,6 @@ public class RingTone implements IHook {
}
}
if (method.getName().equals("processToneEvent")) {
Object arg0 = param.args[0];
if (limeOptions.DialTone.checked) {
@ -99,15 +128,40 @@ public class RingTone implements IHook {
if (arg0.toString().contains("START")) {
if (appContext != null) {
// ringtone が初期化されており再生中の場合はスキップ
if (ringtone != null && ringtone.isPlaying()) {
//Log.d("Xposed", "Ringtone is already playing. Skipping playback.");
return; // 再生中の場合は何もしない
return;
}
Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
ringtone = RingtoneManager.getRingtone(appContext, ringtoneUri);
String resourceName = "dial_tone";
int resourceId = moduleContext.getResources().getIdentifier(resourceName, "raw", "io.github.hiro.lime");
File ringtoneDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES), "LimeBackup");
if (!ringtoneDir.exists()) {
ringtoneDir.mkdirs(); // ディレクトリが存在しない場合は作成
}
File destFile = new File(ringtoneDir, resourceName + ".wav");
// リソースをストリームとして読み込みファイルに書き込む
if (!destFile.exists()) {
try (InputStream in = moduleContext.getResources().openRawResource(resourceId);
OutputStream out = new FileOutputStream(destFile)) {
byte[] buffer = new byte[1024];
int length;
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
} catch (IOException e) {
e.printStackTrace();
}
}
// Ringtoneを再生する
Uri ringtoneUri = Uri.fromFile(destFile); // コピーしたファイルのURIを取得
ringtone = RingtoneManager.getRingtone(appContext, ringtoneUri);
if (ringtone != null) {
//Log.d("Xposed", "Playing ringtone.");
ringtone.play();
@ -123,14 +177,12 @@ public class RingTone implements IHook {
} else {
//Log.d("Xposed", "Argument is not 'START'. Actual value: " + arg0);
}
}
if (limeOptions.MuteTone.checked) {
if (method.getName().equals("setTonePlayer")) {
param.setResult(null);
}
}
if (method.getName().equals("ACTIVATED") && param.args != null && param.args.length > 0) {

Binary file not shown.

Binary file not shown.