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

Commit 948d08b3 authored by Collin Fijalkovich's avatar Collin Fijalkovich
Browse files

Setup getSlotIndex cache invalidation.

Instrument SubscriptionController to invalidate client-side caches when
appropriate.
Bug: 151953109
Test: atest SubscriptionControllerTest
Test: atest android.telephony.cts.SubscriptionManagerTest

Change-Id: Id4b8cede1180fa427e6623e45fcb4b0bf3e4f197
parent 6d6f78ab
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -162,6 +162,7 @@ public class SubscriptionController extends ISub.Stub {
        public void clear() {
            mSlotIndexToSubIds.clear();
            invalidateDefaultSubIdCaches();
            invalidateSlotIndexCaches();
        }

        public Set<Entry<Integer, ArrayList<Integer>>> entrySet() {
@@ -181,11 +182,13 @@ public class SubscriptionController extends ISub.Stub {
        public void put(int slotIndex, ArrayList<Integer> value) {
            mSlotIndexToSubIds.put(slotIndex, value);
            invalidateDefaultSubIdCaches();
            invalidateSlotIndexCaches();
        }

        public void remove(int slotIndex) {
            mSlotIndexToSubIds.remove(slotIndex);
            invalidateDefaultSubIdCaches();
            invalidateSlotIndexCaches();
        }

        public int size() {
@@ -208,6 +211,7 @@ public class SubscriptionController extends ISub.Stub {
                        mSlotIndexToSubIds.remove(slotIndex);
                    }
                    invalidateDefaultSubIdCaches();
                    invalidateSlotIndexCaches();
                    return SUB_ID_FOUND;
                } else {
                    return SUB_ID_NOT_IN_SLOT;
@@ -225,6 +229,7 @@ public class SubscriptionController extends ISub.Stub {
                subIdList.add(value);
            }
            invalidateDefaultSubIdCaches();
            invalidateSlotIndexCaches();
        }

        public void clearSubIdList(int slotIndex) {
@@ -232,6 +237,7 @@ public class SubscriptionController extends ISub.Stub {
            if (subIdList != null) {
                subIdList.clear();
                invalidateDefaultSubIdCaches();
                invalidateSlotIndexCaches();
            }
        }
    }
@@ -253,12 +259,14 @@ public class SubscriptionController extends ISub.Stub {
    }

    private static WatchedSlotIndexToSubIds sSlotIndexToSubIds = new WatchedSlotIndexToSubIds();

    protected static WatchedInt sDefaultFallbackSubId =
            new WatchedInt(SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
        @Override
        public void set(int newValue) {
            super.set(newValue);
            invalidateDefaultSubIdCaches();
            invalidateSlotIndexCaches();
        }
    };

@@ -340,6 +348,7 @@ public class SubscriptionController extends ISub.Stub {
        invalidateDefaultDataSubIdCaches();
        invalidateDefaultSmsSubIdCaches();
        invalidateActiveDataSubIdCaches();
        invalidateSlotIndexCaches();

        if (DBG) logdl("[SubscriptionController] init by Context");
    }
@@ -4069,8 +4078,10 @@ public class SubscriptionController extends ISub.Stub {
            invalidateDefaultDataSubIdCaches();
            invalidateActiveDataSubIdCaches();
            invalidateDefaultSubIdCaches();
            invalidateSlotIndexCaches();
        } else if (name == Settings.Global.MULTI_SIM_VOICE_CALL_SUBSCRIPTION) {
            invalidateDefaultSubIdCaches();
            invalidateSlotIndexCaches();
        } else if (name == Settings.Global.MULTI_SIM_SMS_SUBSCRIPTION) {
            invalidateDefaultSmsSubIdCaches();
        }
@@ -4112,6 +4123,15 @@ public class SubscriptionController extends ISub.Stub {
        }
    }

    /**
     * @hide
     */
    protected static void invalidateSlotIndexCaches() {
        if (sCachingEnabled) {
            SubscriptionManager.invalidateSlotIndexCaches();
        }
    }

    /**
     * @hide
     */
+2 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;

import android.app.AppOpsManager;
import android.app.PropertyInvalidatedCache;
import android.content.Context;
import android.os.Build;
import android.test.suitebuilder.annotation.SmallTest;
@@ -51,6 +52,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest {
    @Before
    public void setUp() throws Exception {
        super.setUp(getClass().getSimpleName());
        PropertyInvalidatedCache.disableForTestMode();
        /* mPhone -> PhoneId: 0 -> SubId:0
           mSecondPhone -> PhoneId:1 -> SubId: 1*/
        doReturn(0).when(mSubscriptionController).getPhoneId(eq(0));