Merge "Merge "ServiceManager: waitForService uses allowBlocking" am: b801a513d1 am: 726c374fa3" into sc-dev-plus-aosp
diff --git a/core/java/android/os/ServiceManager.java b/core/java/android/os/ServiceManager.java
index f853e67..f7d7b21 100644
--- a/core/java/android/os/ServiceManager.java
+++ b/core/java/android/os/ServiceManager.java
@@ -257,7 +257,12 @@
*
* @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.
diff --git a/core/jni/android_os_ServiceManager.cpp b/core/jni/android_os_ServiceManager.cpp
index c747949..d642d0e 100644
--- a/core/jni/android_os_ServiceManager.cpp
+++ b/core/jni/android_os_ServiceManager.cpp
@@ -29,11 +29,8 @@
// 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 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) {