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

Commit 918d7243 authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Make broadcast response fg threshold state configurable.

Bug: 206518114
Test: atest tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java
Change-Id: Ic28b25393b8ff7d50164535722567d1a4e34f102
parent d1e5faba
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ package com.android.server.usage;
import android.annotation.CurrentTimeMillisLong;
import android.annotation.NonNull;
import android.annotation.UserIdInt;
import android.app.ActivityManager.ProcessState;
import android.app.usage.AppStandbyInfo;
import android.app.usage.UsageStatsManager.ForcedReasons;
import android.app.usage.UsageStatsManager.StandbyBuckets;
@@ -223,4 +224,12 @@ public interface AppStandbyInternal {
     * a broadcast.
     */
    long getBroadcastResponseWindowDurationMs();

    /**
     * Returns the process state threshold that should be used for deciding whether or not an app
     * is in the background in the context of recording broadcast response stats. Apps whose
     * process state is higher than this threshold state should be considered to be in background.
     */
    @ProcessState
    int getBroadcastResponseFgThresholdState();
}
+26 −0
Original line number Diff line number Diff line
@@ -355,6 +355,14 @@ public class AppStandbyController
    volatile long mBroadcastResponseWindowDurationMillis =
            ConstantsObserver.DEFAULT_BROADCAST_RESPONSE_WINDOW_DURATION_MS;

    /**
     * Process state threshold that is used for deciding whether or not an app is in the background
     * in the context of recording broadcast response stats. Apps whose process state is higher
     * than this threshold state will be considered to be in background.
     */
    volatile int mBroadcastResponseFgThresholdState =
            ConstantsObserver.DEFAULT_BROADCAST_RESPONSE_FG_THRESHOLD_STATE;

    /**
     * Whether we should allow apps into the
     * {@link android.app.usage.UsageStatsManager#STANDBY_BUCKET_RESTRICTED} bucket or not.
@@ -1787,6 +1795,11 @@ public class AppStandbyController
        return mBroadcastResponseWindowDurationMillis;
    }

    @Override
    public int getBroadcastResponseFgThresholdState() {
        return mBroadcastResponseFgThresholdState;
    }

    @Override
    public void flushToDisk() {
        synchronized (mAppIdleLock) {
@@ -2058,6 +2071,10 @@ public class AppStandbyController
        TimeUtils.formatDuration(mBroadcastResponseWindowDurationMillis, pw);
        pw.println();

        pw.print("  mBroadcastResponseFgThresholdState=");
        pw.print(ActivityManager.procStateToString(mBroadcastResponseFgThresholdState));
        pw.println();

        pw.println();
        pw.print("mAppIdleEnabled="); pw.print(mAppIdleEnabled);
        pw.print(" mAllowRestrictedBucket=");
@@ -2491,6 +2508,8 @@ public class AppStandbyController
        };
        private static final String KEY_BROADCAST_RESPONSE_WINDOW_DURATION_MS =
                "broadcast_response_window_timeout_ms";
        private static final String KEY_BROADCAST_RESPONSE_FG_THRESHOLD_STATE =
                "broadcast_response_fg_threshold_state";
        public static final long DEFAULT_CHECK_IDLE_INTERVAL_MS =
                COMPRESS_TIME ? ONE_MINUTE : 4 * ONE_HOUR;
        public static final long DEFAULT_STRONG_USAGE_TIMEOUT =
@@ -2522,6 +2541,8 @@ public class AppStandbyController
        public static final boolean DEFAULT_CROSS_PROFILE_APPS_SHARE_STANDBY_BUCKETS = true;
        public static final long DEFAULT_BROADCAST_RESPONSE_WINDOW_DURATION_MS =
                2 * ONE_MINUTE;
        public static final int DEFAULT_BROADCAST_RESPONSE_FG_THRESHOLD_STATE =
                ActivityManager.PROCESS_STATE_TOP;

        ConstantsObserver(Handler handler) {
            super(handler);
@@ -2644,6 +2665,11 @@ public class AppStandbyController
                                    KEY_BROADCAST_RESPONSE_WINDOW_DURATION_MS,
                                    DEFAULT_BROADCAST_RESPONSE_WINDOW_DURATION_MS);
                            break;
                        case KEY_BROADCAST_RESPONSE_FG_THRESHOLD_STATE:
                            mBroadcastResponseFgThresholdState = properties.getInt(
                                    KEY_BROADCAST_RESPONSE_FG_THRESHOLD_STATE,
                                    DEFAULT_BROADCAST_RESPONSE_FG_THRESHOLD_STATE);
                            break;
                        default:
                            if (!timeThresholdsUpdated
                                    && (name.startsWith(KEY_PREFIX_SCREEN_TIME_THRESHOLD)
+1 −3
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.server.usage;

import static android.app.ActivityManager.PROCESS_STATE_TOP;
import static android.app.ActivityManager.procStateToString;

import static com.android.server.usage.UsageStatsService.DEBUG_RESPONSE_STATS;
@@ -89,8 +88,7 @@ class BroadcastResponseStatsTracker {
                    sourceUid, targetPackage, targetUser, idForResponseEvent,
                    TimeUtils.formatDuration(timestampMs), procStateToString(targetUidProcState)));
        }
        // TODO (206518114): Make the fg threshold state configurable.
        if (targetUidProcState <= PROCESS_STATE_TOP) {
        if (targetUidProcState <= mAppStandby.getBroadcastResponseFgThresholdState()) {
            // No need to track the broadcast response state while the target app is
            // in the foreground.
            return;