Home | History | Annotate | Download | only in telephony
      1 /*
      2  * Copyright (C) 2006 The Android Open Source Project
      3  * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
      4  * Not a Contribution.
      5  *
      6  * Licensed under the Apache License, Version 2.0 (the "License");
      7  * you may not use this file except in compliance with the License.
      8  * You may obtain a copy of the License at
      9  *
     10  *      http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  * Unless required by applicable law or agreed to in writing, software
     13  * distributed under the License is distributed on an "AS IS" BASIS,
     14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15  * See the License for the specific language governing permissions and
     16  * limitations under the License.
     17  */
     18 
     19 package com.android.internal.telephony;
     20 
     21 import android.os.RemoteException;
     22 import android.os.ServiceManager;
     23 import android.telephony.SubscriptionManager;
     24 import android.telephony.Rlog;
     25 import android.telephony.TelephonyManager;
     26 
     27 import java.lang.NullPointerException;
     28 import java.lang.ArrayIndexOutOfBoundsException;
     29 
     30 import com.android.internal.telephony.IPhoneSubInfo;
     31 import com.android.internal.telephony.Phone;
     32 import com.android.internal.telephony.PhoneSubInfoProxy;
     33 
     34 public class PhoneSubInfoController extends IPhoneSubInfo.Stub {
     35     private static final String TAG = "PhoneSubInfoController";
     36     private Phone[] mPhone;
     37 
     38     public PhoneSubInfoController(Phone[] phone) {
     39         mPhone = phone;
     40         if (ServiceManager.getService("iphonesubinfo") == null) {
     41             ServiceManager.addService("iphonesubinfo", this);
     42         }
     43     }
     44 
     45 
     46     public String getDeviceId() {
     47         return getDeviceIdForSubscriber(getDefaultSubscription());
     48     }
     49 
     50     public String getDeviceIdForSubscriber(long subId) {
     51         PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(subId);
     52         if (phoneSubInfoProxy != null) {
     53             return phoneSubInfoProxy.getDeviceId();
     54         } else {
     55             Rlog.e(TAG,"getDeviceId phoneSubInfoProxy is null" +
     56                       " for Subscription:" + subId);
     57             return null;
     58         }
     59     }
     60 
     61     public String getImeiForSubscriber(long subId) {
     62         PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(subId);
     63         if (phoneSubInfoProxy != null) {
     64             return phoneSubInfoProxy.getImei();
     65         } else {
     66             Rlog.e(TAG,"getDeviceId phoneSubInfoProxy is null" +
     67                     " for Subscription:" + subId);
     68             return null;
     69         }
     70     }
     71 
     72     public String getDeviceSvn() {
     73         PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(getDefaultSubscription());
     74         if (phoneSubInfoProxy != null) {
     75             return phoneSubInfoProxy.getDeviceSvn();
     76         } else {
     77             Rlog.e(TAG,"getDeviceSvn phoneSubInfoProxy is null");
     78             return null;
     79         }
     80     }
     81 
     82     public String getSubscriberId() {
     83         return getSubscriberIdForSubscriber(getDefaultSubscription());
     84     }
     85 
     86     public String getSubscriberIdForSubscriber(long subId) {
     87         PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(subId);
     88         if (phoneSubInfoProxy != null) {
     89             return phoneSubInfoProxy.getSubscriberId();
     90         } else {
     91             Rlog.e(TAG,"getSubscriberId phoneSubInfoProxy is" +
     92                       " null for Subscription:" + subId);
     93             return null;
     94         }
     95     }
     96 
     97     /**
     98      * Retrieves the serial number of the ICC, if applicable.
     99      */
    100     public String getIccSerialNumber() {
    101         return getIccSerialNumberForSubscriber(getDefaultSubscription());
    102     }
    103 
    104     public String getIccSerialNumberForSubscriber(long subId) {
    105         PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(subId);
    106         if (phoneSubInfoProxy != null) {
    107             return phoneSubInfoProxy.getIccSerialNumber();
    108         } else {
    109             Rlog.e(TAG,"getIccSerialNumber phoneSubInfoProxy is" +
    110                       " null for Subscription:" + subId);
    111             return null;
    112         }
    113     }
    114 
    115     public String getLine1Number() {
    116         return getLine1NumberForSubscriber(getDefaultSubscription());
    117     }
    118 
    119     public String getLine1NumberForSubscriber(long subId) {
    120         PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(subId);
    121         if (phoneSubInfoProxy != null) {
    122             return phoneSubInfoProxy.getLine1Number();
    123         } else {
    124             Rlog.e(TAG,"getLine1Number phoneSubInfoProxy is" +
    125                       " null for Subscription:" + subId);
    126             return null;
    127         }
    128     }
    129 
    130     public String getLine1AlphaTag() {
    131         return getLine1AlphaTagForSubscriber(getDefaultSubscription());
    132     }
    133 
    134     public String getLine1AlphaTagForSubscriber(long subId) {
    135         PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(subId);
    136         if (phoneSubInfoProxy != null) {
    137             return phoneSubInfoProxy.getLine1AlphaTag();
    138         } else {
    139             Rlog.e(TAG,"getLine1AlphaTag phoneSubInfoProxy is" +
    140                       " null for Subscription:" + subId);
    141             return null;
    142         }
    143     }
    144 
    145     public String getMsisdn() {
    146         return getMsisdnForSubscriber(getDefaultSubscription());
    147     }
    148 
    149     public String getMsisdnForSubscriber(long subId) {
    150         PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(subId);
    151         if (phoneSubInfoProxy != null) {
    152             return phoneSubInfoProxy.getMsisdn();
    153         } else {
    154             Rlog.e(TAG,"getMsisdn phoneSubInfoProxy is" +
    155                       " null for Subscription:" + subId);
    156             return null;
    157         }
    158     }
    159 
    160     public String getVoiceMailNumber() {
    161         return getVoiceMailNumberForSubscriber(getDefaultSubscription());
    162     }
    163 
    164     public String getVoiceMailNumberForSubscriber(long subId) {
    165         PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(subId);
    166         if (phoneSubInfoProxy != null) {
    167             return phoneSubInfoProxy.getVoiceMailNumber();
    168         } else {
    169             Rlog.e(TAG,"getVoiceMailNumber phoneSubInfoProxy is" +
    170                       " null for Subscription:" + subId);
    171             return null;
    172         }
    173     }
    174 
    175     public String getCompleteVoiceMailNumber() {
    176         return getCompleteVoiceMailNumberForSubscriber(getDefaultSubscription());
    177     }
    178 
    179     public String getCompleteVoiceMailNumberForSubscriber(long subId) {
    180         PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(subId);
    181         if (phoneSubInfoProxy != null) {
    182             return phoneSubInfoProxy.getCompleteVoiceMailNumber();
    183         } else {
    184             Rlog.e(TAG,"getCompleteVoiceMailNumber phoneSubInfoProxy" +
    185                       " is null for Subscription:" + subId);
    186             return null;
    187         }
    188     }
    189 
    190     public String getVoiceMailAlphaTag() {
    191         return getVoiceMailAlphaTagForSubscriber(getDefaultSubscription());
    192     }
    193 
    194     public String getVoiceMailAlphaTagForSubscriber(long subId) {
    195         PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(subId);
    196         if (phoneSubInfoProxy != null) {
    197             return phoneSubInfoProxy.getVoiceMailAlphaTag();
    198         } else {
    199             Rlog.e(TAG,"getVoiceMailAlphaTag phoneSubInfoProxy is" +
    200                       " null for Subscription:" + subId);
    201             return null;
    202         }
    203     }
    204 
    205     /**
    206      * get Phone sub info proxy object based on subId.
    207      **/
    208     private PhoneSubInfoProxy getPhoneSubInfoProxy(long subId) {
    209 
    210         long phoneId = SubscriptionManager.getPhoneId(subId);
    211         if (phoneId < 0 || phoneId >= TelephonyManager.getDefault().getPhoneCount()) {
    212             phoneId = 0;
    213         }
    214 
    215         try {
    216             return ((PhoneProxy)mPhone[(int)phoneId]).getPhoneSubInfoProxy();
    217         } catch (NullPointerException e) {
    218             Rlog.e(TAG, "Exception is :" + e.toString() + " For subId :" + subId);
    219             e.printStackTrace();
    220             return null;
    221         } catch (ArrayIndexOutOfBoundsException e) {
    222             Rlog.e(TAG, "Exception is :" + e.toString() + " For subId :" + subId);
    223             e.printStackTrace();
    224             return null;
    225         }
    226     }
    227 
    228     private long getDefaultSubscription() {
    229         return  PhoneFactory.getDefaultSubscription();
    230     }
    231 
    232 
    233     public String getIsimImpi() {
    234         PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(getDefaultSubscription());
    235         return phoneSubInfoProxy.getIsimImpi();
    236     }
    237 
    238     public String getIsimDomain() {
    239         PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(getDefaultSubscription());
    240         return phoneSubInfoProxy.getIsimDomain();
    241     }
    242 
    243     public String[] getIsimImpu() {
    244         PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(getDefaultSubscription());
    245         return phoneSubInfoProxy.getIsimImpu();
    246     }
    247 
    248     public String getIsimIst() throws RemoteException {
    249         PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(getDefaultSubscription());
    250         return phoneSubInfoProxy.getIsimIst();
    251     }
    252 
    253     public String[] getIsimPcscf() throws RemoteException {
    254         PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(getDefaultSubscription());
    255         return phoneSubInfoProxy.getIsimPcscf();
    256     }
    257 
    258     public String getIsimChallengeResponse(String nonce) throws RemoteException {
    259         PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(getDefaultSubscription());
    260         return phoneSubInfoProxy.getIsimChallengeResponse(nonce);
    261     }
    262 
    263     public String getIccSimChallengeResponse(long subId, int appType, String data)
    264             throws RemoteException {
    265         PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(subId);
    266         return phoneSubInfoProxy.getIccSimChallengeResponse(subId, appType, data);
    267     }
    268 
    269      public String getGroupIdLevel1() {
    270          return getGroupIdLevel1ForSubscriber(getDefaultSubscription());
    271      }
    272 
    273      public String getGroupIdLevel1ForSubscriber(long subId) {
    274          PhoneSubInfoProxy phoneSubInfoProxy = getPhoneSubInfoProxy(subId);
    275          if (phoneSubInfoProxy != null) {
    276              return phoneSubInfoProxy.getGroupIdLevel1();
    277          } else {
    278              Rlog.e(TAG,"getGroupIdLevel1 phoneSubInfoProxy is" +
    279                        " null for Subscription:" + subId);
    280              return null;
    281          }
    282      }
    283 }
    284