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

Commit 1e067eff authored by Steven Moreland's avatar Steven Moreland Committed by Gerrit Code Review
Browse files

Merge changes Ibd2ad90a,Ifeb615dc into main

* changes:
  Change the native_transact to handle local binder txns
  Update HwNoService to implement IServiceManager.Stub
parents 262d3602 9249b41c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -207,6 +207,7 @@ java_library {
        "updatable-driver-protos",
        "ota_metadata_proto_java",
        "android.hidl.base-V1.0-java",
        "android.hidl.manager-V1.2-java",
        "android.hardware.cas-V1-java", // AIDL
        "android.hardware.cas-V1.0-java",
        "android.hardware.cas-V1.1-java",
+102 −12
Original line number Diff line number Diff line
@@ -16,37 +16,127 @@

package android.os;

import android.hidl.manager.V1_2.IServiceManager;
import android.util.Log;

import java.util.ArrayList;

/**
 * A fake hwservicemanager that is used locally when HIDL isn't supported on the device.
 *
 * @hide
 */
final class HwNoService implements IHwBinder, IHwInterface {
final class HwNoService extends IServiceManager.Stub implements IHwBinder, IHwInterface {
    private static final String TAG = "HwNoService";

    /** @hide */
    @Override
    public void transact(int code, HwParcel request, HwParcel reply, int flags) {}
    public String toString() {
        return "[HwNoService]";
    }

    /** @hide */
    @Override
    public IHwInterface queryLocalInterface(String descriptor) {
        return new HwNoService();
    public android.hidl.base.V1_0.IBase get(String fqName, String name)
            throws android.os.RemoteException {
        Log.i(TAG, "get " + fqName + "/" + name + " with no hwservicemanager");
        return null;
    }

    /** @hide */
    @Override
    public boolean linkToDeath(DeathRecipient recipient, long cookie) {
    public boolean add(String name, android.hidl.base.V1_0.IBase service)
            throws android.os.RemoteException {
        Log.i(TAG, "get " + name + " with no hwservicemanager");
        return false;
    }

    @Override
    public byte getTransport(String fqName, String name) throws android.os.RemoteException {
        Log.i(TAG, "getTransoport " + fqName + "/" + name + " with no hwservicemanager");
        return 0x0;
    }

    @Override
    public java.util.ArrayList<String> list() throws android.os.RemoteException {
        Log.i(TAG, "list with no hwservicemanager");
        return new ArrayList<String>();
    }

    @Override
    public java.util.ArrayList<String> listByInterface(String fqName)
            throws android.os.RemoteException {
        Log.i(TAG, "listByInterface with no hwservicemanager");
        return new ArrayList<String>();
    }

    @Override
    public boolean registerForNotifications(
            String fqName, String name, android.hidl.manager.V1_0.IServiceNotification callback)
            throws android.os.RemoteException {
        Log.i(TAG, "registerForNotifications with no hwservicemanager");
        return true;
    }

    /** @hide */
    @Override
    public boolean unlinkToDeath(DeathRecipient recipient) {
    public ArrayList<android.hidl.manager.V1_0.IServiceManager.InstanceDebugInfo> debugDump()
            throws android.os.RemoteException {
        Log.i(TAG, "debugDump with no hwservicemanager");
        return new ArrayList<android.hidl.manager.V1_0.IServiceManager.InstanceDebugInfo>();
    }

    @Override
    public void registerPassthroughClient(String fqName, String name)
            throws android.os.RemoteException {
        Log.i(TAG, "registerPassthroughClient with no hwservicemanager");
    }

    @Override
    public boolean unregisterForNotifications(
            String fqName, String name, android.hidl.manager.V1_0.IServiceNotification callback)
            throws android.os.RemoteException {
        Log.i(TAG, "unregisterForNotifications with no hwservicemanager");
        return true;
    }

    /** @hide */
    @Override
    public IHwBinder asBinder() {
        return this;
    public boolean registerClientCallback(
            String fqName,
            String name,
            android.hidl.base.V1_0.IBase server,
            android.hidl.manager.V1_2.IClientCallback cb)
            throws android.os.RemoteException {
        Log.i(
                TAG,
                "registerClientCallback for " + fqName + "/" + name + " with no hwservicemanager");
        return true;
    }

    @Override
    public boolean unregisterClientCallback(
            android.hidl.base.V1_0.IBase server, android.hidl.manager.V1_2.IClientCallback cb)
            throws android.os.RemoteException {
        Log.i(TAG, "unregisterClientCallback with no hwservicemanager");
        return true;
    }

    @Override
    public boolean addWithChain(
            String name, android.hidl.base.V1_0.IBase service, java.util.ArrayList<String> chain)
            throws android.os.RemoteException {
        Log.i(TAG, "addWithChain with no hwservicemanager");
        return true;
    }

    @Override
    public java.util.ArrayList<String> listManifestByInterface(String fqName)
            throws android.os.RemoteException {
        Log.i(TAG, "listManifestByInterface for " + fqName + " with no hwservicemanager");
        return new ArrayList<String>();
    }

    @Override
    public boolean tryUnregister(String fqName, String name, android.hidl.base.V1_0.IBase service)
            throws android.os.RemoteException {
        Log.i(TAG, "tryUnregister for " + fqName + "/" + name + " with no hwservicemanager");
        return true;
    }
}
+53 −8
Original line number Diff line number Diff line
@@ -258,14 +258,59 @@ static void JHwBinder_native_setup(JNIEnv *env, jobject thiz) {
    JHwBinder::SetNativeContext(env, thiz, context);
}

static void JHwBinder_native_transact(
        JNIEnv * /* env */,
        jobject /* thiz */,
        jint /* code */,
        jobject /* requestObj */,
        jobject /* replyObj */,
        jint /* flags */) {
    CHECK(!"Should not be here");
static void JHwBinder_native_transact(JNIEnv *env, jobject thiz, jint code, jobject requestObj,
                                      jobject replyObj, jint flags) {
    if (requestObj == NULL) {
        jniThrowException(env, "java/lang/NullPointerException", NULL);
        return;
    }
    sp<hardware::IBinder> binder = JHwBinder::GetNativeBinder(env, thiz);
    sp<android::hidl::base::V1_0::IBase> base = new android::hidl::base::V1_0::BpHwBase(binder);
    hidl_string desc;
    auto ret = base->interfaceDescriptor(
            [&desc](const hidl_string &descriptor) { desc = descriptor; });
    ret.assertOk();
    // Only the fake hwservicemanager is allowed to be used locally like this.
    if (desc != "android.hidl.manager@1.2::IServiceManager" &&
        desc != "android.hidl.manager@1.1::IServiceManager" &&
        desc != "android.hidl.manager@1.0::IServiceManager") {
        LOG(FATAL) << "Local binders are not supported!";
    }
    if (replyObj == nullptr) {
        LOG(FATAL) << "Unexpected null replyObj. code: " << code;
        return;
    }
    const hardware::Parcel *request = JHwParcel::GetNativeContext(env, requestObj)->getParcel();
    sp<JHwParcel> replyContext = JHwParcel::GetNativeContext(env, replyObj);
    hardware::Parcel *reply = replyContext->getParcel();

    request->setDataPosition(0);

    bool isOneway = (flags & IBinder::FLAG_ONEWAY) != 0;
    if (!isOneway) {
        replyContext->setTransactCallback([](auto &replyParcel) {});
    }

    env->CallVoidMethod(thiz, gFields.onTransactID, code, requestObj, replyObj, flags);

    if (env->ExceptionCheck()) {
        jthrowable excep = env->ExceptionOccurred();
        env->ExceptionDescribe();
        env->ExceptionClear();

        binder_report_exception(env, excep, "Uncaught error or exception in hwbinder!");

        env->DeleteLocalRef(excep);
    }

    if (!isOneway) {
        if (!replyContext->wasSent()) {
            // The implementation never finished the transaction.
            LOG(ERROR) << "The reply failed to send!";
        }
    }

    reply->setDataPosition(0);
}

static void JHwBinder_native_registerService(