diff --git a/services/api/current.txt b/services/api/current.txt index 4a0a0d8e5aef8..8c90165eeb4ad 100644 --- a/services/api/current.txt +++ b/services/api/current.txt @@ -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 diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java index 5405fc74dfb68..e49c1ed47c931 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java @@ -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(); } diff --git a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java index 9a33fc9548a00..5d2b9f3593817 100644 --- a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java +++ b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java @@ -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(); } diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java index d86b2230ee7a3..b1cb1380e4da4 100644 --- a/services/core/java/com/android/server/StorageManagerService.java +++ b/services/core/java/com/android/server/StorageManagerService.java @@ -279,7 +279,7 @@ class StorageManagerService extends IStorageManager.Stub } @Override - public void onStartUser(TargetUser user) { + public void onUserStarting(TargetUser user) { mStorageManagerService.snapshotAndMonitorLegacyStorageAppOp(user.getUserHandle()); } } diff --git a/services/core/java/com/android/server/SystemService.java b/services/core/java/com/android/server/SystemService.java index aabe98b3afa04..e5c05408f6288 100644 --- a/services/core/java/com/android/server/SystemService.java +++ b/services/core/java/com/android/server/SystemService.java @@ -238,12 +238,12 @@ public abstract class SystemService { *
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. * - *
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 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. *
- * 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. + * + *
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. * - *
This method is only called when the service {@link #isSupportedUser(TargetUser) supports} + *
This method is only called when the service {@link #isUserSupported(TargetUser) supports} * either of the users ({@code from} or {@code to}). * * NOTE: 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). * - *
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. * *
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. * - *
This method is only called when the service {@link #isSupportedUser(TargetUser) supports} + *
This is called after all application process teardown of the user is complete. + * + *
This method is only called when the service {@link #isUserSupported(TargetUser) supports} * this user. * - *
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.
- *
* @param user target user
*/
- public void onCleanupUser(@NonNull TargetUser user) {
+ public void onUserStopped(@NonNull TargetUser user) {
onCleanupUser(user.getUserInfo());
}
diff --git a/services/core/java/com/android/server/SystemServiceManager.java b/services/core/java/com/android/server/SystemServiceManager.java
index e7f78462e6eea..f16f6ef2e72de 100644
--- a/services/core/java/com/android/server/SystemServiceManager.java
+++ b/services/core/java/com/android/server/SystemServiceManager.java
@@ -51,7 +51,8 @@ public class SystemServiceManager {
// Constants used on onUser(...)
private static final String START = "Start";
- private static final String UNLOCK = "Unlock";
+ private static final String UNLOCKING = "Unlocking";
+ private static final String UNLOCKED = "Unlocked";
private static final String SWITCH = "Switch";
private static final String STOP = "Stop";
private static final String CLEANUP = "Cleanup";
@@ -260,7 +261,14 @@ public class SystemServiceManager {
* Unlocks the given user.
*/
public void unlockUser(final @UserIdInt int userHandle) {
- onUser(UNLOCK, userHandle);
+ onUser(UNLOCKING, userHandle);
+ }
+
+ /**
+ * Called after the user was unlocked.
+ */
+ public void onUserUnlocked(final @UserIdInt int userHandle) {
+ onUser(UNLOCKED, userHandle);
}
/**
@@ -304,12 +312,12 @@ public class SystemServiceManager {
for (int i = 0; i < serviceLen; i++) {
final SystemService service = mServices.get(i);
final String serviceName = service.getClass().getName();
- boolean supported = service.isSupportedUser(curUser);
+ boolean supported = service.isUserSupported(curUser);
// Must check if either curUser or prevUser is supported (for example, if switching from
// unsupported to supported, we still need to notify the services)
if (!supported && prevUser != null) {
- supported = service.isSupportedUser(prevUser);
+ supported = service.isUserSupported(prevUser);
}
if (!supported) {
@@ -328,19 +336,22 @@ public class SystemServiceManager {
try {
switch (onWhat) {
case SWITCH:
- service.onSwitchUser(prevUser, curUser);
+ service.onUserSwitching(prevUser, curUser);
break;
case START:
- service.onStartUser(curUser);
+ service.onUserStarting(curUser);
break;
- case UNLOCK:
- service.onUnlockUser(curUser);
+ case UNLOCKING:
+ service.onUserUnlocking(curUser);
+ break;
+ case UNLOCKED:
+ service.onUserUnlocked(curUser);
break;
case STOP:
- service.onStopUser(curUser);
+ service.onUserStopping(curUser);
break;
case CLEANUP:
- service.onCleanupUser(curUser);
+ service.onUserStopped(curUser);
break;
default:
throw new IllegalArgumentException(onWhat + " what?");
diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java
index fb48db4a59213..a7125b4a1151e 100644
--- a/services/core/java/com/android/server/am/UserController.java
+++ b/services/core/java/com/android/server/am/UserController.java
@@ -146,6 +146,7 @@ class UserController implements Handler.Callback {
static final int REPORT_USER_SWITCH_COMPLETE_MSG = 80;
static final int USER_SWITCH_CALLBACKS_TIMEOUT_MSG = 90;
static final int USER_UNLOCK_MSG = 100;
+ static final int USER_UNLOCKED_MSG = 105;
static final int REPORT_LOCKED_BOOT_COMPLETE_MSG = 110;
static final int START_USER_SWITCH_FG_MSG = 120;
@@ -625,6 +626,9 @@ class UserController implements Handler.Callback {
FrameworkStatsLog.BOOT_TIME_EVENT_ELAPSED_TIME__EVENT__FRAMEWORK_BOOT_COMPLETED,
elapsedTimeMs);
}
+
+ mHandler.obtainMessage(USER_UNLOCKED_MSG, userId, 0).sendToTarget();
+
final Intent bootIntent = new Intent(Intent.ACTION_BOOT_COMPLETED, null);
bootIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
bootIntent.addFlags(Intent.FLAG_RECEIVER_NO_ABORT
@@ -2366,6 +2370,9 @@ class UserController implements Handler.Callback {
});
finishUserUnlocked((UserState) msg.obj);
break;
+ case USER_UNLOCKED_MSG:
+ mInjector.getSystemServiceManager().onUserUnlocked(msg.arg1);
+ break;
case USER_CURRENT_MSG:
mInjector.batteryStatsServiceNoteEvent(
BatteryStats.HistoryItem.EVENT_USER_FOREGROUND_FINISH,
diff --git a/services/core/java/com/android/server/infra/AbstractMasterSystemService.java b/services/core/java/com/android/server/infra/AbstractMasterSystemService.java
index 8206fef90ab7d..2672f848f1920 100644
--- a/services/core/java/com/android/server/infra/AbstractMasterSystemService.java
+++ b/services/core/java/com/android/server/infra/AbstractMasterSystemService.java
@@ -713,7 +713,7 @@ public abstract class AbstractMasterSystemService