Merge "Do not hold lock when calling into NotificationManager" into sc-dev am: 250e7a7dff am: 9e0dac3473

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

Change-Id: I45311974a797314a0e3fd2ec8df7d22013edff29
This commit is contained in:
TreeHugger Robot
2021-07-05 10:42:03 +00:00
committed by Automerger Merge Worker

View File

@@ -14991,6 +14991,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
} }
private void setNetworkLoggingActiveInternal(boolean active) { private void setNetworkLoggingActiveInternal(boolean active) {
final boolean[] shouldSendNotification = new boolean[] {false};
synchronized (getLockObject()) { synchronized (getLockObject()) {
mInjector.binderWithCleanCallingIdentity(() -> { mInjector.binderWithCleanCallingIdentity(() -> {
if (active) { if (active) {
@@ -15007,17 +15008,23 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
+ " service not being available yet."); + " service not being available yet.");
} }
maybePauseDeviceWideLoggingLocked(); maybePauseDeviceWideLoggingLocked();
sendNetworkLoggingNotificationLocked(); shouldSendNotification[0] = shouldSendNetworkLoggingNotificationLocked();
} else { } else {
if (mNetworkLogger != null && !mNetworkLogger.stopNetworkLogging()) { if (mNetworkLogger != null && !mNetworkLogger.stopNetworkLogging()) {
Slogf.wtf(LOG_TAG, "Network logging could not be stopped due to the logging" Slogf.wtf(LOG_TAG, "Network logging could not be stopped due to the logging"
+ " service not being available yet."); + " service not being available yet.");
} }
mNetworkLogger = null; mNetworkLogger = null;
mInjector.getNotificationManager().cancel(SystemMessage.NOTE_NETWORK_LOGGING);
} }
}); });
} }
if (active) {
if (shouldSendNotification[0]) {
sendNetworkLoggingNotification();
}
} else {
mInjector.getNotificationManager().cancel(SystemMessage.NOTE_NETWORK_LOGGING);
}
} }
private @UserIdInt int getNetworkLoggingAffectedUser() { private @UserIdInt int getNetworkLoggingAffectedUser() {
@@ -15175,20 +15182,25 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
} }
} }
private void sendNetworkLoggingNotificationLocked() { /**
* Returns whether it's time to post another network logging notification. When returning true,
* this method has the side-effect of updating the recorded last network logging notification
* time to now.
*/
private boolean shouldSendNetworkLoggingNotificationLocked() {
ensureLocked(); ensureLocked();
// Send a network logging notification if the admin is a device owner, not profile owner. // Send a network logging notification if the admin is a device owner, not profile owner.
final ActiveAdmin deviceOwner = getDeviceOwnerAdminLocked(); final ActiveAdmin deviceOwner = getDeviceOwnerAdminLocked();
if (deviceOwner == null || !deviceOwner.isNetworkLoggingEnabled) { if (deviceOwner == null || !deviceOwner.isNetworkLoggingEnabled) {
return; return false;
} }
if (deviceOwner.numNetworkLoggingNotifications if (deviceOwner.numNetworkLoggingNotifications
>= ActiveAdmin.DEF_MAXIMUM_NETWORK_LOGGING_NOTIFICATIONS_SHOWN) { >= ActiveAdmin.DEF_MAXIMUM_NETWORK_LOGGING_NOTIFICATIONS_SHOWN) {
return; return false;
} }
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
if (now - deviceOwner.lastNetworkLoggingNotificationTimeMs < MS_PER_DAY) { if (now - deviceOwner.lastNetworkLoggingNotificationTimeMs < MS_PER_DAY) {
return; return false;
} }
deviceOwner.numNetworkLoggingNotifications++; deviceOwner.numNetworkLoggingNotifications++;
if (deviceOwner.numNetworkLoggingNotifications if (deviceOwner.numNetworkLoggingNotifications
@@ -15197,6 +15209,11 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
} else { } else {
deviceOwner.lastNetworkLoggingNotificationTimeMs = now; deviceOwner.lastNetworkLoggingNotificationTimeMs = now;
} }
saveSettingsLocked(deviceOwner.getUserHandle().getIdentifier());
return true;
}
private void sendNetworkLoggingNotification() {
final PackageManagerInternal pm = mInjector.getPackageManagerInternal(); final PackageManagerInternal pm = mInjector.getPackageManagerInternal();
final Intent intent = new Intent(DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG); final Intent intent = new Intent(DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG);
intent.setPackage(pm.getSystemUiServiceComponent().getPackageName()); intent.setPackage(pm.getSystemUiServiceComponent().getPackageName());
@@ -15215,7 +15232,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
.bigText(mContext.getString(R.string.network_logging_notification_text))) .bigText(mContext.getString(R.string.network_logging_notification_text)))
.build(); .build();
mInjector.getNotificationManager().notify(SystemMessage.NOTE_NETWORK_LOGGING, notification); mInjector.getNotificationManager().notify(SystemMessage.NOTE_NETWORK_LOGGING, notification);
saveSettingsLocked(deviceOwner.getUserHandle().getIdentifier());
} }
/** /**