Advertisement
Guest User

Untitled

a guest
Apr 9th, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.52 KB | None | 0 0
  1. package com.android.internal.telephony;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Collections;
  5.  
  6. import android.content.BroadcastReceiver;
  7. import android.content.Context;
  8. import android.content.Intent;
  9. import android.content.IntentFilter;
  10. import android.net.ConnectivityManager;
  11. import android.os.Handler;
  12. import android.os.Message;
  13. import android.os.AsyncResult;
  14. import android.os.Parcel;
  15. import android.os.SystemProperties;
  16. import android.telephony.PhoneNumberUtils;
  17. import android.telephony.SmsManager;
  18. import android.telephony.SmsMessage;
  19. import android.telephony.TelephonyManager;
  20. import static com.android.internal.telephony.RILConstants.*;
  21.  
  22. import com.android.internal.telephony.CallForwardInfo;
  23. import com.android.internal.telephony.CommandException;
  24. import com.android.internal.telephony.DataCallState;
  25. import com.android.internal.telephony.gsm.NetworkInfo;
  26. import com.android.internal.telephony.gsm.SmsBroadcastConfigInfo;
  27. import com.android.internal.telephony.gsm.SuppServiceNotification;
  28. import com.android.internal.telephony.IccCardApplication;
  29. import com.android.internal.telephony.IccCardStatus;
  30. import com.android.internal.telephony.IccUtils;
  31. import com.android.internal.telephony.RILConstants;
  32. import com.android.internal.telephony.SmsResponse;
  33. import com.android.internal.telephony.cdma.CdmaCallWaitingNotification;
  34. import com.android.internal.telephony.cdma.CdmaInformationRecords;
  35. import com.android.internal.telephony.cdma.CdmaInformationRecords.CdmaSignalInfoRec;
  36. import com.android.internal.telephony.cdma.SignalToneUtil;
  37.  
  38. import android.util.Log;
  39.  
  40. public class SamsungRIL extends RIL implements CommandsInterface {
  41.  
  42. private boolean mSignalbarCount = SystemProperties.getInt("ro.telephony.sends_barcount", 0) == 1 ? true : false;
  43.  
  44. private boolean mIsSamsungCdma = SystemProperties.getBoolean("ro.ril.samsung_cdma", false);
  45.  
  46. public SamsungRIL(Context context) {
  47. super(context);
  48. }
  49.  
  50. public SamsungRIL(Context context, int networkMode, int cdmaSubscription) {
  51. super(context, networkMode, cdmaSubscription);
  52. }
  53.  
  54. //SAMSUNG SGS STATES
  55. static final int RIL_UNSOL_STK_SEND_SMS_RESULT = 11002;
  56. static final int RIL_UNSOL_O2_HOME_ZONE_INFO = 11007;
  57. static final int RIL_UNSOL_DEVICE_READY_NOTI = 11008;
  58. static final int RIL_UNSOL_SAMSUNG_UNKNOWN_MAGIC_REQUEST_2 = 11011;
  59. static final int RIL_UNSOL_HSDPA_STATE_CHANGED = 11016;
  60. static final int RIL_UNSOL_SAMSUNG_UNKNOWN_MAGIC_REQUEST = 11012;
  61. static final int RIL_REQUEST_DIAL_EMERGENCY = 10016;
  62. static final int RIL_UNSOL_GPS_NOTI = 11009;
  63.  
  64. @Override
  65. public void
  66. setRadioPower(boolean on, Message result) {
  67. //if radio is OFF set preferred NW type and cmda subscription
  68. if(mInitialRadioStateChange) {
  69. synchronized (mStateMonitor) {
  70. if (!mState.isOn()) {
  71. RILRequest rrPnt = RILRequest.obtain(
  72. RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE, null);
  73.  
  74. rrPnt.mp.writeInt(1);
  75. rrPnt.mp.writeInt(mNetworkMode);
  76. if (RILJ_LOGD) riljLog(rrPnt.serialString() + "> "
  77. + requestToString(rrPnt.mRequest) + " : " + mNetworkMode);
  78.  
  79. send(rrPnt);
  80.  
  81. RILRequest rrCs = RILRequest.obtain(
  82. RIL_REQUEST_CDMA_SET_SUBSCRIPTION, null);
  83. rrCs.mp.writeInt(1);
  84. rrCs.mp.writeInt(mCdmaSubscription);
  85. if (RILJ_LOGD) riljLog(rrCs.serialString() + "> "
  86. + requestToString(rrCs.mRequest) + " : " + mCdmaSubscription);
  87. send(rrCs);
  88. }
  89. }
  90. }
  91. RILRequest rr
  92. = RILRequest.obtain(RIL_REQUEST_RADIO_POWER, result);
  93.  
  94. //samsung crap for airplane mode
  95. if (on)
  96. {
  97. rr.mp.writeInt(1);
  98. rr.mp.writeInt(1);
  99. } else {
  100. rr.mp.writeInt(2);
  101. rr.mp.writeInt(0);
  102. rr.mp.writeInt(0);
  103. }
  104. if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
  105. send(rr);
  106. }
  107.  
  108. @Override
  109. protected void
  110. processSolicited (Parcel p) {
  111. int serial, error;
  112. boolean found = false;
  113.  
  114. serial = p.readInt();
  115. error = p.readInt();
  116.  
  117. Log.d(LOG_TAG,"Serial: "+ serial);
  118. Log.d(LOG_TAG,"Error: "+ error);
  119.  
  120. RILRequest rr;
  121.  
  122. rr = findAndRemoveRequestFromList(serial);
  123.  
  124. if (rr == null) {
  125. Log.w(LOG_TAG, "Unexpected solicited response! sn: "
  126. + serial + " error: " + error);
  127. return;
  128. }
  129.  
  130. Object ret = null;
  131.  
  132. if (error == 0 || p.dataAvail() > 0) {
  133. // either command succeeds or command fails but with data payload
  134. try {switch (rr.mRequest) {
  135. /*
  136. cat libs/telephony/ril_commands.h \
  137. | egrep "^ *{RIL_" \
  138. | sed -re 's/\{([^,]+),[^,]+,([^}]+).+/case \1: ret = \2(p); break;/'
  139. */
  140. case RIL_REQUEST_GET_SIM_STATUS: ret = responseIccCardStatus(p); break;
  141. case RIL_REQUEST_ENTER_SIM_PIN: ret = responseInts(p); break;
  142. case RIL_REQUEST_ENTER_SIM_PUK: ret = responseInts(p); break;
  143. case RIL_REQUEST_ENTER_SIM_PIN2: ret = responseInts(p); break;
  144. case RIL_REQUEST_ENTER_SIM_PUK2: ret = responseInts(p); break;
  145. case RIL_REQUEST_CHANGE_SIM_PIN: ret = responseInts(p); break;
  146. case RIL_REQUEST_CHANGE_SIM_PIN2: ret = responseInts(p); break;
  147. case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: ret = responseInts(p); break;
  148. case RIL_REQUEST_GET_CURRENT_CALLS: ret = responseCallList(p); break;
  149. case RIL_REQUEST_DIAL: ret = responseVoid(p); break;
  150. case RIL_REQUEST_GET_IMSI: ret = responseString(p); break;
  151. case RIL_REQUEST_HANGUP: ret = responseVoid(p); break;
  152. case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: ret = responseVoid(p); break;
  153. case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: ret = responseVoid(p); break;
  154. case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: ret = responseVoid(p); break;
  155. case RIL_REQUEST_CONFERENCE: ret = responseVoid(p); break;
  156. case RIL_REQUEST_UDUB: ret = responseVoid(p); break;
  157. case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: ret = responseLastCallFailCause(p); break;
  158. case RIL_REQUEST_SIGNAL_STRENGTH: ret = responseSignalStrength(p); break;
  159. case RIL_REQUEST_REGISTRATION_STATE: ret = responseStrings(p); break;
  160. case RIL_REQUEST_GPRS_REGISTRATION_STATE: ret = responseStrings(p); break;
  161. case RIL_REQUEST_OPERATOR: ret = responseStrings(p); break;
  162. case RIL_REQUEST_RADIO_POWER: ret = responseVoid(p); break;
  163. case RIL_REQUEST_DTMF: ret = responseVoid(p); break;
  164. case RIL_REQUEST_SEND_SMS: ret = responseSMS(p); break;
  165. case RIL_REQUEST_SEND_SMS_EXPECT_MORE: ret = responseSMS(p); break;
  166. case RIL_REQUEST_SETUP_DATA_CALL: ret = responseStrings(p); break;
  167. case RIL_REQUEST_SIM_IO: ret = responseICC_IO(p); break;
  168. case RIL_REQUEST_SEND_USSD: ret = responseVoid(p); break;
  169. case RIL_REQUEST_CANCEL_USSD: ret = responseVoid(p); break;
  170. case RIL_REQUEST_GET_CLIR: ret = responseInts(p); break;
  171. case RIL_REQUEST_SET_CLIR: ret = responseVoid(p); break;
  172. case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: ret = responseCallForward(p); break;
  173. case RIL_REQUEST_SET_CALL_FORWARD: ret = responseVoid(p); break;
  174. case RIL_REQUEST_QUERY_CALL_WAITING: ret = responseInts(p); break;
  175. case RIL_REQUEST_SET_CALL_WAITING: ret = responseVoid(p); break;
  176. case RIL_REQUEST_SMS_ACKNOWLEDGE: ret = responseVoid(p); break;
  177. case RIL_REQUEST_GET_IMEI: ret = responseString(p); break;
  178. case RIL_REQUEST_GET_IMEISV: ret = responseString(p); break;
  179. case RIL_REQUEST_ANSWER: ret = responseVoid(p); break;
  180. case RIL_REQUEST_DEACTIVATE_DATA_CALL: ret = responseVoid(p); break;
  181. case RIL_REQUEST_QUERY_FACILITY_LOCK: ret = responseInts(p); break;
  182. case RIL_REQUEST_SET_FACILITY_LOCK: ret = responseInts(p); break;
  183. case RIL_REQUEST_CHANGE_BARRING_PASSWORD: ret = responseVoid(p); break;
  184. case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: ret = responseInts(p); break;
  185. case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: ret = responseVoid(p); break;
  186. case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: ret = responseVoid(p); break;
  187. case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : ret = responseNetworkInfos(p); break;
  188. case RIL_REQUEST_DTMF_START: ret = responseVoid(p); break;
  189. case RIL_REQUEST_DTMF_STOP: ret = responseVoid(p); break;
  190. case RIL_REQUEST_BASEBAND_VERSION: ret = responseString(p); break;
  191. case RIL_REQUEST_SEPARATE_CONNECTION: ret = responseVoid(p); break;
  192. case RIL_REQUEST_SET_MUTE: ret = responseVoid(p); break;
  193. case RIL_REQUEST_GET_MUTE: ret = responseInts(p); break;
  194. case RIL_REQUEST_QUERY_CLIP: ret = responseInts(p); break;
  195. case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: ret = responseInts(p); break;
  196. case RIL_REQUEST_DATA_CALL_LIST: ret = responseDataCallList(p); break;
  197. case RIL_REQUEST_RESET_RADIO: ret = responseVoid(p); break;
  198. case RIL_REQUEST_OEM_HOOK_RAW: ret = responseRaw(p); break;
  199. case RIL_REQUEST_OEM_HOOK_STRINGS: ret = responseStrings(p); break;
  200. case RIL_REQUEST_SCREEN_STATE: ret = responseVoid(p); break;
  201. case RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION: ret = responseVoid(p); break;
  202. case RIL_REQUEST_WRITE_SMS_TO_SIM: ret = responseInts(p); break;
  203. case RIL_REQUEST_DELETE_SMS_ON_SIM: ret = responseVoid(p); break;
  204. case RIL_REQUEST_SET_BAND_MODE: ret = responseVoid(p); break;
  205. case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: ret = responseInts(p); break;
  206. case RIL_REQUEST_STK_GET_PROFILE: ret = responseString(p); break;
  207. case RIL_REQUEST_STK_SET_PROFILE: ret = responseVoid(p); break;
  208. case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: ret = responseString(p); break;
  209. case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: ret = responseVoid(p); break;
  210. case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: ret = responseInts(p); break;
  211. case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: ret = responseVoid(p); break;
  212. case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: ret = responseVoid(p); break;
  213. case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: ret = responseNetworkType(p); break;
  214. case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: ret = responseCellList(p); break;
  215. case RIL_REQUEST_SET_LOCATION_UPDATES: ret = responseVoid(p); break;
  216. case RIL_REQUEST_CDMA_SET_SUBSCRIPTION: ret = responseVoid(p); break;
  217. case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: ret = responseVoid(p); break;
  218. case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: ret = responseInts(p); break;
  219. case RIL_REQUEST_SET_TTY_MODE: ret = responseVoid(p); break;
  220. case RIL_REQUEST_QUERY_TTY_MODE: ret = responseInts(p); break;
  221. case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE: ret = responseVoid(p); break;
  222. case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE: ret = responseInts(p); break;
  223. case RIL_REQUEST_CDMA_FLASH: ret = responseVoid(p); break;
  224. case RIL_REQUEST_CDMA_BURST_DTMF: ret = responseVoid(p); break;
  225. case RIL_REQUEST_CDMA_SEND_SMS: ret = responseSMS(p); break;
  226. case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE: ret = responseVoid(p); break;
  227. case RIL_REQUEST_GSM_GET_BROADCAST_CONFIG: ret = responseGmsBroadcastConfig(p); break;
  228. case RIL_REQUEST_GSM_SET_BROADCAST_CONFIG: ret = responseVoid(p); break;
  229. case RIL_REQUEST_GSM_BROADCAST_ACTIVATION: ret = responseVoid(p); break;
  230. case RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG: ret = responseCdmaBroadcastConfig(p); break;
  231. case RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG: ret = responseVoid(p); break;
  232. case RIL_REQUEST_CDMA_BROADCAST_ACTIVATION: ret = responseVoid(p); break;
  233. case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: ret = responseVoid(p); break;
  234. case RIL_REQUEST_CDMA_SUBSCRIPTION: ret = responseStrings(p); break;
  235. case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: ret = responseInts(p); break;
  236. case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: ret = responseVoid(p); break;
  237. case RIL_REQUEST_DEVICE_IDENTITY: ret = responseStrings(p); break;
  238. case RIL_REQUEST_GET_SMSC_ADDRESS: ret = responseString(p); break;
  239. case RIL_REQUEST_SET_SMSC_ADDRESS: ret = responseVoid(p); break;
  240. case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break;
  241. case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: ret = responseVoid(p); break;
  242. case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: ret = responseVoid(p); break;
  243. default:
  244. throw new RuntimeException("Unrecognized solicited response: " + rr.mRequest);
  245. //break;
  246. }} catch (Throwable tr) {
  247. // Exceptions here usually mean invalid RIL responses
  248.  
  249. Log.w(LOG_TAG, rr.serialString() + "< "
  250. + requestToString(rr.mRequest)
  251. + " exception, possible invalid RIL response", tr);
  252.  
  253. if (rr.mResult != null) {
  254. AsyncResult.forMessage(rr.mResult, null, tr);
  255. rr.mResult.sendToTarget();
  256. }
  257. rr.release();
  258. return;
  259. }
  260. }
  261.  
  262. if (error != 0) {
  263. //ugly fix for Samsung messing up SMS_SEND request fail in binary RIL
  264. if(!(error == -1 && rr.mRequest == RIL_REQUEST_SEND_SMS))
  265. {
  266. rr.onError(error, ret);
  267. rr.release();
  268. return;
  269. } else {
  270. try
  271. {
  272. ret = responseSMS(p);
  273. } catch (Throwable tr) {
  274. Log.w(LOG_TAG, rr.serialString() + "< "
  275. + requestToString(rr.mRequest)
  276. + " exception, Processing Samsung SMS fix ", tr);
  277. rr.onError(error, ret);
  278. rr.release();
  279. return;
  280. }
  281. }
  282. }
  283.  
  284. if (RILJ_LOGD) riljLog(rr.serialString() + "< " + requestToString(rr.mRequest)
  285. + " " + retToString(rr.mRequest, ret));
  286.  
  287. if (rr.mResult != null) {
  288. AsyncResult.forMessage(rr.mResult, ret, null);
  289. rr.mResult.sendToTarget();
  290. }
  291.  
  292. rr.release();
  293. }
  294.  
  295. @Override
  296. public void
  297. dial(String address, int clirMode, UUSInfo uusInfo, Message result) {
  298. if (TelephonyManager.getDefault().getPhoneType() != TelephonyManager.PHONE_TYPE_GSM) {
  299. super.dial(address, clirMode, uusInfo, result);
  300. return;
  301. }
  302.  
  303. RILRequest rr;
  304. if (PhoneNumberUtils.isEmergencyNumber(address)) {
  305. Log.v(LOG_TAG, "Emergency dial: " + address);
  306. rr = RILRequest.obtain(RIL_REQUEST_DIAL_EMERGENCY, result);
  307. rr.mp.writeString(address + "/");
  308. }
  309. else {
  310. rr = RILRequest.obtain(RIL_REQUEST_DIAL, result);
  311. rr.mp.writeString(address);
  312. }
  313.  
  314. rr.mp.writeInt(clirMode);
  315. rr.mp.writeInt(0); // UUS information is absent
  316.  
  317. if (uusInfo == null) {
  318. rr.mp.writeInt(0); // UUS information is absent
  319. } else {
  320. rr.mp.writeInt(1); // UUS information is present
  321. rr.mp.writeInt(uusInfo.getType());
  322. rr.mp.writeInt(uusInfo.getDcs());
  323. rr.mp.writeByteArray(uusInfo.getUserData());
  324. }
  325.  
  326. if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
  327.  
  328. send(rr);
  329. }
  330.  
  331. @Override
  332. protected void
  333. processUnsolicited (Parcel p) {
  334. int response;
  335. Object ret;
  336.  
  337. response = p.readInt();
  338.  
  339. try {switch(response) {
  340. /*
  341. cat libs/telephony/ril_unsol_commands.h \
  342. | egrep "^ *{RIL_" \
  343. | sed -re 's/\{([^,]+),[^,]+,([^}]+).+/case \1: \2(rr, p); break;/'
  344. */
  345.  
  346. case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: ret = responseVoid(p); break;
  347. case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: ret = responseVoid(p); break;
  348. case RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED: ret = responseVoid(p); break;
  349. case RIL_UNSOL_RESPONSE_NEW_SMS: ret = responseString(p); break;
  350. case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: ret = responseString(p); break;
  351. case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: ret = responseInts(p); break;
  352. case RIL_UNSOL_ON_USSD: ret = responseStrings(p); break;
  353. case RIL_UNSOL_NITZ_TIME_RECEIVED: ret = responseString(p); break;
  354. case RIL_UNSOL_SIGNAL_STRENGTH: ret = responseSignalStrength(p); break;
  355. case RIL_UNSOL_DATA_CALL_LIST_CHANGED: ret = responseDataCallList(p);break;
  356. case RIL_UNSOL_SUPP_SVC_NOTIFICATION: ret = responseSuppServiceNotification(p); break;
  357. case RIL_UNSOL_STK_SESSION_END: ret = responseVoid(p); break;
  358. case RIL_UNSOL_STK_PROACTIVE_COMMAND: ret = responseString(p); break;
  359. case RIL_UNSOL_STK_EVENT_NOTIFY: ret = responseString(p); break;
  360. case RIL_UNSOL_STK_CALL_SETUP: ret = responseInts(p); break;
  361. case RIL_UNSOL_SIM_SMS_STORAGE_FULL: ret = responseVoid(p); break;
  362. case RIL_UNSOL_SIM_REFRESH: ret = responseInts(p); break;
  363. case RIL_UNSOL_CALL_RING: ret = responseCallRing(p); break;
  364. case RIL_UNSOL_RESTRICTED_STATE_CHANGED: ret = responseInts(p); break;
  365. case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: ret = responseVoid(p); break;
  366. case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: ret = responseCdmaSms(p); break;
  367. case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: ret = responseString(p); break;
  368. case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: ret = responseVoid(p); break;
  369. case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: ret = responseVoid(p); break;
  370. case RIL_UNSOL_CDMA_CALL_WAITING: ret = responseCdmaCallWaiting(p); break;
  371. case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: ret = responseInts(p); break;
  372. case RIL_UNSOL_CDMA_INFO_REC: ret = responseCdmaInformationRecord(p); break;
  373. case RIL_UNSOL_OEM_HOOK_RAW: ret = responseRaw(p); break;
  374. case RIL_UNSOL_RINGBACK_TONE: ret = responseInts(p); break;
  375. case RIL_UNSOL_RESEND_INCALL_MUTE: ret = responseVoid(p); break;
  376. case RIL_UNSOL_HSDPA_STATE_CHANGED: ret = responseVoid(p); break;
  377.  
  378. //fixing anoying Exceptions caused by the new Samsung states
  379. //FIXME figure out what the states mean an what data is in the parcel
  380.  
  381. case RIL_UNSOL_O2_HOME_ZONE_INFO: ret = responseVoid(p); break;
  382. case RIL_UNSOL_SAMSUNG_UNKNOWN_MAGIC_REQUEST: ret = responseVoid(p); break;
  383. case RIL_UNSOL_STK_SEND_SMS_RESULT: ret = responseVoid(p); break;
  384. case RIL_UNSOL_DEVICE_READY_NOTI: ret = responseVoid(p); break;
  385. case RIL_UNSOL_GPS_NOTI: ret = responseVoid(p); break; // Ignored in TW RIL.
  386. case RIL_UNSOL_SAMSUNG_UNKNOWN_MAGIC_REQUEST_2: ret = responseVoid(p); break;
  387.  
  388. default:
  389. throw new RuntimeException("Unrecognized unsol response: " + response);
  390. //break; (implied)
  391. }} catch (Throwable tr) {
  392. Log.e(LOG_TAG, "Exception processing unsol response: " + response +
  393. "Exception:" + tr.toString());
  394. return;
  395. }
  396.  
  397. switch(response) {
  398. case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
  399. /* has bonus radio state int */
  400. RadioState newState = getRadioStateFromInt(p.readInt());
  401. if (RILJ_LOGD) unsljLogMore(response, newState.toString());
  402.  
  403. switchToRadioState(newState);
  404. break;
  405. case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED:
  406. if (RILJ_LOGD) unsljLog(response);
  407.  
  408. mCallStateRegistrants
  409. .notifyRegistrants(new AsyncResult(null, null, null));
  410. break;
  411. case RIL_UNSOL_HSDPA_STATE_CHANGED:
  412. if (RILJ_LOGD) unsljLog(response);
  413.  
  414. mNetworkStateRegistrants
  415. .notifyRegistrants(new AsyncResult(null, null, null));
  416. break;
  417.  
  418. case RIL_UNSOL_RESPONSE_NETWORK_STATE_CHANGED:
  419. if (RILJ_LOGD) unsljLog(response);
  420.  
  421. mNetworkStateRegistrants
  422. .notifyRegistrants(new AsyncResult(null, null, null));
  423. break;
  424. case RIL_UNSOL_RESPONSE_NEW_SMS: {
  425. if (RILJ_LOGD) unsljLog(response);
  426.  
  427. // FIXME this should move up a layer
  428. String a[] = new String[2];
  429.  
  430. a[1] = (String)ret;
  431.  
  432. SmsMessage sms;
  433.  
  434. sms = SmsMessage.newFromCMT(a);
  435. if (mSMSRegistrant != null) {
  436. mSMSRegistrant
  437. .notifyRegistrant(new AsyncResult(null, sms, null));
  438. }
  439. break;
  440. }
  441. case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT:
  442. if (RILJ_LOGD) unsljLogRet(response, ret);
  443.  
  444. if (mSmsStatusRegistrant != null) {
  445. mSmsStatusRegistrant.notifyRegistrant(
  446. new AsyncResult(null, ret, null));
  447. }
  448. break;
  449. case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM:
  450. if (RILJ_LOGD) unsljLogRet(response, ret);
  451.  
  452. int[] smsIndex = (int[])ret;
  453.  
  454. if(smsIndex.length == 1) {
  455. if (mSmsOnSimRegistrant != null) {
  456. mSmsOnSimRegistrant.
  457. notifyRegistrant(new AsyncResult(null, smsIndex, null));
  458. }
  459. } else {
  460. if (RILJ_LOGD) riljLog(" NEW_SMS_ON_SIM ERROR with wrong length "
  461. + smsIndex.length);
  462. }
  463. break;
  464. case RIL_UNSOL_ON_USSD:
  465. String[] resp = (String[])ret;
  466.  
  467. if (resp.length < 2) {
  468. resp = new String[2];
  469. resp[0] = ((String[])ret)[0];
  470. resp[1] = null;
  471. }
  472. if (RILJ_LOGD) unsljLogMore(response, resp[0]);
  473. if (mUSSDRegistrant != null) {
  474. mUSSDRegistrant.notifyRegistrant(
  475. new AsyncResult (null, resp, null));
  476. }
  477. break;
  478. case RIL_UNSOL_NITZ_TIME_RECEIVED:
  479. if (RILJ_LOGD) unsljLogRet(response, ret);
  480.  
  481. // has bonus long containing milliseconds since boot that the NITZ
  482. // time was received
  483. long nitzReceiveTime = p.readLong();
  484.  
  485. Object[] result = new Object[2];
  486.  
  487. String nitz = (String)ret;
  488. if (RILJ_LOGD) riljLog(" RIL_UNSOL_NITZ_TIME_RECEIVED length = "
  489. + nitz.split("[/:,+-]").length);
  490. //remove the tailing information that samsung added to the string
  491. //it will screw the NITZ parser
  492. if(nitz.split("[/:,+-]").length >= 9)
  493. nitz = nitz.substring(0,(nitz.lastIndexOf(",")));
  494. if (RILJ_LOGD) riljLog(" RIL_UNSOL_NITZ_TIME_RECEIVED striped nitz = "
  495. + nitz);
  496. result[0] = nitz;
  497. result[1] = Long.valueOf(nitzReceiveTime);
  498.  
  499. if (mNITZTimeRegistrant != null) {
  500.  
  501. mNITZTimeRegistrant
  502. .notifyRegistrant(new AsyncResult (null, result, null));
  503. } else {
  504. // in case NITZ time registrant isnt registered yet
  505. mLastNITZTimeInfo = nitz;
  506. }
  507. break;
  508.  
  509. case RIL_UNSOL_SIGNAL_STRENGTH:
  510. // Note this is set to "verbose" because it happens
  511. // frequently
  512. if (RILJ_LOGV) unsljLogvRet(response, ret);
  513.  
  514. if (mSignalStrengthRegistrant != null) {
  515. mSignalStrengthRegistrant.notifyRegistrant(
  516. new AsyncResult (null, ret, null));
  517. }
  518. break;
  519. case RIL_UNSOL_DATA_CALL_LIST_CHANGED:
  520. if (RILJ_LOGD) unsljLogRet(response, ret);
  521.  
  522. mDataConnectionRegistrants.notifyRegistrants(new AsyncResult(null, ret, null));
  523. break;
  524.  
  525. case RIL_UNSOL_SUPP_SVC_NOTIFICATION:
  526. if (RILJ_LOGD) unsljLogRet(response, ret);
  527.  
  528. if (mSsnRegistrant != null) {
  529. mSsnRegistrant.notifyRegistrant(
  530. new AsyncResult (null, ret, null));
  531. }
  532. break;
  533.  
  534. case RIL_UNSOL_STK_SESSION_END:
  535. if (RILJ_LOGD) unsljLog(response);
  536.  
  537. if (mStkSessionEndRegistrant != null) {
  538. mStkSessionEndRegistrant.notifyRegistrant(
  539. new AsyncResult (null, ret, null));
  540. }
  541. break;
  542.  
  543. case RIL_UNSOL_STK_PROACTIVE_COMMAND:
  544. if (RILJ_LOGD) unsljLogRet(response, ret);
  545.  
  546. if (mStkProCmdRegistrant != null) {
  547. mStkProCmdRegistrant.notifyRegistrant(
  548. new AsyncResult (null, ret, null));
  549. }
  550. break;
  551.  
  552. case RIL_UNSOL_STK_EVENT_NOTIFY:
  553. if (RILJ_LOGD) unsljLogRet(response, ret);
  554.  
  555. if (mStkEventRegistrant != null) {
  556. mStkEventRegistrant.notifyRegistrant(
  557. new AsyncResult (null, ret, null));
  558. }
  559. break;
  560.  
  561. case RIL_UNSOL_STK_CALL_SETUP:
  562. if (RILJ_LOGD) unsljLogRet(response, ret);
  563.  
  564. if (mStkCallSetUpRegistrant != null) {
  565. mStkCallSetUpRegistrant.notifyRegistrant(
  566. new AsyncResult (null, ret, null));
  567. }
  568. break;
  569.  
  570. case RIL_UNSOL_SIM_SMS_STORAGE_FULL:
  571. if (RILJ_LOGD) unsljLog(response);
  572.  
  573. if (mIccSmsFullRegistrant != null) {
  574. mIccSmsFullRegistrant.notifyRegistrant();
  575. }
  576. break;
  577.  
  578. case RIL_UNSOL_SIM_REFRESH:
  579. if (RILJ_LOGD) unsljLogRet(response, ret);
  580.  
  581. if (mIccRefreshRegistrant != null) {
  582. mIccRefreshRegistrant.notifyRegistrant(
  583. new AsyncResult (null, ret, null));
  584. }
  585. break;
  586.  
  587. case RIL_UNSOL_CALL_RING:
  588. if (RILJ_LOGD) unsljLogRet(response, ret);
  589.  
  590. if (mRingRegistrant != null) {
  591. mRingRegistrant.notifyRegistrant(
  592. new AsyncResult (null, ret, null));
  593. }
  594. break;
  595.  
  596. case RIL_UNSOL_RESTRICTED_STATE_CHANGED:
  597. if (RILJ_LOGD) unsljLogvRet(response, ret);
  598. if (mRestrictedStateRegistrant != null) {
  599. mRestrictedStateRegistrant.notifyRegistrant(
  600. new AsyncResult (null, ret, null));
  601. }
  602. break;
  603.  
  604. case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED:
  605. if (RILJ_LOGD) unsljLog(response);
  606.  
  607. if (mIccStatusChangedRegistrants != null) {
  608. mIccStatusChangedRegistrants.notifyRegistrants();
  609. }
  610. break;
  611.  
  612. case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS:
  613. if (RILJ_LOGD) unsljLog(response);
  614.  
  615. SmsMessage sms = (SmsMessage) ret;
  616.  
  617. if (mSMSRegistrant != null) {
  618. mSMSRegistrant
  619. .notifyRegistrant(new AsyncResult(null, sms, null));
  620. }
  621. break;
  622.  
  623. case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS:
  624. if (RILJ_LOGD) unsljLog(response);
  625.  
  626. if (mGsmBroadcastSmsRegistrant != null) {
  627. mGsmBroadcastSmsRegistrant
  628. .notifyRegistrant(new AsyncResult(null, ret, null));
  629. }
  630. break;
  631.  
  632. case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL:
  633. if (RILJ_LOGD) unsljLog(response);
  634.  
  635. if (mIccSmsFullRegistrant != null) {
  636. mIccSmsFullRegistrant.notifyRegistrant();
  637. }
  638. break;
  639.  
  640. case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE:
  641. if (RILJ_LOGD) unsljLog(response);
  642.  
  643. if (mEmergencyCallbackModeRegistrant != null) {
  644. mEmergencyCallbackModeRegistrant.notifyRegistrant();
  645. }
  646. break;
  647.  
  648. case RIL_UNSOL_CDMA_CALL_WAITING:
  649. if (RILJ_LOGD) unsljLogRet(response, ret);
  650.  
  651. if (mCallWaitingInfoRegistrants != null) {
  652. mCallWaitingInfoRegistrants.notifyRegistrants(
  653. new AsyncResult (null, ret, null));
  654. }
  655. break;
  656.  
  657. case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS:
  658. if (RILJ_LOGD) unsljLogRet(response, ret);
  659.  
  660. if (mOtaProvisionRegistrants != null) {
  661. mOtaProvisionRegistrants.notifyRegistrants(
  662. new AsyncResult (null, ret, null));
  663. }
  664. break;
  665.  
  666. case RIL_UNSOL_CDMA_INFO_REC:
  667. ArrayList<CdmaInformationRecords> listInfoRecs;
  668.  
  669. try {
  670. listInfoRecs = (ArrayList<CdmaInformationRecords>)ret;
  671. } catch (ClassCastException e) {
  672. Log.e(LOG_TAG, "Unexpected exception casting to listInfoRecs", e);
  673. break;
  674. }
  675.  
  676. for (CdmaInformationRecords rec : listInfoRecs) {
  677. if (RILJ_LOGD) unsljLogRet(response, rec);
  678. notifyRegistrantsCdmaInfoRec(rec);
  679. }
  680. break;
  681.  
  682. case RIL_UNSOL_OEM_HOOK_RAW:
  683. if (RILJ_LOGD) unsljLogvRet(response, IccUtils.bytesToHexString((byte[])ret));
  684. if (mUnsolOemHookRawRegistrant != null) {
  685. mUnsolOemHookRawRegistrant.notifyRegistrant(new AsyncResult(null, ret, null));
  686. }
  687. break;
  688.  
  689. case RIL_UNSOL_RINGBACK_TONE:
  690. if (RILJ_LOGD) unsljLogvRet(response, ret);
  691. if (mRingbackToneRegistrants != null) {
  692. boolean playtone = (((int[])ret)[0] == 1);
  693. mRingbackToneRegistrants.notifyRegistrants(
  694. new AsyncResult (null, playtone, null));
  695. }
  696. break;
  697.  
  698. case RIL_UNSOL_RESEND_INCALL_MUTE:
  699. if (RILJ_LOGD) unsljLogRet(response, ret);
  700.  
  701. if (mResendIncallMuteRegistrants != null) {
  702. mResendIncallMuteRegistrants.notifyRegistrants(
  703. new AsyncResult (null, ret, null));
  704. }
  705. }
  706. }
  707.  
  708. @Override
  709. protected Object
  710. responseCallList(Parcel p) {
  711. int num;
  712. int voiceSettings;
  713. ArrayList<DriverCall> response;
  714. DriverCall dc;
  715. int dataAvail = p.dataAvail();
  716. int pos = p.dataPosition();
  717. int size = p.dataSize();
  718.  
  719. Log.d(LOG_TAG, "Parcel size = " + size);
  720. Log.d(LOG_TAG, "Parcel pos = " + pos);
  721. Log.d(LOG_TAG, "Parcel dataAvail = " + dataAvail);
  722.  
  723. //Samsung fucked up here
  724.  
  725. num = p.readInt();
  726.  
  727. Log.d(LOG_TAG, "num = " + num);
  728. response = new ArrayList<DriverCall>(num);
  729.  
  730. for (int i = 0 ; i < num ; i++) {
  731. if (mIsSamsungCdma)
  732. dc = new SamsungDriverCall();
  733. else
  734. dc = new DriverCall();
  735.  
  736. dc.state = DriverCall.stateFromCLCC(p.readInt());
  737. Log.d(LOG_TAG, "state = " + dc.state);
  738. dc.index = p.readInt();
  739. Log.d(LOG_TAG, "index = " + dc.index);
  740. dc.TOA = p.readInt();
  741. Log.d(LOG_TAG, "state = " + dc.TOA);
  742. dc.isMpty = (0 != p.readInt());
  743. Log.d(LOG_TAG, "isMpty = " + dc.isMpty);
  744. dc.isMT = (0 != p.readInt());
  745. Log.d(LOG_TAG, "isMT = " + dc.isMT);
  746. dc.als = p.readInt();
  747. Log.d(LOG_TAG, "als = " + dc.als);
  748. voiceSettings = p.readInt();
  749. dc.isVoice = (0 == voiceSettings) ? false : true;
  750. Log.d(LOG_TAG, "isVoice = " + dc.isVoice);
  751. dc.isVoicePrivacy = (0 != p.readInt());
  752. //Some Samsung magic data for Videocalls
  753. voiceSettings = p.readInt();
  754. //printing it to cosole for later investigation
  755. Log.d(LOG_TAG, "Samsung magic = " + voiceSettings);
  756. dc.number = p.readString();
  757. Log.d(LOG_TAG, "number = " + dc.number);
  758. int np = p.readInt();
  759. Log.d(LOG_TAG, "np = " + np);
  760. dc.numberPresentation = DriverCall.presentationFromCLIP(np);
  761. dc.name = p.readString();
  762. Log.d(LOG_TAG, "name = " + dc.name);
  763. dc.namePresentation = p.readInt();
  764. Log.d(LOG_TAG, "namePresentation = " + dc.namePresentation);
  765. int uusInfoPresent = p.readInt();
  766. Log.d(LOG_TAG, "uusInfoPresent = " + uusInfoPresent);
  767.  
  768. if (uusInfoPresent == 1) {
  769. dc.uusInfo = new UUSInfo();
  770. dc.uusInfo.setType(p.readInt());
  771. dc.uusInfo.setDcs(p.readInt());
  772. byte[] userData = p.createByteArray();
  773. dc.uusInfo.setUserData(userData);
  774. Log
  775. .v(LOG_TAG, String.format("Incoming UUS : type=%d, dcs=%d, length=%d",
  776. dc.uusInfo.getType(), dc.uusInfo.getDcs(),
  777. dc.uusInfo.getUserData().length));
  778. Log.v(LOG_TAG, "Incoming UUS : data (string)="
  779. + new String(dc.uusInfo.getUserData()));
  780. Log.v(LOG_TAG, "Incoming UUS : data (hex): "
  781. + IccUtils.bytesToHexString(dc.uusInfo.getUserData()));
  782. } else {
  783. Log.v(LOG_TAG, "Incoming UUS : NOT present!");
  784. }
  785.  
  786. // Make sure there's a leading + on addresses with a TOA of 145
  787. dc.number = PhoneNumberUtils.stringFromStringAndTOA(dc.number, dc.TOA);
  788.  
  789. response.add(dc);
  790.  
  791. if (dc.isVoicePrivacy) {
  792. mVoicePrivacyOnRegistrants.notifyRegistrants();
  793. Log.d(LOG_TAG, "InCall VoicePrivacy is enabled");
  794. } else {
  795. mVoicePrivacyOffRegistrants.notifyRegistrants();
  796. Log.d(LOG_TAG, "InCall VoicePrivacy is disabled");
  797. }
  798. }
  799.  
  800. Collections.sort(response);
  801.  
  802. return response;
  803. }
  804.  
  805. protected Object
  806. responseLastCallFailCause(Parcel p) {
  807. int response[] = (int[])responseInts(p);
  808.  
  809. if (mIsSamsungCdma && response.length > 0 &&
  810. response[0] == com.android.internal.telephony.cdma.CallFailCause.ERROR_UNSPECIFIED) {
  811.  
  812. // Far-end hangup returns ERROR_UNSPECIFIED, which shows "Call Lost" dialog.
  813. Log.d(LOG_TAG, "Overriding ERROR_UNSPECIFIED fail cause with NORMAL_CLEARING.");
  814. response[0] = com.android.internal.telephony.cdma.CallFailCause.NORMAL_CLEARING;
  815. }
  816.  
  817. return response;
  818. }
  819.  
  820. @Override
  821. protected Object
  822. responseSignalStrength(Parcel p) {
  823. int numInts = 7;
  824. int response[];
  825.  
  826. /* TODO: Add SignalStrength class to match RIL_SignalStrength */
  827. response = new int[numInts];
  828. for (int i = 0 ; i < numInts ; i++) {
  829. response[i] = p.readInt();
  830. }
  831.  
  832. /* Matching Samsung signal strength to asu.
  833. Method taken from Samsungs cdma/gsmSignalStateTracker */
  834. if(mSignalbarCount)
  835. {
  836. //Samsung sends the count of bars that should be displayed instead of
  837. //a real signal strength
  838. response[0] = ((response[0] & 0xFF00) >> 8) * 3; //gsmDbm
  839. } else {
  840. response[0] = response[0] & 0xFF; //gsmDbm
  841. }
  842. response[1] = -1; //gsmEcio
  843. response[2] = (response[2] < 0)?-120:-response[2]; //cdmaDbm
  844. response[3] = (response[3] < 0)?-160:-response[3]; //cdmaEcio
  845. response[4] = (response[4] < 0)?-120:-response[4]; //evdoRssi
  846. response[5] = (response[5] < 0)?-1:-response[5]; //evdoEcio
  847. if(response[6] < 0 || response[6] > 8)
  848. response[6] = -1;
  849.  
  850. return response;
  851. }
  852.  
  853. protected Object
  854. responseNetworkType(Parcel p) {
  855. int response[] = (int[]) responseInts(p);
  856.  
  857. // When the modem responds Phone.NT_MODE_GLOBAL, it means Phone.NT_MODE_WCDMA_PREF
  858. if (!mIsSamsungCdma && response[0] == Phone.NT_MODE_GLOBAL) {
  859. Log.d(LOG_TAG, "Overriding network type response from global to WCDMA preferred");
  860. response[0] = Phone.NT_MODE_WCDMA_PREF;
  861. }
  862.  
  863. return response;
  864. }
  865.  
  866. // Workaround for Samsung CDMA "ring of death" bug:
  867. //
  868. // Symptom: As soon as the phone receives notice of an incoming call, an
  869. // audible "old fashioned ring" is emitted through the earpiece and
  870. // persists through the duration of the call, or until reboot if the call
  871. // isn't answered.
  872. //
  873. // Background: The CDMA telephony stack implements a number of "signal info
  874. // tones" that are locally generated by ToneGenerator and mixed into the
  875. // voice call path in response to radio RIL_UNSOL_CDMA_INFO_REC requests.
  876. // One of these tones, IS95_CONST_IR_SIG_IS54B_L, is requested by the
  877. // radio just prior to notice of an incoming call when the voice call
  878. // path is muted. CallNotifier is responsible for stopping all signal
  879. // tones (by "playing" the TONE_CDMA_SIGNAL_OFF tone) upon receipt of a
  880. // "new ringing connection", prior to unmuting the voice call path.
  881. //
  882. // Problem: CallNotifier's incoming call path is designed to minimize
  883. // latency to notify users of incoming calls ASAP. Thus,
  884. // SignalInfoTonePlayer requests are handled asynchronously by spawning a
  885. // one-shot thread for each. Unfortunately the ToneGenerator API does
  886. // not provide a mechanism to specify an ordering on requests, and thus,
  887. // unexpected thread interleaving may result in ToneGenerator processing
  888. // them in the opposite order that CallNotifier intended. In this case,
  889. // playing the "signal off" tone first, followed by playing the "old
  890. // fashioned ring" indefinitely.
  891. //
  892. // Solution: An API change to ToneGenerator is required to enable
  893. // SignalInfoTonePlayer to impose an ordering on requests (i.e., drop any
  894. // request that's older than the most recent observed). Such a change,
  895. // or another appropriate fix should be implemented in AOSP first.
  896. //
  897. // Workaround: Intercept RIL_UNSOL_CDMA_INFO_REC requests from the radio,
  898. // check for a signal info record matching IS95_CONST_IR_SIG_IS54B_L, and
  899. // drop it so it's never seen by CallNotifier. If other signal tones are
  900. // observed to cause this problem, they should be dropped here as well.
  901. @Override
  902. protected void
  903. notifyRegistrantsCdmaInfoRec(CdmaInformationRecords infoRec) {
  904. final int response = RIL_UNSOL_CDMA_INFO_REC;
  905.  
  906. if (/* mIsSamsungCdma && */ infoRec.record instanceof CdmaSignalInfoRec) {
  907. CdmaSignalInfoRec sir = (CdmaSignalInfoRec)infoRec.record;
  908. if (sir != null && sir.isPresent &&
  909. sir.signalType == SignalToneUtil.IS95_CONST_IR_SIGNAL_IS54B &&
  910. sir.alertPitch == SignalToneUtil.IS95_CONST_IR_ALERT_MED &&
  911. sir.signal == SignalToneUtil.IS95_CONST_IR_SIG_IS54B_L) {
  912.  
  913. Log.d(LOG_TAG, "Dropping \"" + responseToString(response) + " " +
  914. retToString(response, sir) + "\" to prevent \"ring of death\" bug.");
  915. return;
  916. }
  917. }
  918.  
  919. super.notifyRegistrantsCdmaInfoRec(infoRec);
  920. }
  921.  
  922. protected class SamsungDriverCall extends DriverCall {
  923. @Override
  924. public String
  925. toString() {
  926. // Samsung CDMA devices' call parcel is formatted differently
  927. // fake unused data for video calls, and fix formatting
  928. // so that voice calls' information can be correctly parsed
  929. return "id=" + index + ","
  930. + state + ","
  931. + "toa=" + TOA + ","
  932. + (isMpty ? "conf" : "norm") + ","
  933. + (isMT ? "mt" : "mo") + ","
  934. + "als=" + als + ","
  935. + (isVoice ? "voc" : "nonvoc") + ","
  936. + "nonvid" + ","
  937. + number + ","
  938. + "cli=" + numberPresentation + ","
  939. + "name=" + name + ","
  940. + namePresentation;
  941. }
  942. }
  943. @Override
  944. public void setPreferredNetworkType(int networkType , Message response) {
  945. /* Samsung modem implementation does bad things when a datacall is running
  946. * while switching the preferred networktype.
  947. */
  948. ConnectivityManager cm =
  949. (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
  950.  
  951. if(cm.getMobileDataEnabled())
  952. {
  953. ConnectivityHandler handler = new ConnectivityHandler(mContext);
  954. handler.setPreferedNetworkType(networkType, response);
  955. } else {
  956. sendPreferedNetworktype(networkType, response);
  957. }
  958. }
  959.  
  960.  
  961. //Sends the real RIL request to the modem.
  962. private void sendPreferedNetworktype(int networkType, Message response) {
  963. RILRequest rr = RILRequest.obtain(
  964. RILConstants.RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE, response);
  965.  
  966. rr.mp.writeInt(1);
  967. rr.mp.writeInt(networkType);
  968.  
  969. if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
  970. + " : " + networkType);
  971.  
  972. send(rr);
  973. }
  974. /* private class that does the handling for the dataconnection
  975. * dataconnection is done async, so we send the request for disabling it,
  976. * wait for the response, set the prefered networktype and notify the
  977. * real sender with its result.
  978. */
  979. private class ConnectivityHandler extends Handler{
  980.  
  981. private static final int MESSAGE_SET_PREFERRED_NETWORK_TYPE = 30;
  982. private Context mContext;
  983. private int mDesiredNetworkType;
  984. //the original message, we need it for calling back the original caller when done
  985. private Message mNetworktypeResponse;
  986. private ConnectivityBroadcastReceiver mConnectivityReceiver = new ConnectivityBroadcastReceiver();
  987.  
  988. public ConnectivityHandler(Context context)
  989. {
  990. mContext = context;
  991. }
  992.  
  993. private void startListening() {
  994. IntentFilter filter = new IntentFilter();
  995. filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
  996. mContext.registerReceiver(mConnectivityReceiver, filter);
  997. }
  998.  
  999. private synchronized void stopListening() {
  1000. mContext.unregisterReceiver(mConnectivityReceiver);
  1001. }
  1002.  
  1003. public void setPreferedNetworkType(int networkType, Message response)
  1004. {
  1005. Log.d(LOG_TAG, "Mobile Dataconnection is online setting it down");
  1006. mDesiredNetworkType = networkType;
  1007. mNetworktypeResponse = response;
  1008. ConnectivityManager cm =
  1009. (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
  1010. //start listening for the connectivity change broadcast
  1011. startListening();
  1012. cm.setMobileDataEnabled(false);
  1013. }
  1014.  
  1015. @Override
  1016. public void handleMessage(Message msg) {
  1017. switch(msg.what) {
  1018. //networktype was set, now we can enable the dataconnection again
  1019. case MESSAGE_SET_PREFERRED_NETWORK_TYPE:
  1020. ConnectivityManager cm =
  1021. (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
  1022.  
  1023. Log.d(LOG_TAG, "preferred NetworkType set upping Mobile Dataconnection");
  1024.  
  1025. cm.setMobileDataEnabled(true);
  1026. //everything done now call back that we have set the networktype
  1027. AsyncResult.forMessage(mNetworktypeResponse, null, null);
  1028. mNetworktypeResponse.sendToTarget();
  1029. mNetworktypeResponse = null;
  1030. break;
  1031. default:
  1032. throw new RuntimeException("unexpected event not handled");
  1033. }
  1034. }
  1035.  
  1036. private class ConnectivityBroadcastReceiver extends BroadcastReceiver {
  1037.  
  1038. @Override
  1039. public void onReceive(Context context, Intent intent) {
  1040. String action = intent.getAction();
  1041. if (!action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
  1042. Log.w(LOG_TAG, "onReceived() called with " + intent);
  1043. return;
  1044. }
  1045. boolean noConnectivity =
  1046. intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
  1047.  
  1048. if (noConnectivity) {
  1049. //Ok dataconnection is down, now set the networktype
  1050. Log.w(LOG_TAG, "Mobile Dataconnection is now down setting preferred NetworkType");
  1051. stopListening();
  1052. sendPreferedNetworktype(mDesiredNetworkType, obtainMessage(MESSAGE_SET_PREFERRED_NETWORK_TYPE));
  1053. mDesiredNetworkType = -1;
  1054. }
  1055. }
  1056. }
  1057. }
  1058. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement