Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 58e7458a authored by Felipe Leme's avatar Felipe Leme
Browse files

Improved user callbacks on SystemService:

* Renamed:

  onStartUser() -> onUserStarting()
  onStopUser() -> onUserStopping()
  onSwitchUser() -> onUserSwitching()
  onUnlockUser() -> onUserUnlocking()
  onCleanupUser() -> onUserStopped()
  isSupportedUser() -> isUserSupported()

* Added:

  onUserUnlocked()

Tested on automotive, which uses the callbacks to dump user metrics:

$ adb shell dumpsys car_service --user-metrics
adb shell dumpsys car_service --user-metrics
* User Metrics *
  no users starting
  no users stopping
Last 10 started users
  2020-02-21T19:44:47.101 - user=0 start=2020-02-21 19:44:45.357 unlocking=+885ms unlocked=+1s122ms
  2020-02-21T19:44:56.376 - user=10 start=2020-02-21 19:44:47.380 switch=+209ms unlocking=+8s262ms unlocked=+8s994ms
  2020-02-21T20:00:08.792 - user=11 start=2020-02-21 20:00:04.634 switch(from 10)=+351ms unlocking=+4s44ms unlocked=+4s156ms
Last 10 stopped users
  2020-02-21T20:00:48.323 - user=10 stop=2020-02-21 20:00:16.741 shutdown=+31s581ms

Test: m update-api
Test: atest BackupManagerServiceTest
Test: manual verification (see above)
Fixes: 150001654

Change-Id: I8774c57620030b9aa8e7ec039a6a758ad56db368
parent 2e549f01
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -49,14 +49,15 @@ package com.android.server {
  public abstract class SystemService {
    ctor public SystemService(@NonNull android.content.Context);
    method @NonNull public final android.content.Context getContext();
    method public boolean isSupportedUser(@NonNull com.android.server.SystemService.TargetUser);
    method public boolean isUserSupported(@NonNull com.android.server.SystemService.TargetUser);
    method public void onBootPhase(int);
    method public void onCleanupUser(@NonNull com.android.server.SystemService.TargetUser);
    method public abstract void onStart();
    method public void onStartUser(@NonNull com.android.server.SystemService.TargetUser);
    method public void onStopUser(@NonNull com.android.server.SystemService.TargetUser);
    method public void onSwitchUser(@Nullable com.android.server.SystemService.TargetUser, @NonNull com.android.server.SystemService.TargetUser);
    method public void onUnlockUser(@NonNull com.android.server.SystemService.TargetUser);
    method public void onUserStarting(@NonNull com.android.server.SystemService.TargetUser);
    method public void onUserStopped(@NonNull com.android.server.SystemService.TargetUser);
    method public void onUserStopping(@NonNull com.android.server.SystemService.TargetUser);
    method public void onUserSwitching(@Nullable com.android.server.SystemService.TargetUser, @NonNull com.android.server.SystemService.TargetUser);
    method public void onUserUnlocked(@NonNull com.android.server.SystemService.TargetUser);
    method public void onUserUnlocking(@NonNull com.android.server.SystemService.TargetUser);
    method protected final void publishBinderService(@NonNull String, @NonNull android.os.IBinder);
    method protected final void publishBinderService(@NonNull String, @NonNull android.os.IBinder, boolean);
    field public static final int PHASE_ACTIVITY_MANAGER_READY = 550; // 0x226
+1 −1
Original line number Diff line number Diff line
@@ -331,7 +331,7 @@ public final class AutofillManagerService
    }

    @Override // from SystemService
    public boolean isSupportedUser(TargetUser user) {
    public boolean isUserSupported(TargetUser user) {
        return user.getUserInfo().isFull() || user.getUserInfo().isManagedProfile();
    }

+1 −1
Original line number Diff line number Diff line
@@ -201,7 +201,7 @@ public final class ContentCaptureManagerService extends
    }

    @Override // from SystemService
    public boolean isSupportedUser(TargetUser user) {
    public boolean isUserSupported(TargetUser user) {
        return user.getUserInfo().isFull() || user.getUserInfo().isManagedProfile();
    }

+1 −1
Original line number Diff line number Diff line
@@ -279,7 +279,7 @@ class StorageManagerService extends IStorageManager.Stub
        }

        @Override
        public void onStartUser(TargetUser user) {
        public void onUserStarting(TargetUser user) {
            mStorageManagerService.snapshotAndMonitorLegacyStorageAppOp(user.getUserHandle());
        }
    }
+37 −30
Original line number Diff line number Diff line
@@ -238,12 +238,12 @@ public abstract class SystemService {
     * <p>By default returns {@code true}, but subclasses should extend for optimization, if they
     * don't support some types (like headless system user).
     */
    public boolean isSupportedUser(@NonNull TargetUser user) {
    public boolean isUserSupported(@NonNull TargetUser user) {
        return true;
    }

    /**
     * Helper method used to dump which users are {@link #onStartUser(TargetUser) supported}.
     * Helper method used to dump which users are {@link #onUserStarting(TargetUser) supported}.
     *
     * @hide
     */
@@ -264,7 +264,7 @@ public abstract class SystemService {
    }

    /**
     * @deprecated subclasses should extend {@link #onStartUser(TargetUser)} instead
     * @deprecated subclasses should extend {@link #onUserStarting(TargetUser)} instead
     * (which by default calls this method).
     *
     * @hide
@@ -273,7 +273,7 @@ public abstract class SystemService {
    public void onStartUser(@UserIdInt int userId) {}

    /**
     * @deprecated subclasses should extend {@link #onStartUser(TargetUser)} instead
     * @deprecated subclasses should extend {@link #onUserStarting(TargetUser)} instead
     * (which by default calls this method).
     *
     * @hide
@@ -287,17 +287,17 @@ public abstract class SystemService {
     * Called when a new user is starting, for system services to initialize any per-user
     * state they maintain for running users.
     *
     * <p>This method is only called when the service {@link #isSupportedUser(TargetUser) supports}
     * <p>This method is only called when the service {@link #isUserSupported(TargetUser) supports}
     * this user.
     *
     * @param user target user
     */
    public void onStartUser(@NonNull TargetUser user) {
    public void onUserStarting(@NonNull TargetUser user) {
        onStartUser(user.getUserInfo());
    }

    /**
     * @deprecated subclasses should extend {@link #onUnlockUser(TargetUser)} instead (which by
     * @deprecated subclasses should extend {@link #onUserUnlocking(TargetUser)} instead (which by
     * default calls this method).
     *
     * @hide
@@ -306,7 +306,7 @@ public abstract class SystemService {
    public void onUnlockUser(@UserIdInt int userId) {}

    /**
     * @deprecated subclasses should extend {@link #onUnlockUser(TargetUser)} instead (which by
     * @deprecated subclasses should extend {@link #onUserUnlocking(TargetUser)} instead (which by
     * default calls this method).
     *
     * @hide
@@ -326,19 +326,30 @@ public abstract class SystemService {
     * the user will transition into the {@code STATE_RUNNING_UNLOCKED} state.
     * Code written inside system services should use
     * {@link UserManager#isUserUnlockingOrUnlocked(int)} to handle both of
     * these states.
     * these states, or use {@link #onUserUnlocked(TargetUser)} instead.
     * <p>
     * This method is only called when the service {@link #isSupportedUser(TargetUser) supports}
     * This method is only called when the service {@link #isUserSupported(TargetUser) supports}
     * this user.
     *
     * @param user target user
     */
    public void onUnlockUser(@NonNull TargetUser user) {
    public void onUserUnlocking(@NonNull TargetUser user) {
        onUnlockUser(user.getUserInfo());
    }

    /**
     * @deprecated subclasses should extend {@link #onSwitchUser(TargetUser, TargetUser)} instead
     * Called after an existing user is unlocked.
     *
     * <p>This method is only called when the service {@link #isUserSupported(TargetUser) supports}
     * this user.
     *
     * @param user target user
     */
    public void onUserUnlocked(@NonNull TargetUser user) {
    }

    /**
     * @deprecated subclasses should extend {@link #onUserSwitching(TargetUser, TargetUser)} instead
     * (which by default calls this method).
     *
     * @hide
@@ -347,7 +358,7 @@ public abstract class SystemService {
    public void onSwitchUser(@UserIdInt int toUserId) {}

    /**
     * @deprecated subclasses should extend {@link #onSwitchUser(TargetUser, TargetUser)} instead
     * @deprecated subclasses should extend {@link #onUserSwitching(TargetUser, TargetUser)} instead
     * (which by default calls this method).
     *
     * @hide
@@ -362,7 +373,7 @@ public abstract class SystemService {
     * special behavior for whichever user is currently in the foreground.  This is called
     * before any application processes are aware of the new user.
     *
     * <p>This method is only called when the service {@link #isSupportedUser(TargetUser) supports}
     * <p>This method is only called when the service {@link #isUserSupported(TargetUser) supports}
     * either of the users ({@code from} or {@code to}).
     *
     * <b>NOTE: </b> both {@code from} and {@code to} are "live" objects
@@ -371,12 +382,12 @@ public abstract class SystemService {
     * @param from the user switching from
     * @param to the user switching to
     */
    public void onSwitchUser(@Nullable TargetUser from, @NonNull TargetUser to) {
    public void onUserSwitching(@Nullable TargetUser from, @NonNull TargetUser to) {
        onSwitchUser((from == null ? null : from.getUserInfo()), to.getUserInfo());
    }

    /**
     * @deprecated subclasses should extend {@link #onStopUser(TargetUser)} instead
     * @deprecated subclasses should extend {@link #onUserStopping(TargetUser)} instead
     * (which by default calls this method).
     *
     * @hide
@@ -385,7 +396,7 @@ public abstract class SystemService {
    public void onStopUser(@UserIdInt int userId) {}

    /**
     * @deprecated subclasses should extend {@link #onStopUser(TargetUser)} instead
     * @deprecated subclasses should extend {@link #onUserStopping(TargetUser)} instead
     * (which by default calls this method).
     *
     * @hide
@@ -402,19 +413,19 @@ public abstract class SystemService {
     * broadcast to the user; it is a good place to stop making use of any resources of that
     * user (such as binding to a service running in the user).
     *
     * <p>This method is only called when the service {@link #isSupportedUser(TargetUser) supports}
     * <p>This method is only called when the service {@link #isUserSupported(TargetUser) supports}
     * this user.
     *
     * <p>NOTE: This is the last callback where the callee may access the target user's CE storage.
     *
     * @param user target user
     */
    public void onStopUser(@NonNull TargetUser user) {
    public void onUserStopping(@NonNull TargetUser user) {
        onStopUser(user.getUserInfo());
    }

    /**
     * @deprecated subclasses should extend {@link #onCleanupUser(TargetUser)} instead (which by
     * @deprecated subclasses should extend {@link #onUserStopped(TargetUser)} instead (which by
     * default calls this method).
     *
     * @hide
@@ -423,7 +434,7 @@ public abstract class SystemService {
    public void onCleanupUser(@UserIdInt int userId) {}

    /**
     * @deprecated subclasses should extend {@link #onCleanupUser(TargetUser)} instead (which by
     * @deprecated subclasses should extend {@link #onUserStopped(TargetUser)} instead (which by
     * default calls this method).
     *
     * @hide
@@ -434,20 +445,16 @@ public abstract class SystemService {
    }

    /**
     * Called when an existing user is stopping, for system services to finalize any per-user
     * state they maintain for running users.  This is called after all application process
     * teardown of the user is complete.
     * Called after an existing user is stopped.
     *
     * <p>This method is only called when the service {@link #isSupportedUser(TargetUser) supports}
     * this user.
     * <p>This is called after all application process teardown of the user is complete.
     *
     * <p>NOTE: When this callback is called, the CE storage for the target user may not be
     * accessible already.  Use {@link #onStopUser(TargetUser)} instead if you need to access the CE
     * storage.
     * <p>This method is only called when the service {@link #isUserSupported(TargetUser) supports}
     * this user.
     *
     * @param user target user
     */
    public void onCleanupUser(@NonNull TargetUser user) {
    public void onUserStopped(@NonNull TargetUser user) {
        onCleanupUser(user.getUserInfo());
    }

Loading