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

Commit 4d35df36 authored by Alex Salo's avatar Alex Salo Committed by Android (Google) Code Review
Browse files

Merge "Add screen timeout extension event to statsd"

parents d0eca3b3 d7c3eefe
Loading
Loading
Loading
Loading
+76 −63
Original line number Diff line number Diff line
@@ -234,6 +234,7 @@ message Atom {
        BluetoothBondStateChanged bluetooth_bond_state_changed = 165;
        BluetoothClassicPairingEventReported bluetooth_classic_pairing_event_reported = 166;
        BluetoothSmpPairingEventReported bluetooth_smp_pairing_event_reported = 167;
        ScreenTimeoutExtensionReported screen_timeout_extension_reported = 168;
    }

    // Pulled events will start at field 10000.
@@ -5290,3 +5291,15 @@ message ScheduledJobConstraintChanged {
    }
    optional State state = 4;
}

/**
 * Logs PowerManagerService screen timeout resets (extensions) that happen when an attention check
 * returns true.
 *
 * Logged from:
 *   frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
 */
message ScreenTimeoutExtensionReported {
    // Describes how many times in a row did the power manager reset the screen off timeout.
    optional uint32 consecutive_timeout_extended_count = 1;
}
+19 −0
Original line number Diff line number Diff line
@@ -24,11 +24,13 @@ import android.os.PowerManagerInternal;
import android.os.SystemClock;
import android.service.attention.AttentionService;
import android.util.Slog;
import android.util.StatsLog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.server.LocalServices;

import java.io.PrintWriter;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Class responsible for checking if the user is currently paying attention to the phone and
@@ -79,6 +81,11 @@ public class AttentionDetector {
     */
    private int mWakefulness;

    /**
     * Describes how many times in a row was the timeout extended.
     */
    private AtomicLong mConsecutiveTimeoutExtendedCount = new AtomicLong(0);

    @VisibleForTesting
    final AttentionCallbackInternal mCallback = new AttentionCallbackInternal() {

@@ -95,6 +102,8 @@ public class AttentionDetector {
                    }
                    if (result == AttentionService.ATTENTION_SUCCESS_PRESENT) {
                        mOnUserAttention.run();
                    } else {
                        resetConsecutiveExtensionCount();
                    }
                }
            }
@@ -176,6 +185,7 @@ public class AttentionDetector {
    public int onUserActivity(long eventTime, int event) {
        switch (event) {
            case PowerManager.USER_ACTIVITY_EVENT_ATTENTION:
                mConsecutiveTimeoutExtendedCount.incrementAndGet();
                return 0;
            case PowerManager.USER_ACTIVITY_EVENT_OTHER:
            case PowerManager.USER_ACTIVITY_EVENT_BUTTON:
@@ -183,6 +193,7 @@ public class AttentionDetector {
            case PowerManager.USER_ACTIVITY_EVENT_ACCESSIBILITY:
                cancelCurrentRequestIfAny();
                mLastUserActivityTime = eventTime;
                resetConsecutiveExtensionCount();
                return 1;
            default:
                if (DEBUG) {
@@ -196,6 +207,7 @@ public class AttentionDetector {
        mWakefulness = wakefulness;
        if (wakefulness != PowerManagerInternal.WAKEFULNESS_AWAKE) {
            cancelCurrentRequestIfAny();
            resetConsecutiveExtensionCount();
        }
    }

@@ -206,6 +218,13 @@ public class AttentionDetector {
        }
    }

    private void resetConsecutiveExtensionCount() {
        final long previousCount = mConsecutiveTimeoutExtendedCount.getAndSet(0);
        if (previousCount > 0) {
            StatsLog.write(StatsLog.SCREEN_TIMEOUT_EXTENSION_REPORTED, previousCount);
        }
    }

    @VisibleForTesting
    int getRequestCode() {
        return (int) (mLastUserActivityTime % Integer.MAX_VALUE);