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

Commit b79f95a2 authored by Malcolm Chen's avatar Malcolm Chen
Browse files

Update RadioConfig for 1.1 version

Adding HAL version check and convert proxy to different versions.

Bug: 121354686
Test: sanity
Change-Id: I2f898a926216ea54b8bed83ff5f434155573d68c
Merged-In: I2f898a926216ea54b8bed83ff5f434155573d68c
parent 57684f68
Loading
Loading
Loading
Loading
+46 −16
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import com.android.internal.telephony.uicc.IccSlotStatus;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.concurrent.atomic.AtomicLong;

/**
@@ -53,8 +54,16 @@ public class RadioConfig extends Handler {

    private static final int EVENT_SERVICE_DEAD = 1;

    private static final HalVersion RADIO_CONFIG_HAL_VERSION_UNKNOWN = new HalVersion(-1, -1);

    private static final HalVersion RADIO_CONFIG_HAL_VERSION_1_0 = new HalVersion(1, 0);

    private static final HalVersion RADIO_CONFIG_HAL_VERSION_1_1 = new HalVersion(1, 1);

    private final boolean mIsMobileNetworkSupported;
    private volatile IRadioConfig mRadioConfigProxy = null;
    // IRadioConfig version
    private HalVersion mRadioConfigVersion = RADIO_CONFIG_HAL_VERSION_UNKNOWN;
    private final ServiceDeathRecipient mServiceDeathRecipient;
    private final AtomicLong mRadioConfigProxyCookie = new AtomicLong(0);
    private final RadioConfigResponse mRadioConfigResponse;
@@ -166,24 +175,9 @@ public class RadioConfig extends Handler {
            return mRadioConfigProxy;
        }

        try {
            mRadioConfigProxy = IRadioConfig.getService(true);
            if (mRadioConfigProxy != null) {
                mRadioConfigProxy.linkToDeath(mServiceDeathRecipient,
                        mRadioConfigProxyCookie.incrementAndGet());
                mRadioConfigProxy.setResponseFunctions(mRadioConfigResponse,
                        mRadioConfigIndication);
            } else {
                loge("getRadioConfigProxy: mRadioConfigProxy == null");
            }
        } catch (RemoteException | RuntimeException e) {
            mRadioConfigProxy = null;
            loge("getRadioConfigProxy: RadioConfigProxy getService/setResponseFunctions: " + e);
        }
        updateRadioConfigProxy();

        if (mRadioConfigProxy == null) {
            // getService() is a blocking call, so this should never happen
            loge("getRadioConfigProxy: mRadioConfigProxy == null");
            if (result != null) {
                AsyncResult.forMessage(result, null,
                        CommandException.fromRilErrno(RADIO_NOT_AVAILABLE));
@@ -194,6 +188,42 @@ public class RadioConfig extends Handler {
        return mRadioConfigProxy;
    }

    private void updateRadioConfigProxy() {
        try {
            // Try to get service from different versions.
            try {
                mRadioConfigProxy = android.hardware.radio.config.V1_1.IRadioConfig.getService(
                        true);
                mRadioConfigVersion = RADIO_CONFIG_HAL_VERSION_1_1;
            } catch (NoSuchElementException e) {
            }

            if (mRadioConfigProxy == null) {
                try {
                    mRadioConfigProxy = android.hardware.radio.config.V1_0
                            .IRadioConfig.getService(true);
                    mRadioConfigVersion = RADIO_CONFIG_HAL_VERSION_1_0;
                } catch (NoSuchElementException e) {
                }
            }

            if (mRadioConfigProxy == null) {
                loge("getRadioConfigProxy: mRadioConfigProxy == null");
                return;
            }

            // Link to death recipient and set response. If fails, set proxy to null and return.
            mRadioConfigProxy.linkToDeath(mServiceDeathRecipient,
                    mRadioConfigProxyCookie.incrementAndGet());
            mRadioConfigProxy.setResponseFunctions(mRadioConfigResponse,
                    mRadioConfigIndication);
        } catch (RemoteException | RuntimeException e) {
            mRadioConfigProxy = null;
            loge("getRadioConfigProxy: RadioConfigProxy setResponseFunctions: " + e);
            return;
        }
    }

    private RILRequest obtainRequest(int request, Message result, WorkSource workSource) {
        RILRequest rr = RILRequest.obtain(request, result, workSource);
        synchronized (mRequestList) {