am 64c42cae: Rename HierarchicalStateMachine and HierarchicalState to StateMachine and State.

* commit '64c42cae4482fe0157e977b8ddd0f2c2436b3f31':
  Rename HierarchicalStateMachine and HierarchicalState to StateMachine and State.
This commit is contained in:
Wink Saville
2011-04-18 15:24:47 -07:00
committed by Android Git Automerger
12 changed files with 606 additions and 476 deletions

View File

@@ -26,8 +26,8 @@ import android.server.BluetoothA2dpService;
import android.server.BluetoothService; import android.server.BluetoothService;
import android.util.Log; import android.util.Log;
import com.android.internal.util.HierarchicalState; import com.android.internal.util.State;
import com.android.internal.util.HierarchicalStateMachine; import com.android.internal.util.StateMachine;
import java.util.Set; import java.util.Set;
@@ -57,7 +57,7 @@ import java.util.Set;
* Todo(): Write tests for this class, when the Android Mock support is completed. * Todo(): Write tests for this class, when the Android Mock support is completed.
* @hide * @hide
*/ */
public final class BluetoothDeviceProfileState extends HierarchicalStateMachine { public final class BluetoothDeviceProfileState extends StateMachine {
private static final String TAG = "BluetoothDeviceProfileState"; private static final String TAG = "BluetoothDeviceProfileState";
private static final boolean DBG = false; private static final boolean DBG = false;
@@ -235,16 +235,16 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine
} }
} }
private class BondedDevice extends HierarchicalState { private class BondedDevice extends State {
@Override @Override
protected void enter() { public void enter() {
Log.i(TAG, "Entering ACL Connected state with: " + getCurrentMessage().what); Log.i(TAG, "Entering ACL Connected state with: " + getCurrentMessage().what);
Message m = new Message(); Message m = new Message();
m.copyFrom(getCurrentMessage()); m.copyFrom(getCurrentMessage());
sendMessageAtFrontOfQueue(m); sendMessageAtFrontOfQueue(m);
} }
@Override @Override
protected boolean processMessage(Message message) { public boolean processMessage(Message message) {
log("ACL Connected State -> Processing Message: " + message.what); log("ACL Connected State -> Processing Message: " + message.what);
switch(message.what) { switch(message.what) {
case CONNECT_HFP_OUTGOING: case CONNECT_HFP_OUTGOING:
@@ -353,12 +353,12 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine
} }
} }
private class OutgoingHandsfree extends HierarchicalState { private class OutgoingHandsfree extends State {
private boolean mStatus = false; private boolean mStatus = false;
private int mCommand; private int mCommand;
@Override @Override
protected void enter() { public void enter() {
Log.i(TAG, "Entering OutgoingHandsfree state with: " + getCurrentMessage().what); Log.i(TAG, "Entering OutgoingHandsfree state with: " + getCurrentMessage().what);
mCommand = getCurrentMessage().what; mCommand = getCurrentMessage().what;
if (mCommand != CONNECT_HFP_OUTGOING && if (mCommand != CONNECT_HFP_OUTGOING &&
@@ -374,7 +374,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine
} }
@Override @Override
protected boolean processMessage(Message message) { public boolean processMessage(Message message) {
log("OutgoingHandsfree State -> Processing Message: " + message.what); log("OutgoingHandsfree State -> Processing Message: " + message.what);
Message deferMsg = new Message(); Message deferMsg = new Message();
int command = message.what; int command = message.what;
@@ -466,12 +466,12 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine
} }
} }
private class IncomingHandsfree extends HierarchicalState { private class IncomingHandsfree extends State {
private boolean mStatus = false; private boolean mStatus = false;
private int mCommand; private int mCommand;
@Override @Override
protected void enter() { public void enter() {
Log.i(TAG, "Entering IncomingHandsfree state with: " + getCurrentMessage().what); Log.i(TAG, "Entering IncomingHandsfree state with: " + getCurrentMessage().what);
mCommand = getCurrentMessage().what; mCommand = getCurrentMessage().what;
if (mCommand != CONNECT_HFP_INCOMING && if (mCommand != CONNECT_HFP_INCOMING &&
@@ -487,7 +487,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine
} }
@Override @Override
protected boolean processMessage(Message message) { public boolean processMessage(Message message) {
log("IncomingHandsfree State -> Processing Message: " + message.what); log("IncomingHandsfree State -> Processing Message: " + message.what);
switch(message.what) { switch(message.what) {
case CONNECT_HFP_OUTGOING: case CONNECT_HFP_OUTGOING:
@@ -546,12 +546,12 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine
} }
} }
private class OutgoingA2dp extends HierarchicalState { private class OutgoingA2dp extends State {
private boolean mStatus = false; private boolean mStatus = false;
private int mCommand; private int mCommand;
@Override @Override
protected void enter() { public void enter() {
Log.i(TAG, "Entering OutgoingA2dp state with: " + getCurrentMessage().what); Log.i(TAG, "Entering OutgoingA2dp state with: " + getCurrentMessage().what);
mCommand = getCurrentMessage().what; mCommand = getCurrentMessage().what;
if (mCommand != CONNECT_A2DP_OUTGOING && if (mCommand != CONNECT_A2DP_OUTGOING &&
@@ -567,7 +567,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine
} }
@Override @Override
protected boolean processMessage(Message message) { public boolean processMessage(Message message) {
log("OutgoingA2dp State->Processing Message: " + message.what); log("OutgoingA2dp State->Processing Message: " + message.what);
Message deferMsg = new Message(); Message deferMsg = new Message();
switch(message.what) { switch(message.what) {
@@ -656,12 +656,12 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine
} }
} }
private class IncomingA2dp extends HierarchicalState { private class IncomingA2dp extends State {
private boolean mStatus = false; private boolean mStatus = false;
private int mCommand; private int mCommand;
@Override @Override
protected void enter() { public void enter() {
Log.i(TAG, "Entering IncomingA2dp state with: " + getCurrentMessage().what); Log.i(TAG, "Entering IncomingA2dp state with: " + getCurrentMessage().what);
mCommand = getCurrentMessage().what; mCommand = getCurrentMessage().what;
if (mCommand != CONNECT_A2DP_INCOMING && if (mCommand != CONNECT_A2DP_INCOMING &&
@@ -677,7 +677,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine
} }
@Override @Override
protected boolean processMessage(Message message) { public boolean processMessage(Message message) {
log("IncomingA2dp State->Processing Message: " + message.what); log("IncomingA2dp State->Processing Message: " + message.what);
switch(message.what) { switch(message.what) {
case CONNECT_HFP_OUTGOING: case CONNECT_HFP_OUTGOING:
@@ -734,12 +734,12 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine
} }
private class OutgoingHid extends HierarchicalState { private class OutgoingHid extends State {
private boolean mStatus = false; private boolean mStatus = false;
private int mCommand; private int mCommand;
@Override @Override
protected void enter() { public void enter() {
log("Entering OutgoingHid state with: " + getCurrentMessage().what); log("Entering OutgoingHid state with: " + getCurrentMessage().what);
mCommand = getCurrentMessage().what; mCommand = getCurrentMessage().what;
if (mCommand != CONNECT_HID_OUTGOING && if (mCommand != CONNECT_HID_OUTGOING &&
@@ -751,7 +751,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine
} }
@Override @Override
protected boolean processMessage(Message message) { public boolean processMessage(Message message) {
log("OutgoingHid State->Processing Message: " + message.what); log("OutgoingHid State->Processing Message: " + message.what);
Message deferMsg = new Message(); Message deferMsg = new Message();
switch(message.what) { switch(message.what) {
@@ -815,12 +815,12 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine
} }
} }
private class IncomingHid extends HierarchicalState { private class IncomingHid extends State {
private boolean mStatus = false; private boolean mStatus = false;
private int mCommand; private int mCommand;
@Override @Override
protected void enter() { public void enter() {
log("Entering IncomingHid state with: " + getCurrentMessage().what); log("Entering IncomingHid state with: " + getCurrentMessage().what);
mCommand = getCurrentMessage().what; mCommand = getCurrentMessage().what;
if (mCommand != CONNECT_HID_INCOMING && if (mCommand != CONNECT_HID_INCOMING &&
@@ -832,7 +832,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine
} }
@Override @Override
protected boolean processMessage(Message message) { public boolean processMessage(Message message) {
log("IncomingHid State->Processing Message: " + message.what); log("IncomingHid State->Processing Message: " + message.what);
Message deferMsg = new Message(); Message deferMsg = new Message();
switch(message.what) { switch(message.what) {

View File

@@ -22,8 +22,8 @@ import android.content.IntentFilter;
import android.os.Message; import android.os.Message;
import android.util.Log; import android.util.Log;
import com.android.internal.util.HierarchicalState; import com.android.internal.util.State;
import com.android.internal.util.HierarchicalStateMachine; import com.android.internal.util.StateMachine;
/** /**
* This state machine is used to serialize the connections * This state machine is used to serialize the connections
@@ -39,7 +39,7 @@ import com.android.internal.util.HierarchicalStateMachine;
* @hide * @hide
*/ */
public class BluetoothProfileState extends HierarchicalStateMachine { public class BluetoothProfileState extends StateMachine {
private static final boolean DBG = true; private static final boolean DBG = true;
private static final String TAG = "BluetoothProfileState"; private static final String TAG = "BluetoothProfileState";
@@ -101,15 +101,15 @@ public class BluetoothProfileState extends HierarchicalStateMachine {
context.registerReceiver(mBroadcastReceiver, filter); context.registerReceiver(mBroadcastReceiver, filter);
} }
private class StableState extends HierarchicalState { private class StableState extends State {
@Override @Override
protected void enter() { public void enter() {
log("Entering Stable State"); log("Entering Stable State");
mPendingDevice = null; mPendingDevice = null;
} }
@Override @Override
protected boolean processMessage(Message msg) { public boolean processMessage(Message msg) {
if (msg.what != TRANSITION_TO_STABLE) { if (msg.what != TRANSITION_TO_STABLE) {
transitionTo(mPendingCommandState); transitionTo(mPendingCommandState);
} }
@@ -117,15 +117,15 @@ public class BluetoothProfileState extends HierarchicalStateMachine {
} }
} }
private class PendingCommandState extends HierarchicalState { private class PendingCommandState extends State {
@Override @Override
protected void enter() { public void enter() {
log("Entering PendingCommandState State"); log("Entering PendingCommandState State");
dispatchMessage(getCurrentMessage()); dispatchMessage(getCurrentMessage());
} }
@Override @Override
protected boolean processMessage(Message msg) { public boolean processMessage(Message msg) {
if (msg.what == TRANSITION_TO_STABLE) { if (msg.what == TRANSITION_TO_STABLE) {
transitionTo(mStableState); transitionTo(mStableState);
} else { } else {

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -21,21 +21,29 @@ import android.os.Message;
/** /**
* {@hide} * {@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. * 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 * Called when a message is to be processed by the
@@ -49,28 +57,15 @@ public class HierarchicalState {
* be processed until this routine returns. * be processed until this routine returns.
* *
* @param msg to process * @param msg to process
* @return true if processing has completed and false * @return HANDLED if processing has completed and NOT_HANDLED
* if the parent state's processMessage should * if the message wasn't processed.
* be invoked.
*/ */
protected boolean processMessage(Message msg) { boolean processMessage(Message msg);
return false;
}
/** /**
* Called when a state is exited. * Name of State for debugging purposes.
*
* @return name of state.
*/ */
protected void exit() { String getName();
}
/**
* @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);
}
} }

View File

@@ -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);
}
}

View File

@@ -29,10 +29,10 @@ import java.util.Vector;
/** /**
* {@hide} * {@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> * 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>. * <code>processMessage</code> and optionally <code>enter/exit/getName</code>.
* The enter/exit methods are equivalent to the construction and destruction * The enter/exit methods are equivalent to the construction and destruction
* in Object Oriented programming and are used to perform initialization and * in Object Oriented programming and are used to perform initialization and
@@ -76,7 +76,7 @@ import java.util.Vector;
* will exit the current state and its parent and then exit from the controlling thread * will exit the current state and its parent and then exit from the controlling thread
* and no further messages will be processed.</p> * 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> * 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 * <p>Since the states are arranged in a hierarchy transitioning to a new state
@@ -122,11 +122,11 @@ import java.util.Vector;
* mS4.enter. The new list of active states is mP0, mP1, mS2 and mS4. So * 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> * 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> * It responds with "Hello World" being printed to the log for every message.</p>
<code> <code>
class HelloWorld extends HierarchicalStateMachine { class HelloWorld extends StateMachine {
Hsm1(String name) { HelloWorld(String name) {
super(name); super(name);
addState(mState1); addState(mState1);
setInitialState(mState1); setInitialState(mState1);
@@ -138,7 +138,7 @@ class HelloWorld extends HierarchicalStateMachine {
return hw; return hw;
} }
class State1 extends HierarchicalState { class State1 extends State {
&#64;Override public boolean processMessage(Message message) { &#64;Override public boolean processMessage(Message message) {
Log.d(TAG, "Hello World"); Log.d(TAG, "Hello World");
return HANDLED; return HANDLED;
@@ -221,9 +221,9 @@ state mP2 {
} }
} }
</code> </code>
* <p>The implementation is below and also in HierarchicalStateMachineTest:</p> * <p>The implementation is below and also in StateMachineTest:</p>
<code> <code>
class Hsm1 extends HierarchicalStateMachine { class Hsm1 extends StateMachine {
private static final String TAG = "hsm1"; private static final String TAG = "hsm1";
public static final int CMD_1 = 1; public static final int CMD_1 = 1;
@@ -255,7 +255,7 @@ class Hsm1 extends HierarchicalStateMachine {
Log.d(TAG, "ctor X"); Log.d(TAG, "ctor X");
} }
class P1 extends HierarchicalState { class P1 extends State {
&#64;Override public void enter() { &#64;Override public void enter() {
Log.d(TAG, "mP1.enter"); Log.d(TAG, "mP1.enter");
} }
@@ -282,7 +282,7 @@ class Hsm1 extends HierarchicalStateMachine {
} }
} }
class S1 extends HierarchicalState { class S1 extends State {
&#64;Override public void enter() { &#64;Override public void enter() {
Log.d(TAG, "mS1.enter"); Log.d(TAG, "mS1.enter");
} }
@@ -302,7 +302,7 @@ class Hsm1 extends HierarchicalStateMachine {
} }
} }
class S2 extends HierarchicalState { class S2 extends State {
&#64;Override public void enter() { &#64;Override public void enter() {
Log.d(TAG, "mS2.enter"); Log.d(TAG, "mS2.enter");
} }
@@ -330,7 +330,7 @@ class Hsm1 extends HierarchicalStateMachine {
} }
} }
class P2 extends HierarchicalState { class P2 extends State {
&#64;Override public void enter() { &#64;Override public void enter() {
Log.d(TAG, "mP2.enter"); Log.d(TAG, "mP2.enter");
sendMessage(obtainMessage(CMD_5)); sendMessage(obtainMessage(CMD_5));
@@ -409,16 +409,16 @@ D/hsm1 ( 1999): mP2.exit
D/hsm1 ( 1999): halting D/hsm1 ( 1999): halting
</code> </code>
*/ */
public class HierarchicalStateMachine { public class StateMachine {
private static final String TAG = "HierarchicalStateMachine"; private static final String TAG = "StateMachine";
private String mName; private String mName;
/** Message.what value when quitting */ /** 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 */ /** 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 * Convenience constant that maybe returned by processMessage
@@ -441,8 +441,8 @@ public class HierarchicalStateMachine {
*/ */
public static class ProcessedMessageInfo { public static class ProcessedMessageInfo {
private int what; private int what;
private HierarchicalState state; private State state;
private HierarchicalState orgState; private State orgState;
/** /**
* Constructor * Constructor
@@ -451,7 +451,7 @@ public class HierarchicalStateMachine {
* @param orgState is the first state the received the message but * @param orgState is the first state the received the message but
* did not processes the message. * did not processes the message.
*/ */
ProcessedMessageInfo(Message message, HierarchicalState state, HierarchicalState orgState) { ProcessedMessageInfo(Message message, State state, State orgState) {
update(message, state, orgState); update(message, state, orgState);
} }
@@ -461,7 +461,7 @@ public class HierarchicalStateMachine {
* @param orgState is the first state the received the message but * @param orgState is the first state the received the message but
* did not processes the message. * 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.what = message.what;
this.state = state; this.state = state;
this.orgState = orgState; this.orgState = orgState;
@@ -477,14 +477,14 @@ public class HierarchicalStateMachine {
/** /**
* @return the state that handled this message * @return the state that handled this message
*/ */
public HierarchicalState getState() { public State getState() {
return state; return state;
} }
/** /**
* @return the original state that received the message. * @return the original state that received the message.
*/ */
public HierarchicalState getOriginalState() { public State getOriginalState() {
return orgState; return orgState;
} }
@@ -593,7 +593,7 @@ public class HierarchicalStateMachine {
* @param orgState is the first state the received the message but * @param orgState is the first state the received the message but
* did not processes the message. * did not processes the message.
*/ */
void add(Message message, HierarchicalState state, HierarchicalState orgState) { void add(Message message, State state, State orgState) {
mCount += 1; mCount += 1;
if (mMessages.size() < mMaxSize) { if (mMessages.size() < mMaxSize) {
mMessages.add(new ProcessedMessageInfo(message, state, orgState)); mMessages.add(new ProcessedMessageInfo(message, state, orgState));
@@ -608,7 +608,7 @@ public class HierarchicalStateMachine {
} }
} }
private static class HsmHandler extends Handler { private static class SmHandler extends Handler {
/** The debug flag */ /** The debug flag */
private boolean mDbg = false; private boolean mDbg = false;
@@ -643,8 +643,8 @@ public class HierarchicalStateMachine {
/** State used when state machine is quitting */ /** State used when state machine is quitting */
private QuittingState mQuittingState = new QuittingState(); private QuittingState mQuittingState = new QuittingState();
/** Reference to the HierarchicalStateMachine */ /** Reference to the StateMachine */
private HierarchicalStateMachine mHsm; private StateMachine mSm;
/** /**
* Information about a state. * Information about a state.
@@ -652,7 +652,7 @@ public class HierarchicalStateMachine {
*/ */
private class StateInfo { private class StateInfo {
/** The state */ /** The state */
HierarchicalState state; State state;
/** The parent of this state, null if there is no parent */ /** The parent of this state, null if there is no parent */
StateInfo parentStateInfo; StateInfo parentStateInfo;
@@ -672,14 +672,14 @@ public class HierarchicalStateMachine {
} }
/** The map of all of the states in the state machine */ /** The map of all of the states in the state machine */
private HashMap<HierarchicalState, StateInfo> mStateInfo = private HashMap<State, StateInfo> mStateInfo =
new HashMap<HierarchicalState, StateInfo>(); new HashMap<State, StateInfo>();
/** The initial state that will process the first message */ /** The initial state that will process the first message */
private HierarchicalState mInitialState; private State mInitialState;
/** The destination state when transitionTo has been invoked */ /** The destination state when transitionTo has been invoked */
private HierarchicalState mDestState; private State mDestState;
/** The list of deferred messages */ /** The list of deferred messages */
private ArrayList<Message> mDeferredMessages = new ArrayList<Message>(); private ArrayList<Message> mDeferredMessages = new ArrayList<Message>();
@@ -687,10 +687,10 @@ public class HierarchicalStateMachine {
/** /**
* State entered when transitionToHaltingState is called. * State entered when transitionToHaltingState is called.
*/ */
private class HaltingState extends HierarchicalState { private class HaltingState extends State {
@Override @Override
public boolean processMessage(Message msg) { public boolean processMessage(Message msg) {
mHsm.haltedProcessMessage(msg); mSm.haltedProcessMessage(msg);
return true; return true;
} }
} }
@@ -698,7 +698,7 @@ public class HierarchicalStateMachine {
/** /**
* State entered when a valid quit message is handled. * State entered when a valid quit message is handled.
*/ */
private class QuittingState extends HierarchicalState { private class QuittingState extends State {
@Override @Override
public boolean processMessage(Message msg) { public boolean processMessage(Message msg) {
return NOT_HANDLED; return NOT_HANDLED;
@@ -745,7 +745,7 @@ public class HierarchicalStateMachine {
* the appropriate states. We loop on this to allow * the appropriate states. We loop on this to allow
* enter and exit methods to use transitionTo. * enter and exit methods to use transitionTo.
*/ */
HierarchicalState destState = null; State destState = null;
while (mDestState != null) { while (mDestState != null) {
if (mDbg) Log.d(TAG, "handleMessage: new destination call exit"); if (mDbg) Log.d(TAG, "handleMessage: new destination call exit");
@@ -785,11 +785,11 @@ public class HierarchicalStateMachine {
/** /**
* We are quitting so ignore all messages. * We are quitting so ignore all messages.
*/ */
mHsm.quitting(); mSm.quitting();
if (mHsm.mHsmThread != null) { if (mSm.mSmThread != null) {
// If we made the thread then quit looper which stops the thread. // If we made the thread then quit looper which stops the thread.
getLooper().quit(); getLooper().quit();
mHsm.mHsmThread = null; mSm.mSmThread = null;
} }
} else if (destState == mHaltingState) { } else if (destState == mHaltingState) {
/** /**
@@ -797,7 +797,7 @@ public class HierarchicalStateMachine {
* state. All subsequent messages will be processed in * state. All subsequent messages will be processed in
* in the halting state which invokes haltedProcessMessage(msg); * in the halting state which invokes haltedProcessMessage(msg);
*/ */
mHsm.halting(); mSm.halting();
} }
} }
} }
@@ -833,7 +833,7 @@ public class HierarchicalStateMachine {
* starting at the first entry. * starting at the first entry.
*/ */
mIsConstructionCompleted = true; mIsConstructionCompleted = true;
mMsg = obtainMessage(HSM_INIT_CMD); mMsg = obtainMessage(SM_INIT_CMD);
invokeEnterMethods(0); invokeEnterMethods(0);
/** /**
@@ -863,7 +863,7 @@ public class HierarchicalStateMachine {
/** /**
* No parents left so it's not handled * No parents left so it's not handled
*/ */
mHsm.unhandledMessage(msg); mSm.unhandledMessage(msg);
if (isQuit(msg)) { if (isQuit(msg)) {
transitionTo(mQuittingState); transitionTo(mQuittingState);
} }
@@ -878,7 +878,7 @@ public class HierarchicalStateMachine {
* Record that we processed the message * Record that we processed the message
*/ */
if (curStateInfo != null) { if (curStateInfo != null) {
HierarchicalState orgState = mStateStack[mStateStackTopIndex].state; State orgState = mStateStack[mStateStackTopIndex].state;
mProcessedMessages.add(msg, curStateInfo.state, orgState); mProcessedMessages.add(msg, curStateInfo.state, orgState);
} else { } else {
mProcessedMessages.add(msg, null, null); mProcessedMessages.add(msg, null, null);
@@ -892,7 +892,7 @@ public class HierarchicalStateMachine {
private final void invokeExitMethods(StateInfo commonStateInfo) { private final void invokeExitMethods(StateInfo commonStateInfo) {
while ((mStateStackTopIndex >= 0) && while ((mStateStackTopIndex >= 0) &&
(mStateStack[mStateStackTopIndex] != commonStateInfo)) { (mStateStack[mStateStackTopIndex] != commonStateInfo)) {
HierarchicalState curState = mStateStack[mStateStackTopIndex].state; State curState = mStateStack[mStateStackTopIndex].state;
if (mDbg) Log.d(TAG, "invokeExitMethods: " + curState.getName()); if (mDbg) Log.d(TAG, "invokeExitMethods: " + curState.getName());
curState.exit(); curState.exit();
mStateStack[mStateStackTopIndex].active = false; mStateStack[mStateStackTopIndex].active = false;
@@ -934,7 +934,7 @@ public class HierarchicalStateMachine {
* reversing the order of the items on the temporary stack as * reversing the order of the items on the temporary stack as
* they are moved. * 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() { private final int moveTempStateStackToStateStack() {
int startingIndex = mStateStackTopIndex + 1; int startingIndex = mStateStackTopIndex + 1;
@@ -967,7 +967,7 @@ public class HierarchicalStateMachine {
* @return StateInfo of the common ancestor for the destState and * @return StateInfo of the common ancestor for the destState and
* current state or null if there is no common parent. * 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 * 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 * state. Use a do while() loop as the destState must always be entered
@@ -1019,7 +1019,7 @@ public class HierarchicalStateMachine {
/** /**
* @return current state * @return current state
*/ */
private final HierarchicalState getCurrentState() { private final IState getCurrentState() {
return mStateStack[mStateStackTopIndex].state; return mStateStack[mStateStackTopIndex].state;
} }
@@ -1032,7 +1032,7 @@ public class HierarchicalStateMachine {
* @param parent the parent of state * @param parent the parent of state
* @return stateInfo for this state * @return stateInfo for this state
*/ */
private final StateInfo addState(HierarchicalState state, HierarchicalState parent) { private final StateInfo addState(State state, State parent) {
if (mDbg) { if (mDbg) {
Log.d(TAG, "addStateInternal: E state=" + state.getName() Log.d(TAG, "addStateInternal: E state=" + state.getName()
+ ",parent=" + ((parent == null) ? "" : parent.getName())); + ",parent=" + ((parent == null) ? "" : parent.getName()));
@@ -1067,29 +1067,29 @@ public class HierarchicalStateMachine {
* Constructor * Constructor
* *
* @param looper for dispatching messages * @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); super(looper);
mHsm = hsm; mSm = sm;
addState(mHaltingState, null); addState(mHaltingState, null);
addState(mQuittingState, null); addState(mQuittingState, null);
} }
/** @see HierarchicalStateMachine#setInitialState(HierarchicalState) */ /** @see StateMachine#setInitialState(State) */
private final void setInitialState(HierarchicalState initialState) { private final void setInitialState(State initialState) {
if (mDbg) Log.d(TAG, "setInitialState: initialState" + initialState.getName()); if (mDbg) Log.d(TAG, "setInitialState: initialState" + initialState.getName());
mInitialState = initialState; mInitialState = initialState;
} }
/** @see HierarchicalStateMachine#transitionTo(HierarchicalState) */ /** @see StateMachine#transitionTo(IState) */
private final void transitionTo(HierarchicalState destState) { private final void transitionTo(IState destState) {
if (mDbg) Log.d(TAG, "StateMachine.transitionTo EX destState" + destState.getName()); mDestState = (State) destState;
mDestState = 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) { private final void deferMessage(Message msg) {
if (mDbg) Log.d(TAG, "deferMessage: msg=" + msg.what); if (mDbg) Log.d(TAG, "deferMessage: msg=" + msg.what);
@@ -1100,51 +1100,51 @@ public class HierarchicalStateMachine {
mDeferredMessages.add(newMsg); mDeferredMessages.add(newMsg);
} }
/** @see HierarchicalStateMachine#deferMessage(Message) */ /** @see StateMachine#deferMessage(Message) */
private final void quit() { private final void quit() {
if (mDbg) Log.d(TAG, "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) { 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() { private final boolean isDbg() {
return mDbg; return mDbg;
} }
/** @see HierarchicalStateMachine#setDbg(boolean) */ /** @see StateMachine#setDbg(boolean) */
private final void setDbg(boolean dbg) { private final void setDbg(boolean dbg) {
mDbg = dbg; mDbg = dbg;
} }
/** @see HierarchicalStateMachine#setProcessedMessagesSize(int) */ /** @see StateMachine#setProcessedMessagesSize(int) */
private final void setProcessedMessagesSize(int maxSize) { private final void setProcessedMessagesSize(int maxSize) {
mProcessedMessages.setSize(maxSize); mProcessedMessages.setSize(maxSize);
} }
/** @see HierarchicalStateMachine#getProcessedMessagesSize() */ /** @see StateMachine#getProcessedMessagesSize() */
private final int getProcessedMessagesSize() { private final int getProcessedMessagesSize() {
return mProcessedMessages.size(); return mProcessedMessages.size();
} }
/** @see HierarchicalStateMachine#getProcessedMessagesCount() */ /** @see StateMachine#getProcessedMessagesCount() */
private final int getProcessedMessagesCount() { private final int getProcessedMessagesCount() {
return mProcessedMessages.count(); return mProcessedMessages.count();
} }
/** @see HierarchicalStateMachine#getProcessedMessageInfo(int) */ /** @see StateMachine#getProcessedMessageInfo(int) */
private final ProcessedMessageInfo getProcessedMessageInfo(int index) { private final ProcessedMessageInfo getProcessedMessageInfo(int index) {
return mProcessedMessages.get(index); return mProcessedMessages.get(index);
} }
} }
private HsmHandler mHsmHandler; private SmHandler mSmHandler;
private HandlerThread mHsmThread; private HandlerThread mSmThread;
/** /**
* Initialize. * Initialize.
@@ -1154,28 +1154,28 @@ public class HierarchicalStateMachine {
*/ */
private void initStateMachine(String name, Looper looper) { private void initStateMachine(String name, Looper looper) {
mName = name; 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 * @param name of the state machine
*/ */
protected HierarchicalStateMachine(String name) { protected StateMachine(String name) {
mHsmThread = new HandlerThread(name); mSmThread = new HandlerThread(name);
mHsmThread.start(); mSmThread.start();
Looper looper = mHsmThread.getLooper(); Looper looper = mSmThread.getLooper();
initStateMachine(name, looper); initStateMachine(name, looper);
} }
/** /**
* Constructor creates an HSMStateMachine using the looper. * Constructor creates an StateMachine using the looper.
* *
* @param name of the state machine * @param name of the state machine
*/ */
protected HierarchicalStateMachine(String name, Looper looper) { protected StateMachine(String name, Looper looper) {
initStateMachine(name, looper); initStateMachine(name, looper);
} }
@@ -1184,30 +1184,30 @@ public class HierarchicalStateMachine {
* @param state the state to add * @param state the state to add
* @param parent the parent of state * @param parent the parent of state
*/ */
protected final void addState(HierarchicalState state, HierarchicalState parent) { protected final void addState(State state, State parent) {
mHsmHandler.addState(state, parent); mSmHandler.addState(state, parent);
} }
/** /**
* @return current message * @return current message
*/ */
protected final Message getCurrentMessage() { protected final Message getCurrentMessage() {
return mHsmHandler.getCurrentMessage(); return mSmHandler.getCurrentMessage();
} }
/** /**
* @return current state * @return current state
*/ */
protected final HierarchicalState getCurrentState() { protected final IState getCurrentState() {
return mHsmHandler.getCurrentState(); return mSmHandler.getCurrentState();
} }
/** /**
* Add a new state to the state machine, parent will be null * Add a new state to the state machine, parent will be null
* @param state to add * @param state to add
*/ */
protected final void addState(HierarchicalState state) { protected final void addState(State state) {
mHsmHandler.addState(state, null); mSmHandler.addState(state, null);
} }
/** /**
@@ -1216,8 +1216,8 @@ public class HierarchicalStateMachine {
* *
* @param initialState is the state which will receive the first message. * @param initialState is the state which will receive the first message.
*/ */
protected final void setInitialState(HierarchicalState initialState) { protected final void setInitialState(State initialState) {
mHsmHandler.setInitialState(initialState); mSmHandler.setInitialState(initialState);
} }
/** /**
@@ -1228,8 +1228,8 @@ public class HierarchicalStateMachine {
* *
* @param destState will be the state that receives the next message. * @param destState will be the state that receives the next message.
*/ */
protected final void transitionTo(HierarchicalState destState) { protected final void transitionTo(IState destState) {
mHsmHandler.transitionTo(destState); mSmHandler.transitionTo(destState);
} }
/** /**
@@ -1240,7 +1240,7 @@ public class HierarchicalStateMachine {
* will be called. * will be called.
*/ */
protected final void transitionToHaltingState() { protected final void transitionToHaltingState() {
mHsmHandler.transitionTo(mHsmHandler.mHaltingState); mSmHandler.transitionTo(mSmHandler.mHaltingState);
} }
/** /**
@@ -1253,7 +1253,7 @@ public class HierarchicalStateMachine {
* @param msg is deferred until the next transition. * @param msg is deferred until the next transition.
*/ */
protected final void deferMessage(Message msg) { protected final void deferMessage(Message msg) {
mHsmHandler.deferMessage(msg); mSmHandler.deferMessage(msg);
} }
@@ -1263,7 +1263,7 @@ public class HierarchicalStateMachine {
* @param msg that couldn't be handled. * @param msg that couldn't be handled.
*/ */
protected void unhandledMessage(Message msg) { 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 @@ public class HierarchicalStateMachine {
/** /**
* This will be called once after handling a message that called * This will be called once after handling a message that called
* transitionToHalting. All subsequent messages will invoke * transitionToHalting. All subsequent messages will invoke
* {@link HierarchicalStateMachine#haltedProcessMessage(Message)} * {@link StateMachine#haltedProcessMessage(Message)}
*/ */
protected void halting() { protected void halting() {
} }
/** /**
* This will be called once after a quit message that was NOT handled by * 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 * the derived StateMachine. The StateMachine will stop and any subsequent messages will be
* ignored. In addition, if this HSM created the thread, the thread will * ignored. In addition, if this StateMachine created the thread, the thread will
* be stopped after this method returns. * be stopped after this method returns.
*/ */
protected void quitting() { protected void quitting() {
@@ -1303,35 +1303,35 @@ public class HierarchicalStateMachine {
* @param maxSize number of messages to maintain at anyone time. * @param maxSize number of messages to maintain at anyone time.
*/ */
public final void setProcessedMessagesSize(int maxSize) { public final void setProcessedMessagesSize(int maxSize) {
mHsmHandler.setProcessedMessagesSize(maxSize); mSmHandler.setProcessedMessagesSize(maxSize);
} }
/** /**
* @return number of messages processed * @return number of messages processed
*/ */
public final int getProcessedMessagesSize() { public final int getProcessedMessagesSize() {
return mHsmHandler.getProcessedMessagesSize(); return mSmHandler.getProcessedMessagesSize();
} }
/** /**
* @return the total number of messages processed * @return the total number of messages processed
*/ */
public final int getProcessedMessagesCount() { public final int getProcessedMessagesCount() {
return mHsmHandler.getProcessedMessagesCount(); return mSmHandler.getProcessedMessagesCount();
} }
/** /**
* @return a processed message information * @return a processed message information
*/ */
public final ProcessedMessageInfo getProcessedMessageInfo(int index) { public final ProcessedMessageInfo getProcessedMessageInfo(int index) {
return mHsmHandler.getProcessedMessageInfo(index); return mSmHandler.getProcessedMessageInfo(index);
} }
/** /**
* @return Handler * @return Handler
*/ */
public final Handler getHandler() { public final Handler getHandler() {
return mHsmHandler; return mSmHandler;
} }
/** /**
@@ -1341,7 +1341,7 @@ public class HierarchicalStateMachine {
*/ */
public final Message obtainMessage() public final Message obtainMessage()
{ {
return Message.obtain(mHsmHandler); return Message.obtain(mSmHandler);
} }
/** /**
@@ -1351,7 +1351,7 @@ public class HierarchicalStateMachine {
* @return message * @return message
*/ */
public final Message obtainMessage(int what) { public final Message obtainMessage(int what) {
return Message.obtain(mHsmHandler, what); return Message.obtain(mSmHandler, what);
} }
/** /**
@@ -1364,7 +1364,7 @@ public class HierarchicalStateMachine {
*/ */
public final Message obtainMessage(int what, Object obj) 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 class HierarchicalStateMachine {
*/ */
public final Message obtainMessage(int what, int arg1, int arg2) 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 class HierarchicalStateMachine {
*/ */
public final Message obtainMessage(int what, int arg1, int arg2, Object obj) 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. * Enqueue a message to this state machine.
*/ */
public final void sendMessage(int what) { public final void sendMessage(int what) {
mHsmHandler.sendMessage(obtainMessage(what)); mSmHandler.sendMessage(obtainMessage(what));
} }
/** /**
* Enqueue a message to this state machine. * Enqueue a message to this state machine.
*/ */
public final void sendMessage(int what, Object obj) { 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. * Enqueue a message to this state machine.
*/ */
public final void sendMessage(Message msg) { public final void sendMessage(Message msg) {
mHsmHandler.sendMessage(msg); mSmHandler.sendMessage(msg);
} }
/** /**
* Enqueue a message to this state machine after a delay. * Enqueue a message to this state machine after a delay.
*/ */
public final void sendMessageDelayed(int what, long delayMillis) { 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. * Enqueue a message to this state machine after a delay.
*/ */
public final void sendMessageDelayed(int what, Object obj, long delayMillis) { 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. * Enqueue a message to this state machine after a delay.
*/ */
public final void sendMessageDelayed(Message msg, long delayMillis) { 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. * 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) { 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. * 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) { 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. * 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) { protected final void sendMessageAtFrontOfQueue(Message msg) {
mHsmHandler.sendMessageAtFrontOfQueue(msg); mSmHandler.sendMessageAtFrontOfQueue(msg);
} }
/** /**
* Removes a message from the message queue. * 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) { protected final void removeMessages(int what) {
mHsmHandler.removeMessages(what); mSmHandler.removeMessages(what);
} }
/** /**
* Conditionally quit the looper and stop execution. * 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 * if not handled by any state's processMessage then the
* state machine will be stopped and no further messages * state machine will be stopped and no further messages
* will be processed. * will be processed.
*/ */
public final void quit() { public final void quit() {
mHsmHandler.quit(); mSmHandler.quit();
} }
/** /**
* @return ture if msg is quit * @return ture if msg is quit
*/ */
protected final boolean isQuit(Message msg) { protected final boolean isQuit(Message msg) {
return mHsmHandler.isQuit(msg); return mSmHandler.isQuit(msg);
} }
/** /**
* @return if debugging is enabled * @return if debugging is enabled
*/ */
public boolean isDbg() { public boolean isDbg() {
return mHsmHandler.isDbg(); return mSmHandler.isDbg();
} }
/** /**
@@ -1502,7 +1502,7 @@ public class HierarchicalStateMachine {
* @param dbg is true to enable debugging. * @param dbg is true to enable debugging.
*/ */
public void setDbg(boolean dbg) { public void setDbg(boolean dbg) {
mHsmHandler.setDbg(dbg); mSmHandler.setDbg(dbg);
} }
/** /**
@@ -1510,6 +1510,6 @@ public class HierarchicalStateMachine {
*/ */
public void start() { public void start() {
/** Send the complete construction message */ /** Send the complete construction message */
mHsmHandler.completeConstruction(); mSmHandler.completeConstruction();
} }
} }

View File

@@ -22,9 +22,9 @@ import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.os.SystemClock; import android.os.SystemClock;
import com.android.internal.util.HierarchicalState; import com.android.internal.util.State;
import com.android.internal.util.HierarchicalStateMachine; import com.android.internal.util.StateMachine;
import com.android.internal.util.HierarchicalStateMachine.ProcessedMessageInfo; import com.android.internal.util.StateMachine.ProcessedMessageInfo;
import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.SmallTest;
@@ -33,9 +33,9 @@ import android.util.Log;
import junit.framework.TestCase; 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_1 = 1;
private static final int TEST_CMD_2 = 2; private static final int TEST_CMD_2 = 2;
private static final int TEST_CMD_3 = 3; private static final int TEST_CMD_3 = 3;
@@ -45,12 +45,12 @@ public class HierarchicalStateMachineTest extends TestCase {
private static final boolean DBG = true; private static final boolean DBG = true;
private static final boolean WAIT_FOR_DEBUGGER = false; 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. * Tests that we can quit the state machine.
*/ */
class StateMachineQuitTest extends HierarchicalStateMachine { class StateMachineQuitTest extends StateMachine {
private int mQuitCount = 0; private int mQuitCount = 0;
StateMachineQuitTest(String name) { StateMachineQuitTest(String name) {
@@ -65,8 +65,9 @@ public class HierarchicalStateMachineTest extends TestCase {
setInitialState(mS1); setInitialState(mS1);
} }
class S1 extends HierarchicalState { class S1 extends State {
@Override protected boolean processMessage(Message message) { @Override
public boolean processMessage(Message message) {
if (isQuit(message)) { if (isQuit(message)) {
mQuitCount += 1; mQuitCount += 1;
if (mQuitCount > 2) { if (mQuitCount > 2) {
@@ -129,18 +130,18 @@ public class HierarchicalStateMachineTest extends TestCase {
// The first two message didn't quit and were handled by mS1 // The first two message didn't quit and were handled by mS1
pmi = smQuitTest.getProcessedMessageInfo(6); 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.getState());
assertEquals(smQuitTest.mS1, pmi.getOriginalState()); assertEquals(smQuitTest.mS1, pmi.getOriginalState());
pmi = smQuitTest.getProcessedMessageInfo(7); 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.getState());
assertEquals(smQuitTest.mS1, pmi.getOriginalState()); assertEquals(smQuitTest.mS1, pmi.getOriginalState());
// The last message was never handled so the states are null // The last message was never handled so the states are null
pmi = smQuitTest.getProcessedMessageInfo(8); 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.getState());
assertEquals(null, pmi.getOriginalState()); assertEquals(null, pmi.getOriginalState());
@@ -150,7 +151,7 @@ public class HierarchicalStateMachineTest extends TestCase {
/** /**
* Test enter/exit can use transitionTo * Test enter/exit can use transitionTo
*/ */
class StateMachineEnterExitTransitionToTest extends HierarchicalStateMachine { class StateMachineEnterExitTransitionToTest extends StateMachine {
StateMachineEnterExitTransitionToTest(String name) { StateMachineEnterExitTransitionToTest(String name) {
super(name); super(name);
mThisSm = this; mThisSm = this;
@@ -166,34 +167,38 @@ public class HierarchicalStateMachineTest extends TestCase {
setInitialState(mS1); setInitialState(mS1);
} }
class S1 extends HierarchicalState { class S1 extends State {
@Override protected void enter() { @Override
public void enter() {
// Test that message is HSM_INIT_CMD // 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 // Test that a transition in enter and the initial state works
mS1EnterCount += 1; mS1EnterCount += 1;
transitionTo(mS2); transitionTo(mS2);
Log.d(TAG, "S1.enter"); Log.d(TAG, "S1.enter");
} }
@Override protected void exit() { @Override
public void exit() {
// Test that message is HSM_INIT_CMD // Test that message is HSM_INIT_CMD
assertEquals(HSM_INIT_CMD, getCurrentMessage().what); assertEquals(SM_INIT_CMD, getCurrentMessage().what);
mS1ExitCount += 1; mS1ExitCount += 1;
Log.d(TAG, "S1.exit"); Log.d(TAG, "S1.exit");
} }
} }
class S2 extends HierarchicalState { class S2 extends State {
@Override protected void enter() { @Override
public void enter() {
// Test that message is HSM_INIT_CMD // Test that message is HSM_INIT_CMD
assertEquals(HSM_INIT_CMD, getCurrentMessage().what); assertEquals(SM_INIT_CMD, getCurrentMessage().what);
mS2EnterCount += 1; mS2EnterCount += 1;
Log.d(TAG, "S2.enter"); Log.d(TAG, "S2.enter");
} }
@Override protected void exit() { @Override
public void exit() {
// Test that message is TEST_CMD_1 // Test that message is TEST_CMD_1
assertEquals(TEST_CMD_1, getCurrentMessage().what); assertEquals(TEST_CMD_1, getCurrentMessage().what);
@@ -202,7 +207,8 @@ public class HierarchicalStateMachineTest extends TestCase {
transitionTo(mS4); transitionTo(mS4);
Log.d(TAG, "S2.exit"); 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 // Start a transition to S3 but it will be
// changed to a transition to S4 in exit // changed to a transition to S4 in exit
transitionTo(mS3); transitionTo(mS3);
@@ -211,28 +217,32 @@ public class HierarchicalStateMachineTest extends TestCase {
} }
} }
class S3 extends HierarchicalState { class S3 extends State {
@Override protected void enter() { @Override
public void enter() {
// Test that we can do halting in an enter/exit // Test that we can do halting in an enter/exit
transitionToHaltingState(); transitionToHaltingState();
mS3EnterCount += 1; mS3EnterCount += 1;
Log.d(TAG, "S3.enter"); Log.d(TAG, "S3.enter");
} }
@Override protected void exit() { @Override
public void exit() {
mS3ExitCount += 1; mS3ExitCount += 1;
Log.d(TAG, "S3.exit"); Log.d(TAG, "S3.exit");
} }
} }
class S4 extends HierarchicalState { class S4 extends State {
@Override protected void enter() { @Override
public void enter() {
// Test that we can do halting in an enter/exit // Test that we can do halting in an enter/exit
transitionToHaltingState(); transitionToHaltingState();
mS4EnterCount += 1; mS4EnterCount += 1;
Log.d(TAG, "S4.enter"); Log.d(TAG, "S4.enter");
} }
@Override protected void exit() { @Override
public void exit() {
mS4ExitCount += 1; mS4ExitCount += 1;
Log.d(TAG, "S4.exit"); Log.d(TAG, "S4.exit");
} }
@@ -310,7 +320,7 @@ public class HierarchicalStateMachineTest extends TestCase {
/** /**
* Tests that ProcessedMessage works as a circular buffer. * Tests that ProcessedMessage works as a circular buffer.
*/ */
class StateMachine0 extends HierarchicalStateMachine { class StateMachine0 extends StateMachine {
StateMachine0(String name) { StateMachine0(String name) {
super(name); super(name);
mThisSm = this; mThisSm = this;
@@ -324,8 +334,9 @@ public class HierarchicalStateMachineTest extends TestCase {
setInitialState(mS1); setInitialState(mS1);
} }
class S1 extends HierarchicalState { class S1 extends State {
@Override protected boolean processMessage(Message message) { @Override
public boolean processMessage(Message message) {
if (message.what == TEST_CMD_6) { if (message.what == TEST_CMD_6) {
transitionToHaltingState(); transitionToHaltingState();
} }
@@ -394,7 +405,7 @@ public class HierarchicalStateMachineTest extends TestCase {
* in state mS1. With the first message it transitions to * in state mS1. With the first message it transitions to
* itself which causes it to be exited and reentered. * itself which causes it to be exited and reentered.
*/ */
class StateMachine1 extends HierarchicalStateMachine { class StateMachine1 extends StateMachine {
StateMachine1(String name) { StateMachine1(String name) {
super(name); super(name);
mThisSm = this; mThisSm = this;
@@ -408,12 +419,17 @@ public class HierarchicalStateMachineTest extends TestCase {
if (DBG) Log.d(TAG, "StateMachine1: ctor X"); if (DBG) Log.d(TAG, "StateMachine1: ctor X");
} }
class S1 extends HierarchicalState { class S1 extends State {
@Override protected void enter() { @Override
public void enter() {
mEnterCount++; mEnterCount++;
} }
@Override
@Override protected boolean processMessage(Message message) { public void exit() {
mExitCount++;
}
@Override
public boolean processMessage(Message message) {
if (message.what == TEST_CMD_1) { if (message.what == TEST_CMD_1) {
assertEquals(1, mEnterCount); assertEquals(1, mEnterCount);
assertEquals(0, mExitCount); assertEquals(0, mExitCount);
@@ -425,10 +441,6 @@ public class HierarchicalStateMachineTest extends TestCase {
} }
return HANDLED; return HANDLED;
} }
@Override protected void exit() {
mExitCount++;
}
} }
@Override @Override
@@ -493,7 +505,7 @@ public class HierarchicalStateMachineTest extends TestCase {
* mS2 then receives both of the deferred messages first TEST_CMD_1 and * mS2 then receives both of the deferred messages first TEST_CMD_1 and
* then TEST_CMD_2. * then TEST_CMD_2.
*/ */
class StateMachine2 extends HierarchicalStateMachine { class StateMachine2 extends StateMachine {
StateMachine2(String name) { StateMachine2(String name) {
super(name); super(name);
mThisSm = this; mThisSm = this;
@@ -508,26 +520,28 @@ public class HierarchicalStateMachineTest extends TestCase {
if (DBG) Log.d(TAG, "StateMachine2: ctor X"); if (DBG) Log.d(TAG, "StateMachine2: ctor X");
} }
class S1 extends HierarchicalState { class S1 extends State {
@Override protected void enter() { @Override
public void enter() {
mDidEnter = true; mDidEnter = true;
} }
@Override
@Override protected boolean processMessage(Message message) { public void exit() {
mDidExit = true;
}
@Override
public boolean processMessage(Message message) {
deferMessage(message); deferMessage(message);
if (message.what == TEST_CMD_2) { if (message.what == TEST_CMD_2) {
transitionTo(mS2); transitionTo(mS2);
} }
return HANDLED; return HANDLED;
} }
@Override protected void exit() {
mDidExit = true;
}
} }
class S2 extends HierarchicalState { class S2 extends State {
@Override protected boolean processMessage(Message message) { @Override
public boolean processMessage(Message message) {
if (message.what == TEST_CMD_2) { if (message.what == TEST_CMD_2) {
transitionToHaltingState(); transitionToHaltingState();
} }
@@ -598,7 +612,7 @@ public class HierarchicalStateMachineTest extends TestCase {
* Test that unhandled messages in a child are handled by the parent. * Test that unhandled messages in a child are handled by the parent.
* When TEST_CMD_2 is received. * When TEST_CMD_2 is received.
*/ */
class StateMachine3 extends HierarchicalStateMachine { class StateMachine3 extends StateMachine {
StateMachine3(String name) { StateMachine3(String name) {
super(name); super(name);
mThisSm = this; mThisSm = this;
@@ -615,8 +629,9 @@ public class HierarchicalStateMachineTest extends TestCase {
if (DBG) Log.d(TAG, "StateMachine3: ctor X"); if (DBG) Log.d(TAG, "StateMachine3: ctor X");
} }
class ParentState extends HierarchicalState { class ParentState extends State {
@Override protected boolean processMessage(Message message) { @Override
public boolean processMessage(Message message) {
if (message.what == TEST_CMD_2) { if (message.what == TEST_CMD_2) {
transitionToHaltingState(); transitionToHaltingState();
} }
@@ -624,8 +639,9 @@ public class HierarchicalStateMachineTest extends TestCase {
} }
} }
class ChildState extends HierarchicalState { class ChildState extends State {
@Override protected boolean processMessage(Message message) { @Override
public boolean processMessage(Message message) {
return NOT_HANDLED; return NOT_HANDLED;
} }
} }
@@ -682,7 +698,7 @@ public class HierarchicalStateMachineTest extends TestCase {
* with transition from child 1 to child 2 and child 2 * with transition from child 1 to child 2 and child 2
* lets the parent handle the messages. * lets the parent handle the messages.
*/ */
class StateMachine4 extends HierarchicalStateMachine { class StateMachine4 extends StateMachine {
StateMachine4(String name) { StateMachine4(String name) {
super(name); super(name);
mThisSm = this; mThisSm = this;
@@ -700,8 +716,9 @@ public class HierarchicalStateMachineTest extends TestCase {
if (DBG) Log.d(TAG, "StateMachine4: ctor X"); if (DBG) Log.d(TAG, "StateMachine4: ctor X");
} }
class ParentState extends HierarchicalState { class ParentState extends State {
@Override protected boolean processMessage(Message message) { @Override
public boolean processMessage(Message message) {
if (message.what == TEST_CMD_2) { if (message.what == TEST_CMD_2) {
transitionToHaltingState(); transitionToHaltingState();
} }
@@ -709,15 +726,17 @@ public class HierarchicalStateMachineTest extends TestCase {
} }
} }
class ChildState1 extends HierarchicalState { class ChildState1 extends State {
@Override protected boolean processMessage(Message message) { @Override
public boolean processMessage(Message message) {
transitionTo(mChildState2); transitionTo(mChildState2);
return HANDLED; return HANDLED;
} }
} }
class ChildState2 extends HierarchicalState { class ChildState2 extends State {
@Override protected boolean processMessage(Message message) { @Override
public boolean processMessage(Message message) {
return NOT_HANDLED; return NOT_HANDLED;
} }
} }
@@ -775,7 +794,7 @@ public class HierarchicalStateMachineTest extends TestCase {
* Test transition from one child to another of a "complex" * Test transition from one child to another of a "complex"
* hierarchy with two parents and multiple children. * hierarchy with two parents and multiple children.
*/ */
class StateMachine5 extends HierarchicalStateMachine { class StateMachine5 extends StateMachine {
StateMachine5(String name) { StateMachine5(String name) {
super(name); super(name);
mThisSm = this; mThisSm = this;
@@ -797,23 +816,32 @@ public class HierarchicalStateMachineTest extends TestCase {
if (DBG) Log.d(TAG, "StateMachine5: ctor X"); if (DBG) Log.d(TAG, "StateMachine5: ctor X");
} }
class ParentState1 extends HierarchicalState { class ParentState1 extends State {
@Override protected void enter() { @Override
public void enter() {
mParentState1EnterCount += 1; mParentState1EnterCount += 1;
} }
@Override protected boolean processMessage(Message message) { @Override
return HANDLED; public void exit() {
}
@Override protected void exit() {
mParentState1ExitCount += 1; mParentState1ExitCount += 1;
} }
@Override
public boolean processMessage(Message message) {
return HANDLED;
}
} }
class ChildState1 extends HierarchicalState { class ChildState1 extends State {
@Override protected void enter() { @Override
public void enter() {
mChildState1EnterCount += 1; mChildState1EnterCount += 1;
} }
@Override protected boolean processMessage(Message message) { @Override
public void exit() {
mChildState1ExitCount += 1;
}
@Override
public boolean processMessage(Message message) {
assertEquals(1, mParentState1EnterCount); assertEquals(1, mParentState1EnterCount);
assertEquals(0, mParentState1ExitCount); assertEquals(0, mParentState1ExitCount);
assertEquals(1, mChildState1EnterCount); assertEquals(1, mChildState1EnterCount);
@@ -832,16 +860,19 @@ public class HierarchicalStateMachineTest extends TestCase {
transitionTo(mChildState2); transitionTo(mChildState2);
return HANDLED; return HANDLED;
} }
@Override protected void exit() {
mChildState1ExitCount += 1;
}
} }
class ChildState2 extends HierarchicalState { class ChildState2 extends State {
@Override protected void enter() { @Override
public void enter() {
mChildState2EnterCount += 1; mChildState2EnterCount += 1;
} }
@Override protected boolean processMessage(Message message) { @Override
public void exit() {
mChildState2ExitCount += 1;
}
@Override
public boolean processMessage(Message message) {
assertEquals(1, mParentState1EnterCount); assertEquals(1, mParentState1EnterCount);
assertEquals(0, mParentState1ExitCount); assertEquals(0, mParentState1ExitCount);
assertEquals(1, mChildState1EnterCount); assertEquals(1, mChildState1EnterCount);
@@ -860,16 +891,19 @@ public class HierarchicalStateMachineTest extends TestCase {
transitionTo(mChildState5); transitionTo(mChildState5);
return HANDLED; return HANDLED;
} }
@Override protected void exit() {
mChildState2ExitCount += 1;
}
} }
class ParentState2 extends HierarchicalState { class ParentState2 extends State {
@Override protected void enter() { @Override
public void enter() {
mParentState2EnterCount += 1; 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, mParentState1EnterCount);
assertEquals(1, mParentState1ExitCount); assertEquals(1, mParentState1ExitCount);
assertEquals(1, mChildState1EnterCount); assertEquals(1, mChildState1EnterCount);
@@ -888,16 +922,19 @@ public class HierarchicalStateMachineTest extends TestCase {
transitionToHaltingState(); transitionToHaltingState();
return HANDLED; return HANDLED;
} }
@Override protected void exit() {
mParentState2ExitCount += 1;
}
} }
class ChildState3 extends HierarchicalState { class ChildState3 extends State {
@Override protected void enter() { @Override
public void enter() {
mChildState3EnterCount += 1; 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, mParentState1EnterCount);
assertEquals(1, mParentState1ExitCount); assertEquals(1, mParentState1ExitCount);
assertEquals(1, mChildState1EnterCount); assertEquals(1, mChildState1EnterCount);
@@ -916,16 +953,19 @@ public class HierarchicalStateMachineTest extends TestCase {
transitionTo(mChildState4); transitionTo(mChildState4);
return HANDLED; return HANDLED;
} }
@Override protected void exit() {
mChildState3ExitCount += 1;
}
} }
class ChildState4 extends HierarchicalState { class ChildState4 extends State {
@Override protected void enter() { @Override
public void enter() {
mChildState4EnterCount += 1; 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, mParentState1EnterCount);
assertEquals(1, mParentState1ExitCount); assertEquals(1, mParentState1ExitCount);
assertEquals(1, mChildState1EnterCount); assertEquals(1, mChildState1EnterCount);
@@ -944,16 +984,19 @@ public class HierarchicalStateMachineTest extends TestCase {
transitionTo(mParentState2); transitionTo(mParentState2);
return HANDLED; return HANDLED;
} }
@Override protected void exit() {
mChildState4ExitCount += 1;
}
} }
class ChildState5 extends HierarchicalState { class ChildState5 extends State {
@Override protected void enter() { @Override
public void enter() {
mChildState5EnterCount += 1; 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, mParentState1EnterCount);
assertEquals(1, mParentState1ExitCount); assertEquals(1, mParentState1ExitCount);
assertEquals(1, mChildState1EnterCount); assertEquals(1, mChildState1EnterCount);
@@ -972,9 +1015,6 @@ public class HierarchicalStateMachineTest extends TestCase {
transitionTo(mChildState3); transitionTo(mChildState3);
return HANDLED; return HANDLED;
} }
@Override protected void exit() {
mChildState5ExitCount += 1;
}
} }
@Override @Override
@@ -1089,7 +1129,7 @@ public class HierarchicalStateMachineTest extends TestCase {
* after construction and before any other messages arrive and that * after construction and before any other messages arrive and that
* sendMessageDelayed works. * sendMessageDelayed works.
*/ */
class StateMachine6 extends HierarchicalStateMachine { class StateMachine6 extends StateMachine {
StateMachine6(String name) { StateMachine6(String name) {
super(name); super(name);
mThisSm = this; mThisSm = this;
@@ -1103,13 +1143,13 @@ public class HierarchicalStateMachineTest extends TestCase {
if (DBG) Log.d(TAG, "StateMachine6: ctor X"); if (DBG) Log.d(TAG, "StateMachine6: ctor X");
} }
class S1 extends HierarchicalState { class S1 extends State {
@Override
@Override protected void enter() { public void enter() {
sendMessage(TEST_CMD_1); sendMessage(TEST_CMD_1);
} }
@Override
@Override protected boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (message.what == TEST_CMD_1) { if (message.what == TEST_CMD_1) {
mArrivalTimeMsg1 = SystemClock.elapsedRealtime(); mArrivalTimeMsg1 = SystemClock.elapsedRealtime();
} else if (message.what == TEST_CMD_2) { } else if (message.what == TEST_CMD_2) {
@@ -1118,9 +1158,6 @@ public class HierarchicalStateMachineTest extends TestCase {
} }
return HANDLED; return HANDLED;
} }
@Override protected void exit() {
}
} }
@Override @Override
@@ -1178,7 +1215,7 @@ public class HierarchicalStateMachineTest extends TestCase {
* Test that enter is invoked immediately after exit. This validates * Test that enter is invoked immediately after exit. This validates
* that enter can be used to send a watch dog message for its state. * 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; private final int SM7_DELAY_TIME = 250;
StateMachine7(String name) { StateMachine7(String name) {
@@ -1195,24 +1232,26 @@ public class HierarchicalStateMachineTest extends TestCase {
if (DBG) Log.d(TAG, "StateMachine7: ctor X"); if (DBG) Log.d(TAG, "StateMachine7: ctor X");
} }
class S1 extends HierarchicalState { class S1 extends State {
@Override protected boolean processMessage(Message message) { @Override
public void exit() {
sendMessage(TEST_CMD_2);
}
@Override
public boolean processMessage(Message message) {
transitionTo(mS2); transitionTo(mS2);
return HANDLED; return HANDLED;
} }
@Override protected void exit() {
sendMessage(TEST_CMD_2);
}
} }
class S2 extends HierarchicalState { class S2 extends State {
@Override
@Override protected void enter() { public void enter() {
// Send a delayed message as a watch dog // Send a delayed message as a watch dog
sendMessageDelayed(TEST_CMD_3, SM7_DELAY_TIME); sendMessageDelayed(TEST_CMD_3, SM7_DELAY_TIME);
} }
@Override
@Override protected boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (message.what == TEST_CMD_2) { if (message.what == TEST_CMD_2) {
mMsgCount += 1; mMsgCount += 1;
mArrivalTimeMsg2 = SystemClock.elapsedRealtime(); mArrivalTimeMsg2 = SystemClock.elapsedRealtime();
@@ -1226,9 +1265,6 @@ public class HierarchicalStateMachineTest extends TestCase {
} }
return HANDLED; return HANDLED;
} }
@Override protected void exit() {
}
} }
@Override @Override
@@ -1286,7 +1322,7 @@ public class HierarchicalStateMachineTest extends TestCase {
/** /**
* Test unhandledMessage. * Test unhandledMessage.
*/ */
class StateMachineUnhandledMessage extends HierarchicalStateMachine { class StateMachineUnhandledMessage extends StateMachine {
StateMachineUnhandledMessage(String name) { StateMachineUnhandledMessage(String name) {
super(name); super(name);
mThisSm = this; mThisSm = this;
@@ -1298,13 +1334,14 @@ public class HierarchicalStateMachineTest extends TestCase {
// Set the initial state // Set the initial state
setInitialState(mS1); setInitialState(mS1);
} }
@Override
@Override protected void unhandledMessage(Message message) { public void unhandledMessage(Message message) {
mUnhandledMessageCount += 1; mUnhandledMessageCount += 1;
} }
class S1 extends HierarchicalState { class S1 extends State {
@Override protected boolean processMessage(Message message) { @Override
public boolean processMessage(Message message) {
if (message.what == TEST_CMD_2) { if (message.what == TEST_CMD_2) {
transitionToHaltingState(); transitionToHaltingState();
} }
@@ -1359,7 +1396,7 @@ public class HierarchicalStateMachineTest extends TestCase {
* will be used to notify testStateMachineSharedThread that the test is * will be used to notify testStateMachineSharedThread that the test is
* complete. * complete.
*/ */
class StateMachineSharedThread extends HierarchicalStateMachine { class StateMachineSharedThread extends StateMachine {
StateMachineSharedThread(String name, Looper looper, int maxCount) { StateMachineSharedThread(String name, Looper looper, int maxCount) {
super(name, looper); super(name, looper);
mMaxCount = maxCount; mMaxCount = maxCount;
@@ -1372,8 +1409,9 @@ public class HierarchicalStateMachineTest extends TestCase {
setInitialState(mS1); setInitialState(mS1);
} }
class S1 extends HierarchicalState { class S1 extends State {
@Override protected boolean processMessage(Message message) { @Override
public boolean processMessage(Message message) {
if (message.what == TEST_CMD_4) { if (message.what == TEST_CMD_4) {
transitionToHaltingState(); transitionToHaltingState();
} }
@@ -1503,7 +1541,7 @@ public class HierarchicalStateMachineTest extends TestCase {
} }
} }
class Hsm1 extends HierarchicalStateMachine { class Hsm1 extends StateMachine {
private static final String TAG = "hsm1"; private static final String TAG = "hsm1";
public static final int CMD_1 = 1; public static final int CMD_1 = 1;
@@ -1535,11 +1573,17 @@ class Hsm1 extends HierarchicalStateMachine {
Log.d(TAG, "ctor X"); Log.d(TAG, "ctor X");
} }
class P1 extends HierarchicalState { class P1 extends State {
@Override protected void enter() { @Override
public void enter() {
Log.d(TAG, "P1.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; boolean retVal;
Log.d(TAG, "P1.processMessage what=" + message.what); Log.d(TAG, "P1.processMessage what=" + message.what);
switch(message.what) { switch(message.what) {
@@ -1557,16 +1601,19 @@ class Hsm1 extends HierarchicalStateMachine {
} }
return retVal; return retVal;
} }
@Override protected void exit() {
Log.d(TAG, "P1.exit");
}
} }
class S1 extends HierarchicalState { class S1 extends State {
@Override protected void enter() { @Override
public void enter() {
Log.d(TAG, "S1.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); Log.d(TAG, "S1.processMessage what=" + message.what);
if (message.what == CMD_1) { if (message.what == CMD_1) {
// Transition to ourself to show that enter/exit is called // Transition to ourself to show that enter/exit is called
@@ -1577,16 +1624,19 @@ class Hsm1 extends HierarchicalStateMachine {
return NOT_HANDLED; return NOT_HANDLED;
} }
} }
@Override protected void exit() {
Log.d(TAG, "S1.exit");
}
} }
class S2 extends HierarchicalState { class S2 extends State {
@Override protected void enter() { @Override
public void enter() {
Log.d(TAG, "S2.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; boolean retVal;
Log.d(TAG, "S2.processMessage what=" + message.what); Log.d(TAG, "S2.processMessage what=" + message.what);
switch(message.what) { switch(message.what) {
@@ -1605,17 +1655,20 @@ class Hsm1 extends HierarchicalStateMachine {
} }
return retVal; return retVal;
} }
@Override protected void exit() {
Log.d(TAG, "S2.exit");
}
} }
class P2 extends HierarchicalState { class P2 extends State {
@Override protected void enter() { @Override
public void enter() {
Log.d(TAG, "P2.enter"); Log.d(TAG, "P2.enter");
sendMessage(CMD_5); 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); Log.d(TAG, "P2.processMessage what=" + message.what);
switch(message.what) { switch(message.what) {
case(CMD_3): case(CMD_3):
@@ -1628,9 +1681,6 @@ class Hsm1 extends HierarchicalStateMachine {
} }
return HANDLED; return HANDLED;
} }
@Override protected void exit() {
Log.d(TAG, "P2.exit");
}
} }
@Override @Override

View File

@@ -49,8 +49,9 @@ import android.provider.Settings;
import android.util.Log; import android.util.Log;
import com.android.internal.telephony.Phone; import com.android.internal.telephony.Phone;
import com.android.internal.util.HierarchicalState; import com.android.internal.util.IState;
import com.android.internal.util.HierarchicalStateMachine; import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.PrintWriter; import java.io.PrintWriter;
@@ -122,7 +123,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
// resampled each time we turn on tethering - used as cache for settings/config-val // 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 boolean mDunRequired; // configuration info - must use DUN apn on 3g
private HierarchicalStateMachine mTetherMasterSM; private StateMachine mTetherMasterSM;
private Notification mTetheredNotification; private Notification mTetheredNotification;
@@ -668,7 +669,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
} }
class TetherInterfaceSM extends HierarchicalStateMachine { class TetherInterfaceSM extends StateMachine {
// notification from the master SM that it's not in tether mode // notification from the master SM that it's not in tether mode
static final int CMD_TETHER_MODE_DEAD = 1; static final int CMD_TETHER_MODE_DEAD = 1;
// request from the user that it wants to tether // request from the user that it wants to tether
@@ -694,13 +695,13 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
// the upstream connection has changed // the upstream connection has changed
static final int CMD_TETHER_CONNECTION_CHANGED = 12; static final int CMD_TETHER_CONNECTION_CHANGED = 12;
private HierarchicalState mDefaultState; private State mDefaultState;
private HierarchicalState mInitialState; private State mInitialState;
private HierarchicalState mStartingState; private State mStartingState;
private HierarchicalState mTetheredState; private State mTetheredState;
private HierarchicalState mUnavailableState; private State mUnavailableState;
private boolean mAvailable; private boolean mAvailable;
private boolean mTethered; private boolean mTethered;
@@ -732,7 +733,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
public String toString() { public String toString() {
String res = new String(); String res = new String();
res += mIfaceName + " - "; res += mIfaceName + " - ";
HierarchicalState current = getCurrentState(); IState current = getCurrentState();
if (current == mInitialState) res += "InitialState"; if (current == mInitialState) res += "InitialState";
if (current == mStartingState) res += "StartingState"; if (current == mStartingState) res += "StartingState";
if (current == mTetheredState) res += "TetheredState"; if (current == mTetheredState) res += "TetheredState";
@@ -782,7 +783,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
return (mLastError != ConnectivityManager.TETHER_ERROR_NO_ERROR); return (mLastError != ConnectivityManager.TETHER_ERROR_NO_ERROR);
} }
class InitialState extends HierarchicalState { class InitialState extends State {
@Override @Override
public void enter() { public void enter() {
setAvailable(true); setAvailable(true);
@@ -812,7 +813,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
} }
} }
class StartingState extends HierarchicalState { class StartingState extends State {
@Override @Override
public void enter() { public void enter() {
setAvailable(false); setAvailable(false);
@@ -870,7 +871,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
} }
} }
class TetheredState extends HierarchicalState { class TetheredState extends State {
@Override @Override
public void enter() { public void enter() {
IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE); IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
@@ -1034,7 +1035,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
} }
} }
class UnavailableState extends HierarchicalState { class UnavailableState extends State {
@Override @Override
public void enter() { public void enter() {
setAvailable(false); setAvailable(false);
@@ -1064,7 +1065,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
} }
class TetherMasterSM extends HierarchicalStateMachine { class TetherMasterSM extends StateMachine {
// an interface SM has requested Tethering // an interface SM has requested Tethering
static final int CMD_TETHER_MODE_REQUESTED = 1; static final int CMD_TETHER_MODE_REQUESTED = 1;
// an interface SM has unrequested Tethering // an interface SM has unrequested Tethering
@@ -1082,14 +1083,14 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
// We do not flush the old ones. // We do not flush the old ones.
private int mSequenceNumber; private int mSequenceNumber;
private HierarchicalState mInitialState; private State mInitialState;
private HierarchicalState mTetherModeAliveState; private State mTetherModeAliveState;
private HierarchicalState mSetIpForwardingEnabledErrorState; private State mSetIpForwardingEnabledErrorState;
private HierarchicalState mSetIpForwardingDisabledErrorState; private State mSetIpForwardingDisabledErrorState;
private HierarchicalState mStartTetheringErrorState; private State mStartTetheringErrorState;
private HierarchicalState mStopTetheringErrorState; private State mStopTetheringErrorState;
private HierarchicalState mSetDnsForwardersErrorState; private State mSetDnsForwardersErrorState;
private ArrayList mNotifyList; private ArrayList mNotifyList;
@@ -1125,7 +1126,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
setInitialState(mInitialState); setInitialState(mInitialState);
} }
class TetherMasterUtilState extends HierarchicalState { class TetherMasterUtilState extends State {
protected final static boolean TRY_TO_SETUP_MOBILE_CONNECTION = true; protected final static boolean TRY_TO_SETUP_MOBILE_CONNECTION = true;
protected final static boolean WAIT_FOR_NETWORK_TO_SETTLE = false; protected final static boolean WAIT_FOR_NETWORK_TO_SETTLE = false;
@@ -1440,7 +1441,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
} }
} }
class ErrorState extends HierarchicalState { class ErrorState extends State {
int mErrorNotification; int mErrorNotification;
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {

View File

@@ -17,8 +17,8 @@
package com.android.internal.telephony; package com.android.internal.telephony;
import com.android.internal.util.HierarchicalState; import com.android.internal.util.State;
import com.android.internal.util.HierarchicalStateMachine; import com.android.internal.util.StateMachine;
import android.net.LinkAddress; import android.net.LinkAddress;
import android.net.LinkCapabilities; import android.net.LinkCapabilities;
@@ -37,7 +37,7 @@ import java.util.HashMap;
/** /**
* {@hide} * {@hide}
* *
* DataConnection HierarchicalStateMachine. * DataConnection StateMachine.
* *
* This is an abstract base class for representing a single data connection. * This is an abstract base class for representing a single data connection.
* Instances of this class such as <code>CdmaDataConnection</code> and * Instances of this class such as <code>CdmaDataConnection</code> and
@@ -55,7 +55,7 @@ import java.util.HashMap;
* *
* The other public methods are provided for debugging. * 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 final boolean DBG = true;
protected static Object mCountLock = new Object(); protected static Object mCountLock = new Object();
@@ -484,17 +484,17 @@ public abstract class DataConnection extends HierarchicalStateMachine {
/** /**
* The parent state for all other states. * The parent state for all other states.
*/ */
private class DcDefaultState extends HierarchicalState { private class DcDefaultState extends State {
@Override @Override
protected void enter() { public void enter() {
phone.mCM.registerForRilConnected(getHandler(), EVENT_RIL_CONNECTED, null); phone.mCM.registerForRilConnected(getHandler(), EVENT_RIL_CONNECTED, null);
} }
@Override @Override
protected void exit() { public void exit() {
phone.mCM.unregisterForRilConnected(getHandler()); phone.mCM.unregisterForRilConnected(getHandler());
} }
@Override @Override
protected boolean processMessage(Message msg) { public boolean processMessage(Message msg) {
AsyncResult ar; AsyncResult ar;
switch (msg.what) { switch (msg.what) {
@@ -547,7 +547,7 @@ public abstract class DataConnection extends HierarchicalStateMachine {
/** /**
* The state machine is inactive and expects a EVENT_CONNECT. * 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 ConnectionParams mConnectionParams = null;
private FailCause mFailCause = null; private FailCause mFailCause = null;
private DisconnectParams mDisconnectParams = null; private DisconnectParams mDisconnectParams = null;
@@ -563,7 +563,8 @@ public abstract class DataConnection extends HierarchicalStateMachine {
mDisconnectParams = dp; mDisconnectParams = dp;
} }
@Override protected void enter() { @Override
public void enter() {
mTag += 1; mTag += 1;
/** /**
@@ -583,14 +584,16 @@ public abstract class DataConnection extends HierarchicalStateMachine {
} }
} }
@Override protected void exit() { @Override
public void exit() {
// clear notifications // clear notifications
mConnectionParams = null; mConnectionParams = null;
mFailCause = null; mFailCause = null;
mDisconnectParams = null; mDisconnectParams = null;
} }
@Override protected boolean processMessage(Message msg) { @Override
public boolean processMessage(Message msg) {
boolean retVal; boolean retVal;
switch (msg.what) { switch (msg.what) {
@@ -626,8 +629,9 @@ public abstract class DataConnection extends HierarchicalStateMachine {
/** /**
* The state machine is activating a connection. * The state machine is activating a connection.
*/ */
private class DcActivatingState extends HierarchicalState { private class DcActivatingState extends State {
@Override protected boolean processMessage(Message msg) { @Override
public boolean processMessage(Message msg) {
boolean retVal; boolean retVal;
AsyncResult ar; AsyncResult ar;
ConnectionParams cp; ConnectionParams cp;
@@ -722,7 +726,7 @@ public abstract class DataConnection extends HierarchicalStateMachine {
/** /**
* The state machine is connected, expecting an EVENT_DISCONNECT. * The state machine is connected, expecting an EVENT_DISCONNECT.
*/ */
private class DcActiveState extends HierarchicalState { private class DcActiveState extends State {
private ConnectionParams mConnectionParams = null; private ConnectionParams mConnectionParams = null;
private FailCause mFailCause = null; private FailCause mFailCause = null;
@@ -746,13 +750,15 @@ public abstract class DataConnection extends HierarchicalStateMachine {
} }
} }
@Override protected void exit() { @Override
public void exit() {
// clear notifications // clear notifications
mConnectionParams = null; mConnectionParams = null;
mFailCause = null; mFailCause = null;
} }
@Override protected boolean processMessage(Message msg) { @Override
public boolean processMessage(Message msg) {
boolean retVal; boolean retVal;
switch (msg.what) { switch (msg.what) {
@@ -778,8 +784,9 @@ public abstract class DataConnection extends HierarchicalStateMachine {
/** /**
* The state machine is disconnecting. * The state machine is disconnecting.
*/ */
private class DcDisconnectingState extends HierarchicalState { private class DcDisconnectingState extends State {
@Override protected boolean processMessage(Message msg) { @Override
public boolean processMessage(Message msg) {
boolean retVal; boolean retVal;
switch (msg.what) { switch (msg.what) {
@@ -812,8 +819,9 @@ public abstract class DataConnection extends HierarchicalStateMachine {
/** /**
* The state machine is disconnecting after an creating a connection. * The state machine is disconnecting after an creating a connection.
*/ */
private class DcDisconnectionErrorCreatingConnection extends HierarchicalState { private class DcDisconnectionErrorCreatingConnection extends State {
@Override protected boolean processMessage(Message msg) { @Override
public boolean processMessage(Message msg) {
boolean retVal; boolean retVal;
switch (msg.what) { switch (msg.what) {

View File

@@ -20,15 +20,15 @@ import com.android.internal.telephony.IccFileHandler;
import com.android.internal.telephony.IccUtils; import com.android.internal.telephony.IccUtils;
import android.os.Handler; import android.os.Handler;
import com.android.internal.util.HierarchicalState; import com.android.internal.util.State;
import com.android.internal.util.HierarchicalStateMachine; import com.android.internal.util.StateMachine;
import android.os.Message; import android.os.Message;
/** /**
* Class used for queuing raw ril messages, decoding them into CommanParams * Class used for queuing raw ril messages, decoding them into CommanParams
* objects and sending the result back to the CAT Service. * objects and sending the result back to the CAT Service.
*/ */
class RilMessageDecoder extends HierarchicalStateMachine { class RilMessageDecoder extends StateMachine {
// constants // constants
private static final int CMD_START = 1; private static final int CMD_START = 1;
@@ -101,8 +101,9 @@ class RilMessageDecoder extends HierarchicalStateMachine {
mCmdParamsFactory = CommandParamsFactory.getInstance(this, fh); mCmdParamsFactory = CommandParamsFactory.getInstance(this, fh);
} }
private class StateStart extends HierarchicalState { private class StateStart extends State {
@Override protected boolean processMessage(Message msg) { @Override
public boolean processMessage(Message msg) {
if (msg.what == CMD_START) { if (msg.what == CMD_START) {
if (decodeMessageParams((RilMessage)msg.obj)) { if (decodeMessageParams((RilMessage)msg.obj)) {
transitionTo(mStateCmdParamsReady); transitionTo(mStateCmdParamsReady);
@@ -115,8 +116,9 @@ class RilMessageDecoder extends HierarchicalStateMachine {
} }
} }
private class StateCmdParamsReady extends HierarchicalState { private class StateCmdParamsReady extends State {
@Override protected boolean processMessage(Message msg) { @Override
public boolean processMessage(Message msg) {
if (msg.what == CMD_PARAMS_READY) { if (msg.what == CMD_PARAMS_READY) {
mCurrentRilMessage.mResCode = ResultCode.fromInt(msg.arg1); mCurrentRilMessage.mResCode = ResultCode.fromInt(msg.arg1);
mCurrentRilMessage.mData = msg.obj; mCurrentRilMessage.mData = msg.obj;

View File

@@ -16,8 +16,8 @@
package android.net.wifi; package android.net.wifi;
import com.android.internal.util.HierarchicalState; import com.android.internal.util.State;
import com.android.internal.util.HierarchicalStateMachine; import com.android.internal.util.StateMachine;
import android.net.wifi.WifiStateMachine.StateChangeResult; import android.net.wifi.WifiStateMachine.StateChangeResult;
import android.content.Context; import android.content.Context;
@@ -33,7 +33,7 @@ import android.util.Log;
* - detect a failed WPA handshake that loops indefinitely * - detect a failed WPA handshake that loops indefinitely
* - authentication failure handling * - authentication failure handling
*/ */
class SupplicantStateTracker extends HierarchicalStateMachine { class SupplicantStateTracker extends StateMachine {
private static final String TAG = "SupplicantStateTracker"; private static final String TAG = "SupplicantStateTracker";
private static final boolean DBG = false; private static final boolean DBG = false;
@@ -53,14 +53,14 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
private Context mContext; private Context mContext;
private HierarchicalState mUninitializedState = new UninitializedState(); private State mUninitializedState = new UninitializedState();
private HierarchicalState mDefaultState = new DefaultState(); private State mDefaultState = new DefaultState();
private HierarchicalState mInactiveState = new InactiveState(); private State mInactiveState = new InactiveState();
private HierarchicalState mDisconnectState = new DisconnectedState(); private State mDisconnectState = new DisconnectedState();
private HierarchicalState mScanState = new ScanState(); private State mScanState = new ScanState();
private HierarchicalState mHandshakeState = new HandshakeState(); private State mHandshakeState = new HandshakeState();
private HierarchicalState mCompletedState = new CompletedState(); private State mCompletedState = new CompletedState();
private HierarchicalState mDormantState = new DormantState(); private State mDormantState = new DormantState();
public SupplicantStateTracker(Context context, WifiStateMachine wsm, Handler target) { public SupplicantStateTracker(Context context, WifiStateMachine wsm, Handler target) {
super(TAG, target.getLooper()); super(TAG, target.getLooper());
@@ -146,7 +146,7 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
* HSM states * HSM states
*******************************************************/ *******************************************************/
class DefaultState extends HierarchicalState { class DefaultState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -188,21 +188,21 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
* or after we have lost the control channel * or after we have lost the control channel
* connection to the supplicant * connection to the supplicant
*/ */
class UninitializedState extends HierarchicalState { class UninitializedState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
} }
} }
class InactiveState extends HierarchicalState { class InactiveState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
} }
} }
class DisconnectedState extends HierarchicalState { class DisconnectedState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -221,14 +221,14 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
} }
} }
class ScanState extends HierarchicalState { class ScanState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); 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 * The max number of the WPA supplicant loop iterations before we
* decide that the loop should be terminated: * decide that the loop should be terminated:
@@ -277,7 +277,7 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
} }
} }
class CompletedState extends HierarchicalState { class CompletedState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -318,7 +318,7 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
} }
//TODO: remove after getting rid of the state in supplicant //TODO: remove after getting rid of the state in supplicant
class DormantState extends HierarchicalState { class DormantState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");

View File

@@ -73,8 +73,8 @@ import android.util.LruCache;
import com.android.internal.app.IBatteryStats; import com.android.internal.app.IBatteryStats;
import com.android.internal.util.AsyncChannel; import com.android.internal.util.AsyncChannel;
import com.android.internal.util.HierarchicalState; import com.android.internal.util.State;
import com.android.internal.util.HierarchicalStateMachine; import com.android.internal.util.StateMachine;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.ArrayList; import java.util.ArrayList;
@@ -88,7 +88,7 @@ import java.util.regex.Pattern;
* *
* @hide * @hide
*/ */
public class WifiStateMachine extends HierarchicalStateMachine { public class WifiStateMachine extends StateMachine {
private static final String TAG = "WifiStateMachine"; private static final String TAG = "WifiStateMachine";
private static final String NETWORKTYPE = "WIFI"; private static final String NETWORKTYPE = "WIFI";
@@ -348,50 +348,50 @@ public class WifiStateMachine extends HierarchicalStateMachine {
private static final int MAX_RSSI = 256; private static final int MAX_RSSI = 256;
/* Default parent state */ /* Default parent state */
private HierarchicalState mDefaultState = new DefaultState(); private State mDefaultState = new DefaultState();
/* Temporary initial state */ /* Temporary initial state */
private HierarchicalState mInitialState = new InitialState(); private State mInitialState = new InitialState();
/* Unloading the driver */ /* Unloading the driver */
private HierarchicalState mDriverUnloadingState = new DriverUnloadingState(); private State mDriverUnloadingState = new DriverUnloadingState();
/* Loading the driver */ /* Loading the driver */
private HierarchicalState mDriverUnloadedState = new DriverUnloadedState(); private State mDriverUnloadedState = new DriverUnloadedState();
/* Driver load/unload failed */ /* Driver load/unload failed */
private HierarchicalState mDriverFailedState = new DriverFailedState(); private State mDriverFailedState = new DriverFailedState();
/* Driver loading */ /* Driver loading */
private HierarchicalState mDriverLoadingState = new DriverLoadingState(); private State mDriverLoadingState = new DriverLoadingState();
/* Driver loaded */ /* Driver loaded */
private HierarchicalState mDriverLoadedState = new DriverLoadedState(); private State mDriverLoadedState = new DriverLoadedState();
/* Driver loaded, waiting for supplicant to start */ /* Driver loaded, waiting for supplicant to start */
private HierarchicalState mSupplicantStartingState = new SupplicantStartingState(); private State mSupplicantStartingState = new SupplicantStartingState();
/* Driver loaded and supplicant ready */ /* Driver loaded and supplicant ready */
private HierarchicalState mSupplicantStartedState = new SupplicantStartedState(); private State mSupplicantStartedState = new SupplicantStartedState();
/* Waiting for supplicant to stop and monitor to exit */ /* 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 */ /* Driver start issued, waiting for completed event */
private HierarchicalState mDriverStartingState = new DriverStartingState(); private State mDriverStartingState = new DriverStartingState();
/* Driver started */ /* Driver started */
private HierarchicalState mDriverStartedState = new DriverStartedState(); private State mDriverStartedState = new DriverStartedState();
/* Driver stopping */ /* Driver stopping */
private HierarchicalState mDriverStoppingState = new DriverStoppingState(); private State mDriverStoppingState = new DriverStoppingState();
/* Driver stopped */ /* Driver stopped */
private HierarchicalState mDriverStoppedState = new DriverStoppedState(); private State mDriverStoppedState = new DriverStoppedState();
/* Scan for networks, no connection will be established */ /* Scan for networks, no connection will be established */
private HierarchicalState mScanModeState = new ScanModeState(); private State mScanModeState = new ScanModeState();
/* Connecting to an access point */ /* Connecting to an access point */
private HierarchicalState mConnectModeState = new ConnectModeState(); private State mConnectModeState = new ConnectModeState();
/* Fetching IP after network connection (assoc+auth complete) */ /* Fetching IP after network connection (assoc+auth complete) */
private HierarchicalState mConnectingState = new ConnectingState(); private State mConnectingState = new ConnectingState();
/* Connected with IP addr */ /* Connected with IP addr */
private HierarchicalState mConnectedState = new ConnectedState(); private State mConnectedState = new ConnectedState();
/* disconnect issued, waiting for network disconnect confirmation */ /* 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 */ /* 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*/ /* Waiting for WPS to be completed*/
private HierarchicalState mWaitForWpsCompletionState = new WaitForWpsCompletionState(); private State mWaitForWpsCompletionState = new WaitForWpsCompletionState();
/* Soft Ap is running */ /* Soft Ap is running */
private HierarchicalState mSoftApStartedState = new SoftApStartedState(); private State mSoftApStartedState = new SoftApStartedState();
/** /**
@@ -1527,7 +1527,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
* HSM states * HSM states
*******************************************************/ *******************************************************/
class DefaultState extends HierarchicalState { class DefaultState extends State {
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
@@ -1601,7 +1601,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class InitialState extends HierarchicalState { class InitialState extends State {
@Override @Override
//TODO: could move logging into a common class //TODO: could move logging into a common class
public void enter() { public void enter() {
@@ -1620,7 +1620,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class DriverLoadingState extends HierarchicalState { class DriverLoadingState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -1699,7 +1699,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class DriverLoadedState extends HierarchicalState { class DriverLoadedState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -1752,7 +1752,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class DriverUnloadingState extends HierarchicalState { class DriverUnloadingState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -1833,7 +1833,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class DriverUnloadedState extends HierarchicalState { class DriverUnloadedState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -1854,7 +1854,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class DriverFailedState extends HierarchicalState { class DriverFailedState extends State {
@Override @Override
public void enter() { public void enter() {
Log.e(TAG, getName() + "\n"); Log.e(TAG, getName() + "\n");
@@ -1868,7 +1868,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
class SupplicantStartingState extends HierarchicalState { class SupplicantStartingState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -1940,7 +1940,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class SupplicantStartedState extends HierarchicalState { class SupplicantStartedState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -2063,7 +2063,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class SupplicantStoppingState extends HierarchicalState { class SupplicantStoppingState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -2106,7 +2106,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class DriverStartingState extends HierarchicalState { class DriverStartingState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -2147,7 +2147,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class DriverStartedState extends HierarchicalState { class DriverStartedState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -2251,7 +2251,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class DriverStoppingState extends HierarchicalState { class DriverStoppingState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -2287,7 +2287,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class DriverStoppedState extends HierarchicalState { class DriverStoppedState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -2311,7 +2311,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class ScanModeState extends HierarchicalState { class ScanModeState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -2348,7 +2348,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class ConnectModeState extends HierarchicalState { class ConnectModeState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -2458,7 +2458,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class ConnectingState extends HierarchicalState { class ConnectingState extends State {
boolean mModifiedBluetoothCoexistenceMode; boolean mModifiedBluetoothCoexistenceMode;
int mPowerMode; int mPowerMode;
boolean mUseStaticIp; boolean mUseStaticIp;
@@ -2656,7 +2656,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class ConnectedState extends HierarchicalState { class ConnectedState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -2768,7 +2768,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class DisconnectingState extends HierarchicalState { class DisconnectingState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -2798,7 +2798,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class DisconnectedState extends HierarchicalState { class DisconnectedState extends State {
private boolean mAlarmEnabled = false; private boolean mAlarmEnabled = false;
private long mScanIntervalMs; private long mScanIntervalMs;
@@ -2905,7 +2905,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class WaitForWpsCompletionState extends HierarchicalState { class WaitForWpsCompletionState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -2944,7 +2944,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
} }
} }
class SoftApStartedState extends HierarchicalState { class SoftApStartedState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");

View File

@@ -17,8 +17,8 @@
package android.net.wifi; package android.net.wifi;
import com.android.internal.util.AsyncChannel; import com.android.internal.util.AsyncChannel;
import com.android.internal.util.HierarchicalState; import com.android.internal.util.State;
import com.android.internal.util.HierarchicalStateMachine; import com.android.internal.util.StateMachine;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@@ -46,7 +46,7 @@ import android.util.Log;
* reloads the configuration and updates the IP and proxy * reloads the configuration and updates the IP and proxy
* settings, if any. * settings, if any.
*/ */
class WpsStateMachine extends HierarchicalStateMachine { class WpsStateMachine extends StateMachine {
private static final String TAG = "WpsStateMachine"; private static final String TAG = "WpsStateMachine";
private static final boolean DBG = false; private static final boolean DBG = false;
@@ -58,9 +58,9 @@ class WpsStateMachine extends HierarchicalStateMachine {
private Context mContext; private Context mContext;
AsyncChannel mReplyChannel = new AsyncChannel(); AsyncChannel mReplyChannel = new AsyncChannel();
private HierarchicalState mDefaultState = new DefaultState(); private State mDefaultState = new DefaultState();
private HierarchicalState mInactiveState = new InactiveState(); private State mInactiveState = new InactiveState();
private HierarchicalState mActiveState = new ActiveState(); private State mActiveState = new ActiveState();
public WpsStateMachine(Context context, WifiStateMachine wsm, Handler target) { public WpsStateMachine(Context context, WifiStateMachine wsm, Handler target) {
super(TAG, target.getLooper()); super(TAG, target.getLooper());
@@ -82,7 +82,7 @@ class WpsStateMachine extends HierarchicalStateMachine {
* HSM states * HSM states
*******************************************************/ *******************************************************/
class DefaultState extends HierarchicalState { class DefaultState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -128,7 +128,7 @@ class WpsStateMachine extends HierarchicalStateMachine {
} }
} }
class ActiveState extends HierarchicalState { class ActiveState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");
@@ -182,7 +182,7 @@ class WpsStateMachine extends HierarchicalStateMachine {
} }
} }
class InactiveState extends HierarchicalState { class InactiveState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) Log.d(TAG, getName() + "\n");