Merge "Revert "Properly notify batterystats when packages change idleness.""
diff --git a/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java b/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java
index 258680a..13a2a94 100644
--- a/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java
+++ b/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java
@@ -965,21 +965,17 @@
Slog.d(TAG, " Checking idle state for " + packageName
+ " minBucket=" + standbyBucketToString(minBucket));
}
- final boolean previouslyIdle, stillIdle;
if (minBucket <= STANDBY_BUCKET_ACTIVE) {
// No extra processing needed for ACTIVE or higher since apps can't drop into lower
// buckets.
synchronized (mAppIdleLock) {
- previouslyIdle = mAppIdleHistory.isIdle(packageName, userId, elapsedRealtime);
mAppIdleHistory.setAppStandbyBucket(packageName, userId, elapsedRealtime,
minBucket, REASON_MAIN_DEFAULT);
- stillIdle = mAppIdleHistory.isIdle(packageName, userId, elapsedRealtime);
}
maybeInformListeners(packageName, userId, elapsedRealtime,
minBucket, REASON_MAIN_DEFAULT, false);
} else {
synchronized (mAppIdleLock) {
- previouslyIdle = mAppIdleHistory.isIdle(packageName, userId, elapsedRealtime);
final AppIdleHistory.AppUsageHistory app =
mAppIdleHistory.getAppUsageHistory(packageName,
userId, elapsedRealtime);
@@ -1077,17 +1073,11 @@
if (oldBucket != newBucket || predictionLate) {
mAppIdleHistory.setAppStandbyBucket(packageName, userId,
elapsedRealtime, newBucket, reason);
- stillIdle = mAppIdleHistory.isIdle(packageName, userId, elapsedRealtime);
maybeInformListeners(packageName, userId, elapsedRealtime,
newBucket, reason, false);
- } else {
- stillIdle = previouslyIdle;
}
}
}
- if (previouslyIdle != stillIdle) {
- notifyBatteryStats(packageName, userId, stillIdle);
- }
}
/** Returns true if there hasn't been a prediction for the app in a while. */
@@ -1244,9 +1234,8 @@
appHistory.currentBucket, reason, userStartedInteracting);
}
- final boolean stillIdle = appHistory.currentBucket >= AppIdleHistory.IDLE_BUCKET_CUTOFF;
- if (previouslyIdle != stillIdle) {
- notifyBatteryStats(pkg, userId, stillIdle);
+ if (previouslyIdle) {
+ notifyBatteryStats(pkg, userId, false);
}
}
@@ -1819,14 +1808,8 @@
reason = REASON_MAIN_FORCED_BY_SYSTEM
| (app.bucketingReason & REASON_SUB_MASK)
| (reason & REASON_SUB_MASK);
- final boolean previouslyIdle =
- app.currentBucket >= AppIdleHistory.IDLE_BUCKET_CUTOFF;
mAppIdleHistory.setAppStandbyBucket(packageName, userId, elapsedRealtime,
newBucket, reason, resetTimeout);
- final boolean stillIdle = newBucket >= AppIdleHistory.IDLE_BUCKET_CUTOFF;
- if (previouslyIdle != stillIdle) {
- notifyBatteryStats(packageName, userId, stillIdle);
- }
return;
}
@@ -1927,13 +1910,8 @@
// Make sure we don't put the app in a lower bucket than it's supposed to be in.
newBucket = Math.min(newBucket, getAppMinBucket(packageName, userId));
- final boolean previouslyIdle = app.currentBucket >= AppIdleHistory.IDLE_BUCKET_CUTOFF;
mAppIdleHistory.setAppStandbyBucket(packageName, userId, elapsedRealtime, newBucket,
reason, resetTimeout);
- final boolean stillIdle = newBucket >= AppIdleHistory.IDLE_BUCKET_CUTOFF;
- if (previouslyIdle != stillIdle) {
- notifyBatteryStats(packageName, userId, stillIdle);
- }
}
maybeInformListeners(packageName, userId, elapsedRealtime, newBucket, reason, false);
}
diff --git a/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java b/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
index 9570ff6..dcf1b35 100644
--- a/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
+++ b/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
@@ -87,7 +87,6 @@
import android.content.pm.PackageManagerInternal;
import android.content.pm.ResolveInfo;
import android.hardware.display.DisplayManager;
-import android.os.BatteryStats;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
@@ -120,7 +119,6 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
@@ -251,8 +249,6 @@
.setLong("elapsed_threshold_rare", RARE_THRESHOLD)
.setLong("elapsed_threshold_restricted", RESTRICTED_THRESHOLD);
DeviceConfig.OnPropertiesChangedListener mPropertiesChangedListener;
- String mExpectedNoteEventPackage = null;
- int mLastNoteEvent = BatteryStats.HistoryItem.EVENT_NONE;
MyInjector(Context context, Looper looper) {
super(context, looper);
@@ -324,9 +320,6 @@
@Override
void noteEvent(int event, String packageName, int uid) throws RemoteException {
- if (Objects.equals(mExpectedNoteEventPackage, packageName)) {
- mLastNoteEvent = event;
- }
}
@Override
@@ -2110,50 +2103,6 @@
assertBucket(STANDBY_BUCKET_FREQUENT, PACKAGE_BACKGROUND_LOCATION);
}
- @Test
- public void testBatteryStatsNoteEvent() throws Exception {
- mInjector.mExpectedNoteEventPackage = PACKAGE_1;
- reportEvent(mController, USER_INTERACTION, 0, PACKAGE_1);
-
- mController.setAppStandbyBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_RARE,
- REASON_MAIN_FORCED_BY_USER);
- assertEquals(BatteryStats.HistoryItem.EVENT_PACKAGE_INACTIVE, mInjector.mLastNoteEvent);
-
- mController.setAppStandbyBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_ACTIVE,
- REASON_MAIN_FORCED_BY_USER);
- assertEquals(BatteryStats.HistoryItem.EVENT_PACKAGE_ACTIVE, mInjector.mLastNoteEvent);
-
- // Since we're staying on the PACKAGE_ACTIVE side, noteEvent shouldn't be called.
- // Reset the last event to confirm the method isn't called.
- mInjector.mLastNoteEvent = BatteryStats.HistoryItem.EVENT_NONE;
- mController.setAppStandbyBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_WORKING_SET,
- REASON_MAIN_FORCED_BY_USER);
- assertEquals(BatteryStats.HistoryItem.EVENT_NONE, mInjector.mLastNoteEvent);
-
- mController.setAppStandbyBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_RARE,
- REASON_MAIN_FORCED_BY_USER);
- assertEquals(BatteryStats.HistoryItem.EVENT_PACKAGE_INACTIVE, mInjector.mLastNoteEvent);
-
- // Since we're staying on the PACKAGE_ACTIVE side, noteEvent shouldn't be called.
- // Reset the last event to confirm the method isn't called.
- mInjector.mLastNoteEvent = BatteryStats.HistoryItem.EVENT_NONE;
- mController.setAppStandbyBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_RESTRICTED,
- REASON_MAIN_FORCED_BY_USER);
- assertEquals(BatteryStats.HistoryItem.EVENT_NONE, mInjector.mLastNoteEvent);
-
- mController.setAppStandbyBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_FREQUENT,
- REASON_MAIN_FORCED_BY_USER);
- assertEquals(BatteryStats.HistoryItem.EVENT_PACKAGE_ACTIVE, mInjector.mLastNoteEvent);
-
- mController.setAppStandbyBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_RESTRICTED,
- REASON_MAIN_FORCED_BY_USER);
- assertEquals(BatteryStats.HistoryItem.EVENT_PACKAGE_INACTIVE, mInjector.mLastNoteEvent);
-
- mController.setAppStandbyBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_EXEMPTED,
- REASON_MAIN_FORCED_BY_USER);
- assertEquals(BatteryStats.HistoryItem.EVENT_PACKAGE_ACTIVE, mInjector.mLastNoteEvent);
- }
-
private String getAdminAppsStr(int userId) {
return getAdminAppsStr(userId, mController.getActiveAdminAppsForTest(userId));
}