Ensure networked UI jobs run during BS & Doze.

Make sure user-initiated jobs can run during battery saver and Doze by
explicitly adding the necessary bind flags for
NetworkPolicyManager to grant network access in those states.

Bug: 261999509
Test: atest CtsJobSchedulerTestCases:UserInitiatedJobTest
Change-Id: I3106760b8cf5f76669e361cc75528e0ada9db8cb
This commit is contained in:
Kweku Adams
2023-01-17 16:31:21 +00:00
parent 6cc3ef13dc
commit fe385d6de2
2 changed files with 20 additions and 1 deletions

View File

@@ -361,7 +361,14 @@ public final class JobServiceContext implements ServiceConnection {
boolean binding = false;
try {
final int bindFlags;
if (job.shouldTreatAsExpeditedJob()) {
if (job.shouldTreatAsUserInitiatedJob()) {
// TODO (191785864, 261999509): add an appropriate flag so user-initiated jobs
// can bypass data saver
bindFlags = Context.BIND_AUTO_CREATE
| Context.BIND_ALMOST_PERCEPTIBLE
| Context.BIND_BYPASS_POWER_NETWORK_RESTRICTIONS
| Context.BIND_NOT_APP_COMPONENT_USAGE;
} else if (job.shouldTreatAsExpeditedJob()) {
bindFlags = Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND
| Context.BIND_ALMOST_PERCEPTIBLE
| Context.BIND_BYPASS_POWER_NETWORK_RESTRICTIONS

View File

@@ -98,6 +98,13 @@ public final class ConnectivityController extends RestrictingController implemen
~(ConnectivityManager.BLOCKED_REASON_APP_STANDBY
| ConnectivityManager.BLOCKED_REASON_BATTERY_SAVER
| ConnectivityManager.BLOCKED_REASON_DOZE);
// TODO(261999509): allow bypassing data saver & user-restricted. However, when we allow a UI
// job to run while data saver restricts the app, we must ensure that we don't run regular
// jobs when we put a hole in the data saver wall for the UI job
private static final int UNBYPASSABLE_UI_BLOCKED_REASONS =
~(ConnectivityManager.BLOCKED_REASON_APP_STANDBY
| ConnectivityManager.BLOCKED_REASON_BATTERY_SAVER
| ConnectivityManager.BLOCKED_REASON_DOZE);
private static final int UNBYPASSABLE_FOREGROUND_BLOCKED_REASONS =
~(ConnectivityManager.BLOCKED_REASON_APP_STANDBY
| ConnectivityManager.BLOCKED_REASON_BATTERY_SAVER
@@ -1080,6 +1087,11 @@ public final class ConnectivityController extends RestrictingController implemen
Slog.d(TAG, "Using FG bypass for " + jobStatus.getSourceUid());
}
unbypassableBlockedReasons = UNBYPASSABLE_FOREGROUND_BLOCKED_REASONS;
} else if (jobStatus.shouldTreatAsUserInitiatedJob()) {
if (DEBUG) {
Slog.d(TAG, "Using UI bypass for " + jobStatus.getSourceUid());
}
unbypassableBlockedReasons = UNBYPASSABLE_UI_BLOCKED_REASONS;
} else if (jobStatus.shouldTreatAsExpeditedJob() || jobStatus.startedAsExpeditedJob) {
if (DEBUG) {
Slog.d(TAG, "Using EJ bypass for " + jobStatus.getSourceUid());