Merge "Add locallog to reveal the binding flakiness in CarrierServiceBindHelper"
diff --git a/src/java/com/android/internal/telephony/uicc/PinStorage.java b/src/java/com/android/internal/telephony/uicc/PinStorage.java
index 2885124..bad2d95 100644
--- a/src/java/com/android/internal/telephony/uicc/PinStorage.java
+++ b/src/java/com/android/internal/telephony/uicc/PinStorage.java
@@ -214,10 +214,8 @@
     }
 
     /** Store the {@code pin} for the {@code slotId}. */
-    public synchronized void storePin(String pin, int slotId) {
-        String iccid = getIccid(slotId);
-
-        if (!validatePin(pin) || !validateIccid(iccid) || !validateSlotId(slotId)) {
+    public synchronized void storePin(String pin, int slotId, String iccId) {
+        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);
@@ -231,7 +229,7 @@
         logd("storePin[%d]", slotId);
 
         StoredPin storedPin = new StoredPin();
-        storedPin.iccid = iccid;
+        storedPin.iccid = iccId;
         storedPin.pin = pin;
         storedPin.slotId = slotId;
         storedPin.status = PinStatus.AVAILABLE;
@@ -931,7 +929,7 @@
     }
 
     /** Returns the ICCID of the SIM card for the given {@code slotId}. */
-    private String getIccid(int slotId) {
+    public String getIccid(int slotId) {
         Phone phone = PhoneFactory.getPhone(slotId);
         return phone != null ? phone.getFullIccSerialNumber() : "";
     }
diff --git a/tests/telephonytests/src/com/android/internal/telephony/uicc/PinStorageTest.java b/tests/telephonytests/src/com/android/internal/telephony/uicc/PinStorageTest.java
index a26c0f9..f0dee2b 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/uicc/PinStorageTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/uicc/PinStorageTest.java
@@ -106,7 +106,7 @@
     @Test
     @SmallTest
     public void storePin_withoutReboot_pinCannotBeRetrieved() {
-        mPinStorage.storePin("1234", 0);
+        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
 
         assertThat(mPinStorage.getPin(0, ICCID_1)).isEqualTo("");
     }
@@ -114,7 +114,7 @@
     @Test
     @SmallTest
     public void storePin_normalReboot_pinCannotBeRetrieved() {
-        mPinStorage.storePin("1234", 0);
+        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
 
         simulateReboot();
 
@@ -124,7 +124,7 @@
     @Test
     @SmallTest
     public void storePin_crash_pinCannotBeRetrieved() {
-        mPinStorage.storePin("1234", 0);
+        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
 
         // Simulate crash
         mPinStorage = new PinStorage(mContext);
@@ -136,7 +136,7 @@
     @Test
     @SmallTest
     public void storePin_unattendedReboot_pinCanBeRetrievedOnce() {
-        mPinStorage.storePin("1234", 0);
+        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
 
         int result = mPinStorage.prepareUnattendedReboot();
         assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);
@@ -156,7 +156,7 @@
         when(mKeyguardManager.isDeviceLocked()).thenReturn(true);
         simulateReboot();
 
-        mPinStorage.storePin("1234", 0);
+        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
 
         int result = mPinStorage.prepareUnattendedReboot();
         assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_ERROR);
@@ -170,7 +170,7 @@
     @Test
     @SmallTest
     public void storePin_unattendedReboot_pinIsRemovedAfterDelay() {
-        mPinStorage.storePin("1234", 0);
+        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
 
         int result = mPinStorage.prepareUnattendedReboot();
         assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);
@@ -195,7 +195,7 @@
     @Test
     @SmallTest
     public void storePin_unattendedRebootNotDone_pinCannotBeRetrieved() {
-        mPinStorage.storePin("1234", 0);
+        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
 
         int result = mPinStorage.prepareUnattendedReboot();
         assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);
@@ -211,7 +211,7 @@
     @Test
     @SmallTest
     public void storePin_unattendedReboot_iccidChange() {
-        mPinStorage.storePin("1234", 0);
+        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
 
         int result = mPinStorage.prepareUnattendedReboot();
         assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);
@@ -232,7 +232,7 @@
     @Test
     @SmallTest
     public void clearPin_pinCannotBeRetrieved() {
-        mPinStorage.storePin("1234", 0);
+        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
         mPinStorage.clearPin(0);
 
         int result = mPinStorage.prepareUnattendedReboot();
@@ -246,8 +246,8 @@
     @Test
     @SmallTest
     public void storePin_pinChanged_pinIsUpdated() {
-        mPinStorage.storePin("1234", 0);
-        mPinStorage.storePin("5678", 0);
+        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
+        mPinStorage.storePin("5678", 0, mPinStorage.getIccid(0));
 
         int result = mPinStorage.prepareUnattendedReboot();
         assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);
@@ -260,7 +260,7 @@
     @Test
     @SmallTest
     public void storePin_pinTooShort_pinIsNotStored() {
-        mPinStorage.storePin("12", 0);
+        mPinStorage.storePin("12", 0, mPinStorage.getIccid(0));
 
         int result = mPinStorage.prepareUnattendedReboot();
         assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);
@@ -273,7 +273,7 @@
     @Test
     @SmallTest
     public void storePin_pinTooLong_pinIsNotStored() {
-        mPinStorage.storePin("123456789", 0);
+        mPinStorage.storePin("123456789", 0, mPinStorage.getIccid(0));
 
         int result = mPinStorage.prepareUnattendedReboot();
         assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);
@@ -288,7 +288,7 @@
     public void storePin_invalidIccid_pinIsNotStored() {
         doReturn(ICCID_INVALID).when(mPhone).getFullIccSerialNumber();
 
-        mPinStorage.storePin("1234", 0);
+        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
         int result = mPinStorage.prepareUnattendedReboot();
 
         simulateReboot();
@@ -302,7 +302,7 @@
         mContextFixture.putBooleanResource(
                 R.bool.config_allow_pin_storage_for_unattended_reboot, false);
 
-        mPinStorage.storePin("1234", 0);
+        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
 
         int result = mPinStorage.prepareUnattendedReboot();
         assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);
@@ -321,7 +321,7 @@
         when(mUiccController.getUiccProfileForPhone(anyInt())).thenReturn(mUiccProfile);
         when(mUiccCardApplication3gpp.getPin1State()).thenReturn(PINSTATE_ENABLED_VERIFIED);
 
-        mPinStorage.storePin("1234", 0);
+        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
 
         int result = mPinStorage.prepareUnattendedReboot();
         assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_PIN_REQUIRED);
@@ -339,7 +339,7 @@
                 CarrierConfigManager.KEY_STORE_SIM_PIN_FOR_UNATTENDED_REBOOT_BOOL, false);
         when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(carrierConfigs);
 
-        mPinStorage.storePin("1234", 0);
+        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
 
         int result = mPinStorage.prepareUnattendedReboot();
         assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);
@@ -352,7 +352,7 @@
     @Test
     @SmallTest
     public void storePin_changeToDisabledInCarrierConfig_pinIsRemoved() {
-        mPinStorage.storePin("1234", 0);
+        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
 
         // Simulate change in the carrier configuration
         PersistableBundle carrierConfigs = new PersistableBundle();
@@ -375,7 +375,7 @@
     @Test
     @SmallTest
     public void storePin_simIsRemoved_pinIsRemoved() {
-        mPinStorage.storePin("1234", 0);
+        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
 
         // SIM is removed
         final Intent intent = new Intent(TelephonyManager.ACTION_SIM_CARD_STATE_CHANGED);
@@ -395,7 +395,7 @@
     @Test
     @SmallTest
     public void storePin_simReadyAfterUnattendedReboot_pinIsRemoved() {
-        mPinStorage.storePin("1234", 0);
+        mPinStorage.storePin("1234", 0, mPinStorage.getIccid(0));
 
         int result = mPinStorage.prepareUnattendedReboot();
         assertThat(result).isEqualTo(TelephonyManager.PREPARE_UNATTENDED_REBOOT_SUCCESS);