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