CDMALTEPhone.java revision c38bb60d867c5d61d90b7179a9ed2b2d1848124f
1/* 2 * Copyright (C) 2011 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 17package com.android.internal.telephony.cdma; 18 19import android.content.ContentValues; 20import android.content.Context; 21import android.content.SharedPreferences; 22import android.database.SQLException; 23import android.net.Uri; 24import android.os.AsyncResult; 25import android.os.Message; 26import android.preference.PreferenceManager; 27import android.provider.Telephony; 28import android.util.Log; 29 30import com.android.internal.telephony.CommandsInterface; 31import com.android.internal.telephony.IccCard; 32import com.android.internal.telephony.OperatorInfo; 33import com.android.internal.telephony.Phone; 34import com.android.internal.telephony.PhoneConstants; 35import com.android.internal.telephony.PhoneNotifier; 36import com.android.internal.telephony.PhoneProxy; 37import com.android.internal.telephony.SMSDispatcher; 38import com.android.internal.telephony.gsm.GsmSMSDispatcher; 39import com.android.internal.telephony.gsm.SmsMessage; 40import com.android.internal.telephony.ims.IsimRecords; 41import com.android.internal.telephony.uicc.UiccController; 42 43import java.io.FileDescriptor; 44import java.io.PrintWriter; 45 46public class CDMALTEPhone extends CDMAPhone { 47 static final String LOG_TAG = "CDMA"; 48 49 private static final boolean DBG = true; 50 51 /** Secondary SMSDispatcher for 3GPP format messages. */ 52 SMSDispatcher m3gppSMS; 53 54 /** 55 * Small container class used to hold information relevant to 56 * the carrier selection process. operatorNumeric can be "" 57 * if we are looking for automatic selection. operatorAlphaLong is the 58 * corresponding operator name. 59 */ 60 private static class NetworkSelectMessage { 61 public Message message; 62 public String operatorNumeric; 63 public String operatorAlphaLong; 64 } 65 66 // Constructors 67 public CDMALTEPhone(Context context, CommandsInterface ci, PhoneNotifier notifier) { 68 super(context, ci, notifier, false); 69 m3gppSMS = new GsmSMSDispatcher(this, mSmsStorageMonitor, mSmsUsageMonitor); 70 mIccRecords.registerForNewSms(this, EVENT_NEW_ICC_SMS, null); 71 } 72 73 @Override 74 public void handleMessage (Message msg) { 75 AsyncResult ar; 76 switch (msg.what) { 77 // handle the select network completion callbacks. 78 case EVENT_SET_NETWORK_MANUAL_COMPLETE: 79 handleSetSelectNetwork((AsyncResult) msg.obj); 80 break; 81 case EVENT_NEW_ICC_SMS: 82 ar = (AsyncResult)msg.obj; 83 m3gppSMS.dispatchMessage((SmsMessage)ar.result); 84 break; 85 default: 86 super.handleMessage(msg); 87 } 88 } 89 90 @Override 91 protected void initSstIcc() { 92 mIccCard.set(UiccController.getInstance(this).getIccCard()); 93 mIccRecords = mIccCard.get().getIccRecords(); 94 // CdmaLteServiceStateTracker registers with IccCard to know 95 // when the card is ready. So create mIccCard before the ServiceStateTracker 96 mSST = new CdmaLteServiceStateTracker(this); 97 } 98 99 @Override 100 public void dispose() { 101 synchronized(PhoneProxy.lockForRadioTechnologyChange) { 102 super.dispose(); 103 m3gppSMS.dispose(); 104 mIccRecords.unregisterForNewSms(this); 105 } 106 } 107 108 @Override 109 public void removeReferences() { 110 super.removeReferences(); 111 m3gppSMS = null; 112 } 113 114 @Override 115 public PhoneConstants.DataState getDataConnectionState(String apnType) { 116 PhoneConstants.DataState ret = PhoneConstants.DataState.DISCONNECTED; 117 118 if (mSST == null) { 119 // Radio Technology Change is ongoing, dispose() and 120 // removeReferences() have already been called 121 122 ret = PhoneConstants.DataState.DISCONNECTED; 123 } else if (mDataConnectionTracker.isApnTypeEnabled(apnType) == false) { 124 ret = PhoneConstants.DataState.DISCONNECTED; 125 } else { 126 switch (mDataConnectionTracker.getState(apnType)) { 127 case FAILED: 128 case IDLE: 129 ret = PhoneConstants.DataState.DISCONNECTED; 130 break; 131 132 case CONNECTED: 133 case DISCONNECTING: 134 if (mCT.state != PhoneConstants.State.IDLE && 135 !mSST.isConcurrentVoiceAndDataAllowed()) { 136 ret = PhoneConstants.DataState.SUSPENDED; 137 } else { 138 ret = PhoneConstants.DataState.CONNECTED; 139 } 140 break; 141 142 case INITING: 143 case CONNECTING: 144 case SCANNING: 145 ret = PhoneConstants.DataState.CONNECTING; 146 break; 147 } 148 } 149 150 log("getDataConnectionState apnType=" + apnType + " ret=" + ret); 151 return ret; 152 } 153 154 @Override 155 public void 156 selectNetworkManually(OperatorInfo network, 157 Message response) { 158 // wrap the response message in our own message along with 159 // the operator's id. 160 NetworkSelectMessage nsm = new NetworkSelectMessage(); 161 nsm.message = response; 162 nsm.operatorNumeric = network.getOperatorNumeric(); 163 nsm.operatorAlphaLong = network.getOperatorAlphaLong(); 164 165 // get the message 166 Message msg = obtainMessage(EVENT_SET_NETWORK_MANUAL_COMPLETE, nsm); 167 168 mCM.setNetworkSelectionModeManual(network.getOperatorNumeric(), msg); 169 } 170 171 /** 172 * Used to track the settings upon completion of the network change. 173 */ 174 private void handleSetSelectNetwork(AsyncResult ar) { 175 // look for our wrapper within the asyncresult, skip the rest if it 176 // is null. 177 if (!(ar.userObj instanceof NetworkSelectMessage)) { 178 Log.e(LOG_TAG, "unexpected result from user object."); 179 return; 180 } 181 182 NetworkSelectMessage nsm = (NetworkSelectMessage) ar.userObj; 183 184 // found the object, now we send off the message we had originally 185 // attached to the request. 186 if (nsm.message != null) { 187 if (DBG) log("sending original message to recipient"); 188 AsyncResult.forMessage(nsm.message, ar.result, ar.exception); 189 nsm.message.sendToTarget(); 190 } 191 192 // open the shared preferences editor, and write the value. 193 // nsm.operatorNumeric is "" if we're in automatic.selection. 194 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); 195 SharedPreferences.Editor editor = sp.edit(); 196 editor.putString(NETWORK_SELECTION_KEY, nsm.operatorNumeric); 197 editor.putString(NETWORK_SELECTION_NAME_KEY, nsm.operatorAlphaLong); 198 199 // commit and log the result. 200 if (! editor.commit()) { 201 Log.e(LOG_TAG, "failed to commit network selection preference"); 202 } 203 204 } 205 206 @Override 207 public boolean updateCurrentCarrierInProvider() { 208 if (mIccRecords != null) { 209 try { 210 Uri uri = Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current"); 211 ContentValues map = new ContentValues(); 212 String operatorNumeric = mIccRecords.getOperatorNumeric(); 213 map.put(Telephony.Carriers.NUMERIC, operatorNumeric); 214 if (DBG) log("updateCurrentCarrierInProvider from UICC: numeric=" + 215 operatorNumeric); 216 mContext.getContentResolver().insert(uri, map); 217 return true; 218 } catch (SQLException e) { 219 Log.e(LOG_TAG, "[CDMALTEPhone] Can't store current operator ret false", e); 220 } 221 } else { 222 if (DBG) log("updateCurrentCarrierInProvider mIccRecords == null ret false"); 223 } 224 return false; 225 } 226 227 // return IMSI from USIM as subscriber ID. 228 @Override 229 public String getSubscriberId() { 230 return mIccRecords.getIMSI(); 231 } 232 233 @Override 234 public String getImei() { 235 return mImei; 236 } 237 238 @Override 239 public String getDeviceSvn() { 240 return mImeiSv; 241 } 242 243 @Override 244 public IsimRecords getIsimRecords() { 245 return mIccRecords.getIsimRecords(); 246 } 247 248 @Override 249 public String getMsisdn() { 250 return mIccRecords.getMsisdnNumber(); 251 } 252 253 @Override 254 public void getAvailableNetworks(Message response) { 255 mCM.getAvailableNetworks(response); 256 } 257 258 @Override 259 public void requestIsimAuthentication(String nonce, Message result) { 260 mCM.requestIsimAuthentication(nonce, result); 261 } 262 263 @Override 264 protected void log(String s) { 265 Log.d(LOG_TAG, "[CDMALTEPhone] " + s); 266 } 267 268 @Override 269 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 270 pw.println("CDMALTEPhone extends:"); 271 super.dump(fd, pw, args); 272 pw.println(" m3gppSMS=" + m3gppSMS); 273 } 274} 275