ServiceManager: waitForService uses allowBlocking

For parity with getService and checkService.

Bug: 194806512
Test: boot
Change-Id: Iecc3f1c6d6ae9bee94252281b416d62f3bf30afd
This commit is contained in:
Steven Moreland
2021-08-10 16:31:37 -07:00
parent 7ad87a83da
commit d247e417a2
2 changed files with 11 additions and 12 deletions

View File

@@ -257,7 +257,12 @@ public final class ServiceManager {
*
* @return {@code null} only if there are permission problems or fatal errors.
*/
public static native IBinder waitForService(@NonNull String name);
public static IBinder waitForService(@NonNull String name) {
return Binder.allowBlocking(waitForServiceNative(name));
}
private static native IBinder waitForServiceNative(@NonNull String name);
/**
* Returns the specified service from the service manager, if declared.

View File

@@ -29,11 +29,8 @@ namespace android {
// Native because we have a client-side wait in waitForService() and we do not
// want an unnecessary second copy of it.
static jobject android_os_ServiceManager_waitForService(
JNIEnv *env,
jclass /* clazzObj */,
jstring serviceNameObj) {
static jobject android_os_ServiceManager_waitForServiceNative(JNIEnv* env, jclass /* clazzObj */,
jstring serviceNameObj) {
const jchar* serviceName = env->GetStringCritical(serviceNameObj, nullptr);
if (!serviceName) {
jniThrowNullPointerException(env, nullptr);
@@ -55,12 +52,9 @@ static jobject android_os_ServiceManager_waitForService(
// ----------------------------------------------------------------------------
static const JNINativeMethod method_table[] = {
/* name, signature, funcPtr */
{
"waitForService",
"(Ljava/lang/String;)Landroid/os/IBinder;",
(void*)android_os_ServiceManager_waitForService
},
/* name, signature, funcPtr */
{"waitForServiceNative", "(Ljava/lang/String;)Landroid/os/IBinder;",
(void*)android_os_ServiceManager_waitForServiceNative},
};
int register_android_os_ServiceManager(JNIEnv* env) {