| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app.job; |
| 18 |
|
| 19 |
import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET; |
| 20 |
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_METERED; |
| 21 |
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED; |
| 22 |
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING; |
| 23 |
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VPN; |
| 24 |
import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED; |
| 25 |
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR; |
| 26 |
import static android.util.TimeUtils.formatDuration; |
| 27 |
|
| 28 |
import android.annotation.BytesLong; |
| 29 |
import android.annotation.IntDef; |
| 30 |
import android.annotation.NonNull; |
| 31 |
import android.annotation.Nullable; |
| 32 |
import android.annotation.RequiresPermission; |
| 33 |
import android.compat.Compatibility; |
| 34 |
import android.compat.annotation.ChangeId; |
| 35 |
import android.compat.annotation.EnabledSince; |
| 36 |
import android.compat.annotation.UnsupportedAppUsage; |
| 37 |
import android.content.ClipData; |
| 38 |
import android.content.ComponentName; |
| 39 |
import android.net.NetworkRequest; |
| 40 |
import android.net.NetworkSpecifier; |
| 41 |
import android.net.Uri; |
| 42 |
import android.os.BaseBundle; |
| 43 |
import android.os.Build; |
| 44 |
import android.os.Bundle; |
| 45 |
import android.os.Parcel; |
| 46 |
import android.os.Parcelable; |
| 47 |
import android.os.PersistableBundle; |
| 48 |
import android.util.Log; |
| 49 |
|
| 50 |
import java.lang.annotation.Retention; |
| 51 |
import java.lang.annotation.RetentionPolicy; |
| 52 |
import java.util.ArrayList; |
| 53 |
import java.util.Arrays; |
| 54 |
import java.util.Objects; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public class JobInfo implements Parcelable { |
| 68 |
private static String TAG = "JobInfo"; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
@ChangeId |
| 86 |
@EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 87 |
public static final long DISALLOW_DEADLINES_FOR_PREFETCH_JOBS = 194532703L; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
@ChangeId |
| 97 |
@EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 98 |
public static final long THROW_ON_INVALID_PRIORITY_VALUE = 140852299L; |
| 99 |
|
| 100 |
|
| 101 |
@IntDef(prefix = { "NETWORK_TYPE_" }, value = { |
| 102 |
NETWORK_TYPE_NONE, |
| 103 |
NETWORK_TYPE_ANY, |
| 104 |
NETWORK_TYPE_UNMETERED, |
| 105 |
NETWORK_TYPE_NOT_ROAMING, |
| 106 |
NETWORK_TYPE_CELLULAR, |
| 107 |
}) |
| 108 |
@Retention(RetentionPolicy.SOURCE) |
| 109 |
public @interface NetworkType {} |
| 110 |
|
| 111 |
|
| 112 |
public static final int NETWORK_TYPE_NONE = 0; |
| 113 |
|
| 114 |
public static final int NETWORK_TYPE_ANY = 1; |
| 115 |
|
| 116 |
public static final int NETWORK_TYPE_UNMETERED = 2; |
| 117 |
|
| 118 |
public static final int NETWORK_TYPE_NOT_ROAMING = 3; |
| 119 |
|
| 120 |
public static final int NETWORK_TYPE_CELLULAR = 4; |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
@Deprecated |
| 133 |
public static final int NETWORK_TYPE_METERED = NETWORK_TYPE_CELLULAR; |
| 134 |
|
| 135 |
|
| 136 |
public static final int NETWORK_BYTES_UNKNOWN = -1; |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
public static final long DEFAULT_INITIAL_BACKOFF_MILLIS = 30000L; |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
public static final long MAX_BACKOFF_DELAY_MILLIS = 5 * 60 * 60 * 1000; |
| 147 |
|
| 148 |
|
| 149 |
@IntDef(prefix = { "BACKOFF_POLICY_" }, value = { |
| 150 |
BACKOFF_POLICY_LINEAR, |
| 151 |
BACKOFF_POLICY_EXPONENTIAL, |
| 152 |
}) |
| 153 |
@Retention(RetentionPolicy.SOURCE) |
| 154 |
public @interface BackoffPolicy {} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
public static final int BACKOFF_POLICY_LINEAR = 0; |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
public static final int BACKOFF_POLICY_EXPONENTIAL = 1; |
| 172 |
|
| 173 |
|
| 174 |
private static final long MIN_PERIOD_MILLIS = 15 * 60 * 1000L; |
| 175 |
|
| 176 |
|
| 177 |
private static final long MIN_FLEX_MILLIS = 5 * 60 * 1000L; |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
public static final long MIN_BACKOFF_MILLIS = 10 * 1000L; |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
public static final long getMinPeriodMillis() { |
| 193 |
return MIN_PERIOD_MILLIS; |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
public static final long getMinFlexMillis() { |
| 204 |
return MIN_FLEX_MILLIS; |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
public static final long getMinBackoffMillis() { |
| 212 |
return MIN_BACKOFF_MILLIS; |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
public static final int DEFAULT_BACKOFF_POLICY = BACKOFF_POLICY_EXPONENTIAL; |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
public static final int PRIORITY_MIN = 100; |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
public static final int PRIORITY_LOW = 200; |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
public static final int PRIORITY_DEFAULT = 300; |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
public static final int PRIORITY_HIGH = 400; |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
public static final int PRIORITY_MAX = 500; |
| 269 |
|
| 270 |
|
| 271 |
@IntDef(prefix = {"PRIORITY_"}, value = { |
| 272 |
PRIORITY_MIN, |
| 273 |
PRIORITY_LOW, |
| 274 |
PRIORITY_DEFAULT, |
| 275 |
PRIORITY_HIGH, |
| 276 |
PRIORITY_MAX, |
| 277 |
}) |
| 278 |
@Retention(RetentionPolicy.SOURCE) |
| 279 |
public @interface Priority { |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
public static final int BIAS_DEFAULT = 0; |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
public static final int BIAS_SYNC_EXPEDITED = 10; |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
public static final int BIAS_SYNC_INITIALIZATION = 20; |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
public static final int BIAS_BOUND_FOREGROUND_SERVICE = 30; |
| 306 |
|
| 307 |
|
| 308 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 309 |
public static final int PRIORITY_FOREGROUND_APP = BIAS_BOUND_FOREGROUND_SERVICE; |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
public static final int BIAS_FOREGROUND_SERVICE = 35; |
| 317 |
|
| 318 |
|
| 319 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 320 |
public static final int PRIORITY_FOREGROUND_SERVICE = BIAS_FOREGROUND_SERVICE; |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
public static final int BIAS_TOP_APP = 40; |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
public static final int BIAS_ADJ_OFTEN_RUNNING = -40; |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
public static final int BIAS_ADJ_ALWAYS_RUNNING = -80; |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 359 |
public static final int FLAG_WILL_BE_FOREGROUND = 1 << 0; |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
public static final int FLAG_IMPORTANT_WHILE_FOREGROUND = 1 << 1; |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
public static final int FLAG_PREFETCH = 1 << 2; |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
public static final int FLAG_EXEMPT_FROM_APP_STANDBY = 1 << 3; |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
public static final int FLAG_EXPEDITED = 1 << 4; |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
public static final int CONSTRAINT_FLAG_CHARGING = 1 << 0; |
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
public static final int CONSTRAINT_FLAG_BATTERY_NOT_LOW = 1 << 1; |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
public static final int CONSTRAINT_FLAG_DEVICE_IDLE = 1 << 2; |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
public static final int CONSTRAINT_FLAG_STORAGE_NOT_LOW = 1 << 3; |
| 407 |
|
| 408 |
@UnsupportedAppUsage |
| 409 |
private final int jobId; |
| 410 |
private final PersistableBundle extras; |
| 411 |
private final Bundle transientExtras; |
| 412 |
private final ClipData clipData; |
| 413 |
private final int clipGrantFlags; |
| 414 |
@UnsupportedAppUsage |
| 415 |
private final ComponentName service; |
| 416 |
private final int constraintFlags; |
| 417 |
private final TriggerContentUri[] triggerContentUris; |
| 418 |
private final long triggerContentUpdateDelay; |
| 419 |
private final long triggerContentMaxDelay; |
| 420 |
private final boolean hasEarlyConstraint; |
| 421 |
private final boolean hasLateConstraint; |
| 422 |
private final NetworkRequest networkRequest; |
| 423 |
private final long networkDownloadBytes; |
| 424 |
private final long networkUploadBytes; |
| 425 |
private final long minimumNetworkChunkBytes; |
| 426 |
private final long minLatencyMillis; |
| 427 |
private final long maxExecutionDelayMillis; |
| 428 |
private final boolean isPeriodic; |
| 429 |
private final boolean isPersisted; |
| 430 |
private final long intervalMillis; |
| 431 |
private final long flexMillis; |
| 432 |
private final long initialBackoffMillis; |
| 433 |
private final int backoffPolicy; |
| 434 |
private final int mBias; |
| 435 |
@Priority |
| 436 |
private final int mPriority; |
| 437 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 438 |
private final int flags; |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
public int getId() { |
| 445 |
return jobId; |
| 446 |
} |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
public @NonNull PersistableBundle getExtras() { |
| 452 |
return extras; |
| 453 |
} |
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
public @NonNull Bundle getTransientExtras() { |
| 459 |
return transientExtras; |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
public @Nullable ClipData getClipData() { |
| 466 |
return clipData; |
| 467 |
} |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
public int getClipGrantFlags() { |
| 473 |
return clipGrantFlags; |
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
public @NonNull ComponentName getService() { |
| 480 |
return service; |
| 481 |
} |
| 482 |
|
| 483 |
|
| 484 |
public int getBias() { |
| 485 |
return mBias; |
| 486 |
} |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
@Priority |
| 492 |
public int getPriority() { |
| 493 |
return mPriority; |
| 494 |
} |
| 495 |
|
| 496 |
|
| 497 |
public int getFlags() { |
| 498 |
return flags; |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
public boolean isExemptedFromAppStandby() { |
| 503 |
return ((flags & FLAG_EXEMPT_FROM_APP_STANDBY) != 0) && !isPeriodic(); |
| 504 |
} |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
public boolean isRequireCharging() { |
| 510 |
return (constraintFlags & CONSTRAINT_FLAG_CHARGING) != 0; |
| 511 |
} |
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
public boolean isRequireBatteryNotLow() { |
| 517 |
return (constraintFlags & CONSTRAINT_FLAG_BATTERY_NOT_LOW) != 0; |
| 518 |
} |
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
public boolean isRequireDeviceIdle() { |
| 524 |
return (constraintFlags & CONSTRAINT_FLAG_DEVICE_IDLE) != 0; |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
public boolean isRequireStorageNotLow() { |
| 531 |
return (constraintFlags & CONSTRAINT_FLAG_STORAGE_NOT_LOW) != 0; |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
public int getConstraintFlags() { |
| 538 |
return constraintFlags; |
| 539 |
} |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
public @Nullable TriggerContentUri[] getTriggerContentUris() { |
| 547 |
return triggerContentUris; |
| 548 |
} |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
public long getTriggerContentUpdateDelay() { |
| 556 |
return triggerContentUpdateDelay; |
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
public long getTriggerContentMaxDelay() { |
| 565 |
return triggerContentMaxDelay; |
| 566 |
} |
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
@Deprecated |
| 578 |
public @NetworkType int getNetworkType() { |
| 579 |
if (networkRequest == null) { |
| 580 |
return NETWORK_TYPE_NONE; |
| 581 |
} else if (networkRequest.hasCapability(NET_CAPABILITY_NOT_METERED)) { |
| 582 |
return NETWORK_TYPE_UNMETERED; |
| 583 |
} else if (networkRequest.hasCapability(NET_CAPABILITY_NOT_ROAMING)) { |
| 584 |
return NETWORK_TYPE_NOT_ROAMING; |
| 585 |
} else if (networkRequest.hasTransport(TRANSPORT_CELLULAR)) { |
| 586 |
return NETWORK_TYPE_CELLULAR; |
| 587 |
} else { |
| 588 |
return NETWORK_TYPE_ANY; |
| 589 |
} |
| 590 |
} |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
public @Nullable NetworkRequest getRequiredNetwork() { |
| 599 |
return networkRequest; |
| 600 |
} |
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
public @BytesLong long getEstimatedNetworkDownloadBytes() { |
| 611 |
return networkDownloadBytes; |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
public @BytesLong long getEstimatedNetworkUploadBytes() { |
| 623 |
return networkUploadBytes; |
| 624 |
} |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
public @BytesLong long getMinimumNetworkChunkBytes() { |
| 634 |
return minimumNetworkChunkBytes; |
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
public long getMinLatencyMillis() { |
| 643 |
return minLatencyMillis; |
| 644 |
} |
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
public long getMaxExecutionDelayMillis() { |
| 650 |
return maxExecutionDelayMillis; |
| 651 |
} |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
public boolean isPeriodic() { |
| 659 |
return isPeriodic; |
| 660 |
} |
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
public boolean isPersisted() { |
| 666 |
return isPersisted; |
| 667 |
} |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
public long getIntervalMillis() { |
| 676 |
return intervalMillis; |
| 677 |
} |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
public long getFlexMillis() { |
| 686 |
return flexMillis; |
| 687 |
} |
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
public long getInitialBackoffMillis() { |
| 696 |
return initialBackoffMillis; |
| 697 |
} |
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
public @BackoffPolicy int getBackoffPolicy() { |
| 705 |
return backoffPolicy; |
| 706 |
} |
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
public boolean isExpedited() { |
| 712 |
return (flags & FLAG_EXPEDITED) != 0; |
| 713 |
} |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
public boolean isImportantWhileForeground() { |
| 719 |
return (flags & FLAG_IMPORTANT_WHILE_FOREGROUND) != 0; |
| 720 |
} |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
public boolean isPrefetch() { |
| 726 |
return (flags & FLAG_PREFETCH) != 0; |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
public boolean hasEarlyConstraint() { |
| 735 |
return hasEarlyConstraint; |
| 736 |
} |
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
public boolean hasLateConstraint() { |
| 744 |
return hasLateConstraint; |
| 745 |
} |
| 746 |
|
| 747 |
@Override |
| 748 |
public boolean equals(Object o) { |
| 749 |
if (!(o instanceof JobInfo)) { |
| 750 |
return false; |
| 751 |
} |
| 752 |
JobInfo j = (JobInfo) o; |
| 753 |
if (jobId != j.jobId) { |
| 754 |
return false; |
| 755 |
} |
| 756 |
|
| 757 |
if (!BaseBundle.kindofEquals(extras, j.extras)) { |
| 758 |
return false; |
| 759 |
} |
| 760 |
|
| 761 |
if (!BaseBundle.kindofEquals(transientExtras, j.transientExtras)) { |
| 762 |
return false; |
| 763 |
} |
| 764 |
|
| 765 |
|
| 766 |
if (clipData != j.clipData) { |
| 767 |
return false; |
| 768 |
} |
| 769 |
if (clipGrantFlags != j.clipGrantFlags) { |
| 770 |
return false; |
| 771 |
} |
| 772 |
if (!Objects.equals(service, j.service)) { |
| 773 |
return false; |
| 774 |
} |
| 775 |
if (constraintFlags != j.constraintFlags) { |
| 776 |
return false; |
| 777 |
} |
| 778 |
if (!Arrays.equals(triggerContentUris, j.triggerContentUris)) { |
| 779 |
return false; |
| 780 |
} |
| 781 |
if (triggerContentUpdateDelay != j.triggerContentUpdateDelay) { |
| 782 |
return false; |
| 783 |
} |
| 784 |
if (triggerContentMaxDelay != j.triggerContentMaxDelay) { |
| 785 |
return false; |
| 786 |
} |
| 787 |
if (hasEarlyConstraint != j.hasEarlyConstraint) { |
| 788 |
return false; |
| 789 |
} |
| 790 |
if (hasLateConstraint != j.hasLateConstraint) { |
| 791 |
return false; |
| 792 |
} |
| 793 |
if (!Objects.equals(networkRequest, j.networkRequest)) { |
| 794 |
return false; |
| 795 |
} |
| 796 |
if (networkDownloadBytes != j.networkDownloadBytes) { |
| 797 |
return false; |
| 798 |
} |
| 799 |
if (networkUploadBytes != j.networkUploadBytes) { |
| 800 |
return false; |
| 801 |
} |
| 802 |
if (minimumNetworkChunkBytes != j.minimumNetworkChunkBytes) { |
| 803 |
return false; |
| 804 |
} |
| 805 |
if (minLatencyMillis != j.minLatencyMillis) { |
| 806 |
return false; |
| 807 |
} |
| 808 |
if (maxExecutionDelayMillis != j.maxExecutionDelayMillis) { |
| 809 |
return false; |
| 810 |
} |
| 811 |
if (isPeriodic != j.isPeriodic) { |
| 812 |
return false; |
| 813 |
} |
| 814 |
if (isPersisted != j.isPersisted) { |
| 815 |
return false; |
| 816 |
} |
| 817 |
if (intervalMillis != j.intervalMillis) { |
| 818 |
return false; |
| 819 |
} |
| 820 |
if (flexMillis != j.flexMillis) { |
| 821 |
return false; |
| 822 |
} |
| 823 |
if (initialBackoffMillis != j.initialBackoffMillis) { |
| 824 |
return false; |
| 825 |
} |
| 826 |
if (backoffPolicy != j.backoffPolicy) { |
| 827 |
return false; |
| 828 |
} |
| 829 |
if (mBias != j.mBias) { |
| 830 |
return false; |
| 831 |
} |
| 832 |
if (mPriority != j.mPriority) { |
| 833 |
return false; |
| 834 |
} |
| 835 |
if (flags != j.flags) { |
| 836 |
return false; |
| 837 |
} |
| 838 |
return true; |
| 839 |
} |
| 840 |
|
| 841 |
@Override |
| 842 |
public int hashCode() { |
| 843 |
int hashCode = jobId; |
| 844 |
if (extras != null) { |
| 845 |
hashCode = 31 * hashCode + extras.hashCode(); |
| 846 |
} |
| 847 |
if (transientExtras != null) { |
| 848 |
hashCode = 31 * hashCode + transientExtras.hashCode(); |
| 849 |
} |
| 850 |
if (clipData != null) { |
| 851 |
hashCode = 31 * hashCode + clipData.hashCode(); |
| 852 |
} |
| 853 |
hashCode = 31*hashCode + clipGrantFlags; |
| 854 |
if (service != null) { |
| 855 |
hashCode = 31 * hashCode + service.hashCode(); |
| 856 |
} |
| 857 |
hashCode = 31 * hashCode + constraintFlags; |
| 858 |
if (triggerContentUris != null) { |
| 859 |
hashCode = 31 * hashCode + Arrays.hashCode(triggerContentUris); |
| 860 |
} |
| 861 |
hashCode = 31 * hashCode + Long.hashCode(triggerContentUpdateDelay); |
| 862 |
hashCode = 31 * hashCode + Long.hashCode(triggerContentMaxDelay); |
| 863 |
hashCode = 31 * hashCode + Boolean.hashCode(hasEarlyConstraint); |
| 864 |
hashCode = 31 * hashCode + Boolean.hashCode(hasLateConstraint); |
| 865 |
if (networkRequest != null) { |
| 866 |
hashCode = 31 * hashCode + networkRequest.hashCode(); |
| 867 |
} |
| 868 |
hashCode = 31 * hashCode + Long.hashCode(networkDownloadBytes); |
| 869 |
hashCode = 31 * hashCode + Long.hashCode(networkUploadBytes); |
| 870 |
hashCode = 31 * hashCode + Long.hashCode(minimumNetworkChunkBytes); |
| 871 |
hashCode = 31 * hashCode + Long.hashCode(minLatencyMillis); |
| 872 |
hashCode = 31 * hashCode + Long.hashCode(maxExecutionDelayMillis); |
| 873 |
hashCode = 31 * hashCode + Boolean.hashCode(isPeriodic); |
| 874 |
hashCode = 31 * hashCode + Boolean.hashCode(isPersisted); |
| 875 |
hashCode = 31 * hashCode + Long.hashCode(intervalMillis); |
| 876 |
hashCode = 31 * hashCode + Long.hashCode(flexMillis); |
| 877 |
hashCode = 31 * hashCode + Long.hashCode(initialBackoffMillis); |
| 878 |
hashCode = 31 * hashCode + backoffPolicy; |
| 879 |
hashCode = 31 * hashCode + mBias; |
| 880 |
hashCode = 31 * hashCode + mPriority; |
| 881 |
hashCode = 31 * hashCode + flags; |
| 882 |
return hashCode; |
| 883 |
} |
| 884 |
|
| 885 |
@SuppressWarnings("UnsafeParcelApi") |
| 886 |
private JobInfo(Parcel in) { |
| 887 |
jobId = in.readInt(); |
| 888 |
extras = in.readPersistableBundle(); |
| 889 |
transientExtras = in.readBundle(); |
| 890 |
if (in.readInt() != 0) { |
| 891 |
clipData = ClipData.CREATOR.createFromParcel(in); |
| 892 |
clipGrantFlags = in.readInt(); |
| 893 |
} else { |
| 894 |
clipData = null; |
| 895 |
clipGrantFlags = 0; |
| 896 |
} |
| 897 |
service = in.readParcelable(null); |
| 898 |
constraintFlags = in.readInt(); |
| 899 |
triggerContentUris = in.createTypedArray(TriggerContentUri.CREATOR); |
| 900 |
triggerContentUpdateDelay = in.readLong(); |
| 901 |
triggerContentMaxDelay = in.readLong(); |
| 902 |
if (in.readInt() != 0) { |
| 903 |
networkRequest = NetworkRequest.CREATOR.createFromParcel(in); |
| 904 |
} else { |
| 905 |
networkRequest = null; |
| 906 |
} |
| 907 |
networkDownloadBytes = in.readLong(); |
| 908 |
networkUploadBytes = in.readLong(); |
| 909 |
minimumNetworkChunkBytes = in.readLong(); |
| 910 |
minLatencyMillis = in.readLong(); |
| 911 |
maxExecutionDelayMillis = in.readLong(); |
| 912 |
isPeriodic = in.readInt() == 1; |
| 913 |
isPersisted = in.readInt() == 1; |
| 914 |
intervalMillis = in.readLong(); |
| 915 |
flexMillis = in.readLong(); |
| 916 |
initialBackoffMillis = in.readLong(); |
| 917 |
backoffPolicy = in.readInt(); |
| 918 |
hasEarlyConstraint = in.readInt() == 1; |
| 919 |
hasLateConstraint = in.readInt() == 1; |
| 920 |
mBias = in.readInt(); |
| 921 |
mPriority = in.readInt(); |
| 922 |
flags = in.readInt(); |
| 923 |
} |
| 924 |
|
| 925 |
private JobInfo(JobInfo.Builder b) { |
| 926 |
jobId = b.mJobId; |
| 927 |
extras = b.mExtras.deepCopy(); |
| 928 |
transientExtras = b.mTransientExtras.deepCopy(); |
| 929 |
clipData = b.mClipData; |
| 930 |
clipGrantFlags = b.mClipGrantFlags; |
| 931 |
service = b.mJobService; |
| 932 |
constraintFlags = b.mConstraintFlags; |
| 933 |
triggerContentUris = b.mTriggerContentUris != null |
| 934 |
? b.mTriggerContentUris.toArray(new TriggerContentUri[b.mTriggerContentUris.size()]) |
| 935 |
: null; |
| 936 |
triggerContentUpdateDelay = b.mTriggerContentUpdateDelay; |
| 937 |
triggerContentMaxDelay = b.mTriggerContentMaxDelay; |
| 938 |
networkRequest = b.mNetworkRequest; |
| 939 |
networkDownloadBytes = b.mNetworkDownloadBytes; |
| 940 |
networkUploadBytes = b.mNetworkUploadBytes; |
| 941 |
minimumNetworkChunkBytes = b.mMinimumNetworkChunkBytes; |
| 942 |
minLatencyMillis = b.mMinLatencyMillis; |
| 943 |
maxExecutionDelayMillis = b.mMaxExecutionDelayMillis; |
| 944 |
isPeriodic = b.mIsPeriodic; |
| 945 |
isPersisted = b.mIsPersisted; |
| 946 |
intervalMillis = b.mIntervalMillis; |
| 947 |
flexMillis = b.mFlexMillis; |
| 948 |
initialBackoffMillis = b.mInitialBackoffMillis; |
| 949 |
backoffPolicy = b.mBackoffPolicy; |
| 950 |
hasEarlyConstraint = b.mHasEarlyConstraint; |
| 951 |
hasLateConstraint = b.mHasLateConstraint; |
| 952 |
mBias = b.mBias; |
| 953 |
mPriority = b.mPriority; |
| 954 |
flags = b.mFlags; |
| 955 |
} |
| 956 |
|
| 957 |
@Override |
| 958 |
public int describeContents() { |
| 959 |
return 0; |
| 960 |
} |
| 961 |
|
| 962 |
@Override |
| 963 |
public void writeToParcel(Parcel out, int flags) { |
| 964 |
out.writeInt(jobId); |
| 965 |
out.writePersistableBundle(extras); |
| 966 |
out.writeBundle(transientExtras); |
| 967 |
if (clipData != null) { |
| 968 |
out.writeInt(1); |
| 969 |
clipData.writeToParcel(out, flags); |
| 970 |
out.writeInt(clipGrantFlags); |
| 971 |
} else { |
| 972 |
out.writeInt(0); |
| 973 |
} |
| 974 |
out.writeParcelable(service, flags); |
| 975 |
out.writeInt(constraintFlags); |
| 976 |
out.writeTypedArray(triggerContentUris, flags); |
| 977 |
out.writeLong(triggerContentUpdateDelay); |
| 978 |
out.writeLong(triggerContentMaxDelay); |
| 979 |
if (networkRequest != null) { |
| 980 |
out.writeInt(1); |
| 981 |
networkRequest.writeToParcel(out, flags); |
| 982 |
} else { |
| 983 |
out.writeInt(0); |
| 984 |
} |
| 985 |
out.writeLong(networkDownloadBytes); |
| 986 |
out.writeLong(networkUploadBytes); |
| 987 |
out.writeLong(minimumNetworkChunkBytes); |
| 988 |
out.writeLong(minLatencyMillis); |
| 989 |
out.writeLong(maxExecutionDelayMillis); |
| 990 |
out.writeInt(isPeriodic ? 1 : 0); |
| 991 |
out.writeInt(isPersisted ? 1 : 0); |
| 992 |
out.writeLong(intervalMillis); |
| 993 |
out.writeLong(flexMillis); |
| 994 |
out.writeLong(initialBackoffMillis); |
| 995 |
out.writeInt(backoffPolicy); |
| 996 |
out.writeInt(hasEarlyConstraint ? 1 : 0); |
| 997 |
out.writeInt(hasLateConstraint ? 1 : 0); |
| 998 |
out.writeInt(mBias); |
| 999 |
out.writeInt(mPriority); |
| 1000 |
out.writeInt(this.flags); |
| 1001 |
} |
| 1002 |
|
| 1003 |
public static final @android.annotation.NonNull Creator<JobInfo> CREATOR = new Creator<JobInfo>() { |
| 1004 |
@Override |
| 1005 |
public JobInfo createFromParcel(Parcel in) { |
| 1006 |
return new JobInfo(in); |
| 1007 |
} |
| 1008 |
|
| 1009 |
@Override |
| 1010 |
public JobInfo[] newArray(int size) { |
| 1011 |
return new JobInfo[size]; |
| 1012 |
} |
| 1013 |
}; |
| 1014 |
|
| 1015 |
@Override |
| 1016 |
public String toString() { |
| 1017 |
return "(job:" + jobId + "/" + service.flattenToShortString() + ")"; |
| 1018 |
} |
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
public static final class TriggerContentUri implements Parcelable { |
| 1025 |
private final Uri mUri; |
| 1026 |
private final int mFlags; |
| 1027 |
|
| 1028 |
|
| 1029 |
@Retention(RetentionPolicy.SOURCE) |
| 1030 |
@IntDef(flag = true, prefix = { "FLAG_" }, value = { |
| 1031 |
FLAG_NOTIFY_FOR_DESCENDANTS, |
| 1032 |
}) |
| 1033 |
public @interface Flags { } |
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
public static final int FLAG_NOTIFY_FOR_DESCENDANTS = 1<<0; |
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
public TriggerContentUri(@NonNull Uri uri, @Flags int flags) { |
| 1048 |
mUri = Objects.requireNonNull(uri); |
| 1049 |
mFlags = flags; |
| 1050 |
} |
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
public Uri getUri() { |
| 1056 |
return mUri; |
| 1057 |
} |
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
public @Flags int getFlags() { |
| 1063 |
return mFlags; |
| 1064 |
} |
| 1065 |
|
| 1066 |
@Override |
| 1067 |
public boolean equals(Object o) { |
| 1068 |
if (!(o instanceof TriggerContentUri)) { |
| 1069 |
return false; |
| 1070 |
} |
| 1071 |
TriggerContentUri t = (TriggerContentUri) o; |
| 1072 |
return Objects.equals(t.mUri, mUri) && t.mFlags == mFlags; |
| 1073 |
} |
| 1074 |
|
| 1075 |
@Override |
| 1076 |
public int hashCode() { |
| 1077 |
return (mUri == null ? 0 : mUri.hashCode()) ^ mFlags; |
| 1078 |
} |
| 1079 |
|
| 1080 |
private TriggerContentUri(Parcel in) { |
| 1081 |
mUri = Uri.CREATOR.createFromParcel(in); |
| 1082 |
mFlags = in.readInt(); |
| 1083 |
} |
| 1084 |
|
| 1085 |
@Override |
| 1086 |
public int describeContents() { |
| 1087 |
return 0; |
| 1088 |
} |
| 1089 |
|
| 1090 |
@Override |
| 1091 |
public void writeToParcel(Parcel out, int flags) { |
| 1092 |
mUri.writeToParcel(out, flags); |
| 1093 |
out.writeInt(mFlags); |
| 1094 |
} |
| 1095 |
|
| 1096 |
public static final @android.annotation.NonNull Creator<TriggerContentUri> CREATOR = new Creator<TriggerContentUri>() { |
| 1097 |
@Override |
| 1098 |
public TriggerContentUri createFromParcel(Parcel in) { |
| 1099 |
return new TriggerContentUri(in); |
| 1100 |
} |
| 1101 |
|
| 1102 |
@Override |
| 1103 |
public TriggerContentUri[] newArray(int size) { |
| 1104 |
return new TriggerContentUri[size]; |
| 1105 |
} |
| 1106 |
}; |
| 1107 |
} |
| 1108 |
|
| 1109 |
|
| 1110 |
public static final class Builder { |
| 1111 |
private final int mJobId; |
| 1112 |
private final ComponentName mJobService; |
| 1113 |
private PersistableBundle mExtras = PersistableBundle.EMPTY; |
| 1114 |
private Bundle mTransientExtras = Bundle.EMPTY; |
| 1115 |
private ClipData mClipData; |
| 1116 |
private int mClipGrantFlags; |
| 1117 |
private int mBias = BIAS_DEFAULT; |
| 1118 |
@Priority |
| 1119 |
private int mPriority = PRIORITY_DEFAULT; |
| 1120 |
private int mFlags; |
| 1121 |
|
| 1122 |
private int mConstraintFlags; |
| 1123 |
private NetworkRequest mNetworkRequest; |
| 1124 |
private long mNetworkDownloadBytes = NETWORK_BYTES_UNKNOWN; |
| 1125 |
private long mNetworkUploadBytes = NETWORK_BYTES_UNKNOWN; |
| 1126 |
private long mMinimumNetworkChunkBytes = NETWORK_BYTES_UNKNOWN; |
| 1127 |
private ArrayList<TriggerContentUri> mTriggerContentUris; |
| 1128 |
private long mTriggerContentUpdateDelay = -1; |
| 1129 |
private long mTriggerContentMaxDelay = -1; |
| 1130 |
private boolean mIsPersisted; |
| 1131 |
|
| 1132 |
private long mMinLatencyMillis; |
| 1133 |
private long mMaxExecutionDelayMillis; |
| 1134 |
|
| 1135 |
private boolean mIsPeriodic; |
| 1136 |
private boolean mHasEarlyConstraint; |
| 1137 |
private boolean mHasLateConstraint; |
| 1138 |
private long mIntervalMillis; |
| 1139 |
private long mFlexMillis; |
| 1140 |
|
| 1141 |
private long mInitialBackoffMillis = DEFAULT_INITIAL_BACKOFF_MILLIS; |
| 1142 |
private int mBackoffPolicy = DEFAULT_BACKOFF_POLICY; |
| 1143 |
|
| 1144 |
private boolean mBackoffPolicySet = false; |
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
public Builder(int jobId, @NonNull ComponentName jobService) { |
| 1158 |
mJobService = jobService; |
| 1159 |
mJobId = jobId; |
| 1160 |
} |
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
public Builder(@NonNull JobInfo job) { |
| 1167 |
mJobId = job.getId(); |
| 1168 |
mJobService = job.getService(); |
| 1169 |
mExtras = job.getExtras(); |
| 1170 |
mTransientExtras = job.getTransientExtras(); |
| 1171 |
mClipData = job.getClipData(); |
| 1172 |
mClipGrantFlags = job.getClipGrantFlags(); |
| 1173 |
mBias = job.getBias(); |
| 1174 |
mFlags = job.getFlags(); |
| 1175 |
mConstraintFlags = job.getConstraintFlags(); |
| 1176 |
mNetworkRequest = job.getRequiredNetwork(); |
| 1177 |
mNetworkDownloadBytes = job.getEstimatedNetworkDownloadBytes(); |
| 1178 |
mNetworkUploadBytes = job.getEstimatedNetworkUploadBytes(); |
| 1179 |
mMinimumNetworkChunkBytes = job.getMinimumNetworkChunkBytes(); |
| 1180 |
mTriggerContentUris = job.getTriggerContentUris() != null |
| 1181 |
? new ArrayList<>(Arrays.asList(job.getTriggerContentUris())) : null; |
| 1182 |
mTriggerContentUpdateDelay = job.getTriggerContentUpdateDelay(); |
| 1183 |
mTriggerContentMaxDelay = job.getTriggerContentMaxDelay(); |
| 1184 |
mIsPersisted = job.isPersisted(); |
| 1185 |
mMinLatencyMillis = job.getMinLatencyMillis(); |
| 1186 |
mMaxExecutionDelayMillis = job.getMaxExecutionDelayMillis(); |
| 1187 |
mIsPeriodic = job.isPeriodic(); |
| 1188 |
mHasEarlyConstraint = job.hasEarlyConstraint(); |
| 1189 |
mHasLateConstraint = job.hasLateConstraint(); |
| 1190 |
mIntervalMillis = job.getIntervalMillis(); |
| 1191 |
mFlexMillis = job.getFlexMillis(); |
| 1192 |
mInitialBackoffMillis = job.getInitialBackoffMillis(); |
| 1193 |
|
| 1194 |
|
| 1195 |
mBackoffPolicy = job.getBackoffPolicy(); |
| 1196 |
mPriority = job.getPriority(); |
| 1197 |
} |
| 1198 |
|
| 1199 |
|
| 1200 |
@NonNull |
| 1201 |
public Builder setBias(int bias) { |
| 1202 |
mBias = bias; |
| 1203 |
return this; |
| 1204 |
} |
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
@NonNull |
| 1225 |
public Builder setPriority(@Priority int priority) { |
| 1226 |
if (priority > PRIORITY_MAX || priority < PRIORITY_MIN) { |
| 1227 |
if (Compatibility.isChangeEnabled(THROW_ON_INVALID_PRIORITY_VALUE)) { |
| 1228 |
throw new IllegalArgumentException("Invalid priority value"); |
| 1229 |
} |
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
return this; |
| 1234 |
} |
| 1235 |
mPriority = priority; |
| 1236 |
return this; |
| 1237 |
} |
| 1238 |
|
| 1239 |
|
| 1240 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 1241 |
public Builder setFlags(int flags) { |
| 1242 |
mFlags = flags; |
| 1243 |
return this; |
| 1244 |
} |
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
public Builder setExtras(@NonNull PersistableBundle extras) { |
| 1252 |
mExtras = extras; |
| 1253 |
return this; |
| 1254 |
} |
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
public Builder setTransientExtras(@NonNull Bundle extras) { |
| 1267 |
mTransientExtras = extras; |
| 1268 |
return this; |
| 1269 |
} |
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
public Builder setClipData(@Nullable ClipData clip, int grantFlags) { |
| 1296 |
mClipData = clip; |
| 1297 |
mClipGrantFlags = grantFlags; |
| 1298 |
return this; |
| 1299 |
} |
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
public Builder setRequiredNetworkType(@NetworkType int networkType) { |
| 1327 |
if (networkType == NETWORK_TYPE_NONE) { |
| 1328 |
return setRequiredNetwork(null); |
| 1329 |
} else { |
| 1330 |
final NetworkRequest.Builder builder = new NetworkRequest.Builder(); |
| 1331 |
|
| 1332 |
|
| 1333 |
builder.addCapability(NET_CAPABILITY_INTERNET); |
| 1334 |
builder.addCapability(NET_CAPABILITY_VALIDATED); |
| 1335 |
builder.removeCapability(NET_CAPABILITY_NOT_VPN); |
| 1336 |
builder.removeCapability(NET_CAPABILITY_NOT_RESTRICTED); |
| 1337 |
|
| 1338 |
if (networkType == NETWORK_TYPE_ANY) { |
| 1339 |
|
| 1340 |
} else if (networkType == NETWORK_TYPE_UNMETERED) { |
| 1341 |
builder.addCapability(NET_CAPABILITY_NOT_METERED); |
| 1342 |
} else if (networkType == NETWORK_TYPE_NOT_ROAMING) { |
| 1343 |
builder.addCapability(NET_CAPABILITY_NOT_ROAMING); |
| 1344 |
} else if (networkType == NETWORK_TYPE_CELLULAR) { |
| 1345 |
builder.addTransportType(TRANSPORT_CELLULAR); |
| 1346 |
} |
| 1347 |
|
| 1348 |
return setRequiredNetwork(builder.build()); |
| 1349 |
} |
| 1350 |
} |
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
public Builder setRequiredNetwork(@Nullable NetworkRequest networkRequest) { |
| 1380 |
mNetworkRequest = networkRequest; |
| 1381 |
return this; |
| 1382 |
} |
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
public Builder setEstimatedNetworkBytes(@BytesLong long downloadBytes, |
| 1435 |
@BytesLong long uploadBytes) { |
| 1436 |
mNetworkDownloadBytes = downloadBytes; |
| 1437 |
mNetworkUploadBytes = uploadBytes; |
| 1438 |
return this; |
| 1439 |
} |
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
@NonNull |
| 1466 |
public Builder setMinimumNetworkChunkBytes(@BytesLong long chunkSizeBytes) { |
| 1467 |
if (chunkSizeBytes != NETWORK_BYTES_UNKNOWN && chunkSizeBytes <= 0) { |
| 1468 |
throw new IllegalArgumentException("Minimum chunk size must be positive"); |
| 1469 |
} |
| 1470 |
mMinimumNetworkChunkBytes = chunkSizeBytes; |
| 1471 |
return this; |
| 1472 |
} |
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
public Builder setRequiresCharging(boolean requiresCharging) { |
| 1491 |
mConstraintFlags = (mConstraintFlags&~CONSTRAINT_FLAG_CHARGING) |
| 1492 |
| (requiresCharging ? CONSTRAINT_FLAG_CHARGING : 0); |
| 1493 |
return this; |
| 1494 |
} |
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
public Builder setRequiresBatteryNotLow(boolean batteryNotLow) { |
| 1505 |
mConstraintFlags = (mConstraintFlags&~CONSTRAINT_FLAG_BATTERY_NOT_LOW) |
| 1506 |
| (batteryNotLow ? CONSTRAINT_FLAG_BATTERY_NOT_LOW : 0); |
| 1507 |
return this; |
| 1508 |
} |
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
public Builder setRequiresDeviceIdle(boolean requiresDeviceIdle) { |
| 1530 |
mConstraintFlags = (mConstraintFlags&~CONSTRAINT_FLAG_DEVICE_IDLE) |
| 1531 |
| (requiresDeviceIdle ? CONSTRAINT_FLAG_DEVICE_IDLE : 0); |
| 1532 |
return this; |
| 1533 |
} |
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
public Builder setRequiresStorageNotLow(boolean storageNotLow) { |
| 1544 |
mConstraintFlags = (mConstraintFlags&~CONSTRAINT_FLAG_STORAGE_NOT_LOW) |
| 1545 |
| (storageNotLow ? CONSTRAINT_FLAG_STORAGE_NOT_LOW : 0); |
| 1546 |
return this; |
| 1547 |
} |
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
public Builder addTriggerContentUri(@NonNull TriggerContentUri uri) { |
| 1591 |
if (mTriggerContentUris == null) { |
| 1592 |
mTriggerContentUris = new ArrayList<>(); |
| 1593 |
} |
| 1594 |
mTriggerContentUris.add(uri); |
| 1595 |
return this; |
| 1596 |
} |
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
public Builder setTriggerContentUpdateDelay(long durationMs) { |
| 1606 |
mTriggerContentUpdateDelay = durationMs; |
| 1607 |
return this; |
| 1608 |
} |
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
public Builder setTriggerContentMaxDelay(long durationMs) { |
| 1617 |
mTriggerContentMaxDelay = durationMs; |
| 1618 |
return this; |
| 1619 |
} |
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
public Builder setPeriodic(long intervalMillis) { |
| 1634 |
return setPeriodic(intervalMillis, intervalMillis); |
| 1635 |
} |
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
public Builder setPeriodic(long intervalMillis, long flexMillis) { |
| 1649 |
final long minPeriod = getMinPeriodMillis(); |
| 1650 |
if (intervalMillis < minPeriod) { |
| 1651 |
Log.w(TAG, "Requested interval " + formatDuration(intervalMillis) + " for job " |
| 1652 |
+ mJobId + " is too small; raising to " + formatDuration(minPeriod)); |
| 1653 |
intervalMillis = minPeriod; |
| 1654 |
} |
| 1655 |
|
| 1656 |
final long percentClamp = 5 * intervalMillis / 100; |
| 1657 |
final long minFlex = Math.max(percentClamp, getMinFlexMillis()); |
| 1658 |
if (flexMillis < minFlex) { |
| 1659 |
Log.w(TAG, "Requested flex " + formatDuration(flexMillis) + " for job " + mJobId |
| 1660 |
+ " is too small; raising to " + formatDuration(minFlex)); |
| 1661 |
flexMillis = minFlex; |
| 1662 |
} |
| 1663 |
|
| 1664 |
mIsPeriodic = true; |
| 1665 |
mIntervalMillis = intervalMillis; |
| 1666 |
mFlexMillis = flexMillis; |
| 1667 |
mHasEarlyConstraint = mHasLateConstraint = true; |
| 1668 |
return this; |
| 1669 |
} |
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
public Builder setMinimumLatency(long minLatencyMillis) { |
| 1684 |
mMinLatencyMillis = minLatencyMillis; |
| 1685 |
mHasEarlyConstraint = true; |
| 1686 |
return this; |
| 1687 |
} |
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
public Builder setOverrideDeadline(long maxExecutionDelayMillis) { |
| 1700 |
mMaxExecutionDelayMillis = maxExecutionDelayMillis; |
| 1701 |
mHasLateConstraint = true; |
| 1702 |
return this; |
| 1703 |
} |
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
public Builder setBackoffCriteria(long initialBackoffMillis, |
| 1722 |
@BackoffPolicy int backoffPolicy) { |
| 1723 |
final long minBackoff = getMinBackoffMillis(); |
| 1724 |
if (initialBackoffMillis < minBackoff) { |
| 1725 |
Log.w(TAG, "Requested backoff " + formatDuration(initialBackoffMillis) + " for job " |
| 1726 |
+ mJobId + " is too small; raising to " + formatDuration(minBackoff)); |
| 1727 |
initialBackoffMillis = minBackoff; |
| 1728 |
} |
| 1729 |
|
| 1730 |
mBackoffPolicySet = true; |
| 1731 |
mInitialBackoffMillis = initialBackoffMillis; |
| 1732 |
mBackoffPolicy = backoffPolicy; |
| 1733 |
return this; |
| 1734 |
} |
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
@NonNull |
| 1785 |
public Builder setExpedited(boolean expedited) { |
| 1786 |
if (expedited) { |
| 1787 |
mFlags |= FLAG_EXPEDITED; |
| 1788 |
if (mPriority == PRIORITY_DEFAULT) { |
| 1789 |
|
| 1790 |
|
| 1791 |
mPriority = PRIORITY_MAX; |
| 1792 |
} |
| 1793 |
} else { |
| 1794 |
if (mPriority == PRIORITY_MAX && (mFlags & FLAG_EXPEDITED) != 0) { |
| 1795 |
|
| 1796 |
|
| 1797 |
mPriority = PRIORITY_DEFAULT; |
| 1798 |
} |
| 1799 |
mFlags &= (~FLAG_EXPEDITED); |
| 1800 |
} |
| 1801 |
return this; |
| 1802 |
} |
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
@Deprecated |
| 1825 |
public Builder setImportantWhileForeground(boolean importantWhileForeground) { |
| 1826 |
if (importantWhileForeground) { |
| 1827 |
mFlags |= FLAG_IMPORTANT_WHILE_FOREGROUND; |
| 1828 |
if (mPriority == PRIORITY_DEFAULT) { |
| 1829 |
|
| 1830 |
|
| 1831 |
mPriority = PRIORITY_HIGH; |
| 1832 |
} |
| 1833 |
} else { |
| 1834 |
if (mPriority == PRIORITY_HIGH |
| 1835 |
&& (mFlags & FLAG_IMPORTANT_WHILE_FOREGROUND) != 0) { |
| 1836 |
|
| 1837 |
|
| 1838 |
mPriority = PRIORITY_DEFAULT; |
| 1839 |
} |
| 1840 |
mFlags &= (~FLAG_IMPORTANT_WHILE_FOREGROUND); |
| 1841 |
} |
| 1842 |
return this; |
| 1843 |
} |
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
|
| 1863 |
public Builder setPrefetch(boolean prefetch) { |
| 1864 |
if (prefetch) { |
| 1865 |
mFlags |= FLAG_PREFETCH; |
| 1866 |
} else { |
| 1867 |
mFlags &= (~FLAG_PREFETCH); |
| 1868 |
} |
| 1869 |
return this; |
| 1870 |
} |
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
@RequiresPermission(android.Manifest.permission.RECEIVE_BOOT_COMPLETED) |
| 1880 |
public Builder setPersisted(boolean isPersisted) { |
| 1881 |
mIsPersisted = isPersisted; |
| 1882 |
return this; |
| 1883 |
} |
| 1884 |
|
| 1885 |
|
| 1886 |
|
| 1887 |
|
| 1888 |
public JobInfo build() { |
| 1889 |
return build(Compatibility.isChangeEnabled(DISALLOW_DEADLINES_FOR_PREFETCH_JOBS)); |
| 1890 |
} |
| 1891 |
|
| 1892 |
|
| 1893 |
public JobInfo build(boolean disallowPrefetchDeadlines) { |
| 1894 |
|
| 1895 |
|
| 1896 |
if (mBackoffPolicySet && (mConstraintFlags & CONSTRAINT_FLAG_DEVICE_IDLE) != 0) { |
| 1897 |
throw new IllegalArgumentException("An idle mode job will not respect any" + |
| 1898 |
" back-off policy, so calling setBackoffCriteria with" + |
| 1899 |
" setRequiresDeviceIdle is an error."); |
| 1900 |
} |
| 1901 |
JobInfo jobInfo = new JobInfo(this); |
| 1902 |
jobInfo.enforceValidity(disallowPrefetchDeadlines); |
| 1903 |
return jobInfo; |
| 1904 |
} |
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
public String summarize() { |
| 1910 |
final String service = (mJobService != null) |
| 1911 |
? mJobService.flattenToShortString() |
| 1912 |
: "null"; |
| 1913 |
return "JobInfo.Builder{job:" + mJobId + "/" + service + "}"; |
| 1914 |
} |
| 1915 |
} |
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
public final void enforceValidity(boolean disallowPrefetchDeadlines) { |
| 1921 |
|
| 1922 |
if ((networkDownloadBytes > 0 || networkUploadBytes > 0 || minimumNetworkChunkBytes > 0) |
| 1923 |
&& networkRequest == null) { |
| 1924 |
throw new IllegalArgumentException( |
| 1925 |
"Can't provide estimated network usage without requiring a network"); |
| 1926 |
} |
| 1927 |
final long estimatedTransfer; |
| 1928 |
if (networkUploadBytes == NETWORK_BYTES_UNKNOWN) { |
| 1929 |
estimatedTransfer = networkDownloadBytes; |
| 1930 |
} else { |
| 1931 |
estimatedTransfer = networkUploadBytes |
| 1932 |
+ (networkDownloadBytes == NETWORK_BYTES_UNKNOWN ? 0 : networkDownloadBytes); |
| 1933 |
} |
| 1934 |
if (minimumNetworkChunkBytes != NETWORK_BYTES_UNKNOWN |
| 1935 |
&& estimatedTransfer != NETWORK_BYTES_UNKNOWN |
| 1936 |
&& minimumNetworkChunkBytes > estimatedTransfer) { |
| 1937 |
throw new IllegalArgumentException( |
| 1938 |
"Minimum chunk size can't be greater than estimated network usage"); |
| 1939 |
} |
| 1940 |
if (minimumNetworkChunkBytes != NETWORK_BYTES_UNKNOWN && minimumNetworkChunkBytes <= 0) { |
| 1941 |
throw new IllegalArgumentException("Minimum chunk size must be positive"); |
| 1942 |
} |
| 1943 |
|
| 1944 |
final boolean hasDeadline = maxExecutionDelayMillis != 0L; |
| 1945 |
|
| 1946 |
if (isPeriodic) { |
| 1947 |
if (hasDeadline) { |
| 1948 |
throw new IllegalArgumentException( |
| 1949 |
"Can't call setOverrideDeadline() on a periodic job."); |
| 1950 |
} |
| 1951 |
if (minLatencyMillis != 0L) { |
| 1952 |
throw new IllegalArgumentException( |
| 1953 |
"Can't call setMinimumLatency() on a periodic job"); |
| 1954 |
} |
| 1955 |
if (triggerContentUris != null) { |
| 1956 |
throw new IllegalArgumentException( |
| 1957 |
"Can't call addTriggerContentUri() on a periodic job"); |
| 1958 |
} |
| 1959 |
} |
| 1960 |
|
| 1961 |
|
| 1962 |
if (disallowPrefetchDeadlines && hasDeadline && (flags & FLAG_PREFETCH) != 0) { |
| 1963 |
throw new IllegalArgumentException( |
| 1964 |
"Can't call setOverrideDeadline() on a prefetch job."); |
| 1965 |
} |
| 1966 |
|
| 1967 |
if (isPersisted) { |
| 1968 |
|
| 1969 |
if (networkRequest != null |
| 1970 |
&& networkRequest.getNetworkSpecifier() != null) { |
| 1971 |
throw new IllegalArgumentException( |
| 1972 |
"Network specifiers aren't supported for persistent jobs"); |
| 1973 |
} |
| 1974 |
if (triggerContentUris != null) { |
| 1975 |
throw new IllegalArgumentException( |
| 1976 |
"Can't call addTriggerContentUri() on a persisted job"); |
| 1977 |
} |
| 1978 |
if (!transientExtras.isEmpty()) { |
| 1979 |
throw new IllegalArgumentException( |
| 1980 |
"Can't call setTransientExtras() on a persisted job"); |
| 1981 |
} |
| 1982 |
if (clipData != null) { |
| 1983 |
throw new IllegalArgumentException( |
| 1984 |
"Can't call setClipData() on a persisted job"); |
| 1985 |
} |
| 1986 |
} |
| 1987 |
|
| 1988 |
if ((flags & FLAG_IMPORTANT_WHILE_FOREGROUND) != 0) { |
| 1989 |
if (hasEarlyConstraint) { |
| 1990 |
throw new IllegalArgumentException( |
| 1991 |
"An important while foreground job cannot have a time delay"); |
| 1992 |
} |
| 1993 |
if (mPriority != PRIORITY_HIGH && mPriority != PRIORITY_DEFAULT) { |
| 1994 |
throw new IllegalArgumentException( |
| 1995 |
"An important while foreground job must be high or default priority." |
| 1996 |
+ " Don't mark unimportant tasks as important while foreground."); |
| 1997 |
} |
| 1998 |
} |
| 1999 |
|
| 2000 |
final boolean isExpedited = (flags & FLAG_EXPEDITED) != 0; |
| 2001 |
switch (mPriority) { |
| 2002 |
case PRIORITY_MAX: |
| 2003 |
if (!isExpedited) { |
| 2004 |
throw new IllegalArgumentException("Only expedited jobs can have max priority"); |
| 2005 |
} |
| 2006 |
break; |
| 2007 |
case PRIORITY_HIGH: |
| 2008 |
if ((flags & FLAG_PREFETCH) != 0) { |
| 2009 |
throw new IllegalArgumentException("Prefetch jobs cannot be high priority"); |
| 2010 |
} |
| 2011 |
if (isPeriodic) { |
| 2012 |
throw new IllegalArgumentException("Periodic jobs cannot be high priority"); |
| 2013 |
} |
| 2014 |
break; |
| 2015 |
case PRIORITY_DEFAULT: |
| 2016 |
case PRIORITY_LOW: |
| 2017 |
case PRIORITY_MIN: |
| 2018 |
break; |
| 2019 |
default: |
| 2020 |
throw new IllegalArgumentException("Invalid priority level provided: " + mPriority); |
| 2021 |
} |
| 2022 |
|
| 2023 |
if (isExpedited) { |
| 2024 |
if (hasEarlyConstraint) { |
| 2025 |
throw new IllegalArgumentException("An expedited job cannot have a time delay"); |
| 2026 |
} |
| 2027 |
if (hasLateConstraint) { |
| 2028 |
throw new IllegalArgumentException("An expedited job cannot have a deadline"); |
| 2029 |
} |
| 2030 |
if (isPeriodic) { |
| 2031 |
throw new IllegalArgumentException("An expedited job cannot be periodic"); |
| 2032 |
} |
| 2033 |
if (mPriority != PRIORITY_MAX && mPriority != PRIORITY_HIGH) { |
| 2034 |
throw new IllegalArgumentException( |
| 2035 |
"An expedited job must be high or max priority. Don't use expedited jobs" |
| 2036 |
+ " for unimportant tasks."); |
| 2037 |
} |
| 2038 |
if ((constraintFlags & ~CONSTRAINT_FLAG_STORAGE_NOT_LOW) != 0 |
| 2039 |
|| (flags & ~(FLAG_EXPEDITED | FLAG_EXEMPT_FROM_APP_STANDBY)) != 0) { |
| 2040 |
throw new IllegalArgumentException( |
| 2041 |
"An expedited job can only have network and storage-not-low constraints"); |
| 2042 |
} |
| 2043 |
if (triggerContentUris != null && triggerContentUris.length > 0) { |
| 2044 |
throw new IllegalArgumentException( |
| 2045 |
"Can't call addTriggerContentUri() on an expedited job"); |
| 2046 |
} |
| 2047 |
} |
| 2048 |
} |
| 2049 |
|
| 2050 |
|
| 2051 |
|
| 2052 |
|
| 2053 |
|
| 2054 |
public static String getBiasString(int bias) { |
| 2055 |
switch (bias) { |
| 2056 |
case BIAS_DEFAULT: |
| 2057 |
return BIAS_DEFAULT + " [DEFAULT]"; |
| 2058 |
case BIAS_SYNC_EXPEDITED: |
| 2059 |
return BIAS_SYNC_EXPEDITED + " [SYNC_EXPEDITED]"; |
| 2060 |
case BIAS_SYNC_INITIALIZATION: |
| 2061 |
return BIAS_SYNC_INITIALIZATION + " [SYNC_INITIALIZATION]"; |
| 2062 |
case BIAS_BOUND_FOREGROUND_SERVICE: |
| 2063 |
return BIAS_BOUND_FOREGROUND_SERVICE + " [BFGS_APP]"; |
| 2064 |
case BIAS_FOREGROUND_SERVICE: |
| 2065 |
return BIAS_FOREGROUND_SERVICE + " [FGS_APP]"; |
| 2066 |
case BIAS_TOP_APP: |
| 2067 |
return BIAS_TOP_APP + " [TOP_APP]"; |
| 2068 |
|
| 2069 |
|
| 2070 |
|
| 2071 |
} |
| 2072 |
return bias + " [UNKNOWN]"; |
| 2073 |
} |
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
public static String getPriorityString(@Priority int priority) { |
| 2080 |
switch (priority) { |
| 2081 |
case PRIORITY_MIN: |
| 2082 |
return priority + " [MIN]"; |
| 2083 |
case PRIORITY_LOW: |
| 2084 |
return priority + " [LOW]"; |
| 2085 |
case PRIORITY_DEFAULT: |
| 2086 |
return priority + " [DEFAULT]"; |
| 2087 |
case PRIORITY_HIGH: |
| 2088 |
return priority + " [HIGH]"; |
| 2089 |
case PRIORITY_MAX: |
| 2090 |
return priority + " [MAX]"; |
| 2091 |
} |
| 2092 |
return priority + " [UNKNOWN]"; |
| 2093 |
} |
| 2094 |
} |