Update comparison of new slot status with last status.

The old comparison was based on contains() which can be incorrect
if the new state of a slot is same as the existing state of one
of the other slots. contains() returns true in that case even
though the overall slot status has changed.

Test: atest UiccControllerTest
Bug: 195622658
Merged-In: I79bc992a8cd2336cd6f0c804dd3bde077ca53dd3
Change-Id: I79bc992a8cd2336cd6f0c804dd3bde077ca53dd3
(cherry picked from commit eb28a7169af0dcab4d4b19d6e22a6f9581a0befe)
diff --git a/src/java/com/android/internal/telephony/uicc/UiccController.java b/src/java/com/android/internal/telephony/uicc/UiccController.java
index 36cad5f..fb64b6a 100644
--- a/src/java/com/android/internal/telephony/uicc/UiccController.java
+++ b/src/java/com/android/internal/telephony/uicc/UiccController.java
@@ -1103,12 +1103,16 @@
                 options.toBundle());
     }
 
-    private boolean slotStatusChanged(ArrayList<IccSlotStatus> slotStatusList) {
+    /**
+     * Check if slot status has changed from the last received one
+     */
+    @VisibleForTesting
+    public boolean slotStatusChanged(ArrayList<IccSlotStatus> slotStatusList) {
         if (sLastSlotStatus == null || sLastSlotStatus.size() != slotStatusList.size()) {
             return true;
         }
-        for (IccSlotStatus iccSlotStatus : slotStatusList) {
-            if (!sLastSlotStatus.contains(iccSlotStatus)) {
+        for (int i = 0; i < slotStatusList.size(); i++) {
+            if (!sLastSlotStatus.get(i).equals(slotStatusList.get(i))) {
                 return true;
             }
         }
diff --git a/tests/telephonytests/src/com/android/internal/telephony/ContextFixture.java b/tests/telephonytests/src/com/android/internal/telephony/ContextFixture.java
index f04e69f..14f5aa1 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/ContextFixture.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/ContextFixture.java
@@ -424,6 +424,12 @@
         }
 
         @Override
+        public void sendBroadcast(Intent intent, String receiverPermission, Bundle initialExtras) {
+            logd("sendBroadcast called for " + intent.getAction());
+            sendBroadcast(intent);
+        }
+
+        @Override
         public void sendOrderedBroadcast(Intent intent, String receiverPermission) {
             logd("sendOrderedBroadcast called for " + intent.getAction());
             sendBroadcast(intent);
diff --git a/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccControllerTest.java b/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccControllerTest.java
index c9fccaf..a00e110 100644
--- a/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccControllerTest.java
+++ b/tests/telephonytests/src/com/android/internal/telephony/uicc/UiccControllerTest.java
@@ -18,6 +18,7 @@
 import static junit.framework.Assert.fail;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -634,4 +635,32 @@
         assertEquals(mUiccControllerUT.convertToPublicCardId(knownEidFromApdu),
                 mUiccControllerUT.getCardIdForDefaultEuicc());
     }
+
+    @Test
+    public void testSlotStatusChanged() {
+        // simulate slot status loaded so that the UiccController sets the last slot status
+        IccSlotStatus iss1 = new IccSlotStatus();
+        iss1.setSlotState(1 /* active */);
+        iss1.eid = "eid1";
+        IccSlotStatus iss2 = new IccSlotStatus();
+        iss2.setSlotState(1 /* active */);
+        iss2.eid = "eid2";
+        ArrayList<IccSlotStatus> status = new ArrayList<IccSlotStatus>();
+        status.add(iss1);
+        status.add(iss2);
+        AsyncResult ar = new AsyncResult(null, status, null);
+        Message msg = Message.obtain(mUiccControllerUT, EVENT_GET_SLOT_STATUS_DONE, ar);
+        mUiccControllerUT.handleMessage(msg);
+        processAllMessages();
+
+        assertFalse(mUiccControllerUT.slotStatusChanged(status));
+
+        // change the order of the IccSlotStatus in the list
+        status = new ArrayList<>();
+        status.add(iss2);
+        status.add(iss1);
+
+        // status should be treated different from last status
+        assertTrue(mUiccControllerUT.slotStatusChanged(status));
+    }
 }