Loading core/java/android/bluetooth/BluetoothDeviceProfileState.java +24 −24 Original line number Diff line number Diff line Loading @@ -26,8 +26,8 @@ import android.server.BluetoothA2dpService; import android.server.BluetoothService; import android.util.Log; import com.android.internal.util.HierarchicalState; import com.android.internal.util.HierarchicalStateMachine; import com.android.internal.util.State; import com.android.internal.util.StateMachine; import java.util.Set; Loading Loading @@ -57,7 +57,7 @@ import java.util.Set; * Todo(): Write tests for this class, when the Android Mock support is completed. * @hide */ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine { public final class BluetoothDeviceProfileState extends StateMachine { private static final String TAG = "BluetoothDeviceProfileState"; private static final boolean DBG = false; Loading Loading @@ -235,16 +235,16 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } } private class BondedDevice extends HierarchicalState { private class BondedDevice extends State { @Override protected void enter() { public void enter() { Log.i(TAG, "Entering ACL Connected state with: " + getCurrentMessage().what); Message m = new Message(); m.copyFrom(getCurrentMessage()); sendMessageAtFrontOfQueue(m); } @Override protected boolean processMessage(Message message) { public boolean processMessage(Message message) { log("ACL Connected State -> Processing Message: " + message.what); switch(message.what) { case CONNECT_HFP_OUTGOING: Loading Loading @@ -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 int mCommand; @Override protected void enter() { public void enter() { Log.i(TAG, "Entering OutgoingHandsfree state with: " + getCurrentMessage().what); mCommand = getCurrentMessage().what; if (mCommand != CONNECT_HFP_OUTGOING && Loading @@ -374,7 +374,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } @Override protected boolean processMessage(Message message) { public boolean processMessage(Message message) { log("OutgoingHandsfree State -> Processing Message: " + message.what); Message deferMsg = new Message(); int command = message.what; Loading Loading @@ -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 int mCommand; @Override protected void enter() { public void enter() { Log.i(TAG, "Entering IncomingHandsfree state with: " + getCurrentMessage().what); mCommand = getCurrentMessage().what; if (mCommand != CONNECT_HFP_INCOMING && Loading @@ -487,7 +487,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } @Override protected boolean processMessage(Message message) { public boolean processMessage(Message message) { log("IncomingHandsfree State -> Processing Message: " + message.what); switch(message.what) { case CONNECT_HFP_OUTGOING: Loading Loading @@ -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 int mCommand; @Override protected void enter() { public void enter() { Log.i(TAG, "Entering OutgoingA2dp state with: " + getCurrentMessage().what); mCommand = getCurrentMessage().what; if (mCommand != CONNECT_A2DP_OUTGOING && Loading @@ -567,7 +567,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } @Override protected boolean processMessage(Message message) { public boolean processMessage(Message message) { log("OutgoingA2dp State->Processing Message: " + message.what); Message deferMsg = new Message(); switch(message.what) { Loading Loading @@ -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 int mCommand; @Override protected void enter() { public void enter() { Log.i(TAG, "Entering IncomingA2dp state with: " + getCurrentMessage().what); mCommand = getCurrentMessage().what; if (mCommand != CONNECT_A2DP_INCOMING && Loading @@ -677,7 +677,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } @Override protected boolean processMessage(Message message) { public boolean processMessage(Message message) { log("IncomingA2dp State->Processing Message: " + message.what); switch(message.what) { case CONNECT_HFP_OUTGOING: Loading Loading @@ -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 int mCommand; @Override protected void enter() { public void enter() { log("Entering OutgoingHid state with: " + getCurrentMessage().what); mCommand = getCurrentMessage().what; if (mCommand != CONNECT_HID_OUTGOING && Loading @@ -751,7 +751,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } @Override protected boolean processMessage(Message message) { public boolean processMessage(Message message) { log("OutgoingHid State->Processing Message: " + message.what); Message deferMsg = new Message(); switch(message.what) { Loading Loading @@ -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 int mCommand; @Override protected void enter() { public void enter() { log("Entering IncomingHid state with: " + getCurrentMessage().what); mCommand = getCurrentMessage().what; if (mCommand != CONNECT_HID_INCOMING && Loading @@ -832,7 +832,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } @Override protected boolean processMessage(Message message) { public boolean processMessage(Message message) { log("IncomingHid State->Processing Message: " + message.what); Message deferMsg = new Message(); switch(message.what) { Loading core/java/android/bluetooth/BluetoothProfileState.java +9 −9 Original line number Diff line number Diff line Loading @@ -22,8 +22,8 @@ import android.content.IntentFilter; import android.os.Message; import android.util.Log; import com.android.internal.util.HierarchicalState; import com.android.internal.util.HierarchicalStateMachine; import com.android.internal.util.State; import com.android.internal.util.StateMachine; /** * This state machine is used to serialize the connections Loading @@ -39,7 +39,7 @@ import com.android.internal.util.HierarchicalStateMachine; * @hide */ public class BluetoothProfileState extends HierarchicalStateMachine { public class BluetoothProfileState extends StateMachine { private static final boolean DBG = true; private static final String TAG = "BluetoothProfileState"; Loading Loading @@ -101,15 +101,15 @@ public class BluetoothProfileState extends HierarchicalStateMachine { context.registerReceiver(mBroadcastReceiver, filter); } private class StableState extends HierarchicalState { private class StableState extends State { @Override protected void enter() { public void enter() { log("Entering Stable State"); mPendingDevice = null; } @Override protected boolean processMessage(Message msg) { public boolean processMessage(Message msg) { if (msg.what != TRANSITION_TO_STABLE) { transitionTo(mPendingCommandState); } Loading @@ -117,15 +117,15 @@ public class BluetoothProfileState extends HierarchicalStateMachine { } } private class PendingCommandState extends HierarchicalState { private class PendingCommandState extends State { @Override protected void enter() { public void enter() { log("Entering PendingCommandState State"); dispatchMessage(getCurrentMessage()); } @Override protected boolean processMessage(Message msg) { public boolean processMessage(Message msg) { if (msg.what == TRANSITION_TO_STABLE) { transitionTo(mStableState); } else { Loading core/java/com/android/internal/util/HierarchicalState.java→core/java/com/android/internal/util/IState.java +23 −28 Original line number Diff line number Diff line /** * Copyright (C) 2009 The Android Open Source Project * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading @@ -21,21 +21,29 @@ import android.os.Message; /** * {@hide} * * The class for implementing states in a HierarchicalStateMachine * The interface for implementing states in a {@link StateMachine} */ public class HierarchicalState { public interface IState { /** * Constructor * Returned by processMessage to indicate the the message was processed. */ protected HierarchicalState() { } static final boolean HANDLED = true; /** * Returned by processMessage to indicate the the message was NOT processed. */ static final boolean NOT_HANDLED = false; /** * Called when a state is entered. */ protected void enter() { } void enter(); /** * Called when a state is exited. */ void exit(); /** * Called when a message is to be processed by the Loading @@ -49,28 +57,15 @@ public class HierarchicalState { * be processed until this routine returns. * * @param msg to process * @return true if processing has completed and false * if the parent state's processMessage should * be invoked. * @return HANDLED if processing has completed and NOT_HANDLED * if the message wasn't processed. */ protected boolean processMessage(Message msg) { return false; } /** * Called when a state is exited. */ protected void exit() { } boolean processMessage(Message msg); /** * @return name of state, but default returns the states * class name. An instance name would be better but requiring * it seems unnecessary. * Name of State for debugging purposes. * * @return name of state. */ public String getName() { String name = getClass().getName(); int lastDollar = name.lastIndexOf('$'); return name.substring(lastDollar + 1); } String getName(); } core/java/com/android/internal/util/State.java 0 → 100644 +74 −0 Original line number Diff line number Diff line /** * 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); } } Loading
core/java/android/bluetooth/BluetoothDeviceProfileState.java +24 −24 Original line number Diff line number Diff line Loading @@ -26,8 +26,8 @@ import android.server.BluetoothA2dpService; import android.server.BluetoothService; import android.util.Log; import com.android.internal.util.HierarchicalState; import com.android.internal.util.HierarchicalStateMachine; import com.android.internal.util.State; import com.android.internal.util.StateMachine; import java.util.Set; Loading Loading @@ -57,7 +57,7 @@ import java.util.Set; * Todo(): Write tests for this class, when the Android Mock support is completed. * @hide */ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine { public final class BluetoothDeviceProfileState extends StateMachine { private static final String TAG = "BluetoothDeviceProfileState"; private static final boolean DBG = false; Loading Loading @@ -235,16 +235,16 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } } private class BondedDevice extends HierarchicalState { private class BondedDevice extends State { @Override protected void enter() { public void enter() { Log.i(TAG, "Entering ACL Connected state with: " + getCurrentMessage().what); Message m = new Message(); m.copyFrom(getCurrentMessage()); sendMessageAtFrontOfQueue(m); } @Override protected boolean processMessage(Message message) { public boolean processMessage(Message message) { log("ACL Connected State -> Processing Message: " + message.what); switch(message.what) { case CONNECT_HFP_OUTGOING: Loading Loading @@ -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 int mCommand; @Override protected void enter() { public void enter() { Log.i(TAG, "Entering OutgoingHandsfree state with: " + getCurrentMessage().what); mCommand = getCurrentMessage().what; if (mCommand != CONNECT_HFP_OUTGOING && Loading @@ -374,7 +374,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } @Override protected boolean processMessage(Message message) { public boolean processMessage(Message message) { log("OutgoingHandsfree State -> Processing Message: " + message.what); Message deferMsg = new Message(); int command = message.what; Loading Loading @@ -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 int mCommand; @Override protected void enter() { public void enter() { Log.i(TAG, "Entering IncomingHandsfree state with: " + getCurrentMessage().what); mCommand = getCurrentMessage().what; if (mCommand != CONNECT_HFP_INCOMING && Loading @@ -487,7 +487,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } @Override protected boolean processMessage(Message message) { public boolean processMessage(Message message) { log("IncomingHandsfree State -> Processing Message: " + message.what); switch(message.what) { case CONNECT_HFP_OUTGOING: Loading Loading @@ -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 int mCommand; @Override protected void enter() { public void enter() { Log.i(TAG, "Entering OutgoingA2dp state with: " + getCurrentMessage().what); mCommand = getCurrentMessage().what; if (mCommand != CONNECT_A2DP_OUTGOING && Loading @@ -567,7 +567,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } @Override protected boolean processMessage(Message message) { public boolean processMessage(Message message) { log("OutgoingA2dp State->Processing Message: " + message.what); Message deferMsg = new Message(); switch(message.what) { Loading Loading @@ -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 int mCommand; @Override protected void enter() { public void enter() { Log.i(TAG, "Entering IncomingA2dp state with: " + getCurrentMessage().what); mCommand = getCurrentMessage().what; if (mCommand != CONNECT_A2DP_INCOMING && Loading @@ -677,7 +677,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } @Override protected boolean processMessage(Message message) { public boolean processMessage(Message message) { log("IncomingA2dp State->Processing Message: " + message.what); switch(message.what) { case CONNECT_HFP_OUTGOING: Loading Loading @@ -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 int mCommand; @Override protected void enter() { public void enter() { log("Entering OutgoingHid state with: " + getCurrentMessage().what); mCommand = getCurrentMessage().what; if (mCommand != CONNECT_HID_OUTGOING && Loading @@ -751,7 +751,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } @Override protected boolean processMessage(Message message) { public boolean processMessage(Message message) { log("OutgoingHid State->Processing Message: " + message.what); Message deferMsg = new Message(); switch(message.what) { Loading Loading @@ -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 int mCommand; @Override protected void enter() { public void enter() { log("Entering IncomingHid state with: " + getCurrentMessage().what); mCommand = getCurrentMessage().what; if (mCommand != CONNECT_HID_INCOMING && Loading @@ -832,7 +832,7 @@ public final class BluetoothDeviceProfileState extends HierarchicalStateMachine } @Override protected boolean processMessage(Message message) { public boolean processMessage(Message message) { log("IncomingHid State->Processing Message: " + message.what); Message deferMsg = new Message(); switch(message.what) { Loading
core/java/android/bluetooth/BluetoothProfileState.java +9 −9 Original line number Diff line number Diff line Loading @@ -22,8 +22,8 @@ import android.content.IntentFilter; import android.os.Message; import android.util.Log; import com.android.internal.util.HierarchicalState; import com.android.internal.util.HierarchicalStateMachine; import com.android.internal.util.State; import com.android.internal.util.StateMachine; /** * This state machine is used to serialize the connections Loading @@ -39,7 +39,7 @@ import com.android.internal.util.HierarchicalStateMachine; * @hide */ public class BluetoothProfileState extends HierarchicalStateMachine { public class BluetoothProfileState extends StateMachine { private static final boolean DBG = true; private static final String TAG = "BluetoothProfileState"; Loading Loading @@ -101,15 +101,15 @@ public class BluetoothProfileState extends HierarchicalStateMachine { context.registerReceiver(mBroadcastReceiver, filter); } private class StableState extends HierarchicalState { private class StableState extends State { @Override protected void enter() { public void enter() { log("Entering Stable State"); mPendingDevice = null; } @Override protected boolean processMessage(Message msg) { public boolean processMessage(Message msg) { if (msg.what != TRANSITION_TO_STABLE) { transitionTo(mPendingCommandState); } Loading @@ -117,15 +117,15 @@ public class BluetoothProfileState extends HierarchicalStateMachine { } } private class PendingCommandState extends HierarchicalState { private class PendingCommandState extends State { @Override protected void enter() { public void enter() { log("Entering PendingCommandState State"); dispatchMessage(getCurrentMessage()); } @Override protected boolean processMessage(Message msg) { public boolean processMessage(Message msg) { if (msg.what == TRANSITION_TO_STABLE) { transitionTo(mStableState); } else { Loading
core/java/com/android/internal/util/HierarchicalState.java→core/java/com/android/internal/util/IState.java +23 −28 Original line number Diff line number Diff line /** * Copyright (C) 2009 The Android Open Source Project * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading @@ -21,21 +21,29 @@ import android.os.Message; /** * {@hide} * * The class for implementing states in a HierarchicalStateMachine * The interface for implementing states in a {@link StateMachine} */ public class HierarchicalState { public interface IState { /** * Constructor * Returned by processMessage to indicate the the message was processed. */ protected HierarchicalState() { } static final boolean HANDLED = true; /** * Returned by processMessage to indicate the the message was NOT processed. */ static final boolean NOT_HANDLED = false; /** * Called when a state is entered. */ protected void enter() { } void enter(); /** * Called when a state is exited. */ void exit(); /** * Called when a message is to be processed by the Loading @@ -49,28 +57,15 @@ public class HierarchicalState { * be processed until this routine returns. * * @param msg to process * @return true if processing has completed and false * if the parent state's processMessage should * be invoked. * @return HANDLED if processing has completed and NOT_HANDLED * if the message wasn't processed. */ protected boolean processMessage(Message msg) { return false; } /** * Called when a state is exited. */ protected void exit() { } boolean processMessage(Message msg); /** * @return name of state, but default returns the states * class name. An instance name would be better but requiring * it seems unnecessary. * Name of State for debugging purposes. * * @return name of state. */ public String getName() { String name = getClass().getName(); int lastDollar = name.lastIndexOf('$'); return name.substring(lastDollar + 1); } String getName(); }
core/java/com/android/internal/util/State.java 0 → 100644 +74 −0 Original line number Diff line number Diff line /** * 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); } }