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

Commit 4d11ea27 authored by Sooraj Sasindran's avatar Sooraj Sasindran Committed by Gerrit Code Review
Browse files

Merge "Release wakelock if setRadioCapability is not supported"

parents bad055ac 6bd310f6
Loading
Loading
Loading
Loading
+34 −11
Original line number Original line Diff line number Diff line
@@ -44,7 +44,8 @@ public class ProxyController {
    static final String LOG_TAG = "ProxyController";
    static final String LOG_TAG = "ProxyController";


    private static final int EVENT_NOTIFICATION_RC_CHANGED  = 1;
    private static final int EVENT_NOTIFICATION_RC_CHANGED  = 1;
    private static final int EVENT_START_RC_RESPONSE        = 2;
    @VisibleForTesting
    static final int EVENT_START_RC_RESPONSE                = 2;
    private static final int EVENT_APPLY_RC_RESPONSE        = 3;
    private static final int EVENT_APPLY_RC_RESPONSE        = 3;
    private static final int EVENT_FINISH_RC_RESPONSE       = 4;
    private static final int EVENT_FINISH_RC_RESPONSE       = 4;
    private static final int EVENT_TIMEOUT                  = 5;
    private static final int EVENT_TIMEOUT                  = 5;
@@ -364,7 +365,16 @@ public class ProxyController {
            // Abort here only in Single SIM case, in Multi SIM cases
            // Abort here only in Single SIM case, in Multi SIM cases
            // send FINISH with failure so that below layers can re-bind
            // send FINISH with failure so that below layers can re-bind
            // old logical modems.
            // old logical modems.
            if ((TelephonyManager.getDefault().getPhoneCount() == 1) && (ar.exception != null)) {
            if (ar.exception != null) {
                boolean isPermanaentFailure = false;
                if (ar.exception instanceof CommandException) {
                    CommandException.Error error =
                            ((CommandException) (ar.exception)).getCommandError();
                    if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
                        isPermanaentFailure = true;
                    }
                }
                if (TelephonyManager.getDefault().getPhoneCount() == 1  || isPermanaentFailure) {
                    // just abort now.  They didn't take our start so we don't have to revert
                    // just abort now.  They didn't take our start so we don't have to revert
                    logd("onStartRadioCapabilityResponse got exception=" + ar.exception);
                    logd("onStartRadioCapabilityResponse got exception=" + ar.exception);
                    mRadioCapabilitySessionId = mUniqueIdGenerator.getAndIncrement();
                    mRadioCapabilitySessionId = mUniqueIdGenerator.getAndIncrement();
@@ -373,6 +383,7 @@ public class ProxyController {
                    clearTransaction();
                    clearTransaction();
                    return;
                    return;
                }
                }
            }
            RadioCapability rc = (RadioCapability) ((AsyncResult) msg.obj).result;
            RadioCapability rc = (RadioCapability) ((AsyncResult) msg.obj).result;
            if ((rc == null) || (rc.getSession() != mRadioCapabilitySessionId)) {
            if ((rc == null) || (rc.getSession() != mRadioCapabilitySessionId)) {
                logd("onStartRadioCapabilityResponse: Ignore session=" + mRadioCapabilitySessionId
                logd("onStartRadioCapabilityResponse: Ignore session=" + mRadioCapabilitySessionId
@@ -381,7 +392,7 @@ public class ProxyController {
            }
            }
            mRadioAccessFamilyStatusCounter--;
            mRadioAccessFamilyStatusCounter--;
            int id = rc.getPhoneId();
            int id = rc.getPhoneId();
            if (((AsyncResult) msg.obj).exception != null) {
            if (ar.exception != null) {
                logd("onStartRadioCapabilityResponse: Error response session=" + rc.getSession());
                logd("onStartRadioCapabilityResponse: Error response session=" + rc.getSession());
                logd("onStartRadioCapabilityResponse: phoneId=" + id + " status=FAIL");
                logd("onStartRadioCapabilityResponse: phoneId=" + id + " status=FAIL");
                mSetRadioAccessFamilyStatus[id] = SET_RC_STATUS_FAIL;
                mSetRadioAccessFamilyStatus[id] = SET_RC_STATUS_FAIL;
@@ -618,12 +629,24 @@ public class ProxyController {
                mTransactionFailed = false;
                mTransactionFailed = false;
            }
            }


            if (mWakeLock.isHeld()) {
            if (isWakeLockHeld()) {
                mWakeLock.release();
                mWakeLock.release();
            }
            }
        }
        }
    }
    }


    /**
     * check if wakelock is held.
     *
     * @return true if wakelock is held else false.
     */
    @VisibleForTesting
    public boolean isWakeLockHeld() {
        synchronized (mSetRadioAccessFamilyStatus) {
            return mWakeLock.isHeld();
        }
    }

    private void resetRadioAccessFamilyStatusCounter() {
    private void resetRadioAccessFamilyStatusCounter() {
        mRadioAccessFamilyStatusCounter = mPhones.length;
        mRadioAccessFamilyStatusCounter = mPhones.length;
    }
    }
+35 −1
Original line number Original line Diff line number Diff line
@@ -16,14 +16,22 @@


package com.android.internal.telephony;
package com.android.internal.telephony;


import static android.telephony.RadioAccessFamily.RAF_GSM;
import static android.telephony.RadioAccessFamily.RAF_LTE;

import static com.android.internal.telephony.ProxyController.EVENT_MULTI_SIM_CONFIG_CHANGED;
import static com.android.internal.telephony.ProxyController.EVENT_MULTI_SIM_CONFIG_CHANGED;
import static com.android.internal.telephony.ProxyController.EVENT_START_RC_RESPONSE;


import static org.junit.Assert.assertFalse;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verify;


import android.os.AsyncResult;
import android.os.Handler;
import android.os.Handler;
import android.os.Message;
import android.os.Message;
import android.telephony.RadioAccessFamily;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.testing.TestableLooper;
@@ -40,7 +48,6 @@ import org.mockito.Mock;
public class ProxyControllerTest extends TelephonyTest {
public class ProxyControllerTest extends TelephonyTest {
    @Mock
    @Mock
    Phone mPhone2;
    Phone mPhone2;

    ProxyController mProxyController;
    ProxyController mProxyController;


    @Before
    @Before
@@ -73,4 +80,31 @@ public class ProxyControllerTest extends TelephonyTest {
        Message.obtain(mProxyController.mHandler, EVENT_MULTI_SIM_CONFIG_CHANGED).sendToTarget();
        Message.obtain(mProxyController.mHandler, EVENT_MULTI_SIM_CONFIG_CHANGED).sendToTarget();
        processAllMessages();
        processAllMessages();
    }
    }

    @Test
    @SmallTest
    public void testRequestNotSupported() throws Exception {
        int activeModemCount = 2;
        replaceInstance(PhoneFactory.class, "sPhones", null, new Phone[] {mPhone, mPhone2});
        doReturn(activeModemCount).when(mTelephonyManager).getPhoneCount();
        doReturn(RAF_GSM | RAF_LTE).when(mPhone).getRadioAccessFamily();
        doReturn(RAF_GSM).when(mPhone2).getRadioAccessFamily();

        Message.obtain(mProxyController.mHandler, EVENT_MULTI_SIM_CONFIG_CHANGED).sendToTarget();
        processAllMessages();
        verify(mPhone2).registerForRadioCapabilityChanged(any(), anyInt(), any());

        RadioAccessFamily[] rafs = new RadioAccessFamily[activeModemCount];
        rafs[0] = new RadioAccessFamily(0, RAF_GSM);
        rafs[1] = new RadioAccessFamily(1, RAF_GSM | RAF_LTE);
        mProxyController.setRadioCapability(rafs);

        Message.obtain(mProxyController.mHandler, EVENT_START_RC_RESPONSE,
                new AsyncResult(null, null,
                        new CommandException(CommandException.Error.REQUEST_NOT_SUPPORTED)))
                .sendToTarget();
        processAllMessages();

        assertFalse(mProxyController.isWakeLockHeld());
    }
}
}