am 64c42cae: Rename HierarchicalStateMachine and HierarchicalState to StateMachine and State.
* commit '64c42cae4482fe0157e977b8ddd0f2c2436b3f31':
Rename HierarchicalStateMachine and HierarchicalState to StateMachine and State.
diff --git a/core/java/android/bluetooth/BluetoothDeviceProfileState.java b/core/java/android/bluetooth/BluetoothDeviceProfileState.java
index f4693c2..56f236d 100644
--- a/core/java/android/bluetooth/BluetoothDeviceProfileState.java
+++ b/core/java/android/bluetooth/BluetoothDeviceProfileState.java
@@ -26,8 +26,8 @@
import android.server.BluetoothService;
import android.util.Log;
-import com.android.internal.util.HierarchicalState;
-import com.android.internal.util.HierarchicalStateMachine;
+import com.android.internal.util.State;
+import com.android.internal.util.StateMachine;
import java.util.Set;
@@ -57,7 +57,7 @@
* Todo(): Write tests for this class, when the Android Mock support is completed.
* @hide
*/
-public final class BluetoothDeviceProfileState extends HierarchicalStateMachine {
+public final class BluetoothDeviceProfileState extends StateMachine {
private static final String TAG = "BluetoothDeviceProfileState";
private static final boolean DBG = false;
@@ -235,16 +235,16 @@
}
}
- private class BondedDevice extends HierarchicalState {
+ private class BondedDevice extends State {
@Override
- protected void enter() {
+ public void enter() {
Log.i(TAG, "Entering ACL Connected state with: " + getCurrentMessage().what);
Message m = new Message();
m.copyFrom(getCurrentMessage());
sendMessageAtFrontOfQueue(m);
}
@Override
- protected boolean processMessage(Message message) {
+ public boolean processMessage(Message message) {
log("ACL Connected State -> Processing Message: " + message.what);
switch(message.what) {
case CONNECT_HFP_OUTGOING:
@@ -353,12 +353,12 @@
}
}
- private class OutgoingHandsfree extends HierarchicalState {
+ private class OutgoingHandsfree extends State {
private boolean mStatus = false;
private int mCommand;
@Override
- protected void enter() {
+ public void enter() {
Log.i(TAG, "Entering OutgoingHandsfree state with: " + getCurrentMessage().what);
mCommand = getCurrentMessage().what;
if (mCommand != CONNECT_HFP_OUTGOING &&
@@ -374,7 +374,7 @@
}
@Override
- protected boolean processMessage(Message message) {
+ public boolean processMessage(Message message) {
log("OutgoingHandsfree State -> Processing Message: " + message.what);
Message deferMsg = new Message();
int command = message.what;
@@ -466,12 +466,12 @@
}
}
- private class IncomingHandsfree extends HierarchicalState {
+ private class IncomingHandsfree extends State {
private boolean mStatus = false;
private int mCommand;
@Override
- protected void enter() {
+ public void enter() {
Log.i(TAG, "Entering IncomingHandsfree state with: " + getCurrentMessage().what);
mCommand = getCurrentMessage().what;
if (mCommand != CONNECT_HFP_INCOMING &&
@@ -487,7 +487,7 @@
}
@Override
- protected boolean processMessage(Message message) {
+ public boolean processMessage(Message message) {
log("IncomingHandsfree State -> Processing Message: " + message.what);
switch(message.what) {
case CONNECT_HFP_OUTGOING:
@@ -546,12 +546,12 @@
}
}
- private class OutgoingA2dp extends HierarchicalState {
+ private class OutgoingA2dp extends State {
private boolean mStatus = false;
private int mCommand;
@Override
- protected void enter() {
+ public void enter() {
Log.i(TAG, "Entering OutgoingA2dp state with: " + getCurrentMessage().what);
mCommand = getCurrentMessage().what;
if (mCommand != CONNECT_A2DP_OUTGOING &&
@@ -567,7 +567,7 @@
}
@Override
- protected boolean processMessage(Message message) {
+ public boolean processMessage(Message message) {
log("OutgoingA2dp State->Processing Message: " + message.what);
Message deferMsg = new Message();
switch(message.what) {
@@ -656,12 +656,12 @@
}
}
- private class IncomingA2dp extends HierarchicalState {
+ private class IncomingA2dp extends State {
private boolean mStatus = false;
private int mCommand;
@Override
- protected void enter() {
+ public void enter() {
Log.i(TAG, "Entering IncomingA2dp state with: " + getCurrentMessage().what);
mCommand = getCurrentMessage().what;
if (mCommand != CONNECT_A2DP_INCOMING &&
@@ -677,7 +677,7 @@
}
@Override
- protected boolean processMessage(Message message) {
+ public boolean processMessage(Message message) {
log("IncomingA2dp State->Processing Message: " + message.what);
switch(message.what) {
case CONNECT_HFP_OUTGOING:
@@ -734,12 +734,12 @@
}
- private class OutgoingHid extends HierarchicalState {
+ private class OutgoingHid extends State {
private boolean mStatus = false;
private int mCommand;
@Override
- protected void enter() {
+ public void enter() {
log("Entering OutgoingHid state with: " + getCurrentMessage().what);
mCommand = getCurrentMessage().what;
if (mCommand != CONNECT_HID_OUTGOING &&
@@ -751,7 +751,7 @@
}
@Override
- protected boolean processMessage(Message message) {
+ public boolean processMessage(Message message) {
log("OutgoingHid State->Processing Message: " + message.what);
Message deferMsg = new Message();
switch(message.what) {
@@ -815,12 +815,12 @@
}
}
- private class IncomingHid extends HierarchicalState {
+ private class IncomingHid extends State {
private boolean mStatus = false;
private int mCommand;
@Override
- protected void enter() {
+ public void enter() {
log("Entering IncomingHid state with: " + getCurrentMessage().what);
mCommand = getCurrentMessage().what;
if (mCommand != CONNECT_HID_INCOMING &&
@@ -832,7 +832,7 @@
}
@Override
- protected boolean processMessage(Message message) {
+ public boolean processMessage(Message message) {
log("IncomingHid State->Processing Message: " + message.what);
Message deferMsg = new Message();
switch(message.what) {
diff --git a/core/java/android/bluetooth/BluetoothProfileState.java b/core/java/android/bluetooth/BluetoothProfileState.java
index 18060a0..98afdb8 100644
--- a/core/java/android/bluetooth/BluetoothProfileState.java
+++ b/core/java/android/bluetooth/BluetoothProfileState.java
@@ -22,8 +22,8 @@
import android.os.Message;
import android.util.Log;
-import com.android.internal.util.HierarchicalState;
-import com.android.internal.util.HierarchicalStateMachine;
+import com.android.internal.util.State;
+import com.android.internal.util.StateMachine;
/**
* This state machine is used to serialize the connections
@@ -39,7 +39,7 @@
* @hide
*/
-public class BluetoothProfileState extends HierarchicalStateMachine {
+public class BluetoothProfileState extends StateMachine {
private static final boolean DBG = true;
private static final String TAG = "BluetoothProfileState";
@@ -101,15 +101,15 @@
context.registerReceiver(mBroadcastReceiver, filter);
}
- private class StableState extends HierarchicalState {
+ private class StableState extends State {
@Override
- protected void enter() {
+ public void enter() {
log("Entering Stable State");
mPendingDevice = null;
}
@Override
- protected boolean processMessage(Message msg) {
+ public boolean processMessage(Message msg) {
if (msg.what != TRANSITION_TO_STABLE) {
transitionTo(mPendingCommandState);
}
@@ -117,15 +117,15 @@
}
}
- private class PendingCommandState extends HierarchicalState {
+ private class PendingCommandState extends State {
@Override
- protected void enter() {
+ public void enter() {
log("Entering PendingCommandState State");
dispatchMessage(getCurrentMessage());
}
@Override
- protected boolean processMessage(Message msg) {
+ public boolean processMessage(Message msg) {
if (msg.what == TRANSITION_TO_STABLE) {
transitionTo(mStableState);
} else {
diff --git a/core/java/com/android/internal/util/HierarchicalState.java b/core/java/com/android/internal/util/IState.java
similarity index 61%
rename from core/java/com/android/internal/util/HierarchicalState.java
rename to core/java/com/android/internal/util/IState.java
index b37f46c..056f8e9 100644
--- a/core/java/com/android/internal/util/HierarchicalState.java
+++ b/core/java/com/android/internal/util/IState.java
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,21 +21,29 @@
/**
* {@hide}
*
- * The class for implementing states in a HierarchicalStateMachine
+ * The interface for implementing states in a {@link StateMachine}
*/
-public class HierarchicalState {
+public interface IState {
/**
- * Constructor
+ * Returned by processMessage to indicate the the message was processed.
*/
- protected HierarchicalState() {
- }
+ static final boolean HANDLED = true;
+
+ /**
+ * Returned by processMessage to indicate the the message was NOT processed.
+ */
+ static final boolean NOT_HANDLED = false;
/**
* Called when a state is entered.
*/
- protected void enter() {
- }
+ void enter();
+
+ /**
+ * Called when a state is exited.
+ */
+ void exit();
/**
* Called when a message is to be processed by the
@@ -49,28 +57,15 @@
* be processed until this routine returns.
*
* @param msg to process
- * @return true if processing has completed and false
- * if the parent state's processMessage should
- * be invoked.
+ * @return HANDLED if processing has completed and NOT_HANDLED
+ * if the message wasn't processed.
*/
- protected boolean processMessage(Message msg) {
- return false;
- }
+ boolean processMessage(Message msg);
/**
- * Called when a state is exited.
+ * Name of State for debugging purposes.
+ *
+ * @return name of state.
*/
- protected void exit() {
- }
-
- /**
- * @return name of state, but default returns the states
- * class name. An instance name would be better but requiring
- * it seems unnecessary.
- */
- public String getName() {
- String name = getClass().getName();
- int lastDollar = name.lastIndexOf('$');
- return name.substring(lastDollar + 1);
- }
+ String getName();
}
diff --git a/core/java/com/android/internal/util/State.java b/core/java/com/android/internal/util/State.java
new file mode 100644
index 0000000..3eadff5
--- /dev/null
+++ b/core/java/com/android/internal/util/State.java
@@ -0,0 +1,74 @@
+/**
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.util;
+
+import android.os.Message;
+
+/**
+ * {@hide}
+ *
+ * The class for implementing states in a StateMachine
+ */
+public class State implements IState {
+
+ /**
+ * Constructor
+ */
+ protected State() {
+ }
+
+ /* (non-Javadoc)
+ * @see com.android.internal.util.IState#enter()
+ */
+ @Override
+ public void enter() {
+ }
+
+ /* (non-Javadoc)
+ * @see com.android.internal.util.IState#exit()
+ */
+ @Override
+ public void exit() {
+ }
+
+ /* (non-Javadoc)
+ * @see com.android.internal.util.IState#processMessage(android.os.Message)
+ */
+ @Override
+ public boolean processMessage(Message msg) {
+ return false;
+ }
+
+ /**
+ * Name of State for debugging purposes.
+ *
+ * This default implementation returns the class name, returning
+ * the instance name would better in cases where a State class
+ * is used for multiple states. But normally there is one class per
+ * state and the class name is sufficient and easy to get. You may
+ * want to provide a setName or some other mechanism for setting
+ * another name if the class name is not appropriate.
+ *
+ * @see com.android.internal.util.IState#processMessage(android.os.Message)
+ */
+ @Override
+ public String getName() {
+ String name = getClass().getName();
+ int lastDollar = name.lastIndexOf('$');
+ return name.substring(lastDollar + 1);
+ }
+}
diff --git a/core/java/com/android/internal/util/HierarchicalStateMachine.java b/core/java/com/android/internal/util/StateMachine.java
similarity index 85%
rename from core/java/com/android/internal/util/HierarchicalStateMachine.java
rename to core/java/com/android/internal/util/StateMachine.java
index f6aa184..cbe72dd 100644
--- a/core/java/com/android/internal/util/HierarchicalStateMachine.java
+++ b/core/java/com/android/internal/util/StateMachine.java
@@ -29,10 +29,10 @@
/**
* {@hide}
*
- * <p>A hierarchical state machine is a state machine which processes messages
+ * <p>The state machine defined here is a hierarchical state machine which processes messages
* and can have states arranged hierarchically.</p>
*
- * <p>A state is a <code>HierarchicalState</code> object and must implement
+ * <p>A state is a <code>State</code> object and must implement
* <code>processMessage</code> and optionally <code>enter/exit/getName</code>.
* The enter/exit methods are equivalent to the construction and destruction
* in Object Oriented programming and are used to perform initialization and
@@ -76,7 +76,7 @@
* will exit the current state and its parent and then exit from the controlling thread
* and no further messages will be processed.</p>
*
- * <p>In addition to <code>processMessage</code> each <code>HierarchicalState</code> has
+ * <p>In addition to <code>processMessage</code> each <code>State</code> has
* an <code>enter</code> method and <code>exit</exit> method which may be overridden.</p>
*
* <p>Since the states are arranged in a hierarchy transitioning to a new state
@@ -122,11 +122,11 @@
* mS4.enter. The new list of active states is mP0, mP1, mS2 and mS4. So
* when the next message is received mS4.processMessage will be invoked.</p>
*
- * <p>Now for some concrete examples, here is the canonical HelloWorld as an HSM.
+ * <p>Now for some concrete examples, here is the canonical HelloWorld as a state machine.
* It responds with "Hello World" being printed to the log for every message.</p>
<code>
-class HelloWorld extends HierarchicalStateMachine {
- Hsm1(String name) {
+class HelloWorld extends StateMachine {
+ HelloWorld(String name) {
super(name);
addState(mState1);
setInitialState(mState1);
@@ -138,7 +138,7 @@
return hw;
}
- class State1 extends HierarchicalState {
+ class State1 extends State {
@Override public boolean processMessage(Message message) {
Log.d(TAG, "Hello World");
return HANDLED;
@@ -221,9 +221,9 @@
}
}
</code>
- * <p>The implementation is below and also in HierarchicalStateMachineTest:</p>
+ * <p>The implementation is below and also in StateMachineTest:</p>
<code>
-class Hsm1 extends HierarchicalStateMachine {
+class Hsm1 extends StateMachine {
private static final String TAG = "hsm1";
public static final int CMD_1 = 1;
@@ -255,7 +255,7 @@
Log.d(TAG, "ctor X");
}
- class P1 extends HierarchicalState {
+ class P1 extends State {
@Override public void enter() {
Log.d(TAG, "mP1.enter");
}
@@ -282,7 +282,7 @@
}
}
- class S1 extends HierarchicalState {
+ class S1 extends State {
@Override public void enter() {
Log.d(TAG, "mS1.enter");
}
@@ -302,7 +302,7 @@
}
}
- class S2 extends HierarchicalState {
+ class S2 extends State {
@Override public void enter() {
Log.d(TAG, "mS2.enter");
}
@@ -330,7 +330,7 @@
}
}
- class P2 extends HierarchicalState {
+ class P2 extends State {
@Override public void enter() {
Log.d(TAG, "mP2.enter");
sendMessage(obtainMessage(CMD_5));
@@ -409,16 +409,16 @@
D/hsm1 ( 1999): halting
</code>
*/
-public class HierarchicalStateMachine {
+public class StateMachine {
- private static final String TAG = "HierarchicalStateMachine";
+ private static final String TAG = "StateMachine";
private String mName;
/** Message.what value when quitting */
- public static final int HSM_QUIT_CMD = -1;
+ public static final int SM_QUIT_CMD = -1;
/** Message.what value when initializing */
- public static final int HSM_INIT_CMD = -1;
+ public static final int SM_INIT_CMD = -1;
/**
* Convenience constant that maybe returned by processMessage
@@ -441,8 +441,8 @@
*/
public static class ProcessedMessageInfo {
private int what;
- private HierarchicalState state;
- private HierarchicalState orgState;
+ private State state;
+ private State orgState;
/**
* Constructor
@@ -451,7 +451,7 @@
* @param orgState is the first state the received the message but
* did not processes the message.
*/
- ProcessedMessageInfo(Message message, HierarchicalState state, HierarchicalState orgState) {
+ ProcessedMessageInfo(Message message, State state, State orgState) {
update(message, state, orgState);
}
@@ -461,7 +461,7 @@
* @param orgState is the first state the received the message but
* did not processes the message.
*/
- public void update(Message message, HierarchicalState state, HierarchicalState orgState) {
+ public void update(Message message, State state, State orgState) {
this.what = message.what;
this.state = state;
this.orgState = orgState;
@@ -477,14 +477,14 @@
/**
* @return the state that handled this message
*/
- public HierarchicalState getState() {
+ public State getState() {
return state;
}
/**
* @return the original state that received the message.
*/
- public HierarchicalState getOriginalState() {
+ public State getOriginalState() {
return orgState;
}
@@ -593,7 +593,7 @@
* @param orgState is the first state the received the message but
* did not processes the message.
*/
- void add(Message message, HierarchicalState state, HierarchicalState orgState) {
+ void add(Message message, State state, State orgState) {
mCount += 1;
if (mMessages.size() < mMaxSize) {
mMessages.add(new ProcessedMessageInfo(message, state, orgState));
@@ -608,7 +608,7 @@
}
}
- private static class HsmHandler extends Handler {
+ private static class SmHandler extends Handler {
/** The debug flag */
private boolean mDbg = false;
@@ -643,8 +643,8 @@
/** State used when state machine is quitting */
private QuittingState mQuittingState = new QuittingState();
- /** Reference to the HierarchicalStateMachine */
- private HierarchicalStateMachine mHsm;
+ /** Reference to the StateMachine */
+ private StateMachine mSm;
/**
* Information about a state.
@@ -652,7 +652,7 @@
*/
private class StateInfo {
/** The state */
- HierarchicalState state;
+ State state;
/** The parent of this state, null if there is no parent */
StateInfo parentStateInfo;
@@ -672,14 +672,14 @@
}
/** The map of all of the states in the state machine */
- private HashMap<HierarchicalState, StateInfo> mStateInfo =
- new HashMap<HierarchicalState, StateInfo>();
+ private HashMap<State, StateInfo> mStateInfo =
+ new HashMap<State, StateInfo>();
/** The initial state that will process the first message */
- private HierarchicalState mInitialState;
+ private State mInitialState;
/** The destination state when transitionTo has been invoked */
- private HierarchicalState mDestState;
+ private State mDestState;
/** The list of deferred messages */
private ArrayList<Message> mDeferredMessages = new ArrayList<Message>();
@@ -687,10 +687,10 @@
/**
* State entered when transitionToHaltingState is called.
*/
- private class HaltingState extends HierarchicalState {
+ private class HaltingState extends State {
@Override
public boolean processMessage(Message msg) {
- mHsm.haltedProcessMessage(msg);
+ mSm.haltedProcessMessage(msg);
return true;
}
}
@@ -698,7 +698,7 @@
/**
* State entered when a valid quit message is handled.
*/
- private class QuittingState extends HierarchicalState {
+ private class QuittingState extends State {
@Override
public boolean processMessage(Message msg) {
return NOT_HANDLED;
@@ -745,7 +745,7 @@
* the appropriate states. We loop on this to allow
* enter and exit methods to use transitionTo.
*/
- HierarchicalState destState = null;
+ State destState = null;
while (mDestState != null) {
if (mDbg) Log.d(TAG, "handleMessage: new destination call exit");
@@ -785,11 +785,11 @@
/**
* We are quitting so ignore all messages.
*/
- mHsm.quitting();
- if (mHsm.mHsmThread != null) {
+ mSm.quitting();
+ if (mSm.mSmThread != null) {
// If we made the thread then quit looper which stops the thread.
getLooper().quit();
- mHsm.mHsmThread = null;
+ mSm.mSmThread = null;
}
} else if (destState == mHaltingState) {
/**
@@ -797,7 +797,7 @@
* state. All subsequent messages will be processed in
* in the halting state which invokes haltedProcessMessage(msg);
*/
- mHsm.halting();
+ mSm.halting();
}
}
}
@@ -833,7 +833,7 @@
* starting at the first entry.
*/
mIsConstructionCompleted = true;
- mMsg = obtainMessage(HSM_INIT_CMD);
+ mMsg = obtainMessage(SM_INIT_CMD);
invokeEnterMethods(0);
/**
@@ -863,7 +863,7 @@
/**
* No parents left so it's not handled
*/
- mHsm.unhandledMessage(msg);
+ mSm.unhandledMessage(msg);
if (isQuit(msg)) {
transitionTo(mQuittingState);
}
@@ -878,7 +878,7 @@
* Record that we processed the message
*/
if (curStateInfo != null) {
- HierarchicalState orgState = mStateStack[mStateStackTopIndex].state;
+ State orgState = mStateStack[mStateStackTopIndex].state;
mProcessedMessages.add(msg, curStateInfo.state, orgState);
} else {
mProcessedMessages.add(msg, null, null);
@@ -892,7 +892,7 @@
private final void invokeExitMethods(StateInfo commonStateInfo) {
while ((mStateStackTopIndex >= 0) &&
(mStateStack[mStateStackTopIndex] != commonStateInfo)) {
- HierarchicalState curState = mStateStack[mStateStackTopIndex].state;
+ State curState = mStateStack[mStateStackTopIndex].state;
if (mDbg) Log.d(TAG, "invokeExitMethods: " + curState.getName());
curState.exit();
mStateStack[mStateStackTopIndex].active = false;
@@ -934,7 +934,7 @@
* reversing the order of the items on the temporary stack as
* they are moved.
*
- * @return index into mStateState where entering needs to start
+ * @return index into mStateStack where entering needs to start
*/
private final int moveTempStateStackToStateStack() {
int startingIndex = mStateStackTopIndex + 1;
@@ -967,7 +967,7 @@
* @return StateInfo of the common ancestor for the destState and
* current state or null if there is no common parent.
*/
- private final StateInfo setupTempStateStackWithStatesToEnter(HierarchicalState destState) {
+ private final StateInfo setupTempStateStackWithStatesToEnter(State destState) {
/**
* Search up the parent list of the destination state for an active
* state. Use a do while() loop as the destState must always be entered
@@ -1019,7 +1019,7 @@
/**
* @return current state
*/
- private final HierarchicalState getCurrentState() {
+ private final IState getCurrentState() {
return mStateStack[mStateStackTopIndex].state;
}
@@ -1032,7 +1032,7 @@
* @param parent the parent of state
* @return stateInfo for this state
*/
- private final StateInfo addState(HierarchicalState state, HierarchicalState parent) {
+ private final StateInfo addState(State state, State parent) {
if (mDbg) {
Log.d(TAG, "addStateInternal: E state=" + state.getName()
+ ",parent=" + ((parent == null) ? "" : parent.getName()));
@@ -1067,29 +1067,29 @@
* Constructor
*
* @param looper for dispatching messages
- * @param hsm the hierarchical state machine
+ * @param sm the hierarchical state machine
*/
- private HsmHandler(Looper looper, HierarchicalStateMachine hsm) {
+ private SmHandler(Looper looper, StateMachine sm) {
super(looper);
- mHsm = hsm;
+ mSm = sm;
addState(mHaltingState, null);
addState(mQuittingState, null);
}
- /** @see HierarchicalStateMachine#setInitialState(HierarchicalState) */
- private final void setInitialState(HierarchicalState initialState) {
+ /** @see StateMachine#setInitialState(State) */
+ private final void setInitialState(State initialState) {
if (mDbg) Log.d(TAG, "setInitialState: initialState" + initialState.getName());
mInitialState = initialState;
}
- /** @see HierarchicalStateMachine#transitionTo(HierarchicalState) */
- private final void transitionTo(HierarchicalState destState) {
- if (mDbg) Log.d(TAG, "StateMachine.transitionTo EX destState" + destState.getName());
- mDestState = destState;
+ /** @see StateMachine#transitionTo(IState) */
+ private final void transitionTo(IState destState) {
+ mDestState = (State) destState;
+ if (mDbg) Log.d(TAG, "StateMachine.transitionTo EX destState" + mDestState.getName());
}
- /** @see HierarchicalStateMachine#deferMessage(Message) */
+ /** @see StateMachine#deferMessage(Message) */
private final void deferMessage(Message msg) {
if (mDbg) Log.d(TAG, "deferMessage: msg=" + msg.what);
@@ -1100,51 +1100,51 @@
mDeferredMessages.add(newMsg);
}
- /** @see HierarchicalStateMachine#deferMessage(Message) */
+ /** @see StateMachine#deferMessage(Message) */
private final void quit() {
if (mDbg) Log.d(TAG, "quit:");
- sendMessage(obtainMessage(HSM_QUIT_CMD, mQuitObj));
+ sendMessage(obtainMessage(SM_QUIT_CMD, mQuitObj));
}
- /** @see HierarchicalStateMachine#isQuit(Message) */
+ /** @see StateMachine#isQuit(Message) */
private final boolean isQuit(Message msg) {
- return (msg.what == HSM_QUIT_CMD) && (msg.obj == mQuitObj);
+ return (msg.what == SM_QUIT_CMD) && (msg.obj == mQuitObj);
}
- /** @see HierarchicalStateMachine#isDbg() */
+ /** @see StateMachine#isDbg() */
private final boolean isDbg() {
return mDbg;
}
- /** @see HierarchicalStateMachine#setDbg(boolean) */
+ /** @see StateMachine#setDbg(boolean) */
private final void setDbg(boolean dbg) {
mDbg = dbg;
}
- /** @see HierarchicalStateMachine#setProcessedMessagesSize(int) */
+ /** @see StateMachine#setProcessedMessagesSize(int) */
private final void setProcessedMessagesSize(int maxSize) {
mProcessedMessages.setSize(maxSize);
}
- /** @see HierarchicalStateMachine#getProcessedMessagesSize() */
+ /** @see StateMachine#getProcessedMessagesSize() */
private final int getProcessedMessagesSize() {
return mProcessedMessages.size();
}
- /** @see HierarchicalStateMachine#getProcessedMessagesCount() */
+ /** @see StateMachine#getProcessedMessagesCount() */
private final int getProcessedMessagesCount() {
return mProcessedMessages.count();
}
- /** @see HierarchicalStateMachine#getProcessedMessageInfo(int) */
+ /** @see StateMachine#getProcessedMessageInfo(int) */
private final ProcessedMessageInfo getProcessedMessageInfo(int index) {
return mProcessedMessages.get(index);
}
}
- private HsmHandler mHsmHandler;
- private HandlerThread mHsmThread;
+ private SmHandler mSmHandler;
+ private HandlerThread mSmThread;
/**
* Initialize.
@@ -1154,28 +1154,28 @@
*/
private void initStateMachine(String name, Looper looper) {
mName = name;
- mHsmHandler = new HsmHandler(looper, this);
+ mSmHandler = new SmHandler(looper, this);
}
/**
- * Constructor creates an HSM with its own thread.
+ * Constructor creates a StateMachine with its own thread.
*
* @param name of the state machine
*/
- protected HierarchicalStateMachine(String name) {
- mHsmThread = new HandlerThread(name);
- mHsmThread.start();
- Looper looper = mHsmThread.getLooper();
+ protected StateMachine(String name) {
+ mSmThread = new HandlerThread(name);
+ mSmThread.start();
+ Looper looper = mSmThread.getLooper();
initStateMachine(name, looper);
}
/**
- * Constructor creates an HSMStateMachine using the looper.
+ * Constructor creates an StateMachine using the looper.
*
* @param name of the state machine
*/
- protected HierarchicalStateMachine(String name, Looper looper) {
+ protected StateMachine(String name, Looper looper) {
initStateMachine(name, looper);
}
@@ -1184,30 +1184,30 @@
* @param state the state to add
* @param parent the parent of state
*/
- protected final void addState(HierarchicalState state, HierarchicalState parent) {
- mHsmHandler.addState(state, parent);
+ protected final void addState(State state, State parent) {
+ mSmHandler.addState(state, parent);
}
/**
* @return current message
*/
protected final Message getCurrentMessage() {
- return mHsmHandler.getCurrentMessage();
+ return mSmHandler.getCurrentMessage();
}
/**
* @return current state
*/
- protected final HierarchicalState getCurrentState() {
- return mHsmHandler.getCurrentState();
+ protected final IState getCurrentState() {
+ return mSmHandler.getCurrentState();
}
/**
* Add a new state to the state machine, parent will be null
* @param state to add
*/
- protected final void addState(HierarchicalState state) {
- mHsmHandler.addState(state, null);
+ protected final void addState(State state) {
+ mSmHandler.addState(state, null);
}
/**
@@ -1216,8 +1216,8 @@
*
* @param initialState is the state which will receive the first message.
*/
- protected final void setInitialState(HierarchicalState initialState) {
- mHsmHandler.setInitialState(initialState);
+ protected final void setInitialState(State initialState) {
+ mSmHandler.setInitialState(initialState);
}
/**
@@ -1228,8 +1228,8 @@
*
* @param destState will be the state that receives the next message.
*/
- protected final void transitionTo(HierarchicalState destState) {
- mHsmHandler.transitionTo(destState);
+ protected final void transitionTo(IState destState) {
+ mSmHandler.transitionTo(destState);
}
/**
@@ -1240,7 +1240,7 @@
* will be called.
*/
protected final void transitionToHaltingState() {
- mHsmHandler.transitionTo(mHsmHandler.mHaltingState);
+ mSmHandler.transitionTo(mSmHandler.mHaltingState);
}
/**
@@ -1253,7 +1253,7 @@
* @param msg is deferred until the next transition.
*/
protected final void deferMessage(Message msg) {
- mHsmHandler.deferMessage(msg);
+ mSmHandler.deferMessage(msg);
}
@@ -1263,7 +1263,7 @@
* @param msg that couldn't be handled.
*/
protected void unhandledMessage(Message msg) {
- if (mHsmHandler.mDbg) Log.e(TAG, mName + " - unhandledMessage: msg.what=" + msg.what);
+ if (mSmHandler.mDbg) Log.e(TAG, mName + " - unhandledMessage: msg.what=" + msg.what);
}
/**
@@ -1276,15 +1276,15 @@
/**
* This will be called once after handling a message that called
* transitionToHalting. All subsequent messages will invoke
- * {@link HierarchicalStateMachine#haltedProcessMessage(Message)}
+ * {@link StateMachine#haltedProcessMessage(Message)}
*/
protected void halting() {
}
/**
* This will be called once after a quit message that was NOT handled by
- * the derived HSM. The HSM will stop and any subsequent messages will be
- * ignored. In addition, if this HSM created the thread, the thread will
+ * the derived StateMachine. The StateMachine will stop and any subsequent messages will be
+ * ignored. In addition, if this StateMachine created the thread, the thread will
* be stopped after this method returns.
*/
protected void quitting() {
@@ -1303,35 +1303,35 @@
* @param maxSize number of messages to maintain at anyone time.
*/
public final void setProcessedMessagesSize(int maxSize) {
- mHsmHandler.setProcessedMessagesSize(maxSize);
+ mSmHandler.setProcessedMessagesSize(maxSize);
}
/**
* @return number of messages processed
*/
public final int getProcessedMessagesSize() {
- return mHsmHandler.getProcessedMessagesSize();
+ return mSmHandler.getProcessedMessagesSize();
}
/**
* @return the total number of messages processed
*/
public final int getProcessedMessagesCount() {
- return mHsmHandler.getProcessedMessagesCount();
+ return mSmHandler.getProcessedMessagesCount();
}
/**
* @return a processed message information
*/
public final ProcessedMessageInfo getProcessedMessageInfo(int index) {
- return mHsmHandler.getProcessedMessageInfo(index);
+ return mSmHandler.getProcessedMessageInfo(index);
}
/**
* @return Handler
*/
public final Handler getHandler() {
- return mHsmHandler;
+ return mSmHandler;
}
/**
@@ -1341,7 +1341,7 @@
*/
public final Message obtainMessage()
{
- return Message.obtain(mHsmHandler);
+ return Message.obtain(mSmHandler);
}
/**
@@ -1351,7 +1351,7 @@
* @return message
*/
public final Message obtainMessage(int what) {
- return Message.obtain(mHsmHandler, what);
+ return Message.obtain(mSmHandler, what);
}
/**
@@ -1364,7 +1364,7 @@
*/
public final Message obtainMessage(int what, Object obj)
{
- return Message.obtain(mHsmHandler, what, obj);
+ return Message.obtain(mSmHandler, what, obj);
}
/**
@@ -1378,7 +1378,7 @@
*/
public final Message obtainMessage(int what, int arg1, int arg2)
{
- return Message.obtain(mHsmHandler, what, arg1, arg2);
+ return Message.obtain(mSmHandler, what, arg1, arg2);
}
/**
@@ -1393,107 +1393,107 @@
*/
public final Message obtainMessage(int what, int arg1, int arg2, Object obj)
{
- return Message.obtain(mHsmHandler, what, arg1, arg2, obj);
+ return Message.obtain(mSmHandler, what, arg1, arg2, obj);
}
/**
* Enqueue a message to this state machine.
*/
public final void sendMessage(int what) {
- mHsmHandler.sendMessage(obtainMessage(what));
+ mSmHandler.sendMessage(obtainMessage(what));
}
/**
* Enqueue a message to this state machine.
*/
public final void sendMessage(int what, Object obj) {
- mHsmHandler.sendMessage(obtainMessage(what,obj));
+ mSmHandler.sendMessage(obtainMessage(what,obj));
}
/**
* Enqueue a message to this state machine.
*/
public final void sendMessage(Message msg) {
- mHsmHandler.sendMessage(msg);
+ mSmHandler.sendMessage(msg);
}
/**
* Enqueue a message to this state machine after a delay.
*/
public final void sendMessageDelayed(int what, long delayMillis) {
- mHsmHandler.sendMessageDelayed(obtainMessage(what), delayMillis);
+ mSmHandler.sendMessageDelayed(obtainMessage(what), delayMillis);
}
/**
* Enqueue a message to this state machine after a delay.
*/
public final void sendMessageDelayed(int what, Object obj, long delayMillis) {
- mHsmHandler.sendMessageDelayed(obtainMessage(what, obj), delayMillis);
+ mSmHandler.sendMessageDelayed(obtainMessage(what, obj), delayMillis);
}
/**
* Enqueue a message to this state machine after a delay.
*/
public final void sendMessageDelayed(Message msg, long delayMillis) {
- mHsmHandler.sendMessageDelayed(msg, delayMillis);
+ mSmHandler.sendMessageDelayed(msg, delayMillis);
}
/**
* Enqueue a message to the front of the queue for this state machine.
- * Protected, may only be called by instances of HierarchicalStateMachine.
+ * Protected, may only be called by instances of StateMachine.
*/
protected final void sendMessageAtFrontOfQueue(int what, Object obj) {
- mHsmHandler.sendMessageAtFrontOfQueue(obtainMessage(what, obj));
+ mSmHandler.sendMessageAtFrontOfQueue(obtainMessage(what, obj));
}
/**
* Enqueue a message to the front of the queue for this state machine.
- * Protected, may only be called by instances of HierarchicalStateMachine.
+ * Protected, may only be called by instances of StateMachine.
*/
protected final void sendMessageAtFrontOfQueue(int what) {
- mHsmHandler.sendMessageAtFrontOfQueue(obtainMessage(what));
+ mSmHandler.sendMessageAtFrontOfQueue(obtainMessage(what));
}
/**
* Enqueue a message to the front of the queue for this state machine.
- * Protected, may only be called by instances of HierarchicalStateMachine.
+ * Protected, may only be called by instances of StateMachine.
*/
protected final void sendMessageAtFrontOfQueue(Message msg) {
- mHsmHandler.sendMessageAtFrontOfQueue(msg);
+ mSmHandler.sendMessageAtFrontOfQueue(msg);
}
/**
* Removes a message from the message queue.
- * Protected, may only be called by instances of HierarchicalStateMachine.
+ * Protected, may only be called by instances of StateMachine.
*/
protected final void removeMessages(int what) {
- mHsmHandler.removeMessages(what);
+ mSmHandler.removeMessages(what);
}
/**
* Conditionally quit the looper and stop execution.
*
- * This sends the HSM_QUIT_MSG to the state machine and
+ * This sends the SM_QUIT_MSG to the state machine and
* if not handled by any state's processMessage then the
* state machine will be stopped and no further messages
* will be processed.
*/
public final void quit() {
- mHsmHandler.quit();
+ mSmHandler.quit();
}
/**
* @return ture if msg is quit
*/
protected final boolean isQuit(Message msg) {
- return mHsmHandler.isQuit(msg);
+ return mSmHandler.isQuit(msg);
}
/**
* @return if debugging is enabled
*/
public boolean isDbg() {
- return mHsmHandler.isDbg();
+ return mSmHandler.isDbg();
}
/**
@@ -1502,7 +1502,7 @@
* @param dbg is true to enable debugging.
*/
public void setDbg(boolean dbg) {
- mHsmHandler.setDbg(dbg);
+ mSmHandler.setDbg(dbg);
}
/**
@@ -1510,6 +1510,6 @@
*/
public void start() {
/** Send the complete construction message */
- mHsmHandler.completeConstruction();
+ mSmHandler.completeConstruction();
}
}
diff --git a/core/tests/coretests/src/com/android/internal/util/HierarchicalStateMachineTest.java b/core/tests/coretests/src/com/android/internal/util/StateMachineTest.java
similarity index 87%
rename from core/tests/coretests/src/com/android/internal/util/HierarchicalStateMachineTest.java
rename to core/tests/coretests/src/com/android/internal/util/StateMachineTest.java
index b6f8be5..ab6b2b6 100644
--- a/core/tests/coretests/src/com/android/internal/util/HierarchicalStateMachineTest.java
+++ b/core/tests/coretests/src/com/android/internal/util/StateMachineTest.java
@@ -22,9 +22,9 @@
import android.os.Message;
import android.os.SystemClock;
-import com.android.internal.util.HierarchicalState;
-import com.android.internal.util.HierarchicalStateMachine;
-import com.android.internal.util.HierarchicalStateMachine.ProcessedMessageInfo;
+import com.android.internal.util.State;
+import com.android.internal.util.StateMachine;
+import com.android.internal.util.StateMachine.ProcessedMessageInfo;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
@@ -33,9 +33,9 @@
import junit.framework.TestCase;
/**
- * Test for HierarchicalStateMachine.
+ * Test for StateMachine.
*/
-public class HierarchicalStateMachineTest extends TestCase {
+public class StateMachineTest extends TestCase {
private static final int TEST_CMD_1 = 1;
private static final int TEST_CMD_2 = 2;
private static final int TEST_CMD_3 = 3;
@@ -45,12 +45,12 @@
private static final boolean DBG = true;
private static final boolean WAIT_FOR_DEBUGGER = false;
- private static final String TAG = "HierarchicalStateMachineTest";
+ private static final String TAG = "StateMachineTest";
/**
* Tests that we can quit the state machine.
*/
- class StateMachineQuitTest extends HierarchicalStateMachine {
+ class StateMachineQuitTest extends StateMachine {
private int mQuitCount = 0;
StateMachineQuitTest(String name) {
@@ -65,8 +65,9 @@
setInitialState(mS1);
}
- class S1 extends HierarchicalState {
- @Override protected boolean processMessage(Message message) {
+ class S1 extends State {
+ @Override
+ public boolean processMessage(Message message) {
if (isQuit(message)) {
mQuitCount += 1;
if (mQuitCount > 2) {
@@ -129,18 +130,18 @@
// The first two message didn't quit and were handled by mS1
pmi = smQuitTest.getProcessedMessageInfo(6);
- assertEquals(HierarchicalStateMachine.HSM_QUIT_CMD, pmi.getWhat());
+ assertEquals(StateMachine.SM_QUIT_CMD, pmi.getWhat());
assertEquals(smQuitTest.mS1, pmi.getState());
assertEquals(smQuitTest.mS1, pmi.getOriginalState());
pmi = smQuitTest.getProcessedMessageInfo(7);
- assertEquals(HierarchicalStateMachine.HSM_QUIT_CMD, pmi.getWhat());
+ assertEquals(StateMachine.SM_QUIT_CMD, pmi.getWhat());
assertEquals(smQuitTest.mS1, pmi.getState());
assertEquals(smQuitTest.mS1, pmi.getOriginalState());
// The last message was never handled so the states are null
pmi = smQuitTest.getProcessedMessageInfo(8);
- assertEquals(HierarchicalStateMachine.HSM_QUIT_CMD, pmi.getWhat());
+ assertEquals(StateMachine.SM_QUIT_CMD, pmi.getWhat());
assertEquals(null, pmi.getState());
assertEquals(null, pmi.getOriginalState());
@@ -150,7 +151,7 @@
/**
* Test enter/exit can use transitionTo
*/
- class StateMachineEnterExitTransitionToTest extends HierarchicalStateMachine {
+ class StateMachineEnterExitTransitionToTest extends StateMachine {
StateMachineEnterExitTransitionToTest(String name) {
super(name);
mThisSm = this;
@@ -166,34 +167,38 @@
setInitialState(mS1);
}
- class S1 extends HierarchicalState {
- @Override protected void enter() {
+ class S1 extends State {
+ @Override
+ public void enter() {
// Test that message is HSM_INIT_CMD
- assertEquals(HSM_INIT_CMD, getCurrentMessage().what);
+ assertEquals(SM_INIT_CMD, getCurrentMessage().what);
// Test that a transition in enter and the initial state works
mS1EnterCount += 1;
transitionTo(mS2);
Log.d(TAG, "S1.enter");
}
- @Override protected void exit() {
+ @Override
+ public void exit() {
// Test that message is HSM_INIT_CMD
- assertEquals(HSM_INIT_CMD, getCurrentMessage().what);
+ assertEquals(SM_INIT_CMD, getCurrentMessage().what);
mS1ExitCount += 1;
Log.d(TAG, "S1.exit");
}
}
- class S2 extends HierarchicalState {
- @Override protected void enter() {
+ class S2 extends State {
+ @Override
+ public void enter() {
// Test that message is HSM_INIT_CMD
- assertEquals(HSM_INIT_CMD, getCurrentMessage().what);
+ assertEquals(SM_INIT_CMD, getCurrentMessage().what);
mS2EnterCount += 1;
Log.d(TAG, "S2.enter");
}
- @Override protected void exit() {
+ @Override
+ public void exit() {
// Test that message is TEST_CMD_1
assertEquals(TEST_CMD_1, getCurrentMessage().what);
@@ -202,7 +207,8 @@
transitionTo(mS4);
Log.d(TAG, "S2.exit");
}
- @Override protected boolean processMessage(Message message) {
+ @Override
+ public boolean processMessage(Message message) {
// Start a transition to S3 but it will be
// changed to a transition to S4 in exit
transitionTo(mS3);
@@ -211,28 +217,32 @@
}
}
- class S3 extends HierarchicalState {
- @Override protected void enter() {
+ class S3 extends State {
+ @Override
+ public void enter() {
// Test that we can do halting in an enter/exit
transitionToHaltingState();
mS3EnterCount += 1;
Log.d(TAG, "S3.enter");
}
- @Override protected void exit() {
+ @Override
+ public void exit() {
mS3ExitCount += 1;
Log.d(TAG, "S3.exit");
}
}
- class S4 extends HierarchicalState {
- @Override protected void enter() {
+ class S4 extends State {
+ @Override
+ public void enter() {
// Test that we can do halting in an enter/exit
transitionToHaltingState();
mS4EnterCount += 1;
Log.d(TAG, "S4.enter");
}
- @Override protected void exit() {
+ @Override
+ public void exit() {
mS4ExitCount += 1;
Log.d(TAG, "S4.exit");
}
@@ -310,7 +320,7 @@
/**
* Tests that ProcessedMessage works as a circular buffer.
*/
- class StateMachine0 extends HierarchicalStateMachine {
+ class StateMachine0 extends StateMachine {
StateMachine0(String name) {
super(name);
mThisSm = this;
@@ -324,8 +334,9 @@
setInitialState(mS1);
}
- class S1 extends HierarchicalState {
- @Override protected boolean processMessage(Message message) {
+ class S1 extends State {
+ @Override
+ public boolean processMessage(Message message) {
if (message.what == TEST_CMD_6) {
transitionToHaltingState();
}
@@ -394,7 +405,7 @@
* in state mS1. With the first message it transitions to
* itself which causes it to be exited and reentered.
*/
- class StateMachine1 extends HierarchicalStateMachine {
+ class StateMachine1 extends StateMachine {
StateMachine1(String name) {
super(name);
mThisSm = this;
@@ -408,12 +419,17 @@
if (DBG) Log.d(TAG, "StateMachine1: ctor X");
}
- class S1 extends HierarchicalState {
- @Override protected void enter() {
+ class S1 extends State {
+ @Override
+ public void enter() {
mEnterCount++;
}
-
- @Override protected boolean processMessage(Message message) {
+ @Override
+ public void exit() {
+ mExitCount++;
+ }
+ @Override
+ public boolean processMessage(Message message) {
if (message.what == TEST_CMD_1) {
assertEquals(1, mEnterCount);
assertEquals(0, mExitCount);
@@ -425,10 +441,6 @@
}
return HANDLED;
}
-
- @Override protected void exit() {
- mExitCount++;
- }
}
@Override
@@ -493,7 +505,7 @@
* mS2 then receives both of the deferred messages first TEST_CMD_1 and
* then TEST_CMD_2.
*/
- class StateMachine2 extends HierarchicalStateMachine {
+ class StateMachine2 extends StateMachine {
StateMachine2(String name) {
super(name);
mThisSm = this;
@@ -508,26 +520,28 @@
if (DBG) Log.d(TAG, "StateMachine2: ctor X");
}
- class S1 extends HierarchicalState {
- @Override protected void enter() {
+ class S1 extends State {
+ @Override
+ public void enter() {
mDidEnter = true;
}
-
- @Override protected boolean processMessage(Message message) {
+ @Override
+ public void exit() {
+ mDidExit = true;
+ }
+ @Override
+ public boolean processMessage(Message message) {
deferMessage(message);
if (message.what == TEST_CMD_2) {
transitionTo(mS2);
}
return HANDLED;
}
-
- @Override protected void exit() {
- mDidExit = true;
- }
}
- class S2 extends HierarchicalState {
- @Override protected boolean processMessage(Message message) {
+ class S2 extends State {
+ @Override
+ public boolean processMessage(Message message) {
if (message.what == TEST_CMD_2) {
transitionToHaltingState();
}
@@ -598,7 +612,7 @@
* Test that unhandled messages in a child are handled by the parent.
* When TEST_CMD_2 is received.
*/
- class StateMachine3 extends HierarchicalStateMachine {
+ class StateMachine3 extends StateMachine {
StateMachine3(String name) {
super(name);
mThisSm = this;
@@ -615,8 +629,9 @@
if (DBG) Log.d(TAG, "StateMachine3: ctor X");
}
- class ParentState extends HierarchicalState {
- @Override protected boolean processMessage(Message message) {
+ class ParentState extends State {
+ @Override
+ public boolean processMessage(Message message) {
if (message.what == TEST_CMD_2) {
transitionToHaltingState();
}
@@ -624,8 +639,9 @@
}
}
- class ChildState extends HierarchicalState {
- @Override protected boolean processMessage(Message message) {
+ class ChildState extends State {
+ @Override
+ public boolean processMessage(Message message) {
return NOT_HANDLED;
}
}
@@ -682,7 +698,7 @@
* with transition from child 1 to child 2 and child 2
* lets the parent handle the messages.
*/
- class StateMachine4 extends HierarchicalStateMachine {
+ class StateMachine4 extends StateMachine {
StateMachine4(String name) {
super(name);
mThisSm = this;
@@ -700,8 +716,9 @@
if (DBG) Log.d(TAG, "StateMachine4: ctor X");
}
- class ParentState extends HierarchicalState {
- @Override protected boolean processMessage(Message message) {
+ class ParentState extends State {
+ @Override
+ public boolean processMessage(Message message) {
if (message.what == TEST_CMD_2) {
transitionToHaltingState();
}
@@ -709,15 +726,17 @@
}
}
- class ChildState1 extends HierarchicalState {
- @Override protected boolean processMessage(Message message) {
+ class ChildState1 extends State {
+ @Override
+ public boolean processMessage(Message message) {
transitionTo(mChildState2);
return HANDLED;
}
}
- class ChildState2 extends HierarchicalState {
- @Override protected boolean processMessage(Message message) {
+ class ChildState2 extends State {
+ @Override
+ public boolean processMessage(Message message) {
return NOT_HANDLED;
}
}
@@ -775,7 +794,7 @@
* Test transition from one child to another of a "complex"
* hierarchy with two parents and multiple children.
*/
- class StateMachine5 extends HierarchicalStateMachine {
+ class StateMachine5 extends StateMachine {
StateMachine5(String name) {
super(name);
mThisSm = this;
@@ -797,23 +816,32 @@
if (DBG) Log.d(TAG, "StateMachine5: ctor X");
}
- class ParentState1 extends HierarchicalState {
- @Override protected void enter() {
+ class ParentState1 extends State {
+ @Override
+ public void enter() {
mParentState1EnterCount += 1;
}
- @Override protected boolean processMessage(Message message) {
- return HANDLED;
- }
- @Override protected void exit() {
+ @Override
+ public void exit() {
mParentState1ExitCount += 1;
}
+ @Override
+ public boolean processMessage(Message message) {
+ return HANDLED;
+ }
}
- class ChildState1 extends HierarchicalState {
- @Override protected void enter() {
+ class ChildState1 extends State {
+ @Override
+ public void enter() {
mChildState1EnterCount += 1;
}
- @Override protected boolean processMessage(Message message) {
+ @Override
+ public void exit() {
+ mChildState1ExitCount += 1;
+ }
+ @Override
+ public boolean processMessage(Message message) {
assertEquals(1, mParentState1EnterCount);
assertEquals(0, mParentState1ExitCount);
assertEquals(1, mChildState1EnterCount);
@@ -832,16 +860,19 @@
transitionTo(mChildState2);
return HANDLED;
}
- @Override protected void exit() {
- mChildState1ExitCount += 1;
- }
}
- class ChildState2 extends HierarchicalState {
- @Override protected void enter() {
+ class ChildState2 extends State {
+ @Override
+ public void enter() {
mChildState2EnterCount += 1;
}
- @Override protected boolean processMessage(Message message) {
+ @Override
+ public void exit() {
+ mChildState2ExitCount += 1;
+ }
+ @Override
+ public boolean processMessage(Message message) {
assertEquals(1, mParentState1EnterCount);
assertEquals(0, mParentState1ExitCount);
assertEquals(1, mChildState1EnterCount);
@@ -860,16 +891,19 @@
transitionTo(mChildState5);
return HANDLED;
}
- @Override protected void exit() {
- mChildState2ExitCount += 1;
- }
}
- class ParentState2 extends HierarchicalState {
- @Override protected void enter() {
+ class ParentState2 extends State {
+ @Override
+ public void enter() {
mParentState2EnterCount += 1;
}
- @Override protected boolean processMessage(Message message) {
+ @Override
+ public void exit() {
+ mParentState2ExitCount += 1;
+ }
+ @Override
+ public boolean processMessage(Message message) {
assertEquals(1, mParentState1EnterCount);
assertEquals(1, mParentState1ExitCount);
assertEquals(1, mChildState1EnterCount);
@@ -888,16 +922,19 @@
transitionToHaltingState();
return HANDLED;
}
- @Override protected void exit() {
- mParentState2ExitCount += 1;
- }
}
- class ChildState3 extends HierarchicalState {
- @Override protected void enter() {
+ class ChildState3 extends State {
+ @Override
+ public void enter() {
mChildState3EnterCount += 1;
}
- @Override protected boolean processMessage(Message message) {
+ @Override
+ public void exit() {
+ mChildState3ExitCount += 1;
+ }
+ @Override
+ public boolean processMessage(Message message) {
assertEquals(1, mParentState1EnterCount);
assertEquals(1, mParentState1ExitCount);
assertEquals(1, mChildState1EnterCount);
@@ -916,16 +953,19 @@
transitionTo(mChildState4);
return HANDLED;
}
- @Override protected void exit() {
- mChildState3ExitCount += 1;
- }
}
- class ChildState4 extends HierarchicalState {
- @Override protected void enter() {
+ class ChildState4 extends State {
+ @Override
+ public void enter() {
mChildState4EnterCount += 1;
}
- @Override protected boolean processMessage(Message message) {
+ @Override
+ public void exit() {
+ mChildState4ExitCount += 1;
+ }
+ @Override
+ public boolean processMessage(Message message) {
assertEquals(1, mParentState1EnterCount);
assertEquals(1, mParentState1ExitCount);
assertEquals(1, mChildState1EnterCount);
@@ -944,16 +984,19 @@
transitionTo(mParentState2);
return HANDLED;
}
- @Override protected void exit() {
- mChildState4ExitCount += 1;
- }
}
- class ChildState5 extends HierarchicalState {
- @Override protected void enter() {
+ class ChildState5 extends State {
+ @Override
+ public void enter() {
mChildState5EnterCount += 1;
}
- @Override protected boolean processMessage(Message message) {
+ @Override
+ public void exit() {
+ mChildState5ExitCount += 1;
+ }
+ @Override
+ public boolean processMessage(Message message) {
assertEquals(1, mParentState1EnterCount);
assertEquals(1, mParentState1ExitCount);
assertEquals(1, mChildState1EnterCount);
@@ -972,9 +1015,6 @@
transitionTo(mChildState3);
return HANDLED;
}
- @Override protected void exit() {
- mChildState5ExitCount += 1;
- }
}
@Override
@@ -1089,7 +1129,7 @@
* after construction and before any other messages arrive and that
* sendMessageDelayed works.
*/
- class StateMachine6 extends HierarchicalStateMachine {
+ class StateMachine6 extends StateMachine {
StateMachine6(String name) {
super(name);
mThisSm = this;
@@ -1103,13 +1143,13 @@
if (DBG) Log.d(TAG, "StateMachine6: ctor X");
}
- class S1 extends HierarchicalState {
-
- @Override protected void enter() {
+ class S1 extends State {
+ @Override
+ public void enter() {
sendMessage(TEST_CMD_1);
}
-
- @Override protected boolean processMessage(Message message) {
+ @Override
+ public boolean processMessage(Message message) {
if (message.what == TEST_CMD_1) {
mArrivalTimeMsg1 = SystemClock.elapsedRealtime();
} else if (message.what == TEST_CMD_2) {
@@ -1118,9 +1158,6 @@
}
return HANDLED;
}
-
- @Override protected void exit() {
- }
}
@Override
@@ -1178,7 +1215,7 @@
* Test that enter is invoked immediately after exit. This validates
* that enter can be used to send a watch dog message for its state.
*/
- class StateMachine7 extends HierarchicalStateMachine {
+ class StateMachine7 extends StateMachine {
private final int SM7_DELAY_TIME = 250;
StateMachine7(String name) {
@@ -1195,24 +1232,26 @@
if (DBG) Log.d(TAG, "StateMachine7: ctor X");
}
- class S1 extends HierarchicalState {
- @Override protected boolean processMessage(Message message) {
+ class S1 extends State {
+ @Override
+ public void exit() {
+ sendMessage(TEST_CMD_2);
+ }
+ @Override
+ public boolean processMessage(Message message) {
transitionTo(mS2);
return HANDLED;
}
- @Override protected void exit() {
- sendMessage(TEST_CMD_2);
- }
}
- class S2 extends HierarchicalState {
-
- @Override protected void enter() {
+ class S2 extends State {
+ @Override
+ public void enter() {
// Send a delayed message as a watch dog
sendMessageDelayed(TEST_CMD_3, SM7_DELAY_TIME);
}
-
- @Override protected boolean processMessage(Message message) {
+ @Override
+ public boolean processMessage(Message message) {
if (message.what == TEST_CMD_2) {
mMsgCount += 1;
mArrivalTimeMsg2 = SystemClock.elapsedRealtime();
@@ -1226,9 +1265,6 @@
}
return HANDLED;
}
-
- @Override protected void exit() {
- }
}
@Override
@@ -1286,7 +1322,7 @@
/**
* Test unhandledMessage.
*/
- class StateMachineUnhandledMessage extends HierarchicalStateMachine {
+ class StateMachineUnhandledMessage extends StateMachine {
StateMachineUnhandledMessage(String name) {
super(name);
mThisSm = this;
@@ -1298,13 +1334,14 @@
// Set the initial state
setInitialState(mS1);
}
-
- @Override protected void unhandledMessage(Message message) {
+ @Override
+ public void unhandledMessage(Message message) {
mUnhandledMessageCount += 1;
}
- class S1 extends HierarchicalState {
- @Override protected boolean processMessage(Message message) {
+ class S1 extends State {
+ @Override
+ public boolean processMessage(Message message) {
if (message.what == TEST_CMD_2) {
transitionToHaltingState();
}
@@ -1359,7 +1396,7 @@
* will be used to notify testStateMachineSharedThread that the test is
* complete.
*/
- class StateMachineSharedThread extends HierarchicalStateMachine {
+ class StateMachineSharedThread extends StateMachine {
StateMachineSharedThread(String name, Looper looper, int maxCount) {
super(name, looper);
mMaxCount = maxCount;
@@ -1372,8 +1409,9 @@
setInitialState(mS1);
}
- class S1 extends HierarchicalState {
- @Override protected boolean processMessage(Message message) {
+ class S1 extends State {
+ @Override
+ public boolean processMessage(Message message) {
if (message.what == TEST_CMD_4) {
transitionToHaltingState();
}
@@ -1503,7 +1541,7 @@
}
}
-class Hsm1 extends HierarchicalStateMachine {
+class Hsm1 extends StateMachine {
private static final String TAG = "hsm1";
public static final int CMD_1 = 1;
@@ -1535,11 +1573,17 @@
Log.d(TAG, "ctor X");
}
- class P1 extends HierarchicalState {
- @Override protected void enter() {
+ class P1 extends State {
+ @Override
+ public void enter() {
Log.d(TAG, "P1.enter");
}
- @Override protected boolean processMessage(Message message) {
+ @Override
+ public void exit() {
+ Log.d(TAG, "P1.exit");
+ }
+ @Override
+ public boolean processMessage(Message message) {
boolean retVal;
Log.d(TAG, "P1.processMessage what=" + message.what);
switch(message.what) {
@@ -1557,16 +1601,19 @@
}
return retVal;
}
- @Override protected void exit() {
- Log.d(TAG, "P1.exit");
- }
}
- class S1 extends HierarchicalState {
- @Override protected void enter() {
+ class S1 extends State {
+ @Override
+ public void enter() {
Log.d(TAG, "S1.enter");
}
- @Override protected boolean processMessage(Message message) {
+ @Override
+ public void exit() {
+ Log.d(TAG, "S1.exit");
+ }
+ @Override
+ public boolean processMessage(Message message) {
Log.d(TAG, "S1.processMessage what=" + message.what);
if (message.what == CMD_1) {
// Transition to ourself to show that enter/exit is called
@@ -1577,16 +1624,19 @@
return NOT_HANDLED;
}
}
- @Override protected void exit() {
- Log.d(TAG, "S1.exit");
- }
}
- class S2 extends HierarchicalState {
- @Override protected void enter() {
+ class S2 extends State {
+ @Override
+ public void enter() {
Log.d(TAG, "S2.enter");
}
- @Override protected boolean processMessage(Message message) {
+ @Override
+ public void exit() {
+ Log.d(TAG, "S2.exit");
+ }
+ @Override
+ public boolean processMessage(Message message) {
boolean retVal;
Log.d(TAG, "S2.processMessage what=" + message.what);
switch(message.what) {
@@ -1605,17 +1655,20 @@
}
return retVal;
}
- @Override protected void exit() {
- Log.d(TAG, "S2.exit");
- }
}
- class P2 extends HierarchicalState {
- @Override protected void enter() {
+ class P2 extends State {
+ @Override
+ public void enter() {
Log.d(TAG, "P2.enter");
sendMessage(CMD_5);
}
- @Override protected boolean processMessage(Message message) {
+ @Override
+ public void exit() {
+ Log.d(TAG, "P2.exit");
+ }
+ @Override
+ public boolean processMessage(Message message) {
Log.d(TAG, "P2.processMessage what=" + message.what);
switch(message.what) {
case(CMD_3):
@@ -1628,9 +1681,6 @@
}
return HANDLED;
}
- @Override protected void exit() {
- Log.d(TAG, "P2.exit");
- }
}
@Override
diff --git a/services/java/com/android/server/connectivity/Tethering.java b/services/java/com/android/server/connectivity/Tethering.java
index 5853696..9ff5233 100644
--- a/services/java/com/android/server/connectivity/Tethering.java
+++ b/services/java/com/android/server/connectivity/Tethering.java
@@ -49,8 +49,9 @@
import android.util.Log;
import com.android.internal.telephony.Phone;
-import com.android.internal.util.HierarchicalState;
-import com.android.internal.util.HierarchicalStateMachine;
+import com.android.internal.util.IState;
+import com.android.internal.util.State;
+import com.android.internal.util.StateMachine;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -122,7 +123,7 @@
// resampled each time we turn on tethering - used as cache for settings/config-val
private boolean mDunRequired; // configuration info - must use DUN apn on 3g
- private HierarchicalStateMachine mTetherMasterSM;
+ private StateMachine mTetherMasterSM;
private Notification mTetheredNotification;
@@ -668,7 +669,7 @@
}
- class TetherInterfaceSM extends HierarchicalStateMachine {
+ class TetherInterfaceSM extends StateMachine {
// notification from the master SM that it's not in tether mode
static final int CMD_TETHER_MODE_DEAD = 1;
// request from the user that it wants to tether
@@ -694,13 +695,13 @@
// the upstream connection has changed
static final int CMD_TETHER_CONNECTION_CHANGED = 12;
- private HierarchicalState mDefaultState;
+ private State mDefaultState;
- private HierarchicalState mInitialState;
- private HierarchicalState mStartingState;
- private HierarchicalState mTetheredState;
+ private State mInitialState;
+ private State mStartingState;
+ private State mTetheredState;
- private HierarchicalState mUnavailableState;
+ private State mUnavailableState;
private boolean mAvailable;
private boolean mTethered;
@@ -732,7 +733,7 @@
public String toString() {
String res = new String();
res += mIfaceName + " - ";
- HierarchicalState current = getCurrentState();
+ IState current = getCurrentState();
if (current == mInitialState) res += "InitialState";
if (current == mStartingState) res += "StartingState";
if (current == mTetheredState) res += "TetheredState";
@@ -782,7 +783,7 @@
return (mLastError != ConnectivityManager.TETHER_ERROR_NO_ERROR);
}
- class InitialState extends HierarchicalState {
+ class InitialState extends State {
@Override
public void enter() {
setAvailable(true);
@@ -812,7 +813,7 @@
}
}
- class StartingState extends HierarchicalState {
+ class StartingState extends State {
@Override
public void enter() {
setAvailable(false);
@@ -870,7 +871,7 @@
}
}
- class TetheredState extends HierarchicalState {
+ class TetheredState extends State {
@Override
public void enter() {
IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
@@ -1034,7 +1035,7 @@
}
}
- class UnavailableState extends HierarchicalState {
+ class UnavailableState extends State {
@Override
public void enter() {
setAvailable(false);
@@ -1064,7 +1065,7 @@
}
- class TetherMasterSM extends HierarchicalStateMachine {
+ class TetherMasterSM extends StateMachine {
// an interface SM has requested Tethering
static final int CMD_TETHER_MODE_REQUESTED = 1;
// an interface SM has unrequested Tethering
@@ -1082,14 +1083,14 @@
// We do not flush the old ones.
private int mSequenceNumber;
- private HierarchicalState mInitialState;
- private HierarchicalState mTetherModeAliveState;
+ private State mInitialState;
+ private State mTetherModeAliveState;
- private HierarchicalState mSetIpForwardingEnabledErrorState;
- private HierarchicalState mSetIpForwardingDisabledErrorState;
- private HierarchicalState mStartTetheringErrorState;
- private HierarchicalState mStopTetheringErrorState;
- private HierarchicalState mSetDnsForwardersErrorState;
+ private State mSetIpForwardingEnabledErrorState;
+ private State mSetIpForwardingDisabledErrorState;
+ private State mStartTetheringErrorState;
+ private State mStopTetheringErrorState;
+ private State mSetDnsForwardersErrorState;
private ArrayList mNotifyList;
@@ -1125,7 +1126,7 @@
setInitialState(mInitialState);
}
- class TetherMasterUtilState extends HierarchicalState {
+ class TetherMasterUtilState extends State {
protected final static boolean TRY_TO_SETUP_MOBILE_CONNECTION = true;
protected final static boolean WAIT_FOR_NETWORK_TO_SETTLE = false;
@@ -1440,7 +1441,7 @@
}
}
- class ErrorState extends HierarchicalState {
+ class ErrorState extends State {
int mErrorNotification;
@Override
public boolean processMessage(Message message) {
diff --git a/telephony/java/com/android/internal/telephony/DataConnection.java b/telephony/java/com/android/internal/telephony/DataConnection.java
index 0c47e86..791fbfd 100644
--- a/telephony/java/com/android/internal/telephony/DataConnection.java
+++ b/telephony/java/com/android/internal/telephony/DataConnection.java
@@ -17,8 +17,8 @@
package com.android.internal.telephony;
-import com.android.internal.util.HierarchicalState;
-import com.android.internal.util.HierarchicalStateMachine;
+import com.android.internal.util.State;
+import com.android.internal.util.StateMachine;
import android.net.LinkAddress;
import android.net.LinkCapabilities;
@@ -37,7 +37,7 @@
/**
* {@hide}
*
- * DataConnection HierarchicalStateMachine.
+ * DataConnection StateMachine.
*
* This is an abstract base class for representing a single data connection.
* Instances of this class such as <code>CdmaDataConnection</code> and
@@ -55,7 +55,7 @@
*
* The other public methods are provided for debugging.
*/
-public abstract class DataConnection extends HierarchicalStateMachine {
+public abstract class DataConnection extends StateMachine {
protected static final boolean DBG = true;
protected static Object mCountLock = new Object();
@@ -484,17 +484,17 @@
/**
* The parent state for all other states.
*/
- private class DcDefaultState extends HierarchicalState {
+ private class DcDefaultState extends State {
@Override
- protected void enter() {
+ public void enter() {
phone.mCM.registerForRilConnected(getHandler(), EVENT_RIL_CONNECTED, null);
}
@Override
- protected void exit() {
+ public void exit() {
phone.mCM.unregisterForRilConnected(getHandler());
}
@Override
- protected boolean processMessage(Message msg) {
+ public boolean processMessage(Message msg) {
AsyncResult ar;
switch (msg.what) {
@@ -547,7 +547,7 @@
/**
* The state machine is inactive and expects a EVENT_CONNECT.
*/
- private class DcInactiveState extends HierarchicalState {
+ private class DcInactiveState extends State {
private ConnectionParams mConnectionParams = null;
private FailCause mFailCause = null;
private DisconnectParams mDisconnectParams = null;
@@ -563,7 +563,8 @@
mDisconnectParams = dp;
}
- @Override protected void enter() {
+ @Override
+ public void enter() {
mTag += 1;
/**
@@ -583,14 +584,16 @@
}
}
- @Override protected void exit() {
+ @Override
+ public void exit() {
// clear notifications
mConnectionParams = null;
mFailCause = null;
mDisconnectParams = null;
}
- @Override protected boolean processMessage(Message msg) {
+ @Override
+ public boolean processMessage(Message msg) {
boolean retVal;
switch (msg.what) {
@@ -626,8 +629,9 @@
/**
* The state machine is activating a connection.
*/
- private class DcActivatingState extends HierarchicalState {
- @Override protected boolean processMessage(Message msg) {
+ private class DcActivatingState extends State {
+ @Override
+ public boolean processMessage(Message msg) {
boolean retVal;
AsyncResult ar;
ConnectionParams cp;
@@ -722,7 +726,7 @@
/**
* The state machine is connected, expecting an EVENT_DISCONNECT.
*/
- private class DcActiveState extends HierarchicalState {
+ private class DcActiveState extends State {
private ConnectionParams mConnectionParams = null;
private FailCause mFailCause = null;
@@ -746,13 +750,15 @@
}
}
- @Override protected void exit() {
+ @Override
+ public void exit() {
// clear notifications
mConnectionParams = null;
mFailCause = null;
}
- @Override protected boolean processMessage(Message msg) {
+ @Override
+ public boolean processMessage(Message msg) {
boolean retVal;
switch (msg.what) {
@@ -778,8 +784,9 @@
/**
* The state machine is disconnecting.
*/
- private class DcDisconnectingState extends HierarchicalState {
- @Override protected boolean processMessage(Message msg) {
+ private class DcDisconnectingState extends State {
+ @Override
+ public boolean processMessage(Message msg) {
boolean retVal;
switch (msg.what) {
@@ -812,8 +819,9 @@
/**
* The state machine is disconnecting after an creating a connection.
*/
- private class DcDisconnectionErrorCreatingConnection extends HierarchicalState {
- @Override protected boolean processMessage(Message msg) {
+ private class DcDisconnectionErrorCreatingConnection extends State {
+ @Override
+ public boolean processMessage(Message msg) {
boolean retVal;
switch (msg.what) {
diff --git a/telephony/java/com/android/internal/telephony/cat/RilMessageDecoder.java b/telephony/java/com/android/internal/telephony/cat/RilMessageDecoder.java
index a197c9a..2a1f508 100644
--- a/telephony/java/com/android/internal/telephony/cat/RilMessageDecoder.java
+++ b/telephony/java/com/android/internal/telephony/cat/RilMessageDecoder.java
@@ -20,15 +20,15 @@
import com.android.internal.telephony.IccUtils;
import android.os.Handler;
-import com.android.internal.util.HierarchicalState;
-import com.android.internal.util.HierarchicalStateMachine;
+import com.android.internal.util.State;
+import com.android.internal.util.StateMachine;
import android.os.Message;
/**
* Class used for queuing raw ril messages, decoding them into CommanParams
* objects and sending the result back to the CAT Service.
*/
-class RilMessageDecoder extends HierarchicalStateMachine {
+class RilMessageDecoder extends StateMachine {
// constants
private static final int CMD_START = 1;
@@ -101,8 +101,9 @@
mCmdParamsFactory = CommandParamsFactory.getInstance(this, fh);
}
- private class StateStart extends HierarchicalState {
- @Override protected boolean processMessage(Message msg) {
+ private class StateStart extends State {
+ @Override
+ public boolean processMessage(Message msg) {
if (msg.what == CMD_START) {
if (decodeMessageParams((RilMessage)msg.obj)) {
transitionTo(mStateCmdParamsReady);
@@ -115,8 +116,9 @@
}
}
- private class StateCmdParamsReady extends HierarchicalState {
- @Override protected boolean processMessage(Message msg) {
+ private class StateCmdParamsReady extends State {
+ @Override
+ public boolean processMessage(Message msg) {
if (msg.what == CMD_PARAMS_READY) {
mCurrentRilMessage.mResCode = ResultCode.fromInt(msg.arg1);
mCurrentRilMessage.mData = msg.obj;
diff --git a/wifi/java/android/net/wifi/SupplicantStateTracker.java b/wifi/java/android/net/wifi/SupplicantStateTracker.java
index 3cde949..9ae26da 100644
--- a/wifi/java/android/net/wifi/SupplicantStateTracker.java
+++ b/wifi/java/android/net/wifi/SupplicantStateTracker.java
@@ -16,8 +16,8 @@
package android.net.wifi;
-import com.android.internal.util.HierarchicalState;
-import com.android.internal.util.HierarchicalStateMachine;
+import com.android.internal.util.State;
+import com.android.internal.util.StateMachine;
import android.net.wifi.WifiStateMachine.StateChangeResult;
import android.content.Context;
@@ -33,7 +33,7 @@
* - detect a failed WPA handshake that loops indefinitely
* - authentication failure handling
*/
-class SupplicantStateTracker extends HierarchicalStateMachine {
+class SupplicantStateTracker extends StateMachine {
private static final String TAG = "SupplicantStateTracker";
private static final boolean DBG = false;
@@ -53,14 +53,14 @@
private Context mContext;
- private HierarchicalState mUninitializedState = new UninitializedState();
- private HierarchicalState mDefaultState = new DefaultState();
- private HierarchicalState mInactiveState = new InactiveState();
- private HierarchicalState mDisconnectState = new DisconnectedState();
- private HierarchicalState mScanState = new ScanState();
- private HierarchicalState mHandshakeState = new HandshakeState();
- private HierarchicalState mCompletedState = new CompletedState();
- private HierarchicalState mDormantState = new DormantState();
+ private State mUninitializedState = new UninitializedState();
+ private State mDefaultState = new DefaultState();
+ private State mInactiveState = new InactiveState();
+ private State mDisconnectState = new DisconnectedState();
+ private State mScanState = new ScanState();
+ private State mHandshakeState = new HandshakeState();
+ private State mCompletedState = new CompletedState();
+ private State mDormantState = new DormantState();
public SupplicantStateTracker(Context context, WifiStateMachine wsm, Handler target) {
super(TAG, target.getLooper());
@@ -146,7 +146,7 @@
* HSM states
*******************************************************/
- class DefaultState extends HierarchicalState {
+ class DefaultState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -188,21 +188,21 @@
* or after we have lost the control channel
* connection to the supplicant
*/
- class UninitializedState extends HierarchicalState {
+ class UninitializedState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
}
}
- class InactiveState extends HierarchicalState {
+ class InactiveState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
}
}
- class DisconnectedState extends HierarchicalState {
+ class DisconnectedState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -221,14 +221,14 @@
}
}
- class ScanState extends HierarchicalState {
+ class ScanState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
}
}
- class HandshakeState extends HierarchicalState {
+ class HandshakeState extends State {
/**
* The max number of the WPA supplicant loop iterations before we
* decide that the loop should be terminated:
@@ -277,7 +277,7 @@
}
}
- class CompletedState extends HierarchicalState {
+ class CompletedState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -318,7 +318,7 @@
}
//TODO: remove after getting rid of the state in supplicant
- class DormantState extends HierarchicalState {
+ class DormantState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index 4346b327..afa5c1d 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -73,8 +73,8 @@
import com.android.internal.app.IBatteryStats;
import com.android.internal.util.AsyncChannel;
-import com.android.internal.util.HierarchicalState;
-import com.android.internal.util.HierarchicalStateMachine;
+import com.android.internal.util.State;
+import com.android.internal.util.StateMachine;
import java.net.InetAddress;
import java.util.ArrayList;
@@ -88,7 +88,7 @@
*
* @hide
*/
-public class WifiStateMachine extends HierarchicalStateMachine {
+public class WifiStateMachine extends StateMachine {
private static final String TAG = "WifiStateMachine";
private static final String NETWORKTYPE = "WIFI";
@@ -348,50 +348,50 @@
private static final int MAX_RSSI = 256;
/* Default parent state */
- private HierarchicalState mDefaultState = new DefaultState();
+ private State mDefaultState = new DefaultState();
/* Temporary initial state */
- private HierarchicalState mInitialState = new InitialState();
+ private State mInitialState = new InitialState();
/* Unloading the driver */
- private HierarchicalState mDriverUnloadingState = new DriverUnloadingState();
+ private State mDriverUnloadingState = new DriverUnloadingState();
/* Loading the driver */
- private HierarchicalState mDriverUnloadedState = new DriverUnloadedState();
+ private State mDriverUnloadedState = new DriverUnloadedState();
/* Driver load/unload failed */
- private HierarchicalState mDriverFailedState = new DriverFailedState();
+ private State mDriverFailedState = new DriverFailedState();
/* Driver loading */
- private HierarchicalState mDriverLoadingState = new DriverLoadingState();
+ private State mDriverLoadingState = new DriverLoadingState();
/* Driver loaded */
- private HierarchicalState mDriverLoadedState = new DriverLoadedState();
+ private State mDriverLoadedState = new DriverLoadedState();
/* Driver loaded, waiting for supplicant to start */
- private HierarchicalState mSupplicantStartingState = new SupplicantStartingState();
+ private State mSupplicantStartingState = new SupplicantStartingState();
/* Driver loaded and supplicant ready */
- private HierarchicalState mSupplicantStartedState = new SupplicantStartedState();
+ private State mSupplicantStartedState = new SupplicantStartedState();
/* Waiting for supplicant to stop and monitor to exit */
- private HierarchicalState mSupplicantStoppingState = new SupplicantStoppingState();
+ private State mSupplicantStoppingState = new SupplicantStoppingState();
/* Driver start issued, waiting for completed event */
- private HierarchicalState mDriverStartingState = new DriverStartingState();
+ private State mDriverStartingState = new DriverStartingState();
/* Driver started */
- private HierarchicalState mDriverStartedState = new DriverStartedState();
+ private State mDriverStartedState = new DriverStartedState();
/* Driver stopping */
- private HierarchicalState mDriverStoppingState = new DriverStoppingState();
+ private State mDriverStoppingState = new DriverStoppingState();
/* Driver stopped */
- private HierarchicalState mDriverStoppedState = new DriverStoppedState();
+ private State mDriverStoppedState = new DriverStoppedState();
/* Scan for networks, no connection will be established */
- private HierarchicalState mScanModeState = new ScanModeState();
+ private State mScanModeState = new ScanModeState();
/* Connecting to an access point */
- private HierarchicalState mConnectModeState = new ConnectModeState();
+ private State mConnectModeState = new ConnectModeState();
/* Fetching IP after network connection (assoc+auth complete) */
- private HierarchicalState mConnectingState = new ConnectingState();
+ private State mConnectingState = new ConnectingState();
/* Connected with IP addr */
- private HierarchicalState mConnectedState = new ConnectedState();
+ private State mConnectedState = new ConnectedState();
/* disconnect issued, waiting for network disconnect confirmation */
- private HierarchicalState mDisconnectingState = new DisconnectingState();
+ private State mDisconnectingState = new DisconnectingState();
/* Network is not connected, supplicant assoc+auth is not complete */
- private HierarchicalState mDisconnectedState = new DisconnectedState();
+ private State mDisconnectedState = new DisconnectedState();
/* Waiting for WPS to be completed*/
- private HierarchicalState mWaitForWpsCompletionState = new WaitForWpsCompletionState();
+ private State mWaitForWpsCompletionState = new WaitForWpsCompletionState();
/* Soft Ap is running */
- private HierarchicalState mSoftApStartedState = new SoftApStartedState();
+ private State mSoftApStartedState = new SoftApStartedState();
/**
@@ -1527,7 +1527,7 @@
* HSM states
*******************************************************/
- class DefaultState extends HierarchicalState {
+ class DefaultState extends State {
@Override
public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
@@ -1601,7 +1601,7 @@
}
}
- class InitialState extends HierarchicalState {
+ class InitialState extends State {
@Override
//TODO: could move logging into a common class
public void enter() {
@@ -1620,7 +1620,7 @@
}
}
- class DriverLoadingState extends HierarchicalState {
+ class DriverLoadingState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -1699,7 +1699,7 @@
}
}
- class DriverLoadedState extends HierarchicalState {
+ class DriverLoadedState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -1752,7 +1752,7 @@
}
}
- class DriverUnloadingState extends HierarchicalState {
+ class DriverUnloadingState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -1833,7 +1833,7 @@
}
}
- class DriverUnloadedState extends HierarchicalState {
+ class DriverUnloadedState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -1854,7 +1854,7 @@
}
}
- class DriverFailedState extends HierarchicalState {
+ class DriverFailedState extends State {
@Override
public void enter() {
Log.e(TAG, getName() + "\n");
@@ -1868,7 +1868,7 @@
}
- class SupplicantStartingState extends HierarchicalState {
+ class SupplicantStartingState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -1940,7 +1940,7 @@
}
}
- class SupplicantStartedState extends HierarchicalState {
+ class SupplicantStartedState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -2063,7 +2063,7 @@
}
}
- class SupplicantStoppingState extends HierarchicalState {
+ class SupplicantStoppingState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -2106,7 +2106,7 @@
}
}
- class DriverStartingState extends HierarchicalState {
+ class DriverStartingState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -2147,7 +2147,7 @@
}
}
- class DriverStartedState extends HierarchicalState {
+ class DriverStartedState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -2251,7 +2251,7 @@
}
}
- class DriverStoppingState extends HierarchicalState {
+ class DriverStoppingState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -2287,7 +2287,7 @@
}
}
- class DriverStoppedState extends HierarchicalState {
+ class DriverStoppedState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -2311,7 +2311,7 @@
}
}
- class ScanModeState extends HierarchicalState {
+ class ScanModeState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -2348,7 +2348,7 @@
}
}
- class ConnectModeState extends HierarchicalState {
+ class ConnectModeState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -2458,7 +2458,7 @@
}
}
- class ConnectingState extends HierarchicalState {
+ class ConnectingState extends State {
boolean mModifiedBluetoothCoexistenceMode;
int mPowerMode;
boolean mUseStaticIp;
@@ -2656,7 +2656,7 @@
}
}
- class ConnectedState extends HierarchicalState {
+ class ConnectedState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -2768,7 +2768,7 @@
}
}
- class DisconnectingState extends HierarchicalState {
+ class DisconnectingState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -2798,7 +2798,7 @@
}
}
- class DisconnectedState extends HierarchicalState {
+ class DisconnectedState extends State {
private boolean mAlarmEnabled = false;
private long mScanIntervalMs;
@@ -2905,7 +2905,7 @@
}
}
- class WaitForWpsCompletionState extends HierarchicalState {
+ class WaitForWpsCompletionState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -2944,7 +2944,7 @@
}
}
- class SoftApStartedState extends HierarchicalState {
+ class SoftApStartedState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
diff --git a/wifi/java/android/net/wifi/WpsStateMachine.java b/wifi/java/android/net/wifi/WpsStateMachine.java
index 32d77a1..120b228 100644
--- a/wifi/java/android/net/wifi/WpsStateMachine.java
+++ b/wifi/java/android/net/wifi/WpsStateMachine.java
@@ -17,8 +17,8 @@
package android.net.wifi;
import com.android.internal.util.AsyncChannel;
-import com.android.internal.util.HierarchicalState;
-import com.android.internal.util.HierarchicalStateMachine;
+import com.android.internal.util.State;
+import com.android.internal.util.StateMachine;
import android.content.Context;
import android.content.Intent;
@@ -46,7 +46,7 @@
* reloads the configuration and updates the IP and proxy
* settings, if any.
*/
-class WpsStateMachine extends HierarchicalStateMachine {
+class WpsStateMachine extends StateMachine {
private static final String TAG = "WpsStateMachine";
private static final boolean DBG = false;
@@ -58,9 +58,9 @@
private Context mContext;
AsyncChannel mReplyChannel = new AsyncChannel();
- private HierarchicalState mDefaultState = new DefaultState();
- private HierarchicalState mInactiveState = new InactiveState();
- private HierarchicalState mActiveState = new ActiveState();
+ private State mDefaultState = new DefaultState();
+ private State mInactiveState = new InactiveState();
+ private State mActiveState = new ActiveState();
public WpsStateMachine(Context context, WifiStateMachine wsm, Handler target) {
super(TAG, target.getLooper());
@@ -82,7 +82,7 @@
* HSM states
*******************************************************/
- class DefaultState extends HierarchicalState {
+ class DefaultState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -128,7 +128,7 @@
}
}
- class ActiveState extends HierarchicalState {
+ class ActiveState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");
@@ -182,7 +182,7 @@
}
}
- class InactiveState extends HierarchicalState {
+ class InactiveState extends State {
@Override
public void enter() {
if (DBG) Log.d(TAG, getName() + "\n");