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 */ 16package com.android.internal.telephony; 17 18import java.io.FileDescriptor; 19import java.io.PrintWriter; 20 21import android.content.Context; 22import android.content.pm.PackageManager; 23import android.os.Binder; 24import android.util.Log; 25 26public 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 Log.d(LOG_TAG, "PhoneSubInfo finalized"); 43 } 44 45 /** 46 * Retrieves the unique device ID, e.g., IMEI for GSM phones and MEID for CDMA phones. 47 */ 48 public String getDeviceId() { 49 mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE"); 50 return mPhone.getDeviceId(); 51 } 52 53 /** 54 * Retrieves the software version number for the device, e.g., IMEI/SV 55 * for GSM phones. 56 */ 57 public String getDeviceSvn() { 58 mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE"); 59 return mPhone.getDeviceSvn(); 60 } 61 62 /** 63 * Retrieves the unique sbuscriber ID, e.g., IMSI for GSM phones. 64 */ 65 public String getSubscriberId() { 66 mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE"); 67 return mPhone.getSubscriberId(); 68 } 69 70 /** 71 * Retrieves the serial number of the ICC, if applicable. 72 */ 73 public String getIccSerialNumber() { 74 mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE"); 75 return mPhone.getIccSerialNumber(); 76 } 77 78 /** 79 * Retrieves the phone number string for line 1. 80 */ 81 public String getLine1Number() { 82 mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE"); 83 return mPhone.getLine1Number(); 84 } 85 86 /** 87 * Retrieves the alpha identifier for line 1. 88 */ 89 public String getLine1AlphaTag() { 90 mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE"); 91 return (String) mPhone.getLine1AlphaTag(); 92 } 93 94 /** 95 * Retrieves the voice mail number. 96 */ 97 public String getVoiceMailNumber() { 98 mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE"); 99 return (String) mPhone.getVoiceMailNumber(); 100 } 101 102 /** 103 * Retrieves the alpha identifier associated with the voice mail number. 104 */ 105 public String getVoiceMailAlphaTag() { 106 mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, "Requires READ_PHONE_STATE"); 107 return (String) mPhone.getVoiceMailAlphaTag(); 108 } 109 110 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 111 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) 112 != PackageManager.PERMISSION_GRANTED) { 113 pw.println("Permission Denial: can't dump PhoneSubInfo from from pid=" 114 + Binder.getCallingPid() 115 + ", uid=" + Binder.getCallingUid()); 116 return; 117 } 118 119 pw.println("Phone Subscriber Info:"); 120 pw.println(" Phone Type = " + mPhone.getPhoneName()); 121 pw.println(" Device ID = " + mPhone.getDeviceId()); 122 } 123 124} 125