1 /* 2 * Copyright (C) 2014 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.settings.deviceinfo; 17 18 import com.android.internal.telephony.Phone; 19 import com.android.internal.telephony.PhoneConstants; 20 import com.android.internal.telephony.PhoneFactory; 21 22 import android.content.Context; 23 import android.os.Bundle; 24 import android.preference.Preference; 25 import android.preference.PreferenceActivity; 26 import android.preference.PreferenceScreen; 27 import android.telephony.SubscriptionInfo; 28 import android.telephony.SubscriptionManager; 29 import android.telephony.TelephonyManager; 30 import android.text.TextUtils; 31 import android.util.Log; 32 33 import com.android.settings.R; 34 import java.util.List; 35 36 public class ImeiInformation extends PreferenceActivity { 37 38 private static final String KEY_PRL_VERSION = "prl_version"; 39 private static final String KEY_MIN_NUMBER = "min_number"; 40 private static final String KEY_MEID_NUMBER = "meid_number"; 41 private static final String KEY_ICC_ID = "icc_id"; 42 private static final String KEY_IMEI = "imei"; 43 private static final String KEY_IMEI_SV = "imei_sv"; 44 45 private SubscriptionManager mSubscriptionManager; 46 private boolean isMultiSIM = false; 47 48 @Override 49 protected void onCreate(Bundle savedInstanceState) { 50 super.onCreate(savedInstanceState); 51 mSubscriptionManager = SubscriptionManager.from(this); 52 final TelephonyManager telephonyManager = 53 (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); 54 initPreferenceScreen(telephonyManager.getSimCount()); 55 } 56 57 // Since there are multiple phone for dsds, therefore need to show information for different 58 // phones. 59 private void initPreferenceScreen(int slotCount) { 60 isMultiSIM = (slotCount > 1); 61 for (int slotId = 0; slotId < slotCount; slotId ++) { 62 addPreferencesFromResource(R.xml.device_info_phone_status); 63 setPreferenceValue(slotId); 64 setNewKey(slotId); 65 } 66 } 67 68 private void setPreferenceValue(int phoneId) { 69 final Phone phone = PhoneFactory.getPhone(phoneId); 70 71 if (phone != null) { 72 if (phone.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) { 73 setSummaryText(KEY_MEID_NUMBER, phone.getMeid()); 74 setSummaryText(KEY_MIN_NUMBER, phone.getCdmaMin()); 75 76 if (getResources().getBoolean(R.bool.config_msid_enable)) { 77 findPreference(KEY_MIN_NUMBER).setTitle(R.string.status_msid_number); 78 } 79 80 setSummaryText(KEY_PRL_VERSION, phone.getCdmaPrlVersion()); 81 removePreferenceFromScreen(KEY_IMEI_SV); 82 83 if (phone.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE) { 84 // Show ICC ID and IMEI for LTE device 85 setSummaryText(KEY_ICC_ID, phone.getIccSerialNumber()); 86 setSummaryText(KEY_IMEI, phone.getImei()); 87 } else { 88 // device is not GSM/UMTS, do not display GSM/UMTS features 89 // check Null in case no specified preference in overlay xml 90 removePreferenceFromScreen(KEY_IMEI); 91 removePreferenceFromScreen(KEY_ICC_ID); 92 } 93 } else { 94 setSummaryText(KEY_IMEI, phone.getDeviceId()); 95 setSummaryText(KEY_IMEI_SV, 96 ((TelephonyManager) getSystemService(TELEPHONY_SERVICE)) 97 .getDeviceSoftwareVersion(phoneId)); 98 // device is not CDMA, do not display CDMA features 99 // check Null in case no specified preference in overlay xml 100 removePreferenceFromScreen(KEY_PRL_VERSION); 101 removePreferenceFromScreen(KEY_MEID_NUMBER); 102 removePreferenceFromScreen(KEY_MIN_NUMBER); 103 removePreferenceFromScreen(KEY_ICC_ID); 104 } 105 } 106 } 107 108 // Modify the preference key with prefix "_", so new added information preference can be set 109 // related phone information. 110 private void setNewKey(int slotId) { 111 final PreferenceScreen prefScreen = getPreferenceScreen(); 112 final int count = prefScreen.getPreferenceCount(); 113 for (int i = 0; i < count; i++) { 114 Preference pref = prefScreen.getPreference(i); 115 String key = pref.getKey(); 116 if (!key.startsWith("_")){ 117 key = "_" + key + String.valueOf(slotId); 118 pref.setKey(key); 119 updateTitle(pref, slotId); 120 } 121 } 122 } 123 124 private void updateTitle(Preference pref, int slotId) { 125 if (pref != null) { 126 String title = pref.getTitle().toString(); 127 if (isMultiSIM) { 128 // Slot starts from 1, slotId starts from 0 so plus 1 129 title += " " + getResources().getString(R.string.slot_number, slotId + 1); 130 } 131 pref.setTitle(title); 132 } 133 } 134 135 private void setSummaryText(String key, String text) { 136 final Preference preference = findPreference(key); 137 138 if (TextUtils.isEmpty(text)) { 139 text = getResources().getString(R.string.device_info_default); 140 } 141 142 if (preference != null) { 143 preference.setSummary(text); 144 } 145 } 146 147 /** 148 * Removes the specified preference, if it exists. 149 * @param key the key for the Preference item 150 */ 151 private void removePreferenceFromScreen(String key) { 152 final Preference preference = findPreference(key); 153 if (preference != null) { 154 getPreferenceScreen().removePreference(preference); 155 } 156 } 157 158 } 159