Home | History | Annotate | Download | only in telephony
      1 /*
      2  * Copyright (C) 2006 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 
     17 package com.android.internal.telephony;
     18 
     19 import android.os.AsyncResult;
     20 import android.os.Handler;
     21 import android.os.Message;
     22 import android.os.Registrant;
     23 import android.os.RegistrantList;
     24 
     25 import com.android.internal.telephony.gsm.UsimServiceTable;
     26 import com.android.internal.telephony.ims.IsimRecords;
     27 
     28 /**
     29  * {@hide}
     30  */
     31 public abstract class IccRecords extends Handler implements IccConstants {
     32 
     33     protected static final boolean DBG = true;
     34     // ***** Instance Variables
     35 
     36     protected PhoneBase phone;
     37     protected RegistrantList recordsLoadedRegistrants = new RegistrantList();
     38 
     39     protected int recordsToLoad;  // number of pending load requests
     40 
     41     protected AdnRecordCache adnCache;
     42 
     43     // ***** Cached SIM State; cleared on channel close
     44 
     45     protected boolean recordsRequested = false; // true if we've made requests for the sim records
     46 
     47     public String iccid;
     48     protected String msisdn = null;  // My mobile number
     49     protected String msisdnTag = null;
     50     protected String voiceMailNum = null;
     51     protected String voiceMailTag = null;
     52     protected String newVoiceMailNum = null;
     53     protected String newVoiceMailTag = null;
     54     protected boolean isVoiceMailFixed = false;
     55     protected int countVoiceMessages = 0;
     56 
     57     protected int mncLength = UNINITIALIZED;
     58     protected int mailboxIndex = 0; // 0 is no mailbox dailing number associated
     59 
     60     protected String spn;
     61 
     62     // ***** Constants
     63 
     64     // Markers for mncLength
     65     protected static final int UNINITIALIZED = -1;
     66     protected static final int UNKNOWN = 0;
     67 
     68     // Bitmasks for SPN display rules.
     69     protected static final int SPN_RULE_SHOW_SPN  = 0x01;
     70     protected static final int SPN_RULE_SHOW_PLMN = 0x02;
     71 
     72     // ***** Event Constants
     73     protected static final int EVENT_SET_MSISDN_DONE = 30;
     74 
     75     public static final int EVENT_GET_ICC_RECORD_DONE = 100;
     76 
     77     /**
     78      * Generic ICC record loaded callback. Subclasses can call EF load methods on
     79      * {@link IccFileHandler} passing a Message for onLoaded with the what field set to
     80      * {@link #EVENT_GET_ICC_RECORD_DONE} and the obj field set to an instance
     81      * of this interface. The {@link #handleMessage} method in this class will print a
     82      * log message using {@link #getEfName()} and decrement {@link #recordsToLoad}.
     83      *
     84      * If the record load was successful, {@link #onRecordLoaded} will be called with the result.
     85      * Otherwise, an error log message will be output by {@link #handleMessage} and
     86      * {@link #onRecordLoaded} will not be called.
     87      */
     88     public interface IccRecordLoaded {
     89         String getEfName();
     90         void onRecordLoaded(AsyncResult ar);
     91     }
     92 
     93     // ***** Constructor
     94 
     95     public IccRecords(PhoneBase p) {
     96         this.phone = p;
     97     }
     98 
     99     /**
    100      * Call when the IccRecords object is no longer going to be used.
    101      */
    102     public abstract void dispose();
    103 
    104     protected abstract void onRadioOffOrNotAvailable();
    105 
    106     //***** Public Methods
    107     public AdnRecordCache getAdnCache() {
    108         return adnCache;
    109     }
    110 
    111     public void registerForRecordsLoaded(Handler h, int what, Object obj) {
    112         Registrant r = new Registrant(h, what, obj);
    113         recordsLoadedRegistrants.add(r);
    114 
    115         if (recordsToLoad == 0 && recordsRequested == true) {
    116             r.notifyRegistrant(new AsyncResult(null, null, null));
    117         }
    118     }
    119 
    120     public void unregisterForRecordsLoaded(Handler h) {
    121         recordsLoadedRegistrants.remove(h);
    122     }
    123 
    124     /**
    125      * Get the International Mobile Subscriber ID (IMSI) on a SIM
    126      * for GSM, UMTS and like networks. Default is null if IMSI is
    127      * not supported or unavailable.
    128      *
    129      * @return null if SIM is not yet ready or unavailable
    130      */
    131     public String getIMSI() {
    132         return null;
    133     }
    134 
    135     public String getMsisdnNumber() {
    136         return msisdn;
    137     }
    138 
    139     /**
    140      * Set subscriber number to SIM record
    141      *
    142      * The subscriber number is stored in EF_MSISDN (TS 51.011)
    143      *
    144      * When the operation is complete, onComplete will be sent to its handler
    145      *
    146      * @param alphaTag alpha-tagging of the dailing nubmer (up to 10 characters)
    147      * @param number dailing nubmer (up to 20 digits)
    148      *        if the number starts with '+', then set to international TOA
    149      * @param onComplete
    150      *        onComplete.obj will be an AsyncResult
    151      *        ((AsyncResult)onComplete.obj).exception == null on success
    152      *        ((AsyncResult)onComplete.obj).exception != null on fail
    153      */
    154     public void setMsisdnNumber(String alphaTag, String number,
    155             Message onComplete) {
    156 
    157         msisdn = number;
    158         msisdnTag = alphaTag;
    159 
    160         if(DBG) log("Set MSISDN: " + msisdnTag +" " + msisdn);
    161 
    162 
    163         AdnRecord adn = new AdnRecord(msisdnTag, msisdn);
    164 
    165         new AdnRecordLoader(phone).updateEF(adn, EF_MSISDN, EF_EXT1, 1, null,
    166                 obtainMessage(EVENT_SET_MSISDN_DONE, onComplete));
    167     }
    168 
    169     public String getMsisdnAlphaTag() {
    170         return msisdnTag;
    171     }
    172 
    173     public String getVoiceMailNumber() {
    174         return voiceMailNum;
    175     }
    176 
    177     /**
    178      * Return Service Provider Name stored in SIM (EF_SPN=0x6F46) or in RUIM (EF_RUIM_SPN=0x6F41)
    179      * @return null if SIM is not yet ready or no RUIM entry
    180      */
    181     public String getServiceProviderName() {
    182         return spn;
    183     }
    184 
    185     /**
    186      * Set voice mail number to SIM record
    187      *
    188      * The voice mail number can be stored either in EF_MBDN (TS 51.011) or
    189      * EF_MAILBOX_CPHS (CPHS 4.2)
    190      *
    191      * If EF_MBDN is available, store the voice mail number to EF_MBDN
    192      *
    193      * If EF_MAILBOX_CPHS is enabled, store the voice mail number to EF_CHPS
    194      *
    195      * So the voice mail number will be stored in both EFs if both are available
    196      *
    197      * Return error only if both EF_MBDN and EF_MAILBOX_CPHS fail.
    198      *
    199      * When the operation is complete, onComplete will be sent to its handler
    200      *
    201      * @param alphaTag alpha-tagging of the dailing nubmer (upto 10 characters)
    202      * @param voiceNumber dailing nubmer (upto 20 digits)
    203      *        if the number is start with '+', then set to international TOA
    204      * @param onComplete
    205      *        onComplete.obj will be an AsyncResult
    206      *        ((AsyncResult)onComplete.obj).exception == null on success
    207      *        ((AsyncResult)onComplete.obj).exception != null on fail
    208      */
    209     public abstract void setVoiceMailNumber(String alphaTag, String voiceNumber,
    210             Message onComplete);
    211 
    212     public String getVoiceMailAlphaTag() {
    213         return voiceMailTag;
    214     }
    215 
    216     /**
    217      * Sets the SIM voice message waiting indicator records
    218      * @param line GSM Subscriber Profile Number, one-based. Only '1' is supported
    219      * @param countWaiting The number of messages waiting, if known. Use
    220      *                     -1 to indicate that an unknown number of
    221      *                      messages are waiting
    222      */
    223     public abstract void setVoiceMessageWaiting(int line, int countWaiting);
    224 
    225     /** @return  true if there are messages waiting, false otherwise. */
    226     public boolean getVoiceMessageWaiting() {
    227         return countVoiceMessages != 0;
    228     }
    229 
    230     /**
    231      * Returns number of voice messages waiting, if available
    232      * If not available (eg, on an older CPHS SIM) -1 is returned if
    233      * getVoiceMessageWaiting() is true
    234      */
    235     public int getVoiceMessageCount() {
    236         return countVoiceMessages;
    237     }
    238 
    239     /**
    240      * Called by STK Service when REFRESH is received.
    241      * @param fileChanged indicates whether any files changed
    242      * @param fileList if non-null, a list of EF files that changed
    243      */
    244     public abstract void onRefresh(boolean fileChanged, int[] fileList);
    245 
    246 
    247     public boolean getRecordsLoaded() {
    248         if (recordsToLoad == 0 && recordsRequested == true) {
    249             return true;
    250         } else {
    251             return false;
    252         }
    253     }
    254 
    255     //***** Overridden from Handler
    256     @Override
    257     public void handleMessage(Message msg) {
    258         switch (msg.what) {
    259             case EVENT_GET_ICC_RECORD_DONE:
    260                 try {
    261                     AsyncResult ar = (AsyncResult) msg.obj;
    262                     IccRecordLoaded recordLoaded = (IccRecordLoaded) ar.userObj;
    263                     if (DBG) log(recordLoaded.getEfName() + " LOADED");
    264 
    265                     if (ar.exception != null) {
    266                         loge("Record Load Exception: " + ar.exception);
    267                     } else {
    268                         recordLoaded.onRecordLoaded(ar);
    269                     }
    270                 }catch (RuntimeException exc) {
    271                     // I don't want these exceptions to be fatal
    272                     loge("Exception parsing SIM record: " + exc);
    273                 } finally {
    274                     // Count up record load responses even if they are fails
    275                     onRecordLoaded();
    276                 }
    277                 break;
    278 
    279             default:
    280                 super.handleMessage(msg);
    281         }
    282     }
    283 
    284     protected abstract void onRecordLoaded();
    285 
    286     protected abstract void onAllRecordsLoaded();
    287 
    288     /**
    289      * Returns the SpnDisplayRule based on settings on the SIM and the
    290      * specified plmn (currently-registered PLMN).  See TS 22.101 Annex A
    291      * and TS 51.011 10.3.11 for details.
    292      *
    293      * If the SPN is not found on the SIM, the rule is always PLMN_ONLY.
    294      * Generally used for GSM/UMTS and the like SIMs.
    295      */
    296     public abstract int getDisplayRule(String plmn);
    297 
    298     /**
    299      * Return true if "Restriction of menu options for manual PLMN selection"
    300      * bit is set or EF_CSP data is unavailable, return false otherwise.
    301      * Generally used for GSM/UMTS and the like SIMs.
    302      */
    303     public boolean isCspPlmnEnabled() {
    304         return false;
    305     }
    306 
    307     /**
    308      * Returns the 5 or 6 digit MCC/MNC of the operator that
    309      * provided the SIM card. Returns null of SIM is not yet ready
    310      * or is not valid for the type of IccCard. Generally used for
    311      * GSM/UMTS and the like SIMS
    312      */
    313     public String getOperatorNumeric() {
    314         return null;
    315     }
    316 
    317     /**
    318      * Get the current Voice call forwarding flag for GSM/UMTS and the like SIMs
    319      *
    320      * @return true if enabled
    321      */
    322     public boolean getVoiceCallForwardingFlag() {
    323         return false;
    324     }
    325 
    326     /**
    327      * Set the voice call forwarding flag for GSM/UMTS and the like SIMs
    328      *
    329      * @param line to enable/disable
    330      * @param enable
    331      */
    332     public void setVoiceCallForwardingFlag(int line, boolean enable) {
    333     }
    334 
    335     /**
    336      * Indicates wether SIM is in provisioned state or not.
    337      * Overridden only if SIM can be dynamically provisioned via OTA.
    338      *
    339      * @return true if provisioned
    340      */
    341     public boolean isProvisioned () {
    342         return true;
    343     }
    344 
    345     /**
    346      * Write string to log file
    347      *
    348      * @param s is the string to write
    349      */
    350     protected abstract void log(String s);
    351 
    352     /**
    353      * Write error string to log file.
    354      *
    355      * @param s is the string to write
    356      */
    357     protected abstract void loge(String s);
    358 
    359     /**
    360      * Return an interface to retrieve the ISIM records for IMS, if available.
    361      * @return the interface to retrieve the ISIM records, or null if not supported
    362      */
    363     public IsimRecords getIsimRecords() {
    364         return null;
    365     }
    366 
    367     public UsimServiceTable getUsimServiceTable() {
    368         return null;
    369     }
    370 }
    371