• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.systemui.settings
18 
19 import android.content.Context
20 import android.content.pm.UserInfo
21 import android.os.UserHandle
22 import com.android.systemui.util.annotations.WeaklyReferencedCallback
23 import java.util.concurrent.Executor
24 
25 /**
26  * User tracker for SystemUI.
27  *
28  * This tracker provides async access to current user information, as well as callbacks for
29  * user/profile change.
30  */
31 interface UserTracker : UserContentResolverProvider, UserContextProvider {
32 
33     /** Current user's id. */
34     val userId: Int
35 
36     /** [UserHandle] for current user */
37     val userHandle: UserHandle
38 
39     /** [UserInfo] for current user */
40     val userInfo: UserInfo
41 
42     /**
43      * List of profiles associated with the current user.
44      *
45      * Quiet work profiles will still appear here, but will have the `QUIET_MODE` flag.
46      *
47      * Disabled work profiles will also appear here. Listeners will be notified when profiles go
48      * from disabled to enabled (as UserInfo are immutable) with the updated list.
49      */
50     val userProfiles: List<UserInfo>
51 
52     /** Is the system in the process of switching users? */
53     val isUserSwitching: Boolean
54 
55     /** Add a [Callback] to be notified of chances, on a particular [Executor] */
addCallbacknull56     fun addCallback(callback: Callback, executor: Executor)
57 
58     /** Remove a [Callback] previously added. */
59     fun removeCallback(callback: Callback)
60 
61     /** Callback for notifying of changes. */
62     @WeaklyReferencedCallback
63     interface Callback {
64         /**
65          * Same as {@link onBeforeUserSwitching(Int, Runnable)} but the callback will be called
66          * automatically after the completion of this method.
67          */
68         fun onBeforeUserSwitching(newUser: Int) {}
69 
70         /** Notifies that the current user will be changed. */
71         fun onBeforeUserSwitching(newUser: Int, resultCallback: Runnable) {
72             onBeforeUserSwitching(newUser)
73             resultCallback.run()
74         }
75 
76         /**
77          * Same as {@link onUserChanging(Int, Context, Runnable)} but the callback will be called
78          * automatically after the completion of this method.
79          */
80         fun onUserChanging(newUser: Int, userContext: Context) {}
81 
82         /**
83          * Notifies that the current user is being changed. Override this method to run things while
84          * the screen is frozen for the user switch. Please use {@link #onUserChanged} if the task
85          * doesn't need to push the unfreezing of the screen further. Please be aware that code
86          * executed in this callback will lengthen the user switch duration. When overriding this
87          * method, resultCallback#run() MUST be called once the execution is complete.
88          */
89         fun onUserChanging(newUser: Int, userContext: Context, resultCallback: Runnable) {
90             onUserChanging(newUser, userContext)
91             resultCallback.run()
92         }
93 
94         /**
95          * Notifies that the current user has changed. Override this method to run things after the
96          * screen is unfrozen for the user switch. Please see {@link #onUserChanging} if you need to
97          * hide jank.
98          */
99         fun onUserChanged(newUser: Int, userContext: Context) {}
100 
101         /** Notifies that the current user's profiles have changed. */
102         fun onProfilesChanged(profiles: List<@JvmSuppressWildcards UserInfo>) {}
103     }
104 }
105