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

Commit ab4e9b68 authored by Devin Moore's avatar Devin Moore
Browse files

Create a HwNoService class that fakes hwservicemanager

If HIDL is no longer supporter, we don't expect hwservicemanager to be
installed. This will pretend to be hwservicemanager with no services.

This is done in Java so we can avoid using local binders that are
implemented in C++. That code path is not supported.

Test: m
Bug: 218588089

Change-Id: Icad72f6a3a8e825fdce32afa1a9de8f37b40f732
parent b0f98aa1
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.os;

import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.util.Log;

import libcore.util.NativeAllocationRegistry;

@@ -78,6 +79,17 @@ public abstract class HwBinder implements IHwBinder {
            String iface,
            String serviceName)
        throws RemoteException, NoSuchElementException {
        if (!HidlSupport.isHidlSupported()
                && (iface.equals("android.hidl.manager@1.0::IServiceManager")
                        || iface.equals("android.hidl.manager@1.1::IServiceManager")
                        || iface.equals("android.hidl.manager@1.2::IServiceManager"))) {
            Log.i(
                    TAG,
                    "Replacing Java hwservicemanager with a fake HwNoService"
                            + " because HIDL is not supported on this device.");
            return new HwNoService();
        }

        return getService(iface, serviceName, false /* retry */);
    }
    /**
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.
 */

package android.os;

/**
 * A fake hwservicemanager that is used locally when HIDL isn't supported on the device.
 *
 * @hide
 */
final class HwNoService implements IHwBinder, IHwInterface {
    /** @hide */
    @Override
    public void transact(int code, HwParcel request, HwParcel reply, int flags) {}

    /** @hide */
    @Override
    public IHwInterface queryLocalInterface(String descriptor) {
        return new HwNoService();
    }

    /** @hide */
    @Override
    public boolean linkToDeath(DeathRecipient recipient, long cookie) {
        return true;
    }

    /** @hide */
    @Override
    public boolean unlinkToDeath(DeathRecipient recipient) {
        return true;
    }

    /** @hide */
    @Override
    public IHwBinder asBinder() {
        return this;
    }
}