java: config: Refactor waitAndGetSystemService()
- Make use of waitForService() for >= Android 11. - Reserve manual polling for Android 10 due to lack of waitForService(). - Rework on logs to be less cluttering. Signed-off-by: Dakkshesh <beakthoven@gmail.com>
This commit is contained in:
Generated
-1
@@ -1,4 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="temurin-21" project-jdk-type="JavaSDK">
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package io.github.beakthoven.TrickyStoreOSS.config
|
||||
|
||||
import android.content.pm.IPackageManager
|
||||
import android.os.Build
|
||||
import android.os.FileObserver
|
||||
import android.os.IBinder
|
||||
import android.os.IInterface
|
||||
@@ -182,7 +183,7 @@ object PkgConfig {
|
||||
fun getTargetPackageUids(): Set<Int> {
|
||||
val result = mutableSetOf<Int>()
|
||||
val pm = getPm() ?: return emptySet()
|
||||
val flags = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) 0L else 0
|
||||
val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) 0L else 0
|
||||
val userId = Process.myUid() / 100000
|
||||
|
||||
getTargetPackages().forEach { pkg ->
|
||||
@@ -240,15 +241,21 @@ object PkgConfig {
|
||||
}
|
||||
|
||||
private fun waitAndGetSystemService(name: String): IBinder? {
|
||||
var tryCount = 0
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
return ServiceManager.waitForService(name)
|
||||
}
|
||||
|
||||
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")
|
||||
if (service != null) {
|
||||
Logger.d("Got $name service after $tryCount tries")
|
||||
return service
|
||||
}
|
||||
Thread.sleep(500)
|
||||
}
|
||||
|
||||
Logger.e("Failed to get $name service")
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,18 +7,22 @@ package android.os;
|
||||
|
||||
public class ServiceManager {
|
||||
public static IBinder getService(String name) {
|
||||
throw new UnsupportedOperationException("STUB!");
|
||||
throw new UnsupportedOperationException("");
|
||||
}
|
||||
|
||||
public static IBinder waitForService(String name) {
|
||||
throw new UnsupportedOperationException("");
|
||||
}
|
||||
|
||||
public static void addService(String name, IBinder binder) {
|
||||
throw new UnsupportedOperationException("STUB!");
|
||||
throw new UnsupportedOperationException("");
|
||||
}
|
||||
|
||||
public static IBinder checkService(String name) {
|
||||
throw new UnsupportedOperationException("STUB!");
|
||||
throw new UnsupportedOperationException("");
|
||||
}
|
||||
|
||||
public static String[] listServices() {
|
||||
throw new UnsupportedOperationException("STUB!");
|
||||
throw new UnsupportedOperationException("");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user