Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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.server.am; |
| 18 | |
| 19 | import java.io.PrintWriter; |
| 20 | import java.util.ArrayList; |
| 21 | |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame^] | 22 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_MU; |
| 23 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 24 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 25 | |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 26 | import android.app.IStopUserCallback; |
| 27 | import android.os.UserHandle; |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 28 | import android.util.ArrayMap; |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame^] | 29 | import android.util.Slog; |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 30 | |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 31 | public final class UserState { |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame^] | 32 | private static final String TAG = TAG_WITH_CLASS_NAME ? "UserState" : TAG_AM; |
| 33 | |
Dianne Hackborn | 36d337a | 2012-10-08 14:33:47 -0700 | [diff] [blame] | 34 | // User is first coming up. |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 35 | public final static int STATE_BOOTING = 0; |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame^] | 36 | // User is in the locked running state. |
| 37 | public final static int STATE_RUNNING_LOCKED = 1; |
Dianne Hackborn | 36d337a | 2012-10-08 14:33:47 -0700 | [diff] [blame] | 38 | // User is in the normal running state. |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame^] | 39 | public final static int STATE_RUNNING = 2; |
Dianne Hackborn | 36d337a | 2012-10-08 14:33:47 -0700 | [diff] [blame] | 40 | // User is in the initial process of being stopped. |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame^] | 41 | public final static int STATE_STOPPING = 3; |
Dianne Hackborn | 36d337a | 2012-10-08 14:33:47 -0700 | [diff] [blame] | 42 | // User is in the final phase of stopping, sending Intent.ACTION_SHUTDOWN. |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame^] | 43 | public final static int STATE_SHUTDOWN = 4; |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 44 | |
| 45 | public final UserHandle mHandle; |
| 46 | public final ArrayList<IStopUserCallback> mStopCallbacks |
| 47 | = new ArrayList<IStopUserCallback>(); |
| 48 | |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame^] | 49 | public int state = STATE_BOOTING; |
| 50 | public int lastState = STATE_BOOTING; |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 51 | public boolean switching; |
| 52 | public boolean initializing; |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 53 | |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 54 | /** |
| 55 | * The last time that a provider was reported to usage stats as being brought to important |
| 56 | * foreground procstate. |
| 57 | */ |
| 58 | public final ArrayMap<String,Long> mProviderLastReportedFg = new ArrayMap<>(); |
| 59 | |
Jeff Sharkey | f9fc6d6 | 2015-11-08 16:46:05 -0800 | [diff] [blame] | 60 | public UserState(UserHandle handle) { |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 61 | mHandle = handle; |
| 62 | } |
| 63 | |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame^] | 64 | public void setState(int newState) { |
| 65 | if (DEBUG_MU) { |
| 66 | Slog.i(TAG, "User " + mHandle.getIdentifier() + " state changed from " |
| 67 | + stateToString(state) + " to " + stateToString(newState)); |
Dianne Hackborn | 36d337a | 2012-10-08 14:33:47 -0700 | [diff] [blame] | 68 | } |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame^] | 69 | lastState = state; |
| 70 | state = newState; |
| 71 | } |
| 72 | |
| 73 | private static String stateToString(int state) { |
| 74 | switch (state) { |
| 75 | case STATE_BOOTING: return "BOOTING"; |
| 76 | case STATE_RUNNING_LOCKED: return "RUNNING_LOCKED"; |
| 77 | case STATE_RUNNING: return "RUNNING"; |
| 78 | case STATE_STOPPING: return "STOPPING"; |
| 79 | case STATE_SHUTDOWN: return "SHUTDOWN"; |
| 80 | default: return Integer.toString(state); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | void dump(String prefix, PrintWriter pw) { |
| 85 | pw.print(prefix); |
| 86 | pw.print("state="); pw.print(stateToString(state)); |
| 87 | pw.print(" lastState="); pw.print(stateToString(lastState)); |
Dianne Hackborn | d4ac8d7 | 2012-09-27 23:20:10 -0700 | [diff] [blame] | 88 | if (switching) pw.print(" SWITCHING"); |
| 89 | if (initializing) pw.print(" INITIALIZING"); |
| 90 | pw.println(); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 91 | } |
| 92 | } |