Zvikomborero VIncent Zvikaramba | 9b3a907 | 2016-07-29 05:52:32 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014, The CyanogenMod Project. All rights reserved. |
| 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.telephony.Rlog; |
| 23 | import android.os.AsyncResult; |
| 24 | import android.os.Message; |
| 25 | import android.os.Parcel; |
| 26 | import android.os.SystemProperties; |
| 27 | import android.telephony.PhoneNumberUtils; |
| 28 | import android.telephony.SignalStrength; |
| 29 | import com.android.internal.telephony.uicc.IccCardApplicationStatus; |
| 30 | import com.android.internal.telephony.uicc.IccCardStatus; |
| 31 | import java.util.ArrayList; |
| 32 | import java.util.Collections; |
| 33 | |
| 34 | /** |
| 35 | * Qualcomm RIL for Samsung MSM8916 (3G) devices |
| 36 | * {@hide} |
| 37 | */ |
| 38 | public class SamsungQcom3GDSRIL extends RIL { |
| 39 | |
| 40 | private static final int RIL_REQUEST_DIAL_EMERGENCY = 10001; |
| 41 | private static final int RIL_UNSOL_ON_SS_LL = 11055; |
| 42 | |
| 43 | public SamsungQcom3GDSRIL(Context context, int networkMode, int cdmaSubscription) { |
| 44 | super(context, networkMode, cdmaSubscription, null); |
| 45 | mQANElements = 6; |
| 46 | } |
| 47 | |
| 48 | public SamsungQcom3GDSRIL(Context context, int preferredNetworkType, |
| 49 | int cdmaSubscription, Integer instanceId) { |
| 50 | super(context, preferredNetworkType, cdmaSubscription, instanceId); |
| 51 | mQANElements = 6; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public void |
| 56 | dial(String address, int clirMode, UUSInfo uusInfo, Message result) { |
| 57 | if (PhoneNumberUtils.isEmergencyNumber(address)) { |
| 58 | dialEmergencyCall(address, clirMode, result); |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | RILRequest rr = RILRequest.obtain(RIL_REQUEST_DIAL, result); |
| 63 | |
| 64 | rr.mParcel.writeString(address); |
| 65 | rr.mParcel.writeInt(clirMode); |
| 66 | rr.mParcel.writeInt(0); // CallDetails.call_type |
| 67 | rr.mParcel.writeInt(1); // CallDetails.call_domain |
| 68 | rr.mParcel.writeString(""); // CallDetails.getCsvFromExtras |
| 69 | |
| 70 | if (uusInfo == null) { |
| 71 | rr.mParcel.writeInt(0); // UUS information is absent |
| 72 | } else { |
| 73 | rr.mParcel.writeInt(1); // UUS information is present |
| 74 | rr.mParcel.writeInt(uusInfo.getType()); |
| 75 | rr.mParcel.writeInt(uusInfo.getDcs()); |
| 76 | rr.mParcel.writeByteArray(uusInfo.getUserData()); |
| 77 | } |
| 78 | |
| 79 | if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); |
| 80 | |
| 81 | send(rr); |
| 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 | for (int i = 0 ; i < numApplications ; i++) { |
| 105 | appStatus = new IccCardApplicationStatus(); |
| 106 | appStatus.app_type = appStatus.AppTypeFromRILInt(p.readInt()); |
| 107 | appStatus.app_state = appStatus.AppStateFromRILInt(p.readInt()); |
| 108 | appStatus.perso_substate = appStatus.PersoSubstateFromRILInt(p.readInt()); |
| 109 | appStatus.aid = p.readString(); |
| 110 | appStatus.app_label = p.readString(); |
| 111 | appStatus.pin1_replaced = p.readInt(); |
| 112 | appStatus.pin1 = appStatus.PinStateFromRILInt(p.readInt()); |
| 113 | appStatus.pin2 = appStatus.PinStateFromRILInt(p.readInt()); |
| 114 | p.readInt(); // pin1_num_retries |
| 115 | p.readInt(); // puk1_num_retries |
| 116 | p.readInt(); // pin2_num_retries |
| 117 | p.readInt(); // puk2_num_retries |
| 118 | p.readInt(); // perso_unblock_retries |
| 119 | |
| 120 | cardStatus.mApplications[i] = appStatus; |
| 121 | } |
| 122 | return cardStatus; |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | protected Object |
| 127 | responseCallList(Parcel p) { |
| 128 | int num; |
| 129 | int voiceSettings; |
| 130 | ArrayList<DriverCall> response; |
| 131 | DriverCall dc; |
| 132 | |
| 133 | num = p.readInt(); |
| 134 | response = new ArrayList<DriverCall>(num); |
| 135 | |
| 136 | if (RILJ_LOGV) { |
| 137 | riljLog("responseCallList: num=" + num + |
| 138 | " mEmergencyCallbackModeRegistrant=" + mEmergencyCallbackModeRegistrant + |
| 139 | " mTestingEmergencyCall=" + mTestingEmergencyCall.get()); |
| 140 | } |
| 141 | for (int i = 0 ; i < num ; i++) { |
| 142 | dc = new DriverCall(); |
| 143 | |
| 144 | dc.state = DriverCall.stateFromCLCC(p.readInt()); |
| 145 | dc.index = p.readInt() & 0xff; |
| 146 | dc.TOA = p.readInt(); |
| 147 | dc.isMpty = (0 != p.readInt()); |
| 148 | dc.isMT = (0 != p.readInt()); |
| 149 | dc.als = p.readInt(); |
| 150 | voiceSettings = p.readInt(); |
| 151 | dc.isVoice = (0 == voiceSettings) ? false : true; |
| 152 | boolean isVideo; |
| 153 | int call_type = p.readInt(); // Samsung CallDetails |
| 154 | int call_domain = p.readInt(); // Samsung CallDetails |
| 155 | String csv = p.readString(); // Samsung CallDetails |
| 156 | dc.isVoicePrivacy = (0 != p.readInt()); |
| 157 | dc.number = p.readString(); |
| 158 | int np = p.readInt(); |
| 159 | dc.numberPresentation = DriverCall.presentationFromCLIP(np); |
| 160 | dc.name = p.readString(); |
| 161 | dc.namePresentation = DriverCall.presentationFromCLIP(p.readInt()); |
| 162 | int uusInfoPresent = p.readInt(); |
| 163 | if (uusInfoPresent == 1) { |
| 164 | dc.uusInfo = new UUSInfo(); |
| 165 | dc.uusInfo.setType(p.readInt()); |
| 166 | dc.uusInfo.setDcs(p.readInt()); |
| 167 | byte[] userData = p.createByteArray(); |
| 168 | dc.uusInfo.setUserData(userData); |
| 169 | riljLogv(String.format("Incoming UUS : type=%d, dcs=%d, length=%d", |
| 170 | dc.uusInfo.getType(), dc.uusInfo.getDcs(), |
| 171 | dc.uusInfo.getUserData().length)); |
| 172 | riljLogv("Incoming UUS : data (string)=" |
| 173 | + new String(dc.uusInfo.getUserData())); |
| 174 | riljLogv("Incoming UUS : data (hex): " |
| 175 | + IccUtils.bytesToHexString(dc.uusInfo.getUserData())); |
| 176 | } else { |
| 177 | riljLogv("Incoming UUS : NOT present!"); |
| 178 | } |
| 179 | |
| 180 | // Make sure there's a leading + on addresses with a TOA of 145 |
| 181 | dc.number = PhoneNumberUtils.stringFromStringAndTOA(dc.number, dc.TOA); |
| 182 | |
| 183 | response.add(dc); |
| 184 | |
| 185 | if (dc.isVoicePrivacy) { |
| 186 | mVoicePrivacyOnRegistrants.notifyRegistrants(); |
| 187 | riljLog("InCall VoicePrivacy is enabled"); |
| 188 | } else { |
| 189 | mVoicePrivacyOffRegistrants.notifyRegistrants(); |
| 190 | riljLog("InCall VoicePrivacy is disabled"); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | Collections.sort(response); |
| 195 | |
| 196 | if ((num == 0) && mTestingEmergencyCall.getAndSet(false)) { |
| 197 | if (mEmergencyCallbackModeRegistrant != null) { |
| 198 | riljLog("responseCallList: call ended, testing emergency call," + |
| 199 | " notify ECM Registrants"); |
| 200 | mEmergencyCallbackModeRegistrant.notifyRegistrant(); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | return response; |
| 205 | } |
| 206 | |
| 207 | @Override |
| 208 | protected Object |
| 209 | responseSignalStrength(Parcel p) { |
| 210 | int gsmSignalStrength = p.readInt() & 0xff; |
| 211 | int gsmBitErrorRate = p.readInt(); |
| 212 | int cdmaDbm = p.readInt(); |
| 213 | int cdmaEcio = p.readInt(); |
| 214 | int evdoDbm = p.readInt(); |
| 215 | int evdoEcio = p.readInt(); |
| 216 | int evdoSnr = p.readInt(); |
| 217 | int lteSignalStrength = p.readInt(); |
| 218 | int lteRsrp = p.readInt(); |
| 219 | int lteRsrq = p.readInt(); |
| 220 | int lteRssnr = p.readInt(); |
| 221 | int lteCqi = p.readInt(); |
| 222 | int tdScdmaRscp = p.readInt(); |
| 223 | // constructor sets default true, makeSignalStrengthFromRilParcel does not set it |
| 224 | boolean isGsm = true; |
| 225 | |
| 226 | if ((lteSignalStrength & 0xff) == 255 || lteSignalStrength == 99) { |
| 227 | lteSignalStrength = 99; |
| 228 | lteRsrp = SignalStrength.INVALID; |
| 229 | lteRsrq = SignalStrength.INVALID; |
| 230 | lteRssnr = SignalStrength.INVALID; |
| 231 | lteCqi = SignalStrength.INVALID; |
| 232 | } else { |
| 233 | lteSignalStrength &= 0xff; |
| 234 | } |
| 235 | |
| 236 | if (RILJ_LOGD) |
| 237 | riljLog("gsmSignalStrength:" + gsmSignalStrength + " gsmBitErrorRate:" + gsmBitErrorRate + |
| 238 | " cdmaDbm:" + cdmaDbm + " cdmaEcio:" + cdmaEcio + " evdoDbm:" + evdoDbm + |
| 239 | " evdoEcio: " + evdoEcio + " evdoSnr:" + evdoSnr + |
| 240 | " lteSignalStrength:" + lteSignalStrength + " lteRsrp:" + lteRsrp + |
| 241 | " lteRsrq:" + lteRsrq + " lteRssnr:" + lteRssnr + " lteCqi:" + lteCqi + |
| 242 | " tdScdmaRscp:" + tdScdmaRscp + " isGsm:" + (isGsm ? "true" : "false")); |
| 243 | |
| 244 | return new SignalStrength(gsmSignalStrength, gsmBitErrorRate, cdmaDbm, cdmaEcio, evdoDbm, |
| 245 | evdoEcio, evdoSnr, lteSignalStrength, lteRsrp, lteRsrq, lteRssnr, lteCqi, |
| 246 | tdScdmaRscp, isGsm); |
| 247 | } |
| 248 | |
| 249 | @Override |
| 250 | protected void |
| 251 | processUnsolicited (Parcel p) { |
| 252 | Object ret; |
| 253 | int dataPosition = p.dataPosition(); |
| 254 | int response = p.readInt(); |
| 255 | int newResponse = response; |
| 256 | |
| 257 | switch(response) { |
| 258 | case RIL_UNSOL_ON_SS_LL: |
| 259 | newResponse = RIL_UNSOL_ON_SS; |
| 260 | break; |
| 261 | } |
| 262 | if (newResponse != response) { |
| 263 | p.setDataPosition(dataPosition); |
| 264 | p.writeInt(newResponse); |
| 265 | } |
| 266 | p.setDataPosition(dataPosition); |
| 267 | super.processUnsolicited(p); |
| 268 | } |
| 269 | |
| 270 | @Override |
| 271 | public void |
| 272 | acceptCall (Message result) { |
| 273 | RILRequest rr |
| 274 | = RILRequest.obtain(RIL_REQUEST_ANSWER, result); |
| 275 | |
| 276 | rr.mParcel.writeInt(1); |
| 277 | rr.mParcel.writeInt(0); |
| 278 | |
| 279 | if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); |
| 280 | |
| 281 | send(rr); |
| 282 | } |
| 283 | |
| 284 | private void |
| 285 | dialEmergencyCall(String address, int clirMode, Message result) { |
| 286 | RILRequest rr; |
| 287 | |
| 288 | rr = RILRequest.obtain(RIL_REQUEST_DIAL_EMERGENCY, result); |
| 289 | rr.mParcel.writeString(address); |
| 290 | rr.mParcel.writeInt(clirMode); |
| 291 | rr.mParcel.writeInt(0); // CallDetails.call_type |
| 292 | rr.mParcel.writeInt(3); // CallDetails.call_domain |
| 293 | rr.mParcel.writeString(""); // CallDetails.getCsvFromExtra |
| 294 | rr.mParcel.writeInt(0); // Unknown |
| 295 | |
| 296 | if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)); |
| 297 | |
| 298 | send(rr); |
| 299 | } |
| 300 | |
| 301 | @Override |
| 302 | protected RILRequest |
| 303 | processSolicited (Parcel p) { |
| 304 | int serial, error; |
| 305 | boolean found = false; |
| 306 | int dataPosition = p.dataPosition(); // save off position within the Parcel |
| 307 | serial = p.readInt(); |
| 308 | error = p.readInt(); |
| 309 | RILRequest rr = null; |
| 310 | /* Pre-process the reply before popping it */ |
| 311 | synchronized (mRequestList) { |
| 312 | RILRequest tr = mRequestList.get(serial); |
| 313 | if (tr != null && tr.mSerial == serial) { |
| 314 | if (error == 0 || p.dataAvail() > 0) { |
| 315 | try {switch (tr.mRequest) { |
| 316 | /* Get those we're interested in */ |
| 317 | case RIL_REQUEST_DATA_REGISTRATION_STATE: |
| 318 | rr = tr; |
| 319 | break; |
| 320 | }} catch (Throwable thr) { |
| 321 | // Exceptions here usually mean invalid RIL responses |
| 322 | if (tr.mResult != null) { |
| 323 | AsyncResult.forMessage(tr.mResult, null, thr); |
| 324 | tr.mResult.sendToTarget(); |
| 325 | } |
| 326 | return tr; |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | if (rr == null) { |
| 332 | /* Nothing we care about, go up */ |
| 333 | p.setDataPosition(dataPosition); |
| 334 | // Forward responses that we are not overriding to the super class |
| 335 | return super.processSolicited(p); |
| 336 | } |
| 337 | rr = findAndRemoveRequestFromList(serial); |
| 338 | if (rr == null) { |
| 339 | return rr; |
| 340 | } |
| 341 | Object ret = null; |
| 342 | if (error == 0 || p.dataAvail() > 0) { |
| 343 | switch (rr.mRequest) { |
| 344 | case RIL_REQUEST_DATA_REGISTRATION_STATE: ret = responseDataRegistrationState(p); break; |
| 345 | default: |
| 346 | throw new RuntimeException("Unrecognized solicited response: " + rr.mRequest); |
| 347 | } |
| 348 | //break; |
| 349 | } |
| 350 | if (RILJ_LOGD) riljLog(rr.serialString() + "< " + requestToString(rr.mRequest) |
| 351 | + " " + retToString(rr.mRequest, ret)); |
| 352 | if (rr.mResult != null) { |
| 353 | AsyncResult.forMessage(rr.mResult, ret, null); |
| 354 | rr.mResult.sendToTarget(); |
| 355 | } |
| 356 | return rr; |
| 357 | } |
| 358 | |
| 359 | private Object |
| 360 | responseDataRegistrationState(Parcel p) { |
| 361 | String response[] = (String[])responseStrings(p); |
| 362 | /* DANGER WILL ROBINSON |
| 363 | * In some cases from Vodaphone we are receiving a RAT of 102 |
| 364 | * while in tunnels of the metro. Lets Assume that if we |
| 365 | * receive 102 we actually want a RAT of 2 for EDGE service */ |
| 366 | if (response.length > 4 && |
| 367 | response[0].equals("1") && |
| 368 | response[3].equals("102")) { |
| 369 | response[3] = "2"; |
| 370 | } |
| 371 | return response; |
| 372 | } |
| 373 | } |