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
17package com.android.server.am;
18
19import java.io.PrintWriter;
20import java.util.ArrayList;
21
22import android.app.IStopUserCallback;
23import android.os.UserHandle;
24import android.util.ArrayMap;
25
26public final class UserState {
27    // User is first coming up.
28    public final static int STATE_BOOTING = 0;
29    // User is in the normal running state.
30    public final static int STATE_RUNNING = 1;
31    // User is in the initial process of being stopped.
32    public final static int STATE_STOPPING = 2;
33    // User is in the final phase of stopping, sending Intent.ACTION_SHUTDOWN.
34    public final static int STATE_SHUTDOWN = 3;
35
36    public final UserHandle mHandle;
37    public final ArrayList<IStopUserCallback> mStopCallbacks
38            = new ArrayList<IStopUserCallback>();
39
40    public int mState = STATE_BOOTING;
41    public boolean switching;
42    public boolean initializing;
43
44    /**
45     * The last time that a provider was reported to usage stats as being brought to important
46     * foreground procstate.
47     */
48    public final ArrayMap<String,Long> mProviderLastReportedFg = new ArrayMap<>();
49
50    public UserState(UserHandle handle, boolean initial) {
51        mHandle = handle;
52    }
53
54    void dump(String prefix, PrintWriter pw) {
55        pw.print(prefix); pw.print("mState=");
56        switch (mState) {
57            case STATE_BOOTING: pw.print("BOOTING"); break;
58            case STATE_RUNNING: pw.print("RUNNING"); break;
59            case STATE_STOPPING: pw.print("STOPPING"); break;
60            case STATE_SHUTDOWN: pw.print("SHUTDOWN"); break;
61            default: pw.print(mState); break;
62        }
63        if (switching) pw.print(" SWITCHING");
64        if (initializing) pw.print(" INITIALIZING");
65        pw.println();
66    }
67}
68