1 /**
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.internal.util;
18 
19 import android.compat.annotation.UnsupportedAppUsage;
20 import android.os.Message;
21 
22 /**
23  * {@hide}
24  *
25  * The interface for implementing states in a {@link StateMachine}
26  */
27 public interface IState {
28 
29     /**
30      * Returned by processMessage to indicate the the message was processed.
31      */
32     static final boolean HANDLED = true;
33 
34     /**
35      * Returned by processMessage to indicate the the message was NOT processed.
36      */
37     static final boolean NOT_HANDLED = false;
38 
39     /**
40      * Called when a state is entered.
41      */
enter()42     void enter();
43 
44     /**
45      * Called when a state is exited.
46      */
exit()47     void exit();
48 
49     /**
50      * Called when a message is to be processed by the
51      * state machine.
52      *
53      * This routine is never reentered thus no synchronization
54      * is needed as only one processMessage method will ever be
55      * executing within a state machine at any given time. This
56      * does mean that processing by this routine must be completed
57      * as expeditiously as possible as no subsequent messages will
58      * be processed until this routine returns.
59      *
60      * @param msg to process
61      * @return HANDLED if processing has completed and NOT_HANDLED
62      *         if the message wasn't processed.
63      */
processMessage(Message msg)64     boolean processMessage(Message msg);
65 
66     /**
67      * Name of State for debugging purposes.
68      *
69      * @return name of state.
70      */
71     @UnsupportedAppUsage
getName()72     String getName();
73 }
74