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 java.util.concurrent.CountDownLatch 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 /** 34 * Current user's id. 35 */ 36 val userId: Int 37 38 /** 39 * [UserHandle] for current user 40 */ 41 val userHandle: UserHandle 42 43 /** 44 * [UserInfo] for current user 45 */ 46 val userInfo: UserInfo 47 48 /** 49 * List of profiles associated with the current user. 50 * 51 * Quiet work profiles will still appear here, but will have the `QUIET_MODE` flag. 52 */ 53 val userProfiles: List<UserInfo> 54 55 /** 56 * Add a [Callback] to be notified of chances, on a particular [Executor] 57 */ 58 fun addCallback(callback: Callback, executor: Executor) 59 60 /** 61 * Remove a [Callback] previously added. 62 */ 63 fun removeCallback(callback: Callback) 64 65 /** 66 * Callback for notifying of changes. 67 */ 68 interface Callback { 69 70 /** 71 * Same as {@link onUserChanging(Int, Context, CountDownLatch)} but the latch will be 72 * auto-decremented after the completion of this method. 73 */ 74 @JvmDefault 75 fun onUserChanging(newUser: Int, userContext: Context) {} 76 77 /** 78 * Notifies that the current user is being changed. 79 * Override this method to run things while the screen is frozen for the user switch. 80 * Please use {@link #onUserChanged} if the task doesn't need to push the unfreezing of the 81 * screen further. Please be aware that code executed in this callback will lengthen the 82 * user switch duration. When overriding this method, countDown() MUST be called on the 83 * latch once execution is complete. 84 */ 85 @JvmDefault 86 fun onUserChanging(newUser: Int, userContext: Context, latch: CountDownLatch) { 87 onUserChanging(newUser, userContext) 88 latch.countDown() 89 } 90 91 /** 92 * Notifies that the current user has changed. 93 * Override this method to run things after the screen is unfrozen for the user switch. 94 * Please see {@link #onUserChanging} if you need to hide jank. 95 */ 96 @JvmDefault 97 fun onUserChanged(newUser: Int, userContext: Context) {} 98 99 /** 100 * Notifies that the current user's profiles have changed. 101 */ 102 @JvmDefault 103 fun onProfilesChanged(profiles: List<@JvmSuppressWildcards UserInfo>) {} 104 } 105 } 106