Update TelephonySubscriptionTracker with new CarrierConfigManager APIs
- Replace CarrierConfigChange receiver with listener - Get subset of carrier configs with new API instead of private method Bug: 265961787 Test: atest TelephonySubscriptionTrackerTest Change-Id: I93f14421624ac76bdf84c06cfd4c067bf2ccde7a
This commit is contained in:
@@ -16,9 +16,6 @@
|
||||
|
||||
package com.android.server.vcn;
|
||||
|
||||
import static android.telephony.CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED;
|
||||
import static android.telephony.CarrierConfigManager.EXTRA_SLOT_INDEX;
|
||||
import static android.telephony.CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX;
|
||||
import static android.telephony.SubscriptionManager.INVALID_SIM_SLOT_INDEX;
|
||||
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
import static android.telephony.TelephonyManager.ACTION_MULTI_SIM_CONFIG_CHANGED;
|
||||
@@ -48,7 +45,6 @@ import android.util.Slog;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.annotations.VisibleForTesting.Visibility;
|
||||
import com.android.internal.util.IndentingPrintWriter;
|
||||
import com.android.server.vcn.util.PersistableBundleUtils;
|
||||
import com.android.server.vcn.util.PersistableBundleUtils.PersistableBundleWrapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -109,6 +105,12 @@ public class TelephonySubscriptionTracker extends BroadcastReceiver {
|
||||
|
||||
@NonNull private TelephonySubscriptionSnapshot mCurrentSnapshot;
|
||||
|
||||
@NonNull
|
||||
private final CarrierConfigManager.CarrierConfigChangeListener mCarrierConfigChangeListener =
|
||||
(int logicalSlotIndex, int subscriptionId, int carrierId, int specificCarrierId) ->
|
||||
handleActionCarrierConfigChanged(logicalSlotIndex, subscriptionId);
|
||||
|
||||
|
||||
public TelephonySubscriptionTracker(
|
||||
@NonNull Context context,
|
||||
@NonNull Handler handler,
|
||||
@@ -149,13 +151,14 @@ public class TelephonySubscriptionTracker extends BroadcastReceiver {
|
||||
public void register() {
|
||||
final HandlerExecutor executor = new HandlerExecutor(mHandler);
|
||||
final IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ACTION_CARRIER_CONFIG_CHANGED);
|
||||
filter.addAction(ACTION_MULTI_SIM_CONFIG_CHANGED);
|
||||
|
||||
mContext.registerReceiver(this, filter, null, mHandler);
|
||||
mSubscriptionManager.addOnSubscriptionsChangedListener(
|
||||
executor, mSubscriptionChangedListener);
|
||||
mTelephonyManager.registerTelephonyCallback(executor, mActiveDataSubIdListener);
|
||||
mCarrierConfigManager.registerCarrierConfigChangeListener(executor,
|
||||
mCarrierConfigChangeListener);
|
||||
|
||||
registerCarrierPrivilegesCallbacks();
|
||||
}
|
||||
@@ -197,6 +200,7 @@ public class TelephonySubscriptionTracker extends BroadcastReceiver {
|
||||
mContext.unregisterReceiver(this);
|
||||
mSubscriptionManager.removeOnSubscriptionsChangedListener(mSubscriptionChangedListener);
|
||||
mTelephonyManager.unregisterTelephonyCallback(mActiveDataSubIdListener);
|
||||
mCarrierConfigManager.unregisterCarrierConfigChangeListener(mCarrierConfigChangeListener);
|
||||
|
||||
unregisterCarrierPrivilegesCallbacks();
|
||||
}
|
||||
@@ -273,7 +277,7 @@ public class TelephonySubscriptionTracker extends BroadcastReceiver {
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast receiver for ACTION_CARRIER_CONFIG_CHANGED
|
||||
* Broadcast receiver for ACTION_MULTI_SIM_CONFIG_CHANGED
|
||||
*
|
||||
* <p>The broadcast receiver is registered with mHandler, so callbacks & broadcasts are all
|
||||
* serialized on mHandler, avoiding the need for locking.
|
||||
@@ -281,9 +285,6 @@ public class TelephonySubscriptionTracker extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
switch (intent.getAction()) {
|
||||
case ACTION_CARRIER_CONFIG_CHANGED:
|
||||
handleActionCarrierConfigChanged(context, intent);
|
||||
break;
|
||||
case ACTION_MULTI_SIM_CONFIG_CHANGED:
|
||||
handleActionMultiSimConfigChanged(context, intent);
|
||||
break;
|
||||
@@ -310,26 +311,21 @@ public class TelephonySubscriptionTracker extends BroadcastReceiver {
|
||||
handleSubscriptionsChanged();
|
||||
}
|
||||
|
||||
private void handleActionCarrierConfigChanged(Context context, Intent intent) {
|
||||
// Accept sticky broadcasts; if CARRIER_CONFIG_CHANGED was previously broadcast and it
|
||||
// already was for an identified carrier, we can stop waiting for initial load to complete
|
||||
final int subId = intent.getIntExtra(EXTRA_SUBSCRIPTION_INDEX, INVALID_SUBSCRIPTION_ID);
|
||||
final int slotId = intent.getIntExtra(EXTRA_SLOT_INDEX, INVALID_SIM_SLOT_INDEX);
|
||||
|
||||
private void handleActionCarrierConfigChanged(int slotId, int subId) {
|
||||
if (slotId == INVALID_SIM_SLOT_INDEX) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SubscriptionManager.isValidSubscriptionId(subId)) {
|
||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
|
||||
// Get only configs as needed to save memory.
|
||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId,
|
||||
VcnManager.VCN_RELATED_CARRIER_CONFIG_KEYS);
|
||||
if (mDeps.isConfigForIdentifiedCarrier(carrierConfig)) {
|
||||
mReadySubIdsBySlotId.put(slotId, subId);
|
||||
|
||||
final PersistableBundle minimized =
|
||||
PersistableBundleUtils.minimizeBundle(
|
||||
carrierConfig, VcnManager.VCN_RELATED_CARRIER_CONFIG_KEYS);
|
||||
if (minimized != null) {
|
||||
mSubIdToCarrierConfigMap.put(subId, new PersistableBundleWrapper(minimized));
|
||||
if (!carrierConfig.isEmpty()) {
|
||||
mSubIdToCarrierConfigMap.put(subId,
|
||||
new PersistableBundleWrapper(carrierConfig));
|
||||
}
|
||||
handleSubscriptionsChanged();
|
||||
}
|
||||
|
||||
@@ -19,9 +19,6 @@ package com.android.server.vcn;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
|
||||
import static android.net.vcn.VcnManager.VCN_RESTRICTED_TRANSPORTS_INT_ARRAY_KEY;
|
||||
import static android.telephony.CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED;
|
||||
import static android.telephony.CarrierConfigManager.EXTRA_SLOT_INDEX;
|
||||
import static android.telephony.CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX;
|
||||
import static android.telephony.SubscriptionManager.INVALID_SIM_SLOT_INDEX;
|
||||
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
import static android.telephony.TelephonyCallback.ActiveDataSubscriptionIdListener;
|
||||
@@ -143,6 +140,8 @@ public class TelephonySubscriptionTrackerTest {
|
||||
@NonNull private TelephonySubscriptionTrackerCallback mCallback;
|
||||
@NonNull private TelephonySubscriptionTracker mTelephonySubscriptionTracker;
|
||||
|
||||
@NonNull private CarrierConfigManager.CarrierConfigChangeListener mCarrierConfigChangeListener;
|
||||
|
||||
public TelephonySubscriptionTrackerTest() {
|
||||
mContext = mock(Context.class);
|
||||
mTestLooper = new TestLooper();
|
||||
@@ -173,7 +172,7 @@ public class TelephonySubscriptionTrackerTest {
|
||||
.getSystemService(Context.CARRIER_CONFIG_SERVICE);
|
||||
doReturn(TEST_CARRIER_CONFIG)
|
||||
.when(mCarrierConfigManager)
|
||||
.getConfigForSubId(eq(TEST_SUBSCRIPTION_ID_1));
|
||||
.getConfigForSubId(eq(TEST_SUBSCRIPTION_ID_1), any());
|
||||
|
||||
// subId 1, 2 are in same subGrp, only subId 1 is active
|
||||
doReturn(TEST_PARCEL_UUID).when(TEST_SUBINFO_1).getGroupUuid();
|
||||
@@ -189,9 +188,15 @@ public class TelephonySubscriptionTrackerTest {
|
||||
doReturn(2).when(mTelephonyManager).getActiveModemCount();
|
||||
|
||||
mCallback = mock(TelephonySubscriptionTrackerCallback.class);
|
||||
// Capture CarrierConfigChangeListener to emulate the carrier config change notification
|
||||
ArgumentCaptor<CarrierConfigManager.CarrierConfigChangeListener> listenerArgumentCaptor =
|
||||
ArgumentCaptor.forClass(CarrierConfigManager.CarrierConfigChangeListener.class);
|
||||
mTelephonySubscriptionTracker =
|
||||
new TelephonySubscriptionTracker(mContext, mHandler, mCallback, mDeps);
|
||||
mTelephonySubscriptionTracker.register();
|
||||
verify(mCarrierConfigManager).registerCarrierConfigChangeListener(any(),
|
||||
listenerArgumentCaptor.capture());
|
||||
mCarrierConfigChangeListener = listenerArgumentCaptor.getAllValues().get(0);
|
||||
|
||||
doReturn(true).when(mDeps).isConfigForIdentifiedCarrier(any());
|
||||
doReturn(Arrays.asList(TEST_SUBINFO_1, TEST_SUBINFO_2))
|
||||
@@ -239,14 +244,11 @@ public class TelephonySubscriptionTrackerTest {
|
||||
return intent;
|
||||
}
|
||||
|
||||
private Intent buildTestBroadcastIntent(boolean hasValidSubscription) {
|
||||
Intent intent = new Intent(ACTION_CARRIER_CONFIG_CHANGED);
|
||||
intent.putExtra(EXTRA_SLOT_INDEX, TEST_SIM_SLOT_INDEX);
|
||||
intent.putExtra(
|
||||
EXTRA_SUBSCRIPTION_INDEX,
|
||||
hasValidSubscription ? TEST_SUBSCRIPTION_ID_1 : INVALID_SUBSCRIPTION_ID);
|
||||
|
||||
return intent;
|
||||
private void sendCarrierConfigChange(boolean hasValidSubscription) {
|
||||
mCarrierConfigChangeListener.onCarrierConfigChanged(
|
||||
TEST_SIM_SLOT_INDEX,
|
||||
hasValidSubscription ? TEST_SUBSCRIPTION_ID_1 : INVALID_SUBSCRIPTION_ID,
|
||||
TelephonyManager.UNKNOWN_CARRIER_ID, TelephonyManager.UNKNOWN_CARRIER_ID);
|
||||
}
|
||||
|
||||
private TelephonySubscriptionSnapshot buildExpectedSnapshot(
|
||||
@@ -302,14 +304,15 @@ public class TelephonySubscriptionTrackerTest {
|
||||
any(),
|
||||
eq(mHandler));
|
||||
final IntentFilter filter = getIntentFilter();
|
||||
assertEquals(2, filter.countActions());
|
||||
assertTrue(filter.hasAction(ACTION_CARRIER_CONFIG_CHANGED));
|
||||
assertEquals(1, filter.countActions());
|
||||
assertTrue(filter.hasAction(ACTION_MULTI_SIM_CONFIG_CHANGED));
|
||||
|
||||
verify(mSubscriptionManager)
|
||||
.addOnSubscriptionsChangedListener(any(HandlerExecutor.class), any());
|
||||
assertNotNull(getOnSubscriptionsChangedListener());
|
||||
|
||||
verify(mCarrierConfigManager).registerCarrierConfigChangeListener(any(), any());
|
||||
|
||||
verify(mTelephonyManager, times(2))
|
||||
.registerCarrierPrivilegesCallback(anyInt(), any(HandlerExecutor.class), any());
|
||||
verify(mTelephonyManager)
|
||||
@@ -442,7 +445,7 @@ public class TelephonySubscriptionTrackerTest {
|
||||
|
||||
@Test
|
||||
public void testReceiveBroadcast_ConfigReadyWithSubscriptions() throws Exception {
|
||||
mTelephonySubscriptionTracker.onReceive(mContext, buildTestBroadcastIntent(true));
|
||||
sendCarrierConfigChange(true /* hasValidSubscription */);
|
||||
mTestLooper.dispatchAll();
|
||||
|
||||
verify(mCallback).onNewSnapshot(eq(buildExpectedSnapshot(TEST_PRIVILEGED_PACKAGES)));
|
||||
@@ -454,7 +457,7 @@ public class TelephonySubscriptionTrackerTest {
|
||||
.when(mSubscriptionManager)
|
||||
.getAllSubscriptionInfoList();
|
||||
|
||||
mTelephonySubscriptionTracker.onReceive(mContext, buildTestBroadcastIntent(true));
|
||||
sendCarrierConfigChange(true /* hasValidSubscription */);
|
||||
mTestLooper.dispatchAll();
|
||||
|
||||
// Expect an empty snapshot
|
||||
@@ -465,7 +468,7 @@ public class TelephonySubscriptionTrackerTest {
|
||||
public void testReceiveBroadcast_SlotCleared() throws Exception {
|
||||
setupReadySubIds();
|
||||
|
||||
mTelephonySubscriptionTracker.onReceive(mContext, buildTestBroadcastIntent(false));
|
||||
sendCarrierConfigChange(false /* hasValidSubscription */);
|
||||
mTestLooper.dispatchAll();
|
||||
|
||||
verifyNoActiveSubscriptions();
|
||||
@@ -476,7 +479,7 @@ public class TelephonySubscriptionTrackerTest {
|
||||
public void testReceiveBroadcast_ConfigNotReady() throws Exception {
|
||||
doReturn(false).when(mDeps).isConfigForIdentifiedCarrier(any());
|
||||
|
||||
mTelephonySubscriptionTracker.onReceive(mContext, buildTestBroadcastIntent(true));
|
||||
sendCarrierConfigChange(true /* hasValidSubscription */);
|
||||
mTestLooper.dispatchAll();
|
||||
|
||||
// No interactions expected; config was not loaded
|
||||
@@ -485,21 +488,21 @@ public class TelephonySubscriptionTrackerTest {
|
||||
|
||||
@Test
|
||||
public void testSubscriptionsClearedAfterValidTriggersCallbacks() throws Exception {
|
||||
mTelephonySubscriptionTracker.onReceive(mContext, buildTestBroadcastIntent(true));
|
||||
sendCarrierConfigChange(true /* hasValidSubscription */);
|
||||
mTestLooper.dispatchAll();
|
||||
verify(mCallback).onNewSnapshot(eq(buildExpectedSnapshot(TEST_PRIVILEGED_PACKAGES)));
|
||||
assertNotNull(
|
||||
mTelephonySubscriptionTracker.getReadySubIdsBySlotId().get(TEST_SIM_SLOT_INDEX));
|
||||
|
||||
doReturn(Collections.emptyList()).when(mSubscriptionManager).getAllSubscriptionInfoList();
|
||||
mTelephonySubscriptionTracker.onReceive(mContext, buildTestBroadcastIntent(true));
|
||||
sendCarrierConfigChange(true /* hasValidSubscription */);
|
||||
mTestLooper.dispatchAll();
|
||||
verify(mCallback).onNewSnapshot(eq(buildExpectedSnapshot(emptyMap(), emptyMap())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCarrierConfigUpdatedAfterValidTriggersCallbacks() throws Exception {
|
||||
mTelephonySubscriptionTracker.onReceive(mContext, buildTestBroadcastIntent(true));
|
||||
sendCarrierConfigChange(true /* hasValidSubscription */);
|
||||
mTestLooper.dispatchAll();
|
||||
verify(mCallback).onNewSnapshot(eq(buildExpectedSnapshot(TEST_PRIVILEGED_PACKAGES)));
|
||||
reset(mCallback);
|
||||
@@ -510,12 +513,12 @@ public class TelephonySubscriptionTrackerTest {
|
||||
new int[] {TRANSPORT_WIFI, TRANSPORT_CELLULAR});
|
||||
doReturn(updatedConfig)
|
||||
.when(mCarrierConfigManager)
|
||||
.getConfigForSubId(eq(TEST_SUBSCRIPTION_ID_1));
|
||||
.getConfigForSubId(eq(TEST_SUBSCRIPTION_ID_1), any());
|
||||
|
||||
Map<Integer, PersistableBundleWrapper> subIdToCarrierConfigMap = new HashMap<>();
|
||||
subIdToCarrierConfigMap.put(
|
||||
TEST_SUBSCRIPTION_ID_1, new PersistableBundleWrapper(updatedConfig));
|
||||
mTelephonySubscriptionTracker.onReceive(mContext, buildTestBroadcastIntent(true));
|
||||
sendCarrierConfigChange(true /* hasValidSubscription */);
|
||||
mTestLooper.dispatchAll();
|
||||
|
||||
verify(mCallback)
|
||||
@@ -530,13 +533,13 @@ public class TelephonySubscriptionTrackerTest {
|
||||
|
||||
@Test
|
||||
public void testSlotClearedAfterValidTriggersCallbacks() throws Exception {
|
||||
mTelephonySubscriptionTracker.onReceive(mContext, buildTestBroadcastIntent(true));
|
||||
sendCarrierConfigChange(true /* hasValidSubscription */);
|
||||
mTestLooper.dispatchAll();
|
||||
verify(mCallback).onNewSnapshot(eq(buildExpectedSnapshot(TEST_PRIVILEGED_PACKAGES)));
|
||||
assertNotNull(
|
||||
mTelephonySubscriptionTracker.getReadySubIdsBySlotId().get(TEST_SIM_SLOT_INDEX));
|
||||
|
||||
mTelephonySubscriptionTracker.onReceive(mContext, buildTestBroadcastIntent(false));
|
||||
sendCarrierConfigChange(false /* hasValidSubscription */);
|
||||
mTestLooper.dispatchAll();
|
||||
verify(mCallback)
|
||||
.onNewSnapshot(
|
||||
|
||||
Reference in New Issue
Block a user