blob: b1584fea90c100d3ebe0c06a6e28a6ee99ae40ba [file] [log] [blame]
Adam Lesinski182f73f2013-12-05 16:48:06 -08001/*
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
17package com.android.server;
18
Vishnu Naire3e4d252018-03-01 11:26:57 -080019import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_DEFAULT;
20
Makoto Onukic8815902020-01-08 13:55:25 -080021import android.annotation.IntDef;
Felipe Lemee5434c32019-08-13 09:28:33 -070022import android.annotation.NonNull;
Makoto Onukic8815902020-01-08 13:55:25 -080023import android.annotation.Nullable;
Makoto Onukibf03b1b2020-01-15 11:16:19 -080024import android.annotation.SystemApi;
25import android.annotation.SystemApi.Client;
26import android.annotation.SystemApi.Process;
Felipe Lemee5434c32019-08-13 09:28:33 -070027import android.annotation.UserIdInt;
Adam Lesinskia82b6262017-03-21 16:56:17 -070028import android.app.ActivityThread;
Adam Lesinski182f73f2013-12-05 16:48:06 -080029import android.content.Context;
Felipe Lemee5434c32019-08-13 09:28:33 -070030import android.content.pm.UserInfo;
Adam Lesinski182f73f2013-12-05 16:48:06 -080031import android.os.IBinder;
32import android.os.ServiceManager;
Makoto Onukic8815902020-01-08 13:55:25 -080033import android.os.UserHandle;
Jeff Sharkeybb4988a2017-02-23 17:31:39 -070034import android.os.UserManager;
Adam Lesinski182f73f2013-12-05 16:48:06 -080035
Felipe Lemee5434c32019-08-13 09:28:33 -070036import com.android.server.pm.UserManagerService;
37
Felipe Lemee87735b2019-12-17 09:58:40 -080038import java.io.PrintWriter;
Makoto Onukic8815902020-01-08 13:55:25 -080039import java.lang.annotation.Retention;
40import java.lang.annotation.RetentionPolicy;
Felipe Lemee87735b2019-12-17 09:58:40 -080041import java.util.ArrayList;
42import java.util.List;
43
Adam Lesinski182f73f2013-12-05 16:48:06 -080044/**
Adam Lesinskib102b2c2013-12-20 11:46:14 -080045 * The base class for services running in the system process. Override and implement
46 * the lifecycle event callback methods as needed.
Jeff Brownb880d882014-02-10 19:47:07 -080047 * <p>
Adam Lesinskib102b2c2013-12-20 11:46:14 -080048 * The lifecycle of a SystemService:
Jeff Brownb880d882014-02-10 19:47:07 -080049 * </p><ul>
50 * <li>The constructor is called and provided with the system {@link Context}
51 * to initialize the system service.
52 * <li>{@link #onStart()} is called to get the service running. The service should
53 * publish its binder interface at this point using
54 * {@link #publishBinderService(String, IBinder)}. It may also publish additional
55 * local interfaces that other services within the system server may use to access
56 * privileged internal functions.
57 * <li>Then {@link #onBootPhase(int)} is called as many times as there are boot phases
Dianne Hackborna750a632015-06-16 17:18:23 -070058 * until {@link #PHASE_BOOT_COMPLETED} is sent, which is the last boot phase. Each phase
Adam Lesinskib102b2c2013-12-20 11:46:14 -080059 * is an opportunity to do special work, like acquiring optional service dependencies,
60 * waiting to see if SafeMode is enabled, or registering with a service that gets
61 * started after this one.
Jeff Brownb880d882014-02-10 19:47:07 -080062 * </ul><p>
63 * NOTE: All lifecycle methods are called from the system server's main looper thread.
64 * </p>
Adam Lesinskib102b2c2013-12-20 11:46:14 -080065 *
66 * {@hide}
Adam Lesinski182f73f2013-12-05 16:48:06 -080067 */
Makoto Onukibf03b1b2020-01-15 11:16:19 -080068@SystemApi(client = Client.MODULE_LIBRARIES, process = Process.SYSTEM_SERVER)
Adam Lesinski182f73f2013-12-05 16:48:06 -080069public abstract class SystemService {
Felipe Leme501a5142019-08-15 16:23:47 -070070
Makoto Onukic8815902020-01-08 13:55:25 -080071 /** @hide */
Felipe Leme501a5142019-08-15 16:23:47 -070072 // TODO(b/133242016) STOPSHIP: change to false before R ships
73 protected static final boolean DEBUG_USER = true;
74
Adam Lesinski182f73f2013-12-05 16:48:06 -080075 /*
Makoto Onukic8815902020-01-08 13:55:25 -080076 * The earliest boot phase the system send to system services on boot.
Adam Lesinski182f73f2013-12-05 16:48:06 -080077 */
Makoto Onukic8815902020-01-08 13:55:25 -080078 public static final int PHASE_WAIT_FOR_DEFAULT_DISPLAY = 100;
Adam Lesinski2cb6c602014-02-14 17:19:56 -080079
80 /**
81 * After receiving this boot phase, services can obtain lock settings data.
82 */
Amith Yamasani91588252013-11-22 08:25:26 -080083 public static final int PHASE_LOCK_SETTINGS_READY = 480;
Adam Lesinski2cb6c602014-02-14 17:19:56 -080084
85 /**
86 * After receiving this boot phase, services can safely call into core system services
87 * such as the PowerManager or PackageManager.
88 */
Adam Lesinski182f73f2013-12-05 16:48:06 -080089 public static final int PHASE_SYSTEM_SERVICES_READY = 500;
Adam Lesinski2cb6c602014-02-14 17:19:56 -080090
91 /**
Daichi Hironoedfcb002017-10-10 17:22:58 +090092 * After receiving this boot phase, services can safely call into device specific services.
93 */
94 public static final int PHASE_DEVICE_SPECIFIC_SERVICES_READY = 520;
95
96 /**
Adam Lesinski2cb6c602014-02-14 17:19:56 -080097 * After receiving this boot phase, services can broadcast Intents.
98 */
99 public static final int PHASE_ACTIVITY_MANAGER_READY = 550;
100
101 /**
102 * After receiving this boot phase, services can start/bind to third party apps.
103 * Apps will be able to make Binder calls into services at this point.
104 */
Adam Lesinski182f73f2013-12-05 16:48:06 -0800105 public static final int PHASE_THIRD_PARTY_APPS_CAN_START = 600;
Adam Lesinski2cb6c602014-02-14 17:19:56 -0800106
107 /**
Jeff Brown6d2a9492014-08-07 19:06:49 -0700108 * After receiving this boot phase, services can allow user interaction with the device.
109 * This phase occurs when boot has completed and the home application has started.
110 * System services may prefer to listen to this phase rather than registering a
Makoto Onukic8815902020-01-08 13:55:25 -0800111 * broadcast receiver for {@link android.content.Intent#ACTION_LOCKED_BOOT_COMPLETED}
112 * to reduce overall latency.
Adam Lesinski2cb6c602014-02-14 17:19:56 -0800113 */
Jeff Brown6d2a9492014-08-07 19:06:49 -0700114 public static final int PHASE_BOOT_COMPLETED = 1000;
Adam Lesinski182f73f2013-12-05 16:48:06 -0800115
Makoto Onukic8815902020-01-08 13:55:25 -0800116 /** @hide */
117 @IntDef(flag = true, prefix = { "PHASE_" }, value = {
118 PHASE_WAIT_FOR_DEFAULT_DISPLAY,
119 PHASE_LOCK_SETTINGS_READY,
120 PHASE_SYSTEM_SERVICES_READY,
121 PHASE_DEVICE_SPECIFIC_SERVICES_READY,
122 PHASE_ACTIVITY_MANAGER_READY,
123 PHASE_THIRD_PARTY_APPS_CAN_START,
124 PHASE_BOOT_COMPLETED
125 })
126 @Retention(RetentionPolicy.SOURCE)
127 public @interface BootPhase {}
128
Jeff Brownb880d882014-02-10 19:47:07 -0800129 private final Context mContext;
Adam Lesinski182f73f2013-12-05 16:48:06 -0800130
Jeff Brownb880d882014-02-10 19:47:07 -0800131 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800132 * Class representing user in question in the lifecycle callbacks.
133 * @hide
134 */
Makoto Onukibf03b1b2020-01-15 11:16:19 -0800135 @SystemApi(client = Client.MODULE_LIBRARIES, process = Process.SYSTEM_SERVER)
Makoto Onukic8815902020-01-08 13:55:25 -0800136 public static final class TargetUser {
137 @NonNull
138 private final UserInfo mUserInfo;
139
140 /** @hide */
141 public TargetUser(@NonNull UserInfo userInfo) {
142 mUserInfo = userInfo;
143 }
144
145 /**
146 * @return The information about the user. <b>NOTE: </b> this is a "live" object
147 * referenced by {@link UserManagerService} and hence should not be modified.
148 *
149 * @hide
150 */
151 @NonNull
152 public UserInfo getUserInfo() {
153 return mUserInfo;
154 }
155
156 /**
157 * @return the target {@link UserHandle}.
158 */
159 @NonNull
160 public UserHandle getUserHandle() {
161 return mUserInfo.getUserHandle();
162 }
163
164 /**
165 * @return the integer user id
166 *
167 * @hide
168 */
169 public int getUserIdentifier() {
170 return mUserInfo.id;
171 }
172 }
173
174 /**
Jeff Brownb880d882014-02-10 19:47:07 -0800175 * Initializes the system service.
176 * <p>
177 * Subclasses must define a single argument constructor that accepts the context
178 * and passes it to super.
179 * </p>
180 *
181 * @param context The system server context.
182 */
Makoto Onukic8815902020-01-08 13:55:25 -0800183 public SystemService(@NonNull Context context) {
Adam Lesinski182f73f2013-12-05 16:48:06 -0800184 mContext = context;
Adam Lesinski182f73f2013-12-05 16:48:06 -0800185 }
186
Jeff Brownb880d882014-02-10 19:47:07 -0800187 /**
188 * Gets the system context.
189 */
Makoto Onukic8815902020-01-08 13:55:25 -0800190 @NonNull
Jeff Brownb880d882014-02-10 19:47:07 -0800191 public final Context getContext() {
192 return mContext;
193 }
194
195 /**
Adam Lesinskia82b6262017-03-21 16:56:17 -0700196 * Get the system UI context. This context is to be used for displaying UI. It is themable,
197 * which means resources can be overridden at runtime. Do not use to retrieve properties that
198 * configure the behavior of the device that is not UX related.
Makoto Onukic8815902020-01-08 13:55:25 -0800199 *
200 * @hide
Adam Lesinskia82b6262017-03-21 16:56:17 -0700201 */
202 public final Context getUiContext() {
203 // This has already been set up by the time any SystemServices are created.
204 return ActivityThread.currentActivityThread().getSystemUiContext();
205 }
206
207 /**
Jeff Brownb880d882014-02-10 19:47:07 -0800208 * Returns true if the system is running in safe mode.
209 * TODO: we should define in which phase this becomes valid
Makoto Onukic8815902020-01-08 13:55:25 -0800210 *
211 * @hide
Jeff Brownb880d882014-02-10 19:47:07 -0800212 */
Amith Yamasani91588252013-11-22 08:25:26 -0800213 public final boolean isSafeMode() {
Jeff Brownb880d882014-02-10 19:47:07 -0800214 return getManager().isSafeMode();
Amith Yamasani91588252013-11-22 08:25:26 -0800215 }
216
Adam Lesinski182f73f2013-12-05 16:48:06 -0800217 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800218 * Called when the system service should publish a binder service using
219 * {@link #publishBinderService(String, IBinder).}
Adam Lesinski182f73f2013-12-05 16:48:06 -0800220 */
221 public abstract void onStart();
222
223 /**
224 * Called on each phase of the boot process. Phases before the service's start phase
225 * (as defined in the @Service annotation) are never received.
226 *
227 * @param phase The current boot phase.
228 */
Makoto Onukic8815902020-01-08 13:55:25 -0800229 public void onBootPhase(@BootPhase int phase) {}
Adam Lesinski182f73f2013-12-05 16:48:06 -0800230
231 /**
Felipe Leme501a5142019-08-15 16:23:47 -0700232 * Checks if the service should be available for the given user.
233 *
234 * <p>By default returns {@code true}, but subclasses should extend for optimization, if they
235 * don't support some types (like headless system user).
236 */
Makoto Onukic8815902020-01-08 13:55:25 -0800237 public boolean isSupportedUser(@NonNull TargetUser user) {
Felipe Leme501a5142019-08-15 16:23:47 -0700238 return true;
239 }
240
241 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800242 * Helper method used to dump which users are {@link #onStartUser(TargetUser) supported}.
243 *
244 * @hide
Felipe Lemee87735b2019-12-17 09:58:40 -0800245 */
246 protected void dumpSupportedUsers(@NonNull PrintWriter pw, @NonNull String prefix) {
247 final List<UserInfo> allUsers = UserManager.get(mContext).getUsers();
248 final List<Integer> supportedUsers = new ArrayList<>(allUsers.size());
249 for (UserInfo user : allUsers) {
250 supportedUsers.add(user.id);
251 }
252 if (allUsers.isEmpty()) {
253 pw.print(prefix); pw.println("No supported users");
254 } else {
255 final int size = supportedUsers.size();
256 pw.print(prefix); pw.print(size); pw.print(" supported user");
257 if (size > 1) pw.print("s");
258 pw.print(": "); pw.println(supportedUsers);
259 }
260 }
261
262 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800263 * @deprecated subclasses should extend {@link #onStartUser(TargetUser)} instead
264 * (which by default calls this method).
265 *
266 * @hide
Felipe Lemee5434c32019-08-13 09:28:33 -0700267 */
268 @Deprecated
Bookatzf56f2582019-09-04 16:06:41 -0700269 public void onStartUser(@UserIdInt int userId) {}
Felipe Lemee5434c32019-08-13 09:28:33 -0700270
271 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800272 * @deprecated subclasses should extend {@link #onStartUser(TargetUser)} instead
273 * (which by default calls this method).
Felipe Lemee5434c32019-08-13 09:28:33 -0700274 *
Makoto Onukic8815902020-01-08 13:55:25 -0800275 * @hide
Dianne Hackborn91097de2014-04-04 18:02:06 -0700276 */
Makoto Onukic8815902020-01-08 13:55:25 -0800277 @Deprecated
Felipe Lemee5434c32019-08-13 09:28:33 -0700278 public void onStartUser(@NonNull UserInfo userInfo) {
279 onStartUser(userInfo.id);
280 }
281
282 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800283 * Called when a new user is starting, for system services to initialize any per-user
284 * state they maintain for running users.
285 *
286 * <p>This method is only called when the service {@link #isSupportedUser(TargetUser) supports}
287 * this user.
288 *
289 * @param user target user
290 */
291 public void onStartUser(@NonNull TargetUser user) {
292 onStartUser(user.getUserInfo());
293 }
294
295 /**
296 * @deprecated subclasses should extend {@link #onUnlockUser(TargetUser)} instead (which by
Felipe Lemee5434c32019-08-13 09:28:33 -0700297 * default calls this method).
Makoto Onukic8815902020-01-08 13:55:25 -0800298 *
299 * @hide
Felipe Lemee5434c32019-08-13 09:28:33 -0700300 */
301 @Deprecated
Bookatzf56f2582019-09-04 16:06:41 -0700302 public void onUnlockUser(@UserIdInt int userId) {}
Dianne Hackborn91097de2014-04-04 18:02:06 -0700303
304 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800305 * @deprecated subclasses should extend {@link #onUnlockUser(TargetUser)} instead (which by
306 * default calls this method).
307 *
308 * @hide
309 */
310 @Deprecated
311 public void onUnlockUser(@NonNull UserInfo userInfo) {
312 onUnlockUser(userInfo.id);
313 }
314
315 /**
Jeff Sharkeybb4988a2017-02-23 17:31:39 -0700316 * Called when an existing user is in the process of being unlocked. This
317 * means the credential-encrypted storage for that user is now available,
318 * and encryption-aware component filtering is no longer in effect.
319 * <p>
320 * While dispatching this event to services, the user is in the
321 * {@code STATE_RUNNING_UNLOCKING} state, and once dispatching is finished
322 * the user will transition into the {@code STATE_RUNNING_UNLOCKED} state.
323 * Code written inside system services should use
324 * {@link UserManager#isUserUnlockingOrUnlocked(int)} to handle both of
325 * these states.
Felipe Leme501a5142019-08-15 16:23:47 -0700326 * <p>
Makoto Onukic8815902020-01-08 13:55:25 -0800327 * This method is only called when the service {@link #isSupportedUser(TargetUser) supports}
328 * this user.
Jeff Sharkeybedbaa92015-12-02 16:42:25 -0700329 *
Makoto Onukic8815902020-01-08 13:55:25 -0800330 * @param user target user
Jeff Sharkeybedbaa92015-12-02 16:42:25 -0700331 */
Makoto Onukic8815902020-01-08 13:55:25 -0800332 public void onUnlockUser(@NonNull TargetUser user) {
333 onUnlockUser(user.getUserInfo());
Felipe Lemee5434c32019-08-13 09:28:33 -0700334 }
335
336 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800337 * @deprecated subclasses should extend {@link #onSwitchUser(TargetUser, TargetUser)} instead
Felipe Leme501a5142019-08-15 16:23:47 -0700338 * (which by default calls this method).
Makoto Onukic8815902020-01-08 13:55:25 -0800339 *
340 * @hide
Felipe Lemee5434c32019-08-13 09:28:33 -0700341 */
342 @Deprecated
Makoto Onukic8815902020-01-08 13:55:25 -0800343 public void onSwitchUser(@UserIdInt int toUserId) {}
344
345 /**
346 * @deprecated subclasses should extend {@link #onSwitchUser(TargetUser, TargetUser)} instead
347 * (which by default calls this method).
348 *
349 * @hide
350 */
351 @Deprecated
352 public void onSwitchUser(@Nullable UserInfo from, @NonNull UserInfo to) {
353 onSwitchUser(to.id);
354 }
Jeff Sharkeybedbaa92015-12-02 16:42:25 -0700355
356 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -0700357 * Called when switching to a different foreground user, for system services that have
358 * special behavior for whichever user is currently in the foreground. This is called
359 * before any application processes are aware of the new user.
Felipe Lemee5434c32019-08-13 09:28:33 -0700360 *
Makoto Onukic8815902020-01-08 13:55:25 -0800361 * <p>This method is only called when the service {@link #isSupportedUser(TargetUser) supports}
362 * either of the users ({@code from} or {@code to}).
Felipe Leme501a5142019-08-15 16:23:47 -0700363 *
364 * <b>NOTE: </b> both {@code from} and {@code to} are "live" objects
Felipe Lemee5434c32019-08-13 09:28:33 -0700365 * referenced by {@link UserManagerService} and hence should not be modified.
Felipe Leme501a5142019-08-15 16:23:47 -0700366 *
Makoto Onukic8815902020-01-08 13:55:25 -0800367 * @param from the user switching from
368 * @param to the user switching to
Dianne Hackborn91097de2014-04-04 18:02:06 -0700369 */
Makoto Onukic8815902020-01-08 13:55:25 -0800370 public void onSwitchUser(@Nullable TargetUser from, @NonNull TargetUser to) {
371 onSwitchUser((from == null ? null : from.getUserInfo()), to.getUserInfo());
Felipe Lemee5434c32019-08-13 09:28:33 -0700372 }
373
374 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800375 * @deprecated subclasses should extend {@link #onStopUser(TargetUser)} instead
376 * (which by default calls this method).
377 *
378 * @hide
Felipe Lemee5434c32019-08-13 09:28:33 -0700379 */
380 @Deprecated
Bookatzf56f2582019-09-04 16:06:41 -0700381 public void onStopUser(@UserIdInt int userId) {}
Dianne Hackborn91097de2014-04-04 18:02:06 -0700382
383 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800384 * @deprecated subclasses should extend {@link #onStopUser(TargetUser)} instead
385 * (which by default calls this method).
386 *
387 * @hide
388 */
389 @Deprecated
390 public void onStopUser(@NonNull UserInfo user) {
391 onStopUser(user.id);
392
393 }
394
395 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -0700396 * Called when an existing user is stopping, for system services to finalize any per-user
397 * state they maintain for running users. This is called prior to sending the SHUTDOWN
398 * broadcast to the user; it is a good place to stop making use of any resources of that
399 * user (such as binding to a service running in the user).
Makoto Onuki01ce92b2017-04-28 12:24:16 -0700400 *
Makoto Onukic8815902020-01-08 13:55:25 -0800401 * <p>This method is only called when the service {@link #isSupportedUser(TargetUser) supports}
402 * this user.
Felipe Leme501a5142019-08-15 16:23:47 -0700403 *
Makoto Onuki01ce92b2017-04-28 12:24:16 -0700404 * <p>NOTE: This is the last callback where the callee may access the target user's CE storage.
405 *
Makoto Onukic8815902020-01-08 13:55:25 -0800406 * @param user target user
Dianne Hackborn91097de2014-04-04 18:02:06 -0700407 */
Makoto Onukic8815902020-01-08 13:55:25 -0800408 public void onStopUser(@NonNull TargetUser user) {
409 onStopUser(user.getUserInfo());
Felipe Lemee5434c32019-08-13 09:28:33 -0700410 }
411
412 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800413 * @deprecated subclasses should extend {@link #onCleanupUser(TargetUser)} instead (which by
Felipe Lemee5434c32019-08-13 09:28:33 -0700414 * default calls this method).
Makoto Onukic8815902020-01-08 13:55:25 -0800415 *
416 * @hide
Felipe Lemee5434c32019-08-13 09:28:33 -0700417 */
418 @Deprecated
Bookatzf56f2582019-09-04 16:06:41 -0700419 public void onCleanupUser(@UserIdInt int userId) {}
Dianne Hackborn91097de2014-04-04 18:02:06 -0700420
421 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800422 * @deprecated subclasses should extend {@link #onCleanupUser(TargetUser)} instead (which by
423 * default calls this method).
424 *
425 * @hide
426 */
427 @Deprecated
428 public void onCleanupUser(@NonNull UserInfo user) {
429 onCleanupUser(user.id);
430 }
431
432 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -0700433 * Called when an existing user is stopping, for system services to finalize any per-user
434 * state they maintain for running users. This is called after all application process
435 * teardown of the user is complete.
Makoto Onuki01ce92b2017-04-28 12:24:16 -0700436 *
Makoto Onukic8815902020-01-08 13:55:25 -0800437 * <p>This method is only called when the service {@link #isSupportedUser(TargetUser) supports}
438 * this user.
Felipe Leme501a5142019-08-15 16:23:47 -0700439 *
Makoto Onuki01ce92b2017-04-28 12:24:16 -0700440 * <p>NOTE: When this callback is called, the CE storage for the target user may not be
Makoto Onukic8815902020-01-08 13:55:25 -0800441 * accessible already. Use {@link #onStopUser(TargetUser)} instead if you need to access the CE
Felipe Leme501a5142019-08-15 16:23:47 -0700442 * storage.
Makoto Onuki01ce92b2017-04-28 12:24:16 -0700443 *
Makoto Onukic8815902020-01-08 13:55:25 -0800444 * @param user target user
Dianne Hackborn91097de2014-04-04 18:02:06 -0700445 */
Makoto Onukic8815902020-01-08 13:55:25 -0800446 public void onCleanupUser(@NonNull TargetUser user) {
447 onCleanupUser(user.getUserInfo());
Felipe Lemee5434c32019-08-13 09:28:33 -0700448 }
Dianne Hackborn91097de2014-04-04 18:02:06 -0700449
450 /**
Adam Lesinski182f73f2013-12-05 16:48:06 -0800451 * Publish the service so it is accessible to other services and apps.
Vishnu Naire3e4d252018-03-01 11:26:57 -0800452 *
453 * @param name the name of the new service
454 * @param service the service object
Adam Lesinski182f73f2013-12-05 16:48:06 -0800455 */
Makoto Onukic8815902020-01-08 13:55:25 -0800456 protected final void publishBinderService(@NonNull String name, @NonNull IBinder service) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800457 publishBinderService(name, service, false);
458 }
459
460 /**
461 * Publish the service so it is accessible to other services and apps.
Vishnu Naire3e4d252018-03-01 11:26:57 -0800462 *
463 * @param name the name of the new service
464 * @param service the service object
465 * @param allowIsolated set to true to allow isolated sandboxed processes
466 * to access this service
Jeff Brown4ccb8232014-01-16 22:16:42 -0800467 */
Makoto Onukic8815902020-01-08 13:55:25 -0800468 protected final void publishBinderService(@NonNull String name, @NonNull IBinder service,
Jeff Brown4ccb8232014-01-16 22:16:42 -0800469 boolean allowIsolated) {
Vishnu Naire3e4d252018-03-01 11:26:57 -0800470 publishBinderService(name, service, allowIsolated, DUMP_FLAG_PRIORITY_DEFAULT);
471 }
472
473 /**
474 * Publish the service so it is accessible to other services and apps.
475 *
476 * @param name the name of the new service
477 * @param service the service object
478 * @param allowIsolated set to true to allow isolated sandboxed processes
479 * to access this service
480 * @param dumpPriority supported dump priority levels as a bitmask
Makoto Onukic8815902020-01-08 13:55:25 -0800481 *
482 * @hide
Vishnu Naire3e4d252018-03-01 11:26:57 -0800483 */
484 protected final void publishBinderService(String name, IBinder service,
485 boolean allowIsolated, int dumpPriority) {
486 ServiceManager.addService(name, service, allowIsolated, dumpPriority);
Adam Lesinski182f73f2013-12-05 16:48:06 -0800487 }
488
489 /**
490 * Get a binder service by its name.
Makoto Onukic8815902020-01-08 13:55:25 -0800491 *
492 * @hide
Adam Lesinski182f73f2013-12-05 16:48:06 -0800493 */
494 protected final IBinder getBinderService(String name) {
495 return ServiceManager.getService(name);
496 }
497
498 /**
499 * Publish the service so it is only accessible to the system process.
Makoto Onukic8815902020-01-08 13:55:25 -0800500 *
501 * @hide
Adam Lesinski182f73f2013-12-05 16:48:06 -0800502 */
503 protected final <T> void publishLocalService(Class<T> type, T service) {
504 LocalServices.addService(type, service);
505 }
506
507 /**
508 * Get a local service by interface.
Makoto Onukic8815902020-01-08 13:55:25 -0800509 *
510 * @hide
Adam Lesinski182f73f2013-12-05 16:48:06 -0800511 */
512 protected final <T> T getLocalService(Class<T> type) {
513 return LocalServices.getService(type);
514 }
515
Jeff Brownb880d882014-02-10 19:47:07 -0800516 private SystemServiceManager getManager() {
517 return LocalServices.getService(SystemServiceManager.class);
Adam Lesinski182f73f2013-12-05 16:48:06 -0800518 }
Adam Lesinski182f73f2013-12-05 16:48:06 -0800519}