summaryrefslogtreecommitdiff
path: root/services/core/java/com/android/server/vcn/TelephonySubscriptionTracker.java
blob: 17f5e9585c22caec7e1fac0353c6923d638fc192 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.vcn;

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;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.vcn.VcnManager;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.ParcelUuid;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener;
import android.telephony.TelephonyCallback;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager.CarrierPrivilegesCallback;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Slog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting.Visibility;
import com.android.internal.telephony.flags.Flags;
import com.android.internal.util.IndentingPrintWriter;
import com.android.server.vcn.util.PersistableBundleUtils.PersistableBundleWrapper;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;

/**
 * TelephonySubscriptionTracker provides a caching layer for tracking active subscription groups.
 *
 * <p>This class performs two roles:
 *
 * <ol>
 *   <li>De-noises subscription changes by ensuring that only changes in active and ready
 *       subscription groups are acted upon
 *   <li>Caches mapping between subIds and subscription groups
 * </ol>
 *
 * <p>An subscription group is active and ready if any of its contained subIds has had BOTH the
 * {@link CarrierConfigManager#isConfigForIdentifiedCarrier()} return true, AND the subscription is
 * listed as active per SubscriptionManager#getAllSubscriptionInfoList().
 *
 * <p>Note that due to the asynchronous nature of callbacks and broadcasts, the output of this class
 * is (only) eventually consistent.
 *
 * @hide
 */
public class TelephonySubscriptionTracker extends BroadcastReceiver {
    @NonNull private static final String TAG = TelephonySubscriptionTracker.class.getSimpleName();
    private static final boolean LOG_DBG = false; // STOPSHIP if true

    @NonNull private final Context mContext;
    @NonNull private final Handler mHandler;
    @NonNull private final TelephonySubscriptionTrackerCallback mCallback;
    @NonNull private final Dependencies mDeps;

    @NonNull private final TelephonyManager mTelephonyManager;
    @NonNull private final SubscriptionManager mSubscriptionManager;
    @NonNull private final CarrierConfigManager mCarrierConfigManager;

    @NonNull private final ActiveDataSubscriptionIdListener mActiveDataSubIdListener;

    // TODO (Android T+): Add ability to handle multiple subIds per slot.
    @NonNull private final Map<Integer, Integer> mReadySubIdsBySlotId = new HashMap<>();

    @NonNull
    private final Map<Integer, PersistableBundleWrapper> mSubIdToCarrierConfigMap = new HashMap<>();

    @NonNull private final OnSubscriptionsChangedListener mSubscriptionChangedListener;

    @NonNull
    private final List<CarrierPrivilegesCallback> mCarrierPrivilegesCallbacks = new ArrayList<>();

    @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,
            @NonNull TelephonySubscriptionTrackerCallback callback) {
        this(context, handler, callback, new Dependencies());
    }

    @VisibleForTesting(visibility = Visibility.PRIVATE)
    TelephonySubscriptionTracker(
            @NonNull Context context,
            @NonNull Handler handler,
            @NonNull TelephonySubscriptionTrackerCallback callback,
            @NonNull Dependencies deps) {
        mContext = Objects.requireNonNull(context, "Missing context");
        mHandler = Objects.requireNonNull(handler, "Missing handler");
        mCallback = Objects.requireNonNull(callback, "Missing callback");
        mDeps = Objects.requireNonNull(deps, "Missing deps");

        mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
        mSubscriptionManager = mContext.getSystemService(SubscriptionManager.class);
        mCarrierConfigManager = mContext.getSystemService(CarrierConfigManager.class);
        mActiveDataSubIdListener = new ActiveDataSubscriptionIdListener();

        mSubscriptionChangedListener =
                new OnSubscriptionsChangedListener() {
                    @Override
                    public void onSubscriptionsChanged() {
                        handleSubscriptionsChanged();
                    }
                };
    }

    /**
     * Registers the receivers, and starts tracking subscriptions.
     *
     * <p>Must always be run on the VcnManagementService thread.
     */
    public void register() {
        final HandlerExecutor executor = new HandlerExecutor(mHandler);
        final IntentFilter filter = new IntentFilter();
        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();
    }

    // TODO(b/221306368): Refactor with the new onCarrierServiceChange in the new CPCallback
    private void registerCarrierPrivilegesCallbacks() {
        final HandlerExecutor executor = new HandlerExecutor(mHandler);
        final int modemCount = mTelephonyManager.getActiveModemCount();
        try {
            for (int i = 0; i < modemCount; i++) {
                CarrierPrivilegesCallback carrierPrivilegesCallback =
                        new CarrierPrivilegesCallback() {
                            @Override
                            public void onCarrierPrivilegesChanged(
                                    @NonNull Set<String> privilegedPackageNames,
                                    @NonNull Set<Integer> privilegedUids) {
                                // Re-trigger the synchronous check (which is also very cheap due
                                // to caching in CarrierPrivilegesTracker). This allows consistency
                                // with the onSubscriptionsChangedListener and broadcasts.
                                handleSubscriptionsChanged();
                            }
                        };

                mTelephonyManager.registerCarrierPrivilegesCallback(
                        i, executor, carrierPrivilegesCallback);
                mCarrierPrivilegesCallbacks.add(carrierPrivilegesCallback);
            }
        } catch (IllegalArgumentException e) {
            Slog.wtf(TAG, "Encounted exception registering carrier privileges listeners", e);
        }
    }

    /**
     * Unregisters the receivers, and stops tracking subscriptions.
     *
     * <p>Must always be run on the VcnManagementService thread.
     */
    public void unregister() {
        mContext.unregisterReceiver(this);
        mSubscriptionManager.removeOnSubscriptionsChangedListener(mSubscriptionChangedListener);
        mTelephonyManager.unregisterTelephonyCallback(mActiveDataSubIdListener);
        mCarrierConfigManager.unregisterCarrierConfigChangeListener(mCarrierConfigChangeListener);

        unregisterCarrierPrivilegesCallbacks();
    }

    private void unregisterCarrierPrivilegesCallbacks() {
        for (CarrierPrivilegesCallback carrierPrivilegesCallback :
                mCarrierPrivilegesCallbacks) {
            mTelephonyManager.unregisterCarrierPrivilegesCallback(carrierPrivilegesCallback);
        }
        mCarrierPrivilegesCallbacks.clear();
    }

    /**
     * Handles subscription changes, correlating available subscriptions and loaded carrier configs
     *
     * <p>The subscription change listener is registered with a HandlerExecutor backed by mHandler,
     * so callbacks & broadcasts are all serialized on mHandler, avoiding the need for locking.
     */
    public void handleSubscriptionsChanged() {
        final Map<ParcelUuid, Set<String>> privilegedPackages = new HashMap<>();
        final Map<Integer, SubscriptionInfo> newSubIdToInfoMap = new HashMap<>();

        final List<SubscriptionInfo> allSubs = mSubscriptionManager.getAllSubscriptionInfoList();
        if (allSubs == null) {
            return; // Telephony crashed; no way to verify subscriptions.
        }

        // If allSubs is empty, no subscriptions exist. Cache will be cleared by virtue of no active
        // subscriptions
        for (SubscriptionInfo subInfo : allSubs) {
            if (subInfo.getGroupUuid() == null) {
                continue;
            }

            // Build subId -> subGrp cache
            newSubIdToInfoMap.put(subInfo.getSubscriptionId(), subInfo);

            // Update subscription groups that are both ready, and active. For a group to be
            // considered active, both of the following must be true:
            //
            // 1. A final CARRIER_CONFIG_CHANGED (where config is for an identified carrier)
            // broadcast must have been received for the subId
            // 2. A active subscription (is loaded into a SIM slot) must be part of the subscription
            // group.
            if (subInfo.getSimSlotIndex() != INVALID_SIM_SLOT_INDEX
                    && mReadySubIdsBySlotId.values().contains(subInfo.getSubscriptionId())) {
                final TelephonyManager subIdSpecificTelephonyManager =
                        mTelephonyManager.createForSubscriptionId(subInfo.getSubscriptionId());

                final ParcelUuid subGroup = subInfo.getGroupUuid();
                final Set<String> pkgs =
                        privilegedPackages.getOrDefault(subGroup, new ArraySet<>());
                pkgs.addAll(subIdSpecificTelephonyManager.getPackagesWithCarrierPrivileges());

                privilegedPackages.put(subGroup, pkgs);
            }
        }

        final TelephonySubscriptionSnapshot newSnapshot =
                new TelephonySubscriptionSnapshot(
                        mDeps.getActiveDataSubscriptionId(),
                        newSubIdToInfoMap,
                        mSubIdToCarrierConfigMap,
                        privilegedPackages);

        // If snapshot was meaningfully updated, fire the callback
        if (!newSnapshot.equals(mCurrentSnapshot)) {
            mCurrentSnapshot = newSnapshot;
            mHandler.post(
                    () -> {
                        mCallback.onNewSnapshot(newSnapshot);
                    });
        }
    }

    /**
     * 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.
     */
    @Override
    public void onReceive(Context context, Intent intent) {
        switch (intent.getAction()) {
            case ACTION_MULTI_SIM_CONFIG_CHANGED:
                handleActionMultiSimConfigChanged(context, intent);
                break;
            default:
                Slog.v(TAG, "Unknown intent received with action: " + intent.getAction());
        }
    }

    private void handleActionMultiSimConfigChanged(Context context, Intent intent) {
        unregisterCarrierPrivilegesCallbacks();

        // Clear invalid slotIds from the mReadySubIdsBySlotId map.
        final int modemCount = mTelephonyManager.getActiveModemCount();
        final Iterator<Integer> slotIdIterator = mReadySubIdsBySlotId.keySet().iterator();
        while (slotIdIterator.hasNext()) {
            final int slotId = slotIdIterator.next();

            if (slotId >= modemCount) {
                slotIdIterator.remove();
            }
        }

        registerCarrierPrivilegesCallbacks();
        handleSubscriptionsChanged();
    }

    private void handleActionCarrierConfigChanged(int slotId, int subId) {
        if (slotId == INVALID_SIM_SLOT_INDEX) {
            return;
        }

        if (SubscriptionManager.isValidSubscriptionId(subId)) {
            // Get only configs as needed to save memory.
            final PersistableBundle carrierConfig =
                    Flags.fixCrashOnGettingConfigWhenPhoneIsGone()
                            ? CarrierConfigManager.getCarrierConfigSubset(mContext, subId,
                                    VcnManager.VCN_RELATED_CARRIER_CONFIG_KEYS)
                            : mCarrierConfigManager.getConfigForSubId(subId,
                                    VcnManager.VCN_RELATED_CARRIER_CONFIG_KEYS);
            if (mDeps.isConfigForIdentifiedCarrier(carrierConfig)) {
                mReadySubIdsBySlotId.put(slotId, subId);

                if (!carrierConfig.isEmpty()) {
                    mSubIdToCarrierConfigMap.put(subId,
                            new PersistableBundleWrapper(carrierConfig));
                }
                handleSubscriptionsChanged();
            }
        } else {
            final Integer oldSubid = mReadySubIdsBySlotId.remove(slotId);
            if (oldSubid != null) {
                mSubIdToCarrierConfigMap.remove(oldSubid);
            }
            handleSubscriptionsChanged();
        }
    }

    @VisibleForTesting(visibility = Visibility.PRIVATE)
    void setReadySubIdsBySlotId(Map<Integer, Integer> readySubIdsBySlotId) {
        mReadySubIdsBySlotId.clear();
        mReadySubIdsBySlotId.putAll(readySubIdsBySlotId);
    }

    @VisibleForTesting(visibility = Visibility.PRIVATE)
    void setSubIdToCarrierConfigMap(
            Map<Integer, PersistableBundleWrapper> subIdToCarrierConfigMap) {
        mSubIdToCarrierConfigMap.clear();
        mSubIdToCarrierConfigMap.putAll(subIdToCarrierConfigMap);
    }

    @VisibleForTesting(visibility = Visibility.PRIVATE)
    Map<Integer, Integer> getReadySubIdsBySlotId() {
        return Collections.unmodifiableMap(mReadySubIdsBySlotId);
    }

    @VisibleForTesting(visibility = Visibility.PRIVATE)
    Map<Integer, PersistableBundleWrapper> getSubIdToCarrierConfigMap() {
        return Collections.unmodifiableMap(mSubIdToCarrierConfigMap);
    }

    /** TelephonySubscriptionSnapshot is a class containing info about active subscriptions */
    public static class TelephonySubscriptionSnapshot {
        private final int mActiveDataSubId;
        private final Map<Integer, SubscriptionInfo> mSubIdToInfoMap;
        private final Map<Integer, PersistableBundleWrapper> mSubIdToCarrierConfigMap;
        private final Map<ParcelUuid, Set<String>> mPrivilegedPackages;

        public static final TelephonySubscriptionSnapshot EMPTY_SNAPSHOT =
                new TelephonySubscriptionSnapshot(
                        INVALID_SUBSCRIPTION_ID,
                        Collections.emptyMap(),
                        Collections.emptyMap(),
                        Collections.emptyMap());

        @VisibleForTesting(visibility = Visibility.PRIVATE)
        TelephonySubscriptionSnapshot(
                int activeDataSubId,
                @NonNull Map<Integer, SubscriptionInfo> subIdToInfoMap,
                @NonNull Map<Integer, PersistableBundleWrapper> subIdToCarrierConfigMap,
                @NonNull Map<ParcelUuid, Set<String>> privilegedPackages) {
            mActiveDataSubId = activeDataSubId;
            Objects.requireNonNull(subIdToInfoMap, "subIdToInfoMap was null");
            Objects.requireNonNull(privilegedPackages, "privilegedPackages was null");
            Objects.requireNonNull(subIdToCarrierConfigMap, "subIdToCarrierConfigMap was null");

            mSubIdToInfoMap =
                    Collections.unmodifiableMap(
                            new HashMap<Integer, SubscriptionInfo>(subIdToInfoMap));
            mSubIdToCarrierConfigMap =
                    Collections.unmodifiableMap(
                            new HashMap<Integer, PersistableBundleWrapper>(
                                    subIdToCarrierConfigMap));

            final Map<ParcelUuid, Set<String>> unmodifiableInnerSets = new ArrayMap<>();
            for (Entry<ParcelUuid, Set<String>> entry : privilegedPackages.entrySet()) {
                unmodifiableInnerSets.put(
                        entry.getKey(), Collections.unmodifiableSet(entry.getValue()));
            }
            mPrivilegedPackages = Collections.unmodifiableMap(unmodifiableInnerSets);
        }

        /** Returns the active subscription ID. May be INVALID_SUBSCRIPTION_ID */
        public int getActiveDataSubscriptionId() {
            return mActiveDataSubId;
        }

        /** Returns the active subscription group */
        @Nullable
        public ParcelUuid getActiveDataSubscriptionGroup() {
            final SubscriptionInfo info = mSubIdToInfoMap.get(getActiveDataSubscriptionId());
            if (info == null) {
                return null;
            }

            return info.getGroupUuid();
        }

        /** Returns the active subscription groups */
        @NonNull
        public Set<ParcelUuid> getActiveSubscriptionGroups() {
            return mPrivilegedPackages.keySet();
        }

        /** Checks if the provided package is carrier privileged for the specified sub group. */
        public boolean packageHasPermissionsForSubscriptionGroup(
                @NonNull ParcelUuid subGrp, @NonNull String packageName) {
            final Set<String> privilegedPackages = mPrivilegedPackages.get(subGrp);

            return privilegedPackages != null && privilegedPackages.contains(packageName);
        }

        /** Returns the Subscription Group for a given subId. */
        @Nullable
        public ParcelUuid getGroupForSubId(int subId) {
            return mSubIdToInfoMap.containsKey(subId)
                    ? mSubIdToInfoMap.get(subId).getGroupUuid()
                    : null;
        }

        /**
         * Returns all the subIds in a given group, including available, but inactive subscriptions.
         */
        @NonNull
        public Set<Integer> getAllSubIdsInGroup(ParcelUuid subGrp) {
            final Set<Integer> subIds = new ArraySet<>();

            for (Entry<Integer, SubscriptionInfo> entry : mSubIdToInfoMap.entrySet()) {
                if (subGrp.equals(entry.getValue().getGroupUuid())) {
                    subIds.add(entry.getKey());
                }
            }

            return subIds;
        }

        /** Checks if the requested subscription is opportunistic */
        @NonNull
        public boolean isOpportunistic(int subId) {
            return mSubIdToInfoMap.containsKey(subId)
                    ? mSubIdToInfoMap.get(subId).isOpportunistic()
                    : false;
        }

        /**
         * Retrieves a carrier config for a subscription in the provided group.
         *
         * <p>This method will prioritize non-opportunistic subscriptions, but will use the a
         * carrier config for an opportunistic subscription if no other subscriptions are found.
         */
        @Nullable
        public PersistableBundleWrapper getCarrierConfigForSubGrp(@NonNull ParcelUuid subGrp) {
            PersistableBundleWrapper result = null;

            for (int subId : getAllSubIdsInGroup(subGrp)) {
                final PersistableBundleWrapper config = mSubIdToCarrierConfigMap.get(subId);
                if (config != null) {
                    result = config;

                    // Attempt to use (any) non-opportunistic subscription. If this subscription is
                    // opportunistic, continue and try to find a non-opportunistic subscription,
                    // using the opportunistic ones as a last resort.
                    if (!isOpportunistic(subId)) {
                        return config;
                    }
                }
            }

            return result;
        }

        @Override
        public int hashCode() {
            return Objects.hash(
                    mActiveDataSubId,
                    mSubIdToInfoMap,
                    mSubIdToCarrierConfigMap,
                    mPrivilegedPackages);
        }

        @Override
        public boolean equals(Object obj) {
            if (!(obj instanceof TelephonySubscriptionSnapshot)) {
                return false;
            }

            final TelephonySubscriptionSnapshot other = (TelephonySubscriptionSnapshot) obj;

            return mActiveDataSubId == other.mActiveDataSubId
                    && mSubIdToInfoMap.equals(other.mSubIdToInfoMap)
                    && mSubIdToCarrierConfigMap.equals(other.mSubIdToCarrierConfigMap)
                    && mPrivilegedPackages.equals(other.mPrivilegedPackages);
        }

        /** Dumps the state of this snapshot for logging and debugging purposes. */
        public void dump(IndentingPrintWriter pw) {
            pw.println("TelephonySubscriptionSnapshot:");
            pw.increaseIndent();

            pw.println("mActiveDataSubId: " + mActiveDataSubId);
            pw.println("mSubIdToInfoMap: " + mSubIdToInfoMap);
            pw.println("mSubIdToCarrierConfigMap: " + mSubIdToCarrierConfigMap);
            pw.println("mPrivilegedPackages: " + mPrivilegedPackages);

            pw.decreaseIndent();
        }

        @Override
        public String toString() {
            return "TelephonySubscriptionSnapshot{ "
                    + "mActiveDataSubId=" + mActiveDataSubId
                    + ", mSubIdToInfoMap=" + mSubIdToInfoMap
                    + ", mSubIdToCarrierConfigMap=" + mSubIdToCarrierConfigMap
                    + ", mPrivilegedPackages=" + mPrivilegedPackages
                    + " }";
        }
    }

    /**
     * Interface for listening to changes in subscriptions
     *
     * @see TelephonySubscriptionTracker
     */
    public interface TelephonySubscriptionTrackerCallback {
        /**
         * Called when subscription information changes, and a new subscription snapshot was taken
         *
         * @param snapshot the snapshot of subscription information.
         */
        void onNewSnapshot(@NonNull TelephonySubscriptionSnapshot snapshot);
    }

    private class ActiveDataSubscriptionIdListener extends TelephonyCallback
            implements TelephonyCallback.ActiveDataSubscriptionIdListener {
        @Override
        public void onActiveDataSubscriptionIdChanged(int subId) {
            handleSubscriptionsChanged();
        }
    }

    /** External static dependencies for test injection */
    @VisibleForTesting(visibility = Visibility.PRIVATE)
    public static class Dependencies {
        /** Checks if the given bundle is for an identified carrier */
        public boolean isConfigForIdentifiedCarrier(PersistableBundle bundle) {
            return CarrierConfigManager.isConfigForIdentifiedCarrier(bundle);
        }

        /** Gets the active Subscription ID */
        public int getActiveDataSubscriptionId() {
            return SubscriptionManager.getActiveDataSubscriptionId();
        }
    }
}