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

Commit 6ea08dd4 authored by Collin Fijalkovich's avatar Collin Fijalkovich Committed by Android (Google) Code Review
Browse files

Merge changes from topic "rvc-telephony-caching" into rvc-dev

* changes:
  Setup getSlotIndex cache invalidation.
  Setup getDefaultSmsSubscriptionId cache invalidation
  Setup getActiveDataSubscriptionId cache invalidation
parents 29e6226f 948d08b3
Loading
Loading
Loading
Loading
+21 −11
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import android.telephony.data.ApnSetting;
import android.util.LocalLog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.SubscriptionController.WatchedInt;
import com.android.internal.telephony.dataconnection.ApnConfigTypeRepository;
import com.android.internal.telephony.dataconnection.DcRequest;
import com.android.internal.telephony.metrics.TelephonyMetrics;
@@ -214,7 +215,14 @@ public class PhoneSwitcher extends Handler {
    protected int mPreferredDataPhoneId = SubscriptionManager.INVALID_PHONE_INDEX;

    // Subscription ID corresponds to mPreferredDataPhoneId.
    private int mPreferredDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
    private WatchedInt mPreferredDataSubId =
            new WatchedInt(SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
        @Override
        public void set(int newValue) {
            super.set(newValue);
            SubscriptionController.invalidateActiveDataSubIdCaches();
        }
    };

    // If non-null, An emergency call is about to be started, is ongoing, or has just ended and we
    // are overriding the DDS.
@@ -312,6 +320,7 @@ public class PhoneSwitcher extends Handler {
    public static PhoneSwitcher make(int maxDataAttachModemCount, Context context, Looper looper) {
        if (sPhoneSwitcher == null) {
            sPhoneSwitcher = new PhoneSwitcher(maxDataAttachModemCount, context, looper);
            SubscriptionController.invalidateActiveDataSubIdCaches();
        }

        return sPhoneSwitcher;
@@ -441,10 +450,10 @@ public class PhoneSwitcher extends Handler {
            }
            case EVENT_PRIMARY_DATA_SUB_CHANGED: {
                if (onEvaluate(REQUESTS_UNCHANGED, "primary data subId changed")) {
                    logDataSwitchEvent(mPreferredDataSubId,
                    logDataSwitchEvent(mPreferredDataSubId.get(),
                            TelephonyEvent.EventState.EVENT_STATE_START,
                            DataSwitch.Reason.DATA_SWITCH_REASON_MANUAL);
                    registerDefaultNetworkChangeCallback(mPreferredDataSubId,
                    registerDefaultNetworkChangeCallback(mPreferredDataSubId.get(),
                            DataSwitch.Reason.DATA_SWITCH_REASON_MANUAL);
                }
                break;
@@ -515,10 +524,10 @@ public class PhoneSwitcher extends Handler {
            // fall through
            case EVENT_DATA_ENABLED_CHANGED:
                if (onEvaluate(REQUESTS_UNCHANGED, "EVENT_PRECISE_CALL_STATE_CHANGED")) {
                    logDataSwitchEvent(mPreferredDataSubId,
                    logDataSwitchEvent(mPreferredDataSubId.get(),
                            TelephonyEvent.EventState.EVENT_STATE_START,
                            DataSwitch.Reason.DATA_SWITCH_REASON_IN_CALL);
                    registerDefaultNetworkChangeCallback(mPreferredDataSubId,
                    registerDefaultNetworkChangeCallback(mPreferredDataSubId.get(),
                            DataSwitch.Reason.DATA_SWITCH_REASON_IN_CALL);
                }
                break;
@@ -1083,7 +1092,8 @@ public class PhoneSwitcher extends Handler {
            mPreferredDataPhoneId = phoneId;
        }

        mPreferredDataSubId = mSubscriptionController.getSubIdUsingPhoneId(mPreferredDataPhoneId);
        mPreferredDataSubId.set(
                mSubscriptionController.getSubIdUsingPhoneId(mPreferredDataPhoneId));
    }

    private void transitionToEmergencyPhone() {
@@ -1097,8 +1107,8 @@ public class PhoneSwitcher extends Handler {
            mPreferredDataPhoneId = DEFAULT_EMERGENCY_PHONE_ID;
        }

        if (mPreferredDataSubId != INVALID_SUBSCRIPTION_ID) {
            mPreferredDataSubId = INVALID_SUBSCRIPTION_ID;
        if (mPreferredDataSubId.get() != INVALID_SUBSCRIPTION_ID) {
            mPreferredDataSubId.set(INVALID_SUBSCRIPTION_ID);
            notifyPreferredDataSubIdChanged();
        }
    }
@@ -1373,15 +1383,15 @@ public class PhoneSwitcher extends Handler {
    private void notifyPreferredDataSubIdChanged() {
        TelephonyRegistryManager telephonyRegistryManager = (TelephonyRegistryManager) mContext
                .getSystemService(Context.TELEPHONY_REGISTRY_SERVICE);
        log("notifyPreferredDataSubIdChanged to " + mPreferredDataSubId);
        telephonyRegistryManager.notifyActiveDataSubIdChanged(mPreferredDataSubId);
        log("notifyPreferredDataSubIdChanged to " + mPreferredDataSubId.get());
        telephonyRegistryManager.notifyActiveDataSubIdChanged(mPreferredDataSubId.get());
    }

    /**
     * @return The active data subscription id
     */
    public int getActiveDataSubId() {
        return mPreferredDataSubId;
        return mPreferredDataSubId.get();
    }

    // TODO (b/148396668): add an internal callback method to monitor phone capability change,
+51 −4
Original line number Diff line number Diff line
@@ -164,6 +164,7 @@ public class SubscriptionController extends ISub.Stub {
        public void clear() {
            mSlotIndexToSubIds.clear();
            invalidateDefaultSubIdCaches();
            invalidateSlotIndexCaches();
        }

        public Set<Entry<Integer, ArrayList<Integer>>> entrySet() {
@@ -183,11 +184,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() {
@@ -210,6 +213,7 @@ public class SubscriptionController extends ISub.Stub {
                        mSlotIndexToSubIds.remove(slotIndex);
                    }
                    invalidateDefaultSubIdCaches();
                    invalidateSlotIndexCaches();
                    return SUB_ID_FOUND;
                } else {
                    return SUB_ID_NOT_IN_SLOT;
@@ -227,6 +231,7 @@ public class SubscriptionController extends ISub.Stub {
                subIdList.add(value);
            }
            invalidateDefaultSubIdCaches();
            invalidateSlotIndexCaches();
        }

        public void clearSubIdList(int slotIndex) {
@@ -234,6 +239,7 @@ public class SubscriptionController extends ISub.Stub {
            if (subIdList != null) {
                subIdList.clear();
                invalidateDefaultSubIdCaches();
                invalidateSlotIndexCaches();
            }
        }
    }
@@ -251,13 +257,20 @@ public class SubscriptionController extends ISub.Stub {

        public void set(int newValue) {
            mValue = newValue;
            invalidateDefaultSubIdCaches();
        }
    }

    private static WatchedSlotIndexToSubIds sSlotIndexToSubIds = new WatchedSlotIndexToSubIds();

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

    @UnsupportedAppUsage
    private static int mDefaultPhoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
@@ -336,6 +349,9 @@ public class SubscriptionController extends ISub.Stub {
        // Initial invalidate activates caching.
        invalidateDefaultSubIdCaches();
        invalidateDefaultDataSubIdCaches();
        invalidateDefaultSmsSubIdCaches();
        invalidateActiveDataSubIdCaches();
        invalidateSlotIndexCaches();

        if (DBG) logdl("[SubscriptionController] init by Context");
    }
@@ -4089,9 +4105,14 @@ public class SubscriptionController extends ISub.Stub {
        Settings.Global.putInt(mContext.getContentResolver(), name, value);
        if (name == Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION) {
            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();
        }
    }

@@ -4113,6 +4134,33 @@ public class SubscriptionController extends ISub.Stub {
        }
    }

    /**
     * @hide
     */
    private static void invalidateDefaultSmsSubIdCaches() {
        if (sCachingEnabled) {
            SubscriptionManager.invalidateDefaultSmsSubIdCaches();
        }
    }

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

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

    /**
     * @hide
     */
@@ -4124,9 +4172,8 @@ public class SubscriptionController extends ISub.Stub {
    /**
     * @hide
     */
    @VisibleForTesting
    public static void enableCaching() {
        sCachingEnabled = true;
    }


}
+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));