Merge "Security logging broadcast work profile" into sc-dev

This commit is contained in:
Alex Johnston
2021-05-19 16:17:24 +00:00
committed by Android (Google) Code Review

View File

@@ -226,7 +226,7 @@ class SecurityLogMonitor implements Runnable {
Slog.i(TAG, "Resumed.");
try {
notifyDeviceOwnerIfNeeded(false /* force */);
notifyDeviceOwnerOrProfileOwnerIfNeeded(false /* force */);
} catch (InterruptedException e) {
Log.w(TAG, "Thread interrupted.", e);
}
@@ -439,7 +439,7 @@ class SecurityLogMonitor implements Runnable {
saveLastEvents(newLogs);
newLogs.clear();
notifyDeviceOwnerIfNeeded(force);
notifyDeviceOwnerOrProfileOwnerIfNeeded(force);
} catch (IOException e) {
Log.e(TAG, "Failed to read security log", e);
} catch (InterruptedException e) {
@@ -460,8 +460,9 @@ class SecurityLogMonitor implements Runnable {
Slog.i(TAG, "MonitorThread exit.");
}
private void notifyDeviceOwnerIfNeeded(boolean force) throws InterruptedException {
boolean allowRetrievalAndNotifyDO = false;
private void notifyDeviceOwnerOrProfileOwnerIfNeeded(boolean force)
throws InterruptedException {
boolean allowRetrievalAndNotifyDOOrPO = false;
mLock.lockInterruptibly();
try {
if (mPaused) {
@@ -471,16 +472,16 @@ class SecurityLogMonitor implements Runnable {
if (logSize >= BUFFER_ENTRIES_NOTIFICATION_LEVEL || (force && logSize > 0)) {
// Allow DO to retrieve logs if too many pending logs or if forced.
if (!mAllowedToRetrieve) {
allowRetrievalAndNotifyDO = true;
allowRetrievalAndNotifyDOOrPO = true;
}
if (DEBUG) Slog.d(TAG, "Number of log entries over threshold: " + logSize);
}
if (logSize > 0 && SystemClock.elapsedRealtime() >= mNextAllowedRetrievalTimeMillis) {
// Rate limit reset
allowRetrievalAndNotifyDO = true;
allowRetrievalAndNotifyDOOrPO = true;
if (DEBUG) Slog.d(TAG, "Timeout reached");
}
if (allowRetrievalAndNotifyDO) {
if (allowRetrievalAndNotifyDOOrPO) {
mAllowedToRetrieve = true;
// Set the timeout to retry the notification if the DO misses it.
mNextAllowedRetrievalTimeMillis = SystemClock.elapsedRealtime()
@@ -489,10 +490,10 @@ class SecurityLogMonitor implements Runnable {
} finally {
mLock.unlock();
}
if (allowRetrievalAndNotifyDO) {
Slog.i(TAG, "notify DO");
mService.sendDeviceOwnerCommand(DeviceAdminReceiver.ACTION_SECURITY_LOGS_AVAILABLE,
null);
if (allowRetrievalAndNotifyDOOrPO) {
Slog.i(TAG, "notify DO or PO");
mService.sendDeviceOwnerOrProfileOwnerCommand(
DeviceAdminReceiver.ACTION_SECURITY_LOGS_AVAILABLE, null, mEnabledUser);
}
}