Merge "Remove the setDataTransfer API." into udc-dev

This commit is contained in:
Varun Shah
2023-02-25 18:43:38 +00:00
committed by Android (Google) Code Review
7 changed files with 40 additions and 182 deletions

View File

@@ -396,19 +396,12 @@ public class JobInfo implements Parcelable {
*/ */
public static final int FLAG_EXPEDITED = 1 << 4; public static final int FLAG_EXPEDITED = 1 << 4;
/**
* Whether it's a data transfer job or not.
*
* @hide
*/
public static final int FLAG_DATA_TRANSFER = 1 << 5;
/** /**
* Whether it's a user initiated job or not. * Whether it's a user initiated job or not.
* *
* @hide * @hide
*/ */
public static final int FLAG_USER_INITIATED = 1 << 6; public static final int FLAG_USER_INITIATED = 1 << 5;
/** /**
* @hide * @hide
@@ -737,13 +730,6 @@ public class JobInfo implements Parcelable {
return (flags & FLAG_EXPEDITED) != 0; return (flags & FLAG_EXPEDITED) != 0;
} }
/**
* @see JobInfo.Builder#setDataTransfer(boolean)
*/
public boolean isDataTransfer() {
return (flags & FLAG_DATA_TRANSFER) != 0;
}
/** /**
* @see JobInfo.Builder#setUserInitiated(boolean) * @see JobInfo.Builder#setUserInitiated(boolean)
*/ */
@@ -1849,39 +1835,6 @@ public class JobInfo implements Parcelable {
return this; return this;
} }
/**
* Indicates that this job will be used to transfer data to or from a remote server. The
* system could attempt to run a data transfer job longer than a regular job if the data
* being transferred is potentially very large and can take a long time to complete.
*
* <p>
* You must provide an estimate of the payload size via
* {@link #setEstimatedNetworkBytes(long, long)} when scheduling the job or use
* {@link JobService#updateEstimatedNetworkBytes(JobParameters, long, long)} or
* {@link JobService#updateEstimatedNetworkBytes(JobParameters, JobWorkItem, long, long)}
* shortly after the job starts.
*
* <p>
* For user-initiated transfers that must be started immediately, call
* {@link #setUserInitiated(boolean) setUserInitiated(true)}. Otherwise, the system may
* defer the job to a more opportune time.
*
* <p>
* If you want to perform more than one data transfer job, consider enqueuing multiple
* {@link JobWorkItem JobWorkItems} along with {@link #setDataTransfer(boolean)}.
*
* @see JobInfo#isDataTransfer()
*/
@NonNull
public Builder setDataTransfer(boolean dataTransfer) {
if (dataTransfer) {
mFlags |= FLAG_DATA_TRANSFER;
} else {
mFlags &= (~FLAG_DATA_TRANSFER);
}
return this;
}
/** /**
* Indicates that this job is being scheduled to fulfill an explicit user request. * Indicates that this job is being scheduled to fulfill an explicit user request.
* As such, user-initiated jobs can only be scheduled when the app is in the foreground * As such, user-initiated jobs can only be scheduled when the app is in the foreground
@@ -1909,6 +1862,11 @@ public class JobInfo implements Parcelable {
* {@link SecurityException}. * {@link SecurityException}.
* *
* <p> * <p>
* In {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, user-initiated jobs can only
* be used for network data transfers. As such, they must specify a required network via
* {@link #setRequiredNetwork(NetworkRequest)} or {@link #setRequiredNetworkType(int)}.
*
* <p>
* These jobs will not be subject to quotas and will be started immediately once scheduled * These jobs will not be subject to quotas and will be started immediately once scheduled
* if all constraints are met and the device system health allows for additional tasks. * if all constraints are met and the device system health allows for additional tasks.
* *
@@ -2179,10 +2137,6 @@ public class JobInfo implements Parcelable {
if (isPeriodic) { if (isPeriodic) {
throw new IllegalArgumentException("An expedited job cannot be periodic"); throw new IllegalArgumentException("An expedited job cannot be periodic");
} }
if ((flags & FLAG_DATA_TRANSFER) != 0) {
throw new IllegalArgumentException(
"An expedited job cannot also be a data transfer job");
}
if (isUserInitiated) { if (isUserInitiated) {
throw new IllegalArgumentException("An expedited job cannot be user-initiated"); throw new IllegalArgumentException("An expedited job cannot be user-initiated");
} }
@@ -2202,24 +2156,6 @@ public class JobInfo implements Parcelable {
} }
} }
if ((flags & FLAG_DATA_TRANSFER) != 0) {
if (backoffPolicy == BACKOFF_POLICY_LINEAR) {
throw new IllegalArgumentException(
"A data transfer job cannot have a linear backoff policy.");
}
if (hasLateConstraint) {
throw new IllegalArgumentException("A data transfer job cannot have a deadline");
}
if ((flags & FLAG_PREFETCH) != 0) {
throw new IllegalArgumentException(
"A data transfer job cannot also be a prefetch job");
}
if (networkRequest == null) {
throw new IllegalArgumentException(
"A data transfer job must specify a valid network type");
}
}
if (isUserInitiated) { if (isUserInitiated) {
if (hasEarlyConstraint) { if (hasEarlyConstraint) {
throw new IllegalArgumentException("A user-initiated job cannot have a time delay"); throw new IllegalArgumentException("A user-initiated job cannot have a time delay");
@@ -2245,6 +2181,15 @@ public class JobInfo implements Parcelable {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Can't call addTriggerContentUri() on a user-initiated job"); "Can't call addTriggerContentUri() on a user-initiated job");
} }
// UIDTs
if (networkRequest == null) {
throw new IllegalArgumentException(
"A user-initaited data transfer job must specify a valid network type");
}
if (backoffPolicy == BACKOFF_POLICY_LINEAR) {
throw new IllegalArgumentException(
"A user-initiated data transfer job cannot have a linear backoff policy.");
}
} }
} }

View File

@@ -478,8 +478,6 @@ public class JobSchedulerService extends com.android.server.SystemService
case Constants.KEY_RUNTIME_FREE_QUOTA_MAX_LIMIT_MS: case Constants.KEY_RUNTIME_FREE_QUOTA_MAX_LIMIT_MS:
case Constants.KEY_RUNTIME_MIN_GUARANTEE_MS: case Constants.KEY_RUNTIME_MIN_GUARANTEE_MS:
case Constants.KEY_RUNTIME_MIN_EJ_GUARANTEE_MS: case Constants.KEY_RUNTIME_MIN_EJ_GUARANTEE_MS:
case Constants.KEY_RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS:
case Constants.KEY_RUNTIME_DATA_TRANSFER_LIMIT_MS:
case Constants.KEY_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS: case Constants.KEY_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS:
case Constants.KEY_RUNTIME_USER_INITIATED_LIMIT_MS: case Constants.KEY_RUNTIME_USER_INITIATED_LIMIT_MS:
case Constants.KEY_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR: case Constants.KEY_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR:
@@ -574,10 +572,6 @@ public class JobSchedulerService extends com.android.server.SystemService
"runtime_free_quota_max_limit_ms"; "runtime_free_quota_max_limit_ms";
private static final String KEY_RUNTIME_MIN_GUARANTEE_MS = "runtime_min_guarantee_ms"; private static final String KEY_RUNTIME_MIN_GUARANTEE_MS = "runtime_min_guarantee_ms";
private static final String KEY_RUNTIME_MIN_EJ_GUARANTEE_MS = "runtime_min_ej_guarantee_ms"; private static final String KEY_RUNTIME_MIN_EJ_GUARANTEE_MS = "runtime_min_ej_guarantee_ms";
private static final String KEY_RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS =
"runtime_min_data_transfer_guarantee_ms";
private static final String KEY_RUNTIME_DATA_TRANSFER_LIMIT_MS =
"runtime_data_transfer_limit_ms";
private static final String KEY_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS = private static final String KEY_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS =
"runtime_min_user_initiated_guarantee_ms"; "runtime_min_user_initiated_guarantee_ms";
private static final String KEY_RUNTIME_USER_INITIATED_LIMIT_MS = private static final String KEY_RUNTIME_USER_INITIATED_LIMIT_MS =
@@ -616,10 +610,6 @@ public class JobSchedulerService extends com.android.server.SystemService
public static final long DEFAULT_RUNTIME_MIN_GUARANTEE_MS = 10 * MINUTE_IN_MILLIS; public static final long DEFAULT_RUNTIME_MIN_GUARANTEE_MS = 10 * MINUTE_IN_MILLIS;
@VisibleForTesting @VisibleForTesting
public static final long DEFAULT_RUNTIME_MIN_EJ_GUARANTEE_MS = 3 * MINUTE_IN_MILLIS; public static final long DEFAULT_RUNTIME_MIN_EJ_GUARANTEE_MS = 3 * MINUTE_IN_MILLIS;
public static final long DEFAULT_RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS =
DEFAULT_RUNTIME_MIN_GUARANTEE_MS;
public static final long DEFAULT_RUNTIME_DATA_TRANSFER_LIMIT_MS =
DEFAULT_RUNTIME_FREE_QUOTA_MAX_LIMIT_MS;
public static final long DEFAULT_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS = public static final long DEFAULT_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS =
Math.max(10 * MINUTE_IN_MILLIS, DEFAULT_RUNTIME_MIN_GUARANTEE_MS); Math.max(10 * MINUTE_IN_MILLIS, DEFAULT_RUNTIME_MIN_GUARANTEE_MS);
public static final long DEFAULT_RUNTIME_USER_INITIATED_LIMIT_MS = public static final long DEFAULT_RUNTIME_USER_INITIATED_LIMIT_MS =
@@ -738,18 +728,6 @@ public class JobSchedulerService extends com.android.server.SystemService
*/ */
public long RUNTIME_MIN_EJ_GUARANTEE_MS = DEFAULT_RUNTIME_MIN_EJ_GUARANTEE_MS; public long RUNTIME_MIN_EJ_GUARANTEE_MS = DEFAULT_RUNTIME_MIN_EJ_GUARANTEE_MS;
/**
* The minimum amount of time we try to guarantee normal data transfer jobs will run for.
*/
public long RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS =
DEFAULT_RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS;
/**
* The maximum amount of time we will let a normal data transfer job run for. This will only
* apply if there are no other limits that apply to the specific data transfer job.
*/
public long RUNTIME_DATA_TRANSFER_LIMIT_MS = DEFAULT_RUNTIME_DATA_TRANSFER_LIMIT_MS;
/** /**
* The minimum amount of time we try to guarantee normal user-initiated jobs will run for. * The minimum amount of time we try to guarantee normal user-initiated jobs will run for.
*/ */
@@ -885,8 +863,6 @@ public class JobSchedulerService extends com.android.server.SystemService
KEY_RUNTIME_FREE_QUOTA_MAX_LIMIT_MS, KEY_RUNTIME_FREE_QUOTA_MAX_LIMIT_MS,
KEY_RUNTIME_MIN_GUARANTEE_MS, KEY_RUNTIME_MIN_EJ_GUARANTEE_MS, KEY_RUNTIME_MIN_GUARANTEE_MS, KEY_RUNTIME_MIN_EJ_GUARANTEE_MS,
KEY_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR, KEY_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR,
KEY_RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS,
KEY_RUNTIME_DATA_TRANSFER_LIMIT_MS,
KEY_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS, KEY_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS,
KEY_RUNTIME_USER_INITIATED_LIMIT_MS, KEY_RUNTIME_USER_INITIATED_LIMIT_MS,
KEY_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS, KEY_RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS,
@@ -904,17 +880,6 @@ public class JobSchedulerService extends com.android.server.SystemService
properties.getLong(KEY_RUNTIME_FREE_QUOTA_MAX_LIMIT_MS, properties.getLong(KEY_RUNTIME_FREE_QUOTA_MAX_LIMIT_MS,
DEFAULT_RUNTIME_FREE_QUOTA_MAX_LIMIT_MS)); DEFAULT_RUNTIME_FREE_QUOTA_MAX_LIMIT_MS));
// Make sure min runtime is at least as long as regular jobs. // Make sure min runtime is at least as long as regular jobs.
RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS = Math.max(RUNTIME_MIN_GUARANTEE_MS,
properties.getLong(
KEY_RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS,
DEFAULT_RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS));
// Max limit should be at least the min guarantee AND the free quota.
RUNTIME_DATA_TRANSFER_LIMIT_MS = Math.max(RUNTIME_FREE_QUOTA_MAX_LIMIT_MS,
Math.max(RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS,
properties.getLong(
KEY_RUNTIME_DATA_TRANSFER_LIMIT_MS,
DEFAULT_RUNTIME_DATA_TRANSFER_LIMIT_MS)));
// Make sure min runtime is at least as long as regular jobs.
RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS = Math.max(RUNTIME_MIN_GUARANTEE_MS, RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS = Math.max(RUNTIME_MIN_GUARANTEE_MS,
properties.getLong( properties.getLong(
KEY_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS, KEY_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS,
@@ -993,10 +958,6 @@ public class JobSchedulerService extends com.android.server.SystemService
pw.print(KEY_RUNTIME_MIN_EJ_GUARANTEE_MS, RUNTIME_MIN_EJ_GUARANTEE_MS).println(); pw.print(KEY_RUNTIME_MIN_EJ_GUARANTEE_MS, RUNTIME_MIN_EJ_GUARANTEE_MS).println();
pw.print(KEY_RUNTIME_FREE_QUOTA_MAX_LIMIT_MS, RUNTIME_FREE_QUOTA_MAX_LIMIT_MS) pw.print(KEY_RUNTIME_FREE_QUOTA_MAX_LIMIT_MS, RUNTIME_FREE_QUOTA_MAX_LIMIT_MS)
.println(); .println();
pw.print(KEY_RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS,
RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS).println();
pw.print(KEY_RUNTIME_DATA_TRANSFER_LIMIT_MS,
RUNTIME_DATA_TRANSFER_LIMIT_MS).println();
pw.print(KEY_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS, pw.print(KEY_RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS,
RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS).println(); RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS).println();
pw.print(KEY_RUNTIME_USER_INITIATED_LIMIT_MS, pw.print(KEY_RUNTIME_USER_INITIATED_LIMIT_MS,
@@ -3291,7 +3252,7 @@ public class JobSchedulerService extends com.android.server.SystemService
if (job.shouldTreatAsUserInitiatedJob() if (job.shouldTreatAsUserInitiatedJob()
&& checkRunUserInitiatedJobsPermission( && checkRunUserInitiatedJobsPermission(
job.getSourceUid(), job.getSourcePackageName())) { job.getSourceUid(), job.getSourcePackageName())) {
if (job.getJob().isDataTransfer()) { if (job.getJob().getRequiredNetwork() != null) { // UI+DT
final long estimatedTransferTimeMs = final long estimatedTransferTimeMs =
mConnectivityController.getEstimatedTransferTimeMs(job); mConnectivityController.getEstimatedTransferTimeMs(job);
if (estimatedTransferTimeMs == ConnectivityController.UNKNOWN_TIME) { if (estimatedTransferTimeMs == ConnectivityController.UNKNOWN_TIME) {
@@ -3308,9 +3269,6 @@ public class JobSchedulerService extends com.android.server.SystemService
)); ));
} }
return mConstants.RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS; return mConstants.RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS;
} else if (job.getJob().isDataTransfer()) {
// For now, don't increase a bg data transfer's minimum guarantee.
return mConstants.RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS;
} else if (job.shouldTreatAsExpeditedJob()) { } else if (job.shouldTreatAsExpeditedJob()) {
// Don't guarantee RESTRICTED jobs more than 5 minutes. // Don't guarantee RESTRICTED jobs more than 5 minutes.
return job.getEffectiveStandbyBucket() != RESTRICTED_INDEX return job.getEffectiveStandbyBucket() != RESTRICTED_INDEX
@@ -3328,7 +3286,7 @@ public class JobSchedulerService extends com.android.server.SystemService
final boolean allowLongerJob = job.shouldTreatAsUserInitiatedJob() final boolean allowLongerJob = job.shouldTreatAsUserInitiatedJob()
&& checkRunUserInitiatedJobsPermission( && checkRunUserInitiatedJobsPermission(
job.getSourceUid(), job.getSourcePackageName()); job.getSourceUid(), job.getSourcePackageName());
if (job.getJob().isDataTransfer() && allowLongerJob) { // UI+DT if (job.getJob().getRequiredNetwork() != null && allowLongerJob) { // UI+DT
return mConstants.RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS; return mConstants.RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS;
} }
if (allowLongerJob) { // UI with LRJ permission if (allowLongerJob) { // UI with LRJ permission
@@ -3337,9 +3295,6 @@ public class JobSchedulerService extends com.android.server.SystemService
if (job.shouldTreatAsUserInitiatedJob()) { if (job.shouldTreatAsUserInitiatedJob()) {
return mConstants.RUNTIME_FREE_QUOTA_MAX_LIMIT_MS; return mConstants.RUNTIME_FREE_QUOTA_MAX_LIMIT_MS;
} }
if (job.getJob().isDataTransfer()) {
return mConstants.RUNTIME_DATA_TRANSFER_LIMIT_MS;
}
return Math.min(mConstants.RUNTIME_FREE_QUOTA_MAX_LIMIT_MS, return Math.min(mConstants.RUNTIME_FREE_QUOTA_MAX_LIMIT_MS,
mConstants.USE_TARE_POLICY mConstants.USE_TARE_POLICY
? mTareController.getMaxJobExecutionTimeMsLocked(job) ? mTareController.getMaxJobExecutionTimeMsLocked(job)

View File

@@ -8733,7 +8733,6 @@ package android.app.job {
method public long getTriggerContentMaxDelay(); method public long getTriggerContentMaxDelay();
method public long getTriggerContentUpdateDelay(); method public long getTriggerContentUpdateDelay();
method @Nullable public android.app.job.JobInfo.TriggerContentUri[] getTriggerContentUris(); method @Nullable public android.app.job.JobInfo.TriggerContentUri[] getTriggerContentUris();
method public boolean isDataTransfer();
method public boolean isExpedited(); method public boolean isExpedited();
method public boolean isImportantWhileForeground(); method public boolean isImportantWhileForeground();
method public boolean isPeriodic(); method public boolean isPeriodic();
@@ -8770,7 +8769,6 @@ package android.app.job {
method public android.app.job.JobInfo build(); method public android.app.job.JobInfo build();
method public android.app.job.JobInfo.Builder setBackoffCriteria(long, int); method public android.app.job.JobInfo.Builder setBackoffCriteria(long, int);
method public android.app.job.JobInfo.Builder setClipData(@Nullable android.content.ClipData, int); method public android.app.job.JobInfo.Builder setClipData(@Nullable android.content.ClipData, int);
method @NonNull public android.app.job.JobInfo.Builder setDataTransfer(boolean);
method public android.app.job.JobInfo.Builder setEstimatedNetworkBytes(long, long); method public android.app.job.JobInfo.Builder setEstimatedNetworkBytes(long, long);
method @NonNull public android.app.job.JobInfo.Builder setExpedited(boolean); method @NonNull public android.app.job.JobInfo.Builder setExpedited(boolean);
method public android.app.job.JobInfo.Builder setExtras(@NonNull android.os.PersistableBundle); method public android.app.job.JobInfo.Builder setExtras(@NonNull android.os.PersistableBundle);

View File

@@ -234,15 +234,9 @@ public class JobSchedulerServiceTest {
createJobInfo(5).setPriority(JobInfo.PRIORITY_HIGH)); createJobInfo(5).setPriority(JobInfo.PRIORITY_HIGH));
JobStatus jobDef = createJobStatus("testGetMinJobExecutionGuaranteeMs", JobStatus jobDef = createJobStatus("testGetMinJobExecutionGuaranteeMs",
createJobInfo(6)); createJobInfo(6));
JobStatus jobDT = createJobStatus("testGetMinJobExecutionGuaranteeMs",
createJobInfo(7)
.setDataTransfer(true).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY));
JobStatus jobUI = createJobStatus("testGetMinJobExecutionGuaranteeMs",
createJobInfo(8)); // TODO(255371817): add setUserInitiated(true)
JobStatus jobUIDT = createJobStatus("testGetMinJobExecutionGuaranteeMs", JobStatus jobUIDT = createJobStatus("testGetMinJobExecutionGuaranteeMs",
// TODO(255371817): add setUserInitiated(true)
createJobInfo(9) createJobInfo(9)
.setDataTransfer(true).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)); .setUserInitiated(true).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY));
spyOn(ejMax); spyOn(ejMax);
spyOn(ejHigh); spyOn(ejHigh);
@@ -250,8 +244,6 @@ public class JobSchedulerServiceTest {
spyOn(ejHighDowngraded); spyOn(ejHighDowngraded);
spyOn(jobHigh); spyOn(jobHigh);
spyOn(jobDef); spyOn(jobDef);
spyOn(jobDT);
spyOn(jobUI);
spyOn(jobUIDT); spyOn(jobUIDT);
when(ejMax.shouldTreatAsExpeditedJob()).thenReturn(true); when(ejMax.shouldTreatAsExpeditedJob()).thenReturn(true);
@@ -260,14 +252,11 @@ public class JobSchedulerServiceTest {
when(ejHighDowngraded.shouldTreatAsExpeditedJob()).thenReturn(false); when(ejHighDowngraded.shouldTreatAsExpeditedJob()).thenReturn(false);
when(jobHigh.shouldTreatAsExpeditedJob()).thenReturn(false); when(jobHigh.shouldTreatAsExpeditedJob()).thenReturn(false);
when(jobDef.shouldTreatAsExpeditedJob()).thenReturn(false); when(jobDef.shouldTreatAsExpeditedJob()).thenReturn(false);
when(jobUI.shouldTreatAsUserInitiatedJob()).thenReturn(true);
when(jobUIDT.shouldTreatAsUserInitiatedJob()).thenReturn(true); when(jobUIDT.shouldTreatAsUserInitiatedJob()).thenReturn(true);
ConnectivityController connectivityController = mService.getConnectivityController(); ConnectivityController connectivityController = mService.getConnectivityController();
spyOn(connectivityController); spyOn(connectivityController);
mService.mConstants.RUNTIME_MIN_GUARANTEE_MS = 10 * MINUTE_IN_MILLIS; mService.mConstants.RUNTIME_MIN_GUARANTEE_MS = 10 * MINUTE_IN_MILLIS;
mService.mConstants.RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS = 15 * MINUTE_IN_MILLIS;
mService.mConstants.RUNTIME_DATA_TRANSFER_LIMIT_MS = 60 * MINUTE_IN_MILLIS;
mService.mConstants.RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR = 1.5f; mService.mConstants.RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_BUFFER_FACTOR = 1.5f;
mService.mConstants.RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS = HOUR_IN_MILLIS; mService.mConstants.RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS = HOUR_IN_MILLIS;
mService.mConstants.RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS = 6 * HOUR_IN_MILLIS; mService.mConstants.RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS = 6 * HOUR_IN_MILLIS;
@@ -284,37 +273,14 @@ public class JobSchedulerServiceTest {
mService.getMinJobExecutionGuaranteeMs(jobHigh)); mService.getMinJobExecutionGuaranteeMs(jobHigh));
assertEquals(mService.mConstants.RUNTIME_MIN_GUARANTEE_MS, assertEquals(mService.mConstants.RUNTIME_MIN_GUARANTEE_MS,
mService.getMinJobExecutionGuaranteeMs(jobDef)); mService.getMinJobExecutionGuaranteeMs(jobDef));
grantRunUserInitiatedJobsPermission(false); // Without permission
assertEquals(mService.mConstants.RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS,
mService.getMinJobExecutionGuaranteeMs(jobDT));
grantRunUserInitiatedJobsPermission(true); // With permission
doReturn(ConnectivityController.UNKNOWN_TIME)
.when(connectivityController).getEstimatedTransferTimeMs(any());
assertEquals(mService.mConstants.RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS,
mService.getMinJobExecutionGuaranteeMs(jobDT));
doReturn(mService.mConstants.RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS / 2)
.when(connectivityController).getEstimatedTransferTimeMs(any());
assertEquals(mService.mConstants.RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS,
mService.getMinJobExecutionGuaranteeMs(jobDT));
doReturn(mService.mConstants.RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS * 2)
.when(connectivityController).getEstimatedTransferTimeMs(any());
assertEquals(mService.mConstants.RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS,
mService.getMinJobExecutionGuaranteeMs(jobDT));
doReturn(mService.mConstants.RUNTIME_DATA_TRANSFER_LIMIT_MS * 2)
.when(connectivityController).getEstimatedTransferTimeMs(any());
assertEquals(mService.mConstants.RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS,
mService.getMinJobExecutionGuaranteeMs(jobDT));
// UserInitiated // UserInitiated
grantRunUserInitiatedJobsPermission(false); grantRunUserInitiatedJobsPermission(false);
// Permission isn't granted, so it should just be treated as a regular data transfer job.
assertEquals(mService.mConstants.RUNTIME_MIN_DATA_TRANSFER_GUARANTEE_MS,
mService.getMinJobExecutionGuaranteeMs(jobUIDT));
// Permission isn't granted, so it should just be treated as a regular job. // Permission isn't granted, so it should just be treated as a regular job.
assertEquals(mService.mConstants.RUNTIME_MIN_GUARANTEE_MS, assertEquals(mService.mConstants.RUNTIME_MIN_GUARANTEE_MS,
mService.getMinJobExecutionGuaranteeMs(jobUI)); mService.getMinJobExecutionGuaranteeMs(jobUIDT));
grantRunUserInitiatedJobsPermission(true); // With permission grantRunUserInitiatedJobsPermission(true); // With permission
assertEquals(mService.mConstants.RUNTIME_MIN_USER_INITIATED_GUARANTEE_MS, assertEquals(mService.mConstants.RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS,
mService.getMinJobExecutionGuaranteeMs(jobUI)); mService.getMinJobExecutionGuaranteeMs(jobUIDT));
doReturn(ConnectivityController.UNKNOWN_TIME) doReturn(ConnectivityController.UNKNOWN_TIME)
.when(connectivityController).getEstimatedTransferTimeMs(any()); .when(connectivityController).getEstimatedTransferTimeMs(any());
assertEquals(mService.mConstants.RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS, assertEquals(mService.mConstants.RUNTIME_MIN_USER_INITIATED_DATA_TRANSFER_GUARANTEE_MS,
@@ -338,21 +304,10 @@ public class JobSchedulerServiceTest {
@Test @Test
public void testGetMaxJobExecutionTimeMs() { public void testGetMaxJobExecutionTimeMs() {
JobStatus jobDT = createJobStatus("testGetMaxJobExecutionTimeMs",
createJobInfo(7)
.setDataTransfer(true).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY));
JobStatus jobUI = createJobStatus("testGetMaxJobExecutionTimeMs",
createJobInfo(9)); // TODO(255371817): add setUserInitiated(true)
JobStatus jobUIDT = createJobStatus("testGetMaxJobExecutionTimeMs", JobStatus jobUIDT = createJobStatus("testGetMaxJobExecutionTimeMs",
// TODO(255371817): add setUserInitiated(true)
createJobInfo(10) createJobInfo(10)
.setDataTransfer(true).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)); .setUserInitiated(true).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY));
spyOn(jobDT);
spyOn(jobUI);
spyOn(jobUIDT); spyOn(jobUIDT);
when(jobUI.shouldTreatAsUserInitiatedJob()).thenReturn(true);
when(jobUIDT.shouldTreatAsUserInitiatedJob()).thenReturn(true); when(jobUIDT.shouldTreatAsUserInitiatedJob()).thenReturn(true);
QuotaController quotaController = mService.getQuotaController(); QuotaController quotaController = mService.getQuotaController();
@@ -365,17 +320,9 @@ public class JobSchedulerServiceTest {
.when(quotaController).getMaxJobExecutionTimeMsLocked(any()); .when(quotaController).getMaxJobExecutionTimeMsLocked(any());
grantRunUserInitiatedJobsPermission(true); grantRunUserInitiatedJobsPermission(true);
assertEquals(mService.mConstants.RUNTIME_DATA_TRANSFER_LIMIT_MS,
mService.getMaxJobExecutionTimeMs(jobDT));
assertEquals(mService.mConstants.RUNTIME_USER_INITIATED_LIMIT_MS,
mService.getMaxJobExecutionTimeMs(jobUI));
assertEquals(mService.mConstants.RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS, assertEquals(mService.mConstants.RUNTIME_USER_INITIATED_DATA_TRANSFER_LIMIT_MS,
mService.getMaxJobExecutionTimeMs(jobUIDT)); mService.getMaxJobExecutionTimeMs(jobUIDT));
grantRunUserInitiatedJobsPermission(false); grantRunUserInitiatedJobsPermission(false);
assertEquals(mService.mConstants.RUNTIME_DATA_TRANSFER_LIMIT_MS,
mService.getMaxJobExecutionTimeMs(jobDT));
assertEquals(mService.mConstants.RUNTIME_FREE_QUOTA_MAX_LIMIT_MS,
mService.getMaxJobExecutionTimeMs(jobUI));
assertEquals(mService.mConstants.RUNTIME_FREE_QUOTA_MAX_LIMIT_MS, assertEquals(mService.mConstants.RUNTIME_FREE_QUOTA_MAX_LIMIT_MS,
mService.getMaxJobExecutionTimeMs(jobUIDT)); mService.getMaxJobExecutionTimeMs(jobUIDT));
} }
@@ -478,7 +425,8 @@ public class JobSchedulerServiceTest {
@Test @Test
public void testGetRescheduleJobForFailure_userStopped() { public void testGetRescheduleJobForFailure_userStopped() {
JobStatus uiJob = createJobStatus("testGetRescheduleJobForFailure", JobStatus uiJob = createJobStatus("testGetRescheduleJobForFailure",
createJobInfo().setUserInitiated(true)); createJobInfo().setUserInitiated(true)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY));
JobStatus uvJob = createJobStatus("testGetRescheduleJobForFailure", createJobInfo()); JobStatus uvJob = createJobStatus("testGetRescheduleJobForFailure", createJobInfo());
spyOn(uvJob); spyOn(uvJob);
doReturn(true).when(uvJob).isUserVisibleJob(); doReturn(true).when(uvJob).isUserVisibleJob();

View File

@@ -619,7 +619,7 @@ public class FlexibilityControllerTest {
@Test @Test
public void testExceptions_UserInitiated() { public void testExceptions_UserInitiated() {
JobInfo.Builder jb = createJob(0); JobInfo.Builder jb = createJob(0);
jb.setUserInitiated(true); jb.setUserInitiated(true).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
JobStatus js = createJobStatus("testExceptions_UserInitiated", jb); JobStatus js = createJobStatus("testExceptions_UserInitiated", jb);
assertFalse(js.hasFlexibilityConstraint()); assertFalse(js.hasFlexibilityConstraint());
} }

View File

@@ -170,6 +170,7 @@ public class JobStatusTest {
final JobInfo jobInfo = final JobInfo jobInfo =
new JobInfo.Builder(101, new ComponentName("foo", "bar")) new JobInfo.Builder(101, new ComponentName("foo", "bar"))
.setUserInitiated(true) .setUserInitiated(true)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.build(); .build();
JobStatus job = createJobStatus(jobInfo); JobStatus job = createJobStatus(jobInfo);
assertTrue(job.canRunInBatterySaver()); assertTrue(job.canRunInBatterySaver());
@@ -216,6 +217,7 @@ public class JobStatusTest {
final JobInfo jobInfo = final JobInfo jobInfo =
new JobInfo.Builder(101, new ComponentName("foo", "bar")) new JobInfo.Builder(101, new ComponentName("foo", "bar"))
.setUserInitiated(true) .setUserInitiated(true)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.build(); .build();
JobStatus job = createJobStatus(jobInfo); JobStatus job = createJobStatus(jobInfo);
assertTrue(job.canRunInDoze()); assertTrue(job.canRunInDoze());
@@ -236,6 +238,7 @@ public class JobStatusTest {
// User-initiated jobs are always user-visible unless they've been demoted. // User-initiated jobs are always user-visible unless they've been demoted.
jobInfo = new JobInfo.Builder(101, new ComponentName("foo", "bar")) jobInfo = new JobInfo.Builder(101, new ComponentName("foo", "bar"))
.setUserInitiated(true) .setUserInitiated(true)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.build(); .build();
job = createJobStatus(jobInfo); job = createJobStatus(jobInfo);
@@ -507,6 +510,7 @@ public class JobStatusTest {
jobInfo = new JobInfo.Builder(101, new ComponentName("foo", "bar")) jobInfo = new JobInfo.Builder(101, new ComponentName("foo", "bar"))
.setUserInitiated(true) .setUserInitiated(true)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.build(); .build();
job = createJobStatus(jobInfo); job = createJobStatus(jobInfo);

View File

@@ -16,6 +16,9 @@
package com.android.server.job; package com.android.server.job;
import static android.app.job.JobInfo.NETWORK_TYPE_ANY;
import static android.app.job.JobInfo.NETWORK_TYPE_NONE;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@@ -525,7 +528,9 @@ public class PendingJobQueueTest {
final boolean ui = random.nextBoolean(); final boolean ui = random.nextBoolean();
final boolean ej = !ui && random.nextBoolean(); final boolean ej = !ui && random.nextBoolean();
JobStatus job = createJobStatus("testPendingJobSorting_Random", JobStatus job = createJobStatus("testPendingJobSorting_Random",
createJobInfo(i).setExpedited(ej).setUserInitiated(ui), random.nextInt(250)); createJobInfo(i).setExpedited(ej).setUserInitiated(ui)
.setRequiredNetworkType(ui ? NETWORK_TYPE_ANY : NETWORK_TYPE_NONE),
random.nextInt(250));
job.enqueueTime = random.nextInt(1_000_000); job.enqueueTime = random.nextInt(1_000_000);
jobQueue.add(job); jobQueue.add(job);
} }
@@ -562,7 +567,9 @@ public class PendingJobQueueTest {
final boolean ui = random.nextBoolean(); final boolean ui = random.nextBoolean();
final boolean ej = !ui && random.nextBoolean(); final boolean ej = !ui && random.nextBoolean();
JobStatus job = createJobStatus("testPendingJobSortingTransitivity", JobStatus job = createJobStatus("testPendingJobSortingTransitivity",
createJobInfo(i).setExpedited(ej).setUserInitiated(ui), random.nextInt(50)); createJobInfo(i).setExpedited(ej).setUserInitiated(ui)
.setRequiredNetworkType(ui ? NETWORK_TYPE_ANY : NETWORK_TYPE_NONE),
random.nextInt(50));
job.enqueueTime = random.nextInt(1_000_000); job.enqueueTime = random.nextInt(1_000_000);
job.overrideState = random.nextInt(4); job.overrideState = random.nextInt(4);
jobQueue.add(job); jobQueue.add(job);
@@ -586,7 +593,8 @@ public class PendingJobQueueTest {
final boolean ui = random.nextFloat() < .02; final boolean ui = random.nextFloat() < .02;
final boolean ej = !ui && random.nextFloat() < .03; final boolean ej = !ui && random.nextFloat() < .03;
JobStatus job = createJobStatus("testPendingJobSortingTransitivity_Concentrated", JobStatus job = createJobStatus("testPendingJobSortingTransitivity_Concentrated",
createJobInfo(i).setExpedited(ej).setUserInitiated(ui), createJobInfo(i).setExpedited(ej).setUserInitiated(ui)
.setRequiredNetworkType(ui ? NETWORK_TYPE_ANY : NETWORK_TYPE_NONE),
random.nextInt(20)); random.nextInt(20));
job.enqueueTime = random.nextInt(250); job.enqueueTime = random.nextInt(250);
job.overrideState = random.nextFloat() < .01 job.overrideState = random.nextFloat() < .01