java: make getPM() wait for package manager service initialisation (#30)

This commit is contained in:
Furkan Karcıoğlu
2025-09-01 00:25:45 +05:30
committed by GitHub
parent c285992226
commit 2fad7ff251
@@ -138,7 +138,7 @@ object PkgConfig {
fun getPm(): IPackageManager? {
if (iPm == null) {
val binder = ServiceManager.getService("package") ?: return null
val binder = waitAndGetSystemService("package") ?: return null
binder.linkToDeath(packageManagerDeathRecipient, 0)
iPm = IPackageManager.Stub.asInterface(binder)
}
@@ -238,6 +238,19 @@ object PkgConfig {
}.onFailure {
Logger.e("failed to update patch level", it)
}
private fun waitAndGetSystemService(name: String): IBinder? {
var tryCount = 0
while (tryCount++ < 70) {
val service = ServiceManager.getService(name)
if (service != null) return service
Logger.e("Package manager is null, waiting for 500ms")
Thread.sleep(500)
}
return null
}
}
data class CustomPatchLevel(