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

Commit 137f8753 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use waitForDeclaredService to get Lights HAL" into rvc-dev

parents 6335c269 9e118130
Loading
Loading
Loading
Loading
+39 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package android.os;
package android.os;


import android.annotation.NonNull;
import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Log;
@@ -218,6 +219,44 @@ public final class ServiceManager {
        }
        }
    }
    }


    /**
     * Returns whether the specified service is declared.
     *
     * @return true if the service is declared somewhere (eg. VINTF manifest) and
     * waitForService should always be able to return the service.
     */
    public static boolean isDeclared(@NonNull String name) {
        try {
            return getIServiceManager().isDeclared(name);
        } catch (RemoteException e) {
            Log.e(TAG, "error in isDeclared", e);
            return false;
        }
    }

    /**
     * Returns the specified service from the service manager.
     *
     * If the service is not running, servicemanager will attempt to start it, and this function
     * will wait for it to be ready.
     *
     * @return {@code null} only if there are permission problems or fatal errors.
     */
    public static native IBinder waitForService(@NonNull String name);

    /**
     * Returns the specified service from the service manager, if declared.
     *
     * If the service is not running, servicemanager will attempt to start it, and this function
     * will wait for it to be ready.
     *
     * @return {@code null} if the service is not declared in the manifest, or if there are
     * permission problems, or if there are fatal errors.
     */
    public static IBinder waitForDeclaredService(@NonNull String name) {
        return isDeclared(name) ? waitForService(name) : null;
    }

    /**
    /**
     * Return a list of all currently running services.
     * Return a list of all currently running services.
     * @return an array of all currently running services, or <code>null</code> in
     * @return an array of all currently running services, or <code>null</code> in
+1 −1
Original line number Original line Diff line number Diff line
@@ -87,7 +87,7 @@ class ServiceManagerProxy implements IServiceManager {
    }
    }


    public boolean isDeclared(String name) throws RemoteException {
    public boolean isDeclared(String name) throws RemoteException {
        throw new RemoteException();
        return mServiceManager.isDeclared(name);
    }
    }


    public void registerClientCallback(String name, IBinder service, IClientCallback cb)
    public void registerClientCallback(String name, IBinder service, IClientCallback cb)
+1 −0
Original line number Original line Diff line number Diff line
@@ -123,6 +123,7 @@ cc_library_shared {
                "android_os_MessageQueue.cpp",
                "android_os_MessageQueue.cpp",
                "android_os_Parcel.cpp",
                "android_os_Parcel.cpp",
                "android_os_SELinux.cpp",
                "android_os_SELinux.cpp",
                "android_os_ServiceManager.cpp",
                "android_os_SharedMemory.cpp",
                "android_os_SharedMemory.cpp",
                "android_os_storage_StorageManager.cpp",
                "android_os_storage_StorageManager.cpp",
                "android_os_UEventObserver.cpp",
                "android_os_UEventObserver.cpp",
+2 −0
Original line number Original line Diff line number Diff line
@@ -136,6 +136,7 @@ extern int register_android_os_HwBlob(JNIEnv *env);
extern int register_android_os_HwParcel(JNIEnv *env);
extern int register_android_os_HwParcel(JNIEnv *env);
extern int register_android_os_HwRemoteBinder(JNIEnv *env);
extern int register_android_os_HwRemoteBinder(JNIEnv *env);
extern int register_android_os_NativeHandle(JNIEnv *env);
extern int register_android_os_NativeHandle(JNIEnv *env);
extern int register_android_os_ServiceManager(JNIEnv *env);
extern int register_android_os_MessageQueue(JNIEnv* env);
extern int register_android_os_MessageQueue(JNIEnv* env);
extern int register_android_os_Parcel(JNIEnv* env);
extern int register_android_os_Parcel(JNIEnv* env);
extern int register_android_os_SELinux(JNIEnv* env);
extern int register_android_os_SELinux(JNIEnv* env);
@@ -1461,6 +1462,7 @@ static const RegJNIRec gRegJNI[] = {
        REG_JNI(register_android_os_HwParcel),
        REG_JNI(register_android_os_HwParcel),
        REG_JNI(register_android_os_HwRemoteBinder),
        REG_JNI(register_android_os_HwRemoteBinder),
        REG_JNI(register_android_os_NativeHandle),
        REG_JNI(register_android_os_NativeHandle),
        REG_JNI(register_android_os_ServiceManager),
        REG_JNI(register_android_os_storage_StorageManager),
        REG_JNI(register_android_os_storage_StorageManager),
        REG_JNI(register_android_os_VintfObject),
        REG_JNI(register_android_os_VintfObject),
        REG_JNI(register_android_os_VintfRuntimeInfo),
        REG_JNI(register_android_os_VintfRuntimeInfo),
+71 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "ServiceManager"
//#define LOG_NDEBUG 0
#include <android-base/logging.h>

#include <binder/IInterface.h>
#include <binder/IServiceManager.h>
#include <nativehelper/JNIHelp.h>

#include "android_util_Binder.h"
#include "core_jni_helpers.h"

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) {

    const jchar* serviceName = env->GetStringCritical(serviceNameObj, nullptr);
    if (!serviceName) {
        jniThrowNullPointerException(env, nullptr);
        return nullptr;
    }
    String16 nameCopy = String16(reinterpret_cast<const char16_t *>(serviceName),
            env->GetStringLength(serviceNameObj));
    env->ReleaseStringCritical(serviceNameObj, serviceName);

    sp<IBinder> service = defaultServiceManager()->waitForService(nameCopy);

    if (!service) {
        return nullptr;
    }

    return javaObjectForIBinder(env, service);
}

// ----------------------------------------------------------------------------

static const JNINativeMethod method_table[] = {
     /* name, signature, funcPtr */
    {
        "waitForService",
        "(Ljava/lang/String;)Landroid/os/IBinder;",
        (void*)android_os_ServiceManager_waitForService
    },
};

int register_android_os_ServiceManager(JNIEnv* env) {
    return RegisterMethodsOrDie(
            env, "android/os/ServiceManager", method_table, NELEM(method_table));
}

}; // namespace android
Loading