Merge "Send network & security logging callbacks in foreground" into sc-dev am: 68aa35b03d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14530944

Change-Id: I33387735d9c8ebc1efc59804a2ec1f1659826765
This commit is contained in:
Rubin Xu
2021-05-19 15:40:00 +00:00
committed by Automerger Merge Worker
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
* 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 intent The received intent as per {@link #onReceive}.
* @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
* 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 intent The received intent as per {@link #onReceive}.
* @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 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 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
* 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 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) {
final int deviceOwnerUserId;
final ComponentName receiverComponent;
synchronized (getLockObject()) {
deviceOwnerUserId = mOwners.getDeviceOwnerUserId();
receiverComponent = mOwners.getDeviceOwnerComponent();
}
ComponentName receiverComponent = null;
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);
sendActiveAdminCommand(action, extras, deviceOwnerUserId, receiverComponent,
/* inForeground */ false);
}
void sendDeviceOwnerOrProfileOwnerCommand(String action, Bundle extras, int userId) {
if (userId == UserHandle.USER_ALL) {
userId = UserHandle.USER_SYSTEM;
}
boolean inForeground = false;
ComponentName receiverComponent = null;
if (action.equals(DeviceAdminReceiver.ACTION_NETWORK_LOGS_AVAILABLE)) {
inForeground = true;
receiverComponent = resolveDelegateReceiver(DELEGATION_NETWORK_LOGGING, action, userId);
}
if (action.equals(DeviceAdminReceiver.ACTION_SECURITY_LOGS_AVAILABLE)) {
inForeground = true;
receiverComponent = resolveDelegateReceiver(
DELEGATION_SECURITY_LOGGING, action, userId);
}
if (receiverComponent == null) {
receiverComponent = getOwnerComponent(userId);
}
sendActiveAdminCommand(action, extras, userId, receiverComponent);
sendActiveAdminCommand(action, extras, userId, receiverComponent, inForeground);
}
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,
@UserIdInt int userId, ComponentName receiverComponent) {
@UserIdInt int userId, ComponentName receiverComponent, boolean inForeground) {
final Intent intent = new Intent(action);
intent.setComponent(receiverComponent);
if (extras != null) {
intent.putExtras(extras);
}
if (inForeground) {
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
}
if (VERBOSE_LOG) {
Slogf.v(LOG_TAG, "sendActiveAdminCommand(): broadcasting " + action + " to "
+ receiverComponent.flattenToShortString() + " on user " + userId);