Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3ef1b5e5 authored by Jon Spivack's avatar Jon Spivack Committed by Gerrit Code Review
Browse files

Merge "Made libbinder's waitForService accessible in java"

parents 20a9b3b4 9e45fde5
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -1063,4 +1063,13 @@ public class Binder implements IBinder {
        StrictMode.clearGatheredViolations();
        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;
}
+27 −1
Original line number Diff line number Diff line
@@ -989,6 +989,31 @@ static void android_os_Binder_blockUntilThreadAvailable(JNIEnv* env, jobject cla
    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[] = {
@@ -1016,7 +1041,8 @@ static const JNINativeMethod gBinderMethods[] = {
    { "flushPendingCommands", "()V", (void*)android_os_Binder_flushPendingCommands },
    { "getNativeBBinderHolder", "()J", (void*)android_os_Binder_getNativeBBinderHolder },
    { "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";