diff options
| author | Wink Saville <wink@google.com> | 2010-03-18 17:03:30 -0700 |
|---|---|---|
| committer | Wink Saville <wink@google.com> | 2010-03-18 17:03:30 -0700 |
| commit | e7be6a85da5be32348f4e83ede195477a7ec1790 (patch) | |
| tree | aaf688ed0bd13e2b5a84f3741bf40a530374e0e6 /core/java | |
| parent | b50ebe3a15cc19d5729964db1978d50b94de71ca (diff) | |
Allow transitionTo in enter/exit.
bug: 2435366
Change-Id: Id15c5e2cca49ced5ebbda24887f8c490e717f101
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/com/android/internal/util/HierarchicalState.java | 9 | ||||
| -rw-r--r-- | core/java/com/android/internal/util/HierarchicalStateMachine.java | 58 |
2 files changed, 48 insertions, 19 deletions
diff --git a/core/java/com/android/internal/util/HierarchicalState.java b/core/java/com/android/internal/util/HierarchicalState.java index 002338adfe94..b37f46c1fe43 100644 --- a/core/java/com/android/internal/util/HierarchicalState.java +++ b/core/java/com/android/internal/util/HierarchicalState.java @@ -21,10 +21,9 @@ import android.os.Message; /** * {@hide} * - * The abstract class for implementing states in a - * HierarchicalStateMachine and HandlerStateMachine. + * The class for implementing states in a HierarchicalStateMachine */ -public abstract class HierarchicalState { +public class HierarchicalState { /** * Constructor @@ -54,7 +53,9 @@ public abstract class HierarchicalState { * if the parent state's processMessage should * be invoked. */ - abstract protected boolean processMessage(Message msg); + protected boolean processMessage(Message msg) { + return false; + } /** * Called when a state is exited. diff --git a/core/java/com/android/internal/util/HierarchicalStateMachine.java b/core/java/com/android/internal/util/HierarchicalStateMachine.java index 7d7f1308ba32..9911f486d5ac 100644 --- a/core/java/com/android/internal/util/HierarchicalStateMachine.java +++ b/core/java/com/android/internal/util/HierarchicalStateMachine.java @@ -574,23 +574,41 @@ public class HierarchicalStateMachine { } /** - * Process the message abiding by the hierarchical semantics. + * Process the message abiding by the hierarchical semantics + * and perform any requested transitions. */ processMsg(msg); + performTransitions(); + if (mDbg) Log.d(TAG, "handleMessage: X"); + } + + /** + * Do any transitions + */ + private void performTransitions() { /** * If transitionTo has been called, exit and then enter - * the appropriate states. + * the appropriate states. We loop on this to allow + * enter and exit methods to use transitionTo. */ - if (mDestState != null) { + HierarchicalState destState = null; + while (mDestState != null) { if (mDbg) Log.d(TAG, "handleMessage: new destination call exit"); /** + * Save mDestState locally and set to null + * to know if enter/exit use transitionTo. + */ + destState = mDestState; + mDestState = null; + + /** * Determine the states to exit and enter and return the * common ancestor state of the enter/exit states. Then * invoke the exit methods then the enter methods. */ - StateInfo commonStateInfo = setupTempStateStackWithStatesToEnter(mDestState); + StateInfo commonStateInfo = setupTempStateStackWithStatesToEnter(destState); invokeExitMethods(commonStateInfo); int stateStackEnteringIndex = moveTempStateStackToStateStack(); invokeEnterMethods(stateStackEnteringIndex); @@ -603,25 +621,31 @@ public class HierarchicalStateMachine { * message queue. */ moveDeferredMessageAtFrontOfQueue(); + } - /** - * Call halting() if we've transitioned to the halting - * state. All subsequent messages will be processed in - * in the halting state which invokes haltedProcessMessage(msg); - */ - if (mDestState == mQuittingState) { + /** + * After processing all transitions check and + * see if the last transition was to quit or halt. + */ + if (destState != null) { + if (destState == mQuittingState) { + /** + * We are quitting so ignore all messages. + */ mHsm.quitting(); if (mHsm.mHsmThread != null) { // If we made the thread then quit looper getLooper().quit(); } - } else if (mDestState == mHaltingState) { + } else if (destState == mHaltingState) { + /** + * Call halting() if we've transitioned to the halting + * state. All subsequent messages will be processed in + * in the halting state which invokes haltedProcessMessage(msg); + */ mHsm.halting(); } - mDestState = null; } - - if (mDbg) Log.d(TAG, "handleMessage: X"); } /** @@ -657,6 +681,11 @@ public class HierarchicalStateMachine { mIsConstructionCompleted = true; invokeEnterMethods(0); + /** + * Perform any transitions requested by the enter methods + */ + performTransitions(); + if (mDbg) Log.d(TAG, "completeConstruction: X"); } @@ -1167,7 +1196,6 @@ public class HierarchicalStateMachine { return Message.obtain(mHsmHandler, what, obj); } - /** * Enqueue a message to this state machine. */ |
