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

Commit 291b68aa authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Revert "Refactor PinStorage#storePin to avoid dead lock when unl...""

parents e7cdc84b 02ab1419
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -215,8 +215,10 @@ public class PinStorage extends Handler {
    }

    /** Store the {@code pin} for the {@code slotId}. */
    public synchronized void storePin(String pin, int slotId, String iccId) {
        if (!validatePin(pin) || !validateIccid(iccId) || !validateSlotId(slotId)) {
    public synchronized void storePin(String pin, int slotId) {
        String iccid = getIccid(slotId);

        if (!validatePin(pin) || !validateIccid(iccid) || !validateSlotId(slotId)) {
            // We are unable to store the PIN. At least clear the old one, if present.
            loge("storePin[%d] - Invalid PIN, slotId or ICCID", slotId);
            clearPin(slotId);
@@ -230,7 +232,7 @@ public class PinStorage extends Handler {
        logd("storePin[%d]", slotId);

        StoredPin storedPin = new StoredPin();
        storedPin.iccid = iccId;
        storedPin.iccid = iccid;
        storedPin.pin = pin;
        storedPin.slotId = slotId;
        storedPin.status = PinStatus.AVAILABLE;
@@ -935,7 +937,7 @@ public class PinStorage extends Handler {
    }

    /** Returns the ICCID of the SIM card for the given {@code slotId}. */
    public String getIccid(int slotId) {
    private String getIccid(int slotId) {
        Phone phone = PhoneFactory.getPhone(slotId);
        return phone != null ? phone.getFullIccSerialNumber() : "";
    }
+20 −20
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ public class PinStorageTest extends TelephonyTest {
    @Test
    @SmallTest
    public void storePin_withoutReboot_pinCannotBeRetrieved() {
        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("1234", 0);

        assertThat(mPinStorage.getPin(0, ICCID_1)).isEqualTo("");
    }
@@ -118,7 +118,7 @@ public class PinStorageTest extends TelephonyTest {
    @Test
    @SmallTest
    public void storePin_normalReboot_pinCannotBeRetrieved() {
        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("1234", 0);

        simulateReboot();

@@ -128,7 +128,7 @@ public class PinStorageTest extends TelephonyTest {
    @Test
    @SmallTest
    public void storePin_crash_pinCannotBeRetrieved() {
        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("1234", 0);

        // Simulate crash
        mPinStorage = new PinStorage(mContext);
@@ -140,7 +140,7 @@ public class PinStorageTest extends TelephonyTest {
    @Test
    @SmallTest
    public void storePin_unattendedReboot_pinCanBeRetrievedOnce() {
        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("1234", 0);

        int result = mPinStorage.prepareUnattendedReboot(sWorkSource);
        assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);
@@ -160,7 +160,7 @@ public class PinStorageTest extends TelephonyTest {
        when(mKeyguardManager.isDeviceLocked()).thenReturn(true);
        simulateReboot();

        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("1234", 0);

        int result = mPinStorage.prepareUnattendedReboot(sWorkSource);
        assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_ERROR);
@@ -174,7 +174,7 @@ public class PinStorageTest extends TelephonyTest {
    @Test
    @SmallTest
    public void storePin_unattendedReboot_pinIsRemovedAfterDelay() {
        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("1234", 0);

        int result = mPinStorage.prepareUnattendedReboot(sWorkSource);
        assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);
@@ -199,7 +199,7 @@ public class PinStorageTest extends TelephonyTest {
    @Test
    @SmallTest
    public void storePin_unattendedRebootNotDone_pinCannotBeRetrieved() {
        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("1234", 0);

        int result = mPinStorage.prepareUnattendedReboot(sWorkSource);
        assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);
@@ -215,7 +215,7 @@ public class PinStorageTest extends TelephonyTest {
    @Test
    @SmallTest
    public void storePin_unattendedReboot_iccidChange() {
        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("1234", 0);

        int result = mPinStorage.prepareUnattendedReboot(sWorkSource);
        assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);
@@ -236,7 +236,7 @@ public class PinStorageTest extends TelephonyTest {
    @Test
    @SmallTest
    public void clearPin_pinCannotBeRetrieved() {
        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("1234", 0);
        mPinStorage.clearPin(0);

        int result = mPinStorage.prepareUnattendedReboot(sWorkSource);
@@ -250,8 +250,8 @@ public class PinStorageTest extends TelephonyTest {
    @Test
    @SmallTest
    public void storePin_pinChanged_pinIsUpdated() {
        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("5678", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("1234", 0);
        mPinStorage.storePin("5678", 0);

        int result = mPinStorage.prepareUnattendedReboot(sWorkSource);
        assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);
@@ -264,7 +264,7 @@ public class PinStorageTest extends TelephonyTest {
    @Test
    @SmallTest
    public void storePin_pinTooShort_pinIsNotStored() {
        mPinStorage.storePin("12", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("12", 0);

        int result = mPinStorage.prepareUnattendedReboot(sWorkSource);
        assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);
@@ -277,7 +277,7 @@ public class PinStorageTest extends TelephonyTest {
    @Test
    @SmallTest
    public void storePin_pinTooLong_pinIsNotStored() {
        mPinStorage.storePin("123456789", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("123456789", 0);

        int result = mPinStorage.prepareUnattendedReboot(sWorkSource);
        assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);
@@ -292,7 +292,7 @@ public class PinStorageTest extends TelephonyTest {
    public void storePin_invalidIccid_pinIsNotStored() {
        doReturn(ICCID_INVALID).when(mPhone).getFullIccSerialNumber();

        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("1234", 0);
        int result = mPinStorage.prepareUnattendedReboot(sWorkSource);

        simulateReboot();
@@ -306,7 +306,7 @@ public class PinStorageTest extends TelephonyTest {
        mContextFixture.putBooleanResource(
                R.bool.config_allow_pin_storage_for_unattended_reboot, false);

        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("1234", 0);

        int result = mPinStorage.prepareUnattendedReboot(sWorkSource);
        assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);
@@ -325,7 +325,7 @@ public class PinStorageTest extends TelephonyTest {
        when(mUiccController.getUiccProfileForPhone(anyInt())).thenReturn(mUiccProfile);
        when(mUiccCardApplication3gpp.getPin1State()).thenReturn(PINSTATE_ENABLED_VERIFIED);

        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("1234", 0);

        int result = mPinStorage.prepareUnattendedReboot(sWorkSource);
        assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_PIN_REQUIRED);
@@ -343,7 +343,7 @@ public class PinStorageTest extends TelephonyTest {
                CarrierConfigManager.KEY_STORE_SIM_PIN_FOR_UNATTENDED_REBOOT_BOOL, false);
        when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(carrierConfigs);

        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("1234", 0);

        int result = mPinStorage.prepareUnattendedReboot(sWorkSource);
        assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);
@@ -356,7 +356,7 @@ public class PinStorageTest extends TelephonyTest {
    @Test
    @SmallTest
    public void storePin_changeToDisabledInCarrierConfig_pinIsRemoved() {
        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("1234", 0);

        // Simulate change in the carrier configuration
        PersistableBundle carrierConfigs = new PersistableBundle();
@@ -379,7 +379,7 @@ public class PinStorageTest extends TelephonyTest {
    @Test
    @SmallTest
    public void storePin_simIsRemoved_pinIsRemoved() {
        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("1234", 0);

        // SIM is removed
        final Intent intent = new Intent(TelephonyManager.ACTION_SIM_CARD_STATE_CHANGED);
@@ -399,7 +399,7 @@ public class PinStorageTest extends TelephonyTest {
    @Test
    @SmallTest
    public void storePin_simReadyAfterUnattendedReboot_pinIsRemoved() {
        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
        mPinStorage.storePin("1234", 0);

        int result = mPinStorage.prepareUnattendedReboot(sWorkSource);
        assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);