Merge "Send network & security logging callbacks in foreground" into sc-dev

This commit is contained in:
Rubin Xu
2021-05-19 15:34:31 +00:00
committed by Android (Google) Code Review
3 changed files with 34 additions and 21 deletions

View File

@@ -104,6 +104,10 @@ public class DelegatedAdminReceiver extends BroadcastReceiver {
* receiver's manifest in order to receive this callback. The default implementation * receiver's manifest in order to receive this callback. The default implementation
* simply throws {@link UnsupportedOperationException}. * simply throws {@link UnsupportedOperationException}.
* *
* <p>
* This callback is triggered by a foreground broadcast and the app should ensure that any
* long-running work is not executed synchronously inside the callback.
*
* @param context The running context as per {@link #onReceive}. * @param context The running context as per {@link #onReceive}.
* @param intent The received intent as per {@link #onReceive}. * @param intent The received intent as per {@link #onReceive}.
* @param batchToken The token representing the current batch of network logs. * @param batchToken The token representing the current batch of network logs.
@@ -130,6 +134,10 @@ public class DelegatedAdminReceiver extends BroadcastReceiver {
* the receiver's manifest in order to receive this callback. The default implementation * the receiver's manifest in order to receive this callback. The default implementation
* simply throws {@link UnsupportedOperationException}. * simply throws {@link UnsupportedOperationException}.
* *
* <p>
* This callback is triggered by a foreground broadcast and the app should ensure that any
* long-running work is not executed synchronously inside the callback.
*
* @param context The running context as per {@link #onReceive}. * @param context The running context as per {@link #onReceive}.
* @param intent The received intent as per {@link #onReceive}. * @param intent The received intent as per {@link #onReceive}.
* @see DevicePolicyManager#retrieveSecurityLogs * @see DevicePolicyManager#retrieveSecurityLogs

View File

@@ -942,7 +942,12 @@ public class DeviceAdminReceiver extends BroadcastReceiver {
* *
* <p>This callback will be re-triggered if the logs are not retrieved. * <p>This callback will be re-triggered if the logs are not retrieved.
* *
* <p>This callback is only applicable to device owners. * <p>This callback is only applicable to device owners and profile owners of
* organization-owned managed profiles.
*
* <p>
* This callback is triggered by a foreground broadcast and the app should ensure that any
* long-running work is not executed synchronously inside the callback.
* *
* @param context The running context as per {@link #onReceive}. * @param context The running context as per {@link #onReceive}.
* @param intent The received intent as per {@link #onReceive}. * @param intent The received intent as per {@link #onReceive}.
@@ -961,7 +966,11 @@ public class DeviceAdminReceiver extends BroadcastReceiver {
* possible to retrieve the network logs batch with the most recent {@code batchToken} provided * possible to retrieve the network logs batch with the most recent {@code batchToken} provided
* by this callback. See {@link DevicePolicyManager#setAffiliationIds}. * by this callback. See {@link DevicePolicyManager#setAffiliationIds}.
* *
* <p>This callback is only applicable to device owners. * <p>This callback is only applicable to device owners and profile owners.
*
* <p>
* This callback is triggered by a foreground broadcast and the app should ensure that any
* long-running work is not executed synchronously inside the callback.
* *
* @param context The running context as per {@link #onReceive}. * @param context The running context as per {@link #onReceive}.
* @param intent The received intent as per {@link #onReceive}. * @param intent The received intent as per {@link #onReceive}.

View File

@@ -7870,56 +7870,52 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
void sendDeviceOwnerCommand(String action, Bundle extras) { void sendDeviceOwnerCommand(String action, Bundle extras) {
final int deviceOwnerUserId; final int deviceOwnerUserId;
final ComponentName receiverComponent;
synchronized (getLockObject()) { synchronized (getLockObject()) {
deviceOwnerUserId = mOwners.getDeviceOwnerUserId(); deviceOwnerUserId = mOwners.getDeviceOwnerUserId();
receiverComponent = mOwners.getDeviceOwnerComponent();
} }
sendActiveAdminCommand(action, extras, deviceOwnerUserId, receiverComponent,
ComponentName receiverComponent = null; /* inForeground */ false);
if (action.equals(DeviceAdminReceiver.ACTION_NETWORK_LOGS_AVAILABLE)) {
receiverComponent = resolveDelegateReceiver(DELEGATION_NETWORK_LOGGING, action,
deviceOwnerUserId);
}
if (action.equals(DeviceAdminReceiver.ACTION_SECURITY_LOGS_AVAILABLE)) {
receiverComponent = resolveDelegateReceiver(DELEGATION_SECURITY_LOGGING, action,
deviceOwnerUserId);
}
if (receiverComponent == null) {
synchronized (getLockObject()) {
receiverComponent = mOwners.getDeviceOwnerComponent();
}
}
sendActiveAdminCommand(action, extras, deviceOwnerUserId, receiverComponent);
} }
void sendDeviceOwnerOrProfileOwnerCommand(String action, Bundle extras, int userId) { void sendDeviceOwnerOrProfileOwnerCommand(String action, Bundle extras, int userId) {
if (userId == UserHandle.USER_ALL) { if (userId == UserHandle.USER_ALL) {
userId = UserHandle.USER_SYSTEM; userId = UserHandle.USER_SYSTEM;
} }
boolean inForeground = false;
ComponentName receiverComponent = null; ComponentName receiverComponent = null;
if (action.equals(DeviceAdminReceiver.ACTION_NETWORK_LOGS_AVAILABLE)) { if (action.equals(DeviceAdminReceiver.ACTION_NETWORK_LOGS_AVAILABLE)) {
inForeground = true;
receiverComponent = resolveDelegateReceiver(DELEGATION_NETWORK_LOGGING, action, userId); receiverComponent = resolveDelegateReceiver(DELEGATION_NETWORK_LOGGING, action, userId);
} }
if (action.equals(DeviceAdminReceiver.ACTION_SECURITY_LOGS_AVAILABLE)) { if (action.equals(DeviceAdminReceiver.ACTION_SECURITY_LOGS_AVAILABLE)) {
inForeground = true;
receiverComponent = resolveDelegateReceiver( receiverComponent = resolveDelegateReceiver(
DELEGATION_SECURITY_LOGGING, action, userId); DELEGATION_SECURITY_LOGGING, action, userId);
} }
if (receiverComponent == null) { if (receiverComponent == null) {
receiverComponent = getOwnerComponent(userId); receiverComponent = getOwnerComponent(userId);
} }
sendActiveAdminCommand(action, extras, userId, receiverComponent); sendActiveAdminCommand(action, extras, userId, receiverComponent, inForeground);
} }
private void sendProfileOwnerCommand(String action, Bundle extras, @UserIdInt int userId) { private void sendProfileOwnerCommand(String action, Bundle extras, @UserIdInt int userId) {
sendActiveAdminCommand(action, extras, userId, mOwners.getProfileOwnerComponent(userId)); sendActiveAdminCommand(action, extras, userId, mOwners.getProfileOwnerComponent(userId),
/* inForeground */ false);
} }
private void sendActiveAdminCommand(String action, Bundle extras, private void sendActiveAdminCommand(String action, Bundle extras,
@UserIdInt int userId, ComponentName receiverComponent) { @UserIdInt int userId, ComponentName receiverComponent, boolean inForeground) {
final Intent intent = new Intent(action); final Intent intent = new Intent(action);
intent.setComponent(receiverComponent); intent.setComponent(receiverComponent);
if (extras != null) { if (extras != null) {
intent.putExtras(extras); intent.putExtras(extras);
} }
if (inForeground) {
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
}
if (VERBOSE_LOG) { if (VERBOSE_LOG) {
Slogf.v(LOG_TAG, "sendActiveAdminCommand(): broadcasting " + action + " to " Slogf.v(LOG_TAG, "sendActiveAdminCommand(): broadcasting " + action + " to "
+ receiverComponent.flattenToShortString() + " on user " + userId); + receiverComponent.flattenToShortString() + " on user " + userId);