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

Commit b7a47e05 authored by Sooraj Sasindran's avatar Sooraj Sasindran Committed by Automerger Merge Worker
Browse files

Merge "Release wakelock if setRadioCapability is not supported" am: 4d11ea27...

Merge "Release wakelock if setRadioCapability is not supported" am: 4d11ea27 am: 77cb2314 am: 0f66398f am: a24a3c41

Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/1969941

Change-Id: I3a5326eae28ed8788d06f407bcad4ea80c35330d
parents 9fe3ef5b a24a3c41
Loading
Loading
Loading
Loading
+34 −11
Original line number Diff line number Diff line
@@ -45,7 +45,8 @@ public class ProxyController {
    static final String LOG_TAG = "ProxyController";

    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_FINISH_RC_RESPONSE       = 4;
    private static final int EVENT_TIMEOUT                  = 5;
@@ -365,7 +366,16 @@ public class ProxyController {
            // Abort here only in Single SIM case, in Multi SIM cases
            // send FINISH with failure so that below layers can re-bind
            // 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
                    logd("onStartRadioCapabilityResponse got exception=" + ar.exception);
                    mRadioCapabilitySessionId = mUniqueIdGenerator.getAndIncrement();
@@ -374,6 +384,7 @@ public class ProxyController {
                    clearTransaction();
                    return;
                }
            }
            RadioCapability rc = (RadioCapability) ((AsyncResult) msg.obj).result;
            if ((rc == null) || (rc.getSession() != mRadioCapabilitySessionId)) {
                logd("onStartRadioCapabilityResponse: Ignore session=" + mRadioCapabilitySessionId
@@ -382,7 +393,7 @@ public class ProxyController {
            }
            mRadioAccessFamilyStatusCounter--;
            int id = rc.getPhoneId();
            if (((AsyncResult) msg.obj).exception != null) {
            if (ar.exception != null) {
                logd("onStartRadioCapabilityResponse: Error response session=" + rc.getSession());
                logd("onStartRadioCapabilityResponse: phoneId=" + id + " status=FAIL");
                mSetRadioAccessFamilyStatus[id] = SET_RC_STATUS_FAIL;
@@ -619,12 +630,24 @@ public class ProxyController {
                mTransactionFailed = false;
            }

            if (mWakeLock.isHeld()) {
            if (isWakeLockHeld()) {
                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() {
        mRadioAccessFamilyStatusCounter = mPhones.length;
    }
+35 −1
Original line number Diff line number Diff line
@@ -16,14 +16,22 @@

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_START_RC_RESPONSE;

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

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

    ProxyController mProxyController;

    @Before
@@ -73,4 +80,31 @@ public class ProxyControllerTest extends TelephonyTest {
        Message.obtain(mProxyController.mHandler, EVENT_MULTI_SIM_CONFIG_CHANGED).sendToTarget();
        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());
    }
}