/**
     * Process the message. If the current state doesn't handle it, call the states parent and so
     * on. If it is never handled then call the state machines unhandledMessage method.
     */
    private final void processMsg(Message msg) {
      StateInfo curStateInfo = mStateStack[mStateStackTopIndex];
      if (mDbg) {
        Log.d(TAG, "processMsg: " + curStateInfo.state.getName());
      }
      while (!curStateInfo.state.processMessage(msg)) {
        /** Not processed */
        curStateInfo = curStateInfo.parentStateInfo;
        if (curStateInfo == null) {
          /** No parents left so it's not handled */
          mSm.unhandledMessage(msg);
          if (isQuit(msg)) {
            transitionTo(mQuittingState);
          }
          break;
        }
        if (mDbg) {
          Log.d(TAG, "processMsg: " + curStateInfo.state.getName());
        }
      }

      /** Record that we processed the message */
      if (curStateInfo != null) {
        State orgState = mStateStack[mStateStackTopIndex].state;
        mProcessedMessages.add(msg, curStateInfo.state, orgState);
      } else {
        mProcessedMessages.add(msg, null, null);
      }
    }
    /** Cleanup all the static variables and the looper after the SM has been quit. */
    private final void cleanupAfterQuitting() {
      mSm.quitting();
      if (mSm.mSmThread != null) {
        // If we made the thread then quit looper which stops the thread.
        getLooper().quit();
        mSm.mSmThread = null;
      }

      mSm.mSmHandler = null;
      mSm = null;
      mMsg = null;
      mProcessedMessages.cleanup();
      mStateStack = null;
      mTempStateStack = null;
      mStateInfo.clear();
      mInitialState = null;
      mDestState = null;
      mDeferredMessages.clear();
    }
 /** @see StateMachine#getProcessedMessageInfo(int) */
 private final ProcessedMessageInfo getProcessedMessageInfo(int index) {
   return mProcessedMessages.get(index);
 }
 /** @see StateMachine#getProcessedMessagesCount() */
 private final int getProcessedMessagesCount() {
   return mProcessedMessages.count();
 }
 /** @see StateMachine#getProcessedMessagesSize() */
 private final int getProcessedMessagesSize() {
   return mProcessedMessages.size();
 }
 /** @see StateMachine#setProcessedMessagesSize(int) */
 private final void setProcessedMessagesSize(int maxSize) {
   mProcessedMessages.setSize(maxSize);
 }