1bda761320929f714951c328bfec6a51a1978db97Wink Saville/* 2bda761320929f714951c328bfec6a51a1978db97Wink Saville * Copyright (C) 2014 The Android Open Source Project 3bda761320929f714951c328bfec6a51a1978db97Wink Saville * 4bda761320929f714951c328bfec6a51a1978db97Wink Saville * Licensed under the Apache License, Version 2.0 (the "License"); 5bda761320929f714951c328bfec6a51a1978db97Wink Saville * you may not use this file except in compliance with the License. 6bda761320929f714951c328bfec6a51a1978db97Wink Saville * You may obtain a copy of the License at 7bda761320929f714951c328bfec6a51a1978db97Wink Saville * 8bda761320929f714951c328bfec6a51a1978db97Wink Saville * http://www.apache.org/licenses/LICENSE-2.0 9bda761320929f714951c328bfec6a51a1978db97Wink Saville * 10bda761320929f714951c328bfec6a51a1978db97Wink Saville * Unless required by applicable law or agreed to in writing, software 11bda761320929f714951c328bfec6a51a1978db97Wink Saville * distributed under the License is distributed on an "AS IS" BASIS, 12bda761320929f714951c328bfec6a51a1978db97Wink Saville * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13bda761320929f714951c328bfec6a51a1978db97Wink Saville * See the License for the specific language governing permissions and 14bda761320929f714951c328bfec6a51a1978db97Wink Saville * limitations under the License. 15bda761320929f714951c328bfec6a51a1978db97Wink Saville */ 16bda761320929f714951c328bfec6a51a1978db97Wink Saville 17bda761320929f714951c328bfec6a51a1978db97Wink Savillepackage com.android.internal.telephony.dataconnection; 18bda761320929f714951c328bfec6a51a1978db97Wink Saville 19bda761320929f714951c328bfec6a51a1978db97Wink Savilleimport com.android.internal.util.AsyncChannel; 20f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajanimport com.android.internal.util.IState; 21bda761320929f714951c328bfec6a51a1978db97Wink Savilleimport com.android.internal.util.Protocol; 22bda761320929f714951c328bfec6a51a1978db97Wink Savilleimport com.android.internal.util.State; 23bda761320929f714951c328bfec6a51a1978db97Wink Savilleimport com.android.internal.util.StateMachine; 24689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwaltimport com.android.internal.telephony.CommandException; 25bda761320929f714951c328bfec6a51a1978db97Wink Savilleimport com.android.internal.telephony.Phone; 26bda761320929f714951c328bfec6a51a1978db97Wink Savilleimport com.android.internal.telephony.PhoneConstants; 27bda761320929f714951c328bfec6a51a1978db97Wink Savilleimport com.android.internal.telephony.PhoneBase; 28bda761320929f714951c328bfec6a51a1978db97Wink Savilleimport com.android.internal.telephony.PhoneProxy; 29bda761320929f714951c328bfec6a51a1978db97Wink Savilleimport com.android.internal.telephony.dataconnection.DcSwitchAsyncChannel.RequestInfo; 30bda761320929f714951c328bfec6a51a1978db97Wink Saville 31a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwaltimport android.os.AsyncResult; 32bda761320929f714951c328bfec6a51a1978db97Wink Savilleimport android.os.Message; 33bda761320929f714951c328bfec6a51a1978db97Wink Savilleimport android.telephony.Rlog; 34bda761320929f714951c328bfec6a51a1978db97Wink Saville 35bda761320929f714951c328bfec6a51a1978db97Wink Savillepublic class DcSwitchStateMachine extends StateMachine { 36bda761320929f714951c328bfec6a51a1978db97Wink Saville private static final boolean DBG = true; 37bda761320929f714951c328bfec6a51a1978db97Wink Saville private static final boolean VDBG = false; 38bda761320929f714951c328bfec6a51a1978db97Wink Saville private static final String LOG_TAG = "DcSwitchSM"; 39bda761320929f714951c328bfec6a51a1978db97Wink Saville 40bda761320929f714951c328bfec6a51a1978db97Wink Saville // ***** Event codes for driving the state machine 41bda761320929f714951c328bfec6a51a1978db97Wink Saville private static final int BASE = Protocol.BASE_DATA_CONNECTION_TRACKER + 0x00001000; 42689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt private static final int EVENT_CONNECTED = BASE + 0; 43689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt private static final int EVENT_DATA_ALLOWED = BASE + 1; 44689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt private static final int CMD_RETRY_ATTACH = BASE + 2; 45689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt private static final int EVENT_DATA_DISALLOWED = BASE + 3; 46bda761320929f714951c328bfec6a51a1978db97Wink Saville 47bda761320929f714951c328bfec6a51a1978db97Wink Saville private int mId; 48bda761320929f714951c328bfec6a51a1978db97Wink Saville private Phone mPhone; 49bda761320929f714951c328bfec6a51a1978db97Wink Saville private AsyncChannel mAc; 50bda761320929f714951c328bfec6a51a1978db97Wink Saville 51bda761320929f714951c328bfec6a51a1978db97Wink Saville private IdleState mIdleState = new IdleState(); 52f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan private EmergencyState mEmergencyState = new EmergencyState(); 53bda761320929f714951c328bfec6a51a1978db97Wink Saville private AttachingState mAttachingState = new AttachingState(); 54bda761320929f714951c328bfec6a51a1978db97Wink Saville private AttachedState mAttachedState = new AttachedState(); 55bda761320929f714951c328bfec6a51a1978db97Wink Saville private DetachingState mDetachingState = new DetachingState(); 56bda761320929f714951c328bfec6a51a1978db97Wink Saville private DefaultState mDefaultState = new DefaultState(); 57bda761320929f714951c328bfec6a51a1978db97Wink Saville 58f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan // In case of transition to emergency state, this tracks the state of the state machine prior 59f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan // to entering emergency state 60f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan private IState mPreEmergencyState; 61f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan 62bda761320929f714951c328bfec6a51a1978db97Wink Saville protected DcSwitchStateMachine(Phone phone, String name, int id) { 63bda761320929f714951c328bfec6a51a1978db97Wink Saville super(name); 64bda761320929f714951c328bfec6a51a1978db97Wink Saville if (DBG) log("DcSwitchState constructor E"); 65bda761320929f714951c328bfec6a51a1978db97Wink Saville mPhone = phone; 66bda761320929f714951c328bfec6a51a1978db97Wink Saville mId = id; 67bda761320929f714951c328bfec6a51a1978db97Wink Saville 68bda761320929f714951c328bfec6a51a1978db97Wink Saville addState(mDefaultState); 69bda761320929f714951c328bfec6a51a1978db97Wink Saville addState(mIdleState, mDefaultState); 70f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan addState(mEmergencyState, mDefaultState); 71bda761320929f714951c328bfec6a51a1978db97Wink Saville addState(mAttachingState, mDefaultState); 72bda761320929f714951c328bfec6a51a1978db97Wink Saville addState(mAttachedState, mDefaultState); 73bda761320929f714951c328bfec6a51a1978db97Wink Saville addState(mDetachingState, mDefaultState); 74bda761320929f714951c328bfec6a51a1978db97Wink Saville setInitialState(mIdleState); 75bda761320929f714951c328bfec6a51a1978db97Wink Saville if (DBG) log("DcSwitchState constructor X"); 76bda761320929f714951c328bfec6a51a1978db97Wink Saville } 77bda761320929f714951c328bfec6a51a1978db97Wink Saville 78bda761320929f714951c328bfec6a51a1978db97Wink Saville// public void notifyDataConnection(int phoneId, String state, String reason, 79bda761320929f714951c328bfec6a51a1978db97Wink Saville// String apnName, String apnType, boolean unavailable) { 80bda761320929f714951c328bfec6a51a1978db97Wink Saville// if (phoneId == mId && 81bda761320929f714951c328bfec6a51a1978db97Wink Saville// TextUtils.equals(state, PhoneConstants.DataState.CONNECTED.toString())) { 82bda761320929f714951c328bfec6a51a1978db97Wink Saville// sendMessage(obtainMessage(EVENT_CONNECTED)); 83bda761320929f714951c328bfec6a51a1978db97Wink Saville// } 84bda761320929f714951c328bfec6a51a1978db97Wink Saville// } 85bda761320929f714951c328bfec6a51a1978db97Wink Saville 86bda761320929f714951c328bfec6a51a1978db97Wink Saville private class IdleState extends State { 87bda761320929f714951c328bfec6a51a1978db97Wink Saville @Override 88bda761320929f714951c328bfec6a51a1978db97Wink Saville public void enter() { 89bda761320929f714951c328bfec6a51a1978db97Wink Saville if (DBG) log("IdleState: enter"); 90bda761320929f714951c328bfec6a51a1978db97Wink Saville 91bda761320929f714951c328bfec6a51a1978db97Wink Saville try { 92bda761320929f714951c328bfec6a51a1978db97Wink Saville DctController.getInstance().processRequests(); 93bda761320929f714951c328bfec6a51a1978db97Wink Saville } catch (RuntimeException e) { 94bda761320929f714951c328bfec6a51a1978db97Wink Saville if (DBG) loge("DctController is not ready"); 95bda761320929f714951c328bfec6a51a1978db97Wink Saville } 96bda761320929f714951c328bfec6a51a1978db97Wink Saville } 97bda761320929f714951c328bfec6a51a1978db97Wink Saville 98bda761320929f714951c328bfec6a51a1978db97Wink Saville @Override 99bda761320929f714951c328bfec6a51a1978db97Wink Saville public boolean processMessage(Message msg) { 100bda761320929f714951c328bfec6a51a1978db97Wink Saville boolean retVal; 101bda761320929f714951c328bfec6a51a1978db97Wink Saville 102bda761320929f714951c328bfec6a51a1978db97Wink Saville switch (msg.what) { 103bda761320929f714951c328bfec6a51a1978db97Wink Saville case DcSwitchAsyncChannel.REQ_CONNECT: { 104a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt RequestInfo apnRequest = (RequestInfo)msg.obj; 1052dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt apnRequest.log("DcSwitchStateMachine.IdleState: REQ_CONNECT"); 106a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt if (DBG) log("IdleState: REQ_CONNECT, apnRequest=" + apnRequest); 107a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt transitionTo(mAttachingState); 108a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt retVal = HANDLED; 109a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt break; 110a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt } 111bda761320929f714951c328bfec6a51a1978db97Wink Saville 112a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt case DcSwitchAsyncChannel.REQ_DISCONNECT_ALL: { 113a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt if (DBG) log("AttachingState: REQ_DISCONNECT_ALL" ); 114bda761320929f714951c328bfec6a51a1978db97Wink Saville 115a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt // Shouldn't have any requests, but why not try.. 116a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt DctController.getInstance().releaseAllRequests(mId); 117bda761320929f714951c328bfec6a51a1978db97Wink Saville 118bda761320929f714951c328bfec6a51a1978db97Wink Saville retVal = HANDLED; 119bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 120bda761320929f714951c328bfec6a51a1978db97Wink Saville } 121bda761320929f714951c328bfec6a51a1978db97Wink Saville 122a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt 123bda761320929f714951c328bfec6a51a1978db97Wink Saville case DcSwitchAsyncChannel.EVENT_DATA_ATTACHED: 124bda761320929f714951c328bfec6a51a1978db97Wink Saville if (DBG) { 125bda761320929f714951c328bfec6a51a1978db97Wink Saville log("AttachingState: EVENT_DATA_ATTACHED"); 126bda761320929f714951c328bfec6a51a1978db97Wink Saville } 127bda761320929f714951c328bfec6a51a1978db97Wink Saville transitionTo(mAttachedState); 128bda761320929f714951c328bfec6a51a1978db97Wink Saville retVal = HANDLED; 129bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 130bda761320929f714951c328bfec6a51a1978db97Wink Saville 131bda761320929f714951c328bfec6a51a1978db97Wink Saville case EVENT_CONNECTED: { 132bda761320929f714951c328bfec6a51a1978db97Wink Saville if (DBG) { 133bda761320929f714951c328bfec6a51a1978db97Wink Saville log("IdleState: Receive invalid event EVENT_CONNECTED!"); 134bda761320929f714951c328bfec6a51a1978db97Wink Saville } 135bda761320929f714951c328bfec6a51a1978db97Wink Saville retVal = HANDLED; 136bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 137bda761320929f714951c328bfec6a51a1978db97Wink Saville } 138bda761320929f714951c328bfec6a51a1978db97Wink Saville default: 139bda761320929f714951c328bfec6a51a1978db97Wink Saville if (VDBG) { 140bda761320929f714951c328bfec6a51a1978db97Wink Saville log("IdleState: nothandled msg.what=0x" + 141bda761320929f714951c328bfec6a51a1978db97Wink Saville Integer.toHexString(msg.what)); 142bda761320929f714951c328bfec6a51a1978db97Wink Saville } 143bda761320929f714951c328bfec6a51a1978db97Wink Saville retVal = NOT_HANDLED; 144bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 145bda761320929f714951c328bfec6a51a1978db97Wink Saville } 146bda761320929f714951c328bfec6a51a1978db97Wink Saville return retVal; 147bda761320929f714951c328bfec6a51a1978db97Wink Saville } 148bda761320929f714951c328bfec6a51a1978db97Wink Saville } 149bda761320929f714951c328bfec6a51a1978db97Wink Saville 150f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan private class EmergencyState extends State { 151f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan @Override 152f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan public boolean processMessage(Message msg) { 153f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan final PhoneBase pb = (PhoneBase)((PhoneProxy)mPhone).getActivePhone(); 154f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan if (!pb.mDcTracker.isEmergency()) { 155f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan loge("EmergencyState: isEmergency() is false. deferMessage msg.what=0x" + 156f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan Integer.toHexString(msg.what)); 157f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan deferMessage(msg); 158f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan transitionTo(mPreEmergencyState); 159f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan return HANDLED; 160f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan } 161f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan 162f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan switch (msg.what) { 163f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan case DcSwitchAsyncChannel.EVENT_EMERGENCY_CALL_ENDED: { 164f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan transitionTo(mPreEmergencyState); 165f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan break; 166f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan } 167f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan 168f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan case DcSwitchAsyncChannel.EVENT_EMERGENCY_CALL_STARTED: { 169f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan loge("EmergencyState: ignoring EVENT_EMERGENCY_CALL_STARTED"); 170f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan break; 171f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan } 172f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan 173082f02d3d9a865510db6c67162d302772559a93eRobert Greenwalt // explicitly call out the messages we must defer 174082f02d3d9a865510db6c67162d302772559a93eRobert Greenwalt // anything not listed falls through to the default state 175082f02d3d9a865510db6c67162d302772559a93eRobert Greenwalt case DcSwitchAsyncChannel.REQ_CONNECT: 176082f02d3d9a865510db6c67162d302772559a93eRobert Greenwalt case DcSwitchAsyncChannel.REQ_RETRY_CONNECT: 177082f02d3d9a865510db6c67162d302772559a93eRobert Greenwalt case DcSwitchAsyncChannel.REQ_DISCONNECT_ALL: 178082f02d3d9a865510db6c67162d302772559a93eRobert Greenwalt case DcSwitchAsyncChannel.EVENT_DATA_ATTACHED: 179082f02d3d9a865510db6c67162d302772559a93eRobert Greenwalt case DcSwitchAsyncChannel.EVENT_DATA_DETACHED: { 180f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan log("EmergencyState: deferMessage msg.what=0x" + Integer.toHexString(msg.what)); 181f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan deferMessage(msg); 182f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan break; 183f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan } 184082f02d3d9a865510db6c67162d302772559a93eRobert Greenwalt 185082f02d3d9a865510db6c67162d302772559a93eRobert Greenwalt default: { 186082f02d3d9a865510db6c67162d302772559a93eRobert Greenwalt if (VDBG) { 187082f02d3d9a865510db6c67162d302772559a93eRobert Greenwalt log("EmergencyState: nothandled msg.what=0x" + 188082f02d3d9a865510db6c67162d302772559a93eRobert Greenwalt Integer.toHexString(msg.what)); 189082f02d3d9a865510db6c67162d302772559a93eRobert Greenwalt } 190082f02d3d9a865510db6c67162d302772559a93eRobert Greenwalt return NOT_HANDLED; 191082f02d3d9a865510db6c67162d302772559a93eRobert Greenwalt } 192f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan } 193f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan 194f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan return HANDLED; 195f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan } 196f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan } 197f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan 198bda761320929f714951c328bfec6a51a1978db97Wink Saville private class AttachingState extends State { 199a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt private int mCurrentAllowedSequence = 0; 200bda761320929f714951c328bfec6a51a1978db97Wink Saville @Override 201bda761320929f714951c328bfec6a51a1978db97Wink Saville public void enter() { 202bda761320929f714951c328bfec6a51a1978db97Wink Saville log("AttachingState: enter"); 203a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt doEnter(); 204a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt } 205a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt 206a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt private void doEnter() { 207a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt final PhoneBase pb = (PhoneBase)((PhoneProxy)mPhone).getActivePhone(); 208a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt pb.mCi.setDataAllowed(true, obtainMessage(EVENT_DATA_ALLOWED, 209a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt ++mCurrentAllowedSequence, 0)); 210aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt // if we're on a carrier that unattaches us if we're idle for too long 211aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt // (on wifi) and they won't re-attach until we poke them. Poke them! 212aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt // essentially react as Attached does here in Attaching. 213aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt if (pb.mDcTracker.getAutoAttachOnCreation()) { 214aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt if (DBG) log("AttachingState executeAll due to autoAttach"); 215aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt DctController.getInstance().executeAllRequests(mId); 216aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt } 217bda761320929f714951c328bfec6a51a1978db97Wink Saville } 218bda761320929f714951c328bfec6a51a1978db97Wink Saville 219bda761320929f714951c328bfec6a51a1978db97Wink Saville @Override 220bda761320929f714951c328bfec6a51a1978db97Wink Saville public boolean processMessage(Message msg) { 221bda761320929f714951c328bfec6a51a1978db97Wink Saville boolean retVal; 222bda761320929f714951c328bfec6a51a1978db97Wink Saville 223bda761320929f714951c328bfec6a51a1978db97Wink Saville switch (msg.what) { 224bda761320929f714951c328bfec6a51a1978db97Wink Saville case DcSwitchAsyncChannel.REQ_CONNECT: { 225a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt RequestInfo apnRequest = (RequestInfo)msg.obj; 2262dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt apnRequest.log("DcSwitchStateMachine.AttachingState: REQ_CONNECT"); 227a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt if (DBG) log("AttachingState: REQ_CONNECT, apnRequest=" + apnRequest); 228bda761320929f714951c328bfec6a51a1978db97Wink Saville 229aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt final PhoneBase pb = (PhoneBase)((PhoneProxy)mPhone).getActivePhone(); 230aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt if (pb.mDcTracker.getAutoAttachOnCreation() == false) { 231aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt // do nothing - wait til we attach and then we'll execute all requests 232aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt } else { 233aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt apnRequest.log("DcSwitchStateMachine processing due to autoAttach"); 234aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt DctController.getInstance().executeRequest(apnRequest); 235aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt } 236a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt retVal = HANDLED; 237a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt break; 238a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt } 239a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt case EVENT_DATA_ALLOWED: { 240a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt AsyncResult ar = (AsyncResult)msg.obj; 241a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt if (mCurrentAllowedSequence != msg.arg1) { 242689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt loge("EVENT_DATA_ALLOWED ignored arg1=" + msg.arg1 + ", seq=" + 243a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt mCurrentAllowedSequence); 244a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt } else if (ar.exception != null) { 245689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt if (ar.exception instanceof CommandException) { 246689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt CommandException e = (CommandException)ar.exception; 247689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt if (e.getCommandError() == 248689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt CommandException.Error.REQUEST_NOT_SUPPORTED) { 249689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt // must be on a single-sim device so stay in Attaching 250689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt // this is important to avoid an infinite loop 251689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt retVal = HANDLED; 252689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt break; 253689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt } 254689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt } 255689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt loge("EVENT_DATA_ALLOWED failed, " + ar.exception); 256a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt transitionTo(mIdleState); 257a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt } 258bda761320929f714951c328bfec6a51a1978db97Wink Saville retVal = HANDLED; 259bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 260bda761320929f714951c328bfec6a51a1978db97Wink Saville } 261bda761320929f714951c328bfec6a51a1978db97Wink Saville 262a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt case DcSwitchAsyncChannel.REQ_RETRY_CONNECT: { 263a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt if (DBG) log("AttachingState going to retry"); 264a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt doEnter(); 265a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt retVal = HANDLED; 266a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt break; 267a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt } 268a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt 269a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt case DcSwitchAsyncChannel.EVENT_DATA_ATTACHED: { 270bda761320929f714951c328bfec6a51a1978db97Wink Saville if (DBG) { 271bda761320929f714951c328bfec6a51a1978db97Wink Saville log("AttachingState: EVENT_DATA_ATTACHED"); 272bda761320929f714951c328bfec6a51a1978db97Wink Saville } 273bda761320929f714951c328bfec6a51a1978db97Wink Saville transitionTo(mAttachedState); 274bda761320929f714951c328bfec6a51a1978db97Wink Saville retVal = HANDLED; 275bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 276a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt } 277bda761320929f714951c328bfec6a51a1978db97Wink Saville 278bda761320929f714951c328bfec6a51a1978db97Wink Saville case DcSwitchAsyncChannel.REQ_DISCONNECT_ALL: { 279bda761320929f714951c328bfec6a51a1978db97Wink Saville if (DBG) { 280bda761320929f714951c328bfec6a51a1978db97Wink Saville log("AttachingState: REQ_DISCONNECT_ALL" ); 281bda761320929f714951c328bfec6a51a1978db97Wink Saville } 282aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt final PhoneBase pb = (PhoneBase)((PhoneProxy)mPhone).getActivePhone(); 283aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt if (pb.mDcTracker.getAutoAttachOnCreation()) { 284aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt // if AutoAttachOnCreation, then we may have executed requests 285aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt // without ever actually getting to Attached, so release the request 286aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt // here in that case. 287aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt if (DBG) log("releasingAll due to autoAttach"); 288aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt DctController.getInstance().releaseAllRequests(mId); 289aacc11b299ac047e73e1e712aa396ea0a6a80158Robert Greenwalt } 290bda761320929f714951c328bfec6a51a1978db97Wink Saville 291a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt // modem gets unhappy if we try to detach while attaching 292a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt // wait til attach finishes. 293a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt deferMessage(msg); 294bda761320929f714951c328bfec6a51a1978db97Wink Saville retVal = HANDLED; 295bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 296bda761320929f714951c328bfec6a51a1978db97Wink Saville } 297bda761320929f714951c328bfec6a51a1978db97Wink Saville 298bda761320929f714951c328bfec6a51a1978db97Wink Saville default: 299bda761320929f714951c328bfec6a51a1978db97Wink Saville if (VDBG) { 300bda761320929f714951c328bfec6a51a1978db97Wink Saville log("AttachingState: nothandled msg.what=0x" + 301bda761320929f714951c328bfec6a51a1978db97Wink Saville Integer.toHexString(msg.what)); 302bda761320929f714951c328bfec6a51a1978db97Wink Saville } 303bda761320929f714951c328bfec6a51a1978db97Wink Saville retVal = NOT_HANDLED; 304bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 305bda761320929f714951c328bfec6a51a1978db97Wink Saville } 306bda761320929f714951c328bfec6a51a1978db97Wink Saville return retVal; 307bda761320929f714951c328bfec6a51a1978db97Wink Saville } 308bda761320929f714951c328bfec6a51a1978db97Wink Saville } 309bda761320929f714951c328bfec6a51a1978db97Wink Saville 310bda761320929f714951c328bfec6a51a1978db97Wink Saville private class AttachedState extends State { 311bda761320929f714951c328bfec6a51a1978db97Wink Saville @Override 312bda761320929f714951c328bfec6a51a1978db97Wink Saville public void enter() { 313bda761320929f714951c328bfec6a51a1978db97Wink Saville if (DBG) log("AttachedState: enter"); 314bda761320929f714951c328bfec6a51a1978db97Wink Saville //When enter attached state, we need exeute all requests. 315bda761320929f714951c328bfec6a51a1978db97Wink Saville DctController.getInstance().executeAllRequests(mId); 316bda761320929f714951c328bfec6a51a1978db97Wink Saville } 317bda761320929f714951c328bfec6a51a1978db97Wink Saville 318bda761320929f714951c328bfec6a51a1978db97Wink Saville @Override 319bda761320929f714951c328bfec6a51a1978db97Wink Saville public boolean processMessage(Message msg) { 320bda761320929f714951c328bfec6a51a1978db97Wink Saville boolean retVal; 321bda761320929f714951c328bfec6a51a1978db97Wink Saville 322bda761320929f714951c328bfec6a51a1978db97Wink Saville switch (msg.what) { 323bda761320929f714951c328bfec6a51a1978db97Wink Saville case DcSwitchAsyncChannel.REQ_CONNECT: { 324bda761320929f714951c328bfec6a51a1978db97Wink Saville RequestInfo apnRequest = (RequestInfo)msg.obj; 3252dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt apnRequest.log("DcSwitchStateMachine.AttachedState: REQ_CONNECT"); 326a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt if (DBG) log("AttachedState: REQ_CONNECT, apnRequest=" + apnRequest); 327bda761320929f714951c328bfec6a51a1978db97Wink Saville 328bda761320929f714951c328bfec6a51a1978db97Wink Saville DctController.getInstance().executeRequest(apnRequest); 329bda761320929f714951c328bfec6a51a1978db97Wink Saville retVal = HANDLED; 330bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 331bda761320929f714951c328bfec6a51a1978db97Wink Saville } 332bda761320929f714951c328bfec6a51a1978db97Wink Saville 333bda761320929f714951c328bfec6a51a1978db97Wink Saville case DcSwitchAsyncChannel.REQ_DISCONNECT_ALL: { 334bda761320929f714951c328bfec6a51a1978db97Wink Saville if (DBG) { 335bda761320929f714951c328bfec6a51a1978db97Wink Saville log("AttachedState: REQ_DISCONNECT_ALL" ); 336bda761320929f714951c328bfec6a51a1978db97Wink Saville } 337bda761320929f714951c328bfec6a51a1978db97Wink Saville DctController.getInstance().releaseAllRequests(mId); 338bda761320929f714951c328bfec6a51a1978db97Wink Saville transitionTo(mDetachingState); 339bda761320929f714951c328bfec6a51a1978db97Wink Saville retVal = HANDLED; 340bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 341bda761320929f714951c328bfec6a51a1978db97Wink Saville } 342bda761320929f714951c328bfec6a51a1978db97Wink Saville 343bda761320929f714951c328bfec6a51a1978db97Wink Saville case DcSwitchAsyncChannel.EVENT_DATA_DETACHED: { 344bda761320929f714951c328bfec6a51a1978db97Wink Saville if (DBG) { 345bda761320929f714951c328bfec6a51a1978db97Wink Saville log("AttachedState: EVENT_DATA_DETACHED"); 346bda761320929f714951c328bfec6a51a1978db97Wink Saville } 347bda761320929f714951c328bfec6a51a1978db97Wink Saville transitionTo(mAttachingState); 348bda761320929f714951c328bfec6a51a1978db97Wink Saville retVal = HANDLED; 349bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 350bda761320929f714951c328bfec6a51a1978db97Wink Saville } 351bda761320929f714951c328bfec6a51a1978db97Wink Saville 352bda761320929f714951c328bfec6a51a1978db97Wink Saville default: 353bda761320929f714951c328bfec6a51a1978db97Wink Saville if (VDBG) { 354bda761320929f714951c328bfec6a51a1978db97Wink Saville log("AttachedState: nothandled msg.what=0x" + 355bda761320929f714951c328bfec6a51a1978db97Wink Saville Integer.toHexString(msg.what)); 356bda761320929f714951c328bfec6a51a1978db97Wink Saville } 357bda761320929f714951c328bfec6a51a1978db97Wink Saville retVal = NOT_HANDLED; 358bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 359bda761320929f714951c328bfec6a51a1978db97Wink Saville } 360bda761320929f714951c328bfec6a51a1978db97Wink Saville return retVal; 361bda761320929f714951c328bfec6a51a1978db97Wink Saville } 362bda761320929f714951c328bfec6a51a1978db97Wink Saville } 363bda761320929f714951c328bfec6a51a1978db97Wink Saville 364bda761320929f714951c328bfec6a51a1978db97Wink Saville private class DetachingState extends State { 365689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt private int mCurrentDisallowedSequence = 0; 366689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt 367bda761320929f714951c328bfec6a51a1978db97Wink Saville @Override 368bda761320929f714951c328bfec6a51a1978db97Wink Saville public void enter() { 369bda761320929f714951c328bfec6a51a1978db97Wink Saville if (DBG) log("DetachingState: enter"); 370bda761320929f714951c328bfec6a51a1978db97Wink Saville PhoneBase pb = (PhoneBase)((PhoneProxy)mPhone).getActivePhone(); 371689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt pb.mCi.setDataAllowed(false, obtainMessage(EVENT_DATA_DISALLOWED, 372689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt ++mCurrentDisallowedSequence, 0)); 373bda761320929f714951c328bfec6a51a1978db97Wink Saville } 374bda761320929f714951c328bfec6a51a1978db97Wink Saville 375bda761320929f714951c328bfec6a51a1978db97Wink Saville @Override 376bda761320929f714951c328bfec6a51a1978db97Wink Saville public boolean processMessage(Message msg) { 377bda761320929f714951c328bfec6a51a1978db97Wink Saville boolean retVal; 378bda761320929f714951c328bfec6a51a1978db97Wink Saville 379bda761320929f714951c328bfec6a51a1978db97Wink Saville switch (msg.what) { 380a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt case DcSwitchAsyncChannel.REQ_CONNECT: { 381a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt RequestInfo apnRequest = (RequestInfo)msg.obj; 3822dde8b1659b1eb231e667bc19307ef294b627bebRobert Greenwalt apnRequest.log("DcSwitchStateMachine.DetachingState: REQ_CONNECT"); 383a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt if (DBG) log("DetachingState: REQ_CONNECT, apnRequest=" + apnRequest); 384a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt 385a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt // can't process this now - wait until we return to idle 386a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt deferMessage(msg); 387a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt retVal = HANDLED; 388a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt break; 389a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt } 390a5ea9112a448ee8a51df1a2317457ae560a191f2Robert Greenwalt 391bda761320929f714951c328bfec6a51a1978db97Wink Saville case DcSwitchAsyncChannel.EVENT_DATA_DETACHED: { 392bda761320929f714951c328bfec6a51a1978db97Wink Saville if (DBG) { 393bda761320929f714951c328bfec6a51a1978db97Wink Saville log("DetachingState: EVENT_DATA_DETACHED"); 394bda761320929f714951c328bfec6a51a1978db97Wink Saville } 395bda761320929f714951c328bfec6a51a1978db97Wink Saville transitionTo(mIdleState); 396bda761320929f714951c328bfec6a51a1978db97Wink Saville retVal = HANDLED; 397bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 398bda761320929f714951c328bfec6a51a1978db97Wink Saville } 399689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt case EVENT_DATA_DISALLOWED: { 400689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt AsyncResult ar = (AsyncResult)msg.obj; 401689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt if (mCurrentDisallowedSequence != msg.arg1) { 402689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt loge("EVENT_DATA_DISALLOWED ignored arg1=" + msg.arg1 + ", seq=" + 403689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt mCurrentDisallowedSequence); 404689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt } else if (ar.exception != null) { 405689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt // go back to attached as we still think we are. Notifications 406689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt // from the ServiceStateTracker will kick us out of attached when 407689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt // appropriate. 408689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt loge("EVENT_DATA_DISALLOWED failed, " + ar.exception); 409689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt transitionTo(mAttachedState); 410689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt } 411689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt retVal = HANDLED; 412689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt break; 413689e05fa14800639cf3d7997fc855bb158656efdRobert Greenwalt } 414bda761320929f714951c328bfec6a51a1978db97Wink Saville case DcSwitchAsyncChannel.REQ_DISCONNECT_ALL: { 415bda761320929f714951c328bfec6a51a1978db97Wink Saville if (DBG) { 416bda761320929f714951c328bfec6a51a1978db97Wink Saville log("DetachingState: REQ_DISCONNECT_ALL, already detaching" ); 417bda761320929f714951c328bfec6a51a1978db97Wink Saville } 418bda761320929f714951c328bfec6a51a1978db97Wink Saville retVal = HANDLED; 419bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 420bda761320929f714951c328bfec6a51a1978db97Wink Saville } 421bda761320929f714951c328bfec6a51a1978db97Wink Saville 422bda761320929f714951c328bfec6a51a1978db97Wink Saville default: 423bda761320929f714951c328bfec6a51a1978db97Wink Saville if (VDBG) { 424bda761320929f714951c328bfec6a51a1978db97Wink Saville log("DetachingState: nothandled msg.what=0x" + 425bda761320929f714951c328bfec6a51a1978db97Wink Saville Integer.toHexString(msg.what)); 426bda761320929f714951c328bfec6a51a1978db97Wink Saville } 427bda761320929f714951c328bfec6a51a1978db97Wink Saville retVal = NOT_HANDLED; 428bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 429bda761320929f714951c328bfec6a51a1978db97Wink Saville } 430bda761320929f714951c328bfec6a51a1978db97Wink Saville return retVal; 431bda761320929f714951c328bfec6a51a1978db97Wink Saville } 432bda761320929f714951c328bfec6a51a1978db97Wink Saville } 433bda761320929f714951c328bfec6a51a1978db97Wink Saville 434bda761320929f714951c328bfec6a51a1978db97Wink Saville private class DefaultState extends State { 435bda761320929f714951c328bfec6a51a1978db97Wink Saville @Override 436bda761320929f714951c328bfec6a51a1978db97Wink Saville public boolean processMessage(Message msg) { 437bda761320929f714951c328bfec6a51a1978db97Wink Saville switch (msg.what) { 438bda761320929f714951c328bfec6a51a1978db97Wink Saville case AsyncChannel.CMD_CHANNEL_FULL_CONNECTION: { 439bda761320929f714951c328bfec6a51a1978db97Wink Saville if (mAc != null) { 440bda761320929f714951c328bfec6a51a1978db97Wink Saville if (VDBG) log("Disconnecting to previous connection mAc=" + mAc); 441bda761320929f714951c328bfec6a51a1978db97Wink Saville mAc.replyToMessage(msg, AsyncChannel.CMD_CHANNEL_FULLY_CONNECTED, 442bda761320929f714951c328bfec6a51a1978db97Wink Saville AsyncChannel.STATUS_FULL_CONNECTION_REFUSED_ALREADY_CONNECTED); 443bda761320929f714951c328bfec6a51a1978db97Wink Saville } else { 444bda761320929f714951c328bfec6a51a1978db97Wink Saville mAc = new AsyncChannel(); 445bda761320929f714951c328bfec6a51a1978db97Wink Saville mAc.connected(null, getHandler(), msg.replyTo); 446bda761320929f714951c328bfec6a51a1978db97Wink Saville if (VDBG) log("DcDefaultState: FULL_CONNECTION reply connected"); 447bda761320929f714951c328bfec6a51a1978db97Wink Saville mAc.replyToMessage(msg, AsyncChannel.CMD_CHANNEL_FULLY_CONNECTED, 448bda761320929f714951c328bfec6a51a1978db97Wink Saville AsyncChannel.STATUS_SUCCESSFUL, mId, "hi"); 449bda761320929f714951c328bfec6a51a1978db97Wink Saville } 450bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 451bda761320929f714951c328bfec6a51a1978db97Wink Saville } 452bda761320929f714951c328bfec6a51a1978db97Wink Saville case AsyncChannel.CMD_CHANNEL_DISCONNECT: { 453bda761320929f714951c328bfec6a51a1978db97Wink Saville if (VDBG) log("CMD_CHANNEL_DISCONNECT"); 454bda761320929f714951c328bfec6a51a1978db97Wink Saville mAc.disconnect(); 455bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 456bda761320929f714951c328bfec6a51a1978db97Wink Saville } 457bda761320929f714951c328bfec6a51a1978db97Wink Saville case AsyncChannel.CMD_CHANNEL_DISCONNECTED: { 458bda761320929f714951c328bfec6a51a1978db97Wink Saville if (VDBG) log("CMD_CHANNEL_DISCONNECTED"); 459bda761320929f714951c328bfec6a51a1978db97Wink Saville mAc = null; 460bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 461bda761320929f714951c328bfec6a51a1978db97Wink Saville } 462bda761320929f714951c328bfec6a51a1978db97Wink Saville case DcSwitchAsyncChannel.REQ_IS_IDLE_STATE: { 463bda761320929f714951c328bfec6a51a1978db97Wink Saville boolean val = getCurrentState() == mIdleState; 464bda761320929f714951c328bfec6a51a1978db97Wink Saville if (VDBG) log("REQ_IS_IDLE_STATE isIdle=" + val); 465bda761320929f714951c328bfec6a51a1978db97Wink Saville mAc.replyToMessage(msg, DcSwitchAsyncChannel.RSP_IS_IDLE_STATE, val ? 1 : 0); 466bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 467bda761320929f714951c328bfec6a51a1978db97Wink Saville } 468bda761320929f714951c328bfec6a51a1978db97Wink Saville case DcSwitchAsyncChannel.REQ_IS_IDLE_OR_DETACHING_STATE: { 469bda761320929f714951c328bfec6a51a1978db97Wink Saville boolean val = (getCurrentState() == mIdleState || 470bda761320929f714951c328bfec6a51a1978db97Wink Saville getCurrentState() == mDetachingState); 471bda761320929f714951c328bfec6a51a1978db97Wink Saville if (VDBG) log("REQ_IS_IDLE_OR_DETACHING_STATE isIdleDetaching=" + val); 472bda761320929f714951c328bfec6a51a1978db97Wink Saville mAc.replyToMessage(msg, 473bda761320929f714951c328bfec6a51a1978db97Wink Saville DcSwitchAsyncChannel.RSP_IS_IDLE_OR_DETACHING_STATE, val ? 1 : 0); 474bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 475bda761320929f714951c328bfec6a51a1978db97Wink Saville } 476f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan case DcSwitchAsyncChannel.EVENT_EMERGENCY_CALL_STARTED: { 477f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan mPreEmergencyState = getCurrentState(); 478f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan transitionTo(mEmergencyState); 479f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan break; 480f3cb9192272e4ddd68970352e998690f6c80e393Amit Mahajan } 481bda761320929f714951c328bfec6a51a1978db97Wink Saville default: 482bda761320929f714951c328bfec6a51a1978db97Wink Saville if (DBG) { 483bda761320929f714951c328bfec6a51a1978db97Wink Saville log("DefaultState: shouldn't happen but ignore msg.what=0x" + 484bda761320929f714951c328bfec6a51a1978db97Wink Saville Integer.toHexString(msg.what)); 485bda761320929f714951c328bfec6a51a1978db97Wink Saville } 486bda761320929f714951c328bfec6a51a1978db97Wink Saville break; 487bda761320929f714951c328bfec6a51a1978db97Wink Saville } 488bda761320929f714951c328bfec6a51a1978db97Wink Saville return HANDLED; 489bda761320929f714951c328bfec6a51a1978db97Wink Saville } 490bda761320929f714951c328bfec6a51a1978db97Wink Saville } 491bda761320929f714951c328bfec6a51a1978db97Wink Saville 492bda761320929f714951c328bfec6a51a1978db97Wink Saville @Override 493bda761320929f714951c328bfec6a51a1978db97Wink Saville protected void log(String s) { 494bda761320929f714951c328bfec6a51a1978db97Wink Saville Rlog.d(LOG_TAG, "[" + getName() + "] " + s); 495bda761320929f714951c328bfec6a51a1978db97Wink Saville } 496bda761320929f714951c328bfec6a51a1978db97Wink Saville} 497