Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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; |
| 18 | |
Vishnu Nair | e3e4d25 | 2018-03-01 11:26:57 -0800 | [diff] [blame] | 19 | import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_DEFAULT; |
| 20 | |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 21 | import android.annotation.IntDef; |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 22 | import android.annotation.NonNull; |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 23 | import android.annotation.Nullable; |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 24 | import android.annotation.UserIdInt; |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 25 | import android.app.ActivityThread; |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 26 | import android.content.Context; |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 27 | import android.content.pm.UserInfo; |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 28 | import android.os.IBinder; |
| 29 | import android.os.ServiceManager; |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 30 | import android.os.UserHandle; |
Jeff Sharkey | bb4988a | 2017-02-23 17:31:39 -0700 | [diff] [blame] | 31 | import android.os.UserManager; |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 32 | |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 33 | import com.android.server.pm.UserManagerService; |
| 34 | |
Felipe Leme | e87735b | 2019-12-17 09:58:40 -0800 | [diff] [blame] | 35 | import java.io.PrintWriter; |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 36 | import java.lang.annotation.Retention; |
| 37 | import java.lang.annotation.RetentionPolicy; |
Felipe Leme | e87735b | 2019-12-17 09:58:40 -0800 | [diff] [blame] | 38 | import java.util.ArrayList; |
| 39 | import java.util.List; |
| 40 | |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 41 | /** |
Adam Lesinski | b102b2c | 2013-12-20 11:46:14 -0800 | [diff] [blame] | 42 | * The base class for services running in the system process. Override and implement |
| 43 | * the lifecycle event callback methods as needed. |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 44 | * <p> |
Adam Lesinski | b102b2c | 2013-12-20 11:46:14 -0800 | [diff] [blame] | 45 | * The lifecycle of a SystemService: |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 46 | * </p><ul> |
| 47 | * <li>The constructor is called and provided with the system {@link Context} |
| 48 | * to initialize the system service. |
| 49 | * <li>{@link #onStart()} is called to get the service running. The service should |
| 50 | * publish its binder interface at this point using |
| 51 | * {@link #publishBinderService(String, IBinder)}. It may also publish additional |
| 52 | * local interfaces that other services within the system server may use to access |
| 53 | * privileged internal functions. |
| 54 | * <li>Then {@link #onBootPhase(int)} is called as many times as there are boot phases |
Dianne Hackborn | a750a63 | 2015-06-16 17:18:23 -0700 | [diff] [blame] | 55 | * until {@link #PHASE_BOOT_COMPLETED} is sent, which is the last boot phase. Each phase |
Adam Lesinski | b102b2c | 2013-12-20 11:46:14 -0800 | [diff] [blame] | 56 | * is an opportunity to do special work, like acquiring optional service dependencies, |
| 57 | * waiting to see if SafeMode is enabled, or registering with a service that gets |
| 58 | * started after this one. |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 59 | * </ul><p> |
| 60 | * NOTE: All lifecycle methods are called from the system server's main looper thread. |
| 61 | * </p> |
Adam Lesinski | b102b2c | 2013-12-20 11:46:14 -0800 | [diff] [blame] | 62 | * |
| 63 | * {@hide} |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 64 | */ |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 65 | //@SystemApi(client = Client.MODULE_LIBRARIES, process = Process.SYSTEM_SERVER) |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 66 | public abstract class SystemService { |
Felipe Leme | 501a514 | 2019-08-15 16:23:47 -0700 | [diff] [blame] | 67 | |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 68 | /** @hide */ |
Felipe Leme | 501a514 | 2019-08-15 16:23:47 -0700 | [diff] [blame] | 69 | // TODO(b/133242016) STOPSHIP: change to false before R ships |
| 70 | protected static final boolean DEBUG_USER = true; |
| 71 | |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 72 | /* |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 73 | * The earliest boot phase the system send to system services on boot. |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 74 | */ |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 75 | public static final int PHASE_WAIT_FOR_DEFAULT_DISPLAY = 100; |
Adam Lesinski | 2cb6c60 | 2014-02-14 17:19:56 -0800 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * After receiving this boot phase, services can obtain lock settings data. |
| 79 | */ |
Amith Yamasani | 9158825 | 2013-11-22 08:25:26 -0800 | [diff] [blame] | 80 | public static final int PHASE_LOCK_SETTINGS_READY = 480; |
Adam Lesinski | 2cb6c60 | 2014-02-14 17:19:56 -0800 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * After receiving this boot phase, services can safely call into core system services |
| 84 | * such as the PowerManager or PackageManager. |
| 85 | */ |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 86 | public static final int PHASE_SYSTEM_SERVICES_READY = 500; |
Adam Lesinski | 2cb6c60 | 2014-02-14 17:19:56 -0800 | [diff] [blame] | 87 | |
| 88 | /** |
Daichi Hirono | edfcb00 | 2017-10-10 17:22:58 +0900 | [diff] [blame] | 89 | * After receiving this boot phase, services can safely call into device specific services. |
| 90 | */ |
| 91 | public static final int PHASE_DEVICE_SPECIFIC_SERVICES_READY = 520; |
| 92 | |
| 93 | /** |
Adam Lesinski | 2cb6c60 | 2014-02-14 17:19:56 -0800 | [diff] [blame] | 94 | * After receiving this boot phase, services can broadcast Intents. |
| 95 | */ |
| 96 | public static final int PHASE_ACTIVITY_MANAGER_READY = 550; |
| 97 | |
| 98 | /** |
| 99 | * After receiving this boot phase, services can start/bind to third party apps. |
| 100 | * Apps will be able to make Binder calls into services at this point. |
| 101 | */ |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 102 | public static final int PHASE_THIRD_PARTY_APPS_CAN_START = 600; |
Adam Lesinski | 2cb6c60 | 2014-02-14 17:19:56 -0800 | [diff] [blame] | 103 | |
| 104 | /** |
Jeff Brown | 6d2a949 | 2014-08-07 19:06:49 -0700 | [diff] [blame] | 105 | * After receiving this boot phase, services can allow user interaction with the device. |
| 106 | * This phase occurs when boot has completed and the home application has started. |
| 107 | * System services may prefer to listen to this phase rather than registering a |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 108 | * broadcast receiver for {@link android.content.Intent#ACTION_LOCKED_BOOT_COMPLETED} |
| 109 | * to reduce overall latency. |
Adam Lesinski | 2cb6c60 | 2014-02-14 17:19:56 -0800 | [diff] [blame] | 110 | */ |
Jeff Brown | 6d2a949 | 2014-08-07 19:06:49 -0700 | [diff] [blame] | 111 | public static final int PHASE_BOOT_COMPLETED = 1000; |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 112 | |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 113 | /** @hide */ |
| 114 | @IntDef(flag = true, prefix = { "PHASE_" }, value = { |
| 115 | PHASE_WAIT_FOR_DEFAULT_DISPLAY, |
| 116 | PHASE_LOCK_SETTINGS_READY, |
| 117 | PHASE_SYSTEM_SERVICES_READY, |
| 118 | PHASE_DEVICE_SPECIFIC_SERVICES_READY, |
| 119 | PHASE_ACTIVITY_MANAGER_READY, |
| 120 | PHASE_THIRD_PARTY_APPS_CAN_START, |
| 121 | PHASE_BOOT_COMPLETED |
| 122 | }) |
| 123 | @Retention(RetentionPolicy.SOURCE) |
| 124 | public @interface BootPhase {} |
| 125 | |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 126 | private final Context mContext; |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 127 | |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 128 | /** |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 129 | * Class representing user in question in the lifecycle callbacks. |
| 130 | * @hide |
| 131 | */ |
| 132 | //@SystemApi(client = Client.MODULE_LIBRARIES, process = Process.SYSTEM_SERVER) |
| 133 | public static final class TargetUser { |
| 134 | @NonNull |
| 135 | private final UserInfo mUserInfo; |
| 136 | |
| 137 | /** @hide */ |
| 138 | public TargetUser(@NonNull UserInfo userInfo) { |
| 139 | mUserInfo = userInfo; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * @return The information about the user. <b>NOTE: </b> this is a "live" object |
| 144 | * referenced by {@link UserManagerService} and hence should not be modified. |
| 145 | * |
| 146 | * @hide |
| 147 | */ |
| 148 | @NonNull |
| 149 | public UserInfo getUserInfo() { |
| 150 | return mUserInfo; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * @return the target {@link UserHandle}. |
| 155 | */ |
| 156 | @NonNull |
| 157 | public UserHandle getUserHandle() { |
| 158 | return mUserInfo.getUserHandle(); |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * @return the integer user id |
| 163 | * |
| 164 | * @hide |
| 165 | */ |
| 166 | public int getUserIdentifier() { |
| 167 | return mUserInfo.id; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | /** |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 172 | * Initializes the system service. |
| 173 | * <p> |
| 174 | * Subclasses must define a single argument constructor that accepts the context |
| 175 | * and passes it to super. |
| 176 | * </p> |
| 177 | * |
| 178 | * @param context The system server context. |
| 179 | */ |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 180 | public SystemService(@NonNull Context context) { |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 181 | mContext = context; |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 182 | } |
| 183 | |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 184 | /** |
| 185 | * Gets the system context. |
| 186 | */ |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 187 | @NonNull |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 188 | public final Context getContext() { |
| 189 | return mContext; |
| 190 | } |
| 191 | |
| 192 | /** |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 193 | * Get the system UI context. This context is to be used for displaying UI. It is themable, |
| 194 | * which means resources can be overridden at runtime. Do not use to retrieve properties that |
| 195 | * configure the behavior of the device that is not UX related. |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 196 | * |
| 197 | * @hide |
Adam Lesinski | a82b626 | 2017-03-21 16:56:17 -0700 | [diff] [blame] | 198 | */ |
| 199 | public final Context getUiContext() { |
| 200 | // This has already been set up by the time any SystemServices are created. |
| 201 | return ActivityThread.currentActivityThread().getSystemUiContext(); |
| 202 | } |
| 203 | |
| 204 | /** |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 205 | * Returns true if the system is running in safe mode. |
| 206 | * TODO: we should define in which phase this becomes valid |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 207 | * |
| 208 | * @hide |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 209 | */ |
Amith Yamasani | 9158825 | 2013-11-22 08:25:26 -0800 | [diff] [blame] | 210 | public final boolean isSafeMode() { |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 211 | return getManager().isSafeMode(); |
Amith Yamasani | 9158825 | 2013-11-22 08:25:26 -0800 | [diff] [blame] | 212 | } |
| 213 | |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 214 | /** |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 215 | * Called when the system service should publish a binder service using |
| 216 | * {@link #publishBinderService(String, IBinder).} |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 217 | */ |
| 218 | public abstract void onStart(); |
| 219 | |
| 220 | /** |
| 221 | * Called on each phase of the boot process. Phases before the service's start phase |
| 222 | * (as defined in the @Service annotation) are never received. |
| 223 | * |
| 224 | * @param phase The current boot phase. |
| 225 | */ |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 226 | public void onBootPhase(@BootPhase int phase) {} |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 227 | |
| 228 | /** |
Felipe Leme | 501a514 | 2019-08-15 16:23:47 -0700 | [diff] [blame] | 229 | * Checks if the service should be available for the given user. |
| 230 | * |
| 231 | * <p>By default returns {@code true}, but subclasses should extend for optimization, if they |
| 232 | * don't support some types (like headless system user). |
| 233 | */ |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 234 | public boolean isSupportedUser(@NonNull TargetUser user) { |
Felipe Leme | 501a514 | 2019-08-15 16:23:47 -0700 | [diff] [blame] | 235 | return true; |
| 236 | } |
| 237 | |
| 238 | /** |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 239 | * Helper method used to dump which users are {@link #onStartUser(TargetUser) supported}. |
| 240 | * |
| 241 | * @hide |
Felipe Leme | e87735b | 2019-12-17 09:58:40 -0800 | [diff] [blame] | 242 | */ |
| 243 | protected void dumpSupportedUsers(@NonNull PrintWriter pw, @NonNull String prefix) { |
| 244 | final List<UserInfo> allUsers = UserManager.get(mContext).getUsers(); |
| 245 | final List<Integer> supportedUsers = new ArrayList<>(allUsers.size()); |
| 246 | for (UserInfo user : allUsers) { |
| 247 | supportedUsers.add(user.id); |
| 248 | } |
| 249 | if (allUsers.isEmpty()) { |
| 250 | pw.print(prefix); pw.println("No supported users"); |
| 251 | } else { |
| 252 | final int size = supportedUsers.size(); |
| 253 | pw.print(prefix); pw.print(size); pw.print(" supported user"); |
| 254 | if (size > 1) pw.print("s"); |
| 255 | pw.print(": "); pw.println(supportedUsers); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | /** |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 260 | * @deprecated subclasses should extend {@link #onStartUser(TargetUser)} instead |
| 261 | * (which by default calls this method). |
| 262 | * |
| 263 | * @hide |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 264 | */ |
| 265 | @Deprecated |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 266 | public void onStartUser(@UserIdInt int userId) {} |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 267 | |
| 268 | /** |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 269 | * @deprecated subclasses should extend {@link #onStartUser(TargetUser)} instead |
| 270 | * (which by default calls this method). |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 271 | * |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 272 | * @hide |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 273 | */ |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 274 | @Deprecated |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 275 | public void onStartUser(@NonNull UserInfo userInfo) { |
| 276 | onStartUser(userInfo.id); |
| 277 | } |
| 278 | |
| 279 | /** |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 280 | * Called when a new user is starting, for system services to initialize any per-user |
| 281 | * state they maintain for running users. |
| 282 | * |
| 283 | * <p>This method is only called when the service {@link #isSupportedUser(TargetUser) supports} |
| 284 | * this user. |
| 285 | * |
| 286 | * @param user target user |
| 287 | */ |
| 288 | public void onStartUser(@NonNull TargetUser user) { |
| 289 | onStartUser(user.getUserInfo()); |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * @deprecated subclasses should extend {@link #onUnlockUser(TargetUser)} instead (which by |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 294 | * default calls this method). |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 295 | * |
| 296 | * @hide |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 297 | */ |
| 298 | @Deprecated |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 299 | public void onUnlockUser(@UserIdInt int userId) {} |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 300 | |
| 301 | /** |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 302 | * @deprecated subclasses should extend {@link #onUnlockUser(TargetUser)} instead (which by |
| 303 | * default calls this method). |
| 304 | * |
| 305 | * @hide |
| 306 | */ |
| 307 | @Deprecated |
| 308 | public void onUnlockUser(@NonNull UserInfo userInfo) { |
| 309 | onUnlockUser(userInfo.id); |
| 310 | } |
| 311 | |
| 312 | /** |
Jeff Sharkey | bb4988a | 2017-02-23 17:31:39 -0700 | [diff] [blame] | 313 | * Called when an existing user is in the process of being unlocked. This |
| 314 | * means the credential-encrypted storage for that user is now available, |
| 315 | * and encryption-aware component filtering is no longer in effect. |
| 316 | * <p> |
| 317 | * While dispatching this event to services, the user is in the |
| 318 | * {@code STATE_RUNNING_UNLOCKING} state, and once dispatching is finished |
| 319 | * the user will transition into the {@code STATE_RUNNING_UNLOCKED} state. |
| 320 | * Code written inside system services should use |
| 321 | * {@link UserManager#isUserUnlockingOrUnlocked(int)} to handle both of |
| 322 | * these states. |
Felipe Leme | 501a514 | 2019-08-15 16:23:47 -0700 | [diff] [blame] | 323 | * <p> |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 324 | * This method is only called when the service {@link #isSupportedUser(TargetUser) supports} |
| 325 | * this user. |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 326 | * |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 327 | * @param user target user |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 328 | */ |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 329 | public void onUnlockUser(@NonNull TargetUser user) { |
| 330 | onUnlockUser(user.getUserInfo()); |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | /** |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 334 | * @deprecated subclasses should extend {@link #onSwitchUser(TargetUser, TargetUser)} instead |
Felipe Leme | 501a514 | 2019-08-15 16:23:47 -0700 | [diff] [blame] | 335 | * (which by default calls this method). |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 336 | * |
| 337 | * @hide |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 338 | */ |
| 339 | @Deprecated |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 340 | public void onSwitchUser(@UserIdInt int toUserId) {} |
| 341 | |
| 342 | /** |
| 343 | * @deprecated subclasses should extend {@link #onSwitchUser(TargetUser, TargetUser)} instead |
| 344 | * (which by default calls this method). |
| 345 | * |
| 346 | * @hide |
| 347 | */ |
| 348 | @Deprecated |
| 349 | public void onSwitchUser(@Nullable UserInfo from, @NonNull UserInfo to) { |
| 350 | onSwitchUser(to.id); |
| 351 | } |
Jeff Sharkey | bedbaa9 | 2015-12-02 16:42:25 -0700 | [diff] [blame] | 352 | |
| 353 | /** |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 354 | * Called when switching to a different foreground user, for system services that have |
| 355 | * special behavior for whichever user is currently in the foreground. This is called |
| 356 | * before any application processes are aware of the new user. |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 357 | * |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 358 | * <p>This method is only called when the service {@link #isSupportedUser(TargetUser) supports} |
| 359 | * either of the users ({@code from} or {@code to}). |
Felipe Leme | 501a514 | 2019-08-15 16:23:47 -0700 | [diff] [blame] | 360 | * |
| 361 | * <b>NOTE: </b> both {@code from} and {@code to} are "live" objects |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 362 | * referenced by {@link UserManagerService} and hence should not be modified. |
Felipe Leme | 501a514 | 2019-08-15 16:23:47 -0700 | [diff] [blame] | 363 | * |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 364 | * @param from the user switching from |
| 365 | * @param to the user switching to |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 366 | */ |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 367 | public void onSwitchUser(@Nullable TargetUser from, @NonNull TargetUser to) { |
| 368 | onSwitchUser((from == null ? null : from.getUserInfo()), to.getUserInfo()); |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | /** |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 372 | * @deprecated subclasses should extend {@link #onStopUser(TargetUser)} instead |
| 373 | * (which by default calls this method). |
| 374 | * |
| 375 | * @hide |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 376 | */ |
| 377 | @Deprecated |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 378 | public void onStopUser(@UserIdInt int userId) {} |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 379 | |
| 380 | /** |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 381 | * @deprecated subclasses should extend {@link #onStopUser(TargetUser)} instead |
| 382 | * (which by default calls this method). |
| 383 | * |
| 384 | * @hide |
| 385 | */ |
| 386 | @Deprecated |
| 387 | public void onStopUser(@NonNull UserInfo user) { |
| 388 | onStopUser(user.id); |
| 389 | |
| 390 | } |
| 391 | |
| 392 | /** |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 393 | * Called when an existing user is stopping, for system services to finalize any per-user |
| 394 | * state they maintain for running users. This is called prior to sending the SHUTDOWN |
| 395 | * broadcast to the user; it is a good place to stop making use of any resources of that |
| 396 | * user (such as binding to a service running in the user). |
Makoto Onuki | 01ce92b | 2017-04-28 12:24:16 -0700 | [diff] [blame] | 397 | * |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 398 | * <p>This method is only called when the service {@link #isSupportedUser(TargetUser) supports} |
| 399 | * this user. |
Felipe Leme | 501a514 | 2019-08-15 16:23:47 -0700 | [diff] [blame] | 400 | * |
Makoto Onuki | 01ce92b | 2017-04-28 12:24:16 -0700 | [diff] [blame] | 401 | * <p>NOTE: This is the last callback where the callee may access the target user's CE storage. |
| 402 | * |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 403 | * @param user target user |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 404 | */ |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 405 | public void onStopUser(@NonNull TargetUser user) { |
| 406 | onStopUser(user.getUserInfo()); |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | /** |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 410 | * @deprecated subclasses should extend {@link #onCleanupUser(TargetUser)} instead (which by |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 411 | * default calls this method). |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 412 | * |
| 413 | * @hide |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 414 | */ |
| 415 | @Deprecated |
Bookatz | f56f258 | 2019-09-04 16:06:41 -0700 | [diff] [blame] | 416 | public void onCleanupUser(@UserIdInt int userId) {} |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 417 | |
| 418 | /** |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 419 | * @deprecated subclasses should extend {@link #onCleanupUser(TargetUser)} instead (which by |
| 420 | * default calls this method). |
| 421 | * |
| 422 | * @hide |
| 423 | */ |
| 424 | @Deprecated |
| 425 | public void onCleanupUser(@NonNull UserInfo user) { |
| 426 | onCleanupUser(user.id); |
| 427 | } |
| 428 | |
| 429 | /** |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 430 | * Called when an existing user is stopping, for system services to finalize any per-user |
| 431 | * state they maintain for running users. This is called after all application process |
| 432 | * teardown of the user is complete. |
Makoto Onuki | 01ce92b | 2017-04-28 12:24:16 -0700 | [diff] [blame] | 433 | * |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 434 | * <p>This method is only called when the service {@link #isSupportedUser(TargetUser) supports} |
| 435 | * this user. |
Felipe Leme | 501a514 | 2019-08-15 16:23:47 -0700 | [diff] [blame] | 436 | * |
Makoto Onuki | 01ce92b | 2017-04-28 12:24:16 -0700 | [diff] [blame] | 437 | * <p>NOTE: When this callback is called, the CE storage for the target user may not be |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 438 | * accessible already. Use {@link #onStopUser(TargetUser)} instead if you need to access the CE |
Felipe Leme | 501a514 | 2019-08-15 16:23:47 -0700 | [diff] [blame] | 439 | * storage. |
Makoto Onuki | 01ce92b | 2017-04-28 12:24:16 -0700 | [diff] [blame] | 440 | * |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 441 | * @param user target user |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 442 | */ |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 443 | public void onCleanupUser(@NonNull TargetUser user) { |
| 444 | onCleanupUser(user.getUserInfo()); |
Felipe Leme | e5434c3 | 2019-08-13 09:28:33 -0700 | [diff] [blame] | 445 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 446 | |
| 447 | /** |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 448 | * Publish the service so it is accessible to other services and apps. |
Vishnu Nair | e3e4d25 | 2018-03-01 11:26:57 -0800 | [diff] [blame] | 449 | * |
| 450 | * @param name the name of the new service |
| 451 | * @param service the service object |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 452 | */ |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 453 | protected final void publishBinderService(@NonNull String name, @NonNull IBinder service) { |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 454 | publishBinderService(name, service, false); |
| 455 | } |
| 456 | |
| 457 | /** |
| 458 | * Publish the service so it is accessible to other services and apps. |
Vishnu Nair | e3e4d25 | 2018-03-01 11:26:57 -0800 | [diff] [blame] | 459 | * |
| 460 | * @param name the name of the new service |
| 461 | * @param service the service object |
| 462 | * @param allowIsolated set to true to allow isolated sandboxed processes |
| 463 | * to access this service |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 464 | */ |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 465 | protected final void publishBinderService(@NonNull String name, @NonNull IBinder service, |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 466 | boolean allowIsolated) { |
Vishnu Nair | e3e4d25 | 2018-03-01 11:26:57 -0800 | [diff] [blame] | 467 | publishBinderService(name, service, allowIsolated, DUMP_FLAG_PRIORITY_DEFAULT); |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * Publish the service so it is accessible to other services and apps. |
| 472 | * |
| 473 | * @param name the name of the new service |
| 474 | * @param service the service object |
| 475 | * @param allowIsolated set to true to allow isolated sandboxed processes |
| 476 | * to access this service |
| 477 | * @param dumpPriority supported dump priority levels as a bitmask |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 478 | * |
| 479 | * @hide |
Vishnu Nair | e3e4d25 | 2018-03-01 11:26:57 -0800 | [diff] [blame] | 480 | */ |
| 481 | protected final void publishBinderService(String name, IBinder service, |
| 482 | boolean allowIsolated, int dumpPriority) { |
| 483 | ServiceManager.addService(name, service, allowIsolated, dumpPriority); |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /** |
| 487 | * Get a binder service by its name. |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 488 | * |
| 489 | * @hide |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 490 | */ |
| 491 | protected final IBinder getBinderService(String name) { |
| 492 | return ServiceManager.getService(name); |
| 493 | } |
| 494 | |
| 495 | /** |
| 496 | * Publish the service so it is only accessible to the system process. |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 497 | * |
| 498 | * @hide |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 499 | */ |
| 500 | protected final <T> void publishLocalService(Class<T> type, T service) { |
| 501 | LocalServices.addService(type, service); |
| 502 | } |
| 503 | |
| 504 | /** |
| 505 | * Get a local service by interface. |
Makoto Onuki | c881590 | 2020-01-08 13:55:25 -0800 | [diff] [blame] | 506 | * |
| 507 | * @hide |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 508 | */ |
| 509 | protected final <T> T getLocalService(Class<T> type) { |
| 510 | return LocalServices.getService(type); |
| 511 | } |
| 512 | |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 513 | private SystemServiceManager getManager() { |
| 514 | return LocalServices.getService(SystemServiceManager.class); |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 515 | } |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 516 | } |