Advertisement
Guest User

Untitled

a guest
Sep 7th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.65 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2016 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 com.android.internal.telephony.dataconnection.DataCallResponse;
  22. import com.android.internal.telephony.uicc.IccRefreshResponse;
  23.  
  24. import android.content.Context;
  25. import android.os.AsyncResult;
  26. import android.os.Message;
  27. import android.os.Parcel;
  28. import android.os.SystemProperties;
  29.  
  30. import android.provider.Settings;
  31. import android.provider.Settings.Global;
  32.  
  33. import android.telephony.TelephonyManager;
  34. import android.telephony.Rlog;
  35.  
  36. import com.android.internal.telephony.MtkEccList;
  37.  
  38.  
  39. /**
  40. * Custom wrapper for MTK requests
  41. *
  42. * {@hide}
  43. */
  44. public class MT6753 extends RIL implements CommandsInterface {
  45.  
  46. private static final int RIL_UNSOL_RESPONSE_PS_NETWORK_STATE_CHANGED = 3015;
  47. private static final int RIL_UNSOL_RESPONSE_REGISTRATION_SUSPENDED = 3024;
  48. private static final int RIL_UNSOL_INCOMING_CALL_INDICATION = 3042;
  49. private static final int RIL_UNSOL_CALL_INFO_INDICATION = 3049;
  50. private static final int RIL_UNSOL_SET_ATTACH_APN = 3073;
  51.  
  52. private static final int RIL_REQUEST_MODEM_POWEROFF = 2010;
  53. private static final int RIL_REQUEST_MODEM_POWERON = 2028;
  54. private static final int RIL_REQUEST_RESUME_REGISTRATION = 2065;
  55. private static final int RIL_REQUEST_SET_CALL_INDICATION = 2086;
  56. private static final int RIL_REQUEST_EMERGENCY_DIAL = 2087;
  57. private static final int RIL_REQUEST_SET_ECC_SERVICE_CATEGORY = 2088;
  58. private static final int RIL_REQUEST_SET_ECC_LIST = 2089;
  59.  
  60. private static final int REFRESH_SESSION_RESET = 6; /* Session reset */
  61.  
  62. private int[] dataCallCids = { -1, -1, -1, -1, -1 };
  63.  
  64. private Context mContext;
  65. private TelephonyManager mTelephonyManager;
  66. private MtkEccList mEccList;
  67.  
  68. public MT6753(Context context, int preferredNetworkType, int cdmaSubscription) {
  69. super(context, preferredNetworkType, cdmaSubscription, null);
  70. }
  71.  
  72. public MT6753(Context context, int preferredNetworkType,
  73. int cdmaSubscription, Integer instanceId) {
  74. super(context, preferredNetworkType, cdmaSubscription, instanceId);
  75. mContext = context;
  76. mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  77. mEccList = new MtkEccList();
  78. }
  79.  
  80. private static String
  81. localRequestToString(int request)
  82. {
  83. switch(request) {
  84. case RIL_REQUEST_RESUME_REGISTRATION: return "RIL_REQUEST_RESUME_REGISTRATION";
  85. case RIL_REQUEST_SET_CALL_INDICATION: return "RIL_REQUEST_SET_CALL_INDICATION";
  86. case RIL_REQUEST_EMERGENCY_DIAL: return "RIL_REQUEST_EMERGENCY_DIAL";
  87. case RIL_REQUEST_SET_ECC_SERVICE_CATEGORY: return "RIL_REQUEST_SET_ECC_SERVICE_CATEGORY";
  88. case RIL_REQUEST_SET_ECC_LIST: return "RIL_REQUEST_SET_ECC_LIST";
  89. case RIL_REQUEST_MODEM_POWEROFF: return "RIL_REQUEST_MODEM_POWEROFF";
  90. case RIL_REQUEST_MODEM_POWERON: return "RIL_REQUEST_MODEM_POWERON";
  91. default: return "<unknown response>";
  92. }
  93. }
  94.  
  95.  
  96. @Override
  97. protected void
  98. processUnsolicited (Parcel p) {
  99. Object ret;
  100. int dataPosition = p.dataPosition(); // save off position within the Parcel
  101. int response = p.readInt();
  102.  
  103. switch(response) {
  104. case RIL_UNSOL_RESPONSE_REGISTRATION_SUSPENDED: ret = responseRegSuspended(p); break;
  105. case RIL_UNSOL_INCOMING_CALL_INDICATION: ret = responseIncomingCallIndication(p); break;
  106. case RIL_UNSOL_CALL_INFO_INDICATION: ret = responseCallProgress(p); break;
  107. case RIL_UNSOL_SET_ATTACH_APN: ret = responseSetAttachApn(p); break;
  108. case RIL_UNSOL_ON_USSD: ret = responseStrings(p); break;
  109. case RIL_UNSOL_RESPONSE_PS_NETWORK_STATE_CHANGED: ret = responseInts(p); break;
  110. default:
  111. // Rewind the Parcel
  112. p.setDataPosition(dataPosition);
  113. // Forward responses that we are not overriding to the super class
  114. super.processUnsolicited(p);
  115. return;
  116. }
  117. switch(response) {
  118. case RIL_UNSOL_INCOMING_CALL_INDICATION:
  119. mCallStateRegistrants
  120. .notifyRegistrants(new AsyncResult(null, null, null));
  121. break;
  122. case RIL_UNSOL_CALL_INFO_INDICATION:
  123. if (ret == null) {
  124. mCallStateRegistrants
  125. .notifyRegistrants(new AsyncResult(null, null, null));
  126. }
  127. break;
  128. case RIL_UNSOL_ON_USSD:
  129. String[] resp = (String[])ret;
  130.  
  131. if (resp.length < 2) {
  132. resp = new String[2];
  133. resp[0] = ((String[])ret)[0];
  134. resp[1] = null;
  135. }
  136. if (resp[0] != null &&
  137. Integer.parseInt(resp[0]) >= 2 &&
  138. Integer.parseInt(resp[0]) <=5 ) {
  139. // support USSD_SESSION_END and USSD_HANDLED_BY_STK as normal finishes
  140. resp[0] = "0";
  141. }
  142.  
  143. if (RILJ_LOGD) unsljLogMore(response, resp[0]);
  144. if (mUSSDRegistrant != null) {
  145. mUSSDRegistrant.notifyRegistrant(
  146. new AsyncResult (null, resp, null));
  147. }
  148. break;
  149. case RIL_UNSOL_RESPONSE_PS_NETWORK_STATE_CHANGED:
  150. if (((int[])ret)[0] != 4)
  151. mVoiceNetworkStateRegistrants
  152. .notifyRegistrants(new AsyncResult(null, null, null));
  153. break;
  154.  
  155. }
  156.  
  157. }
  158.  
  159. protected Object
  160. responseRegSuspended(Parcel p) {
  161. int numInts;
  162. int response[];
  163.  
  164. numInts = p.readInt();
  165.  
  166. response = new int[numInts];
  167.  
  168. for (int i = 0 ; i < numInts ; i++) {
  169. response[i] = p.readInt();
  170. }
  171.  
  172. RILRequest rr = RILRequest.obtain(RIL_REQUEST_RESUME_REGISTRATION, null);
  173.  
  174. if (RILJ_LOGD) riljLog(rr.serialString() + "> " + localRequestToString(rr.mRequest)
  175. + " sessionId " + response[0]);
  176.  
  177. rr.mParcel.writeInt(1);
  178. rr.mParcel.writeInt(response[0]);
  179.  
  180. send(rr);
  181.  
  182. return response;
  183. }
  184.  
  185. protected Object
  186. responseIncomingCallIndication(Parcel p) {
  187. String response[];
  188.  
  189. response = p.readStringArray();
  190.  
  191. RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_CALL_INDICATION, null);
  192.  
  193. if (RILJ_LOGD) riljLog(rr.serialString() + "> " + localRequestToString(rr.mRequest));
  194.  
  195. rr.mParcel.writeInt(3);
  196. rr.mParcel.writeInt(Integer.parseInt(response[3]));
  197. rr.mParcel.writeInt(Integer.parseInt(response[0]));
  198. rr.mParcel.writeInt(Integer.parseInt(response[4]));
  199. send(rr);
  200.  
  201. return response;
  202. }
  203.  
  204. protected Object
  205. responseCallProgress(Parcel p) {
  206. String response[];
  207.  
  208. response = p.readStringArray();
  209.  
  210. if (response.length >= 2) {
  211. if (response[1].equals("129")) { // Call termination
  212. return null;
  213. }
  214. }
  215. return response;
  216. }
  217.  
  218. @Override
  219. public void setInitialAttachApn(String apn, String protocol, int authType, String username,
  220. String password, Message result) {
  221. RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_INITIAL_ATTACH_APN, null);
  222.  
  223. String operatorNumber = mTelephonyManager.getSimOperatorNumericForPhone(mInstanceId);
  224. if (RILJ_LOGD) { riljLog("Set RIL_REQUEST_SET_INITIAL_ATTACH_APN"); }
  225.  
  226. rr.mParcel.writeString(apn);
  227. rr.mParcel.writeString(protocol);
  228. rr.mParcel.writeInt(authType);
  229. rr.mParcel.writeString(username);
  230. rr.mParcel.writeString(password);
  231.  
  232. rr.mParcel.writeString(operatorNumber);
  233. rr.mParcel.writeInt(1);
  234. rr.mParcel.writeStringArray(null);
  235.  
  236. if (RILJ_LOGD) { riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
  237. + ", apn:" + apn + ", protocol:" + protocol + ", authType:" + authType
  238. + ", username:" + username + ", password:" + password + ", operator:" + operatorNumber);
  239. }
  240.  
  241. send(rr);
  242. }
  243.  
  244. protected Object
  245. responseSetAttachApn(Parcel p) {
  246. // The stack refuses to attach to LTE unless an IA APN was set, and
  247. // will loop until it happens. Set an empty one to unblock.
  248. setInitialAttachApn("","",0,"","",null);
  249. return null;
  250. }
  251.  
  252. @Override
  253. protected Object
  254. responseSimRefresh(Parcel p) {
  255. IccRefreshResponse response = new IccRefreshResponse();
  256.  
  257. response.refreshResult = p.readInt();
  258. String rawefId = p.readString();
  259. response.efId = rawefId == null ? 0 : Integer.parseInt(rawefId);
  260. response.aid = p.readString();
  261.  
  262. if (response.refreshResult > IccRefreshResponse.REFRESH_RESULT_RESET) {
  263. if (response.refreshResult == REFRESH_SESSION_RESET) {
  264. response.refreshResult = IccRefreshResponse.REFRESH_RESULT_RESET;
  265. } else {
  266. response.refreshResult = IccRefreshResponse.REFRESH_RESULT_INIT;
  267. }
  268. }
  269.  
  270. return response;
  271. }
  272.  
  273. @Override
  274. public void
  275. setupDataCall(String radioTechnology, String profile, String apn,
  276. String user, String password, String authType, String protocol,
  277. Message result) {
  278. int interfaceId=0;
  279. RILRequest rr
  280. = RILRequest.obtain(RIL_REQUEST_SETUP_DATA_CALL, result);
  281.  
  282. rr.mParcel.writeInt(8); //bumped by one
  283.  
  284. rr.mParcel.writeString(radioTechnology);
  285. rr.mParcel.writeString(profile);
  286. rr.mParcel.writeString(apn);
  287. rr.mParcel.writeString(user);
  288. rr.mParcel.writeString(password);
  289. rr.mParcel.writeString(authType);
  290. rr.mParcel.writeString(protocol);
  291.  
  292. /* Find the first available interfaceId */
  293. for (int i=0; i < 4; i++) {
  294. if (dataCallCids[i] < 0) {
  295. interfaceId = i+1;
  296. break;
  297. }
  298. }
  299. rr.mParcel.writeString(interfaceId+"");
  300.  
  301. if (RILJ_LOGD) riljLog(rr.serialString() + "> "
  302. + requestToString(rr.mRequest) + " " + radioTechnology + " "
  303. + profile + " " + apn + " " + user + " "
  304. + password + " " + authType + " " + protocol + " " + interfaceId);
  305.  
  306. send(rr);
  307. }
  308.  
  309. @Override
  310. public void
  311. deactivateDataCall(int cid, int reason, Message result) {
  312. for (int i=0; i < 4; i++) {
  313. if (dataCallCids[i] == cid) {
  314. dataCallCids[i] = -1;
  315. break;
  316. }
  317. }
  318. super.deactivateDataCall(cid, reason, result);
  319. }
  320.  
  321. @Override
  322. public void
  323. dial(String address, int clirMode, UUSInfo uusInfo, Message result) {
  324. if (mEccList.isEmergencyNumberExt(address)) {
  325. int serviceCategory = mEccList.getServiceCategoryFromEcc(address);
  326.  
  327. RILRequest rr = RILRequest.obtain(RIL_REQUEST_SET_ECC_SERVICE_CATEGORY, null);
  328.  
  329. rr.mParcel.writeInt(1);
  330. rr.mParcel.writeInt(serviceCategory);
  331.  
  332. if (RILJ_LOGD) riljLog(rr.serialString() + "> " + localRequestToString(rr.mRequest)
  333. + " " + serviceCategory);
  334.  
  335. send(rr);
  336.  
  337.  
  338. rr = RILRequest.obtain(RIL_REQUEST_EMERGENCY_DIAL, result);
  339. rr.mParcel.writeString(address);
  340. rr.mParcel.writeInt(clirMode);
  341. rr.mParcel.writeInt(0); // UUS information is absent
  342.  
  343. if (uusInfo == null) {
  344. rr.mParcel.writeInt(0); // UUS information is absent
  345. } else {
  346. rr.mParcel.writeInt(1); // UUS information is present
  347. rr.mParcel.writeInt(uusInfo.getType());
  348. rr.mParcel.writeInt(uusInfo.getDcs());
  349. rr.mParcel.writeByteArray(uusInfo.getUserData());
  350. }
  351.  
  352. if (RILJ_LOGD) riljLog(rr.serialString() + "> " + localRequestToString(rr.mRequest));
  353.  
  354. send(rr);
  355.  
  356. } else {
  357. super.dial(address, clirMode, uusInfo, result);
  358. }
  359. }
  360.  
  361. private void refreshEmergencyList() {
  362. if (mEccList != null) mEccList.updateEmergencyNumbersProperty();
  363. }
  364.  
  365. @Override
  366. public void
  367. setRadioPower(boolean on, Message result) {
  368. boolean isInApm = Settings.Global.getInt(mContext.getContentResolver(),
  369. Settings.Global.AIRPLANE_MODE_ON, 0) == 1;
  370. boolean wasInApm = SystemProperties.get("persist.radio.airplane.mode.on").equals("true");
  371.  
  372. SystemProperties.set("persist.radio.airplane.mode.on", isInApm ? "true" : "false");
  373.  
  374. if (on && wasInApm && !isInApm) {
  375. SystemProperties.set("gsm.ril.eboot", "0");
  376. RILRequest rr = RILRequest.obtain(RIL_REQUEST_MODEM_POWERON, result);
  377. if (RILJ_LOGD) {
  378. riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
  379. }
  380. send(rr);
  381. } else if (!on && isInApm) {
  382. SystemProperties.set("gsm.ril.eboot", "1");
  383. RILRequest rr = RILRequest.obtain(RIL_REQUEST_MODEM_POWEROFF, result);
  384. if (RILJ_LOGD) {
  385. riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
  386. }
  387. send(rr);
  388. } else {
  389. super.setRadioPower(on, result);
  390. }
  391. }
  392.  
  393. // Solicited request handling
  394. @Override
  395. protected RILRequest
  396. processSolicited (Parcel p) {
  397. int serial, error;
  398. int dataPosition = p.dataPosition(); // save off position within the Parcel
  399. serial = p.readInt();
  400. error = p.readInt();
  401.  
  402. RILRequest rr = null;
  403.  
  404. /* Pre-process the reply before popping it */
  405. synchronized (mRequestList) {
  406. RILRequest tr = mRequestList.get(serial);
  407. if (tr != null && tr.mSerial == serial) {
  408. if (error == 0 || p.dataAvail() > 0) {
  409. try {switch (tr.mRequest) {
  410. /* Get those we're interested in */
  411. case RIL_REQUEST_EMERGENCY_DIAL:
  412. case RIL_REQUEST_SET_ECC_SERVICE_CATEGORY:
  413. case RIL_REQUEST_DATA_REGISTRATION_STATE:
  414. case RIL_REQUEST_SETUP_DATA_CALL:
  415. case RIL_REQUEST_ALLOW_DATA:
  416. rr = tr;
  417. break;
  418. // vendor ril refreshes the properties while generating this answer. Do our own updates afterwards
  419. case RIL_REQUEST_GET_SIM_STATUS: refreshEmergencyList(); // no break, we want the superclass to process this
  420. }} catch (Throwable thr) {
  421. // Exceptions here usually mean invalid RIL responses
  422. if (tr.mResult != null) {
  423. AsyncResult.forMessage(tr.mResult, null, thr);
  424. tr.mResult.sendToTarget();
  425. }
  426. return tr;
  427. }
  428. }
  429. }
  430. }
  431.  
  432. if (rr == null) {
  433. /* Nothing we care about, go up */
  434. p.setDataPosition(dataPosition);
  435.  
  436. // Forward responses that we are not overriding to the super class
  437. return super.processSolicited(p);
  438. }
  439.  
  440.  
  441. rr = findAndRemoveRequestFromList(serial);
  442.  
  443. if (rr == null) {
  444. return rr;
  445. }
  446.  
  447. Object ret = null;
  448.  
  449. if (error == 0 || p.dataAvail() > 0) {
  450. switch (rr.mRequest) {
  451. case RIL_REQUEST_EMERGENCY_DIAL: ret = responseVoid(p); break;
  452. case RIL_REQUEST_SET_ECC_SERVICE_CATEGORY: ret = responseVoid(p); break;
  453. case RIL_REQUEST_DATA_REGISTRATION_STATE: ret = fixupPSBearerDataRegistration(p); break;
  454. case RIL_REQUEST_SETUP_DATA_CALL: ret = fetchCidFromDataCall(p); break;
  455. case RIL_REQUEST_ALLOW_DATA: ret = responseVoid(p); mVoiceNetworkStateRegistrants.notifyRegistrants(new AsyncResult(null, null, null)); break;
  456. default:
  457. throw new RuntimeException("Shouldn't be here: " + rr.mRequest);
  458. }
  459. //break;
  460. }
  461.  
  462. if (RILJ_LOGD) riljLog(rr.serialString() + "< " + requestToString(rr.mRequest)
  463. + " " + retToString(rr.mRequest, ret));
  464.  
  465. if (rr.mResult != null) {
  466. AsyncResult.forMessage(rr.mResult, ret, null);
  467. rr.mResult.sendToTarget();
  468. }
  469.  
  470. return rr;
  471. }
  472.  
  473. private Object
  474. fixupPSBearerDataRegistration(Parcel p) {
  475. int num;
  476. String response[];
  477.  
  478. response = p.readStringArray();
  479.  
  480. if (response.length >= 4 &&
  481. response[3] != null &&
  482. Integer.parseInt(response[3]) >= 128) {
  483. // extended values >= RIL_RADIO_TECHNOLOGY_MTK (128) == HSPAP (15)
  484. response[3] = "15";
  485. }
  486.  
  487. return response;
  488. }
  489.  
  490. private Object
  491. fetchCidFromDataCall(Parcel p) {
  492. DataCallResponse ret = (DataCallResponse)super.responseSetupDataCall(p);
  493.  
  494. if (ret.cid >= 0) {
  495. for (int i = 0; i < 4; i++) {
  496. if (dataCallCids[i] < 0) {
  497. dataCallCids[i] = ret.cid;
  498. break;
  499. }
  500. }
  501. }
  502. return ret;
  503. }
  504.  
  505. @Override
  506. public void
  507. iccIOForApp (int command, int fileid, String path, int p1, int p2, int p3,
  508. String data, String pin2, String aid, Message result) {
  509. if (command == 0xc0 && p3 == 0) {
  510. Rlog.i("MT6753", "Override the size for the COMMAND_GET_RESPONSE 0 => 15");
  511. p3 = 15;
  512. }
  513. super.iccIOForApp(command, fileid, path, p1, p2, p3, data, pin2, aid, result);
  514. }
  515.  
  516. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement