SubscriptionManager.java revision 7a96207e2ba549843e9fcbbc7f2fde7ed96ada84
1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.telephony; 18 19import android.annotation.SdkConstant; 20import android.annotation.SdkConstant.SdkConstantType; 21import android.content.Intent; 22import android.net.Uri; 23import android.provider.BaseColumns; 24import android.telephony.Rlog; 25import android.os.ServiceManager; 26import android.os.RemoteException; 27 28import com.android.internal.telephony.ISub; 29import com.android.internal.telephony.PhoneConstants; 30 31import java.util.List; 32 33/** 34 * SubscriptionManager is the application interface to SubscriptionController 35 * and provides information about the current Telephony Subscriptions. 36 * 37 * @hide 38 */ 39public class SubscriptionManager implements BaseColumns { 40 private static final String LOG_TAG = "SUB"; 41 private static final boolean DBG = true; 42 private static final boolean VDBG = false; 43 44 // An invalid phone identifier 45 /** @hide */ 46 public static final int INVALID_PHONE_ID = -1000; 47 48 // Indicates the caller wants the default phone id. 49 /** @hide */ 50 public static final int DEFAULT_PHONE_ID = Integer.MAX_VALUE; 51 52 // An invalid slot identifier 53 /** @hide */ 54 public static final int INVALID_SLOT_ID = -1000; 55 56 // Indicates the caller wants the default slot id. 57 /** @hide */ 58 public static final int DEFAULT_SLOT_ID = Integer.MAX_VALUE; 59 60 // An invalid subscription identifier 61 /** @hide */ 62 public static final long INVALID_SUB_ID = -1000; 63 64 // Indicates the user should be asked which sub to use. 65 /** @hide */ 66 public static final long ASK_USER_SUB_ID = -1001; 67 68 // Indicates the caller wants the default sub id. 69 /** @hide */ 70 public static final long DEFAULT_SUB_ID = Long.MAX_VALUE; 71 72 /** @hide */ 73 public static final Uri CONTENT_URI = Uri.parse("content://telephony/siminfo"); 74 75 /** @hide */ 76 public static final int DEFAULT_INT_VALUE = -100; 77 78 /** @hide */ 79 public static final String DEFAULT_STRING_VALUE = "N/A"; 80 81 /** @hide */ 82 public static final int EXTRA_VALUE_NEW_SIM = 1; 83 84 /** @hide */ 85 public static final int EXTRA_VALUE_REMOVE_SIM = 2; 86 /** @hide */ 87 public static final int EXTRA_VALUE_REPOSITION_SIM = 3; 88 /** @hide */ 89 public static final int EXTRA_VALUE_NOCHANGE = 4; 90 91 /** @hide */ 92 public static final String INTENT_KEY_DETECT_STATUS = "simDetectStatus"; 93 /** @hide */ 94 public static final String INTENT_KEY_SIM_COUNT = "simCount"; 95 /** @hide */ 96 public static final String INTENT_KEY_NEW_SIM_SLOT = "newSIMSlot"; 97 /** @hide */ 98 public static final String INTENT_KEY_NEW_SIM_STATUS = "newSIMStatus"; 99 100 /** 101 * The ICC ID of a SIM. 102 * <P>Type: TEXT (String)</P> 103 */ 104 /** @hide */ 105 public static final String ICC_ID = "icc_id"; 106 107 /** 108 * <P>Type: INTEGER (int)</P> 109 */ 110 /** @hide */ 111 public static final String SIM_ID = "sim_id"; 112 /** @hide */ 113 public static final int SIM_NOT_INSERTED = -1; 114 115 /** 116 * The display name of a SIM. 117 * <P>Type: TEXT (String)</P> 118 */ 119 /** @hide */ 120 public static final String DISPLAY_NAME = "display_name"; 121 122 /** @hide */ 123 public static final int DEFAULT_NAME_RES = com.android.internal.R.string.unknownName; 124 125 /** 126 * The display name source of a SIM. 127 * <P>Type: INT (int)</P> 128 */ 129 /** @hide */ 130 public static final String NAME_SOURCE = "name_source"; 131 132 /** @hide */ 133 public static final int NAME_SOURCE_UNDEFINDED = -1; 134 135 /** @hide */ 136 public static final int NAME_SOURCE_DEFAULT_SOURCE = 0; 137 138 /** @hide */ 139 public static final int NAME_SOURCE_SIM_SOURCE = 1; 140 141 /** @hide */ 142 public static final int NAME_SOURCE_USER_INPUT = 2; 143 144 /** 145 * The color of a SIM. 146 * <P>Type: INTEGER (int)</P> 147 */ 148 /** @hide */ 149 public static final String COLOR = "color"; 150 151 /** @hide */ 152 public static final int COLOR_1 = 0; 153 154 /** @hide */ 155 public static final int COLOR_2 = 1; 156 157 /** @hide */ 158 public static final int COLOR_3 = 2; 159 160 /** @hide */ 161 public static final int COLOR_4 = 3; 162 163 /** @hide */ 164 public static final int COLOR_DEFAULT = COLOR_1; 165 166 /** 167 * The phone number of a SIM. 168 * <P>Type: TEXT (String)</P> 169 */ 170 /** @hide */ 171 public static final String NUMBER = "number"; 172 173 /** 174 * The number display format of a SIM. 175 * <P>Type: INTEGER (int)</P> 176 */ 177 /** @hide */ 178 public static final String DISPLAY_NUMBER_FORMAT = "display_number_format"; 179 180 /** @hide */ 181 public static final int DISPLAY_NUMBER_NONE = 0; 182 183 /** @hide */ 184 public static final int DISPLAY_NUMBER_FIRST = 1; 185 186 /** @hide */ 187 public static final int DISPLAY_NUMBER_LAST = 2; 188 189 /** @hide */ 190 public static final int DISLPAY_NUMBER_DEFAULT = DISPLAY_NUMBER_FIRST; 191 192 /** 193 * Permission for data roaming of a SIM. 194 * <P>Type: INTEGER (int)</P> 195 */ 196 /** @hide */ 197 public static final String DATA_ROAMING = "data_roaming"; 198 199 /** @hide */ 200 public static final int DATA_ROAMING_ENABLE = 1; 201 202 /** @hide */ 203 public static final int DATA_ROAMING_DISABLE = 0; 204 205 /** @hide */ 206 public static final int DATA_ROAMING_DEFAULT = DATA_ROAMING_DISABLE; 207 208 /** 209 * The MCC associated with a SIM. 210 * <P>Type: INTEGER (int)</P> 211 */ 212 public static final String MCC = "mcc"; 213 214 /** 215 * The MNC associated with a SIM. 216 * <P>Type: INTEGER (int)</P> 217 */ 218 public static final String MNC = "mnc"; 219 220 221 private static final int RES_TYPE_BACKGROUND_DARK = 0; 222 223 private static final int RES_TYPE_BACKGROUND_LIGHT = 1; 224 225 private static final int[] sSimBackgroundDarkRes = setSimResource(RES_TYPE_BACKGROUND_DARK); 226 227 /** 228 * Broadcast Action: The user has changed one of the default subs related to 229 * data, phone calls, or sms</p> 230 * @hide 231 */ 232 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 233 public static final String SUB_DEFAULT_CHANGED_ACTION = 234 "android.intent.action.SUB_DEFAULT_CHANGED"; 235 236 /** @hide */ 237 public SubscriptionManager() { 238 if (DBG) logd("SubscriptionManager created"); 239 } 240 241 /** 242 * Get the SubInfoRecord according to an index 243 * @param subId The unique SubInfoRecord index in database 244 * @return SubInfoRecord, maybe null 245 * @hide 246 */ 247 public static SubInfoRecord getSubInfoUsingSubId(long subId) { 248 if (!isValidSubId(subId)) { 249 logd("[getSubInfoUsingSubIdx]- invalid subId"); 250 return null; 251 } 252 253 SubInfoRecord subInfo = null; 254 255 try { 256 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 257 if (iSub != null) { 258 subInfo = iSub.getSubInfoUsingSubId(subId); 259 } 260 } catch (RemoteException ex) { 261 // ignore it 262 } 263 264 return subInfo; 265 266 } 267 268 /** 269 * Get the SubInfoRecord according to an IccId 270 * @param iccId the IccId of SIM card 271 * @return SubInfoRecord, maybe null 272 * @hide 273 */ 274 public static List<SubInfoRecord> getSubInfoUsingIccId(String iccId) { 275 if (VDBG) logd("[getSubInfoUsingIccId]+ iccId=" + iccId); 276 if (iccId == null) { 277 logd("[getSubInfoUsingIccId]- null iccid"); 278 return null; 279 } 280 281 List<SubInfoRecord> result = null; 282 283 try { 284 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 285 if (iSub != null) { 286 result = iSub.getSubInfoUsingIccId(iccId); 287 } 288 } catch (RemoteException ex) { 289 // ignore it 290 } 291 292 return result; 293 } 294 295 /** 296 * Get the SubInfoRecord according to slotId 297 * @param slotId the slot which the SIM is inserted 298 * @return SubInfoRecord, maybe null 299 * @hide 300 */ 301 public static List<SubInfoRecord> getSubInfoUsingSlotId(int slotId) { 302 // FIXME: Consider never returning null 303 if (!isValidSlotId(slotId)) { 304 logd("[getSubInfoUsingSlotId]- invalid slotId"); 305 return null; 306 } 307 308 List<SubInfoRecord> result = null; 309 310 try { 311 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 312 if (iSub != null) { 313 result = iSub.getSubInfoUsingSlotId(slotId); 314 } 315 } catch (RemoteException ex) { 316 // ignore it 317 } 318 319 return result; 320 } 321 322 /** 323 * Get all the SubInfoRecord(s) in subinfo database 324 * @return Array list of all SubInfoRecords in database, include thsoe that were inserted before 325 * @hide 326 */ 327 public static List<SubInfoRecord> getAllSubInfoList() { 328 if (VDBG) logd("[getAllSubInfoList]+"); 329 330 List<SubInfoRecord> result = null; 331 332 try { 333 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 334 if (iSub != null) { 335 result = iSub.getAllSubInfoList(); 336 } 337 } catch (RemoteException ex) { 338 // ignore it 339 } 340 341 return result; 342 } 343 344 /** 345 * Get the SubInfoRecord(s) of the currently inserted SIM(s) 346 * @return Array list of currently inserted SubInfoRecord(s) 347 * @hide 348 */ 349 public static List<SubInfoRecord> getActiveSubInfoList() { 350 List<SubInfoRecord> result = null; 351 352 try { 353 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 354 if (iSub != null) { 355 result = iSub.getActiveSubInfoList(); 356 } 357 } catch (RemoteException ex) { 358 // ignore it 359 } 360 361 return result; 362 } 363 364 /** 365 * Get the SUB count of all SUB(s) in subinfo database 366 * @return all SIM count in database, include what was inserted before 367 * @hide 368 */ 369 public static int getAllSubInfoCount() { 370 if (VDBG) logd("[getAllSubInfoCount]+"); 371 372 int result = 0; 373 374 try { 375 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 376 if (iSub != null) { 377 result = iSub.getAllSubInfoCount(); 378 } 379 } catch (RemoteException ex) { 380 // ignore it 381 } 382 383 return result; 384 } 385 386 /** 387 * Get the count of active SUB(s) 388 * @return active SIM count 389 * @hide 390 */ 391 public static int getActiveSubInfoCount() { 392 int result = 0; 393 394 try { 395 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 396 if (iSub != null) { 397 result = iSub.getActiveSubInfoCount(); 398 } 399 } catch (RemoteException ex) { 400 // ignore it 401 } 402 403 return result; 404 } 405 406 /** 407 * Add a new SubInfoRecord to subinfo database if needed 408 * @param iccId the IccId of the SIM card 409 * @param slotId the slot which the SIM is inserted 410 * @return the URL of the newly created row or the updated row 411 * @hide 412 */ 413 public static Uri addSubInfoRecord(String iccId, int slotId) { 414 if (VDBG) logd("[addSubInfoRecord]+ iccId:" + iccId + " slotId:" + slotId); 415 if (iccId == null) { 416 logd("[addSubInfoRecord]- null iccId"); 417 } 418 if (!isValidSlotId(slotId)) { 419 logd("[addSubInfoRecord]- invalid slotId"); 420 } 421 422 try { 423 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 424 if (iSub != null) { 425 // FIXME: This returns 1 on success, 0 on error should should we return it? 426 iSub.addSubInfoRecord(iccId, slotId); 427 } 428 } catch (RemoteException ex) { 429 // ignore it 430 } 431 432 // FIXME: Always returns null? 433 return null; 434 435 } 436 437 /** 438 * Set SIM color by simInfo index 439 * @param color the color of the SIM 440 * @param subId the unique SubInfoRecord index in database 441 * @return the number of records updated 442 * @hide 443 */ 444 public static int setColor(int color, long subId) { 445 if (VDBG) logd("[setColor]+ color:" + color + " subId:" + subId); 446 int size = sSimBackgroundDarkRes.length; 447 if (!isValidSubId(subId) || color < 0 || color >= size) { 448 logd("[setColor]- fail"); 449 return -1; 450 } 451 452 int result = 0; 453 454 try { 455 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 456 if (iSub != null) { 457 result = iSub.setColor(color, subId); 458 } 459 } catch (RemoteException ex) { 460 // ignore it 461 } 462 463 return result; 464 465 } 466 467 /** 468 * Set display name by simInfo index 469 * @param displayName the display name of SIM card 470 * @param subId the unique SubInfoRecord index in database 471 * @return the number of records updated 472 * @hide 473 */ 474 public static int setDisplayName(String displayName, long subId) { 475 return setDisplayName(displayName, subId, NAME_SOURCE_UNDEFINDED); 476 } 477 478 /** 479 * Set display name by simInfo index with name source 480 * @param displayName the display name of SIM card 481 * @param subId the unique SubInfoRecord index in database 482 * @param nameSource 0: NAME_SOURCE_DEFAULT_SOURCE, 1: NAME_SOURCE_SIM_SOURCE, 483 * 2: NAME_SOURCE_USER_INPUT, -1 NAME_SOURCE_UNDEFINED 484 * @return the number of records updated or -1 if invalid subId 485 * @hide 486 */ 487 public static int setDisplayName(String displayName, long subId, long nameSource) { 488 if (VDBG) { 489 logd("[setDisplayName]+ displayName:" + displayName + " subId:" + subId 490 + " nameSource:" + nameSource); 491 } 492 if (!isValidSubId(subId)) { 493 logd("[setDisplayName]- fail"); 494 return -1; 495 } 496 497 int result = 0; 498 499 try { 500 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 501 if (iSub != null) { 502 result = iSub.setDisplayNameUsingSrc(displayName, subId, nameSource); 503 } 504 } catch (RemoteException ex) { 505 // ignore it 506 } 507 508 return result; 509 510 } 511 512 /** 513 * Set phone number by subId 514 * @param number the phone number of the SIM 515 * @param subId the unique SubInfoRecord index in database 516 * @return the number of records updated 517 * @hide 518 */ 519 public static int setDisplayNumber(String number, long subId) { 520 if (number == null || !isValidSubId(subId)) { 521 logd("[setDisplayNumber]- fail"); 522 return -1; 523 } 524 525 int result = 0; 526 527 try { 528 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 529 if (iSub != null) { 530 result = iSub.setDisplayNumber(number, subId); 531 } 532 } catch (RemoteException ex) { 533 // ignore it 534 } 535 536 return result; 537 538 } 539 540 /** 541 * Set number display format. 0: none, 1: the first four digits, 2: the last four digits 542 * @param format the display format of phone number 543 * @param subId the unique SubInfoRecord index in database 544 * @return the number of records updated 545 * @hide 546 */ 547 public static int setDisplayNumberFormat(int format, long subId) { 548 if (VDBG) logd("[setDisplayNumberFormat]+ format:" + format + " subId:" + subId); 549 if (format < 0 || !isValidSubId(subId)) { 550 logd("[setDisplayNumberFormat]- fail, return -1"); 551 return -1; 552 } 553 554 int result = 0; 555 556 try { 557 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 558 if (iSub != null) { 559 result = iSub.setDisplayNumberFormat(format, subId); 560 } 561 } catch (RemoteException ex) { 562 // ignore it 563 } 564 565 return result; 566 567 } 568 569 /** 570 * Set data roaming by simInfo index 571 * @param roaming 0:Don't allow data when roaming, 1:Allow data when roaming 572 * @param subId the unique SubInfoRecord index in database 573 * @return the number of records updated 574 * @hide 575 */ 576 public static int setDataRoaming(int roaming, long subId) { 577 if (VDBG) logd("[setDataRoaming]+ roaming:" + roaming + " subId:" + subId); 578 if (roaming < 0 || !isValidSubId(subId)) { 579 logd("[setDataRoaming]- fail"); 580 return -1; 581 } 582 583 int result = 0; 584 585 try { 586 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 587 if (iSub != null) { 588 result = iSub.setDataRoaming(roaming, subId); 589 } 590 } catch (RemoteException ex) { 591 // ignore it 592 } 593 594 return result; 595 } 596 597 /** @hide */ 598 public static int getSlotId(long subId) { 599 if (!isValidSubId(subId)) { 600 logd("[getSlotId]- fail"); 601 } 602 603 int result = INVALID_SLOT_ID; 604 605 try { 606 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 607 if (iSub != null) { 608 result = iSub.getSlotId(subId); 609 } 610 } catch (RemoteException ex) { 611 // ignore it 612 } 613 614 return result; 615 616 } 617 618 /** @hide */ 619 public static long[] getSubId(int slotId) { 620 if (!isValidSlotId(slotId)) { 621 logd("[getSubId]- fail"); 622 return null; 623 } 624 625 long[] subId = null; 626 627 try { 628 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 629 if (iSub != null) { 630 subId = iSub.getSubId(slotId); 631 } 632 } catch (RemoteException ex) { 633 // ignore it 634 } 635 636 return subId; 637 } 638 639 /** @hide */ 640 public static int getPhoneId(long subId) { 641 if (!isValidSubId(subId)) { 642 logd("[getPhoneId]- fail"); 643 return INVALID_PHONE_ID; 644 } 645 646 int result = INVALID_PHONE_ID; 647 648 try { 649 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 650 if (iSub != null) { 651 result = iSub.getPhoneId(subId); 652 } 653 } catch (RemoteException ex) { 654 // ignore it 655 } 656 657 if (VDBG) logd("[getPhoneId]- phoneId=" + result); 658 return result; 659 660 } 661 662 private static int[] setSimResource(int type) { 663 int[] simResource = null; 664 665 switch (type) { 666 case RES_TYPE_BACKGROUND_DARK: 667 simResource = new int[] { 668 com.android.internal.R.drawable.sim_dark_blue, 669 com.android.internal.R.drawable.sim_dark_orange, 670 com.android.internal.R.drawable.sim_dark_green, 671 com.android.internal.R.drawable.sim_dark_purple 672 }; 673 break; 674 case RES_TYPE_BACKGROUND_LIGHT: 675 simResource = new int[] { 676 com.android.internal.R.drawable.sim_light_blue, 677 com.android.internal.R.drawable.sim_light_orange, 678 com.android.internal.R.drawable.sim_light_green, 679 com.android.internal.R.drawable.sim_light_purple 680 }; 681 break; 682 } 683 684 return simResource; 685 } 686 687 private static void logd(String msg) { 688 Rlog.d(LOG_TAG, "[SubManager] " + msg); 689 } 690 691 /** 692 * @return the "system" defaultSubId on a voice capable device this 693 * will be getDefaultVoiceSubId() and on a data only device it will be 694 * getDefaultDataSubId(). 695 * @hide 696 */ 697 public static long getDefaultSubId() { 698 long subId = INVALID_SUB_ID; 699 700 try { 701 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 702 if (iSub != null) { 703 subId = iSub.getDefaultSubId(); 704 } 705 } catch (RemoteException ex) { 706 // ignore it 707 } 708 709 if (VDBG) logd("getDefaultSubId=" + subId); 710 return subId; 711 } 712 713 /** @hide */ 714 public static long getDefaultVoiceSubId() { 715 long subId = INVALID_SUB_ID; 716 717 try { 718 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 719 if (iSub != null) { 720 subId = iSub.getDefaultVoiceSubId(); 721 } 722 } catch (RemoteException ex) { 723 // ignore it 724 } 725 726 if (VDBG) logd("getDefaultVoiceSubId, sub id = " + subId); 727 return subId; 728 } 729 730 /** @hide */ 731 public static void setDefaultVoiceSubId(long subId) { 732 if (VDBG) logd("setDefaultVoiceSubId sub id = " + subId); 733 try { 734 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 735 if (iSub != null) { 736 iSub.setDefaultVoiceSubId(subId); 737 } 738 } catch (RemoteException ex) { 739 // ignore it 740 } 741 } 742 743 /** @hide */ 744 public static SubInfoRecord getDefaultVoiceSubInfo() { 745 return getSubInfoUsingSubId(getDefaultVoiceSubId()); 746 } 747 748 /** @hide */ 749 public static int getDefaultVoicePhoneId() { 750 return getPhoneId(getDefaultVoiceSubId()); 751 } 752 753 /** @hide */ 754 public static long getDefaultSmsSubId() { 755 long subId = INVALID_SUB_ID; 756 757 try { 758 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 759 if (iSub != null) { 760 subId = iSub.getDefaultSmsSubId(); 761 } 762 } catch (RemoteException ex) { 763 // ignore it 764 } 765 766 if (VDBG) logd("getDefaultSmsSubId, sub id = " + subId); 767 return subId; 768 } 769 770 /** @hide */ 771 public static void setDefaultSmsSubId(long subId) { 772 if (VDBG) logd("setDefaultSmsSubId sub id = " + subId); 773 try { 774 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 775 if (iSub != null) { 776 iSub.setDefaultSmsSubId(subId); 777 } 778 } catch (RemoteException ex) { 779 // ignore it 780 } 781 } 782 783 /** @hide */ 784 public static SubInfoRecord getDefaultSmsSubInfo() { 785 return getSubInfoUsingSubId(getDefaultSmsSubId()); 786 } 787 788 /** @hide */ 789 public static int getDefaultSmsPhoneId() { 790 return getPhoneId(getDefaultSmsSubId()); 791 } 792 793 /** @hide */ 794 public static long getDefaultDataSubId() { 795 long subId = INVALID_SUB_ID; 796 797 try { 798 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 799 if (iSub != null) { 800 subId = iSub.getDefaultDataSubId(); 801 } 802 } catch (RemoteException ex) { 803 // ignore it 804 } 805 806 if (VDBG) logd("getDefaultDataSubId, sub id = " + subId); 807 return subId; 808 } 809 810 /** @hide */ 811 public static void setDefaultDataSubId(long subId) { 812 if (VDBG) logd("setDataSubscription sub id = " + subId); 813 try { 814 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 815 if (iSub != null) { 816 iSub.setDefaultDataSubId(subId); 817 } 818 } catch (RemoteException ex) { 819 // ignore it 820 } 821 } 822 823 /** @hide */ 824 public static SubInfoRecord getDefaultDataSubInfo() { 825 return getSubInfoUsingSubId(getDefaultDataSubId()); 826 } 827 828 /** @hide */ 829 public static int getDefaultDataPhoneId() { 830 return getPhoneId(getDefaultDataSubId()); 831 } 832 833 /** @hide */ 834 public static void clearSubInfo() { 835 try { 836 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 837 if (iSub != null) { 838 iSub.clearSubInfo(); 839 } 840 } catch (RemoteException ex) { 841 // ignore it 842 } 843 844 return; 845 } 846 847 //FIXME this is vulnerable to race conditions 848 /** @hide */ 849 public static boolean allDefaultsSelected() { 850 if (getDefaultDataSubId() == INVALID_SUB_ID) { 851 return false; 852 } 853 if (getDefaultSmsSubId() == INVALID_SUB_ID) { 854 return false; 855 } 856 if (getDefaultVoiceSubId() == INVALID_SUB_ID) { 857 return false; 858 } 859 return true; 860 } 861 862 /** 863 * If a default is set to subscription which is not active, this will reset that default back to 864 * INVALID_SUB_ID. 865 * @hide 866 */ 867 public static void clearDefaultsForInactiveSubIds() { 868 if (VDBG) logd("clearDefaultsForInactiveSubIds"); 869 try { 870 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 871 if (iSub != null) { 872 iSub.clearDefaultsForInactiveSubIds(); 873 } 874 } catch (RemoteException ex) { 875 // ignore it 876 } 877 } 878 879 /** @hide */ 880 public static boolean isValidSubId(long subId) { 881 return subId > INVALID_SUB_ID ; 882 } 883 884 /** @hide */ 885 public static boolean isValidSlotId(int slotId) { 886 return slotId > INVALID_SLOT_ID && slotId < TelephonyManager.getDefault().getSimCount(); 887 } 888 889 /** @hide */ 890 public static boolean isValidPhoneId(int phoneId) { 891 return phoneId > INVALID_PHONE_ID 892 && phoneId < TelephonyManager.getDefault().getPhoneCount(); 893 } 894 895 /** @hide */ 896 public static void putPhoneIdAndSubIdExtra(Intent intent, int phoneId) { 897 long[] subIds = SubscriptionManager.getSubId(phoneId); 898 if (subIds != null && subIds.length > 0) { 899 putPhoneIdAndSubIdExtra(intent, phoneId, subIds[0]); 900 } else { 901 logd("putPhoneIdAndSubIdExtra: no valid subs"); 902 } 903 } 904 905 /** @hide */ 906 public static void putPhoneIdAndSubIdExtra(Intent intent, int phoneId, long subId) { 907 if (VDBG) logd("putPhoneIdAndSubIdExtra: phoneId=" + phoneId + " subId=" + subId); 908 intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, subId); 909 intent.putExtra(PhoneConstants.PHONE_KEY, phoneId); 910 //FIXME this is using phoneId and slotId interchangeably 911 //Eventually, this should be removed as it is not the slot id 912 intent.putExtra(PhoneConstants.SLOT_KEY, phoneId); 913 } 914 915 /** 916 * @return the list of subId's that are active, 917 * is never null but the length maybe 0. 918 * @hide 919 */ 920 public static long[] getActiveSubIdList() { 921 long[] subId = null; 922 923 try { 924 ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub")); 925 if (iSub != null) { 926 subId = iSub.getActiveSubIdList(); 927 } 928 } catch (RemoteException ex) { 929 // ignore it 930 } 931 932 if (subId == null) { 933 subId = new long[0]; 934 } 935 936 return subId; 937 938 } 939} 940 941