stateMachine状态转换流程
/packages/apps/Bluetooth/src/com/android/bluetooth/pbapclient/PbapClientStateMachine.java
351 public void disconnect(BluetoothDevice device) {
352 Log.d(TAG, "Disconnect Request " + device);
353 sendMessage(MSG_DISCONNECT, device);
354 }
/frameworks/base/core/java/com/android/internal/util/StateMachine.java
1713 /**
1714 * Enqueue a message to this state machine.
1715 *
1716 * Message is ignored if state machine has quit.
1717 */
1718 public void sendMessage(int what, Object obj) {
1719 // mSmHandler can be null if the state machine has quit.
1720 SmHandler smh = mSmHandler;
1721 if (smh == null) return;
1722
1723 smh.sendMessage(obtainMessage(what, obj)); // private static class SmHandler extends Handler
1724 }
/frameworks/base/core/java/android/os/Handler.java
593 /**
594 * Pushes a message onto the end of the message queue after all pending messages
595 * before the current time. It will be received in {@link #handleMessage},
596 * in the thread attached to this handler.
597 *
598 * @return Returns true if the message was successfully placed in to the
599 * message queue. Returns false on failure, usually because the
600 * looper processing the message queue is exiting.
601 */
602 public final boolean sendMessage(Message msg)
603 {
604 return sendMessageDelayed(msg, 0);
605 }
/frameworks/base/core/java/com/android/internal/util/StateMachine.java
787 /**
788 * Handle messages sent to the state machine by calling
789 * the current state's processMessage. It also handles
790 * the enter/exit calls and placing any deferred messages
791 * back onto the queue when transitioning to a new state.
792 */
793 @Override
794 public final void handleMessage(Message msg) {
795 if (!mHasQuit) {
796 if (mSm != null && msg.what != SM_INIT_CMD && msg.what != SM_QUIT_CMD) {
797 mSm.onPreHandleMessage(msg);
798 }
799
800 if (mDbg) mSm.log("handleMessage: E msg.what=" + msg.what);
801
802 /** Save the current message */
803 mMsg = msg;
804
805 /** State that processed the message */
806 State msgProcessedState = null;
807 if (mIsConstructionCompleted || (mMsg.what == SM_QUIT_CMD)) {
808