Android中的设计模式(5)

其中DcDefaultState是所有状态的父状态,

状态含义
DcInactiveState   非活动状态  
DcActivatingState   激活状态  
DcActiveState   活动状态  
DcDisconnectingState   去激活状态  
DcDisconnectionErrorCreatingConnection   创建连接时出错状态  
状态转换图

这里写图片描述

初始化 protected DataConnection(PhoneBase phone, String name, int id, RetryManager rm, DataConnectionTracker dct) { ...... addState(mDefaultState); addState(mInactiveState, mDefaultState); addState(mActivatingState, mDefaultState); addState(mActiveState, mDefaultState); addState(mDisconnectingState, mDefaultState); addState(mDisconnectingErrorCreatingConnection, mDefaultState); setInitialState(mInactiveState); ....

最开始处在DcInactiveState状态,当DataConnectionTracker调用DataConnection的bringUp方法时

public void bringUp(Message onCompletedMsg, ApnSetting apn) { sendMessage(obtainMessage(EVENT_CONNECT, new ConnectionParams(apn, onCompletedMsg))); }

会发送EVENT_CONNECT消息,这就会调用到当前状态DcInactiveState的processMessage方法。

public boolean processMessage(Message msg) { boolean retVal; switch (msg.what) { case EVENT_CONNECT: ConnectionParams cp = (ConnectionParams) msg.obj; cp.tag = mTag; if (DBG) { log("DcInactiveState msg.what=EVENT_CONNECT." + "RefCount = " + mRefCount); } mRefCount = 1; onConnect(cp); //调用phone.mCM.setupDataCall 方法想RILJ发送RIL_REQUEST_SETUP_DATA_CALL请求。 transitionTo(mActivatingState);//切换到mActivatingState状态。 retVal = HANDLED; break;

其他状态的切换的处理根据需求和兴趣自行阅读即可。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/21cf657be5adb10b5c3e5a3111333ab9.html