summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java8
-rw-r--r--apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java18
-rw-r--r--apex/jobscheduler/service/java/com/android/server/job/controllers/QuotaController.java23
-rw-r--r--apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java288
-rw-r--r--core/java/android/app/usage/UsageStatsManagerInternal.java12
-rw-r--r--core/java/android/provider/Settings.java12
-rw-r--r--core/proto/android/server/jobscheduler.proto4
-rw-r--r--services/core/java/com/android/server/AlarmManagerService.java52
-rw-r--r--services/core/java/com/android/server/AppStateTracker.java7
-rw-r--r--services/core/java/com/android/server/net/NetworkPolicyManagerService.java58
-rw-r--r--services/tests/mockingservicestests/src/com/android/server/AlarmManagerServiceTest.java20
-rw-r--r--services/tests/mockingservicestests/src/com/android/server/AppStateTrackerTest.java9
-rw-r--r--services/tests/servicestests/src/com/android/server/net/ConnOnActivityStartTest.java33
-rw-r--r--services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java211
-rw-r--r--services/usage/java/com/android/server/usage/UsageStatsService.java15
15 files changed, 80 insertions, 690 deletions
diff --git a/apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java b/apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java
index 3cfb08082ff7..c036c772d7d0 100644
--- a/apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java
+++ b/apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java
@@ -35,8 +35,6 @@ public interface AppStandbyInternal {
void onBootPhase(int phase);
- boolean isParoledOrCharging();
-
void postCheckIdleStates(int userId);
/**
@@ -59,13 +57,15 @@ public interface AppStandbyInternal {
int getAppId(String packageName);
- boolean isAppIdleFilteredOrParoled(String packageName, int userId, long elapsedRealtime,
+ /**
+ * @see #isAppIdleFiltered(String, int, int, long)
+ */
+ boolean isAppIdleFiltered(String packageName, int userId, long elapsedRealtime,
boolean shouldObfuscateInstantApps);
/**
* Checks if an app has been idle for a while and filters out apps that are excluded.
* It returns false if the current system state allows all apps to be considered active.
- * This happens if the device is plugged in or temporarily allowed to make exceptions.
* Called by interface impls.
*/
boolean isAppIdleFiltered(String packageName, int appId, int userId,
diff --git a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java
index 14d5a683ce83..c3ffad66d829 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/JobSchedulerService.java
@@ -266,11 +266,6 @@ public class JobSchedulerService extends com.android.server.SystemService
boolean mReportedActive;
/**
- * Are we currently in device-wide standby parole?
- */
- volatile boolean mInParole;
-
- /**
* A mapping of which uids are currently in the foreground to their effective priority.
*/
final SparseIntArray mUidPriorityOverride = new SparseIntArray();
@@ -2361,14 +2356,6 @@ public class JobSchedulerService extends com.android.server.SystemService
}
@Override
- public void onParoleStateChanged(boolean isParoleOn) {
- if (DEBUG_STANDBY) {
- Slog.i(TAG, "Global parole state now " + (isParoleOn ? "ON" : "OFF"));
- }
- mInParole = isParoleOn;
- }
-
- @Override
public void onUserInteractionStarted(String packageName, int userId) {
final int uid = mLocalPM.getPackageUid(packageName,
PackageManager.MATCH_UNINSTALLED_PACKAGES, userId);
@@ -3031,10 +3018,6 @@ public class JobSchedulerService extends com.android.server.SystemService
}
pw.println();
- pw.print(" In parole?: ");
- pw.print(mInParole);
- pw.println();
-
for (int i = mJobRestrictions.size() - 1; i >= 0; i--) {
pw.print(" ");
mJobRestrictions.get(i).dumpConstants(pw);
@@ -3222,7 +3205,6 @@ public class JobSchedulerService extends com.android.server.SystemService
}
proto.end(settingsToken);
- proto.write(JobSchedulerServiceDumpProto.IN_PAROLE, mInParole);
for (int i = mJobRestrictions.size() - 1; i >= 0; i--) {
mJobRestrictions.get(i).dumpConstants(proto);
}
diff --git a/apex/jobscheduler/service/java/com/android/server/job/controllers/QuotaController.java b/apex/jobscheduler/service/java/com/android/server/job/controllers/QuotaController.java
index 400d90203453..14dce84e686a 100644
--- a/apex/jobscheduler/service/java/com/android/server/job/controllers/QuotaController.java
+++ b/apex/jobscheduler/service/java/com/android/server/job/controllers/QuotaController.java
@@ -414,8 +414,6 @@ public final class QuotaController extends StateController {
private final Handler mHandler;
private final QcConstants mQcConstants;
- private volatile boolean mInParole;
-
/** How much time each app will have to run jobs within their standby bucket window. */
private long mAllowedTimePerPeriodMs = QcConstants.DEFAULT_ALLOWED_TIME_PER_PERIOD_MS;
@@ -711,7 +709,6 @@ public final class QuotaController extends StateController {
public long getMaxJobExecutionTimeMsLocked(@NonNull final JobStatus jobStatus) {
// If quota is currently "free", then the job can run for the full amount of time.
if (mChargeTracker.isCharging()
- || mInParole
|| isTopStartedJobLocked(jobStatus)
|| isUidInForeground(jobStatus.getSourceUid())) {
return JobServiceContext.EXECUTING_TIMESLICE_MILLIS;
@@ -737,8 +734,8 @@ public final class QuotaController extends StateController {
final int standbyBucket) {
if (standbyBucket == NEVER_INDEX) return false;
- // Quota constraint is not enforced while charging or when parole is on.
- if (mChargeTracker.isCharging() || mInParole) {
+ // Quota constraint is not enforced while charging.
+ if (mChargeTracker.isCharging()) {
return true;
}
@@ -1780,20 +1777,6 @@ public final class QuotaController extends StateController {
}
});
}
-
- @Override
- public void onParoleStateChanged(final boolean isParoleOn) {
- mInParole = isParoleOn;
- if (DEBUG) {
- Slog.i(TAG, "Global parole state now " + (isParoleOn ? "ON" : "OFF"));
- }
- // Update job bookkeeping out of band.
- BackgroundThread.getHandler().post(() -> {
- synchronized (mLock) {
- maybeUpdateAllConstraintsLocked();
- }
- });
- }
}
private final class DeleteTimingSessionsFunctor implements Consumer<List<TimingSession>> {
@@ -2515,7 +2498,6 @@ public final class QuotaController extends StateController {
public void dumpControllerStateLocked(final IndentingPrintWriter pw,
final Predicate<JobStatus> predicate) {
pw.println("Is charging: " + mChargeTracker.isCharging());
- pw.println("In parole: " + mInParole);
pw.println("Current elapsed time: " + sElapsedRealtimeClock.millis());
pw.println();
@@ -2639,7 +2621,6 @@ public final class QuotaController extends StateController {
final long mToken = proto.start(StateControllerProto.QUOTA);
proto.write(StateControllerProto.QuotaController.IS_CHARGING, mChargeTracker.isCharging());
- proto.write(StateControllerProto.QuotaController.IS_IN_PAROLE, mInParole);
proto.write(StateControllerProto.QuotaController.ELAPSED_REALTIME,
sElapsedRealtimeClock.millis());
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 7c472a9813aa..ecc045995521 100644
--- a/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java
+++ b/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java
@@ -45,7 +45,6 @@ import static android.app.usage.UsageStatsManager.STANDBY_BUCKET_NEVER;
import static android.app.usage.UsageStatsManager.STANDBY_BUCKET_RARE;
import static android.app.usage.UsageStatsManager.STANDBY_BUCKET_WORKING_SET;
-import static com.android.server.SystemService.PHASE_BOOT_COMPLETED;
import static com.android.server.SystemService.PHASE_SYSTEM_SERVICES_READY;
import android.annotation.UserIdInt;
@@ -70,10 +69,8 @@ import android.database.ContentObserver;
import android.hardware.display.DisplayManager;
import android.net.ConnectivityManager;
import android.net.Network;
-import android.net.NetworkInfo;
import android.net.NetworkRequest;
import android.net.NetworkScoreManager;
-import android.os.BatteryManager;
import android.os.BatteryStats;
import android.os.Environment;
import android.os.Handler;
@@ -192,21 +189,14 @@ public class AppStandbyController implements AppStandbyInternal {
static final int MSG_INFORM_LISTENERS = 3;
static final int MSG_FORCE_IDLE_STATE = 4;
static final int MSG_CHECK_IDLE_STATES = 5;
- static final int MSG_CHECK_PAROLE_TIMEOUT = 6;
- static final int MSG_PAROLE_END_TIMEOUT = 7;
static final int MSG_REPORT_CONTENT_PROVIDER_USAGE = 8;
- static final int MSG_PAROLE_STATE_CHANGED = 9;
static final int MSG_ONE_TIME_CHECK_IDLE_STATES = 10;
/** Check the state of one app: arg1 = userId, arg2 = uid, obj = (String) packageName */
static final int MSG_CHECK_PACKAGE_IDLE_STATE = 11;
static final int MSG_REPORT_SYNC_SCHEDULED = 12;
static final int MSG_REPORT_EXEMPTED_SYNC_START = 13;
- static final int MSG_UPDATE_STABLE_CHARGING= 14;
long mCheckIdleIntervalMillis;
- long mAppIdleParoleIntervalMillis;
- long mAppIdleParoleWindowMillis;
- long mAppIdleParoleDurationMillis;
long[] mAppStandbyScreenThresholds = SCREEN_TIME_THRESHOLDS;
long[] mAppStandbyElapsedThresholds = ELAPSED_TIME_THRESHOLDS;
/** Minimum time a strong usage event should keep the bucket elevated. */
@@ -244,20 +234,12 @@ public class AppStandbyController implements AppStandbyInternal {
* start is the first usage of the app
*/
long mInitialForegroundServiceStartTimeoutMillis;
- /** The length of time phone must be charging before considered stable enough to run jobs */
- long mStableChargingThresholdMillis;
private volatile boolean mAppIdleEnabled;
- boolean mAppIdleTempParoled;
- boolean mCharging;
- boolean mChargingStable;
- private long mLastAppIdleParoledTime;
private boolean mSystemServicesReady = false;
// There was a system update, defaults need to be initialized after services are ready
private boolean mPendingInitializeDefaults;
- private final DeviceStateReceiver mDeviceStateReceiver;
-
private volatile boolean mPendingOneTimeCheckIdleStates;
private final AppStandbyHandler mHandler;
@@ -267,7 +249,6 @@ public class AppStandbyController implements AppStandbyInternal {
private AppWidgetManager mAppWidgetManager;
private ConnectivityManager mConnectivityManager;
- private PowerManager mPowerManager;
private PackageManager mPackageManager;
Injector mInjector;
@@ -329,12 +310,6 @@ public class AppStandbyController implements AppStandbyInternal {
mContext = mInjector.getContext();
mHandler = new AppStandbyHandler(mInjector.getLooper());
mPackageManager = mContext.getPackageManager();
- mDeviceStateReceiver = new DeviceStateReceiver();
-
- IntentFilter deviceStates = new IntentFilter(BatteryManager.ACTION_CHARGING);
- deviceStates.addAction(BatteryManager.ACTION_DISCHARGING);
- deviceStates.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
- mContext.registerReceiver(mDeviceStateReceiver, deviceStates);
synchronized (mAppIdleLock) {
mAppIdleHistory = new AppIdleHistory(mInjector.getDataSystemDirectory(),
@@ -353,15 +328,7 @@ public class AppStandbyController implements AppStandbyInternal {
@VisibleForTesting
void setAppIdleEnabled(boolean enabled) {
- synchronized (mAppIdleLock) {
- if (mAppIdleEnabled != enabled) {
- final boolean oldParoleState = isParoledOrCharging();
- mAppIdleEnabled = enabled;
- if (isParoledOrCharging() != oldParoleState) {
- postParoleStateChanged();
- }
- }
- }
+ mAppIdleEnabled = enabled;
}
@Override
@@ -381,7 +348,6 @@ public class AppStandbyController implements AppStandbyInternal {
mAppWidgetManager = mContext.getSystemService(AppWidgetManager.class);
mConnectivityManager = mContext.getSystemService(ConnectivityManager.class);
- mPowerManager = mContext.getSystemService(PowerManager.class);
mInjector.registerDisplayListener(mDisplayListener, mHandler);
synchronized (mAppIdleLock) {
@@ -402,8 +368,6 @@ public class AppStandbyController implements AppStandbyInternal {
if (mPendingOneTimeCheckIdleStates) {
postOneTimeCheckIdleStates();
}
- } else if (phase == PHASE_BOOT_COMPLETED) {
- setChargingState(mInjector.isCharging());
}
}
@@ -504,93 +468,6 @@ public class AppStandbyController implements AppStandbyInternal {
}
}
- @VisibleForTesting
- void setChargingState(boolean charging) {
- synchronized (mAppIdleLock) {
- if (mCharging != charging) {
- mCharging = charging;
- if (DEBUG) Slog.d(TAG, "Setting mCharging to " + charging);
- if (charging) {
- if (DEBUG) {
- Slog.d(TAG, "Scheduling MSG_UPDATE_STABLE_CHARGING delay = "
- + mStableChargingThresholdMillis);
- }
- mHandler.sendEmptyMessageDelayed(MSG_UPDATE_STABLE_CHARGING,
- mStableChargingThresholdMillis);
- } else {
- mHandler.removeMessages(MSG_UPDATE_STABLE_CHARGING);
- updateChargingStableState();
- }
- }
- }
- }
-
- private void updateChargingStableState() {
- synchronized (mAppIdleLock) {
- if (mChargingStable != mCharging) {
- if (DEBUG) Slog.d(TAG, "Setting mChargingStable to " + mCharging);
- mChargingStable = mCharging;
- postParoleStateChanged();
- }
- }
- }
-
- private void setAppIdleParoled(boolean paroled) {
- synchronized (mAppIdleLock) {
- final long now = mInjector.currentTimeMillis();
- if (mAppIdleTempParoled != paroled) {
- mAppIdleTempParoled = paroled;
- if (DEBUG) Slog.d(TAG, "Changing paroled to " + mAppIdleTempParoled);
- if (paroled) {
- postParoleEndTimeout();
- } else {
- mLastAppIdleParoledTime = now;
- postNextParoleTimeout(now, false);
- }
- postParoleStateChanged();
- }
- }
- }
-
- @Override
- public boolean isParoledOrCharging() {
- if (!mAppIdleEnabled) return true;
- synchronized (mAppIdleLock) {
- // Only consider stable charging when determining charge state.
- return mAppIdleTempParoled || mChargingStable;
- }
- }
-
- private void postNextParoleTimeout(long now, boolean forced) {
- if (DEBUG) Slog.d(TAG, "Posting MSG_CHECK_PAROLE_TIMEOUT");
- mHandler.removeMessages(MSG_CHECK_PAROLE_TIMEOUT);
- // Compute when the next parole needs to happen. We check more frequently than necessary
- // since the message handler delays are based on elapsedRealTime and not wallclock time.
- // The comparison is done in wallclock time.
- long timeLeft = (mLastAppIdleParoledTime + mAppIdleParoleIntervalMillis) - now;
- if (forced) {
- // Set next timeout for the end of the parole window
- // If parole is not set by the end of the window it will be forced
- timeLeft += mAppIdleParoleWindowMillis;
- }
- if (timeLeft < 0) {
- timeLeft = 0;
- }
- mHandler.sendEmptyMessageDelayed(MSG_CHECK_PAROLE_TIMEOUT, timeLeft);
- }
-
- private void postParoleEndTimeout() {
- if (DEBUG) Slog.d(TAG, "Posting MSG_PAROLE_END_TIMEOUT");
- mHandler.removeMessages(MSG_PAROLE_END_TIMEOUT);
- mHandler.sendEmptyMessageDelayed(MSG_PAROLE_END_TIMEOUT, mAppIdleParoleDurationMillis);
- }
-
- private void postParoleStateChanged() {
- if (DEBUG) Slog.d(TAG, "Posting MSG_PAROLE_STATE_CHANGED");
- mHandler.removeMessages(MSG_PAROLE_STATE_CHANGED);
- mHandler.sendEmptyMessage(MSG_PAROLE_STATE_CHANGED);
- }
-
@Override
public void postCheckIdleStates(int userId) {
mHandler.sendMessage(mHandler.obtainMessage(MSG_CHECK_IDLE_STATES, userId, 0));
@@ -787,48 +664,6 @@ public class AppStandbyController implements AppStandbyInternal {
return THRESHOLD_BUCKETS[bucketIndex];
}
- private void checkParoleTimeout() {
- boolean setParoled = false;
- boolean waitForNetwork = false;
- NetworkInfo activeNetwork = mConnectivityManager.getActiveNetworkInfo();
- boolean networkActive = activeNetwork != null &&
- activeNetwork.isConnected();
-
- synchronized (mAppIdleLock) {
- final long now = mInjector.currentTimeMillis();
- if (!mAppIdleTempParoled) {
- final long timeSinceLastParole = now - mLastAppIdleParoledTime;
- if (timeSinceLastParole > mAppIdleParoleIntervalMillis) {
- if (DEBUG) Slog.d(TAG, "Crossed default parole interval");
- if (networkActive) {
- // If network is active set parole
- setParoled = true;
- } else {
- if (timeSinceLastParole
- > mAppIdleParoleIntervalMillis + mAppIdleParoleWindowMillis) {
- if (DEBUG) Slog.d(TAG, "Crossed end of parole window, force parole");
- setParoled = true;
- } else {
- if (DEBUG) Slog.d(TAG, "Network unavailable, delaying parole");
- waitForNetwork = true;
- postNextParoleTimeout(now, true);
- }
- }
- } else {
- if (DEBUG) Slog.d(TAG, "Not long enough to go to parole");
- postNextParoleTimeout(now, false);
- }
- }
- }
- if (waitForNetwork) {
- mConnectivityManager.registerNetworkCallback(mNetworkRequest, mNetworkCallback);
- }
- if (setParoled) {
- // Set parole if network is available
- setAppIdleParoled(true);
- }
- }
-
private void notifyBatteryStats(String packageName, int userId, boolean idle) {
try {
final int uid = mPackageManager.getPackageUidAsUser(packageName,
@@ -844,30 +679,6 @@ public class AppStandbyController implements AppStandbyInternal {
}
}
- private void onDeviceIdleModeChanged() {
- final boolean deviceIdle = mPowerManager.isDeviceIdleMode();
- if (DEBUG) Slog.i(TAG, "DeviceIdleMode changed to " + deviceIdle);
- boolean paroled = false;
- synchronized (mAppIdleLock) {
- final long timeSinceLastParole =
- mInjector.currentTimeMillis() - mLastAppIdleParoledTime;
- if (!deviceIdle
- && timeSinceLastParole >= mAppIdleParoleIntervalMillis) {
- if (DEBUG) {
- Slog.i(TAG,
- "Bringing idle apps out of inactive state due to deviceIdleMode=false");
- }
- paroled = true;
- } else if (deviceIdle) {
- if (DEBUG) Slog.i(TAG, "Device idle, back to prison");
- paroled = false;
- } else {
- return;
- }
- }
- setAppIdleParoled(paroled);
- }
-
@Override
public void reportEvent(UsageEvents.Event event, long elapsedRealtime, int userId) {
if (!mAppIdleEnabled) return;
@@ -1038,11 +849,8 @@ public class AppStandbyController implements AppStandbyInternal {
}
@Override
- public boolean isAppIdleFilteredOrParoled(String packageName, int userId, long elapsedRealtime,
+ public boolean isAppIdleFiltered(String packageName, int userId, long elapsedRealtime,
boolean shouldObfuscateInstantApps) {
- if (isParoledOrCharging()) {
- return false;
- }
if (shouldObfuscateInstantApps &&
mInjector.isPackageEphemeral(userId, packageName)) {
return false;
@@ -1388,15 +1196,6 @@ public class AppStandbyController implements AppStandbyInternal {
}
}
- private void informParoleStateChanged() {
- final boolean paroled = isParoledOrCharging();
- synchronized (mPackageAccessListeners) {
- for (AppIdleStateChangeListener listener : mPackageAccessListeners) {
- listener.onParoleStateChanged(paroled);
- }
- }
- }
-
@Override
public void flushToDisk(int userId) {
synchronized (mAppIdleLock) {
@@ -1517,18 +1316,6 @@ public class AppStandbyController implements AppStandbyInternal {
TimeUtils.formatDuration(mCheckIdleIntervalMillis, pw);
pw.println();
- pw.print(" mAppIdleParoleIntervalMillis=");
- TimeUtils.formatDuration(mAppIdleParoleIntervalMillis, pw);
- pw.println();
-
- pw.print(" mAppIdleParoleWindowMillis=");
- TimeUtils.formatDuration(mAppIdleParoleWindowMillis, pw);
- pw.println();
-
- pw.print(" mAppIdleParoleDurationMillis=");
- TimeUtils.formatDuration(mAppIdleParoleDurationMillis, pw);
- pw.println();
-
pw.print(" mStrongUsageTimeoutMillis=");
TimeUtils.formatDuration(mStrongUsageTimeoutMillis, pw);
pw.println();
@@ -1566,22 +1353,11 @@ public class AppStandbyController implements AppStandbyInternal {
TimeUtils.formatDuration(mSystemUpdateUsageTimeoutMillis, pw);
pw.println();
- pw.print(" mStableChargingThresholdMillis=");
- TimeUtils.formatDuration(mStableChargingThresholdMillis, pw);
- pw.println();
-
pw.println();
pw.print("mAppIdleEnabled="); pw.print(mAppIdleEnabled);
- pw.print(" mAppIdleTempParoled="); pw.print(mAppIdleTempParoled);
- pw.print(" mCharging="); pw.print(mCharging);
- pw.print(" mChargingStable="); pw.print(mChargingStable);
- pw.print(" mLastAppIdleParoledTime=");
- TimeUtils.formatDuration(now - mLastAppIdleParoledTime, pw);
pw.println();
pw.print("mScreenThresholds="); pw.println(Arrays.toString(mAppStandbyScreenThresholds));
pw.print("mElapsedThresholds="); pw.println(Arrays.toString(mAppStandbyElapsedThresholds));
- pw.print("mStableChargingThresholdMillis=");
- TimeUtils.formatDuration(mStableChargingThresholdMillis, pw);
pw.println();
}
@@ -1655,10 +1431,6 @@ public class AppStandbyController implements AppStandbyInternal {
return buildFlag && runtimeFlag;
}
- boolean isCharging() {
- return mContext.getSystemService(BatteryManager.class).isCharging();
- }
-
boolean isPowerSaveWhitelistExceptIdleApp(String packageName) throws RemoteException {
return mDeviceIdleController.isPowerSaveWhitelistExceptIdleApp(packageName);
}
@@ -1748,15 +1520,6 @@ public class AppStandbyController implements AppStandbyInternal {
checkIdleStates(UserHandle.USER_ALL);
break;
- case MSG_CHECK_PAROLE_TIMEOUT:
- checkParoleTimeout();
- break;
-
- case MSG_PAROLE_END_TIMEOUT:
- if (DEBUG) Slog.d(TAG, "Ending parole");
- setAppIdleParoled(false);
- break;
-
case MSG_REPORT_CONTENT_PROVIDER_USAGE:
SomeArgs args = (SomeArgs) msg.obj;
reportContentProviderUsage((String) args.arg1, // authority name
@@ -1765,11 +1528,6 @@ public class AppStandbyController implements AppStandbyInternal {
args.recycle();
break;
- case MSG_PAROLE_STATE_CHANGED:
- if (DEBUG) Slog.d(TAG, "Parole state: " + mAppIdleTempParoled
- + ", Charging state:" + mChargingStable);
- informParoleStateChanged();
- break;
case MSG_CHECK_PACKAGE_IDLE_STATE:
checkAndUpdateStandbyState((String) msg.obj, msg.arg1, msg.arg2,
mInjector.elapsedRealtime());
@@ -1788,10 +1546,6 @@ public class AppStandbyController implements AppStandbyInternal {
reportExemptedSyncStart((String) msg.obj, msg.arg1);
break;
- case MSG_UPDATE_STABLE_CHARGING:
- updateChargingStableState();
- break;
-
default:
super.handleMessage(msg);
break;
@@ -1800,23 +1554,6 @@ public class AppStandbyController implements AppStandbyInternal {
}
};
- private class DeviceStateReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- switch (intent.getAction()) {
- case BatteryManager.ACTION_CHARGING:
- setChargingState(true);
- break;
- case BatteryManager.ACTION_DISCHARGING:
- setChargingState(false);
- break;
- case PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED:
- onDeviceIdleModeChanged();
- break;
- }
- }
- }
-
private final NetworkRequest mNetworkRequest = new NetworkRequest.Builder().build();
private final ConnectivityManager.NetworkCallback mNetworkCallback
@@ -1824,7 +1561,6 @@ public class AppStandbyController implements AppStandbyInternal {
@Override
public void onAvailable(Network network) {
mConnectivityManager.unregisterNetworkCallback(this);
- checkParoleTimeout();
}
};
@@ -1851,9 +1587,6 @@ public class AppStandbyController implements AppStandbyInternal {
* Observe settings changes for {@link Global#APP_IDLE_CONSTANTS}.
*/
private class SettingsObserver extends ContentObserver {
- private static final String KEY_PAROLE_INTERVAL = "parole_interval";
- private static final String KEY_PAROLE_WINDOW = "parole_window";
- private static final String KEY_PAROLE_DURATION = "parole_duration";
private static final String KEY_SCREEN_TIME_THRESHOLDS = "screen_thresholds";
private static final String KEY_ELAPSED_TIME_THRESHOLDS = "elapsed_thresholds";
private static final String KEY_STRONG_USAGE_HOLD_DURATION = "strong_usage_duration";
@@ -1875,7 +1608,6 @@ public class AppStandbyController implements AppStandbyInternal {
"system_interaction_duration";
private static final String KEY_INITIAL_FOREGROUND_SERVICE_START_HOLD_DURATION =
"initial_foreground_service_start_duration";
- private static final String KEY_STABLE_CHARGING_THRESHOLD = "stable_charging_threshold";
public static final long DEFAULT_STRONG_USAGE_TIMEOUT = 1 * ONE_HOUR;
public static final long DEFAULT_NOTIFICATION_TIMEOUT = 12 * ONE_HOUR;
public static final long DEFAULT_SYSTEM_UPDATE_TIMEOUT = 2 * ONE_HOUR;
@@ -1885,7 +1617,6 @@ public class AppStandbyController implements AppStandbyInternal {
public static final long DEFAULT_EXEMPTED_SYNC_SCHEDULED_DOZE_TIMEOUT = 4 * ONE_HOUR;
public static final long DEFAULT_EXEMPTED_SYNC_START_TIMEOUT = 10 * ONE_MINUTE;
public static final long DEFAULT_UNEXEMPTED_SYNC_SCHEDULED_TIMEOUT = 10 * ONE_MINUTE;
- public static final long DEFAULT_STABLE_CHARGING_THRESHOLD = 10 * ONE_MINUTE;
public static final long DEFAULT_INITIAL_FOREGROUND_SERVICE_START_TIMEOUT = 30 * ONE_MINUTE;
private final KeyValueListParser mParser = new KeyValueListParser(',');
@@ -1932,17 +1663,6 @@ public class AppStandbyController implements AppStandbyInternal {
synchronized (mAppIdleLock) {
- // Default: 24 hours between paroles
- mAppIdleParoleIntervalMillis = mParser.getDurationMillis(KEY_PAROLE_INTERVAL,
- COMPRESS_TIME ? ONE_MINUTE * 10 : 24 * 60 * ONE_MINUTE);
-
- // Default: 2 hours to wait on network
- mAppIdleParoleWindowMillis = mParser.getDurationMillis(KEY_PAROLE_WINDOW,
- COMPRESS_TIME ? ONE_MINUTE * 2 : 2 * 60 * ONE_MINUTE);
-
- mAppIdleParoleDurationMillis = mParser.getDurationMillis(KEY_PAROLE_DURATION,
- COMPRESS_TIME ? ONE_MINUTE : 10 * ONE_MINUTE); // 10 minutes
-
String screenThresholdsValue = mParser.getString(KEY_SCREEN_TIME_THRESHOLDS, null);
mAppStandbyScreenThresholds = parseLongArray(screenThresholdsValue,
SCREEN_TIME_THRESHOLDS);
@@ -1997,10 +1717,6 @@ public class AppStandbyController implements AppStandbyInternal {
KEY_INITIAL_FOREGROUND_SERVICE_START_HOLD_DURATION,
COMPRESS_TIME ? ONE_MINUTE :
DEFAULT_INITIAL_FOREGROUND_SERVICE_START_TIMEOUT);
-
- mStableChargingThresholdMillis = mParser.getDurationMillis(
- KEY_STABLE_CHARGING_THRESHOLD,
- COMPRESS_TIME ? ONE_MINUTE : DEFAULT_STABLE_CHARGING_THRESHOLD);
}
// Check if app_idle_enabled has changed. Do this after getting the rest of the settings
diff --git a/core/java/android/app/usage/UsageStatsManagerInternal.java b/core/java/android/app/usage/UsageStatsManagerInternal.java
index b3260c4c5cce..024afe25f98e 100644
--- a/core/java/android/app/usage/UsageStatsManagerInternal.java
+++ b/core/java/android/app/usage/UsageStatsManagerInternal.java
@@ -154,12 +154,6 @@ public abstract class UsageStatsManagerInternal {
public abstract int[] getIdleUidsForUser(@UserIdInt int userId);
/**
- * @return True if currently app idle parole mode is on. This means all idle apps are allow to
- * run for a short period of time.
- */
- public abstract boolean isAppIdleParoleOn();
-
- /**
* Sets up a listener for changes to packages being accessed.
* @param listener A listener within the system process.
*/
@@ -180,12 +174,6 @@ public abstract class UsageStatsManagerInternal {
boolean idle, int bucket, int reason);
/**
- * Callback to inform listeners that the parole state has changed. This means apps are
- * allowed to do work even if they're idle or in a low bucket.
- */
- public abstract void onParoleStateChanged(boolean isParoleOn);
-
- /**
* Optional callback to inform the listener that the app has transitioned into
* an active state due to user interaction.
*/
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 065ee0bd97e3..800c15c18143 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -10863,16 +10863,13 @@ public final class Settings {
* App standby (app idle) specific settings.
* This is encoded as a key=value list, separated by commas. Ex:
* <p>
- * "idle_duration=5000,parole_interval=4500,screen_thresholds=0/0/60000/120000"
+ * "idle_duration=5000,prediction_timeout=4500,screen_thresholds=0/0/60000/120000"
* <p>
* All durations are in millis.
* Array values are separated by forward slashes
* The following keys are supported:
*
* <pre>
- * parole_interval (long)
- * parole_window (long)
- * parole_duration (long)
* screen_thresholds (long[4])
* elapsed_thresholds (long[4])
* strong_usage_duration (long)
@@ -10883,17 +10880,12 @@ public final class Settings {
* exempted_sync_duration (long)
* system_interaction_duration (long)
* initial_foreground_service_start_duration (long)
- * stable_charging_threshold (long)
- *
- * idle_duration (long) // This is deprecated and used to circumvent b/26355386.
- * idle_duration2 (long) // deprecated
- * wallclock_threshold (long) // deprecated
* </pre>
*
* <p>
* Type: string
* @hide
- * @see com.android.server.usage.UsageStatsService.SettingsObserver
+ * @see com.android.server.usage.AppStandbyController
*/
public static final String APP_IDLE_CONSTANTS = "app_idle_constants";
diff --git a/core/proto/android/server/jobscheduler.proto b/core/proto/android/server/jobscheduler.proto
index 15b98af8e1f3..06040a599df1 100644
--- a/core/proto/android/server/jobscheduler.proto
+++ b/core/proto/android/server/jobscheduler.proto
@@ -43,7 +43,7 @@ message JobSchedulerServiceDumpProto {
reserved 15; // next_heartbeat
reserved 16; // last_heartbeat_time_millis
reserved 17; // next_heartbeat_time_millis
- optional bool in_parole = 18;
+ reserved 18; // in_parole
optional bool in_thermal = 19;
repeated int32 started_users = 2;
@@ -534,7 +534,7 @@ message StateControllerProto {
option (.android.msg_privacy).dest = DEST_AUTOMATIC;
optional bool is_charging = 1;
- optional bool is_in_parole = 2;
+ reserved 2; // is_in_parole
optional int64 elapsed_realtime = 6;
// List of UIDs currently in the foreground.
diff --git a/services/core/java/com/android/server/AlarmManagerService.java b/services/core/java/com/android/server/AlarmManagerService.java
index 9a97ddb3e3a7..b41e95fee15c 100644
--- a/services/core/java/com/android/server/AlarmManagerService.java
+++ b/services/core/java/com/android/server/AlarmManagerService.java
@@ -47,6 +47,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PermissionInfo;
import android.database.ContentObserver;
import android.net.Uri;
+import android.os.BatteryManager;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
@@ -1564,6 +1565,7 @@ class AlarmManagerService extends SystemService {
Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT, UserHandle.ALL);
mClockReceiver = mInjector.getClockReceiver(this);
+ new ChargingReceiver();
new InteractiveStateReceiver();
new UninstallReceiver();
@@ -4148,7 +4150,7 @@ class AlarmManagerService extends SystemService {
public static final int LISTENER_TIMEOUT = 3;
public static final int REPORT_ALARMS_ACTIVE = 4;
public static final int APP_STANDBY_BUCKET_CHANGED = 5;
- public static final int APP_STANDBY_PAROLE_CHANGED = 6;
+ public static final int CHARGING_STATUS_CHANGED = 6;
public static final int REMOVE_FOR_STOPPED = 7;
public static final int UNREGISTER_CANCEL_LISTENER = 8;
@@ -4206,7 +4208,7 @@ class AlarmManagerService extends SystemService {
}
break;
- case APP_STANDBY_PAROLE_CHANGED:
+ case CHARGING_STATUS_CHANGED:
synchronized (mLock) {
mAppStandbyParole = (Boolean) msg.obj;
if (reorderAlarmsBasedOnStandbyBuckets(null)) {
@@ -4247,6 +4249,37 @@ class AlarmManagerService extends SystemService {
}
}
+ @VisibleForTesting
+ class ChargingReceiver extends BroadcastReceiver {
+ ChargingReceiver() {
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(BatteryManager.ACTION_CHARGING);
+ filter.addAction(BatteryManager.ACTION_DISCHARGING);
+ getContext().registerReceiver(this, filter);
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ final String action = intent.getAction();
+ final boolean charging;
+ if (BatteryManager.ACTION_CHARGING.equals(action)) {
+ if (DEBUG_STANDBY) {
+ Slog.d(TAG, "Device is charging.");
+ }
+ charging = true;
+ } else {
+ if (DEBUG_STANDBY) {
+ Slog.d(TAG, "Disconnected from power.");
+ }
+ charging = false;
+ }
+ mHandler.removeMessages(AlarmHandler.CHARGING_STATUS_CHANGED);
+ mHandler.obtainMessage(AlarmHandler.CHARGING_STATUS_CHANGED, charging)
+ .sendToTarget();
+ }
+ }
+
+ @VisibleForTesting
class ClockReceiver extends BroadcastReceiver {
public ClockReceiver() {
IntentFilter filter = new IntentFilter();
@@ -4429,7 +4462,7 @@ class AlarmManagerService extends SystemService {
@Override public void onUidCachedChanged(int uid, boolean cached) {
}
- };
+ }
/**
* Tracking of app assignments to standby buckets
@@ -4447,18 +4480,7 @@ class AlarmManagerService extends SystemService {
mHandler.obtainMessage(AlarmHandler.APP_STANDBY_BUCKET_CHANGED, userId, -1, packageName)
.sendToTarget();
}
-
- @Override
- public void onParoleStateChanged(boolean isParoleOn) {
- if (DEBUG_STANDBY) {
- Slog.d(TAG, "Global parole state now " + (isParoleOn ? "ON" : "OFF"));
- }
- mHandler.removeMessages(AlarmHandler.APP_STANDBY_BUCKET_CHANGED);
- mHandler.removeMessages(AlarmHandler.APP_STANDBY_PAROLE_CHANGED);
- mHandler.obtainMessage(AlarmHandler.APP_STANDBY_PAROLE_CHANGED,
- Boolean.valueOf(isParoleOn)).sendToTarget();
- }
- };
+ }
private final Listener mForceAppStandbyListener = new Listener() {
@Override
diff --git a/services/core/java/com/android/server/AppStateTracker.java b/services/core/java/com/android/server/AppStateTracker.java
index 2c67c5046c6d..da760b6f7ffd 100644
--- a/services/core/java/com/android/server/AppStateTracker.java
+++ b/services/core/java/com/android/server/AppStateTracker.java
@@ -71,8 +71,7 @@ import java.util.List;
* - Temporary power save whitelist
* - Global "force all apps standby" mode enforced by battery saver.
*
- * Test:
- atest $ANDROID_BUILD_TOP/frameworks/base/services/tests/servicestests/src/com/android/server/AppStateTrackerTest.java
+ * Test: atest com.android.server.AppStateTrackerTest
*/
public class AppStateTracker {
private static final String TAG = "AppStateTracker";
@@ -710,10 +709,6 @@ public class AppStateTracker {
mHandler.notifyExemptChanged();
}
}
-
- @Override
- public void onParoleStateChanged(boolean isParoleOn) {
- }
}
private Listener[] cloneListeners() {
diff --git a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
index 812ce32a6030..09be474a5598 100644
--- a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
+++ b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
@@ -797,6 +797,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
writePolicyAL();
}
+ enableFirewallChainUL(FIREWALL_CHAIN_STANDBY, true);
setRestrictBackgroundUL(mLoadedRestrictBackground);
updateRulesForGlobalChangeAL(false);
updateNotificationsNL();
@@ -3830,39 +3831,6 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
}
/**
- * Toggle the firewall standby chain and inform listeners if the uid rules have effectively
- * changed.
- */
- @GuardedBy("mUidRulesFirstLock")
- void updateRulesForAppIdleParoleUL() {
- boolean paroled = mUsageStats.isAppIdleParoleOn();
- boolean enableChain = !paroled;
- enableFirewallChainUL(FIREWALL_CHAIN_STANDBY, enableChain);
-
- int ruleCount = mUidFirewallStandbyRules.size();
- for (int i = 0; i < ruleCount; i++) {
- int uid = mUidFirewallStandbyRules.keyAt(i);
- int oldRules = mUidRules.get(uid);
- if (enableChain) {
- // Chain wasn't enabled before and the other power-related
- // chains are whitelists, so we can clear the
- // MASK_ALL_NETWORKS part of the rules and re-inform listeners if
- // the effective rules result in blocking network access.
- oldRules &= MASK_METERED_NETWORKS;
- } else {
- // Skip if it had no restrictions to begin with
- if ((oldRules & MASK_ALL_NETWORKS) == 0) continue;
- }
- final int newUidRules = updateRulesForPowerRestrictionsUL(uid, oldRules, paroled);
- if (newUidRules == RULE_NONE) {
- mUidRules.delete(uid);
- } else {
- mUidRules.put(uid, newUidRules);
- }
- }
- }
-
- /**
* Update rules that might be changed by {@link #mRestrictBackground},
* {@link #mRestrictPower}, or {@link #mDeviceIdleMode} value.
*/
@@ -4317,7 +4285,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
private void updateRulesForPowerRestrictionsUL(int uid) {
final int oldUidRules = mUidRules.get(uid, RULE_NONE);
- final int newUidRules = updateRulesForPowerRestrictionsUL(uid, oldUidRules, false);
+ final int newUidRules = updateRulesForPowerRestrictionsUL(uid, oldUidRules);
if (newUidRules == RULE_NONE) {
mUidRules.delete(uid);
@@ -4331,30 +4299,28 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
*
* @param uid the uid of the app to update rules for
* @param oldUidRules the current rules for the uid, in order to determine if there's a change
- * @param paroled whether to ignore idle state of apps and only look at other restrictions.
*
* @return the new computed rules for the uid
*/
- private int updateRulesForPowerRestrictionsUL(int uid, int oldUidRules, boolean paroled) {
+ private int updateRulesForPowerRestrictionsUL(int uid, int oldUidRules) {
if (Trace.isTagEnabled(Trace.TRACE_TAG_NETWORK)) {
Trace.traceBegin(Trace.TRACE_TAG_NETWORK,
- "updateRulesForPowerRestrictionsUL: " + uid + "/" + oldUidRules + "/"
- + (paroled ? "P" : "-"));
+ "updateRulesForPowerRestrictionsUL: " + uid + "/" + oldUidRules);
}
try {
- return updateRulesForPowerRestrictionsULInner(uid, oldUidRules, paroled);
+ return updateRulesForPowerRestrictionsULInner(uid, oldUidRules);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_NETWORK);
}
}
- private int updateRulesForPowerRestrictionsULInner(int uid, int oldUidRules, boolean paroled) {
+ private int updateRulesForPowerRestrictionsULInner(int uid, int oldUidRules) {
if (!isUidValidForBlacklistRules(uid)) {
if (LOGD) Slog.d(TAG, "no need to update restrict power rules for uid " + uid);
return RULE_NONE;
}
- final boolean isIdle = !paroled && isUidIdle(uid);
+ final boolean isIdle = isUidIdle(uid);
final boolean restrictMode = isIdle || mRestrictPower || mDeviceIdleMode;
final boolean isForeground = isUidForegroundOnRestrictPowerUL(uid);
@@ -4426,14 +4392,6 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
} catch (NameNotFoundException nnfe) {
}
}
-
- @Override
- public void onParoleStateChanged(boolean isParoleOn) {
- synchronized (mUidRulesFirstLock) {
- mLogger.paroleStateChanged(isParoleOn);
- updateRulesForAppIdleParoleUL();
- }
- }
}
private void dispatchUidRulesChanged(INetworkPolicyListener listener, int uid, int uidRules) {
@@ -4775,7 +4733,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
}
/**
- * Calls {@link #setUidFirewallRules(int, SparseIntArray)} and
+ * Calls {@link #setUidFirewallRulesUL(int, SparseIntArray)} and
* {@link #enableFirewallChainUL(int, boolean)} synchronously.
*
* @param chain firewall chain.
diff --git a/services/tests/mockingservicestests/src/com/android/server/AlarmManagerServiceTest.java b/services/tests/mockingservicestests/src/com/android/server/AlarmManagerServiceTest.java
index 6e8b86add2c4..7b7b8e6c628a 100644
--- a/services/tests/mockingservicestests/src/com/android/server/AlarmManagerServiceTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/AlarmManagerServiceTest.java
@@ -34,7 +34,7 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
import static com.android.server.AlarmManagerService.ACTIVE_INDEX;
import static com.android.server.AlarmManagerService.AlarmHandler.APP_STANDBY_BUCKET_CHANGED;
-import static com.android.server.AlarmManagerService.AlarmHandler.APP_STANDBY_PAROLE_CHANGED;
+import static com.android.server.AlarmManagerService.AlarmHandler.CHARGING_STATUS_CHANGED;
import static com.android.server.AlarmManagerService.Constants.KEY_ALLOW_WHILE_IDLE_LONG_TIME;
import static com.android.server.AlarmManagerService.Constants.KEY_ALLOW_WHILE_IDLE_SHORT_TIME;
import static com.android.server.AlarmManagerService.Constants.KEY_ALLOW_WHILE_IDLE_WHITELIST_DURATION;
@@ -53,6 +53,7 @@ import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.atLeastOnce;
@@ -68,6 +69,7 @@ import android.app.usage.UsageStatsManagerInternal;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
+import android.os.BatteryManager;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -107,6 +109,7 @@ public class AlarmManagerServiceTest {
private long mAppStandbyWindow;
private AlarmManagerService mService;
private UsageStatsManagerInternal.AppIdleStateChangeListener mAppStandbyListener;
+ private AlarmManagerService.ChargingReceiver mChargingReceiver;
@Mock
private ContentResolver mMockResolver;
@Mock
@@ -290,6 +293,13 @@ public class AlarmManagerServiceTest {
ArgumentCaptor.forClass(UsageStatsManagerInternal.AppIdleStateChangeListener.class);
verify(mUsageStatsManagerInternal).addAppIdleStateChangeListener(captor.capture());
mAppStandbyListener = captor.getValue();
+
+ ArgumentCaptor<AlarmManagerService.ChargingReceiver> chargingReceiverCaptor =
+ ArgumentCaptor.forClass(AlarmManagerService.ChargingReceiver.class);
+ verify(mMockContext).registerReceiver(chargingReceiverCaptor.capture(),
+ argThat((filter) -> filter.hasAction(BatteryManager.ACTION_CHARGING)
+ && filter.hasAction(BatteryManager.ACTION_DISCHARGING)));
+ mChargingReceiver = chargingReceiverCaptor.getValue();
}
private void setTestAlarm(int type, long triggerTime, PendingIntent operation) {
@@ -724,17 +734,19 @@ public class AlarmManagerServiceTest {
}
private void assertAndHandleParoleChanged(boolean parole) {
- mAppStandbyListener.onParoleStateChanged(parole);
+ mChargingReceiver.onReceive(mMockContext,
+ new Intent(parole ? BatteryManager.ACTION_CHARGING
+ : BatteryManager.ACTION_DISCHARGING));
final ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
verify(mService.mHandler, atLeastOnce()).sendMessage(messageCaptor.capture());
final Message lastMessage = messageCaptor.getValue();
assertEquals("Unexpected message send to handler", lastMessage.what,
- APP_STANDBY_PAROLE_CHANGED);
+ CHARGING_STATUS_CHANGED);
mService.mHandler.handleMessage(lastMessage);
}
@Test
- public void testParole() throws Exception {
+ public void testCharging() throws Exception {
setQuotasEnabled(true);
final int workingQuota = mService.getQuotaForBucketLocked(STANDBY_BUCKET_WORKING_SET);
when(mUsageStatsManagerInternal.getAppStandbyBucket(eq(TEST_CALLING_PACKAGE), anyInt(),
diff --git a/services/tests/mockingservicestests/src/com/android/server/AppStateTrackerTest.java b/services/tests/mockingservicestests/src/com/android/server/AppStateTrackerTest.java
index d0158e0c819f..247a3581c78c 100644
--- a/services/tests/mockingservicestests/src/com/android/server/AppStateTrackerTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/AppStateTrackerTest.java
@@ -64,6 +64,9 @@ import android.test.mock.MockContentResolver;
import android.util.ArraySet;
import android.util.Pair;
+import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
+
import com.android.internal.app.IAppOpsCallback;
import com.android.internal.app.IAppOpsService;
import com.android.server.AppStateTracker.Listener;
@@ -85,14 +88,10 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
-import androidx.test.filters.SmallTest;
-import androidx.test.runner.AndroidJUnit4;
-
/**
* Tests for {@link AppStateTracker}
*
- * Run with:
- atest $ANDROID_BUILD_TOP/frameworks/base/services/tests/mockingservicestests/src/com/android/server/AppStateTrackerTest.java
+ * Run with: atest com.android.server.AppStateTrackerTest
*/
@SmallTest
@RunWith(AndroidJUnit4.class)
diff --git a/services/tests/servicestests/src/com/android/server/net/ConnOnActivityStartTest.java b/services/tests/servicestests/src/com/android/server/net/ConnOnActivityStartTest.java
index fe7a376d9e8d..25b41db1aea3 100644
--- a/services/tests/servicestests/src/com/android/server/net/ConnOnActivityStartTest.java
+++ b/services/tests/servicestests/src/com/android/server/net/ConnOnActivityStartTest.java
@@ -29,7 +29,6 @@ import android.os.BatteryManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.SystemClock;
-import android.provider.Settings;
import android.support.test.uiautomator.UiDevice;
import android.text.TextUtils;
import android.util.Log;
@@ -88,17 +87,11 @@ public class ConnOnActivityStartTest {
private static final int REPEAT_TEST_COUNT = 5;
- private static final String KEY_PAROLE_DURATION = "parole_duration";
- private static final String DESIRED_PAROLE_DURATION = "0";
-
private static Context mContext;
private static UiDevice mUiDevice;
private static int mTestPkgUid;
private static BatteryManager mBatteryManager;
- private static boolean mAppIdleConstsUpdated;
- private static String mOriginalAppIdleConsts;
-
private static ServiceConnection mServiceConnection;
private static ICmdReceiverService mCmdReceiverService;
@@ -107,7 +100,6 @@ public class ConnOnActivityStartTest {
mContext = InstrumentationRegistry.getContext();
mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
- setDesiredParoleDuration();
mContext.getPackageManager().setApplicationEnabledSetting(TEST_PKG,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);
mTestPkgUid = mContext.getPackageManager().getPackageUid(TEST_PKG, 0);
@@ -119,10 +111,6 @@ public class ConnOnActivityStartTest {
@AfterClass
public static void tearDownOnce() throws Exception {
batteryReset();
- if (mAppIdleConstsUpdated) {
- Settings.Global.putString(mContext.getContentResolver(),
- Settings.Global.APP_IDLE_CONSTANTS, mOriginalAppIdleConsts);
- }
unbindService();
}
@@ -160,27 +148,6 @@ public class ConnOnActivityStartTest {
}
}
- private static void setDesiredParoleDuration() {
- mOriginalAppIdleConsts = Settings.Global.getString(mContext.getContentResolver(),
- Settings.Global.APP_IDLE_CONSTANTS);
- String newAppIdleConstants;
- final String newConstant = KEY_PAROLE_DURATION + "=" + DESIRED_PAROLE_DURATION;
- if (mOriginalAppIdleConsts == null || "null".equals(mOriginalAppIdleConsts)) {
- // app_idle_constants is initially empty, so just assign the desired value.
- newAppIdleConstants = newConstant;
- } else if (mOriginalAppIdleConsts.contains(KEY_PAROLE_DURATION)) {
- // app_idle_constants contains parole_duration, so replace it with the desired value.
- newAppIdleConstants = mOriginalAppIdleConsts.replaceAll(
- KEY_PAROLE_DURATION + "=\\d+", newConstant);
- } else {
- // app_idle_constants didn't have parole_duration, so append the desired value.
- newAppIdleConstants = mOriginalAppIdleConsts + "," + newConstant;
- }
- Settings.Global.putString(mContext.getContentResolver(),
- Settings.Global.APP_IDLE_CONSTANTS, newAppIdleConstants);
- mAppIdleConstsUpdated = true;
- }
-
@Test
public void testStartActivity_batterySaver() throws Exception {
setBatterySaverMode(true);
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 4ffcf8fa18b7..12ba219d0365 100644
--- a/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
+++ b/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
@@ -47,7 +47,6 @@ import static org.mockito.Mockito.mock;
import android.app.usage.AppStandbyInfo;
import android.app.usage.UsageEvents;
-import android.app.usage.UsageStatsManagerInternal;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.ContextWrapper;
@@ -77,7 +76,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
-import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/**
@@ -108,8 +106,6 @@ public class AppStandbyControllerTests {
private static final long WORKING_SET_THRESHOLD = 12 * HOUR_MS;
private static final long FREQUENT_THRESHOLD = 24 * HOUR_MS;
private static final long RARE_THRESHOLD = 48 * HOUR_MS;
- // Short STABLE_CHARGING_THRESHOLD for testing purposes
- private static final long STABLE_CHARGING_THRESHOLD = 2000;
/** Mock variable used in {@link MyInjector#isPackageInstalled(String, int, int)} */
private static boolean isPackageInstalled = true;
@@ -132,7 +128,6 @@ public class AppStandbyControllerTests {
static class MyInjector extends AppStandbyController.Injector {
long mElapsedRealtime;
boolean mIsAppIdleEnabled = true;
- boolean mIsCharging;
List<String> mPowerSaveWhitelistExceptIdle = new ArrayList<>();
boolean mDisplayOn;
DisplayManager.DisplayListener mDisplayListener;
@@ -167,11 +162,6 @@ public class AppStandbyControllerTests {
}
@Override
- boolean isCharging() {
- return mIsCharging;
- }
-
- @Override
boolean isPowerSaveWhitelistExceptIdleApp(String packageName) throws RemoteException {
return mPowerSaveWhitelistExceptIdle.contains(packageName);
}
@@ -228,8 +218,7 @@ public class AppStandbyControllerTests {
return "screen_thresholds=0/0/0/" + HOUR_MS + ",elapsed_thresholds=0/"
+ WORKING_SET_THRESHOLD + "/"
+ FREQUENT_THRESHOLD + "/"
- + RARE_THRESHOLD + ","
- + "stable_charging_threshold=" + STABLE_CHARGING_THRESHOLD;
+ + RARE_THRESHOLD;
}
@Override
@@ -273,13 +262,6 @@ public class AppStandbyControllerTests {
} catch (PackageManager.NameNotFoundException nnfe) {}
}
- private void setChargingState(AppStandbyController controller, boolean charging) {
- mInjector.mIsCharging = charging;
- if (controller != null) {
- controller.setChargingState(charging);
- }
- }
-
private void setAppIdleEnabled(AppStandbyController controller, boolean enabled) {
mInjector.mIsAppIdleEnabled = enabled;
if (controller != null) {
@@ -296,7 +278,6 @@ public class AppStandbyControllerTests {
controller.onBootPhase(SystemService.PHASE_BOOT_COMPLETED);
mInjector.setDisplayOn(false);
mInjector.setDisplayOn(true);
- setChargingState(controller, false);
controller.checkIdleStates(USER_ID);
assertNotEquals(STANDBY_BUCKET_EXEMPTED,
controller.getAppStandbyBucket(PACKAGE_1, USER_ID,
@@ -314,65 +295,6 @@ public class AppStandbyControllerTests {
MyContextWrapper myContext = new MyContextWrapper(InstrumentationRegistry.getContext());
mInjector = new MyInjector(myContext, Looper.getMainLooper());
mController = setupController();
- setChargingState(mController, false);
- }
-
- private class TestParoleListener extends UsageStatsManagerInternal.AppIdleStateChangeListener {
- private boolean mOnParole = false;
- private CountDownLatch mLatch;
- private long mLastParoleChangeTime;
- private boolean mIsExpecting = false;
- private boolean mExpectedParoleState;
-
- public boolean getParoleState() {
- synchronized (this) {
- return mOnParole;
- }
- }
-
- public void rearmLatch() {
- synchronized (this) {
- mLatch = new CountDownLatch(1);
- mIsExpecting = false;
- }
- }
-
- public void rearmLatch(boolean expectedParoleState) {
- synchronized (this) {
- mLatch = new CountDownLatch(1);
- mIsExpecting = true;
- mExpectedParoleState = expectedParoleState;
- }
- }
-
- public void awaitOnLatch(long time) throws Exception {
- mLatch.await(time, TimeUnit.MILLISECONDS);
- }
-
- public long getLastParoleChangeTime() {
- synchronized (this) {
- return mLastParoleChangeTime;
- }
- }
-
- @Override
- public void onAppIdleStateChanged(String packageName, int userId, boolean idle,
- int bucket, int reason) {
- }
-
- @Override
- public void onParoleStateChanged(boolean isParoleOn) {
- synchronized (this) {
- // Only record information if it is being looked for
- if (mLatch != null && mLatch.getCount() > 0) {
- mOnParole = isParoleOn;
- mLastParoleChangeTime = getCurrentTime();
- if (!mIsExpecting || isParoleOn == mExpectedParoleState) {
- mLatch.countDown();
- }
- }
- }
- }
}
@Test
@@ -383,133 +305,6 @@ public class AppStandbyControllerTests {
mInjector.mElapsedRealtime, false));
}
- @Test
- public void testCharging() throws Exception {
- long startTime;
- TestParoleListener paroleListener = new TestParoleListener();
- long marginOfError = 200;
-
- // Charging
- paroleListener.rearmLatch();
- mController.addListener(paroleListener);
- startTime = getCurrentTime();
- setChargingState(mController, true);
- paroleListener.awaitOnLatch(STABLE_CHARGING_THRESHOLD * 3 / 2);
- assertTrue(paroleListener.mOnParole);
- // Parole will only be granted after device has been charging for a sufficient amount of
- // time.
- assertEquals(STABLE_CHARGING_THRESHOLD,
- paroleListener.getLastParoleChangeTime() - startTime,
- marginOfError);
-
- // Discharging
- paroleListener.rearmLatch();
- startTime = getCurrentTime();
- setChargingState(mController, false);
- mController.checkIdleStates(USER_ID);
- paroleListener.awaitOnLatch(STABLE_CHARGING_THRESHOLD * 3 / 2);
- assertFalse(paroleListener.getParoleState());
- // Parole should be revoked immediately
- assertEquals(0,
- paroleListener.getLastParoleChangeTime() - startTime,
- marginOfError);
-
- // Brief Charging
- paroleListener.rearmLatch();
- setChargingState(mController, true);
- setChargingState(mController, false);
- // Device stopped charging before the stable charging threshold.
- // Parole should not be granted at the end of the threshold
- paroleListener.awaitOnLatch(STABLE_CHARGING_THRESHOLD * 3 / 2);
- assertFalse(paroleListener.getParoleState());
-
- // Charging Again
- paroleListener.rearmLatch();
- startTime = getCurrentTime();
- setChargingState(mController, true);
- paroleListener.awaitOnLatch(STABLE_CHARGING_THRESHOLD * 3 / 2);
- assertTrue(paroleListener.getParoleState());
- assertTrue(paroleListener.mOnParole);
- assertEquals(STABLE_CHARGING_THRESHOLD,
- paroleListener.getLastParoleChangeTime() - startTime,
- marginOfError);
- }
-
- @Test
- public void testEnabledState() throws Exception {
- TestParoleListener paroleListener = new TestParoleListener();
- paroleListener.rearmLatch(true);
- mController.addListener(paroleListener);
- long lastUpdateTime;
-
- // Test that listeners are notified if enabled changes when the device is not in parole.
- setChargingState(mController, false);
-
- // Start off not enabled. Device is effectively in permanent parole.
- setAppIdleEnabled(mController, false);
- // Since AppStandbyController uses a handler to notify listeners of a state change, there is
- // some inherent latency between changing the state and getting the notification. We need to
- // wait until the paroleListener has been notified that parole is on before continuing with
- // the test.
- paroleListener.awaitOnLatch(STABLE_CHARGING_THRESHOLD * 3 / 2);
- assertTrue(paroleListener.mOnParole);
-
- // Enable controller
- paroleListener.rearmLatch();
- setAppIdleEnabled(mController, true);
- paroleListener.awaitOnLatch(STABLE_CHARGING_THRESHOLD * 3 / 2);
- assertFalse(paroleListener.mOnParole);
- lastUpdateTime = paroleListener.getLastParoleChangeTime();
-
- paroleListener.rearmLatch();
- setAppIdleEnabled(mController, true);
- paroleListener.awaitOnLatch(STABLE_CHARGING_THRESHOLD * 3 / 2);
- assertFalse(paroleListener.mOnParole);
- // Make sure AppStandbyController doesn't notify listeners when there's no change.
- assertEquals(lastUpdateTime, paroleListener.getLastParoleChangeTime());
-
- // Disable controller
- paroleListener.rearmLatch();
- setAppIdleEnabled(mController, false);
- paroleListener.awaitOnLatch(STABLE_CHARGING_THRESHOLD * 3 / 2);
- assertTrue(paroleListener.mOnParole);
- lastUpdateTime = paroleListener.getLastParoleChangeTime();
-
- paroleListener.rearmLatch();
- setAppIdleEnabled(mController, false);
- paroleListener.awaitOnLatch(STABLE_CHARGING_THRESHOLD * 3 / 2);
- assertTrue(paroleListener.mOnParole);
- // Make sure AppStandbyController doesn't notify listeners when there's no change.
- assertEquals(lastUpdateTime, paroleListener.getLastParoleChangeTime());
-
-
- // Test that listeners aren't notified if enabled status changes when the device is already
- // in parole.
-
- // A device is in parole whenever it's charging.
- setChargingState(mController, true);
-
- // Start off not enabled.
- paroleListener.rearmLatch();
- setAppIdleEnabled(mController, false);
- paroleListener.awaitOnLatch(STABLE_CHARGING_THRESHOLD * 3 / 2);
- assertTrue(paroleListener.mOnParole);
- lastUpdateTime = paroleListener.getLastParoleChangeTime();
-
- // Test that toggling doesn't notify the listener.
- paroleListener.rearmLatch();
- setAppIdleEnabled(mController, true);
- paroleListener.awaitOnLatch(STABLE_CHARGING_THRESHOLD * 3 / 2);
- assertTrue(paroleListener.mOnParole);
- assertEquals(lastUpdateTime, paroleListener.getLastParoleChangeTime());
-
- paroleListener.rearmLatch();
- setAppIdleEnabled(mController, false);
- paroleListener.awaitOnLatch(STABLE_CHARGING_THRESHOLD * 3 / 2);
- assertTrue(paroleListener.mOnParole);
- assertEquals(lastUpdateTime, paroleListener.getLastParoleChangeTime());
- }
-
private void assertTimeout(AppStandbyController controller, long elapsedTime, int bucket) {
mInjector.mElapsedRealtime = elapsedTime;
controller.checkIdleStates(USER_ID);
@@ -804,8 +599,6 @@ public class AppStandbyControllerTests {
@Test
public void testSystemInteractionTimeout() throws Exception {
- setChargingState(mController, false);
-
reportEvent(mController, USER_INTERACTION, 0, PACKAGE_1);
// Fast forward to RARE
mInjector.mElapsedRealtime = RARE_THRESHOLD + 100;
@@ -829,8 +622,6 @@ public class AppStandbyControllerTests {
@Test
public void testInitialForegroundServiceTimeout() throws Exception {
- setChargingState(mController, false);
-
mInjector.mElapsedRealtime = 1 * RARE_THRESHOLD + 100;
// Make sure app is in NEVER bucket
mController.setAppStandbyBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_NEVER,
diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java
index ecee709054ee..2cd207f72d6f 100644
--- a/services/usage/java/com/android/server/usage/UsageStatsService.java
+++ b/services/usage/java/com/android/server/usage/UsageStatsService.java
@@ -97,8 +97,6 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
@@ -191,11 +189,6 @@ public class UsageStatsService extends SystemService implements
event.mPackage = packageName;
reportEventOrAddToQueue(userId, event);
}
-
- @Override
- public void onParoleStateChanged(boolean isParoleOn) {
-
- }
};
public UsageStatsService(Context context) {
@@ -1426,7 +1419,7 @@ public class UsageStatsService extends SystemService implements
Binder.getCallingUid(), userId);
final long token = Binder.clearCallingIdentity();
try {
- return mAppStandby.isAppIdleFilteredOrParoled(
+ return mAppStandby.isAppIdleFiltered(
packageName, userId,
SystemClock.elapsedRealtime(), obfuscateInstantApps);
} finally {
@@ -1995,11 +1988,6 @@ public class UsageStatsService extends SystemService implements
}
@Override
- public boolean isAppIdleParoleOn() {
- return mAppStandby.isParoledOrCharging();
- }
-
- @Override
public void prepareShutdown() {
// This method *WILL* do IO work, but we must block until it is finished or else
// we might not shutdown cleanly. This is ok to do with the 'am' lock held, because
@@ -2015,7 +2003,6 @@ public class UsageStatsService extends SystemService implements
@Override
public void addAppIdleStateChangeListener(AppIdleStateChangeListener listener) {
mAppStandby.addListener(listener);
- listener.onParoleStateChanged(isAppIdleParoleOn());
}
@Override