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

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

Use new AIDL IR interface for ConsumerIr service

Continue using the HIDL service if it is registered, otherwise use the
AIDL service.

Test: atest ConsumerIrTest VtsHalIrTargetTest hal_implementation_test
Bug: 205000342
Change-Id: I648aa765d14c4f5d4c862523a1bb69b2e7bc5cc1
parent 325b64ce
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -154,6 +154,7 @@ java_library_static {
        "android.hardware.oemlock-V1.0-java",
        "android.hardware.configstore-V1.1-java",
        "android.hardware.contexthub-V1.0-java",
        "android.hardware.ir-V1-java",
        "android.hardware.rebootescrow-V1-java",
        "android.hardware.soundtrigger-V2.3-java",
        "android.hardware.power.stats-V1-java",
+51 −9
Original line number Diff line number Diff line
@@ -19,17 +19,19 @@ package com.android.server;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.IConsumerIrService;
import android.hardware.ir.ConsumerIrFreqRange;
import android.hardware.ir.IConsumerIr;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Slog;

import java.lang.RuntimeException;

public class ConsumerIrService extends IConsumerIrService.Stub {
    private static final String TAG = "ConsumerIrService";

    private static final int MAX_XMIT_TIME = 2000000; /* in microseconds */

    private static native boolean halOpen();
    private static native boolean getHidlHalService();
    private static native int halTransmit(int carrierFrequency, int[] pattern);
    private static native int[] halGetCarrierFrequencies();

@@ -37,6 +39,7 @@ public class ConsumerIrService extends IConsumerIrService.Stub {
    private final PowerManager.WakeLock mWakeLock;
    private final boolean mHasNativeHal;
    private final Object mHalLock = new Object();
    private IConsumerIr mAidlService = null;

    ConsumerIrService(Context context) {
        mContext = context;
@@ -45,7 +48,8 @@ public class ConsumerIrService extends IConsumerIrService.Stub {
        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
        mWakeLock.setReferenceCounted(true);

        mHasNativeHal = halOpen();
        mHasNativeHal = getHalService();

        if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CONSUMER_IR)) {
            if (!mHasNativeHal) {
                throw new RuntimeException("FEATURE_CONSUMER_IR present, but no IR HAL loaded!");
@@ -60,6 +64,19 @@ public class ConsumerIrService extends IConsumerIrService.Stub {
        return mHasNativeHal;
    }

    private boolean getHalService() {
        // Attempt to get the AIDL HAL service first
        final String fqName = IConsumerIr.DESCRIPTOR + "/default";
        mAidlService = IConsumerIr.Stub.asInterface(
                        ServiceManager.waitForDeclaredService(fqName));
        if (mAidlService != null) {
            return true;
        }

        // Fall back to the HIDL HAL service
        return getHidlHalService();
    }

    private void throwIfNoIrEmitter() {
        if (!mHasNativeHal) {
            throw new UnsupportedOperationException("IR emitter not available");
@@ -91,6 +108,13 @@ public class ConsumerIrService extends IConsumerIrService.Stub {

        // Right now there is no mechanism to ensure fair queing of IR requests
        synchronized (mHalLock) {
            if (mAidlService != null) {
                try {
                    mAidlService.transmit(carrierFrequency, pattern);
                } catch (RemoteException ignore) {
                    Slog.e(TAG, "Error transmitting frequency: " + carrierFrequency);
                }
            } else {
                int err = halTransmit(carrierFrequency, pattern);

                if (err < 0) {
@@ -98,6 +122,7 @@ public class ConsumerIrService extends IConsumerIrService.Stub {
                }
            }
        }
    }

    @Override
    public int[] getCarrierFrequencies() {
@@ -109,7 +134,24 @@ public class ConsumerIrService extends IConsumerIrService.Stub {
        throwIfNoIrEmitter();

        synchronized(mHalLock) {
            if (mAidlService != null) {
                try {
                    ConsumerIrFreqRange[] output = mAidlService.getCarrierFreqs();
                    if (output.length <= 0) {
                        Slog.e(TAG, "Error getting carrier frequencies.");
                    }
                    int[] result = new int[output.length * 2];
                    for (int i = 0; i < output.length; i++) {
                        result[i * 2] = output[i].minHz;
                        result[i * 2 + 1] = output[i].maxHz;
                    }
                    return result;
                } catch (RemoteException ignore) {
                    return null;
                }
            } else {
                return halGetCarrierFrequencies();
            }
        }
    }
}
+4 −4
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ namespace android {

static sp<IConsumerIr> mHal;

static jboolean halOpen(JNIEnv* /* env */, jobject /* obj */) {
static jboolean getHidlHalService(JNIEnv * /* env */, jobject /* obj */) {
    // TODO(b/31632518)
    mHal = IConsumerIr::getService();
    return mHal != nullptr;
@@ -84,7 +84,7 @@ static jintArray halGetCarrierFrequencies(JNIEnv *env, jobject /* obj */) {
}

static const JNINativeMethod method_table[] = {
    { "halOpen", "()Z", (void *)halOpen },
        {"getHidlHalService", "()Z", (void *)getHidlHalService},
        {"halTransmit", "(I[I)I", (void *)halTransmit},
        {"halGetCarrierFrequencies", "()[I", (void *)halGetCarrierFrequencies},
};