Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9b8ad443 authored by Alex Johnston's avatar Alex Johnston Committed by Automerger Merge Worker
Browse files

Merge "Security logging broadcast work profile" into sc-dev am: e9614f06

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

Change-Id: I4e8ec6b944161ef0c7f9a6a1feb1dc9f38a958ae
parents 610266c3 e9614f06
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -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);
        }
    }