Skip to content

Commit afccc44

Browse files
phhussonAndyCGYan
authored andcommitted
Use phh-signed IMS apps rather than AOSP-signed when the "phh_signature" patch is integrated
Change-Id: Id3f4cbfa17874c3b4df3bc144a19491c10391f27
1 parent f5a6e11 commit afccc44

2 files changed

Lines changed: 30 additions & 9 deletions

File tree

app/src/main/java/me/phh/treble/app/Ims.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import android.os.SystemProperties
1414
import android.preference.PreferenceManager
1515
import android.provider.Settings
1616
import android.util.Log
17+
import dalvik.system.PathClassLoader
1718
import java.lang.ref.WeakReference
1819

1920
@SuppressLint("StaticFieldLeak")

app/src/main/java/me/phh/treble/app/ImsSettings.kt

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import android.widget.Toast
1919
import androidx.core.content.FileProvider
2020
import androidx.preference.ListPreference
2121
import androidx.preference.Preference
22+
import dalvik.system.PathClassLoader
2223
import java.io.ByteArrayInputStream
2324
import java.io.File
2425
import java.io.FileInputStream
@@ -29,6 +30,23 @@ object ImsSettings : Settings {
2930
val forceEnableSettings = "key_ims_force_enable_setting"
3031
val installImsApk = "key_ims_install_apn"
3132

33+
fun checkHasPhhSignature(): Boolean {
34+
try {
35+
val cl = PathClassLoader(
36+
"/system/framework/services.jar",
37+
ClassLoader.getSystemClassLoader()
38+
)
39+
val pmUtils = cl.loadClass("com.android.server.pm.PackageManagerServiceUtils")
40+
val field = pmUtils.getDeclaredField("PHH_SIGNATURE")
41+
Log.d("PHH", "checkHasPhhSignature Field $field")
42+
return true
43+
} catch(t: Throwable) {
44+
Log.d("PHH", "checkHasPhhSignature Field failed")
45+
return false
46+
}
47+
}
48+
49+
3250
override fun enabled() = true
3351
}
3452

@@ -97,19 +115,21 @@ class ImsSettingsFragment : SettingsFragment() {
97115
Log.d("PHH", "Qualcomm HIDL radio = ${Ims.gotQcomHidl}")
98116
Log.d("PHH", "Qualcomm AIDL radio = ${Ims.gotQcomAidl}")
99117

118+
val signSuffix = if(ImsSettings.checkHasPhhSignature()) "-resigned" else ""
119+
100120
val (url, message) =
101121
when {
102122
(Ims.gotMtkR || Ims.gotMtkS || Ims.gotMtkAidl) && Build.VERSION.SDK_INT >= 34
103-
-> Pair("https://treble.phh.me/ims-mtk-u.apk", "MediaTek R+ vendor")
104-
Ims.gotMtkP -> Pair("https://treble.phh.me/stable/ims-mtk-p.apk", "MediaTek P vendor")
105-
Ims.gotMtkQ -> Pair("https://treble.phh.me/stable/ims-mtk-q.apk", "MediaTek Q vendor")
106-
Ims.gotMtkR -> Pair("https://treble.phh.me/stable/ims-mtk-r.apk", "MediaTek R vendor")
107-
Ims.gotMtkS -> Pair("https://treble.phh.me/stable/ims-mtk-s.apk", "MediaTek S vendor")
123+
-> Pair("https://treble.phh.me/ims-mtk-u$signSuffix.apk", "MediaTek R+ vendor")
124+
Ims.gotMtkP -> Pair("https://treble.phh.me/stable/ims-mtk-p$signSuffix.apk", "MediaTek P vendor")
125+
Ims.gotMtkQ -> Pair("https://treble.phh.me/stable/ims-mtk-q$signSuffix.apk", "MediaTek Q vendor")
126+
Ims.gotMtkR -> Pair("https://treble.phh.me/stable/ims-mtk-r$signSuffix.apk", "MediaTek R vendor")
127+
Ims.gotMtkS -> Pair("https://treble.phh.me/stable/ims-mtk-s$signSuffix.apk", "MediaTek S vendor")
108128
(Ims.gotQcomHidl || Ims.gotQcomAidl) && Build.VERSION.SDK_INT >= 34
109-
-> Pair("https://treble.phh.me/ims-caf-u.apk", "Qualcomm vendor")
110-
Ims.gotQcomHidlMoto -> Pair("https://treble.phh.me/stable/ims-caf-moto.apk", "Qualcomm pre-S vendor (Motorola)")
111-
Ims.gotQcomHidl -> Pair("https://treble.phh.me/stable/ims-q.64.apk", "Qualcomm pre-S vendor")
112-
Ims.gotQcomAidl -> Pair("https://treble.phh.me/stable/ims-caf-s.apk", "Qualcomm S+ vendor")
129+
-> Pair("https://treble.phh.me/ims-caf-u$signSuffix.apk", "Qualcomm vendor")
130+
Ims.gotQcomHidlMoto -> Pair("https://treble.phh.me/stable/ims-caf-moto$signSuffix.apk", "Qualcomm pre-S vendor (Motorola)")
131+
Ims.gotQcomHidl -> Pair("https://treble.phh.me/stable/ims-q.64$signSuffix.apk", "Qualcomm pre-S vendor")
132+
Ims.gotQcomAidl -> Pair("https://treble.phh.me/stable/ims-caf-s$signSuffix.apk", "Qualcomm S+ vendor")
113133
else -> Pair("", "NOT SUPPORTED")
114134
}
115135

0 commit comments

Comments
 (0)