Home | History | Annotate | Download | only in telephony
      1 /*
      2  * Copyright (C) 2007 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 package com.android.internal.telephony;
     17 
     18 import java.io.FileDescriptor;
     19 import java.io.PrintWriter;
     20 
     21 import android.content.Context;
     22 import android.content.pm.PackageManager;
     23 import android.os.Binder;
     24 import android.telephony.PhoneNumberUtils;
     25 import android.util.Log;
     26 
     27 public class PhoneSubInfo extends IPhoneSubInfo.Stub {
     28     static final String LOG_TAG = "PHONE";
     29     private Phone mPhone;
     30     private Context mContext;
     31     private static final String READ_PHONE_STATE =
     32         android.Manifest.permission.READ_PHONE_STATE;
     33     private static final String CALL_PRIVILEGED =
     34         // TODO Add core/res/AndriodManifest.xml#READ_PRIVILEGED_PHONE_STATE
     35         android.Manifest.permission.CALL_PRIVILEGED;
     36 
     37     public PhoneSubInfo(Phone phone) {
     38         mPhone = phone;
     39         mContext = phone.getContext();
     40     }
     41 
     42     public void dispose() {
     43     }
     44 
     45     protected void finalize() {
     46         try {
     47             super.finalize();
     48         } catch (Throwable throwable) {
     49             Log.e(LOG_TAG, "Error while finalizing:", throwable);
     50         }
     51         Log.d(LOG_TAG, "PhoneSubInfo finalized");
     52     }
     53 
     54     /**
     55      * Retrieves the unique device ID, e.g., IMEI for GSM phones and MEID for CDMA phones.
     56      */
     57     public String getDeviceId() {
     58         mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE");
     59         return mPhone.getDeviceId();
     60     }
     61 
     62     /**
     63      * Retrieves the software version number for the device, e.g., IMEI/SV
     64      * for GSM phones.
     65      */
     66     public String getDeviceSvn() {
     67         mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE");
     68         return mPhone.getDeviceSvn();
     69     }
     70 
     71     /**
     72      * Retrieves the unique subscriber ID, e.g., IMSI for GSM phones.
     73      */
     74     public String getSubscriberId() {
     75         mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE");
     76         return mPhone.getSubscriberId();
     77     }
     78 
     79     /**
     80      * Retrieves the serial number of the ICC, if applicable.
     81      */
     82     public String getIccSerialNumber() {
     83         mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE");
     84         return mPhone.getIccSerialNumber();
     85     }
     86 
     87     /**
     88      * Retrieves the phone number string for line 1.
     89      */
     90     public String getLine1Number() {
     91         mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE");
     92         return mPhone.getLine1Number();
     93     }
     94 
     95     /**
     96      * Retrieves the alpha identifier for line 1.
     97      */
     98     public String getLine1AlphaTag() {
     99         mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE");
    100         return (String) mPhone.getLine1AlphaTag();
    101     }
    102 
    103     /**
    104      * Retrieves the voice mail number.
    105      */
    106     public String getVoiceMailNumber() {
    107         mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE");
    108         String number = PhoneNumberUtils.extractNetworkPortion(mPhone.getVoiceMailNumber());
    109         Log.d(LOG_TAG, "VM: PhoneSubInfo.getVoiceMailNUmber: "); // + number);
    110         return number;
    111     }
    112 
    113     /**
    114      * Retrieves the complete voice mail number.
    115      *
    116      * @hide
    117      */
    118     public String getCompleteVoiceMailNumber() {
    119         mContext.enforceCallingOrSelfPermission(CALL_PRIVILEGED,
    120                 "Requires CALL_PRIVILEGED");
    121         String number = mPhone.getVoiceMailNumber();
    122         Log.d(LOG_TAG, "VM: PhoneSubInfo.getCompleteVoiceMailNUmber: "); // + number);
    123         return number;
    124     }
    125 
    126     /**
    127      * Retrieves the alpha identifier associated with the voice mail number.
    128      */
    129     public String getVoiceMailAlphaTag() {
    130         mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE");
    131         return (String) mPhone.getVoiceMailAlphaTag();
    132     }
    133 
    134     protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    135         if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
    136                 != PackageManager.PERMISSION_GRANTED) {
    137             pw.println("Permission Denial: can't dump PhoneSubInfo from from pid="
    138                     + Binder.getCallingPid()
    139                     + ", uid=" + Binder.getCallingUid());
    140             return;
    141         }
    142 
    143         pw.println("Phone Subscriber Info:");
    144         pw.println("  Phone Type = " + mPhone.getPhoneName());
    145         pw.println("  Device ID = " + mPhone.getDeviceId());
    146     }
    147 
    148 }
    149