Skip to content

Commit 8b15584

Browse files
fix module
1 parent ce0316c commit 8b15584

File tree

2 files changed

+37
-16
lines changed
  • VolumeStepsIncrease/src/main/java/com/programminghoch10/VolumeStepsIncrease

2 files changed

+37
-16
lines changed

VolumeStepsIncrease/src/main/java/com/programminghoch10/VolumeStepsIncrease/Common.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,25 @@ object Common {
1818
"ro.config.alarm_vol_steps" to STREAM_ALARM,
1919
"ro.config.system_vol_steps" to STREAM_SYSTEM,
2020
)
21+
val streamsToSystemProperties = systemPropertyToStream.entries.associate { it.value to it.key }
2122

2223
val moduleDefaultVolumeSteps = mapOf(
2324
STREAM_MUSIC to MAX_STREAM_VOLUME[STREAM_MUSIC] * 2,
2425
STREAM_VOICE_CALL to MAX_STREAM_VOLUME[STREAM_VOICE_CALL] * 2,
2526
)
2627

2728
fun getSystemMaxVolumeSteps(stream: Int): Int {
28-
return MAX_STREAM_VOLUME[stream]
29+
val default = MAX_STREAM_VOLUME[stream]
30+
if (streamsToSystemProperties.contains(stream)) {
31+
val systemProperty = streamsToSystemProperties[stream]
32+
try {
33+
val SystemPropertiesClass = Class.forName("android.os.SystemProperties")
34+
val getIntMethod = SystemPropertiesClass.getMethod("getInt", String::class.java, Int::class.java)
35+
return getIntMethod.invoke(null, systemProperty, default) as Int
36+
} catch (_: Exception) {
37+
}
38+
}
39+
return default
2940
}
3041

3142
fun getModuleDefaultVolumeSteps(stream: Int): Int {
Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.programminghoch10.VolumeStepsIncrease
22

3-
import android.util.Log
43
import com.programminghoch10.VolumeStepsIncrease.Common.SHARED_PREFERENCES_NAME
54
import com.programminghoch10.VolumeStepsIncrease.Common.STREAMS
65
import com.programminghoch10.VolumeStepsIncrease.Common.getPreferenceKey
@@ -14,7 +13,30 @@ import de.robv.android.xposed.XC_MethodHook as MethodHook
1413

1514
class Hook : IXposedHookLoadPackage {
1615
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
17-
if (lpparam.packageName == BuildConfig.APPLICATION_ID) return
16+
when (lpparam.packageName) {
17+
BuildConfig.APPLICATION_ID -> return
18+
"android" -> hookAndroid(lpparam)
19+
else -> hookApp(lpparam)
20+
}
21+
}
22+
23+
fun hookAndroid(lpparam: XC_LoadPackage.LoadPackageParam) {
24+
25+
val AudioServiceClass = XposedHelpers.findClass("com.android.server.audio.AudioService", lpparam.classLoader)
26+
XposedBridge.hookAllConstructors(AudioServiceClass, object : MethodHook() {
27+
override fun afterHookedMethod(param: MethodHookParam) {
28+
val MAX_STREAM_VOLUME = XposedHelpers.getObjectField(param.thisObject, "MAX_STREAM_VOLUME") as IntArray
29+
val preferences = XSharedPreferences(BuildConfig.APPLICATION_ID, SHARED_PREFERENCES_NAME)
30+
STREAMS.filter { preferences.contains(getPreferenceKey(it.value)) }
31+
.map { it.value to preferences.getInt(getPreferenceKey(it.value), MAX_STREAM_VOLUME[it.value]) }
32+
.forEach { MAX_STREAM_VOLUME[it.first] = it.second }
33+
}
34+
})
35+
36+
hookApp(lpparam)
37+
}
38+
39+
fun hookApp(lpparam: XC_LoadPackage.LoadPackageParam) {
1840

1941
val SystemPropertiesClass = XposedHelpers.findClass("android.os.SystemProperties", lpparam.classLoader)
2042

@@ -26,8 +48,7 @@ class Hook : IXposedHookLoadPackage {
2648
val streamInt = systemPropertyToStream[key] ?: return
2749
val preferences = XSharedPreferences(BuildConfig.APPLICATION_ID, SHARED_PREFERENCES_NAME)
2850
if (!preferences.contains(getPreferenceKey(streamInt))) return
29-
param.result = preferences.getInt(key, result)
30-
Log.d("Logger", "beforeHookedMethod: replace $key with ${param.result}")
51+
param.result = preferences.getInt(getPreferenceKey(streamInt), result)
3152
}
3253
})
3354

@@ -37,16 +58,5 @@ class Hook : IXposedHookLoadPackage {
3758
if (key == "audio.safemedia.bypass") param.result = true
3859
}
3960
})
40-
41-
val AudioServiceClass = XposedHelpers.findClass("com.android.server.audio.AudioService", lpparam.classLoader)
42-
XposedBridge.hookAllConstructors(AudioServiceClass, object : MethodHook() {
43-
override fun afterHookedMethod(param: MethodHookParam) {
44-
val MAX_STREAM_VOLUME = XposedHelpers.getObjectField(param.thisObject, "MAX_STREAM_VOLUME") as Array<Int>
45-
val preferences = XSharedPreferences(BuildConfig.APPLICATION_ID, SHARED_PREFERENCES_NAME)
46-
STREAMS.filter { preferences.contains(getPreferenceKey(it.value)) }
47-
.map { it.value to preferences.getInt(getPreferenceKey(it.value), MAX_STREAM_VOLUME[it.value]) }
48-
.forEach { MAX_STREAM_VOLUME[it.first] = it.second }
49-
}
50-
})
5161
}
5262
}

0 commit comments

Comments
 (0)