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 import com.android.internal.telephony.ims.IsimRecords; 28 29 public class PhoneSubInfo extends IPhoneSubInfo.Stub { 30 static final String LOG_TAG = "PHONE"; 31 private Phone mPhone; 32 private Context mContext; 33 private static final String READ_PHONE_STATE = 34 android.Manifest.permission.READ_PHONE_STATE; 35 // TODO: change getCompleteVoiceMailNumber() to require READ_PRIVILEGED_PHONE_STATE 36 private static final String CALL_PRIVILEGED = 37 android.Manifest.permission.CALL_PRIVILEGED; 38 private static final String READ_PRIVILEGED_PHONE_STATE = 39 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE; 40 41 public PhoneSubInfo(Phone phone) { 42 mPhone = phone; 43 mContext = phone.getContext(); 44 } 45 46 public void dispose() { 47 } 48 49 protected void finalize() { 50 try { 51 super.finalize(); 52 } catch (Throwable throwable) { 53 Log.e(LOG_TAG, "Error while finalizing:", throwable); 54 } 55 Log.d(LOG_TAG, "PhoneSubInfo finalized"); 56 } 57 58 /** 59 * Retrieves the unique device ID, e.g., IMEI for GSM phones and MEID for CDMA phones. 60 */ 61 public String getDeviceId() { 62 mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE"); 63 return mPhone.getDeviceId(); 64 } 65 66 /** 67 * Retrieves the software version number for the device, e.g., IMEI/SV 68 * for GSM phones. 69 */ 70 public String getDeviceSvn() { 71 mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE"); 72 return mPhone.getDeviceSvn(); 73 } 74 75 /** 76 * Retrieves the unique subscriber ID, e.g., IMSI for GSM phones. 77 */ 78 public String getSubscriberId() { 79 mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE"); 80 return mPhone.getSubscriberId(); 81 } 82 83 /** 84 * Retrieves the serial number of the ICC, if applicable. 85 */ 86 public String getIccSerialNumber() { 87 mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE"); 88 return mPhone.getIccSerialNumber(); 89 } 90 91 /** 92 * Retrieves the phone number string for line 1. 93 */ 94 public String getLine1Number() { 95 mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE"); 96 return mPhone.getLine1Number(); 97 } 98 99 /** 100 * Retrieves the alpha identifier for line 1. 101 */ 102 public String getLine1AlphaTag() { 103 mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE"); 104 return (String) mPhone.getLine1AlphaTag(); 105 } 106 107 /** 108 * Retrieves the MSISDN string. 109 */ 110 public String getMsisdn() { 111 mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE"); 112 return mPhone.getMsisdn(); 113 } 114 115 /** 116 * Retrieves the voice mail number. 117 */ 118 public String getVoiceMailNumber() { 119 mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE"); 120 String number = PhoneNumberUtils.extractNetworkPortion(mPhone.getVoiceMailNumber()); 121 Log.d(LOG_TAG, "VM: PhoneSubInfo.getVoiceMailNUmber: "); // + number); 122 return number; 123 } 124 125 /** 126 * Retrieves the complete voice mail number. 127 * 128 * @hide 129 */ 130 public String getCompleteVoiceMailNumber() { 131 mContext.enforceCallingOrSelfPermission(CALL_PRIVILEGED, 132 "Requires CALL_PRIVILEGED"); 133 String number = mPhone.getVoiceMailNumber(); 134 Log.d(LOG_TAG, "VM: PhoneSubInfo.getCompleteVoiceMailNUmber: "); // + number); 135 return number; 136 } 137 138 /** 139 * Retrieves the alpha identifier associated with the voice mail number. 140 */ 141 public String getVoiceMailAlphaTag() { 142 mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE"); 143 return (String) mPhone.getVoiceMailAlphaTag(); 144 } 145 146 /** 147 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. 148 * @return the IMPI, or null if not present or not loaded 149 */ 150 public String getIsimImpi() { 151 mContext.enforceCallingOrSelfPermission(READ_PRIVILEGED_PHONE_STATE, 152 "Requires READ_PRIVILEGED_PHONE_STATE"); 153 IsimRecords isim = mPhone.getIsimRecords(); 154 if (isim != null) { 155 return isim.getIsimImpi(); 156 } else { 157 return null; 158 } 159 } 160 161 /** 162 * Returns the IMS home network domain name that was loaded from the ISIM. 163 * @return the IMS domain name, or null if not present or not loaded 164 */ 165 public String getIsimDomain() { 166 mContext.enforceCallingOrSelfPermission(READ_PRIVILEGED_PHONE_STATE, 167 "Requires READ_PRIVILEGED_PHONE_STATE"); 168 IsimRecords isim = mPhone.getIsimRecords(); 169 if (isim != null) { 170 return isim.getIsimDomain(); 171 } else { 172 return null; 173 } 174 } 175 176 /** 177 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM. 178 * @return an array of IMPU strings, with one IMPU per string, or null if 179 * not present or not loaded 180 */ 181 public String[] getIsimImpu() { 182 mContext.enforceCallingOrSelfPermission(READ_PRIVILEGED_PHONE_STATE, 183 "Requires READ_PRIVILEGED_PHONE_STATE"); 184 IsimRecords isim = mPhone.getIsimRecords(); 185 if (isim != null) { 186 return isim.getIsimImpu(); 187 } else { 188 return null; 189 } 190 } 191 192 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 193 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) 194 != PackageManager.PERMISSION_GRANTED) { 195 pw.println("Permission Denial: can't dump PhoneSubInfo from from pid=" 196 + Binder.getCallingPid() 197 + ", uid=" + Binder.getCallingUid()); 198 return; 199 } 200 201 pw.println("Phone Subscriber Info:"); 202 pw.println(" Phone Type = " + mPhone.getPhoneName()); 203 pw.println(" Device ID = " + mPhone.getDeviceId()); 204 } 205 206 } 207