Merge "Made libbinder's waitForService accessible in java"
This commit is contained in:
@@ -1063,4 +1063,13 @@ public class Binder implements IBinder {
|
|||||||
StrictMode.clearGatheredViolations();
|
StrictMode.clearGatheredViolations();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the specified service from servicemanager. If the service is not running,
|
||||||
|
* servicemanager will attempt to start it, and this function will wait for it to be ready.
|
||||||
|
* Returns nullptr only if there are permission problems or fatal errors.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final native @Nullable IBinder waitForService(@NonNull String serviceName)
|
||||||
|
throws RemoteException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -989,6 +989,31 @@ static void android_os_Binder_blockUntilThreadAvailable(JNIEnv* env, jobject cla
|
|||||||
return IPCThreadState::self()->blockUntilThreadAvailable();
|
return IPCThreadState::self()->blockUntilThreadAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static jobject android_os_Binder_waitForService(
|
||||||
|
JNIEnv *env,
|
||||||
|
jclass /* clazzObj */,
|
||||||
|
jstring serviceNameObj) {
|
||||||
|
|
||||||
|
const jchar* serviceName = env->GetStringCritical(serviceNameObj, nullptr);
|
||||||
|
if (!serviceName) {
|
||||||
|
signalExceptionForError(env, nullptr, BAD_VALUE, true /*canThrowRemoteException*/);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
String16 nameCopy = String16(reinterpret_cast<const char16_t *>(serviceName),
|
||||||
|
env->GetStringLength(serviceNameObj));
|
||||||
|
env->ReleaseStringCritical(serviceNameObj, serviceName);
|
||||||
|
|
||||||
|
auto sm = android::defaultServiceManager();
|
||||||
|
sp<IBinder> service = sm->waitForService(nameCopy);
|
||||||
|
|
||||||
|
if (!service) {
|
||||||
|
signalExceptionForError(env, nullptr, NAME_NOT_FOUND, true /*canThrowRemoteException*/);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return javaObjectForIBinder(env, service);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
static const JNINativeMethod gBinderMethods[] = {
|
static const JNINativeMethod gBinderMethods[] = {
|
||||||
@@ -1016,7 +1041,8 @@ static const JNINativeMethod gBinderMethods[] = {
|
|||||||
{ "flushPendingCommands", "()V", (void*)android_os_Binder_flushPendingCommands },
|
{ "flushPendingCommands", "()V", (void*)android_os_Binder_flushPendingCommands },
|
||||||
{ "getNativeBBinderHolder", "()J", (void*)android_os_Binder_getNativeBBinderHolder },
|
{ "getNativeBBinderHolder", "()J", (void*)android_os_Binder_getNativeBBinderHolder },
|
||||||
{ "getNativeFinalizer", "()J", (void*)android_os_Binder_getNativeFinalizer },
|
{ "getNativeFinalizer", "()J", (void*)android_os_Binder_getNativeFinalizer },
|
||||||
{ "blockUntilThreadAvailable", "()V", (void*)android_os_Binder_blockUntilThreadAvailable }
|
{ "blockUntilThreadAvailable", "()V", (void*)android_os_Binder_blockUntilThreadAvailable },
|
||||||
|
{ "waitForService", "(Ljava/lang/String;)Landroid/os/IBinder;", (void*)android_os_Binder_waitForService }
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* const kBinderPathName = "android/os/Binder";
|
const char* const kBinderPathName = "android/os/Binder";
|
||||||
|
|||||||
Reference in New Issue
Block a user