Merge "Improved user callbacks on SystemService:" into rvc-dev

This commit is contained in:
Felipe Leme
2020-02-24 16:59:32 +00:00
committed by Android (Google) Code Review
11 changed files with 83 additions and 57 deletions

View File

@@ -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

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -279,7 +279,7 @@ class StorageManagerService extends IStorageManager.Stub
}
@Override
public void onStartUser(TargetUser user) {
public void onUserStarting(TargetUser user) {
mStorageManagerService.snapshotAndMonitorLegacyStorageAppOp(user.getUserHandle());
}
}

View File

@@ -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}
* <p>This is called after all application process teardown of the user is complete.
*
* <p>This method is only called when the service {@link #isUserSupported(TargetUser) supports}
* this user.
*
* <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.
*
* @param user target user
*/
public void onCleanupUser(@NonNull TargetUser user) {
public void onUserStopped(@NonNull TargetUser user) {
onCleanupUser(user.getUserInfo());
}

View File

@@ -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?");

View File

@@ -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,

View File

@@ -713,7 +713,7 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem
/**
* Gets a list of all supported users (i.e., those that pass the
* {@link #isSupportedUser(TargetUser)}check).
* {@link #isUserSupported(TargetUser)}check).
*/
@NonNull
protected List<UserInfo> getSupportedUsers() {
@@ -722,7 +722,7 @@ public abstract class AbstractMasterSystemService<M extends AbstractMasterSystem
final List<UserInfo> supportedUsers = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
final UserInfo userInfo = allUsers[i];
if (isSupportedUser(new TargetUser(userInfo))) {
if (isUserSupported(new TargetUser(userInfo))) {
supportedUsers.add(userInfo);
}
}

View File

@@ -71,12 +71,12 @@ public class PeopleService extends SystemService {
}
@Override
public void onUnlockUser(@NonNull TargetUser targetUser) {
public void onUserUnlocking(@NonNull TargetUser targetUser) {
mDataManager.onUserUnlocked(targetUser.getUserIdentifier());
}
@Override
public void onStopUser(@NonNull TargetUser targetUser) {
public void onUserStopping(@NonNull TargetUser targetUser) {
mDataManager.onUserStopped(targetUser.getUserIdentifier());
}

View File

@@ -110,18 +110,18 @@ public class UsbService extends IUsbManager.Stub {
}
@Override
public void onSwitchUser(TargetUser from, TargetUser to) {
public void onUserSwitching(TargetUser from, TargetUser to) {
FgThread.getHandler()
.postAtFrontOfQueue(() -> mUsbService.onSwitchUser(to.getUserIdentifier()));
}
@Override
public void onStopUser(TargetUser userInfo) {
public void onUserStopping(TargetUser userInfo) {
mUsbService.onStopUser(userInfo.getUserHandle());
}
@Override
public void onUnlockUser(TargetUser userInfo) {
public void onUserUnlocking(TargetUser userInfo) {
mUsbService.onUnlockUser(userInfo.getUserIdentifier());
}
}

View File

@@ -167,7 +167,7 @@ public class VoiceInteractionManagerService extends SystemService {
}
@Override
public boolean isSupportedUser(TargetUser user) {
public boolean isUserSupported(TargetUser user) {
return isSupported(user.getUserInfo());
}