Loading src/java/com/android/internal/telephony/uicc/PinStorage.java +6 −4 Original line number Diff line number Diff line Loading @@ -214,8 +214,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); Loading @@ -229,7 +231,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; Loading Loading @@ -929,7 +931,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() : ""; } Loading tests/telephonytests/src/com/android/internal/telephony/uicc/PinStorageTest.java +20 −20 Original line number Diff line number Diff line Loading @@ -106,7 +106,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(""); } Loading @@ -114,7 +114,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(); Loading @@ -124,7 +124,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); Loading @@ -136,7 +136,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading @@ -156,7 +156,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_ERROR); Loading @@ -170,7 +170,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading @@ -195,7 +195,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading @@ -211,7 +211,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading @@ -232,7 +232,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(); Loading @@ -246,8 +246,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading @@ -260,7 +260,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading @@ -273,7 +273,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading @@ -288,7 +288,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(); simulateReboot(); Loading @@ -302,7 +302,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading @@ -321,7 +321,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_PIN_REQUIRED); Loading @@ -339,7 +339,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading @@ -352,7 +352,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(); Loading @@ -375,7 +375,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); Loading @@ -395,7 +395,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading Loading
src/java/com/android/internal/telephony/uicc/PinStorage.java +6 −4 Original line number Diff line number Diff line Loading @@ -214,8 +214,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); Loading @@ -229,7 +231,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; Loading Loading @@ -929,7 +931,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() : ""; } Loading
tests/telephonytests/src/com/android/internal/telephony/uicc/PinStorageTest.java +20 −20 Original line number Diff line number Diff line Loading @@ -106,7 +106,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(""); } Loading @@ -114,7 +114,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(); Loading @@ -124,7 +124,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); Loading @@ -136,7 +136,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading @@ -156,7 +156,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_ERROR); Loading @@ -170,7 +170,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading @@ -195,7 +195,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading @@ -211,7 +211,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading @@ -232,7 +232,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(); Loading @@ -246,8 +246,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading @@ -260,7 +260,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading @@ -273,7 +273,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading @@ -288,7 +288,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(); simulateReboot(); Loading @@ -302,7 +302,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading @@ -321,7 +321,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_PIN_REQUIRED); Loading @@ -339,7 +339,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading @@ -352,7 +352,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(); Loading @@ -375,7 +375,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); Loading @@ -395,7 +395,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(); assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS); Loading