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