Zvikomborero VIncent Zvikaramba | 9b3a907 | 2016-07-29 05:52:32 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012-2014 The CyanogenMod 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 | |
| 17 | package com.android.internal.telephony; |
| 18 | |
| 19 | import static com.android.internal.telephony.RILConstants.*; |
| 20 | |
| 21 | import android.content.Context; |
| 22 | import android.media.AudioManager; |
| 23 | import android.os.AsyncResult; |
| 24 | import android.os.Handler; |
| 25 | import android.os.HandlerThread; |
| 26 | import android.os.Looper; |
| 27 | import android.os.Message; |
| 28 | import android.os.Parcel; |
| 29 | import android.telephony.SmsMessage; |
| 30 | import android.os.SystemProperties; |
| 31 | import android.os.SystemClock; |
| 32 | import android.provider.Settings; |
| 33 | import android.text.TextUtils; |
| 34 | import android.telephony.Rlog; |
| 35 | |
| 36 | import android.telephony.SignalStrength; |
| 37 | |
| 38 | import android.telephony.PhoneNumberUtils; |
| 39 | import com.android.internal.telephony.RILConstants; |
| 40 | import com.android.internal.telephony.gsm.SmsBroadcastConfigInfo; |
| 41 | import com.android.internal.telephony.cdma.CdmaInformationRecords; |
| 42 | import com.android.internal.telephony.cdma.CdmaInformationRecords.CdmaSignalInfoRec; |
| 43 | import com.android.internal.telephony.cdma.SignalToneUtil; |
| 44 | |
| 45 | import java.io.IOException; |
| 46 | import java.util.ArrayList; |
| 47 | import java.util.Collections; |
| 48 | |
| 49 | import com.android.internal.telephony.uicc.IccCardApplicationStatus; |
| 50 | import com.android.internal.telephony.uicc.IccCardStatus; |
| 51 | |
| 52 | /** |
| 53 | * Qualcomm RIL for the Samsung family. |
| 54 | * Quad core Exynos4 with Qualcomm modem and later is supported |
| 55 | * Snapdragon S3 and later is supported |
| 56 | * This RIL is univerisal meaning it supports CDMA and GSM radio. |
| 57 | * Handles most GSM and CDMA cases. |
| 58 | * {@hide} |
| 59 | */ |
| 60 | public class smdk4x12QComRIL extends RIL implements CommandsInterface { |
| 61 | |
| 62 | private AudioManager mAudioManager; |
| 63 | |
| 64 | private Object mSMSLock = new Object(); |
| 65 | private boolean mIsSendingSMS = false; |
| 66 | protected boolean isGSM = false; |
| 67 | public static final long SEND_SMS_TIMEOUT_IN_MS = 30000; |
| 68 | private boolean samsungEmergency = needsOldRilFeature("samsungEMSReq"); |
| 69 | |
| 70 | private Message mPendingGetSimStatus; |
| 71 | |
| 72 | public smdk4x12QComRIL(Context context, int preferredNetworkType, |
| 73 | int cdmaSubscription, Integer instanceId) { |
| 74 | this(context, preferredNetworkType, cdmaSubscription); |
| 75 | } |
| 76 | |
| 77 | public smdk4x12QComRIL(Context context, int networkMode, |
| 78 | int cdmaSubscription) { |
| 79 | super(context, networkMode, cdmaSubscription); |
| 80 | mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); |
| 81 | mQANElements = SystemProperties.getInt("ro.ril.telephony.mqanelements", 6); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | protected Object |
| 86 | responseIccCardStatus(Parcel p) { |
| 87 | IccCardApplicationStatus appStatus; |
| 88 | |
| 89 | IccCardStatus cardStatus = new IccCardStatus(); |
| 90 | cardStatus.setCardState(p.readInt()); |
| 91 | cardStatus.setUniversalPinState(p.readInt()); |
| 92 | cardStatus.mGsmUmtsSubscriptionAppIndex = p.readInt(); |
| 93 | cardStatus.mCdmaSubscriptionAppIndex = p.readInt(); |
| 94 | cardStatus.mImsSubscriptionAppIndex = p.readInt(); |
| 95 | |
| 96 | int numApplications = p.readInt(); |
| 97 | |
| 98 | // limit to maximum allowed applications |
| 99 | if (numApplications > IccCardStatus.CARD_MAX_APPS) { |
| 100 | numApplications = IccCardStatus.CARD_MAX_APPS; |
| 101 | } |
| 102 | cardStatus.mApplications = new IccCardApplicationStatus[numApplications]; |
| 103 | |
| 104 | appStatus = new IccCardApplicationStatus(); |
| 105 | for (int i = 0 ; i < numApplications ; i++) { |
| 106 | if (i!=0) { |
| 107 | appStatus = new IccCardApplicationStatus(); |
| 108 | } |
| 109 | appStatus.app_type = appStatus.AppTypeFromRILInt(p.readInt()); |
| 110 | appStatus.app_state = appStatus.AppStateFromRILInt(p.readInt()); |
| 111 | appStatus.perso_substate = appStatus.PersoSubstateFromRILInt(p.readInt()); |
| 112 | appStatus.aid = p.readString(); |
| 113 | appStatus.app_label = p.readString(); |
| 114 | appStatus.pin1_replaced = p.readInt(); |
| 115 | appStatus.pin1 = appStatus.PinStateFromRILInt(p.readInt()); |
| 116 | appStatus.pin2 = appStatus.PinStateFromRILInt(p.readInt()); |
| 117 | p.readInt(); // remaining_count_pin1 - pin1_num_retries |
| 118 | p.readInt(); // remaining_count_puk1 - puk1_num_retries |
| 119 | p.readInt(); // remaining_count_pin2 - pin2_num_retries |
| 120 | p.readInt(); // remaining_count_puk2 - puk2_num_retries |
| 121 | p.readInt(); // - perso_unblock_retries |
| 122 | cardStatus.mApplications[i] = appStatus; |
| 123 | } |
| 124 | if (numApplications==1 && !isGSM && appStatus.app_type == appStatus.AppTypeFromRILInt(2)) { |
| 125 | cardStatus.mApplications = new IccCardApplicationStatus[numApplications+2]; |
| 126 | cardStatus.mGsmUmtsSubscriptionAppIndex = 0; |
| 127 | cardStatus.mApplications[cardStatus.mGsmUmtsSubscriptionAppIndex]=appStatus; |
| 128 | cardStatus.mCdmaSubscriptionAppIndex = 1; |
| 129 | cardStatus.mImsSubscriptionAppIndex = 2; |
| 130 | IccCardApplicationStatus appStatus2 = new IccCardApplicationStatus(); |
| 131 | appStatus2.app_type = appStatus2.AppTypeFromRILInt(4); // csim state |
| 132 | appStatus2.app_state = appStatus.app_state; |
| 133 | appStatus2.perso_substate = appStatus.perso_substate; |
| 134 | appStatus2.aid = appStatus.aid; |
| 135 | appStatus2.app_label = appStatus.app_label; |
| 136 | appStatus2.pin1_replaced = appStatus.pin1_replaced; |
| 137 | appStatus2.pin1 = appStatus.pin1; |
| 138 | appStatus2.pin2 = appStatus.pin2; |
| 139 | cardStatus.mApplications[cardStatus.mCdmaSubscriptionAppIndex] = appStatus2; |
| 140 | IccCardApplicationStatus appStatus3 = new IccCardApplicationStatus(); |
| 141 | appStatus3.app_type = appStatus3.AppTypeFromRILInt(5); // ims state |
| 142 | appStatus3.app_state = appStatus.app_state; |
| 143 | appStatus3.perso_substate = appStatus.perso_substate; |
| 144 | appStatus3.aid = appStatus.aid; |
| 145 | appStatus3.app_label = appStatus.app_label; |
| 146 | appStatus3.pin1_replaced = appStatus.pin1_replaced; |
| 147 | appStatus3.pin1 = appStatus.pin1; |
| 148 | appStatus3.pin2 = appStatus.pin2; |
| 149 | cardStatus.mApplications[cardStatus.mImsSubscriptionAppIndex] = appStatus3; |
| 150 | } |
| 151 | return cardStatus; |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public void |
| 156 | sendCdmaSms(byte[] pdu, Message result) { |
| 157 | smsLock(); |
| 158 | super.sendCdmaSms(pdu, result); |
| 159 | } |
| 160 | |
| 161 | @Override |
| 162 | public void |
| 163 | sendSMS (String smscPDU, String pdu, Message result) { |
| 164 | smsLock(); |
| 165 | super.sendSMS(smscPDU, pdu, result); |
| 166 | } |
| 167 | |
| 168 | private void smsLock(){ |
| 169 | // Do not send a new SMS until the response for the previous SMS has been received |
| 170 | // * for the error case where the response never comes back, time out after |
| 171 | // 30 seconds and just try the next SEND_SMS |
| 172 | synchronized (mSMSLock) { |
| 173 | long timeoutTime = SystemClock.elapsedRealtime() + SEND_SMS_TIMEOUT_IN_MS; |
| 174 | long waitTimeLeft = SEND_SMS_TIMEOUT_IN_MS; |
| 175 | while (mIsSendingSMS && (waitTimeLeft > 0)) { |
| 176 | Rlog.d(RILJ_LOG_TAG, "sendSMS() waiting for response of previous SEND_SMS"); |
| 177 | try { |
| 178 | mSMSLock.wait(waitTimeLeft); |
| 179 | } catch (InterruptedException ex) { |
| 180 | // ignore the interrupt and rewait for the remainder |
| 181 | } |
| 182 | waitTimeLeft = timeoutTime - SystemClock.elapsedRealtime(); |
| 183 | } |
| 184 | if (waitTimeLeft <= 0) { |
| 185 | Rlog.e(RILJ_LOG_TAG, "sendSms() timed out waiting for response of previous CDMA_SEND_SMS"); |
| 186 | } |
| 187 | mIsSendingSMS = true; |
| 188 | } |
| 189 | |
| 190 | } |
| 191 | |
| 192 | @Override |
| 193 | protected Object responseSignalStrength(Parcel p) { |
| 194 | int numInts = 13; |
| 195 | int response[]; |
| 196 | |
| 197 | // Get raw data |
| 198 | response = new int[numInts]; |
| 199 | for (int i = 0; i < numInts; i++) { |
| 200 | response[i] = p.readInt(); |
| 201 | } |
| 202 | //gsm |
| 203 | response[0] &= 0xff; |
| 204 | //cdma |
| 205 | response[2] %= 256; |
| 206 | response[4] %= 256; |
| 207 | response[7] &= 0xff; |
| 208 | |
| 209 | return new SignalStrength(response[0], response[1], response[2], response[3], response[4], response[5], response[6], response[7], response[8], response[9], response[10], response[11], (response[12] != 0)); |
| 210 | |
| 211 | } |
| 212 | |
| 213 | @Override |
| 214 | public void setPhoneType(int phoneType){ |
| 215 | super.setPhoneType(phoneType); |
| 216 | isGSM = (phoneType != RILConstants.CDMA_PHONE); |
| 217 | } |
| 218 | |
| 219 | protected Object |
| 220 | responseCallList(Parcel p) { |
| 221 | int num; |
| 222 | int voiceSettings; |
| 223 | ArrayList<DriverCall> response; |
| 224 | DriverCall dc; |
| 225 | |
| 226 | num = p.readInt(); |
| 227 | response = new ArrayList<DriverCall>(num); |
| 228 | |
| 229 | if (RILJ_LOGV) { |
| 230 | riljLog("responseCallList: num=" + num + |
| 231 | " mEmergencyCallbackModeRegistrant=" + mEmergencyCallbackModeRegistrant + |
| 232 | " mTestingEmergencyCall=" + mTestingEmergencyCall.get()); |
| 233 | } |
| 234 | for (int i = 0 ; i < num ; i++) { |
| 235 | dc = new DriverCall(); |
| 236 | |
| 237 | dc.state = DriverCall.stateFromCLCC(p.readInt()); |
| 238 | dc.index = p.readInt() & 0xff; |
| 239 | dc.TOA = p.readInt(); |
| 240 | dc.isMpty = (0 != p.readInt()); |
| 241 | dc.isMT = (0 != p.readInt()); |
| 242 | dc.als = p.readInt(); |
| 243 | voiceSettings = p.readInt(); |
| 244 | if (isGSM){ |
| 245 | p.readInt(); |
| 246 | } |
| 247 | dc.isVoice = (0 == voiceSettings) ? false : true; |
| 248 | dc.isVoicePrivacy = (0 != p.readInt()); |
| 249 | if (isGSM) { |
| 250 | p.readInt(); |
| 251 | p.readInt(); |
| 252 | p.readString(); |
| 253 | } |
| 254 | dc.number = p.readString(); |
| 255 | int np = p.readInt(); |
| 256 | dc.numberPresentation = DriverCall.presentationFromCLIP(np); |
| 257 | dc.name = p.readString(); |
| 258 | dc.namePresentation = p.readInt(); |
| 259 | int uusInfoPresent = p.readInt(); |
| 260 | if (uusInfoPresent == 1) { |
| 261 | dc.uusInfo = new UUSInfo(); |
| 262 | dc.uusInfo.setType(p.readInt()); |
| 263 | dc.uusInfo.setDcs(p.readInt()); |
| 264 | byte[] userData = p.createByteArray(); |
| 265 | dc.uusInfo.setUserData(userData); |
| 266 | riljLogv(String.format("Incoming UUS : type=%d, dcs=%d, length=%d", |
| 267 | dc.uusInfo.getType(), dc.uusInfo.getDcs(), |
| 268 | dc.uusInfo.getUserData().length)); |
| 269 | riljLogv("Incoming UUS : data (string)=" |
| 270 | + new String(dc.uusInfo.getUserData())); |
| 271 | riljLogv("Incoming UUS : data (hex): " |
| 272 | + IccUtils.bytesToHexString(dc.uusInfo.getUserData())); |
| 273 | } else { |
| 274 | riljLogv("Incoming UUS : NOT present!"); |
| 275 | } |
| 276 | |
| 277 | // Make sure there's a leading + on addresses with a TOA of 145 |
| 278 | dc.number = PhoneNumberUtils.stringFromStringAndTOA(dc.number, dc.TOA); |
| 279 | |
| 280 | response.add(dc); |
| 281 | |
| 282 | if (dc.isVoicePrivacy) { |
| 283 | mVoicePrivacyOnRegistrants.notifyRegistrants(); |
| 284 | riljLog("InCall VoicePrivacy is enabled"); |
| 285 | } else { |
| 286 | mVoicePrivacyOffRegistrants.notifyRegistrants(); |
| 287 | riljLog("InCall VoicePrivacy is disabled"); |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | Collections.sort(response); |
| 292 | |
| 293 | if ((num == 0) && mTestingEmergencyCall.getAndSet(false)) { |
| 294 | if (mEmergencyCallbackModeRegistrant != null) { |
| 295 | riljLog("responseCallList: call ended, testing emergency call," + |
| 296 | " notify ECM Registrants"); |
| 297 | mEmergencyCallbackModeRegistrant.notifyRegistrant(); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | return response; |
| 302 | } |
| 303 | |
| 304 | @Override |
| 305 | protected void |
| 306 | processUnsolicited (Parcel p) { |
| 307 | Object ret; |
| 308 | int dataPosition = p.dataPosition(); // save off position within the Parcel |
| 309 | int response = p.readInt(); |
| 310 | |
| 311 | switch(response) { |
| 312 | case RIL_UNSOL_RIL_CONNECTED: |
| 313 | ret = responseInts(p); |
| 314 | setRadioPower(false, null); |
| 315 | setPreferredNetworkType(mPreferredNetworkType, null); |
| 316 | setCdmaSubscriptionSource(mCdmaSubscription, null); |
| 317 | if(mRilVersion >= 8) |
| 318 | setCellInfoListRate(Integer.MAX_VALUE, null); |
| 319 | notifyRegistrantsRilConnectionChanged(((int[])ret)[0]); |
| 320 | break; |
| 321 | // SAMSUNG STATES |
| 322 | case 11010: // RIL_UNSOL_AM: |
| 323 | ret = responseString(p); |
| 324 | String amString = (String) ret; |
| 325 | Rlog.d(RILJ_LOG_TAG, "Executing AM: " + amString); |
| 326 | |
| 327 | try { |
| 328 | Runtime.getRuntime().exec("am " + amString); |
| 329 | } catch (IOException e) { |
| 330 | e.printStackTrace(); |
| 331 | Rlog.e(RILJ_LOG_TAG, "am " + amString + " could not be executed."); |
| 332 | } |
| 333 | break; |
| 334 | case 11021: // RIL_UNSOL_RESPONSE_HANDOVER: |
| 335 | ret = responseVoid(p); |
| 336 | break; |
| 337 | case 1036: |
| 338 | ret = responseVoid(p); |
| 339 | break; |
| 340 | case 11017: // RIL_UNSOL_WB_AMR_STATE: |
| 341 | ret = responseInts(p); |
| 342 | setWbAmr(((int[])ret)[0]); |
| 343 | break; |
| 344 | default: |
| 345 | // Rewind the Parcel |
| 346 | p.setDataPosition(dataPosition); |
| 347 | |
| 348 | // Forward responses that we are not overriding to the super class |
| 349 | super.processUnsolicited(p); |
| 350 | return; |
| 351 | } |
| 352 | |
| 353 | } |
| 354 | |
| 355 | @Override |
| 356 | protected RILRequest |
| 357 | processSolicited (Parcel p) { |
| 358 | int serial, error; |
| 359 | boolean found = false; |
| 360 | |
| 361 | serial = p.readInt(); |
| 362 | error = p.readInt(); |
| 363 | |
| 364 | RILRequest rr; |
| 365 | |
| 366 | rr = findAndRemoveRequestFromList(serial); |
| 367 | |
| 368 | if (rr == null) { |
| 369 | Rlog.w(RILJ_LOG_TAG, "Unexpected solicited response! sn: " |
| 370 | + serial + " error: " + error); |
| 371 | return null; |
| 372 | } |
| 373 | |
| 374 | Object ret = null; |
| 375 | |
| 376 | if (error == 0 || p.dataAvail() > 0) { |
| 377 | // either command succeeds or command fails but with data payload |
| 378 | try {switch (rr.mRequest) { |
| 379 | /* |
| 380 | cat libs/telephony/ril_commands.h \ |
| 381 | | egrep "^ *{RIL_" \ |
| 382 | | sed -re 's/\{([^,]+),[^,]+,([^}]+).+/case \1: ret = \2(p); break;/' |
| 383 | */ |
| 384 | case RIL_REQUEST_GET_SIM_STATUS: ret = responseIccCardStatus(p); break; |
| 385 | case RIL_REQUEST_ENTER_SIM_PIN: ret = responseInts(p); break; |
| 386 | case RIL_REQUEST_ENTER_SIM_PUK: ret = responseInts(p); break; |
| 387 | case RIL_REQUEST_ENTER_SIM_PIN2: ret = responseInts(p); break; |
| 388 | case RIL_REQUEST_ENTER_SIM_PUK2: ret = responseInts(p); break; |
| 389 | case RIL_REQUEST_CHANGE_SIM_PIN: ret = responseInts(p); break; |
| 390 | case RIL_REQUEST_CHANGE_SIM_PIN2: ret = responseInts(p); break; |
| 391 | case RIL_REQUEST_ENTER_DEPERSONALIZATION_CODE: ret = responseInts(p); break; |
| 392 | case RIL_REQUEST_GET_CURRENT_CALLS: ret = responseCallList(p); break; |
| 393 | case RIL_REQUEST_DIAL: ret = responseVoid(p); break; |
| 394 | case RIL_REQUEST_GET_IMSI: ret = responseString(p); break; |
| 395 | case RIL_REQUEST_HANGUP: ret = responseVoid(p); break; |
| 396 | case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: ret = responseVoid(p); break; |
| 397 | case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: { |
| 398 | if (mTestingEmergencyCall.getAndSet(false)) { |
| 399 | if (mEmergencyCallbackModeRegistrant != null) { |
| 400 | riljLog("testing emergency call, notify ECM Registrants"); |
| 401 | mEmergencyCallbackModeRegistrant.notifyRegistrant(); |
| 402 | } |
| 403 | } |
| 404 | ret = responseVoid(p); |
| 405 | break; |
| 406 | } |
| 407 | case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: ret = responseVoid(p); break; |
| 408 | case RIL_REQUEST_CONFERENCE: ret = responseVoid(p); break; |
| 409 | case RIL_REQUEST_UDUB: ret = responseVoid(p); break; |
| 410 | case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: ret = responseInts(p); break; |
| 411 | case RIL_REQUEST_SIGNAL_STRENGTH: ret = responseSignalStrength(p); break; |
| 412 | case RIL_REQUEST_VOICE_REGISTRATION_STATE: ret = responseVoiceDataRegistrationState(p); break; |
| 413 | case RIL_REQUEST_DATA_REGISTRATION_STATE: ret = responseVoiceDataRegistrationState(p); break; |
| 414 | case RIL_REQUEST_OPERATOR: ret = operatorCheck(p); break; |
| 415 | case RIL_REQUEST_RADIO_POWER: ret = responseVoid(p); break; |
| 416 | case RIL_REQUEST_DTMF: ret = responseVoid(p); break; |
| 417 | case RIL_REQUEST_SEND_SMS: ret = responseSMS(p); break; |
| 418 | case RIL_REQUEST_SEND_SMS_EXPECT_MORE: ret = responseSMS(p); break; |
| 419 | case RIL_REQUEST_SETUP_DATA_CALL: ret = responseSetupDataCall(p); break; |
| 420 | case RIL_REQUEST_SIM_IO: ret = responseICC_IO(p); break; |
| 421 | case RIL_REQUEST_SEND_USSD: ret = responseVoid(p); break; |
| 422 | case RIL_REQUEST_CANCEL_USSD: ret = responseVoid(p); break; |
| 423 | case RIL_REQUEST_GET_CLIR: ret = responseInts(p); break; |
| 424 | case RIL_REQUEST_SET_CLIR: ret = responseVoid(p); break; |
| 425 | case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: ret = responseCallForward(p); break; |
| 426 | case RIL_REQUEST_SET_CALL_FORWARD: ret = responseVoid(p); break; |
| 427 | case RIL_REQUEST_QUERY_CALL_WAITING: ret = responseInts(p); break; |
| 428 | case RIL_REQUEST_SET_CALL_WAITING: ret = responseVoid(p); break; |
| 429 | case RIL_REQUEST_SMS_ACKNOWLEDGE: ret = responseVoid(p); break; |
| 430 | case RIL_REQUEST_GET_IMEI: ret = responseString(p); break; |
| 431 | case RIL_REQUEST_GET_IMEISV: ret = responseString(p); break; |
| 432 | case RIL_REQUEST_ANSWER: ret = responseVoid(p); break; |
| 433 | case RIL_REQUEST_DEACTIVATE_DATA_CALL: ret = responseVoid(p); break; |
| 434 | case RIL_REQUEST_QUERY_FACILITY_LOCK: ret = responseInts(p); break; |
| 435 | case RIL_REQUEST_SET_FACILITY_LOCK: ret = responseInts(p); break; |
| 436 | case RIL_REQUEST_CHANGE_BARRING_PASSWORD: ret = responseVoid(p); break; |
| 437 | case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: ret = responseInts(p); break; |
| 438 | case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: ret = responseVoid(p); break; |
| 439 | case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: ret = responseVoid(p); break; |
| 440 | case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : ret = responseOperatorInfos(p); break; |
| 441 | case RIL_REQUEST_DTMF_START: ret = responseVoid(p); break; |
| 442 | case RIL_REQUEST_DTMF_STOP: ret = responseVoid(p); break; |
| 443 | case RIL_REQUEST_BASEBAND_VERSION: ret = responseString(p); break; |
| 444 | case RIL_REQUEST_SEPARATE_CONNECTION: ret = responseVoid(p); break; |
| 445 | case RIL_REQUEST_SET_MUTE: ret = responseVoid(p); break; |
| 446 | case RIL_REQUEST_GET_MUTE: ret = responseInts(p); break; |
| 447 | case RIL_REQUEST_QUERY_CLIP: ret = responseInts(p); break; |
| 448 | case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: ret = responseInts(p); break; |
| 449 | case RIL_REQUEST_DATA_CALL_LIST: ret = responseDataCallList(p); break; |
| 450 | case RIL_REQUEST_RESET_RADIO: ret = responseVoid(p); break; |
| 451 | case RIL_REQUEST_OEM_HOOK_RAW: ret = responseRaw(p); break; |
| 452 | case RIL_REQUEST_OEM_HOOK_STRINGS: ret = responseStrings(p); break; |
| 453 | case RIL_REQUEST_SCREEN_STATE: ret = responseVoid(p); break; |
| 454 | case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: ret = responseVoid(p); break; |
| 455 | case RIL_REQUEST_WRITE_SMS_TO_SIM: ret = responseInts(p); break; |
| 456 | case RIL_REQUEST_DELETE_SMS_ON_SIM: ret = responseVoid(p); break; |
| 457 | case RIL_REQUEST_SET_BAND_MODE: ret = responseVoid(p); break; |
| 458 | case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: ret = responseInts(p); break; |
| 459 | case RIL_REQUEST_STK_GET_PROFILE: ret = responseString(p); break; |
| 460 | case RIL_REQUEST_STK_SET_PROFILE: ret = responseVoid(p); break; |
| 461 | case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: ret = responseString(p); break; |
| 462 | case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: ret = responseVoid(p); break; |
| 463 | case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: ret = responseInts(p); break; |
| 464 | case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: ret = responseVoid(p); break; |
| 465 | case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: ret = responseVoid(p); break; |
| 466 | case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: ret = responseGetPreferredNetworkType(p); break; |
| 467 | case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: ret = responseCellList(p); break; |
| 468 | case RIL_REQUEST_SET_LOCATION_UPDATES: ret = responseVoid(p); break; |
| 469 | case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: ret = responseVoid(p); break; |
| 470 | case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: ret = responseVoid(p); break; |
| 471 | case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: ret = responseInts(p); break; |
| 472 | case RIL_REQUEST_SET_TTY_MODE: ret = responseVoid(p); break; |
| 473 | case RIL_REQUEST_QUERY_TTY_MODE: ret = responseInts(p); break; |
| 474 | case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: ret = responseVoid(p); break; |
| 475 | case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: ret = responseInts(p); break; |
| 476 | case RIL_REQUEST_CDMA_FLASH: ret = responseVoid(p); break; |
| 477 | case RIL_REQUEST_CDMA_BURST_DTMF: ret = responseVoid(p); break; |
| 478 | case RIL_REQUEST_CDMA_SEND_SMS: ret = responseSMS(p); break; |
| 479 | case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: ret = responseVoid(p); break; |
| 480 | case RIL_REQUEST_GSM_GET_BROADCAST_CONFIG: ret = responseGmsBroadcastConfig(p); break; |
| 481 | case RIL_REQUEST_GSM_SET_BROADCAST_CONFIG: ret = responseVoid(p); break; |
| 482 | case RIL_REQUEST_GSM_BROADCAST_ACTIVATION: ret = responseVoid(p); break; |
| 483 | case RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG: ret = responseCdmaBroadcastConfig(p); break; |
| 484 | case RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG: ret = responseVoid(p); break; |
| 485 | case RIL_REQUEST_CDMA_BROADCAST_ACTIVATION: ret = responseVoid(p); break; |
| 486 | case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: ret = responseVoid(p); break; |
| 487 | case RIL_REQUEST_CDMA_SUBSCRIPTION: ret = responseStrings(p); break; |
| 488 | case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: ret = responseInts(p); break; |
| 489 | case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: ret = responseVoid(p); break; |
| 490 | case RIL_REQUEST_DEVICE_IDENTITY: ret = responseStrings(p); break; |
| 491 | case RIL_REQUEST_GET_SMSC_ADDRESS: ret = responseString(p); break; |
| 492 | case RIL_REQUEST_SET_SMSC_ADDRESS: ret = responseVoid(p); break; |
| 493 | case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break; |
| 494 | case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: ret = responseVoid(p); break; |
| 495 | case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: ret = responseVoid(p); break; |
| 496 | case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: ret = responseInts(p); break; |
| 497 | case RIL_REQUEST_ISIM_AUTHENTICATION: ret = responseString(p); break; |
| 498 | case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: ret = responseVoid(p); break; |
| 499 | case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: ret = responseICC_IO(p); break; |
| 500 | case RIL_REQUEST_VOICE_RADIO_TECH: ret = responseInts(p); break; |
| 501 | case RIL_REQUEST_GET_CELL_INFO_LIST: ret = responseCellInfoList(p); break; |
| 502 | case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: ret = responseVoid(p); break; |
| 503 | case RIL_REQUEST_SET_INITIAL_ATTACH_APN: ret = responseVoid(p); break; |
| 504 | case RIL_REQUEST_IMS_REGISTRATION_STATE: ret = responseInts(p); break; |
| 505 | case RIL_REQUEST_IMS_SEND_SMS: ret = responseSMS(p); break; |
| 506 | default: |
| 507 | throw new RuntimeException("Unrecognized solicited response: " + rr.mRequest); |
| 508 | //break; |
| 509 | }} catch (Throwable tr) { |
| 510 | // Exceptions here usually mean invalid RIL responses |
| 511 | |
| 512 | Rlog.w(RILJ_LOG_TAG, rr.serialString() + "< " |
| 513 | + requestToString(rr.mRequest) |
| 514 | + " exception, possible invalid RIL response", tr); |
| 515 | |
| 516 | if (rr.mResult != null) { |
| 517 | AsyncResult.forMessage(rr.mResult, null, tr); |
| 518 | rr.mResult.sendToTarget(); |
| 519 | } |
| 520 | return rr; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | // Here and below fake RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, see b/7255789. |
| 525 | // This is needed otherwise we don't automatically transition to the main lock |
| 526 | // screen when the pin or puk is entered incorrectly. |
| 527 | switch (rr.mRequest) { |
| 528 | case RIL_REQUEST_ENTER_SIM_PUK: |
| 529 | case RIL_REQUEST_ENTER_SIM_PUK2: |
| 530 | if (mIccStatusChangedRegistrants != null) { |
| 531 | if (RILJ_LOGD) { |
| 532 | riljLog("ON enter sim puk fakeSimStatusChanged: reg count=" |
| 533 | + mIccStatusChangedRegistrants.size()); |
| 534 | } |
| 535 | mIccStatusChangedRegistrants.notifyRegistrants(); |
| 536 | } |
| 537 | break; |
| 538 | } |
| 539 | |
| 540 | if (error != 0) { |
| 541 | switch (rr.mRequest) { |
| 542 | case RIL_REQUEST_ENTER_SIM_PIN: |
| 543 | case RIL_REQUEST_ENTER_SIM_PIN2: |
| 544 | case RIL_REQUEST_CHANGE_SIM_PIN: |
| 545 | case RIL_REQUEST_CHANGE_SIM_PIN2: |
| 546 | case RIL_REQUEST_SET_FACILITY_LOCK: |
| 547 | if (mIccStatusChangedRegistrants != null) { |
| 548 | if (RILJ_LOGD) { |
| 549 | riljLog("ON some errors fakeSimStatusChanged: reg count=" |
| 550 | + mIccStatusChangedRegistrants.size()); |
| 551 | } |
| 552 | mIccStatusChangedRegistrants.notifyRegistrants(); |
| 553 | } |
| 554 | break; |
| 555 | } |
| 556 | |
| 557 | rr.onError(error, ret); |
| 558 | } else { |
| 559 | |
| 560 | if (RILJ_LOGD) riljLog(rr.serialString() + "< " + requestToString(rr.mRequest) |
| 561 | + " " + retToString(rr.mRequest, ret)); |
| 562 | |
| 563 | if (rr.mResult != null) { |
| 564 | AsyncResult.forMessage(rr.mResult, ret, null); |
| 565 | rr.mResult.sendToTarget(); |
| 566 | } |
| 567 | } |
| 568 | return rr; |
| 569 | } |
| 570 | |
| 571 | private Object |
| 572 | operatorCheck(Parcel p) { |
| 573 | String response[] = (String[])responseStrings(p); |
| 574 | for(int i=0; i<2; i++){ |
| 575 | if (response[i]!= null){ |
| 576 | response[i] = Operators.operatorReplace(response[i]); |
| 577 | } |
| 578 | } |
| 579 | return response; |
| 580 | } |
| 581 | |
| 582 | private Object |
| 583 | responseVoiceDataRegistrationState(Parcel p) { |
| 584 | String response[] = (String[])responseStrings(p); |
| 585 | if (isGSM){ |
| 586 | return response; |
| 587 | } |
| 588 | if (response.length>=10){ |
| 589 | for(int i=6; i<=9; i++){ |
| 590 | if (response[i]== null){ |
| 591 | response[i]=Integer.toString(Integer.MAX_VALUE); |
| 592 | } else { |
| 593 | try { |
| 594 | Integer.parseInt(response[i]); |
| 595 | } catch(NumberFormatException e) { |
| 596 | response[i]=Integer.toString(Integer.parseInt(response[i],16)); |
| 597 | } |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | return response; |
| 603 | } |
| 604 | |
| 605 | /** |
| 606 | * Set audio parameter "wb_amr" for HD-Voice (Wideband AMR). |
| 607 | * |
| 608 | * @param state: 0 = unsupported, 1 = supported. |
| 609 | */ |
| 610 | private void setWbAmr(int state) { |
| 611 | if (state == 1) { |
| 612 | Rlog.d(RILJ_LOG_TAG, "setWbAmr(): setting audio parameter - wb_amr=on"); |
| 613 | mAudioManager.setParameters("wide_voice_enable=true"); |
| 614 | }else if (state == 0) { |
| 615 | Rlog.d(RILJ_LOG_TAG, "setWbAmr(): setting audio parameter - wb_amr=off"); |
| 616 | mAudioManager.setParameters("wide_voice_enable=false"); |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | // Workaround for Samsung CDMA "ring of death" bug: |
| 621 | // |
| 622 | // Symptom: As soon as the phone receives notice of an incoming call, an |
| 623 | // audible "old fashioned ring" is emitted through the earpiece and |
| 624 | // persists through the duration of the call, or until reboot if the call |
| 625 | // isn't answered. |
| 626 | // |
| 627 | // Background: The CDMA telephony stack implements a number of "signal info |
| 628 | // tones" that are locally generated by ToneGenerator and mixed into the |
| 629 | // voice call path in response to radio RIL_UNSOL_CDMA_INFO_REC requests. |
| 630 | // One of these tones, IS95_CONST_IR_SIG_IS54B_L, is requested by the |
| 631 | // radio just prior to notice of an incoming call when the voice call |
| 632 | // path is muted. CallNotifier is responsible for stopping all signal |
| 633 | // tones (by "playing" the TONE_CDMA_SIGNAL_OFF tone) upon receipt of a |
| 634 | // "new ringing connection", prior to unmuting the voice call path. |
| 635 | // |
| 636 | // Problem: CallNotifier's incoming call path is designed to minimize |
| 637 | // latency to notify users of incoming calls ASAP. Thus, |
| 638 | // SignalInfoTonePlayer requests are handled asynchronously by spawning a |
| 639 | // one-shot thread for each. Unfortunately the ToneGenerator API does |
| 640 | // not provide a mechanism to specify an ordering on requests, and thus, |
| 641 | // unexpected thread interleaving may result in ToneGenerator processing |
| 642 | // them in the opposite order that CallNotifier intended. In this case, |
| 643 | // playing the "signal off" tone first, followed by playing the "old |
| 644 | // fashioned ring" indefinitely. |
| 645 | // |
| 646 | // Solution: An API change to ToneGenerator is required to enable |
| 647 | // SignalInfoTonePlayer to impose an ordering on requests (i.e., drop any |
| 648 | // request that's older than the most recent observed). Such a change, |
| 649 | // or another appropriate fix should be implemented in AOSP first. |
| 650 | // |
| 651 | // Workaround: Intercept RIL_UNSOL_CDMA_INFO_REC requests from the radio, |
| 652 | // check for a signal info record matching IS95_CONST_IR_SIG_IS54B_L, and |
| 653 | // drop it so it's never seen by CallNotifier. If other signal tones are |
| 654 | // observed to cause this problem, they should be dropped here as well. |
| 655 | @Override |
| 656 | protected void notifyRegistrantsCdmaInfoRec(CdmaInformationRecords infoRec) { |
| 657 | final int response = RIL_UNSOL_CDMA_INFO_REC; |
| 658 | |
| 659 | if (infoRec.record instanceof CdmaSignalInfoRec) { |
| 660 | CdmaSignalInfoRec sir = (CdmaSignalInfoRec) infoRec.record; |
| 661 | if (sir != null |
| 662 | && sir.isPresent |
| 663 | && sir.signalType == SignalToneUtil.IS95_CONST_IR_SIGNAL_IS54B |
| 664 | && sir.alertPitch == SignalToneUtil.IS95_CONST_IR_ALERT_MED |
| 665 | && sir.signal == SignalToneUtil.IS95_CONST_IR_SIG_IS54B_L) { |
| 666 | |
| 667 | Rlog.d(RILJ_LOG_TAG, "Dropping \"" + responseToString(response) + " " |
| 668 | + retToString(response, sir) |
| 669 | + "\" to prevent \"ring of death\" bug."); |
| 670 | return; |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | super.notifyRegistrantsCdmaInfoRec(infoRec); |
| 675 | } |
| 676 | |
| 677 | |
| 678 | |
| 679 | @Override |
| 680 | protected Object |
| 681 | responseSMS(Parcel p) { |
| 682 | // Notify that sendSMS() can send the next SMS |
| 683 | synchronized (mSMSLock) { |
| 684 | mIsSendingSMS = false; |
| 685 | mSMSLock.notify(); |
| 686 | } |
| 687 | |
| 688 | return super.responseSMS(p); |
| 689 | } |
| 690 | |
| 691 | @Override |
| 692 | public void |
| 693 | dial(String address, int clirMode, UUSInfo uusInfo, Message result) { |
| 694 | if (samsungEmergency && PhoneNumberUtils.isEmergencyNumber(address)) { |
| 695 | dialEmergencyCall(address, clirMode, result); |
| 696 | return; |
| 697 | } |
| 698 | RILRequest rr = RILRequest.obtain(RIL_REQUEST_DIAL, result); |
| 699 | |
| 700 | rr.mParcel.writeString(address); |
| 701 | rr.mParcel.writeInt(clirMode); |
| 702 | rr.mParcel.writeInt(0); |
| 703 | rr.mParcel.writeInt(1); |
| 704 | rr.mParcel.writeString(""); |
| 705 | |
| 706 | if (uusInfo == null) { |
| 707 | rr.mParcel.writeInt(0); // UUS information is absent |
| 708 | } else { |
| 709 | rr.mParcel.writeInt(1); // UUS information is present |
| 710 | rr.mParcel.writeInt(uusInfo.getType()); |
| 711 | rr.mParcel.writeInt(uusInfo.getDcs()); |
| 712 | rr.mParcel.writeByteArray(uusInfo.getUserData()); |
| 713 | } |
| 714 | |
| 715 | if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); |
| 716 | |
| 717 | send(rr); |
| 718 | } |
| 719 | |
| 720 | //this method is used in the search network functionality. |
| 721 | // in mobile network setting-> network operators |
| 722 | @Override |
| 723 | protected Object |
| 724 | responseOperatorInfos(Parcel p) { |
| 725 | String strings[] = (String [])responseStrings(p); |
| 726 | ArrayList<OperatorInfo> ret; |
| 727 | |
| 728 | if (strings.length % mQANElements != 0) { |
| 729 | throw new RuntimeException( |
| 730 | "RIL_REQUEST_QUERY_AVAILABLE_NETWORKS: invalid response. Got " |
| 731 | + strings.length + " strings, expected multiple of " + mQANElements); |
| 732 | } |
| 733 | |
| 734 | Rlog.v(RILJ_LOG_TAG, "responseOperatorInfos"); |
| 735 | ret = new ArrayList<OperatorInfo>(strings.length / mQANElements); |
| 736 | Operators init = null; |
| 737 | if (strings.length != 0) { |
| 738 | init = new Operators(); |
| 739 | } |
| 740 | for (int i = 0 ; i < strings.length ; i += mQANElements) { |
| 741 | String temp = init.unOptimizedOperatorReplace(strings[i+0]); |
| 742 | ret.add ( |
| 743 | new OperatorInfo( |
| 744 | temp, //operatorAlphaLong |
| 745 | temp,//operatorAlphaShort |
| 746 | strings[i+2],//operatorNumeric |
| 747 | strings[i+3]));//state |
| 748 | } |
| 749 | |
| 750 | return ret; |
| 751 | } |
| 752 | |
| 753 | @Override |
| 754 | public void getImsRegistrationState(Message result) { |
| 755 | if(mRilVersion >= 8) |
| 756 | super.getImsRegistrationState(result); |
| 757 | else { |
| 758 | if (result != null) { |
| 759 | CommandException ex = new CommandException( |
| 760 | CommandException.Error.REQUEST_NOT_SUPPORTED); |
| 761 | AsyncResult.forMessage(result, null, ex); |
| 762 | result.sendToTarget(); |
| 763 | } |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | static final int RIL_REQUEST_DIAL_EMERGENCY = 10016; |
| 768 | public void |
| 769 | dialEmergencyCall(String address, int clirMode, Message result) { |
| 770 | RILRequest rr; |
| 771 | Rlog.v(RILJ_LOG_TAG, "Emergency dial: " + address); |
| 772 | |
| 773 | rr = RILRequest.obtain(RIL_REQUEST_DIAL_EMERGENCY, result); |
| 774 | rr.mParcel.writeString(address + "/"); |
| 775 | rr.mParcel.writeInt(clirMode); |
| 776 | rr.mParcel.writeInt(0); // UUS information is absent |
| 777 | |
| 778 | if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); |
| 779 | |
| 780 | send(rr); |
| 781 | } |
| 782 | |
| 783 | // This call causes ril to crash the socket, stopping further communication |
| 784 | @Override |
| 785 | public void |
| 786 | getHardwareConfig (Message result) { |
| 787 | riljLog("Ignoring call to 'getHardwareConfig'"); |
| 788 | if (result != null) { |
| 789 | CommandException ex = new CommandException( |
| 790 | CommandException.Error.REQUEST_NOT_SUPPORTED); |
| 791 | AsyncResult.forMessage(result, null, ex); |
| 792 | result.sendToTarget(); |
| 793 | } |
| 794 | } |
| 795 | } |