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

Commit b094f383 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Clear mLoaded in IccRecords when SIM is disabled." into rvc-dev am:...

Merge "Clear mLoaded in IccRecords when SIM is disabled." into rvc-dev am: ff074e9b am: fd0fb329

Change-Id: I13d7c0ea960e37ed69ba7e08d558ba27364c7419
parents c046fae5 fd0fb329
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -202,6 +202,7 @@ public abstract class IccRecords extends Handler implements IccConstants {
    protected static final int EVENT_APP_READY = 1 + SYSTEM_EVENT_BASE;
    protected static final int EVENT_APP_LOCKED = 2 + SYSTEM_EVENT_BASE;
    protected static final int EVENT_APP_NETWORK_LOCKED = 3 + SYSTEM_EVENT_BASE;
    protected static final int EVENT_APP_DETECTED = 4 + SYSTEM_EVENT_BASE;

    public static final int CALL_FORWARDING_STATUS_DISABLED = 0;
    public static final int CALL_FORWARDING_STATUS_ENABLED = 1;
@@ -285,6 +286,7 @@ public abstract class IccRecords extends Handler implements IccConstants {
        mCi.registerForIccRefresh(this, EVENT_REFRESH, null);

        mParentApp.registerForReady(this, EVENT_APP_READY, null);
        mParentApp.registerForDetected(this, EVENT_APP_DETECTED, null);
        mParentApp.registerForLocked(this, EVENT_APP_LOCKED, null);
        mParentApp.registerForNetworkLocked(this, EVENT_APP_NETWORK_LOCKED, null);
    }
@@ -306,6 +308,7 @@ public abstract class IccRecords extends Handler implements IccConstants {

        mCi.unregisterForIccRefresh(this);
        mParentApp.unregisterForReady(this);
        mParentApp.unregisterForDetected(this);
        mParentApp.unregisterForLocked(this);
        mParentApp.unregisterForNetworkLocked(this);

@@ -321,6 +324,11 @@ public abstract class IccRecords extends Handler implements IccConstants {

    protected abstract void onReady();

    protected void onDetected() {
        mRecordsRequested = false;
        mLoaded.set(false);
    }

    protected void onLocked() {
        // The LOADED state should not be indicated while the lock is effective.
        mRecordsRequested = false;
@@ -822,6 +830,11 @@ public abstract class IccRecords extends Handler implements IccConstants {
                onReady();
                break;

            case EVENT_APP_DETECTED:
                mLockedRecordsReqReason = LOCKED_RECORDS_REQ_REASON_NONE;
                onDetected();
                break;

            case EVENT_APP_LOCKED:
                mLockedRecordsReqReason = LOCKED_RECORDS_REQ_REASON_LOCKED;
                onLocked();
+36 −0
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ public class UiccCardApplication {
    private boolean mDestroyed;//set to true once this App is commanded to be disposed of.

    private RegistrantList mReadyRegistrants = new RegistrantList();
    private RegistrantList mDetectedRegistrants = new RegistrantList();
    private RegistrantList mPinLockedRegistrants = new RegistrantList();
    private RegistrantList mNetworkLockedRegistrants = new RegistrantList();

@@ -174,6 +175,7 @@ public class UiccCardApplication {
                }
                notifyPinLockedRegistrantsIfNeeded(null);
                notifyReadyRegistrantsIfNeeded(null);
                notifyDetectedRegistrantsIfNeeded(null);
            } else {
                if (mPin1State != oldPin1State)
                    queryPin1State();
@@ -445,6 +447,20 @@ public class UiccCardApplication {
        }
    }

    public void registerForDetected(Handler h, int what, Object obj) {
        synchronized (mLock) {
            Registrant r = new Registrant(h, what, obj);
            mDetectedRegistrants.add(r);
            notifyDetectedRegistrantsIfNeeded(r);
        }
    }

    public void unregisterForDetected(Handler h) {
        synchronized (mLock) {
            mDetectedRegistrants.remove(h);
        }
    }

    /**
     * Notifies handler of any transition into State.isPinLocked()
     */
@@ -506,6 +522,26 @@ public class UiccCardApplication {
        }
    }

    /**
     * Notifies specified registrant, assume mLock is held.
     *
     * @param r Registrant to be notified. If null - all registrants will be notified
     */
    private void notifyDetectedRegistrantsIfNeeded(Registrant r) {
        if (mDestroyed) {
            return;
        }
        if (mAppState == AppState.APPSTATE_DETECTED) {
            if (r == null) {
                if (DBG) log("Notifying registrants: DETECTED");
                mDetectedRegistrants.notifyRegistrants();
            } else {
                if (DBG) log("Notifying 1 registrant: DETECTED");
                r.notifyRegistrant(new AsyncResult(null, null, null));
            }
        }
    }

    /**
     * Notifies specified registrant, assume mLock is held.
     *
+28 −1
Original line number Diff line number Diff line
@@ -29,10 +29,16 @@

package com.android.internal.telephony.uicc;

import static com.android.internal.telephony.uicc.IccRecords.EVENT_APP_DETECTED;
import static com.android.internal.telephony.uicc.IccRecords.EVENT_APP_READY;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.isNull;
import static org.mockito.Mockito.verify;

import android.os.AsyncResult;
import android.os.HandlerThread;
@@ -68,6 +74,10 @@ public class IccRecordsTest extends TelephonyTest {
        super.setUp(this.getClass().getSimpleName());
        new IccRecordsTestHandler(TAG).start();
        waitUntilReady();
        verify(mUiccCardApplication3gpp).registerForReady(
                mIccRecords, EVENT_APP_READY, null);
        verify(mUiccCardApplication3gpp).registerForDetected(
                mIccRecords, EVENT_APP_DETECTED, null);
    }

    @After
@@ -168,6 +178,23 @@ public class IccRecordsTest extends TelephonyTest {
                timeSpent >= mSimulatedCommands.ICC_SIM_CHALLENGE_TIMEOUT_MILLIS);
    }

    @Test
    public void testAppStateChange() {
        assertFalse(mIccRecords.isLoaded());

        mIccRecords.obtainMessage(EVENT_APP_READY).sendToTarget();
        waitForLastHandlerAction(mIccRecords);
        assertTrue(mIccRecords.isLoaded());

        mIccRecords.obtainMessage(EVENT_APP_DETECTED).sendToTarget();
        waitForLastHandlerAction(mIccRecords);
        assertFalse(mIccRecords.isLoaded());

        mIccRecords.obtainMessage(EVENT_APP_READY).sendToTarget();
        waitForLastHandlerAction(mIccRecords);
        assertTrue(mIccRecords.isLoaded());
    }

    @Test
    public void testGetIccSimChallengeResponseDefault() {
        long startTime;
+35 −0
Original line number Diff line number Diff line
@@ -52,10 +52,13 @@ public class UiccCardApplicationTest extends TelephonyTest {
    private Handler mHandler;
    private int mAttemptsRemaining = -1;
    private CommandException mException = null;
    private IccCardApplicationStatus.AppState mAppState;
    private static final int UICCCARDAPP_ENABLE_FDN_EVENT = 1;
    private static final int UICCCARDAPP_ENABLE_LOCK_EVENT = 2;
    private static final int UICCCARDAPP_CHANGE_PSW_EVENT = 3;
    private static final int UICCCARDAPP_SUPPLY_PIN_EVENT = 4;
    private static final int EVENT_APP_STATE_DETECTED     = 5;
    private static final int EVENT_APP_STATE_READY        = 6;

    @Before
    public void setUp() throws Exception {
@@ -83,6 +86,12 @@ public class UiccCardApplicationTest extends TelephonyTest {
                            logd("remaining Attempt:" + mAttemptsRemaining);
                        }
                        break;
                    case EVENT_APP_STATE_DETECTED:
                        mAppState = IccCardApplicationStatus.AppState.APPSTATE_DETECTED;
                        break;
                    case EVENT_APP_STATE_READY:
                        mAppState = IccCardApplicationStatus.AppState.APPSTATE_READY;
                        break;
                    default:
                        logd("Unknown Event " + msg.what);
                }
@@ -192,4 +201,30 @@ public class UiccCardApplicationTest extends TelephonyTest {
        processAllMessages();
        assertEquals(-1, mAttemptsRemaining);
    }

    @Test
    @SmallTest
    public void testAppStateChangeNotification() {
        mUiccCardApplication.registerForDetected(mHandler, EVENT_APP_STATE_DETECTED, null);
        mUiccCardApplication.registerForReady(mHandler, EVENT_APP_STATE_READY, null);
        processAllMessages();
        assertEquals(null, mAppState);

        // Change to DETECTED state.
        mUiccCardAppStatus.app_state = IccCardApplicationStatus.AppState.APPSTATE_DETECTED;
        mUiccCardApplication.update(mUiccCardAppStatus, mContext, mSimulatedCommands);
        processAllMessages();
        assertEquals(IccCardApplicationStatus.AppState.APPSTATE_DETECTED, mAppState);
        assertEquals(IccCardApplicationStatus.AppState.APPSTATE_DETECTED,
                mUiccCardApplication.getState());

        // Change to READY state.
        mUiccCardAppStatus.app_state = IccCardApplicationStatus.AppState.APPSTATE_READY;
        mUiccCardAppStatus.pin1 = IccCardStatus.PinState.PINSTATE_ENABLED_VERIFIED;
        mUiccCardApplication.update(mUiccCardAppStatus, mContext, mSimulatedCommands);
        processAllMessages();
        assertEquals(IccCardApplicationStatus.AppState.APPSTATE_READY, mAppState);
        assertEquals(IccCardApplicationStatus.AppState.APPSTATE_READY,
                mUiccCardApplication.getState());
    }
}