This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
/
SubscriptionInfo.java
1714 lines (1558 loc) · 59.2 KB
/
SubscriptionInfo.java
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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2014 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 android.telephony;
import static android.text.TextUtils.formatSimple;
import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Parcel;
import android.os.ParcelUuid;
import android.os.Parcelable;
import android.telephony.SubscriptionManager.ProfileClass;
import android.telephony.SubscriptionManager.SimDisplayNameSource;
import android.telephony.SubscriptionManager.SubscriptionType;
import android.telephony.SubscriptionManager.UsageSetting;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import com.android.internal.telephony.flags.Flags;
import com.android.internal.telephony.util.TelephonyUtils;
import com.android.telephony.Rlog;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* A Parcelable class for Subscription Information.
*/
public class SubscriptionInfo implements Parcelable {
/**
* Size of text to render on the icon.
*/
private static final int TEXT_SIZE = 16;
/**
* Subscription Identifier, this is a device unique number
* and not an index into an array
*/
private final int mId;
/**
* The ICCID of the SIM that is associated with this subscription, empty if unknown.
*/
@NonNull
private final String mIccId;
/**
* The index of the SIM slot that currently contains the subscription and not necessarily unique
* and maybe {@link SubscriptionManager#INVALID_SIM_SLOT_INDEX} if unknown or the subscription
* is inactive.
*/
private final int mSimSlotIndex;
/**
* The name displayed to the user that identifies this subscription. This name is used
* in Settings page and can be renamed by the user.
*/
@NonNull
private final CharSequence mDisplayName;
/**
* The name displayed to the user that identifies subscription provider name. This name is the
* SPN displayed in status bar and many other places. Can't be renamed by the user.
*/
@NonNull
private final CharSequence mCarrierName;
/**
* The source of the {@link #mDisplayName}.
*/
@SimDisplayNameSource
private final int mDisplayNameSource;
/**
* The color to be used for tinting the icon when displaying to the user.
*/
private final int mIconTint;
/**
* The number presented to the user identify this subscription.
*/
@NonNull
private final String mNumber;
/**
* Whether user enables data roaming for this subscription or not. Either
* {@link SubscriptionManager#DATA_ROAMING_ENABLE} or
* {@link SubscriptionManager#DATA_ROAMING_DISABLE}.
*/
private final int mDataRoaming;
/**
* Mobile Country Code.
*/
@Nullable
private final String mMcc;
/**
* Mobile Network Code.
*/
@Nullable
private final String mMnc;
/**
* EHPLMNs associated with the subscription.
*/
@NonNull
private final String[] mEhplmns;
/**
* HPLMNs associated with the subscription.
*/
@NonNull
private final String[] mHplmns;
/**
* Whether the subscription is from eSIM.
*/
private final boolean mIsEmbedded;
/**
* The string ID of the SIM card. It is the ICCID of the active profile for a UICC card and the
* EID for an eUICC card.
*/
@NonNull
private final String mCardString;
/**
* The access rules for this subscription, if it is embedded and defines any. This does not
* include access rules for non-embedded subscriptions.
*/
@Nullable
private final UiccAccessRule[] mNativeAccessRules;
/**
* The carrier certificates for this subscription that are saved in carrier configs.
* This does not include access rules from the Uicc, whether embedded or non-embedded.
*/
@Nullable
private final UiccAccessRule[] mCarrierConfigAccessRules;
/**
* Whether the subscription is opportunistic.
*/
private final boolean mIsOpportunistic;
/**
* A UUID assigned to the subscription group. {@code null} if not assigned.
*
* @see SubscriptionManager#createSubscriptionGroup(List)
*/
@Nullable
private final ParcelUuid mGroupUuid;
/**
* ISO Country code for the subscription's provider.
*/
@NonNull
private final String mCountryIso;
/**
* The subscription carrier id.
*
* @see TelephonyManager#getSimCarrierId()
*/
private final int mCarrierId;
/**
* The profile class populated from the profile metadata if present. Otherwise,
* the profile class defaults to {@link SubscriptionManager#PROFILE_CLASS_UNSET} if there is no
* profile metadata or the subscription is not on an eUICC ({@link #isEmbedded} returns
* {@code false}).
*/
@ProfileClass
private final int mProfileClass;
/**
* Type of the subscription.
*/
@SubscriptionType
private final int mType;
/**
* A package name that specifies who created the group. Empty if not available.
*/
@NonNull
private final String mGroupOwner;
/**
* Whether uicc applications are configured to enable or disable.
* By default it's true.
*/
private final boolean mAreUiccApplicationsEnabled;
/**
* The port index of the Uicc card.
*/
private final int mPortIndex;
/**
* Subscription's preferred usage setting.
*/
@UsageSetting
private final int mUsageSetting;
// Below are the fields that do not exist in the database.
/**
* SIM icon bitmap cache.
*/
@Nullable
private Bitmap mIconBitmap;
/**
* The card ID of the SIM card. This maps uniquely to {@link #mCardString}.
*/
private final int mCardId;
/**
* Whether group of the subscription is disabled. This is only useful if it's a grouped
* opportunistic subscription. In this case, if all primary (non-opportunistic) subscriptions
* in the group are deactivated (unplugged pSIM or deactivated eSIM profile), we should disable
* this opportunistic subscription.
*/
private final boolean mIsGroupDisabled;
/**
* Whether this subscription is used for communicating with non-terrestrial networks.
*/
private final boolean mIsOnlyNonTerrestrialNetwork;
/**
* @hide
*
* @deprecated Use {@link SubscriptionInfo.Builder}.
*/
// TODO: Clean up after external usages moved to builder model.
@Deprecated
public SubscriptionInfo(int id, String iccId, int simSlotIndex, CharSequence displayName,
CharSequence carrierName, int nameSource, int iconTint, String number, int roaming,
Bitmap icon, String mcc, String mnc, String countryIso, boolean isEmbedded,
@Nullable UiccAccessRule[] nativeAccessRules, String cardString) {
this(id, iccId, simSlotIndex, displayName, carrierName, nameSource, iconTint, number,
roaming, icon, mcc, mnc, countryIso, isEmbedded, nativeAccessRules, cardString, -1,
false, null, false, TelephonyManager.UNKNOWN_CARRIER_ID,
SubscriptionManager.PROFILE_CLASS_UNSET,
SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM, null, null, true);
}
/**
* @hide
*
* @deprecated Use {@link SubscriptionInfo.Builder}.
*/
// TODO: Clean up after external usages moved to builder model.
@Deprecated
public SubscriptionInfo(int id, String iccId, int simSlotIndex, CharSequence displayName,
CharSequence carrierName, int nameSource, int iconTint, String number, int roaming,
Bitmap icon, String mcc, String mnc, String countryIso, boolean isEmbedded,
@Nullable UiccAccessRule[] nativeAccessRules, String cardString,
boolean isOpportunistic, @Nullable String groupUUID, int carrierId, int profileClass) {
this(id, iccId, simSlotIndex, displayName, carrierName, nameSource, iconTint, number,
roaming, icon, mcc, mnc, countryIso, isEmbedded, nativeAccessRules, cardString, -1,
isOpportunistic, groupUUID, false, carrierId, profileClass,
SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM, null, null, true);
}
/**
* @hide
*
* @deprecated Use {@link SubscriptionInfo.Builder}.
*/
// TODO: Clean up after external usages moved to builder model.
@Deprecated
public SubscriptionInfo(int id, String iccId, int simSlotIndex, CharSequence displayName,
CharSequence carrierName, int nameSource, int iconTint, String number, int roaming,
Bitmap icon, String mcc, String mnc, String countryIso, boolean isEmbedded,
@Nullable UiccAccessRule[] nativeAccessRules, String cardString, int cardId,
boolean isOpportunistic, @Nullable String groupUUID, boolean isGroupDisabled,
int carrierId, int profileClass, int subType, @Nullable String groupOwner,
@Nullable UiccAccessRule[] carrierConfigAccessRules,
boolean areUiccApplicationsEnabled) {
this(id, iccId, simSlotIndex, displayName, carrierName, nameSource, iconTint, number,
roaming, icon, mcc, mnc, countryIso, isEmbedded, nativeAccessRules, cardString,
cardId, isOpportunistic, groupUUID, isGroupDisabled, carrierId, profileClass,
subType, groupOwner, carrierConfigAccessRules, areUiccApplicationsEnabled, 0);
}
/**
* @hide
*
* @deprecated Use {@link SubscriptionInfo.Builder}.
*/
// TODO: Clean up after external usages moved to builder model.
@Deprecated
public SubscriptionInfo(int id, String iccId, int simSlotIndex, CharSequence displayName,
CharSequence carrierName, int displayNameSource, int iconTint, String number,
int roaming, Bitmap icon, String mcc, String mnc, String countryIso, boolean isEmbedded,
@Nullable UiccAccessRule[] nativeAccessRules, String cardString, int cardId,
boolean isOpportunistic, @Nullable String groupUUID, boolean isGroupDisabled,
int carrierId, int profileClass, int subType, @Nullable String groupOwner,
@Nullable UiccAccessRule[] carrierConfigAccessRules,
boolean areUiccApplicationsEnabled, int portIndex) {
this(id, iccId, simSlotIndex, displayName, carrierName, displayNameSource, iconTint, number,
roaming, icon, mcc, mnc, countryIso, isEmbedded, nativeAccessRules, cardString,
cardId, isOpportunistic, groupUUID, isGroupDisabled, carrierId, profileClass,
subType, groupOwner, carrierConfigAccessRules, areUiccApplicationsEnabled,
portIndex, SubscriptionManager.USAGE_SETTING_DEFAULT);
}
/**
* @hide
*
* @deprecated Use {@link SubscriptionInfo.Builder}.
*/
// TODO: Clean up after external usages moved to builder model.
@Deprecated
public SubscriptionInfo(int id, String iccId, int simSlotIndex, CharSequence displayName,
CharSequence carrierName, int nameSource, int iconTint, String number, int roaming,
Bitmap icon, String mcc, String mnc, String countryIso, boolean isEmbedded,
@Nullable UiccAccessRule[] nativeAccessRules, String cardString, int cardId,
boolean isOpportunistic, @Nullable String groupUuid, boolean isGroupDisabled,
int carrierId, int profileClass, int subType, @Nullable String groupOwner,
@Nullable UiccAccessRule[] carrierConfigAccessRules,
boolean areUiccApplicationsEnabled, int portIndex, @UsageSetting int usageSetting) {
this.mId = id;
this.mIccId = iccId;
this.mSimSlotIndex = simSlotIndex;
this.mDisplayName = displayName;
this.mCarrierName = carrierName;
this.mDisplayNameSource = nameSource;
this.mIconTint = iconTint;
this.mNumber = number;
this.mDataRoaming = roaming;
this.mIconBitmap = icon;
this.mMcc = TextUtils.emptyIfNull(mcc);
this.mMnc = TextUtils.emptyIfNull(mnc);
this.mHplmns = null;
this.mEhplmns = null;
this.mCountryIso = TextUtils.emptyIfNull(countryIso);
this.mIsEmbedded = isEmbedded;
this.mNativeAccessRules = nativeAccessRules;
this.mCardString = TextUtils.emptyIfNull(cardString);
this.mCardId = cardId;
this.mIsOpportunistic = isOpportunistic;
this.mGroupUuid = groupUuid == null ? null : ParcelUuid.fromString(groupUuid);
this.mIsGroupDisabled = isGroupDisabled;
this.mCarrierId = carrierId;
this.mProfileClass = profileClass;
this.mType = subType;
this.mGroupOwner = TextUtils.emptyIfNull(groupOwner);
this.mCarrierConfigAccessRules = carrierConfigAccessRules;
this.mAreUiccApplicationsEnabled = areUiccApplicationsEnabled;
this.mPortIndex = portIndex;
this.mUsageSetting = usageSetting;
this.mIsOnlyNonTerrestrialNetwork = false;
}
/**
* Constructor from builder.
*
* @param builder Builder of {@link SubscriptionInfo}.
*/
private SubscriptionInfo(@NonNull Builder builder) {
this.mId = builder.mId;
this.mIccId = builder.mIccId;
this.mSimSlotIndex = builder.mSimSlotIndex;
this.mDisplayName = builder.mDisplayName;
this.mCarrierName = builder.mCarrierName;
this.mDisplayNameSource = builder.mDisplayNameSource;
this.mIconTint = builder.mIconTint;
this.mNumber = builder.mNumber;
this.mDataRoaming = builder.mDataRoaming;
this.mIconBitmap = builder.mIconBitmap;
this.mMcc = builder.mMcc;
this.mMnc = builder.mMnc;
this.mEhplmns = builder.mEhplmns;
this.mHplmns = builder.mHplmns;
this.mCountryIso = builder.mCountryIso;
this.mIsEmbedded = builder.mIsEmbedded;
this.mNativeAccessRules = builder.mNativeAccessRules;
this.mCardString = builder.mCardString;
this.mCardId = builder.mCardId;
this.mIsOpportunistic = builder.mIsOpportunistic;
this.mGroupUuid = builder.mGroupUuid;
this.mIsGroupDisabled = builder.mIsGroupDisabled;
this.mCarrierId = builder.mCarrierId;
this.mProfileClass = builder.mProfileClass;
this.mType = builder.mType;
this.mGroupOwner = builder.mGroupOwner;
this.mCarrierConfigAccessRules = builder.mCarrierConfigAccessRules;
this.mAreUiccApplicationsEnabled = builder.mAreUiccApplicationsEnabled;
this.mPortIndex = builder.mPortIndex;
this.mUsageSetting = builder.mUsageSetting;
this.mIsOnlyNonTerrestrialNetwork = builder.mIsOnlyNonTerrestrialNetwork;
}
/**
* @return The subscription ID.
*/
public int getSubscriptionId() {
return mId;
}
/**
* Returns the ICC ID.
*
* Starting with API level 29 Security Patch 2021-04-05, returns the ICC ID if the calling app
* has been granted the READ_PRIVILEGED_PHONE_STATE permission, has carrier privileges (see
* {@link TelephonyManager#hasCarrierPrivileges}), or is a device owner or profile owner that
* has been granted the READ_PHONE_STATE permission. The profile owner is an app that owns a
* managed profile on the device; for more details see <a
* href="https://developer.android.com/work/managed-profiles">Work profiles</a>. Profile
* owner access is deprecated and will be removed in a future release.
*
* @return the ICC ID, or an empty string if one of these requirements is not met
*/
public String getIccId() {
return mIccId;
}
/**
* @return The index of the SIM slot that currently contains the subscription and not
* necessarily unique and maybe {@link SubscriptionManager#INVALID_SIM_SLOT_INDEX} if unknown or
* the subscription is inactive.
*/
public int getSimSlotIndex() {
return mSimSlotIndex;
}
/**
* @return The carrier id of this subscription carrier.
*
* @see TelephonyManager#getSimCarrierId()
*/
public int getCarrierId() {
return mCarrierId;
}
/**
* @return The name displayed to the user that identifies this subscription. This name is
* used in Settings page and can be renamed by the user.
*
* @see #getCarrierName()
*/
public CharSequence getDisplayName() {
return mDisplayName;
}
/**
* @return The name displayed to the user that identifies subscription provider name. This name
* is the SPN displayed in status bar and many other places. Can't be renamed by the user.
*
* @see #getDisplayName()
*/
public CharSequence getCarrierName() {
return mCarrierName;
}
/**
* @return The source of the {@link #getDisplayName()}.
*
* @hide
*/
@SimDisplayNameSource
public int getDisplayNameSource() {
return mDisplayNameSource;
}
/**
* Creates and returns an icon {@code Bitmap} to represent this {@code SubscriptionInfo} in a
* user interface.
*
* @param context A {@code Context} to get the {@code DisplayMetrics}s from.
*
* @return A bitmap icon for this {@code SubscriptionInfo}.
*/
public Bitmap createIconBitmap(Context context) {
if (mIconBitmap == null) {
mIconBitmap = BitmapFactory.decodeResource(context.getResources(),
com.android.internal.R.drawable.ic_sim_card_multi_24px_clr);
}
int width = mIconBitmap.getWidth();
int height = mIconBitmap.getHeight();
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
// Create a new bitmap of the same size because it will be modified.
Bitmap workingBitmap = Bitmap.createBitmap(metrics, width, height, mIconBitmap.getConfig());
Canvas canvas = new Canvas(workingBitmap);
Paint paint = new Paint();
// Tint the icon with the color.
paint.setColorFilter(new PorterDuffColorFilter(mIconTint, PorterDuff.Mode.SRC_ATOP));
canvas.drawBitmap(mIconBitmap, 0, 0, paint);
paint.setColorFilter(null);
// Write the sim slot index.
paint.setAntiAlias(true);
paint.setTypeface(Typeface.create("sans-serif", Typeface.NORMAL));
paint.setColor(Color.WHITE);
// Set text size scaled by density
paint.setTextSize(TEXT_SIZE * metrics.density);
// Convert sim slot index to localized string
final String index = formatSimple("%d", mSimSlotIndex + 1);
final Rect textBound = new Rect();
paint.getTextBounds(index, 0, 1, textBound);
final float xOffset = (width / 2.f) - textBound.centerX();
final float yOffset = (height / 2.f) - textBound.centerY();
canvas.drawText(index, xOffset, yOffset, paint);
return workingBitmap;
}
/**
* A highlight color to use in displaying information about this {@code PhoneAccount}.
*
* @return A hexadecimal color value.
*/
public int getIconTint() {
return mIconTint;
}
/**
* Returns the number of this subscription.
*
* Starting with API level 30, returns the number of this subscription if the calling app meets
* one of the following requirements:
* <ul>
* <li>If the calling app's target SDK is API level 29 or lower and the app has been granted
* the READ_PHONE_STATE permission.
* <li>If the calling app has been granted any of READ_PRIVILEGED_PHONE_STATE,
* READ_PHONE_NUMBERS, or READ_SMS.
* <li>If the calling app has carrier privileges (see {@link
* TelephonyManager#hasCarrierPrivileges}).
* <li>If the calling app is the default SMS role holder.
* </ul>
*
* @return the number of this subscription, or an empty string if one of these requirements is
* not met
* @deprecated use {@link SubscriptionManager#getPhoneNumber(int)} instead, which takes a
* {@link #getSubscriptionId() subscription ID}.
*/
@Deprecated
public String getNumber() {
return mNumber;
}
/**
* Whether user enables data roaming for this subscription or not. Either
* {@link SubscriptionManager#DATA_ROAMING_ENABLE} or
* {@link SubscriptionManager#DATA_ROAMING_DISABLE}.
*/
public int getDataRoaming() {
return mDataRoaming;
}
/**
* @return The mobile country code.
*
* @deprecated Use {@link #getMccString()} instead.
*/
@Deprecated
public int getMcc() {
try {
return mMcc == null ? 0 : Integer.parseInt(mMcc);
} catch (NumberFormatException e) {
Log.w(SubscriptionInfo.class.getSimpleName(), "MCC string is not a number");
return 0;
}
}
/**
* @return The mobile network code.
*
* @deprecated Use {@link #getMncString()} instead.
*/
@Deprecated
public int getMnc() {
try {
return mMnc == null ? 0 : Integer.parseInt(mMnc);
} catch (NumberFormatException e) {
Log.w(SubscriptionInfo.class.getSimpleName(), "MNC string is not a number");
return 0;
}
}
/**
* @return The mobile country code.
*/
@Nullable
public String getMccString() {
return mMcc;
}
/**
* @return The mobile network code.
*/
@Nullable
public String getMncString() {
return mMnc;
}
/**
* @return The ISO country code. Empty if not available.
*/
public String getCountryIso() {
return mCountryIso;
}
/**
* @return {@code true} if the subscription is from eSIM.
*/
public boolean isEmbedded() {
return mIsEmbedded;
}
/**
* An opportunistic subscription connects to a network that is
* limited in functionality and / or coverage.
*
* @return Whether subscription is opportunistic.
*/
public boolean isOpportunistic() {
return mIsOpportunistic;
}
/**
* @return {@code true} if the subscription is from the actively used SIM.
*
* @hide
*/
public boolean isActive() {
return mSimSlotIndex >= 0 || mType == SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM;
}
/**
* Used in scenarios where different subscriptions are bundled as a group.
* It's typically a primary and an opportunistic subscription. (see {@link #isOpportunistic()})
* Such that those subscriptions will have some affiliated behaviors such as opportunistic
* subscription may be invisible to the user.
*
* @return Group UUID a String of group UUID if it belongs to a group. Otherwise
* {@code null}.
*/
@Nullable
public ParcelUuid getGroupUuid() {
return mGroupUuid;
}
/**
* @hide
*/
@NonNull
public List<String> getEhplmns() {
return Collections.unmodifiableList(mEhplmns == null
? Collections.emptyList() : Arrays.asList(mEhplmns));
}
/**
* @hide
*/
@NonNull
public List<String> getHplmns() {
return Collections.unmodifiableList(mHplmns == null
? Collections.emptyList() : Arrays.asList(mHplmns));
}
/**
* @return The owner package of group the subscription belongs to.
*
* @hide
*/
@NonNull
public String getGroupOwner() {
return mGroupOwner;
}
/**
* @return The profile class populated from the profile metadata if present. Otherwise,
* the profile class defaults to {@link SubscriptionManager#PROFILE_CLASS_UNSET} if there is no
* profile metadata or the subscription is not on an eUICC ({@link #isEmbedded} return
* {@code false}).
*
* @hide
*/
@SystemApi
@ProfileClass
public int getProfileClass() {
return mProfileClass;
}
/**
* This method returns the type of a subscription. It can be
* {@link SubscriptionManager#SUBSCRIPTION_TYPE_LOCAL_SIM} or
* {@link SubscriptionManager#SUBSCRIPTION_TYPE_REMOTE_SIM}.
*
* @return The type of the subscription.
*/
@SubscriptionType
public int getSubscriptionType() {
return mType;
}
/**
* Checks whether the app with the given context is authorized to manage this subscription
* according to its metadata. Only supported for embedded subscriptions (if {@link #isEmbedded}
* returns true).
*
* @param context Context of the application to check.
* @return Whether the app is authorized to manage this subscription per its metadata.
* @hide
* @deprecated - Do not use.
*/
@Deprecated
public boolean canManageSubscription(Context context) {
return canManageSubscription(context, context.getPackageName());
}
/**
* Checks whether the given app is authorized to manage this subscription according to its
* metadata. Only supported for embedded subscriptions (if {@link #isEmbedded} returns true).
*
* @param context Any context.
* @param packageName Package name of the app to check.
* @return whether the app is authorized to manage this subscription per its metadata.
* @hide
* @deprecated - Do not use.
*/
@Deprecated
public boolean canManageSubscription(Context context, String packageName) {
List<UiccAccessRule> allAccessRules = getAccessRules();
if (allAccessRules == null) {
return false;
}
PackageManager packageManager = context.getPackageManager();
PackageInfo packageInfo;
try {
packageInfo = packageManager.getPackageInfo(packageName,
PackageManager.GET_SIGNING_CERTIFICATES);
} catch (PackageManager.NameNotFoundException e) {
Log.d("SubscriptionInfo", "canManageSubscription: Unknown package: " + packageName, e);
return false;
}
for (UiccAccessRule rule : allAccessRules) {
if (rule.getCarrierPrivilegeStatus(packageInfo)
== TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
return true;
}
}
return false;
}
/**
* @return The {@link UiccAccessRule}s that are stored in Uicc, dictating who is authorized to
* manage this subscription.
*
* @hide
*/
@SystemApi
@Nullable
public List<UiccAccessRule> getAccessRules() {
List<UiccAccessRule> merged = new ArrayList<>();
if (mNativeAccessRules != null) {
merged.addAll(Arrays.asList(mNativeAccessRules));
}
if (mCarrierConfigAccessRules != null) {
merged.addAll(Arrays.asList(mCarrierConfigAccessRules));
}
return merged.isEmpty() ? null : Collections.unmodifiableList(merged);
}
/**
* Returns the card string of the SIM card which contains the subscription.
*
* Starting with API level 29 Security Patch 2021-04-05, returns the card string if the calling
* app has been granted the READ_PRIVILEGED_PHONE_STATE permission, has carrier privileges (see
* {@link TelephonyManager#hasCarrierPrivileges}), or is a device owner or profile owner that
* has been granted the READ_PHONE_STATE permission. The profile owner is an app that owns a
* managed profile on the device; for more details see <a
* href="https://developer.android.com/work/managed-profiles">Work profiles</a>. Profile
* owner access is deprecated and will be removed in a future release.
*
* @return The card string of the SIM card which contains the subscription or an empty string
* if these requirements are not met. The card string is the ICCID for UICCs or the EID for
* eUICCs.
*
* @hide
*/
@NonNull
public String getCardString() {
return mCardString;
}
/**
* @return The card ID of the SIM card which contains the subscription.
*
* @see UiccCardInfo#getCardId().
*/
public int getCardId() {
return mCardId;
}
/**
* @return The port index of the SIM card which contains the subscription.
*/
public int getPortIndex() {
return mPortIndex;
}
/**
* @return {@code true} if the group of the subscription is disabled. This is only useful if
* it's a grouped opportunistic subscription. In this case, if all primary (non-opportunistic)
* subscriptions in the group are deactivated (unplugged pSIM or deactivated eSIM profile), we
* should disable this opportunistic subscription.
*
* @hide
*/
@SystemApi
public boolean isGroupDisabled() {
return mIsGroupDisabled;
}
/**
* @return {@code true} if Uicc applications are set to be enabled or disabled.
* @hide
*/
@SystemApi
public boolean areUiccApplicationsEnabled() {
return mAreUiccApplicationsEnabled;
}
/**
* Get the usage setting for this subscription.
*
* @return The usage setting used for this subscription.
*/
@UsageSetting
public int getUsageSetting() {
return mUsageSetting;
}
/**
* Check if the subscription is exclusively for non-terrestrial networks.
*
* @return {@code true} if it is a non-terrestrial network subscription, {@code false}
* otherwise.
*/
@FlaggedApi(Flags.FLAG_OEM_ENABLED_SATELLITE_FLAG)
public boolean isOnlyNonTerrestrialNetwork() {
return mIsOnlyNonTerrestrialNetwork;
}
@NonNull
public static final Parcelable.Creator<SubscriptionInfo> CREATOR =
new Parcelable.Creator<SubscriptionInfo>() {
@Override
public SubscriptionInfo createFromParcel(Parcel source) {
return new Builder()
.setId(source.readInt())
.setIccId(source.readString())
.setSimSlotIndex(source.readInt())
.setDisplayName(TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source))
.setCarrierName(TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source))
.setDisplayNameSource(source.readInt())
.setIconTint(source.readInt())
.setNumber(source.readString())
.setDataRoaming(source.readInt())
.setMcc(source.readString())
.setMnc(source.readString())
.setCountryIso(source.readString())
.setEmbedded(source.readBoolean())
.setNativeAccessRules(source.createTypedArray(UiccAccessRule.CREATOR))
.setCardString(source.readString())
.setCardId(source.readInt())
.setPortIndex(source.readInt())
.setOpportunistic(source.readBoolean())
.setGroupUuid(source.readString8())
.setGroupDisabled(source.readBoolean())
.setCarrierId(source.readInt())
.setProfileClass(source.readInt())
.setType(source.readInt())
.setEhplmns(source.createStringArray())
.setHplmns(source.createStringArray())
.setGroupOwner(source.readString())
.setCarrierConfigAccessRules(source.createTypedArray(
UiccAccessRule.CREATOR))
.setUiccApplicationsEnabled(source.readBoolean())
.setUsageSetting(source.readInt())
.setOnlyNonTerrestrialNetwork(source.readBoolean())
.build();
}
@Override
public SubscriptionInfo[] newArray(int size) {
return new SubscriptionInfo[size];
}
};
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mId);
dest.writeString(mIccId);
dest.writeInt(mSimSlotIndex);
TextUtils.writeToParcel(mDisplayName, dest, 0);
TextUtils.writeToParcel(mCarrierName, dest, 0);
dest.writeInt(mDisplayNameSource);
dest.writeInt(mIconTint);
dest.writeString(mNumber);
dest.writeInt(mDataRoaming);
dest.writeString(mMcc);
dest.writeString(mMnc);
dest.writeString(mCountryIso);
// Do not write mIconBitmap since it should be lazily loaded on first usage
dest.writeBoolean(mIsEmbedded);
dest.writeTypedArray(mNativeAccessRules, flags);
dest.writeString(mCardString);
dest.writeInt(mCardId);
dest.writeInt(mPortIndex);
dest.writeBoolean(mIsOpportunistic);
dest.writeString8(mGroupUuid == null ? null : mGroupUuid.toString());
dest.writeBoolean(mIsGroupDisabled);
dest.writeInt(mCarrierId);
dest.writeInt(mProfileClass);
dest.writeInt(mType);
dest.writeStringArray(mEhplmns);
dest.writeStringArray(mHplmns);
dest.writeString(mGroupOwner);
dest.writeTypedArray(mCarrierConfigAccessRules, flags);
dest.writeBoolean(mAreUiccApplicationsEnabled);
dest.writeInt(mUsageSetting);
dest.writeBoolean(mIsOnlyNonTerrestrialNetwork);
}
@Override
public int describeContents() {
return 0;
}
/**
* Get stripped PII information from the id.
*
* @param id The raw id (e.g. ICCID, IMSI, etc...).
* @return The stripped string.
*
* @hide
*/
@Nullable
public static String getPrintableId(@Nullable String id) {
String idToPrint = null;
if (id != null) {
if (id.length() > 9 && !TelephonyUtils.IS_DEBUGGABLE) {
idToPrint = id.substring(0, 9) + Rlog.pii(false, id.substring(9));
} else {
idToPrint = id;
}
}
return idToPrint;
}
@Override
public String toString() {
String iccIdToPrint = getPrintableId(mIccId);
String cardStringToPrint = getPrintableId(mCardString);
return "[SubscriptionInfo: id=" + mId
+ " iccId=" + iccIdToPrint
+ " simSlotIndex=" + mSimSlotIndex
+ " portIndex=" + mPortIndex
+ " isEmbedded=" + mIsEmbedded