Send callbacks to DO when a user is added or removed.

BUG:32764090
Test: manual
Change-Id: Icfac801fd2c9670f3d68cf6971f7aba2332dbb6b
This commit is contained in:
Nicolas Prevot
2016-11-17 17:30:55 +00:00
parent d6658ac131
commit e95c2817f7
5 changed files with 66 additions and 0 deletions

View File

@@ -5963,6 +5963,8 @@ package android.app.admin {
method public void onReceive(android.content.Context, android.content.Intent);
method public void onSecurityLogsAvailable(android.content.Context, android.content.Intent);
method public void onSystemUpdatePending(android.content.Context, android.content.Intent, long);
method public void onUserAdded(android.content.Context, android.content.Intent, android.os.UserHandle);
method public void onUserRemoved(android.content.Context, android.content.Intent, android.os.UserHandle);
field public static final java.lang.String ACTION_DEVICE_ADMIN_DISABLED = "android.app.action.DEVICE_ADMIN_DISABLED";
field public static final java.lang.String ACTION_DEVICE_ADMIN_DISABLE_REQUESTED = "android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED";
field public static final java.lang.String ACTION_DEVICE_ADMIN_ENABLED = "android.app.action.DEVICE_ADMIN_ENABLED";

View File

@@ -6134,6 +6134,8 @@ package android.app.admin {
method public void onReceive(android.content.Context, android.content.Intent);
method public void onSecurityLogsAvailable(android.content.Context, android.content.Intent);
method public void onSystemUpdatePending(android.content.Context, android.content.Intent, long);
method public void onUserAdded(android.content.Context, android.content.Intent, android.os.UserHandle);
method public void onUserRemoved(android.content.Context, android.content.Intent, android.os.UserHandle);
field public static final java.lang.String ACTION_DEVICE_ADMIN_DISABLED = "android.app.action.DEVICE_ADMIN_DISABLED";
field public static final java.lang.String ACTION_DEVICE_ADMIN_DISABLE_REQUESTED = "android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED";
field public static final java.lang.String ACTION_DEVICE_ADMIN_ENABLED = "android.app.action.DEVICE_ADMIN_ENABLED";

View File

@@ -5979,6 +5979,8 @@ package android.app.admin {
method public void onReceive(android.content.Context, android.content.Intent);
method public void onSecurityLogsAvailable(android.content.Context, android.content.Intent);
method public void onSystemUpdatePending(android.content.Context, android.content.Intent, long);
method public void onUserAdded(android.content.Context, android.content.Intent, android.os.UserHandle);
method public void onUserRemoved(android.content.Context, android.content.Intent, android.os.UserHandle);
field public static final java.lang.String ACTION_DEVICE_ADMIN_DISABLED = "android.app.action.DEVICE_ADMIN_DISABLED";
field public static final java.lang.String ACTION_DEVICE_ADMIN_DISABLE_REQUESTED = "android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED";
field public static final java.lang.String ACTION_DEVICE_ADMIN_ENABLED = "android.app.action.DEVICE_ADMIN_ENABLED";

View File

@@ -28,6 +28,7 @@ import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.UserHandle;
import android.security.KeyChain;
import java.lang.annotation.Retention;
@@ -305,6 +306,24 @@ public class DeviceAdminReceiver extends BroadcastReceiver {
public static final String EXTRA_NETWORK_LOGS_COUNT =
"android.app.extra.EXTRA_NETWORK_LOGS_COUNT";
/**
* Broadcast action: notify the device owner that a user or profile has been added.
* Carries an extra {@link Intent#EXTRA_USER} that has the {@link UserHandle} of
* the new user.
* @hide
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_USER_ADDED = "android.app.action.USER_ADDED";
/**
* Broadcast action: notify the device owner that a user or profile has been removed.
* Carries an extra {@link Intent#EXTRA_USER} that has the {@link UserHandle} of
* the new user.
* @hide
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String ACTION_USER_REMOVED = "android.app.action.USER_REMOVED";
/**
* A string containing the SHA-256 hash of the bugreport file.
*
@@ -690,6 +709,30 @@ public class DeviceAdminReceiver extends BroadcastReceiver {
int networkLogsCount) {
}
/**
* Called when a user or profile is created.
*
* <p>This callback is only applicable to device owners.
*
* @param context The running context as per {@link #onReceive}.
* @param intent The received intent as per {@link #onReceive}.
* @param newUser The {@link UserHandle} of the user that has just been added.
*/
public void onUserAdded(Context context, Intent intent, UserHandle newUser) {
}
/**
* Called when a user or profile is removed.
*
* <p>This callback is only applicable to device owners.
*
* @param context The running context as per {@link #onReceive}.
* @param intent The received intent as per {@link #onReceive}.
* @param removedUser The {@link UserHandle} of the user that has just been removed.
*/
public void onUserRemoved(Context context, Intent intent, UserHandle removedUser) {
}
/**
* Intercept standard device administrator broadcasts. Implementations
* should not override this method; it is better to implement the
@@ -748,6 +791,10 @@ public class DeviceAdminReceiver extends BroadcastReceiver {
long batchToken = intent.getLongExtra(EXTRA_NETWORK_LOGS_TOKEN, -1);
int networkLogsCount = intent.getIntExtra(EXTRA_NETWORK_LOGS_COUNT, 0);
onNetworkLogsAvailable(context, intent, batchToken, networkLogsCount);
} else if (ACTION_USER_ADDED.equals(action)) {
onUserAdded(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
} else if (ACTION_USER_REMOVED.equals(action)) {
onUserRemoved(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
}
}
}

View File

@@ -544,8 +544,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
new MonitoringCertNotificationTask().execute(userId);
}
if (Intent.ACTION_USER_ADDED.equals(action)) {
sendUserAddedOrRemovedCommand(DeviceAdminReceiver.ACTION_USER_ADDED, userHandle);
disableDeviceOwnerManagedSingleUserFeaturesIfNeeded();
} else if (Intent.ACTION_USER_REMOVED.equals(action)) {
sendUserAddedOrRemovedCommand(DeviceAdminReceiver.ACTION_USER_REMOVED, userHandle);
disableDeviceOwnerManagedSingleUserFeaturesIfNeeded();
removeUserData(userHandle);
} else if (Intent.ACTION_USER_STARTED.equals(action)) {
@@ -568,6 +570,17 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
clearWipeProfileNotification();
}
}
private void sendUserAddedOrRemovedCommand(String action, int userHandle) {
synchronized (DevicePolicyManagerService.this) {
ActiveAdmin deviceOwner = getDeviceOwnerAdminLocked();
if (deviceOwner != null) {
Bundle extras = new Bundle();
extras.putParcelable(Intent.EXTRA_USER, UserHandle.of(userHandle));
sendAdminCommandLocked(deviceOwner, action, extras, null);
}
}
}
};
static class ActiveAdmin {