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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513
|
/*
* Copyright (C) 2019 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 android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.compat.Compatibility;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledAfter;
import android.content.Context;
import android.os.Binder;
import android.os.Build;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.service.carrier.CarrierService;
import android.telephony.Annotation.CallState;
import android.telephony.Annotation.DataActivityType;
import android.telephony.Annotation.DisconnectCauses;
import android.telephony.Annotation.NetworkType;
import android.telephony.Annotation.PreciseCallStates;
import android.telephony.Annotation.PreciseDisconnectCauses;
import android.telephony.Annotation.RadioPowerState;
import android.telephony.Annotation.SimActivationState;
import android.telephony.Annotation.SrvccState;
import android.telephony.TelephonyManager.CarrierPrivilegesCallback;
import android.telephony.emergency.EmergencyNumber;
import android.telephony.ims.ImsReasonInfo;
import android.util.ArraySet;
import android.util.Log;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.listeners.ListenerExecutor;
import com.android.internal.telephony.ICarrierConfigChangeListener;
import com.android.internal.telephony.ICarrierPrivilegesCallback;
import com.android.internal.telephony.IOnSubscriptionsChangedListener;
import com.android.internal.telephony.ITelephonyRegistry;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;
/**
* A centralized place to notify telephony related status changes, e.g, {@link ServiceState} update
* or {@link PhoneCapability} changed. This might trigger callback from applications side through
* {@link android.telephony.PhoneStateListener}
*
* TODO: limit API access to only carrier apps with certain permissions or apps running on
* privileged UID.
*
* @hide
*/
public class TelephonyRegistryManager {
private static final String TAG = "TelephonyRegistryManager";
private static ITelephonyRegistry sRegistry;
private final Context mContext;
/**
* A mapping between {@link SubscriptionManager.OnSubscriptionsChangedListener} and
* its callback IOnSubscriptionsChangedListener.
*/
private final Map<SubscriptionManager.OnSubscriptionsChangedListener,
IOnSubscriptionsChangedListener> mSubscriptionChangedListenerMap = new HashMap<>();
/**
* A mapping between {@link SubscriptionManager.OnOpportunisticSubscriptionsChangedListener} and
* its callback IOnSubscriptionsChangedListener.
*/
private final Map<SubscriptionManager.OnOpportunisticSubscriptionsChangedListener,
IOnSubscriptionsChangedListener> mOpportunisticSubscriptionChangedListenerMap
= new HashMap<>();
/**
* A mapping between {@link CarrierConfigManager.CarrierConfigChangeListener} and its callback
* ICarrierConfigChangeListener.
*/
private final ConcurrentHashMap<CarrierConfigManager.CarrierConfigChangeListener,
ICarrierConfigChangeListener>
mCarrierConfigChangeListenerMap = new ConcurrentHashMap<>();
/** @hide **/
public TelephonyRegistryManager(@NonNull Context context) {
mContext = context;
if (sRegistry == null) {
sRegistry = ITelephonyRegistry.Stub.asInterface(
ServiceManager.getService("telephony.registry"));
}
}
/**
* Register for changes to the list of active {@link SubscriptionInfo} records or to the
* individual records themselves. When a change occurs the onSubscriptionsChanged method of
* the listener will be invoked immediately if there has been a notification. The
* onSubscriptionChanged method will also be triggered once initially when calling this
* function.
*
* @param listener an instance of {@link SubscriptionManager.OnSubscriptionsChangedListener}
* with onSubscriptionsChanged overridden.
* @param executor the executor that will execute callbacks.
*/
public void addOnSubscriptionsChangedListener(
@NonNull SubscriptionManager.OnSubscriptionsChangedListener listener,
@NonNull Executor executor) {
if (mSubscriptionChangedListenerMap.get(listener) != null) {
Log.d(TAG, "addOnSubscriptionsChangedListener listener already present");
return;
}
IOnSubscriptionsChangedListener callback = new IOnSubscriptionsChangedListener.Stub() {
@Override
public void onSubscriptionsChanged () {
final long identity = Binder.clearCallingIdentity();
try {
executor.execute(() -> listener.onSubscriptionsChanged());
} finally {
Binder.restoreCallingIdentity(identity);
}
}
};
mSubscriptionChangedListenerMap.put(listener, callback);
try {
sRegistry.addOnSubscriptionsChangedListener(mContext.getOpPackageName(),
mContext.getAttributionTag(), callback);
} catch (RemoteException ex) {
// system server crash
throw ex.rethrowFromSystemServer();
}
}
/**
* Unregister the {@link SubscriptionManager.OnSubscriptionsChangedListener}. This is not
* strictly necessary as the listener will automatically be unregistered if an attempt to
* invoke the listener fails.
*
* @param listener that is to be unregistered.
*/
public void removeOnSubscriptionsChangedListener(
@NonNull SubscriptionManager.OnSubscriptionsChangedListener listener) {
if (mSubscriptionChangedListenerMap.get(listener) == null) {
return;
}
try {
sRegistry.removeOnSubscriptionsChangedListener(mContext.getOpPackageName(),
mSubscriptionChangedListenerMap.get(listener));
mSubscriptionChangedListenerMap.remove(listener);
} catch (RemoteException ex) {
// system server crash
throw ex.rethrowFromSystemServer();
}
}
/**
* Register for changes to the list of opportunistic subscription records or to the
* individual records themselves. When a change occurs the onOpportunisticSubscriptionsChanged
* method of the listener will be invoked immediately if there has been a notification.
*
* @param listener an instance of
* {@link SubscriptionManager.OnOpportunisticSubscriptionsChangedListener} with
* onOpportunisticSubscriptionsChanged overridden.
* @param executor an Executor that will execute callbacks.
*/
public void addOnOpportunisticSubscriptionsChangedListener(
@NonNull SubscriptionManager.OnOpportunisticSubscriptionsChangedListener listener,
@NonNull Executor executor) {
if (mOpportunisticSubscriptionChangedListenerMap.get(listener) != null) {
Log.d(TAG, "addOnOpportunisticSubscriptionsChangedListener listener already present");
return;
}
/**
* The callback methods need to be called on the executor thread where
* this object was created. If the binder did that for us it'd be nice.
*/
IOnSubscriptionsChangedListener callback = new IOnSubscriptionsChangedListener.Stub() {
@Override
public void onSubscriptionsChanged() {
final long identity = Binder.clearCallingIdentity();
try {
Log.d(TAG, "onOpportunisticSubscriptionsChanged callback received.");
executor.execute(() -> listener.onOpportunisticSubscriptionsChanged());
} finally {
Binder.restoreCallingIdentity(identity);
}
}
};
mOpportunisticSubscriptionChangedListenerMap.put(listener, callback);
try {
sRegistry.addOnOpportunisticSubscriptionsChangedListener(mContext.getOpPackageName(),
mContext.getAttributionTag(), callback);
} catch (RemoteException ex) {
// system server crash
throw ex.rethrowFromSystemServer();
}
}
/**
* Unregister the {@link SubscriptionManager.OnOpportunisticSubscriptionsChangedListener}
* that is currently listening opportunistic subscriptions change. This is not strictly
* necessary as the listener will automatically be unregistered if an attempt to invoke the
* listener fails.
*
* @param listener that is to be unregistered.
*/
public void removeOnOpportunisticSubscriptionsChangedListener(
@NonNull SubscriptionManager.OnOpportunisticSubscriptionsChangedListener listener) {
if (mOpportunisticSubscriptionChangedListenerMap.get(listener) == null) {
return;
}
try {
sRegistry.removeOnSubscriptionsChangedListener(mContext.getOpPackageName(),
mOpportunisticSubscriptionChangedListenerMap.get(listener));
mOpportunisticSubscriptionChangedListenerMap.remove(listener);
} catch (RemoteException ex) {
// system server crash
throw ex.rethrowFromSystemServer();
}
}
/**
* To check the SDK version for {@link #listenFromListener}.
*/
@ChangeId
@EnabledAfter(targetSdkVersion = Build.VERSION_CODES.P)
private static final long LISTEN_CODE_CHANGE = 147600208L;
/**
* Listen for incoming subscriptions
* @param subId Subscription ID
* @param pkg Package name
* @param featureId Feature ID
* @param listener Listener providing callback
* @param events Events
* @param notifyNow Whether to notify instantly
*/
public void listenFromListener(int subId, @NonNull boolean renounceFineLocationAccess,
@NonNull boolean renounceCoarseLocationAccess, @NonNull String pkg,
@NonNull String featureId, @NonNull PhoneStateListener listener,
@NonNull int events, boolean notifyNow) {
if (listener == null) {
throw new IllegalStateException("telephony service is null.");
}
try {
int[] eventsList = getEventsFromBitmask(events).stream().mapToInt(i -> i).toArray();
// subId from PhoneStateListener is deprecated Q on forward, use the subId from
// TelephonyManager instance. Keep using subId from PhoneStateListener for pre-Q.
if (Compatibility.isChangeEnabled(LISTEN_CODE_CHANGE)) {
// Since mSubId in PhoneStateListener is deprecated from Q on forward, this is
// the only place to set mSubId and its for "informational" only.
listener.mSubId = (eventsList.length == 0)
? SubscriptionManager.INVALID_SUBSCRIPTION_ID : subId;
} else if (listener.mSubId != null) {
subId = listener.mSubId;
}
sRegistry.listenWithEventList(renounceFineLocationAccess, renounceCoarseLocationAccess,
subId, pkg, featureId, listener.callback, eventsList, notifyNow);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Listen for incoming subscriptions
* @param subId Subscription ID
* @param pkg Package name
* @param featureId Feature ID
* @param telephonyCallback Listener providing callback
* @param events List events
* @param notifyNow Whether to notify instantly
*/
private void listenFromCallback(boolean renounceFineLocationAccess,
boolean renounceCoarseLocationAccess, int subId,
@NonNull String pkg, @NonNull String featureId,
@NonNull TelephonyCallback telephonyCallback, @NonNull int[] events,
boolean notifyNow) {
try {
sRegistry.listenWithEventList(renounceFineLocationAccess, renounceCoarseLocationAccess,
subId, pkg, featureId, telephonyCallback.callback, events, notifyNow);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Informs the system of an intentional upcoming carrier network change by a carrier app.
* This call only used to allow the system to provide alternative UI while telephony is
* performing an action that may result in intentional, temporary network lack of connectivity.
* <p>
* Based on the active parameter passed in, this method will either show or hide the alternative
* UI. There is no timeout associated with showing this UX, so a carrier app must be sure to
* call with active set to false sometime after calling with it set to {@code true}.
* <p>
* This will apply to all subscriptions the carrier app has carrier privileges on.
* <p>
* Requires Permission: calling app has carrier privileges.
*
* @param active Whether the carrier network change is or shortly will be
* active. Set this value to true to begin showing alternative UI and false to stop.
* @see TelephonyManager#hasCarrierPrivileges
*/
public void notifyCarrierNetworkChange(boolean active) {
try {
sRegistry.notifyCarrierNetworkChange(active);
} catch (RemoteException ex) {
// system server crash
throw ex.rethrowFromSystemServer();
}
}
/**
* Informs the system of an intentional upcoming carrier network change by a carrier app on the
* given {@code subscriptionId}. This call only used to allow the system to provide alternative
* UI while telephony is performing an action that may result in intentional, temporary network
* lack of connectivity.
* <p>
* Based on the active parameter passed in, this method will either show or hide the
* alternative UI. There is no timeout associated with showing this UX, so a carrier app must be
* sure to call with active set to false sometime after calling with it set to {@code true}.
* <p>
* Requires Permission: calling app has carrier privileges.
*
* @param subscriptionId the subscription of the carrier network.
* @param active whether the carrier network change is or shortly will be active. Set this value
* to true to begin showing alternative UI and false to stop.
* @see TelephonyManager#hasCarrierPrivileges
*/
public void notifyCarrierNetworkChange(int subscriptionId, boolean active) {
try {
sRegistry.notifyCarrierNetworkChangeWithSubId(subscriptionId, active);
} catch (RemoteException ex) {
// system server crash
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify call state changed on certain subscription.
*
* @param slotIndex for which call state changed. Can be derived from subId except when subId is
* invalid.
* @param subId for which call state changed.
* @param state latest call state. e.g, offhook, ringing
* @param incomingNumber incoming phone number.
*/
public void notifyCallStateChanged(int slotIndex, int subId, @CallState int state,
@Nullable String incomingNumber) {
try {
sRegistry.notifyCallState(slotIndex, subId, state, incomingNumber);
} catch (RemoteException ex) {
// system server crash
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify call state changed on all subscriptions.
*
* @param state latest call state. e.g, offhook, ringing
* @param incomingNumber incoming phone number.
* @hide
*/
@RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
public void notifyCallStateChangedForAllSubscriptions(@CallState int state,
@Nullable String incomingNumber) {
try {
sRegistry.notifyCallStateForAllSubs(state, incomingNumber);
} catch (RemoteException ex) {
// system server crash
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify {@link SubscriptionInfo} change.
* @hide
*/
public void notifySubscriptionInfoChanged() {
try {
sRegistry.notifySubscriptionInfoChanged();
} catch (RemoteException ex) {
// system server crash
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify opportunistic {@link SubscriptionInfo} change.
* @hide
*/
public void notifyOpportunisticSubscriptionInfoChanged() {
try {
sRegistry.notifyOpportunisticSubscriptionInfoChanged();
} catch (RemoteException ex) {
// system server crash
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify {@link ServiceState} update on certain subscription.
*
* @param slotIndex for which the service state changed. Can be derived from subId except
* subId is invalid.
* @param subId for which the service state changed.
* @param state service state e.g, in service, out of service or roaming status.
*/
public void notifyServiceStateChanged(int slotIndex, int subId, @NonNull ServiceState state) {
try {
sRegistry.notifyServiceStateForPhoneId(slotIndex, subId, state);
} catch (RemoteException ex) {
// system server crash
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify {@link SignalStrength} update on certain subscription.
*
* @param slotIndex for which the signalstrength changed. Can be derived from subId except when
* subId is invalid.
* @param subId for which the signalstrength changed.
* @param signalStrength e.g, signalstrength level {@see SignalStrength#getLevel()}
*/
public void notifySignalStrengthChanged(int slotIndex, int subId,
@NonNull SignalStrength signalStrength) {
try {
sRegistry.notifySignalStrengthForPhoneId(slotIndex, subId, signalStrength);
} catch (RemoteException ex) {
// system server crash
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify changes to the message-waiting indicator on certain subscription. e.g, The status bar
* uses message waiting indicator to determine when to display the voicemail icon.
*
* @param slotIndex for which message waiting indicator changed. Can be derived from subId
* except when subId is invalid.
* @param subId for which message waiting indicator changed.
* @param msgWaitingInd {@code true} indicates there is message-waiting indicator, {@code false}
* otherwise.
*/
public void notifyMessageWaitingChanged(int slotIndex, int subId, boolean msgWaitingInd) {
try {
sRegistry.notifyMessageWaitingChangedForPhoneId(slotIndex, subId, msgWaitingInd);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify changes to the call-forwarding status on certain subscription.
*
* @param subId for which call forwarding status changed.
* @param callForwardInd {@code true} indicates there is call forwarding, {@code false}
* otherwise.
*/
public void notifyCallForwardingChanged(int subId, boolean callForwardInd) {
try {
sRegistry.notifyCallForwardingChangedForSubscriber(subId, callForwardInd);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify changes to activity state changes on certain subscription.
*
* @param subId for which data activity state changed.
* @param dataActivityType indicates the latest data activity type e.g, {@link
* TelephonyManager#DATA_ACTIVITY_IN}
*/
public void notifyDataActivityChanged(int subId, @DataActivityType int dataActivityType) {
try {
sRegistry.notifyDataActivityForSubscriber(subId, dataActivityType);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify changes to default (Internet) data connection state on certain subscription.
*
* @param slotIndex for which data connections state changed. Can be derived from subId except
* when subId is invalid.
* @param subId for which data connection state changed.
* @param preciseState the PreciseDataConnectionState
*
* @see PreciseDataConnectionState
* @see TelephonyManager#DATA_DISCONNECTED
*/
public void notifyDataConnectionForSubscriber(int slotIndex, int subId,
@NonNull PreciseDataConnectionState preciseState) {
try {
sRegistry.notifyDataConnectionForSubscriber(
slotIndex, subId, preciseState);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify {@link CallQuality} change on certain subscription.
*
* @param slotIndex for which call quality state changed. Can be derived from subId except when
* subId is invalid.
* @param subId for which call quality state changed.
* @param callQuality Information about call quality e.g, call quality level
* @param networkType associated with this data connection. e.g, LTE
*/
public void notifyCallQualityChanged(int slotIndex, int subId, @NonNull CallQuality callQuality,
@NetworkType int networkType) {
try {
sRegistry.notifyCallQualityChanged(callQuality, slotIndex, subId, networkType);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify emergency number list changed on certain subscription.
*
* @param slotIndex for which emergency number list changed. Can be derived from subId except
* when subId is invalid.
* @param subId for which emergency number list changed.
*/
public void notifyEmergencyNumberList( int slotIndex, int subId) {
try {
sRegistry.notifyEmergencyNumberList(slotIndex, subId);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify outgoing emergency call.
* @param phoneId Sender phone ID.
* @param subId Sender subscription ID.
* @param emergencyNumber Emergency number.
*/
public void notifyOutgoingEmergencyCall(int phoneId, int subId,
@NonNull EmergencyNumber emergencyNumber) {
try {
sRegistry.notifyOutgoingEmergencyCall(phoneId, subId, emergencyNumber);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify outgoing emergency SMS.
* @param phoneId Sender phone ID.
* @param subId Sender subscription ID.
* @param emergencyNumber Emergency number.
*/
public void notifyOutgoingEmergencySms(int phoneId, int subId,
@NonNull EmergencyNumber emergencyNumber) {
try {
sRegistry.notifyOutgoingEmergencySms(phoneId, subId, emergencyNumber);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify radio power state changed on certain subscription.
*
* @param slotIndex for which radio power state changed. Can be derived from subId except when
* subId is invalid.
* @param subId for which radio power state changed.
* @param radioPowerState the current modem radio state.
*/
public void notifyRadioPowerStateChanged(int slotIndex, int subId,
@RadioPowerState int radioPowerState) {
try {
sRegistry.notifyRadioPowerStateChanged(slotIndex, subId, radioPowerState);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify {@link PhoneCapability} changed.
*
* @param phoneCapability the capability of the modem group.
*/
public void notifyPhoneCapabilityChanged(@NonNull PhoneCapability phoneCapability) {
try {
sRegistry.notifyPhoneCapabilityChanged(phoneCapability);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Sim activation type: voice
* @see #notifyVoiceActivationStateChanged
* @hide
*/
public static final int SIM_ACTIVATION_TYPE_VOICE = 0;
/**
* Sim activation type: data
* @see #notifyDataActivationStateChanged
* @hide
*/
public static final int SIM_ACTIVATION_TYPE_DATA = 1;
/**
* Notify data activation state changed on certain subscription.
* @see TelephonyManager#getDataActivationState()
*
* @param slotIndex for which data activation state changed. Can be derived from subId except
* when subId is invalid.
* @param subId for which data activation state changed.
* @param activationState sim activation state e.g, activated.
*/
public void notifyDataActivationStateChanged(int slotIndex, int subId,
@SimActivationState int activationState) {
try {
sRegistry.notifySimActivationStateChangedForPhoneId(slotIndex, subId,
SIM_ACTIVATION_TYPE_DATA, activationState);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify voice activation state changed on certain subscription.
* @see TelephonyManager#getVoiceActivationState()
*
* @param slotIndex for which voice activation state changed. Can be derived from subId except
* subId is invalid.
* @param subId for which voice activation state changed.
* @param activationState sim activation state e.g, activated.
*/
public void notifyVoiceActivationStateChanged(int slotIndex, int subId,
@SimActivationState int activationState) {
try {
sRegistry.notifySimActivationStateChangedForPhoneId(slotIndex, subId,
SIM_ACTIVATION_TYPE_VOICE, activationState);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify User mobile data state changed on certain subscription. e.g, mobile data is enabled
* or disabled.
*
* @param slotIndex for which mobile data state has changed. Can be derived from subId except
* when subId is invalid.
* @param subId for which mobile data state has changed.
* @param state {@code true} indicates mobile data is enabled/on. {@code false} otherwise.
*/
public void notifyUserMobileDataStateChanged(int slotIndex, int subId, boolean state) {
try {
sRegistry.notifyUserMobileDataStateChangedForPhoneId(slotIndex, subId, state);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify display info changed.
*
* @param slotIndex The SIM slot index for which display info has changed. Can be
* derived from {@code subscriptionId} except when {@code subscriptionId} is invalid, such as
* when the device is in emergency-only mode.
* @param subscriptionId Subscription id for which display network info has changed.
* @param telephonyDisplayInfo The display info.
*/
public void notifyDisplayInfoChanged(int slotIndex, int subscriptionId,
@NonNull TelephonyDisplayInfo telephonyDisplayInfo) {
try {
sRegistry.notifyDisplayInfoChanged(slotIndex, subscriptionId, telephonyDisplayInfo);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify IMS call disconnect causes which contains {@link android.telephony.ims.ImsReasonInfo}.
*
* @param subId for which ims call disconnect.
* @param imsReasonInfo the reason for ims call disconnect.
*/
public void notifyImsDisconnectCause(int subId, @NonNull ImsReasonInfo imsReasonInfo) {
try {
sRegistry.notifyImsDisconnectCause(subId, imsReasonInfo);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify single Radio Voice Call Continuity (SRVCC) state change for the currently active call
* on certain subscription.
*
* @param subId for which srvcc state changed.
* @param state srvcc state
*/
public void notifySrvccStateChanged(int subId, @SrvccState int state) {
try {
sRegistry.notifySrvccStateChanged(subId, state);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify precise call state changed on certain subscription, including foreground, background
* and ringcall states.
*
* @param slotIndex for which precise call state changed. Can be derived from subId except when
* subId is invalid.
* @param subId for which precise call state changed.
* @param ringCallPreciseState ringCall state.
* @param foregroundCallPreciseState foreground call state.
* @param backgroundCallPreciseState background call state.
*/
public void notifyPreciseCallState(int slotIndex, int subId,
@PreciseCallStates int ringCallPreciseState,
@PreciseCallStates int foregroundCallPreciseState,
@PreciseCallStates int backgroundCallPreciseState) {
try {
sRegistry.notifyPreciseCallState(slotIndex, subId, ringCallPreciseState,
foregroundCallPreciseState, backgroundCallPreciseState);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify call disconnect causes which contains {@link DisconnectCause} and {@link
* android.telephony.PreciseDisconnectCause}.
*
* @param slotIndex for which call disconnected. Can be derived from subId except when subId is
* invalid.
* @param subId for which call disconnected.
* @param cause {@link DisconnectCause} for the disconnected call.
* @param preciseCause {@link android.telephony.PreciseDisconnectCause} for the disconnected
* call.
*/
public void notifyDisconnectCause(int slotIndex, int subId, @DisconnectCauses int cause,
@PreciseDisconnectCauses int preciseCause) {
try {
sRegistry.notifyDisconnectCause(slotIndex, subId, cause, preciseCause);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify {@link android.telephony.CellLocation} changed.
*
* <p>To be compatible with {@link TelephonyRegistry}, use {@link CellIdentity} which is
* parcelable, and convert to CellLocation in client code.
*/
public void notifyCellLocation(int subId, @NonNull CellIdentity cellLocation) {
try {
sRegistry.notifyCellLocationForSubscriber(subId, cellLocation);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify {@link CellInfo} changed on certain subscription. e.g, when an observed cell info has
* changed or new cells have been added or removed on the given subscription.
*
* @param subId for which cellinfo changed.
* @param cellInfo A list of cellInfo associated with the given subscription.
*/
public void notifyCellInfoChanged(int subId, @NonNull List<CellInfo> cellInfo) {
try {
sRegistry.notifyCellInfoForSubscriber(subId, cellInfo);
} catch (RemoteException ex) {
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify that the active data subscription ID has changed.
* @param activeDataSubId The new subscription ID for active data
*/
public void notifyActiveDataSubIdChanged(int activeDataSubId) {
try {
sRegistry.notifyActiveDataSubIdChanged(activeDataSubId);
} catch (RemoteException ex) {
throw ex.rethrowFromSystemServer();
}
}
/**
* Report that Registration or a Location/Routing/Tracking Area update has failed.
*
* @param slotIndex for which call disconnected. Can be derived from subId except when subId is
* invalid.
* @param subId for which cellinfo changed.
* @param cellIdentity the CellIdentity, which must include the globally unique identifier
* for the cell (for example, all components of the CGI or ECGI).
* @param chosenPlmn a 5 or 6 digit alphanumeric PLMN (MCC|MNC) among those broadcast by the
* cell that was chosen for the failed registration attempt.
* @param domain DOMAIN_CS, DOMAIN_PS or both in case of a combined procedure.
* @param causeCode the primary failure cause code of the procedure.
* For GSM/UMTS (MM), values are in TS 24.008 Sec 10.5.95
* For GSM/UMTS (GMM), values are in TS 24.008 Sec 10.5.147
* For LTE (EMM), cause codes are TS 24.301 Sec 9.9.3.9
* For NR (5GMM), cause codes are TS 24.501 Sec 9.11.3.2
* Integer.MAX_VALUE if this value is unused.
* @param additionalCauseCode the cause code of any secondary/combined procedure if appropriate.
* For UMTS, if a combined attach succeeds for PS only, then the GMM cause code shall be
* included as an additionalCauseCode. For LTE (ESM), cause codes are in
* TS 24.301 9.9.4.4. Integer.MAX_VALUE if this value is unused.
*/
public void notifyRegistrationFailed(int slotIndex, int subId,
@NonNull CellIdentity cellIdentity, @NonNull String chosenPlmn,
int domain, int causeCode, int additionalCauseCode) {
try {
sRegistry.notifyRegistrationFailed(slotIndex, subId, cellIdentity,
chosenPlmn, domain, causeCode, additionalCauseCode);
} catch (RemoteException ex) {
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify {@link BarringInfo} has changed for a specific subscription.
*
* @param slotIndex for the phone object that got updated barring info.
* @param subId for which the BarringInfo changed.
* @param barringInfo updated BarringInfo.
*/
public void notifyBarringInfoChanged(
int slotIndex, int subId, @NonNull BarringInfo barringInfo) {
try {
sRegistry.notifyBarringInfoChanged(slotIndex, subId, barringInfo);
} catch (RemoteException ex) {
// system server crash
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify {@link PhysicalChannelConfig} has changed for a specific subscription.
*
* @param slotIndex for which physical channel configs changed.
* @param subId the subId
* @param configs a list of {@link PhysicalChannelConfig}, the configs of physical channel.
*/
public void notifyPhysicalChannelConfigForSubscriber(int slotIndex, int subId,
List<PhysicalChannelConfig> configs) {
try {
sRegistry.notifyPhysicalChannelConfigForSubscriber(slotIndex, subId, configs);
} catch (RemoteException ex) {
// system server crash
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify that the data enabled has changed.
*
* @param enabled True if data is enabled, otherwise disabled.
* @param reason Reason for data enabled/disabled. See {@code REASON_*} in
* {@link TelephonyManager}.
*/
public void notifyDataEnabled(int slotIndex, int subId, boolean enabled,
@TelephonyManager.DataEnabledReason int reason) {
try {
sRegistry.notifyDataEnabled(slotIndex, subId, enabled, reason);
} catch (RemoteException ex) {
// system server crash
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify the allowed network types has changed for a specific subscription and the specific
* reason.
* @param slotIndex for which allowed network types changed.
* @param subId for which allowed network types changed.
* @param reason an allowed network type reasons.
* @param allowedNetworkType an allowed network type bitmask value.
*/
public void notifyAllowedNetworkTypesChanged(int slotIndex, int subId,
int reason, long allowedNetworkType) {
try {
sRegistry.notifyAllowedNetworkTypesChanged(slotIndex, subId, reason,
allowedNetworkType);
} catch (RemoteException ex) {
// system process is dead
throw ex.rethrowFromSystemServer();
}
}
/**
* Notify that the link capacity estimate has changed.
* @param slotIndex for the phone object that gets the updated link capacity estimate
* @param subId for subscription that gets the updated link capacity estimate
* @param linkCapacityEstimateList a list of {@link LinkCapacityEstimate}
*/
public void notifyLinkCapacityEstimateChanged(int slotIndex, int subId,
List<LinkCapacityEstimate> linkCapacityEstimateList) {
try {
sRegistry.notifyLinkCapacityEstimateChanged(slotIndex, subId, linkCapacityEstimateList);
} catch (RemoteException ex) {
// system server crash
throw ex.rethrowFromSystemServer();
}
}
public @NonNull Set<Integer> getEventsFromCallback(
@NonNull TelephonyCallback telephonyCallback) {
Set<Integer> eventList = new ArraySet<>();
if (telephonyCallback instanceof TelephonyCallback.ServiceStateListener) {
eventList.add(TelephonyCallback.EVENT_SERVICE_STATE_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.MessageWaitingIndicatorListener) {
eventList.add(TelephonyCallback.EVENT_MESSAGE_WAITING_INDICATOR_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.CallForwardingIndicatorListener) {
eventList.add(TelephonyCallback.EVENT_CALL_FORWARDING_INDICATOR_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.CellLocationListener) {
eventList.add(TelephonyCallback.EVENT_CELL_LOCATION_CHANGED);
}
// Note: Legacy PhoneStateListeners use EVENT_LEGACY_CALL_STATE_CHANGED
if (telephonyCallback instanceof TelephonyCallback.CallStateListener) {
eventList.add(TelephonyCallback.EVENT_CALL_STATE_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.DataConnectionStateListener) {
eventList.add(TelephonyCallback.EVENT_DATA_CONNECTION_STATE_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.DataActivityListener) {
eventList.add(TelephonyCallback.EVENT_DATA_ACTIVITY_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.SignalStrengthsListener) {
eventList.add(TelephonyCallback.EVENT_SIGNAL_STRENGTHS_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.CellInfoListener) {
eventList.add(TelephonyCallback.EVENT_CELL_INFO_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.PreciseCallStateListener) {
eventList.add(TelephonyCallback.EVENT_PRECISE_CALL_STATE_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.CallDisconnectCauseListener) {
eventList.add(TelephonyCallback.EVENT_CALL_DISCONNECT_CAUSE_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.ImsCallDisconnectCauseListener) {
eventList.add(TelephonyCallback.EVENT_IMS_CALL_DISCONNECT_CAUSE_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.PreciseDataConnectionStateListener) {
eventList.add(TelephonyCallback.EVENT_PRECISE_DATA_CONNECTION_STATE_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.SrvccStateListener) {
eventList.add(TelephonyCallback.EVENT_SRVCC_STATE_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.VoiceActivationStateListener) {
eventList.add(TelephonyCallback.EVENT_VOICE_ACTIVATION_STATE_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.DataActivationStateListener) {
eventList.add(TelephonyCallback.EVENT_DATA_ACTIVATION_STATE_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.UserMobileDataStateListener) {
eventList.add(TelephonyCallback.EVENT_USER_MOBILE_DATA_STATE_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.DisplayInfoListener) {
eventList.add(TelephonyCallback.EVENT_DISPLAY_INFO_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.EmergencyNumberListListener) {
eventList.add(TelephonyCallback.EVENT_EMERGENCY_NUMBER_LIST_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.OutgoingEmergencyCallListener) {
eventList.add(TelephonyCallback.EVENT_OUTGOING_EMERGENCY_CALL);
}
if (telephonyCallback instanceof TelephonyCallback.OutgoingEmergencySmsListener) {
eventList.add(TelephonyCallback.EVENT_OUTGOING_EMERGENCY_SMS);
}
if (telephonyCallback instanceof TelephonyCallback.PhoneCapabilityListener) {
eventList.add(TelephonyCallback.EVENT_PHONE_CAPABILITY_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.ActiveDataSubscriptionIdListener) {
eventList.add(TelephonyCallback.EVENT_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.RadioPowerStateListener) {
eventList.add(TelephonyCallback.EVENT_RADIO_POWER_STATE_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.CarrierNetworkListener) {
eventList.add(TelephonyCallback.EVENT_CARRIER_NETWORK_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.RegistrationFailedListener) {
eventList.add(TelephonyCallback.EVENT_REGISTRATION_FAILURE);
}
if (telephonyCallback instanceof TelephonyCallback.CallAttributesListener) {
eventList.add(TelephonyCallback.EVENT_CALL_ATTRIBUTES_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.BarringInfoListener) {
eventList.add(TelephonyCallback.EVENT_BARRING_INFO_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.PhysicalChannelConfigListener) {
eventList.add(TelephonyCallback.EVENT_PHYSICAL_CHANNEL_CONFIG_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.DataEnabledListener) {
eventList.add(TelephonyCallback.EVENT_DATA_ENABLED_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.AllowedNetworkTypesListener) {
eventList.add(TelephonyCallback.EVENT_ALLOWED_NETWORK_TYPE_LIST_CHANGED);
}
if (telephonyCallback instanceof TelephonyCallback.LinkCapacityEstimateChangedListener) {
eventList.add(TelephonyCallback.EVENT_LINK_CAPACITY_ESTIMATE_CHANGED);
}
return eventList;
}
private @NonNull Set<Integer> getEventsFromBitmask(int eventMask) {
Set<Integer> eventList = new ArraySet<>();
if ((eventMask & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
eventList.add(TelephonyCallback.EVENT_SERVICE_STATE_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_SIGNAL_STRENGTH) != 0) {
eventList.add(TelephonyCallback.EVENT_SIGNAL_STRENGTH_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_MESSAGE_WAITING_INDICATOR) != 0) {
eventList.add(TelephonyCallback.EVENT_MESSAGE_WAITING_INDICATOR_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_CALL_FORWARDING_INDICATOR) != 0) {
eventList.add(TelephonyCallback.EVENT_CALL_FORWARDING_INDICATOR_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_CELL_LOCATION) != 0) {
eventList.add(TelephonyCallback.EVENT_CELL_LOCATION_CHANGED);
}
// Note: Legacy call state listeners can get the phone number which is not provided in the
// new version in TelephonyCallback.
if ((eventMask & PhoneStateListener.LISTEN_CALL_STATE) != 0) {
eventList.add(TelephonyCallback.EVENT_LEGACY_CALL_STATE_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
eventList.add(TelephonyCallback.EVENT_DATA_CONNECTION_STATE_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_DATA_ACTIVITY) != 0) {
eventList.add(TelephonyCallback.EVENT_DATA_ACTIVITY_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_SIGNAL_STRENGTHS) != 0) {
eventList.add(TelephonyCallback.EVENT_SIGNAL_STRENGTHS_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_CELL_INFO) != 0) {
eventList.add(TelephonyCallback.EVENT_CELL_INFO_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_PRECISE_CALL_STATE) != 0) {
eventList.add(TelephonyCallback.EVENT_PRECISE_CALL_STATE_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE) != 0) {
eventList.add(TelephonyCallback.EVENT_PRECISE_DATA_CONNECTION_STATE_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_DATA_CONNECTION_REAL_TIME_INFO) != 0) {
eventList.add(TelephonyCallback.EVENT_DATA_CONNECTION_REAL_TIME_INFO_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_OEM_HOOK_RAW_EVENT) != 0) {
eventList.add(TelephonyCallback.EVENT_OEM_HOOK_RAW);
}
if ((eventMask & PhoneStateListener.LISTEN_SRVCC_STATE_CHANGED) != 0) {
eventList.add(TelephonyCallback.EVENT_SRVCC_STATE_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_CARRIER_NETWORK_CHANGE) != 0) {
eventList.add(TelephonyCallback.EVENT_CARRIER_NETWORK_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_VOICE_ACTIVATION_STATE) != 0) {
eventList.add(TelephonyCallback.EVENT_VOICE_ACTIVATION_STATE_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_DATA_ACTIVATION_STATE) != 0) {
eventList.add(TelephonyCallback.EVENT_DATA_ACTIVATION_STATE_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_USER_MOBILE_DATA_STATE) != 0) {
eventList.add(TelephonyCallback.EVENT_USER_MOBILE_DATA_STATE_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_DISPLAY_INFO_CHANGED) != 0) {
eventList.add(TelephonyCallback.EVENT_DISPLAY_INFO_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE) != 0) {
eventList.add(TelephonyCallback.EVENT_PHONE_CAPABILITY_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE) != 0) {
eventList.add(TelephonyCallback.EVENT_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED) != 0) {
eventList.add(TelephonyCallback.EVENT_RADIO_POWER_STATE_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_EMERGENCY_NUMBER_LIST) != 0) {
eventList.add(TelephonyCallback.EVENT_EMERGENCY_NUMBER_LIST_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_CALL_DISCONNECT_CAUSES) != 0) {
eventList.add(TelephonyCallback.EVENT_CALL_DISCONNECT_CAUSE_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_CALL_ATTRIBUTES_CHANGED) != 0) {
eventList.add(TelephonyCallback.EVENT_CALL_ATTRIBUTES_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_IMS_CALL_DISCONNECT_CAUSES) != 0) {
eventList.add(TelephonyCallback.EVENT_IMS_CALL_DISCONNECT_CAUSE_CHANGED);
}
if ((eventMask & PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_CALL) != 0) {
eventList.add(TelephonyCallback.EVENT_OUTGOING_EMERGENCY_CALL);
}
if ((eventMask & PhoneStateListener.LISTEN_OUTGOING_EMERGENCY_SMS) != 0) {
eventList.add(TelephonyCallback.EVENT_OUTGOING_EMERGENCY_SMS);
}
if ((eventMask & PhoneStateListener.LISTEN_REGISTRATION_FAILURE) != 0) {
eventList.add(TelephonyCallback.EVENT_REGISTRATION_FAILURE);
}
if ((eventMask & PhoneStateListener.LISTEN_BARRING_INFO) != 0) {
eventList.add(TelephonyCallback.EVENT_BARRING_INFO_CHANGED);
}
return eventList;
}
/**
* Registers a callback object to receive notification of changes in specified telephony states.
* <p>
* To register a callback, pass a {@link TelephonyCallback} which implements
* interfaces of events. For example,
* FakeServiceStateCallback extends {@link TelephonyCallback} implements
* {@link TelephonyCallback.ServiceStateListener}.
*
* At registration, and when a specified telephony state changes, the telephony manager invokes
* the appropriate callback method on the callback object and passes the current (updated)
* values.
* <p>
*
* If this TelephonyManager object has been created with
* {@link TelephonyManager#createForSubscriptionId}, applies to the given subId.
* Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()}.
* To register events for multiple subIds, pass a separate callback object to
* each TelephonyManager object created with {@link TelephonyManager#createForSubscriptionId}.
*
* Note: if you call this method while in the middle of a binder transaction, you <b>must</b>
* call {@link android.os.Binder#clearCallingIdentity()} before calling this method. A
* {@link SecurityException} will be thrown otherwise.
*
* This API should be used sparingly -- large numbers of callbacks will cause system
* instability. If a process has registered too many callbacks without unregistering them, it
* may encounter an {@link IllegalStateException} when trying to register more callbacks.
*
* @param callback The {@link TelephonyCallback} object to register.
*/
public void registerTelephonyCallback(boolean renounceFineLocationAccess,
boolean renounceCoarseLocationAccess,
@NonNull @CallbackExecutor Executor executor,
int subId, String pkgName, String attributionTag, @NonNull TelephonyCallback callback,
boolean notifyNow) {
if (callback == null) {
throw new IllegalStateException("telephony service is null.");
}
callback.init(executor);
listenFromCallback(renounceFineLocationAccess, renounceCoarseLocationAccess, subId,
pkgName, attributionTag, callback,
getEventsFromCallback(callback).stream().mapToInt(i -> i).toArray(), notifyNow);
}
/**
* Unregister an existing {@link TelephonyCallback}.
*
* @param callback The {@link TelephonyCallback} object to unregister.
*/
public void unregisterTelephonyCallback(int subId, String pkgName, String attributionTag,
@NonNull TelephonyCallback callback, boolean notifyNow) {
listenFromCallback(false, false, subId,
pkgName, attributionTag, callback, new int[0], notifyNow);
}
private static class CarrierPrivilegesCallbackWrapper extends ICarrierPrivilegesCallback.Stub
implements ListenerExecutor {
@NonNull private final WeakReference<CarrierPrivilegesCallback> mCallback;
@NonNull private final Executor mExecutor;
CarrierPrivilegesCallbackWrapper(
@NonNull CarrierPrivilegesCallback callback, @NonNull Executor executor) {
mCallback = new WeakReference<>(callback);
mExecutor = executor;
}
@Override
public void onCarrierPrivilegesChanged(
@NonNull List<String> privilegedPackageNames, @NonNull int[] privilegedUids) {
// AIDL interface does not support Set, keep the List/Array and translate them here
Set<String> privilegedPkgNamesSet = Set.copyOf(privilegedPackageNames);
Set<Integer> privilegedUidsSet = Arrays.stream(privilegedUids).boxed().collect(
Collectors.toSet());
Binder.withCleanCallingIdentity(
() ->
executeSafely(
mExecutor,
mCallback::get,
cpc ->
cpc.onCarrierPrivilegesChanged(
privilegedPkgNamesSet, privilegedUidsSet)));
}
@Override
public void onCarrierServiceChanged(@Nullable String packageName, int uid) {
Binder.withCleanCallingIdentity(
() ->
executeSafely(
mExecutor,
mCallback::get,
cpc -> cpc.onCarrierServiceChanged(packageName, uid)));
}
}
@NonNull
@GuardedBy("sCarrierPrivilegeCallbacks")
private static final WeakHashMap<CarrierPrivilegesCallback,
WeakReference<CarrierPrivilegesCallbackWrapper>>
sCarrierPrivilegeCallbacks = new WeakHashMap<>();
/**
* Registers a {@link CarrierPrivilegesCallback} on the given {@code logicalSlotIndex} to
* receive callbacks when the set of packages with carrier privileges changes. The callback will
* immediately be called with the latest state.
*
* @param logicalSlotIndex The SIM slot to listen on
* @param executor The executor where {@code listener} will be invoked
* @param callback The callback to register
*/
public void addCarrierPrivilegesCallback(
int logicalSlotIndex,
@NonNull @CallbackExecutor Executor executor,
@NonNull CarrierPrivilegesCallback callback) {
if (callback == null || executor == null) {
throw new IllegalArgumentException("callback and executor must be non-null");
}
synchronized (sCarrierPrivilegeCallbacks) {
WeakReference<CarrierPrivilegesCallbackWrapper> existing =
sCarrierPrivilegeCallbacks.get(callback);
if (existing != null && existing.get() != null) {
Log.d(TAG, "addCarrierPrivilegesCallback: callback already registered");
return;
}
CarrierPrivilegesCallbackWrapper wrapper =
new CarrierPrivilegesCallbackWrapper(callback, executor);
sCarrierPrivilegeCallbacks.put(callback, new WeakReference<>(wrapper));
try {
sRegistry.addCarrierPrivilegesCallback(
logicalSlotIndex,
wrapper,
mContext.getOpPackageName(),
mContext.getAttributionTag());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
/**
* Unregisters a {@link CarrierPrivilegesCallback}.
*
* @param callback The callback to unregister
*/
public void removeCarrierPrivilegesCallback(@NonNull CarrierPrivilegesCallback callback) {
if (callback == null) {
throw new IllegalArgumentException("listener must be non-null");
}
synchronized (sCarrierPrivilegeCallbacks) {
WeakReference<CarrierPrivilegesCallbackWrapper> ref =
sCarrierPrivilegeCallbacks.remove(callback);
if (ref == null) return;
CarrierPrivilegesCallbackWrapper wrapper = ref.get();
if (wrapper == null) return;
try {
sRegistry.removeCarrierPrivilegesCallback(wrapper, mContext.getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
/**
* Notify listeners that the set of packages with carrier privileges has changed.
*
* @param logicalSlotIndex The SIM slot the change occurred on
* @param privilegedPackageNames The updated set of packages names with carrier privileges
* @param privilegedUids The updated set of UIDs with carrier privileges
*/
public void notifyCarrierPrivilegesChanged(
int logicalSlotIndex,
@NonNull Set<String> privilegedPackageNames,
@NonNull Set<Integer> privilegedUids) {
if (privilegedPackageNames == null || privilegedUids == null) {
throw new IllegalArgumentException(
"privilegedPackageNames and privilegedUids must be non-null");
}
try {
// AIDL doesn't support Set yet. Convert Set to List/Array
List<String> pkgList = List.copyOf(privilegedPackageNames);
int[] uids = privilegedUids.stream().mapToInt(Number::intValue).toArray();
sRegistry.notifyCarrierPrivilegesChanged(logicalSlotIndex, pkgList, uids);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Notify listeners that the {@link CarrierService} for current user has changed.
*
* @param logicalSlotIndex the SIM slot the change occurred on
* @param packageName the package name of the changed {@link CarrierService}
* @param uid the UID of the changed {@link CarrierService}
*/
public void notifyCarrierServiceChanged(int logicalSlotIndex, @Nullable String packageName,
int uid) {
try {
sRegistry.notifyCarrierServiceChanged(logicalSlotIndex, packageName, uid);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Register a {@link android.telephony.CarrierConfigManager.CarrierConfigChangeListener} to get
* notification when carrier configurations have changed.
*
* @param executor The executor on which the callback will be executed.
* @param listener The CarrierConfigChangeListener to be registered with.
*/
public void addCarrierConfigChangedListener(
@NonNull @CallbackExecutor Executor executor,
@NonNull CarrierConfigManager.CarrierConfigChangeListener listener) {
Objects.requireNonNull(executor, "Executor should be non-null.");
Objects.requireNonNull(listener, "Listener should be non-null.");
if (mCarrierConfigChangeListenerMap.get(listener) != null) {
Log.e(TAG, "registerCarrierConfigChangeListener: listener already present");
return;
}
ICarrierConfigChangeListener callback = new ICarrierConfigChangeListener.Stub() {
@Override
public void onCarrierConfigChanged(int slotIndex, int subId, int carrierId,
int specificCarrierId) {
Log.d(TAG, "onCarrierConfigChanged call in ICarrierConfigChangeListener callback");
final long identify = Binder.clearCallingIdentity();
try {
executor.execute(() -> listener.onCarrierConfigChanged(slotIndex, subId,
carrierId, specificCarrierId));
} finally {
Binder.restoreCallingIdentity(identify);
}
}
};
try {
sRegistry.addCarrierConfigChangeListener(callback,
mContext.getOpPackageName(), mContext.getAttributionTag());
mCarrierConfigChangeListenerMap.put(listener, callback);
} catch (RemoteException re) {
// system server crashes
throw re.rethrowFromSystemServer();
}
}
/**
* Unregister to stop the notification when carrier configurations changed.
*
* @param listener The CarrierConfigChangeListener to be unregistered with.
*/
public void removeCarrierConfigChangedListener(
@NonNull CarrierConfigManager.CarrierConfigChangeListener listener) {
Objects.requireNonNull(listener, "Listener should be non-null.");
if (mCarrierConfigChangeListenerMap.get(listener) == null) {
Log.e(TAG, "removeCarrierConfigChangedListener: listener was not present");
return;
}
try {
sRegistry.removeCarrierConfigChangeListener(
mCarrierConfigChangeListenerMap.get(listener), mContext.getOpPackageName());
mCarrierConfigChangeListenerMap.remove(listener);
} catch (RemoteException re) {
// System sever crashes
throw re.rethrowFromSystemServer();
}
}
/**
* Notify the registrants the carrier configurations have changed.
*
* @param slotIndex The SIM slot index on which to monitor and get notification.
* @param subId The subscription on the SIM slot. May be
* {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID}.
* @param carrierId The optional carrier Id, may be
* {@link TelephonyManager#UNKNOWN_CARRIER_ID}.
* @param specificCarrierId The optional specific carrier Id, may be {@link
* TelephonyManager#UNKNOWN_CARRIER_ID}.
*/
public void notifyCarrierConfigChanged(int slotIndex, int subId, int carrierId,
int specificCarrierId) {
// Only validate slotIndex, all others are optional and allowed to be invalid
if (!SubscriptionManager.isValidPhoneId(slotIndex)) {
Log.e(TAG, "notifyCarrierConfigChanged, ignored: invalid slotIndex " + slotIndex);
return;
}
try {
sRegistry.notifyCarrierConfigChanged(slotIndex, subId, carrierId, specificCarrierId);
} catch (RemoteException re) {
throw re.rethrowFromSystemServer();
}
}
}
|