blob: e3c73252326439aab4cf3754a13467a32c58e0ad [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;
Felipe Lemee5434c32019-08-13 09:28:33 -070026import android.annotation.UserIdInt;
Adam Lesinskia82b6262017-03-21 16:56:17 -070027import android.app.ActivityThread;
Adam Lesinski182f73f2013-12-05 16:48:06 -080028import android.content.Context;
Felipe Lemee5434c32019-08-13 09:28:33 -070029import android.content.pm.UserInfo;
Adam Lesinski182f73f2013-12-05 16:48:06 -080030import android.os.IBinder;
31import android.os.ServiceManager;
Makoto Onukic8815902020-01-08 13:55:25 -080032import android.os.UserHandle;
Jeff Sharkeybb4988a2017-02-23 17:31:39 -070033import android.os.UserManager;
Adam Lesinski182f73f2013-12-05 16:48:06 -080034
Felipe Lemee5434c32019-08-13 09:28:33 -070035import com.android.server.pm.UserManagerService;
36
Felipe Lemee87735b2019-12-17 09:58:40 -080037import java.io.PrintWriter;
Makoto Onukic8815902020-01-08 13:55:25 -080038import java.lang.annotation.Retention;
39import java.lang.annotation.RetentionPolicy;
Felipe Lemee87735b2019-12-17 09:58:40 -080040import java.util.ArrayList;
41import java.util.List;
42
Adam Lesinski182f73f2013-12-05 16:48:06 -080043/**
Adam Lesinskib102b2c2013-12-20 11:46:14 -080044 * The base class for services running in the system process. Override and implement
45 * the lifecycle event callback methods as needed.
Jeff Brownb880d882014-02-10 19:47:07 -080046 * <p>
Adam Lesinskib102b2c2013-12-20 11:46:14 -080047 * The lifecycle of a SystemService:
Jeff Brownb880d882014-02-10 19:47:07 -080048 * </p><ul>
49 * <li>The constructor is called and provided with the system {@link Context}
50 * to initialize the system service.
51 * <li>{@link #onStart()} is called to get the service running. The service should
52 * publish its binder interface at this point using
53 * {@link #publishBinderService(String, IBinder)}. It may also publish additional
54 * local interfaces that other services within the system server may use to access
55 * privileged internal functions.
56 * <li>Then {@link #onBootPhase(int)} is called as many times as there are boot phases
Dianne Hackborna750a632015-06-16 17:18:23 -070057 * until {@link #PHASE_BOOT_COMPLETED} is sent, which is the last boot phase. Each phase
Adam Lesinskib102b2c2013-12-20 11:46:14 -080058 * is an opportunity to do special work, like acquiring optional service dependencies,
59 * waiting to see if SafeMode is enabled, or registering with a service that gets
60 * started after this one.
Jeff Brownb880d882014-02-10 19:47:07 -080061 * </ul><p>
62 * NOTE: All lifecycle methods are called from the system server's main looper thread.
63 * </p>
Adam Lesinskib102b2c2013-12-20 11:46:14 -080064 *
65 * {@hide}
Adam Lesinski182f73f2013-12-05 16:48:06 -080066 */
Makoto Onukiaf97aef2020-02-03 10:32:52 -080067@SystemApi(client = Client.SYSTEM_SERVER)
Adam Lesinski182f73f2013-12-05 16:48:06 -080068public abstract class SystemService {
Felipe Leme501a5142019-08-15 16:23:47 -070069
Makoto Onukic8815902020-01-08 13:55:25 -080070 /** @hide */
Felipe Leme501a5142019-08-15 16:23:47 -070071 // TODO(b/133242016) STOPSHIP: change to false before R ships
72 protected static final boolean DEBUG_USER = true;
73
Adam Lesinski182f73f2013-12-05 16:48:06 -080074 /*
Makoto Onukic8815902020-01-08 13:55:25 -080075 * The earliest boot phase the system send to system services on boot.
Adam Lesinski182f73f2013-12-05 16:48:06 -080076 */
Makoto Onukic8815902020-01-08 13:55:25 -080077 public static final int PHASE_WAIT_FOR_DEFAULT_DISPLAY = 100;
Adam Lesinski2cb6c602014-02-14 17:19:56 -080078
79 /**
80 * After receiving this boot phase, services can obtain lock settings data.
81 */
Amith Yamasani91588252013-11-22 08:25:26 -080082 public static final int PHASE_LOCK_SETTINGS_READY = 480;
Adam Lesinski2cb6c602014-02-14 17:19:56 -080083
84 /**
85 * After receiving this boot phase, services can safely call into core system services
86 * such as the PowerManager or PackageManager.
87 */
Adam Lesinski182f73f2013-12-05 16:48:06 -080088 public static final int PHASE_SYSTEM_SERVICES_READY = 500;
Adam Lesinski2cb6c602014-02-14 17:19:56 -080089
90 /**
Daichi Hironoedfcb002017-10-10 17:22:58 +090091 * After receiving this boot phase, services can safely call into device specific services.
92 */
93 public static final int PHASE_DEVICE_SPECIFIC_SERVICES_READY = 520;
94
95 /**
Adam Lesinski2cb6c602014-02-14 17:19:56 -080096 * After receiving this boot phase, services can broadcast Intents.
97 */
98 public static final int PHASE_ACTIVITY_MANAGER_READY = 550;
99
100 /**
101 * After receiving this boot phase, services can start/bind to third party apps.
102 * Apps will be able to make Binder calls into services at this point.
103 */
Adam Lesinski182f73f2013-12-05 16:48:06 -0800104 public static final int PHASE_THIRD_PARTY_APPS_CAN_START = 600;
Adam Lesinski2cb6c602014-02-14 17:19:56 -0800105
106 /**
Jeff Brown6d2a9492014-08-07 19:06:49 -0700107 * After receiving this boot phase, services can allow user interaction with the device.
108 * This phase occurs when boot has completed and the home application has started.
109 * System services may prefer to listen to this phase rather than registering a
Makoto Onukic8815902020-01-08 13:55:25 -0800110 * broadcast receiver for {@link android.content.Intent#ACTION_LOCKED_BOOT_COMPLETED}
111 * to reduce overall latency.
Adam Lesinski2cb6c602014-02-14 17:19:56 -0800112 */
Jeff Brown6d2a9492014-08-07 19:06:49 -0700113 public static final int PHASE_BOOT_COMPLETED = 1000;
Adam Lesinski182f73f2013-12-05 16:48:06 -0800114
Makoto Onukic8815902020-01-08 13:55:25 -0800115 /** @hide */
116 @IntDef(flag = true, prefix = { "PHASE_" }, value = {
117 PHASE_WAIT_FOR_DEFAULT_DISPLAY,
118 PHASE_LOCK_SETTINGS_READY,
119 PHASE_SYSTEM_SERVICES_READY,
120 PHASE_DEVICE_SPECIFIC_SERVICES_READY,
121 PHASE_ACTIVITY_MANAGER_READY,
122 PHASE_THIRD_PARTY_APPS_CAN_START,
123 PHASE_BOOT_COMPLETED
124 })
125 @Retention(RetentionPolicy.SOURCE)
126 public @interface BootPhase {}
127
Jeff Brownb880d882014-02-10 19:47:07 -0800128 private final Context mContext;
Adam Lesinski182f73f2013-12-05 16:48:06 -0800129
Jeff Brownb880d882014-02-10 19:47:07 -0800130 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800131 * Class representing user in question in the lifecycle callbacks.
132 * @hide
133 */
Makoto Onukiaf97aef2020-02-03 10:32:52 -0800134 @SystemApi(client = Client.SYSTEM_SERVER)
Makoto Onukic8815902020-01-08 13:55:25 -0800135 public static final class TargetUser {
136 @NonNull
137 private final UserInfo mUserInfo;
138
139 /** @hide */
140 public TargetUser(@NonNull UserInfo userInfo) {
141 mUserInfo = userInfo;
142 }
143
144 /**
145 * @return The information about the user. <b>NOTE: </b> this is a "live" object
146 * referenced by {@link UserManagerService} and hence should not be modified.
147 *
148 * @hide
149 */
150 @NonNull
151 public UserInfo getUserInfo() {
152 return mUserInfo;
153 }
154
155 /**
156 * @return the target {@link UserHandle}.
157 */
158 @NonNull
159 public UserHandle getUserHandle() {
160 return mUserInfo.getUserHandle();
161 }
162
163 /**
164 * @return the integer user id
165 *
166 * @hide
167 */
168 public int getUserIdentifier() {
169 return mUserInfo.id;
170 }
171 }
172
173 /**
Jeff Brownb880d882014-02-10 19:47:07 -0800174 * Initializes the system service.
175 * <p>
176 * Subclasses must define a single argument constructor that accepts the context
177 * and passes it to super.
178 * </p>
179 *
180 * @param context The system server context.
181 */
Makoto Onukic8815902020-01-08 13:55:25 -0800182 public SystemService(@NonNull Context context) {
Adam Lesinski182f73f2013-12-05 16:48:06 -0800183 mContext = context;
Adam Lesinski182f73f2013-12-05 16:48:06 -0800184 }
185
Jeff Brownb880d882014-02-10 19:47:07 -0800186 /**
187 * Gets the system context.
188 */
Makoto Onukic8815902020-01-08 13:55:25 -0800189 @NonNull
Jeff Brownb880d882014-02-10 19:47:07 -0800190 public final Context getContext() {
191 return mContext;
192 }
193
194 /**
Adam Lesinskia82b6262017-03-21 16:56:17 -0700195 * Get the system UI context. This context is to be used for displaying UI. It is themable,
196 * which means resources can be overridden at runtime. Do not use to retrieve properties that
197 * configure the behavior of the device that is not UX related.
Makoto Onukic8815902020-01-08 13:55:25 -0800198 *
199 * @hide
Adam Lesinskia82b6262017-03-21 16:56:17 -0700200 */
201 public final Context getUiContext() {
202 // This has already been set up by the time any SystemServices are created.
203 return ActivityThread.currentActivityThread().getSystemUiContext();
204 }
205
206 /**
Jeff Brownb880d882014-02-10 19:47:07 -0800207 * Returns true if the system is running in safe mode.
208 * TODO: we should define in which phase this becomes valid
Makoto Onukic8815902020-01-08 13:55:25 -0800209 *
210 * @hide
Jeff Brownb880d882014-02-10 19:47:07 -0800211 */
Amith Yamasani91588252013-11-22 08:25:26 -0800212 public final boolean isSafeMode() {
Jeff Brownb880d882014-02-10 19:47:07 -0800213 return getManager().isSafeMode();
Amith Yamasani91588252013-11-22 08:25:26 -0800214 }
215
Adam Lesinski182f73f2013-12-05 16:48:06 -0800216 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800217 * Called when the system service should publish a binder service using
218 * {@link #publishBinderService(String, IBinder).}
Adam Lesinski182f73f2013-12-05 16:48:06 -0800219 */
220 public abstract void onStart();
221
222 /**
223 * Called on each phase of the boot process. Phases before the service's start phase
224 * (as defined in the @Service annotation) are never received.
225 *
226 * @param phase The current boot phase.
227 */
Makoto Onukic8815902020-01-08 13:55:25 -0800228 public void onBootPhase(@BootPhase int phase) {}
Adam Lesinski182f73f2013-12-05 16:48:06 -0800229
230 /**
Felipe Leme501a5142019-08-15 16:23:47 -0700231 * Checks if the service should be available for the given user.
232 *
233 * <p>By default returns {@code true}, but subclasses should extend for optimization, if they
234 * don't support some types (like headless system user).
235 */
Makoto Onukic8815902020-01-08 13:55:25 -0800236 public boolean isSupportedUser(@NonNull TargetUser user) {
Felipe Leme501a5142019-08-15 16:23:47 -0700237 return true;
238 }
239
240 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800241 * Helper method used to dump which users are {@link #onStartUser(TargetUser) supported}.
242 *
243 * @hide
Felipe Lemee87735b2019-12-17 09:58:40 -0800244 */
245 protected void dumpSupportedUsers(@NonNull PrintWriter pw, @NonNull String prefix) {
246 final List<UserInfo> allUsers = UserManager.get(mContext).getUsers();
247 final List<Integer> supportedUsers = new ArrayList<>(allUsers.size());
248 for (UserInfo user : allUsers) {
249 supportedUsers.add(user.id);
250 }
251 if (allUsers.isEmpty()) {
252 pw.print(prefix); pw.println("No supported users");
253 } else {
254 final int size = supportedUsers.size();
255 pw.print(prefix); pw.print(size); pw.print(" supported user");
256 if (size > 1) pw.print("s");
257 pw.print(": "); pw.println(supportedUsers);
258 }
259 }
260
261 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800262 * @deprecated subclasses should extend {@link #onStartUser(TargetUser)} instead
263 * (which by default calls this method).
264 *
265 * @hide
Felipe Lemee5434c32019-08-13 09:28:33 -0700266 */
267 @Deprecated
Bookatzf56f2582019-09-04 16:06:41 -0700268 public void onStartUser(@UserIdInt int userId) {}
Felipe Lemee5434c32019-08-13 09:28:33 -0700269
270 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800271 * @deprecated subclasses should extend {@link #onStartUser(TargetUser)} instead
272 * (which by default calls this method).
Felipe Lemee5434c32019-08-13 09:28:33 -0700273 *
Makoto Onukic8815902020-01-08 13:55:25 -0800274 * @hide
Dianne Hackborn91097de2014-04-04 18:02:06 -0700275 */
Makoto Onukic8815902020-01-08 13:55:25 -0800276 @Deprecated
Felipe Lemee5434c32019-08-13 09:28:33 -0700277 public void onStartUser(@NonNull UserInfo userInfo) {
278 onStartUser(userInfo.id);
279 }
280
281 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800282 * Called when a new user is starting, for system services to initialize any per-user
283 * state they maintain for running users.
284 *
285 * <p>This method is only called when the service {@link #isSupportedUser(TargetUser) supports}
286 * this user.
287 *
288 * @param user target user
289 */
290 public void onStartUser(@NonNull TargetUser user) {
291 onStartUser(user.getUserInfo());
292 }
293
294 /**
295 * @deprecated subclasses should extend {@link #onUnlockUser(TargetUser)} instead (which by
Felipe Lemee5434c32019-08-13 09:28:33 -0700296 * default calls this method).
Makoto Onukic8815902020-01-08 13:55:25 -0800297 *
298 * @hide
Felipe Lemee5434c32019-08-13 09:28:33 -0700299 */
300 @Deprecated
Bookatzf56f2582019-09-04 16:06:41 -0700301 public void onUnlockUser(@UserIdInt int userId) {}
Dianne Hackborn91097de2014-04-04 18:02:06 -0700302
303 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800304 * @deprecated subclasses should extend {@link #onUnlockUser(TargetUser)} instead (which by
305 * default calls this method).
306 *
307 * @hide
308 */
309 @Deprecated
310 public void onUnlockUser(@NonNull UserInfo userInfo) {
311 onUnlockUser(userInfo.id);
312 }
313
314 /**
Jeff Sharkeybb4988a2017-02-23 17:31:39 -0700315 * Called when an existing user is in the process of being unlocked. This
316 * means the credential-encrypted storage for that user is now available,
317 * and encryption-aware component filtering is no longer in effect.
318 * <p>
319 * While dispatching this event to services, the user is in the
320 * {@code STATE_RUNNING_UNLOCKING} state, and once dispatching is finished
321 * the user will transition into the {@code STATE_RUNNING_UNLOCKED} state.
322 * Code written inside system services should use
323 * {@link UserManager#isUserUnlockingOrUnlocked(int)} to handle both of
324 * these states.
Felipe Leme501a5142019-08-15 16:23:47 -0700325 * <p>
Makoto Onukic8815902020-01-08 13:55:25 -0800326 * This method is only called when the service {@link #isSupportedUser(TargetUser) supports}
327 * this user.
Jeff Sharkeybedbaa92015-12-02 16:42:25 -0700328 *
Makoto Onukic8815902020-01-08 13:55:25 -0800329 * @param user target user
Jeff Sharkeybedbaa92015-12-02 16:42:25 -0700330 */
Makoto Onukic8815902020-01-08 13:55:25 -0800331 public void onUnlockUser(@NonNull TargetUser user) {
332 onUnlockUser(user.getUserInfo());
Felipe Lemee5434c32019-08-13 09:28:33 -0700333 }
334
335 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800336 * @deprecated subclasses should extend {@link #onSwitchUser(TargetUser, TargetUser)} instead
Felipe Leme501a5142019-08-15 16:23:47 -0700337 * (which by default calls this method).
Makoto Onukic8815902020-01-08 13:55:25 -0800338 *
339 * @hide
Felipe Lemee5434c32019-08-13 09:28:33 -0700340 */
341 @Deprecated
Makoto Onukic8815902020-01-08 13:55:25 -0800342 public void onSwitchUser(@UserIdInt int toUserId) {}
343
344 /**
345 * @deprecated subclasses should extend {@link #onSwitchUser(TargetUser, TargetUser)} instead
346 * (which by default calls this method).
347 *
348 * @hide
349 */
350 @Deprecated
351 public void onSwitchUser(@Nullable UserInfo from, @NonNull UserInfo to) {
352 onSwitchUser(to.id);
353 }
Jeff Sharkeybedbaa92015-12-02 16:42:25 -0700354
355 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -0700356 * Called when switching to a different foreground user, for system services that have
357 * special behavior for whichever user is currently in the foreground. This is called
358 * before any application processes are aware of the new user.
Felipe Lemee5434c32019-08-13 09:28:33 -0700359 *
Makoto Onukic8815902020-01-08 13:55:25 -0800360 * <p>This method is only called when the service {@link #isSupportedUser(TargetUser) supports}
361 * either of the users ({@code from} or {@code to}).
Felipe Leme501a5142019-08-15 16:23:47 -0700362 *
363 * <b>NOTE: </b> both {@code from} and {@code to} are "live" objects
Felipe Lemee5434c32019-08-13 09:28:33 -0700364 * referenced by {@link UserManagerService} and hence should not be modified.
Felipe Leme501a5142019-08-15 16:23:47 -0700365 *
Makoto Onukic8815902020-01-08 13:55:25 -0800366 * @param from the user switching from
367 * @param to the user switching to
Dianne Hackborn91097de2014-04-04 18:02:06 -0700368 */
Makoto Onukic8815902020-01-08 13:55:25 -0800369 public void onSwitchUser(@Nullable TargetUser from, @NonNull TargetUser to) {
370 onSwitchUser((from == null ? null : from.getUserInfo()), to.getUserInfo());
Felipe Lemee5434c32019-08-13 09:28:33 -0700371 }
372
373 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800374 * @deprecated subclasses should extend {@link #onStopUser(TargetUser)} instead
375 * (which by default calls this method).
376 *
377 * @hide
Felipe Lemee5434c32019-08-13 09:28:33 -0700378 */
379 @Deprecated
Bookatzf56f2582019-09-04 16:06:41 -0700380 public void onStopUser(@UserIdInt int userId) {}
Dianne Hackborn91097de2014-04-04 18:02:06 -0700381
382 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800383 * @deprecated subclasses should extend {@link #onStopUser(TargetUser)} instead
384 * (which by default calls this method).
385 *
386 * @hide
387 */
388 @Deprecated
389 public void onStopUser(@NonNull UserInfo user) {
390 onStopUser(user.id);
391
392 }
393
394 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -0700395 * Called when an existing user is stopping, for system services to finalize any per-user
396 * state they maintain for running users. This is called prior to sending the SHUTDOWN
397 * broadcast to the user; it is a good place to stop making use of any resources of that
398 * user (such as binding to a service running in the user).
Makoto Onuki01ce92b2017-04-28 12:24:16 -0700399 *
Makoto Onukic8815902020-01-08 13:55:25 -0800400 * <p>This method is only called when the service {@link #isSupportedUser(TargetUser) supports}
401 * this user.
Felipe Leme501a5142019-08-15 16:23:47 -0700402 *
Makoto Onuki01ce92b2017-04-28 12:24:16 -0700403 * <p>NOTE: This is the last callback where the callee may access the target user's CE storage.
404 *
Makoto Onukic8815902020-01-08 13:55:25 -0800405 * @param user target user
Dianne Hackborn91097de2014-04-04 18:02:06 -0700406 */
Makoto Onukic8815902020-01-08 13:55:25 -0800407 public void onStopUser(@NonNull TargetUser user) {
408 onStopUser(user.getUserInfo());
Felipe Lemee5434c32019-08-13 09:28:33 -0700409 }
410
411 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800412 * @deprecated subclasses should extend {@link #onCleanupUser(TargetUser)} instead (which by
Felipe Lemee5434c32019-08-13 09:28:33 -0700413 * default calls this method).
Makoto Onukic8815902020-01-08 13:55:25 -0800414 *
415 * @hide
Felipe Lemee5434c32019-08-13 09:28:33 -0700416 */
417 @Deprecated
Bookatzf56f2582019-09-04 16:06:41 -0700418 public void onCleanupUser(@UserIdInt int userId) {}
Dianne Hackborn91097de2014-04-04 18:02:06 -0700419
420 /**
Makoto Onukic8815902020-01-08 13:55:25 -0800421 * @deprecated subclasses should extend {@link #onCleanupUser(TargetUser)} instead (which by
422 * default calls this method).
423 *
424 * @hide
425 */
426 @Deprecated
427 public void onCleanupUser(@NonNull UserInfo user) {
428 onCleanupUser(user.id);
429 }
430
431 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -0700432 * Called when an existing user is stopping, for system services to finalize any per-user
433 * state they maintain for running users. This is called after all application process
434 * teardown of the user is complete.
Makoto Onuki01ce92b2017-04-28 12:24:16 -0700435 *
Makoto Onukic8815902020-01-08 13:55:25 -0800436 * <p>This method is only called when the service {@link #isSupportedUser(TargetUser) supports}
437 * this user.
Felipe Leme501a5142019-08-15 16:23:47 -0700438 *
Makoto Onuki01ce92b2017-04-28 12:24:16 -0700439 * <p>NOTE: When this callback is called, the CE storage for the target user may not be
Makoto Onukic8815902020-01-08 13:55:25 -0800440 * accessible already. Use {@link #onStopUser(TargetUser)} instead if you need to access the CE
Felipe Leme501a5142019-08-15 16:23:47 -0700441 * storage.
Makoto Onuki01ce92b2017-04-28 12:24:16 -0700442 *
Makoto Onukic8815902020-01-08 13:55:25 -0800443 * @param user target user
Dianne Hackborn91097de2014-04-04 18:02:06 -0700444 */
Makoto Onukic8815902020-01-08 13:55:25 -0800445 public void onCleanupUser(@NonNull TargetUser user) {
446 onCleanupUser(user.getUserInfo());
Felipe Lemee5434c32019-08-13 09:28:33 -0700447 }
Dianne Hackborn91097de2014-04-04 18:02:06 -0700448
449 /**
Adam Lesinski182f73f2013-12-05 16:48:06 -0800450 * Publish the service so it is accessible to other services and apps.
Vishnu Naire3e4d252018-03-01 11:26:57 -0800451 *
452 * @param name the name of the new service
453 * @param service the service object
Adam Lesinski182f73f2013-12-05 16:48:06 -0800454 */
Makoto Onukic8815902020-01-08 13:55:25 -0800455 protected final void publishBinderService(@NonNull String name, @NonNull IBinder service) {
Jeff Brown4ccb8232014-01-16 22:16:42 -0800456 publishBinderService(name, service, false);
457 }
458
459 /**
460 * Publish the service so it is accessible to other services and apps.
Vishnu Naire3e4d252018-03-01 11:26:57 -0800461 *
462 * @param name the name of the new service
463 * @param service the service object
464 * @param allowIsolated set to true to allow isolated sandboxed processes
465 * to access this service
Jeff Brown4ccb8232014-01-16 22:16:42 -0800466 */
Makoto Onukic8815902020-01-08 13:55:25 -0800467 protected final void publishBinderService(@NonNull String name, @NonNull IBinder service,
Jeff Brown4ccb8232014-01-16 22:16:42 -0800468 boolean allowIsolated) {
Vishnu Naire3e4d252018-03-01 11:26:57 -0800469 publishBinderService(name, service, allowIsolated, DUMP_FLAG_PRIORITY_DEFAULT);
470 }
471
472 /**
473 * Publish the service so it is accessible to other services and apps.
474 *
475 * @param name the name of the new service
476 * @param service the service object
477 * @param allowIsolated set to true to allow isolated sandboxed processes
478 * to access this service
479 * @param dumpPriority supported dump priority levels as a bitmask
Makoto Onukic8815902020-01-08 13:55:25 -0800480 *
481 * @hide
Vishnu Naire3e4d252018-03-01 11:26:57 -0800482 */
483 protected final void publishBinderService(String name, IBinder service,
484 boolean allowIsolated, int dumpPriority) {
485 ServiceManager.addService(name, service, allowIsolated, dumpPriority);
Adam Lesinski182f73f2013-12-05 16:48:06 -0800486 }
487
488 /**
489 * Get a binder service by its name.
Makoto Onukic8815902020-01-08 13:55:25 -0800490 *
491 * @hide
Adam Lesinski182f73f2013-12-05 16:48:06 -0800492 */
493 protected final IBinder getBinderService(String name) {
494 return ServiceManager.getService(name);
495 }
496
497 /**
498 * Publish the service so it is only accessible to the system process.
Makoto Onukic8815902020-01-08 13:55:25 -0800499 *
500 * @hide
Adam Lesinski182f73f2013-12-05 16:48:06 -0800501 */
502 protected final <T> void publishLocalService(Class<T> type, T service) {
503 LocalServices.addService(type, service);
504 }
505
506 /**
507 * Get a local service by interface.
Makoto Onukic8815902020-01-08 13:55:25 -0800508 *
509 * @hide
Adam Lesinski182f73f2013-12-05 16:48:06 -0800510 */
511 protected final <T> T getLocalService(Class<T> type) {
512 return LocalServices.getService(type);
513 }
514
Jeff Brownb880d882014-02-10 19:47:07 -0800515 private SystemServiceManager getManager() {
516 return LocalServices.getService(SystemServiceManager.class);
Adam Lesinski182f73f2013-12-05 16:48:06 -0800517 }
Adam Lesinski182f73f2013-12-05 16:48:06 -0800518}