1 /**
2  * Copyright (C) 2009 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.annotation.SuppressLint;
20 import android.compat.annotation.UnsupportedAppUsage;
21 import android.os.Build;
22 import android.os.Message;
23 
24 /**
25  * {@hide}
26  *
27  * The class for implementing states in a StateMachine
28  */
29 @SuppressLint("AndroidFrameworkRequiresPermission")
30 public class State implements IState {
31 
32     /**
33      * Constructor
34      */
35     @UnsupportedAppUsage
State()36     protected State() {
37     }
38 
39     /* (non-Javadoc)
40      * @see com.android.internal.util.IState#enter()
41      */
42     @UnsupportedAppUsage
43     @Override
enter()44     public void enter() {
45     }
46 
47     /* (non-Javadoc)
48      * @see com.android.internal.util.IState#exit()
49      */
50     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
51     @Override
exit()52     public void exit() {
53     }
54 
55     /* (non-Javadoc)
56      * @see com.android.internal.util.IState#processMessage(android.os.Message)
57      */
58     @UnsupportedAppUsage
59     @Override
processMessage(Message msg)60     public boolean processMessage(Message msg) {
61         return false;
62     }
63 
64     /**
65      * Name of State for debugging purposes.
66      *
67      * This default implementation returns the class name, returning
68      * the instance name would better in cases where a State class
69      * is used for multiple states. But normally there is one class per
70      * state and the class name is sufficient and easy to get. You may
71      * want to provide a setName or some other mechanism for setting
72      * another name if the class name is not appropriate.
73      *
74      * @see com.android.internal.util.IState#processMessage(android.os.Message)
75      */
76     @UnsupportedAppUsage
77     @Override
getName()78     public String getName() {
79         String name = getClass().getName();
80         int lastDollar = name.lastIndexOf('$');
81         return name.substring(lastDollar + 1);
82     }
83 }
84