@Override public void handleMessage(Message msg) { switch (msg.what) { case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED: if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) { if (VDBG) { mMdst.log("MdstHandler connected"); } mMdst.mDataConnectionTrackerAc = (AsyncChannel) msg.obj; } else { if (VDBG) { mMdst.log("MdstHandler %s NOT connected error=" + msg.arg1); } } break; case AsyncChannel.CMD_CHANNEL_DISCONNECTED: if (VDBG) mMdst.log("Disconnected from DataStateTracker"); mMdst.mDataConnectionTrackerAc = null; break; default: { if (VDBG) mMdst.log("Ignorning unknown message=" + msg); break; } } }
@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()); } }