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.util.Log;
     25 
     26 public class PhoneSubInfo extends IPhoneSubInfo.Stub {
     27     static final String LOG_TAG = "PHONE";
     28     private Phone mPhone;
     29     private Context mContext;
     30     private static final String READ_PHONE_STATE =
     31         android.Manifest.permission.READ_PHONE_STATE;
     32 
     33     public PhoneSubInfo(Phone phone) {
     34         mPhone = phone;
     35         mContext = phone.getContext();
     36     }
     37 
     38     public void dispose() {
     39     }
     40 
     41     protected void finalize() {
     42         try {
     43             super.finalize();
     44         } catch (Throwable throwable) {
     45             Log.e(LOG_TAG, "Error while finalizing:", throwable);
     46         }
     47         Log.d(LOG_TAG, "PhoneSubInfo finalized");
     48     }
     49 
     50     /**
     51      * Retrieves the unique device ID, e.g., IMEI for GSM phones and MEID for CDMA phones.
     52      */
     53     public String getDeviceId() {
     54         mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE");
     55         return mPhone.getDeviceId();
     56     }
     57 
     58     /**
     59      * Retrieves the software version number for the device, e.g., IMEI/SV
     60      * for GSM phones.
     61      */
     62     public String getDeviceSvn() {
     63         mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE");
     64         return mPhone.getDeviceSvn();
     65     }
     66 
     67     /**
     68      * Retrieves the unique sbuscriber ID, e.g., IMSI for GSM phones.
     69      */
     70     public String getSubscriberId() {
     71         mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE");
     72         return mPhone.getSubscriberId();
     73     }
     74 
     75     /**
     76      * Retrieves the serial number of the ICC, if applicable.
     77      */
     78     public String getIccSerialNumber() {
     79         mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE");
     80         return mPhone.getIccSerialNumber();
     81     }
     82 
     83     /**
     84      * Retrieves the phone number string for line 1.
     85      */
     86     public String getLine1Number() {
     87         mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE");
     88         return mPhone.getLine1Number();
     89     }
     90 
     91     /**
     92      * Retrieves the alpha identifier for line 1.
     93      */
     94     public String getLine1AlphaTag() {
     95         mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE");
     96         return (String) mPhone.getLine1AlphaTag();
     97     }
     98 
     99     /**
    100      * Retrieves the voice mail number.
    101      */
    102     public String getVoiceMailNumber() {
    103         mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE");
    104         return (String) mPhone.getVoiceMailNumber();
    105     }
    106 
    107     /**
    108      * Retrieves the alpha identifier associated with the voice mail number.
    109      */
    110     public String getVoiceMailAlphaTag() {
    111         mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE");
    112         return (String) mPhone.getVoiceMailAlphaTag();
    113     }
    114 
    115     protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    116         if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
    117                 != PackageManager.PERMISSION_GRANTED) {
    118             pw.println("Permission Denial: can't dump PhoneSubInfo from from pid="
    119                     + Binder.getCallingPid()
    120                     + ", uid=" + Binder.getCallingUid());
    121             return;
    122         }
    123 
    124         pw.println("Phone Subscriber Info:");
    125         pw.println("  Phone Type = " + mPhone.getPhoneName());
    126         pw.println("  Device ID = " + mPhone.getDeviceId());
    127     }
    128 
    129 }
    130