/** * Re-enable mobile data connectivity after a {@link #teardown()}. * * @param radioNum 0:sim1, 1:sim2 */ public boolean reconnectGemini(int radioNum) { boolean retValue = false; // false: failed, true: network is connecting or connected // reset teardown flag setTeardownRequested(false); switch (setEnableApnGemini(mApnType, true, radioNum)) { case PhoneConstants.APN_ALREADY_ACTIVE: // need to set self to CONNECTING so the below message is handled. // TODO: need to notify the app retValue = true; break; case PhoneConstants.APN_REQUEST_STARTED: // set IDLE here , avoid the following second FAILED not sent out if (!mNetworkInfo.isConnectedOrConnecting()) { mNetworkInfo.setDetailedState(DetailedState.IDLE, null, null); } retValue = true; break; case PhoneConstants.APN_REQUEST_FAILED: case PhoneConstants.APN_TYPE_NOT_AVAILABLE: break; default: loge("Error in reconnect - unexpected response."); break; } return retValue; }
/** * Re-enable mobile data connectivity after a {@link #teardown()}. TODO - make async and always * get a notification? */ public boolean reconnect() { boolean retValue = false; // connected or expect to be? setTeardownRequested(false); switch (setEnableApn(mApnType, true)) { case Phone.APN_ALREADY_ACTIVE: // need to set self to CONNECTING so the below message is handled. retValue = true; break; case Phone.APN_REQUEST_STARTED: // set IDLE here , avoid the following second FAILED not sent out mNetworkInfo.setDetailedState(DetailedState.IDLE, null, null); retValue = true; break; case Phone.APN_REQUEST_FAILED: case Phone.APN_TYPE_NOT_AVAILABLE: break; default: loge("Error in reconnect - unexpected response."); break; } return retValue; }
/** * Tear down mobile data connectivity, i.e., disable the ability to create mobile data * connections. * * @param radioNum 0:sim1, 1:sim2 */ public boolean teardownGemini(int radioNum) { setTeardownRequested(true); return (setEnableApnGemini(mApnType, false, radioNum) != PhoneConstants.APN_REQUEST_FAILED); }
/** * Tear down mobile data connectivity, i.e., disable the ability to create mobile data * connections. TODO - make async and return nothing? */ public boolean teardown() { setTeardownRequested(true); return (setEnableApn(mApnType, false) != PhoneConstants.APN_REQUEST_FAILED); }
@Override public void onReceive(Context context, Intent intent) { if (intent .getAction() .equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED_MOBILE)) { String apnType = intent.getStringExtra(PhoneConstants.DATA_APN_TYPE_KEY); MobileDataStateTracker tracker = mTrackerMap.get(apnType); if (tracker == null) { return; } int slot = 0; int curSlot = 0; if (FeatureOption.MTK_GEMINI_SUPPORT) { slot = intent.getIntExtra(PhoneConstants.GEMINI_SIM_ID_KEY, PhoneConstants.GEMINI_SIM_1); curSlot = tracker.mNetworkInfo.getSimId(); } if (tracker.mMobileDataState == PhoneConstants.DataState.CONNECTED) { if (slot != curSlot) { tracker.log("Receive peer SIM data state.ignor!"); return; } } if (VDBG) Slog.d( TAG, "MobileDataStateReceiver received: ACTION_ANY_DATA_CONNECTION_STATE_CHANGED_MOBILE [" + apnType + "]"); tracker.log( "Intent from SIM " + slot + ", current SIM " + curSlot + ", current DataState " + tracker.mMobileDataState); int oldSubtype = tracker.mNetworkInfo.getSubtype(); int newSubType = TelephonyManager.NETWORK_TYPE_UNKNOWN; String subTypeName; if (FeatureOption.MTK_GEMINI_SUPPORT) { newSubType = TelephonyManager.getDefault().getNetworkTypeGemini(tracker.mNetworkInfo.getSimId()); subTypeName = TelephonyManager.getDefault() .getNetworkTypeNameGemini(tracker.mNetworkInfo.getSimId()); } else { newSubType = TelephonyManager.getDefault().getNetworkType(); subTypeName = TelephonyManager.getDefault().getNetworkTypeName(); } tracker.mNetworkInfo.setSubtype(newSubType, subTypeName); if (newSubType != oldSubtype && tracker.mNetworkInfo.isConnected()) { Message msg = tracker.mTarget.obtainMessage( EVENT_NETWORK_SUBTYPE_CHANGED, oldSubtype, 0, tracker.mNetworkInfo); msg.sendToTarget(); } PhoneConstants.DataState state = Enum.valueOf( PhoneConstants.DataState.class, intent.getStringExtra(PhoneConstants.STATE_KEY)); String reason = intent.getStringExtra(PhoneConstants.STATE_CHANGE_REASON_KEY); String apnName = intent.getStringExtra(PhoneConstants.DATA_APN_KEY); tracker.mNetworkInfo.setRoaming( intent.getBooleanExtra(PhoneConstants.DATA_NETWORK_ROAMING_KEY, false)); if (VDBG) { tracker.log( tracker.mApnType + " setting isAvailable to " + !intent.getBooleanExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, false)); } tracker.mNetworkInfo.setIsAvailable( !intent.getBooleanExtra(PhoneConstants.NETWORK_UNAVAILABLE_KEY, false)); if (DBG) { tracker.log( "Received state=" + state + ", old=" + tracker.mMobileDataState + ", reason=" + (reason == null ? "(unspecified)" : reason)); } if (tracker.mMobileDataState != state) { tracker.mMobileDataState = state; switch (state) { case DISCONNECTED: if (tracker.isTeardownRequested()) { tracker.setTeardownRequested(false); } if (FeatureOption.MTK_GEMINI_SUPPORT) { tracker.setDetailedStateGemini(DetailedState.DISCONNECTED, reason, apnName, slot); } else { tracker.setDetailedState(DetailedState.DISCONNECTED, reason, apnName); } // can't do this here - ConnectivityService needs it to clear stuff // it's ok though - just leave it to be refreshed next time // we connect. // if (DBG) log("clearing mInterfaceName for "+ mApnType + // " as it DISCONNECTED"); // mInterfaceName = null; break; case CONNECTING: if (FeatureOption.MTK_GEMINI_SUPPORT) { tracker.setDetailedStateGemini(DetailedState.CONNECTING, reason, apnName, slot); } else { tracker.setDetailedState(DetailedState.CONNECTING, reason, apnName); } break; case SUSPENDED: if (FeatureOption.MTK_GEMINI_SUPPORT) { tracker.setDetailedStateGemini(DetailedState.SUSPENDED, reason, apnName, slot); } else { tracker.setDetailedState(DetailedState.SUSPENDED, reason, apnName); } break; case CONNECTED: tracker.mLinkProperties = intent.getParcelableExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY); if (tracker.mLinkProperties == null) { tracker.loge("CONNECTED event did not supply link properties."); tracker.mLinkProperties = new LinkProperties(); } tracker.mLinkCapabilities = intent.getParcelableExtra(PhoneConstants.DATA_LINK_CAPABILITIES_KEY); if (tracker.mLinkCapabilities == null) { tracker.loge("CONNECTED event did not supply link capabilities."); tracker.mLinkCapabilities = new LinkCapabilities(); } if (FeatureOption.MTK_GEMINI_SUPPORT) { tracker.setDetailedStateGemini(DetailedState.CONNECTED, reason, apnName, slot); } else { tracker.setDetailedState(DetailedState.CONNECTED, reason, apnName); } break; } } else { // There was no state change. Check if LinkProperties has been updated. if (TextUtils.equals(reason, PhoneConstants.REASON_LINK_PROPERTIES_CHANGED)) { tracker.mLinkProperties = intent.getParcelableExtra(PhoneConstants.DATA_LINK_PROPERTIES_KEY); if (tracker.mLinkProperties == null) { tracker.loge("No link property in LINK_PROPERTIES change event."); tracker.mLinkProperties = new LinkProperties(); } // Just update reason field in this NetworkInfo tracker.mNetworkInfo.setDetailedState( tracker.mNetworkInfo.getDetailedState(), reason, tracker.mNetworkInfo.getExtraInfo()); Message msg = tracker.mTarget.obtainMessage(EVENT_CONFIGURATION_CHANGED, tracker.mNetworkInfo); msg.sendToTarget(); } if (reason != null && (reason.equals(Phone.REASON_APN_FAILED) || reason.equals(PhoneConstants.REASON_NO_SUCH_PDP)) && apnType != null && !apnType.equals(PhoneConstants.APN_TYPE_DEFAULT)) { tracker.log( "Handle PhoneConstants.REASON_APN_FAILED OR PhoneConstants.REASON_NO_SUCH_PDP from GeminiDataSubUtil"); if (state == PhoneConstants.DataState.DISCONNECTED) { if (tracker.isTeardownRequested()) { tracker.setTeardownRequested(false); } if (FeatureOption.MTK_GEMINI_SUPPORT) { tracker.setDetailedStateGemini(DetailedState.DISCONNECTED, reason, apnName, slot); } else { tracker.setDetailedState(DetailedState.DISCONNECTED, reason, apnName); } } } } } else if (intent.getAction().equals(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED)) { String apnType = intent.getStringExtra(PhoneConstants.DATA_APN_TYPE_KEY); MobileDataStateTracker tracker = mTrackerMap.get(apnType); if (tracker == null) { return; } if (DBG) Slog.d( TAG, "MobileDataStateReceiver received: ACTION_ANY_DATA_CONNECTION_FAILED ignore [" + apnType + "]"); int slot = 0; String reason = intent.getStringExtra(PhoneConstants.FAILURE_REASON_KEY); String apnName = intent.getStringExtra(PhoneConstants.DATA_APN_KEY); if (DBG) { tracker.log( "Received " + intent.getAction() + " broadcast" + reason == null ? "" : "(" + reason + ")"); } if (FeatureOption.MTK_GEMINI_SUPPORT) { slot = intent.getIntExtra(PhoneConstants.GEMINI_SIM_ID_KEY, PhoneConstants.GEMINI_SIM_1); tracker.setDetailedStateGemini(DetailedState.FAILED, reason, apnName, slot); } else { tracker.setDetailedState(DetailedState.FAILED, reason, apnName); } } else if (intent.getAction().equals(DctConstants.ACTION_DATA_CONNECTION_TRACKER_MESSENGER)) { if (VDBG) Slog.d(TAG, "MobileDataStateReceiver received: ACTION_DATA_CONNECTION_TRACKER_MESSENGER"); Messenger messenger = intent.getParcelableExtra(DctConstants.EXTRA_MESSENGER); Collection<MobileDataStateTracker> collection = mTrackerMap.values(); Iterator<MobileDataStateTracker> iter = collection.iterator(); while (iter.hasNext()) { MobileDataStateTracker tracker = iter.next(); tracker.mMessenger = messenger; AsyncChannel ac = new AsyncChannel(); ac.connect(tracker.mContext, tracker.mHandler, tracker.mMessenger); } } else { if (DBG) Slog.d(TAG, "MobileDataStateReceiver received: ignore " + intent.getAction()); } }