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

Commit f0692adb authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Android (Google) Code Review
Browse files

Merge "Ensure standby bucket of an unused app gets treated correctly." into tm-dev

parents 574ae112 23721767
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -623,7 +623,8 @@ public class AppIdleHistory {
     * @param elapsedRealtime current time
     * @param screenTimeThresholds Array of screen times, in ascending order, first one is 0
     * @param elapsedTimeThresholds Array of elapsed time, in ascending order, first one is 0
     * @return The index whose values the app's used time exceeds (in both arrays)
     * @return The index whose values the app's used time exceeds (in both arrays) or {@code -1} to
     *         indicate that the app has never been used.
     */
    int getThresholdIndex(String packageName, int userId, long elapsedRealtime,
            long[] screenTimeThresholds, long[] elapsedTimeThresholds) {
@@ -631,14 +632,13 @@ public class AppIdleHistory {
        AppUsageHistory appUsageHistory = getPackageHistory(userHistory, packageName,
                elapsedRealtime, false);
        // If we don't have any state for the app, assume never used
        if (appUsageHistory == null) return screenTimeThresholds.length - 1;

        long screenOnDelta = appUsageHistory.lastUsedScreenTime >= 0
                ? getScreenOnTime(elapsedRealtime) - appUsageHistory.lastUsedScreenTime
                : Long.MAX_VALUE;
        long elapsedDelta = appUsageHistory.lastUsedElapsedTime >= 0
                ? getElapsedTime(elapsedRealtime) - appUsageHistory.lastUsedElapsedTime
                : Long.MAX_VALUE;
        if (appUsageHistory == null || appUsageHistory.lastUsedElapsedTime < 0
                || appUsageHistory.lastUsedScreenTime < 0) {
            return -1;
        }

        long screenOnDelta = getScreenOnTime(elapsedRealtime) - appUsageHistory.lastUsedScreenTime;
        long elapsedDelta = getElapsedTime(elapsedRealtime) - appUsageHistory.lastUsedElapsedTime;

        if (DEBUG) Slog.d(TAG, packageName
                + " lastUsedScreen=" + appUsageHistory.lastUsedScreenTime
+4 −6
Original line number Diff line number Diff line
@@ -898,11 +898,9 @@ public class AppStandbyController
                    }
                }

                final long elapsedLastUsedByUserTimeDelta = app.lastUsedByUserElapsedTime >= 0
                        ? elapsedTimeAdjusted - app.lastUsedByUserElapsedTime
                        : Long.MAX_VALUE;
                if (app.lastRestrictAttemptElapsedTime > app.lastUsedByUserElapsedTime
                        && elapsedLastUsedByUserTimeDelta
                if (app.lastUsedByUserElapsedTime >= 0
                        && app.lastRestrictAttemptElapsedTime > app.lastUsedByUserElapsedTime
                        && elapsedTimeAdjusted - app.lastUsedByUserElapsedTime
                        >= mInjector.getAutoRestrictedBucketDelayMs()) {
                    newBucket = STANDBY_BUCKET_RESTRICTED;
                    reason = app.lastRestrictReason;
@@ -974,7 +972,7 @@ public class AppStandbyController
            long elapsedRealtime) {
        int bucketIndex = mAppIdleHistory.getThresholdIndex(packageName, userId,
                elapsedRealtime, mAppStandbyScreenThresholds, mAppStandbyElapsedThresholds);
        return THRESHOLD_BUCKETS[bucketIndex];
        return bucketIndex >= 0 ? THRESHOLD_BUCKETS[bucketIndex] : STANDBY_BUCKET_NEVER;
    }

    private void notifyBatteryStats(String packageName, int userId, boolean idle) {