| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app; |
| 18 |
|
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.annotation.IntRange; |
| 21 |
import android.annotation.NonNull; |
| 22 |
import android.annotation.Nullable; |
| 23 |
import android.annotation.RequiresPermission; |
| 24 |
import android.annotation.SystemApi; |
| 25 |
import android.annotation.TestApi; |
| 26 |
import android.app.compat.CompatChanges; |
| 27 |
import android.compat.annotation.ChangeId; |
| 28 |
import android.compat.annotation.Disabled; |
| 29 |
import android.compat.annotation.EnabledSince; |
| 30 |
import android.content.BroadcastReceiver; |
| 31 |
import android.content.Intent; |
| 32 |
import android.content.IntentFilter; |
| 33 |
import android.os.Build; |
| 34 |
import android.os.Bundle; |
| 35 |
import android.os.BundleMerger; |
| 36 |
import android.os.PowerExemptionManager; |
| 37 |
import android.os.PowerExemptionManager.ReasonCode; |
| 38 |
import android.os.PowerExemptionManager.TempAllowListType; |
| 39 |
|
| 40 |
import java.lang.annotation.Retention; |
| 41 |
import java.lang.annotation.RetentionPolicy; |
| 42 |
import java.util.Objects; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public class BroadcastOptions extends ComponentOptions { |
| 50 |
private @Flags int mFlags; |
| 51 |
private long mTemporaryAppAllowlistDuration; |
| 52 |
private @TempAllowListType int mTemporaryAppAllowlistType; |
| 53 |
private @ReasonCode int mTemporaryAppAllowlistReasonCode; |
| 54 |
private @Nullable String mTemporaryAppAllowlistReason; |
| 55 |
private int mMinManifestReceiverApiLevel = 0; |
| 56 |
private int mMaxManifestReceiverApiLevel = Build.VERSION_CODES.CUR_DEVELOPMENT; |
| 57 |
private String[] mRequireAllOfPermissions; |
| 58 |
private String[] mRequireNoneOfPermissions; |
| 59 |
private long mRequireCompatChangeId = CHANGE_INVALID; |
| 60 |
private long mIdForResponseEvent; |
| 61 |
private @DeliveryGroupPolicy int mDeliveryGroupPolicy; |
| 62 |
private @Nullable String mDeliveryGroupMatchingNamespaceFragment; |
| 63 |
private @Nullable String mDeliveryGroupMatchingKeyFragment; |
| 64 |
private @Nullable BundleMerger mDeliveryGroupExtrasMerger; |
| 65 |
private @Nullable IntentFilter mDeliveryGroupMatchingFilter; |
| 66 |
private @DeferralPolicy int mDeferralPolicy; |
| 67 |
|
| 68 |
|
| 69 |
@IntDef(flag = true, prefix = { "FLAG_" }, value = { |
| 70 |
FLAG_DONT_SEND_TO_RESTRICTED_APPS, |
| 71 |
FLAG_ALLOW_BACKGROUND_ACTIVITY_STARTS, |
| 72 |
FLAG_REQUIRE_COMPAT_CHANGE_ENABLED, |
| 73 |
FLAG_IS_ALARM_BROADCAST, |
| 74 |
FLAG_SHARE_IDENTITY, |
| 75 |
FLAG_INTERACTIVE, |
| 76 |
}) |
| 77 |
@Retention(RetentionPolicy.SOURCE) |
| 78 |
public @interface Flags {} |
| 79 |
|
| 80 |
private static final int FLAG_DONT_SEND_TO_RESTRICTED_APPS = 1 << 0; |
| 81 |
private static final int FLAG_ALLOW_BACKGROUND_ACTIVITY_STARTS = 1 << 1; |
| 82 |
private static final int FLAG_REQUIRE_COMPAT_CHANGE_ENABLED = 1 << 2; |
| 83 |
private static final int FLAG_IS_ALARM_BROADCAST = 1 << 3; |
| 84 |
private static final int FLAG_SHARE_IDENTITY = 1 << 4; |
| 85 |
private static final int FLAG_INTERACTIVE = 1 << 5; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
public static final long CHANGE_INVALID = Long.MIN_VALUE; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
@TestApi |
| 100 |
@ChangeId |
| 101 |
@EnabledSince(targetSdkVersion = android.os.Build.VERSION_CODES.BASE) |
| 102 |
public static final long CHANGE_ALWAYS_ENABLED = 209888056L; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
@TestApi |
| 110 |
@ChangeId |
| 111 |
@Disabled |
| 112 |
public static final long CHANGE_ALWAYS_DISABLED = 210856463L; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
private static final String KEY_FLAGS = "android:broadcast.flags"; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
private static final String KEY_TEMPORARY_APP_ALLOWLIST_DURATION |
| 124 |
= "android:broadcast.temporaryAppAllowlistDuration"; |
| 125 |
|
| 126 |
private static final String KEY_TEMPORARY_APP_ALLOWLIST_TYPE |
| 127 |
= "android:broadcast.temporaryAppAllowlistType"; |
| 128 |
|
| 129 |
private static final String KEY_TEMPORARY_APP_ALLOWLIST_REASON_CODE = |
| 130 |
"android:broadcast.temporaryAppAllowlistReasonCode"; |
| 131 |
|
| 132 |
private static final String KEY_TEMPORARY_APP_ALLOWLIST_REASON = |
| 133 |
"android:broadcast.temporaryAppAllowlistReason"; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
private static final String KEY_MIN_MANIFEST_RECEIVER_API_LEVEL |
| 139 |
= "android:broadcast.minManifestReceiverApiLevel"; |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
private static final String KEY_MAX_MANIFEST_RECEIVER_API_LEVEL |
| 145 |
= "android:broadcast.maxManifestReceiverApiLevel"; |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
public static final String KEY_REQUIRE_ALL_OF_PERMISSIONS = |
| 152 |
"android:broadcast.requireAllOfPermissions"; |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
public static final String KEY_REQUIRE_NONE_OF_PERMISSIONS = |
| 159 |
"android:broadcast.requireNoneOfPermissions"; |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
private static final String KEY_REQUIRE_COMPAT_CHANGE_ID = |
| 165 |
"android:broadcast.requireCompatChangeId"; |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
private static final String KEY_REQUIRE_COMPAT_CHANGE_ENABLED = |
| 171 |
"android:broadcast.requireCompatChangeEnabled"; |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
public static final String KEY_ALARM_BROADCAST = |
| 178 |
"android:broadcast.is_alarm"; |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
@Deprecated |
| 186 |
public static final int TEMPORARY_WHITELIST_TYPE_FOREGROUND_SERVICE_ALLOWED = |
| 187 |
PowerExemptionManager.TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_ALLOWED; |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
@Deprecated |
| 195 |
public static final int TEMPORARY_WHITELIST_TYPE_FOREGROUND_SERVICE_NOT_ALLOWED = |
| 196 |
PowerExemptionManager.TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_NOT_ALLOWED; |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
private static final String KEY_ID_FOR_RESPONSE_EVENT = |
| 202 |
"android:broadcast.idForResponseEvent"; |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
private static final String KEY_DELIVERY_GROUP_POLICY = |
| 208 |
"android:broadcast.deliveryGroupPolicy"; |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
private static final String KEY_DELIVERY_GROUP_NAMESPACE = |
| 214 |
"android:broadcast.deliveryGroupMatchingNamespace"; |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
private static final String KEY_DELIVERY_GROUP_KEY = |
| 220 |
"android:broadcast.deliveryGroupMatchingKey"; |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
private static final String KEY_DELIVERY_GROUP_EXTRAS_MERGER = |
| 226 |
"android:broadcast.deliveryGroupExtrasMerger"; |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
private static final String KEY_DELIVERY_GROUP_MATCHING_FILTER = |
| 232 |
"android:broadcast.deliveryGroupMatchingFilter"; |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
private static final String KEY_DEFERRAL_POLICY = |
| 238 |
"android:broadcast.deferralPolicy"; |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
@IntDef(prefix = { "DELIVERY_GROUP_POLICY_" }, value = { |
| 246 |
DELIVERY_GROUP_POLICY_ALL, |
| 247 |
DELIVERY_GROUP_POLICY_MOST_RECENT, |
| 248 |
DELIVERY_GROUP_POLICY_MERGED, |
| 249 |
}) |
| 250 |
@Retention(RetentionPolicy.SOURCE) |
| 251 |
public @interface DeliveryGroupPolicy {} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
public static final int DELIVERY_GROUP_POLICY_ALL = 0; |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
public static final int DELIVERY_GROUP_POLICY_MOST_RECENT = 1; |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
public static final int DELIVERY_GROUP_POLICY_MERGED = 2; |
| 272 |
|
| 273 |
|
| 274 |
@IntDef(prefix = { "DEFERRAL_POLICY_" }, value = { |
| 275 |
DEFERRAL_POLICY_DEFAULT, |
| 276 |
DEFERRAL_POLICY_NONE, |
| 277 |
DEFERRAL_POLICY_UNTIL_ACTIVE, |
| 278 |
}) |
| 279 |
@Retention(RetentionPolicy.SOURCE) |
| 280 |
public @interface DeferralPolicy {} |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
public static final int DEFERRAL_POLICY_DEFAULT = 0; |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
public static final int DEFERRAL_POLICY_NONE = 1; |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
public static final int DEFERRAL_POLICY_UNTIL_ACTIVE = 2; |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
public static @NonNull BroadcastOptions makeBasic() { |
| 323 |
BroadcastOptions opts = new BroadcastOptions(); |
| 324 |
return opts; |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
@TestApi |
| 329 |
public BroadcastOptions() { |
| 330 |
super(); |
| 331 |
resetTemporaryAppAllowlist(); |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
@TestApi |
| 336 |
public BroadcastOptions(@NonNull Bundle opts) { |
| 337 |
super(opts); |
| 338 |
|
| 339 |
mFlags = opts.getInt(KEY_FLAGS, 0); |
| 340 |
if (opts.containsKey(KEY_TEMPORARY_APP_ALLOWLIST_DURATION)) { |
| 341 |
mTemporaryAppAllowlistDuration = opts.getLong(KEY_TEMPORARY_APP_ALLOWLIST_DURATION); |
| 342 |
mTemporaryAppAllowlistType = opts.getInt(KEY_TEMPORARY_APP_ALLOWLIST_TYPE); |
| 343 |
mTemporaryAppAllowlistReasonCode = opts.getInt(KEY_TEMPORARY_APP_ALLOWLIST_REASON_CODE, |
| 344 |
PowerExemptionManager.REASON_UNKNOWN); |
| 345 |
mTemporaryAppAllowlistReason = opts.getString(KEY_TEMPORARY_APP_ALLOWLIST_REASON); |
| 346 |
} else { |
| 347 |
resetTemporaryAppAllowlist(); |
| 348 |
} |
| 349 |
mMinManifestReceiverApiLevel = opts.getInt(KEY_MIN_MANIFEST_RECEIVER_API_LEVEL, 0); |
| 350 |
mMaxManifestReceiverApiLevel = opts.getInt(KEY_MAX_MANIFEST_RECEIVER_API_LEVEL, |
| 351 |
Build.VERSION_CODES.CUR_DEVELOPMENT); |
| 352 |
mRequireAllOfPermissions = opts.getStringArray(KEY_REQUIRE_ALL_OF_PERMISSIONS); |
| 353 |
mRequireNoneOfPermissions = opts.getStringArray(KEY_REQUIRE_NONE_OF_PERMISSIONS); |
| 354 |
mRequireCompatChangeId = opts.getLong(KEY_REQUIRE_COMPAT_CHANGE_ID, CHANGE_INVALID); |
| 355 |
mIdForResponseEvent = opts.getLong(KEY_ID_FOR_RESPONSE_EVENT); |
| 356 |
mDeliveryGroupPolicy = opts.getInt(KEY_DELIVERY_GROUP_POLICY, |
| 357 |
DELIVERY_GROUP_POLICY_ALL); |
| 358 |
mDeliveryGroupMatchingNamespaceFragment = opts.getString(KEY_DELIVERY_GROUP_NAMESPACE); |
| 359 |
mDeliveryGroupMatchingKeyFragment = opts.getString(KEY_DELIVERY_GROUP_KEY); |
| 360 |
mDeliveryGroupExtrasMerger = opts.getParcelable(KEY_DELIVERY_GROUP_EXTRAS_MERGER, |
| 361 |
BundleMerger.class); |
| 362 |
mDeliveryGroupMatchingFilter = opts.getParcelable(KEY_DELIVERY_GROUP_MATCHING_FILTER, |
| 363 |
IntentFilter.class); |
| 364 |
mDeferralPolicy = opts.getInt(KEY_DEFERRAL_POLICY, DEFERRAL_POLICY_DEFAULT); |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
@Deprecated |
| 375 |
@SystemApi |
| 376 |
@RequiresPermission(anyOf = {android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST, |
| 377 |
android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND, |
| 378 |
android.Manifest.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND}) |
| 379 |
public void setTemporaryAppWhitelistDuration(long duration) { |
| 380 |
setTemporaryAppAllowlist(duration, |
| 381 |
PowerExemptionManager.TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_ALLOWED, |
| 382 |
PowerExemptionManager.REASON_UNKNOWN, null); |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
@SystemApi |
| 402 |
@RequiresPermission(anyOf = {android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST, |
| 403 |
android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND, |
| 404 |
android.Manifest.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND}) |
| 405 |
public void setTemporaryAppAllowlist(long duration, @TempAllowListType int type, |
| 406 |
@ReasonCode int reasonCode, @Nullable String reason) { |
| 407 |
mTemporaryAppAllowlistDuration = duration; |
| 408 |
mTemporaryAppAllowlistType = type; |
| 409 |
mTemporaryAppAllowlistReasonCode = reasonCode; |
| 410 |
mTemporaryAppAllowlistReason = reason; |
| 411 |
|
| 412 |
if (!isTemporaryAppAllowlistSet()) { |
| 413 |
resetTemporaryAppAllowlist(); |
| 414 |
} |
| 415 |
} |
| 416 |
|
| 417 |
private boolean isTemporaryAppAllowlistSet() { |
| 418 |
return mTemporaryAppAllowlistDuration > 0 |
| 419 |
&& mTemporaryAppAllowlistType |
| 420 |
!= PowerExemptionManager.TEMPORARY_ALLOW_LIST_TYPE_NONE; |
| 421 |
} |
| 422 |
|
| 423 |
private void resetTemporaryAppAllowlist() { |
| 424 |
mTemporaryAppAllowlistDuration = 0; |
| 425 |
mTemporaryAppAllowlistType = PowerExemptionManager.TEMPORARY_ALLOW_LIST_TYPE_NONE; |
| 426 |
mTemporaryAppAllowlistReasonCode = PowerExemptionManager.REASON_UNKNOWN; |
| 427 |
mTemporaryAppAllowlistReason = null; |
| 428 |
} |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
@TestApi |
| 435 |
public long getTemporaryAppAllowlistDuration() { |
| 436 |
return mTemporaryAppAllowlistDuration; |
| 437 |
} |
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
@TestApi |
| 444 |
public @TempAllowListType int getTemporaryAppAllowlistType() { |
| 445 |
return mTemporaryAppAllowlistType; |
| 446 |
} |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
@TestApi |
| 453 |
public @ReasonCode int getTemporaryAppAllowlistReasonCode() { |
| 454 |
return mTemporaryAppAllowlistReasonCode; |
| 455 |
} |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
@TestApi |
| 462 |
public @Nullable String getTemporaryAppAllowlistReason() { |
| 463 |
return mTemporaryAppAllowlistReason; |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
@Deprecated |
| 480 |
public void setMinManifestReceiverApiLevel(int apiLevel) { |
| 481 |
mMinManifestReceiverApiLevel = apiLevel; |
| 482 |
} |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
@Deprecated |
| 496 |
public int getMinManifestReceiverApiLevel() { |
| 497 |
return mMinManifestReceiverApiLevel; |
| 498 |
} |
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
@TestApi |
| 514 |
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) |
| 515 |
@Deprecated |
| 516 |
public void setMaxManifestReceiverApiLevel(int apiLevel) { |
| 517 |
mMaxManifestReceiverApiLevel = apiLevel; |
| 518 |
} |
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
@TestApi |
| 532 |
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) |
| 533 |
@Deprecated |
| 534 |
public int getMaxManifestReceiverApiLevel() { |
| 535 |
return mMaxManifestReceiverApiLevel; |
| 536 |
} |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
@SystemApi |
| 545 |
public void setDontSendToRestrictedApps(boolean dontSendToRestrictedApps) { |
| 546 |
if (dontSendToRestrictedApps) { |
| 547 |
mFlags |= FLAG_DONT_SEND_TO_RESTRICTED_APPS; |
| 548 |
} else { |
| 549 |
mFlags &= ~FLAG_DONT_SEND_TO_RESTRICTED_APPS; |
| 550 |
} |
| 551 |
} |
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
public boolean isDontSendToRestrictedApps() { |
| 558 |
return (mFlags & FLAG_DONT_SEND_TO_RESTRICTED_APPS) != 0; |
| 559 |
} |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
@SystemApi |
| 567 |
@RequiresPermission(android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND) |
| 568 |
public void setBackgroundActivityStartsAllowed(boolean allowBackgroundActivityStarts) { |
| 569 |
if (allowBackgroundActivityStarts) { |
| 570 |
mFlags |= FLAG_ALLOW_BACKGROUND_ACTIVITY_STARTS; |
| 571 |
} else { |
| 572 |
mFlags &= ~FLAG_ALLOW_BACKGROUND_ACTIVITY_STARTS; |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
@Deprecated |
| 581 |
public boolean allowsBackgroundActivityStarts() { |
| 582 |
return (mFlags & FLAG_ALLOW_BACKGROUND_ACTIVITY_STARTS) != 0; |
| 583 |
} |
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
@SystemApi |
| 600 |
public void setRequireAllOfPermissions(@Nullable String[] requiredPermissions) { |
| 601 |
mRequireAllOfPermissions = requiredPermissions; |
| 602 |
} |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
@SystemApi |
| 619 |
public void setRequireNoneOfPermissions(@Nullable String[] excludedPermissions) { |
| 620 |
mRequireNoneOfPermissions = excludedPermissions; |
| 621 |
} |
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
@SystemApi |
| 642 |
public void setRequireCompatChange(long changeId, boolean enabled) { |
| 643 |
mRequireCompatChangeId = changeId; |
| 644 |
if (enabled) { |
| 645 |
mFlags |= FLAG_REQUIRE_COMPAT_CHANGE_ENABLED; |
| 646 |
} else { |
| 647 |
mFlags &= ~FLAG_REQUIRE_COMPAT_CHANGE_ENABLED; |
| 648 |
} |
| 649 |
} |
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
@SystemApi |
| 657 |
public void clearRequireCompatChange() { |
| 658 |
setRequireCompatChange(CHANGE_INVALID, true); |
| 659 |
} |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
public void setAlarmBroadcast(boolean senderIsAlarm) { |
| 670 |
if (senderIsAlarm) { |
| 671 |
mFlags |= FLAG_IS_ALARM_BROADCAST; |
| 672 |
} else { |
| 673 |
mFlags &= ~FLAG_IS_ALARM_BROADCAST; |
| 674 |
} |
| 675 |
} |
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
public boolean isAlarmBroadcast() { |
| 683 |
return (mFlags & FLAG_IS_ALARM_BROADCAST) != 0; |
| 684 |
} |
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
public @NonNull BroadcastOptions setShareIdentityEnabled(boolean shareIdentityEnabled) { |
| 703 |
if (shareIdentityEnabled) { |
| 704 |
mFlags |= FLAG_SHARE_IDENTITY; |
| 705 |
} else { |
| 706 |
mFlags &= ~FLAG_SHARE_IDENTITY; |
| 707 |
} |
| 708 |
return this; |
| 709 |
} |
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
public boolean isShareIdentityEnabled() { |
| 720 |
return (mFlags & FLAG_SHARE_IDENTITY) != 0; |
| 721 |
} |
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
public boolean isPushMessagingBroadcast() { |
| 730 |
return mTemporaryAppAllowlistReasonCode == PowerExemptionManager.REASON_PUSH_MESSAGING; |
| 731 |
} |
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
public boolean isPushMessagingOverQuotaBroadcast() { |
| 741 |
return mTemporaryAppAllowlistReasonCode |
| 742 |
== PowerExemptionManager.REASON_PUSH_MESSAGING_OVER_QUOTA; |
| 743 |
} |
| 744 |
|
| 745 |
|
| 746 |
public long getRequireCompatChangeId() { |
| 747 |
return mRequireCompatChangeId; |
| 748 |
} |
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
@TestApi |
| 757 |
public boolean testRequireCompatChange(int uid) { |
| 758 |
if (mRequireCompatChangeId != CHANGE_INVALID) { |
| 759 |
final boolean requireEnabled = (mFlags & FLAG_REQUIRE_COMPAT_CHANGE_ENABLED) != 0; |
| 760 |
return CompatChanges.isChangeEnabled(mRequireCompatChangeId, uid) == requireEnabled; |
| 761 |
} else { |
| 762 |
return true; |
| 763 |
} |
| 764 |
} |
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
@SystemApi |
| 779 |
@RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RESPONSE_STATS) |
| 780 |
public void recordResponseEventWhileInBackground(@IntRange(from = 0) long id) { |
| 781 |
mIdForResponseEvent = id; |
| 782 |
} |
| 783 |
|
| 784 |
|
| 785 |
@IntRange(from = 0) |
| 786 |
public long getIdForResponseEvent() { |
| 787 |
return mIdForResponseEvent; |
| 788 |
} |
| 789 |
|
| 790 |
|
| 791 |
@Deprecated |
| 792 |
public @NonNull BroadcastOptions setDeferUntilActive(boolean shouldDefer) { |
| 793 |
if (shouldDefer) { |
| 794 |
setDeferralPolicy(DEFERRAL_POLICY_UNTIL_ACTIVE); |
| 795 |
} else { |
| 796 |
setDeferralPolicy(DEFERRAL_POLICY_NONE); |
| 797 |
} |
| 798 |
return this; |
| 799 |
} |
| 800 |
|
| 801 |
|
| 802 |
@Deprecated |
| 803 |
public boolean isDeferUntilActive() { |
| 804 |
return (mDeferralPolicy == DEFERRAL_POLICY_UNTIL_ACTIVE); |
| 805 |
} |
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
public @NonNull BroadcastOptions setDeferralPolicy(@DeferralPolicy int deferralPolicy) { |
| 812 |
mDeferralPolicy = deferralPolicy; |
| 813 |
return this; |
| 814 |
} |
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
public @DeferralPolicy int getDeferralPolicy() { |
| 821 |
return mDeferralPolicy; |
| 822 |
} |
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
public void clearDeferralPolicy() { |
| 829 |
mDeferralPolicy = DEFERRAL_POLICY_DEFAULT; |
| 830 |
} |
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
@NonNull |
| 837 |
public BroadcastOptions setDeliveryGroupPolicy(@DeliveryGroupPolicy int policy) { |
| 838 |
mDeliveryGroupPolicy = policy; |
| 839 |
return this; |
| 840 |
} |
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
public @DeliveryGroupPolicy int getDeliveryGroupPolicy() { |
| 847 |
return mDeliveryGroupPolicy; |
| 848 |
} |
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
public void clearDeliveryGroupPolicy() { |
| 856 |
mDeliveryGroupPolicy = DELIVERY_GROUP_POLICY_ALL; |
| 857 |
} |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
@NonNull |
| 871 |
public BroadcastOptions setDeliveryGroupMatchingKey(@NonNull String namespace, |
| 872 |
@NonNull String key) { |
| 873 |
mDeliveryGroupMatchingNamespaceFragment = Objects.requireNonNull(namespace); |
| 874 |
mDeliveryGroupMatchingKeyFragment = Objects.requireNonNull(key); |
| 875 |
return this; |
| 876 |
} |
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
@Nullable |
| 886 |
public String getDeliveryGroupMatchingKey() { |
| 887 |
if (mDeliveryGroupMatchingNamespaceFragment == null |
| 888 |
|| mDeliveryGroupMatchingKeyFragment == null) { |
| 889 |
return null; |
| 890 |
} |
| 891 |
return String.join(":", mDeliveryGroupMatchingNamespaceFragment, |
| 892 |
mDeliveryGroupMatchingKeyFragment); |
| 893 |
} |
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
@Nullable |
| 904 |
public String getDeliveryGroupMatchingNamespaceFragment() { |
| 905 |
return mDeliveryGroupMatchingNamespaceFragment; |
| 906 |
} |
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
@Nullable |
| 917 |
public String getDeliveryGroupMatchingKeyFragment() { |
| 918 |
return mDeliveryGroupMatchingKeyFragment; |
| 919 |
} |
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
public void clearDeliveryGroupMatchingKey() { |
| 926 |
mDeliveryGroupMatchingNamespaceFragment = null; |
| 927 |
mDeliveryGroupMatchingKeyFragment = null; |
| 928 |
} |
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
@NonNull |
| 942 |
public BroadcastOptions setDeliveryGroupMatchingFilter(@NonNull IntentFilter matchingFilter) { |
| 943 |
mDeliveryGroupMatchingFilter = Objects.requireNonNull(matchingFilter); |
| 944 |
return this; |
| 945 |
} |
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
@Nullable |
| 955 |
public IntentFilter getDeliveryGroupMatchingFilter() { |
| 956 |
return mDeliveryGroupMatchingFilter; |
| 957 |
} |
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
public void clearDeliveryGroupMatchingFilter() { |
| 964 |
mDeliveryGroupMatchingFilter = null; |
| 965 |
} |
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
@NonNull |
| 977 |
public BroadcastOptions setDeliveryGroupExtrasMerger(@NonNull BundleMerger extrasMerger) { |
| 978 |
mDeliveryGroupExtrasMerger = Objects.requireNonNull(extrasMerger); |
| 979 |
return this; |
| 980 |
} |
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
@Nullable |
| 991 |
public BundleMerger getDeliveryGroupExtrasMerger() { |
| 992 |
return mDeliveryGroupExtrasMerger; |
| 993 |
} |
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
public void clearDeliveryGroupExtrasMerger() { |
| 1001 |
mDeliveryGroupExtrasMerger = null; |
| 1002 |
} |
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
public @NonNull BroadcastOptions setInteractive(boolean interactive) { |
| 1013 |
if (interactive) { |
| 1014 |
mFlags |= FLAG_INTERACTIVE; |
| 1015 |
} else { |
| 1016 |
mFlags &= ~FLAG_INTERACTIVE; |
| 1017 |
} |
| 1018 |
return this; |
| 1019 |
} |
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
public boolean isInteractive() { |
| 1029 |
return (mFlags & FLAG_INTERACTIVE) != 0; |
| 1030 |
} |
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
@SystemApi |
| 1041 |
@Override |
| 1042 |
@Deprecated public void setPendingIntentBackgroundActivityLaunchAllowed(boolean allowed) { |
| 1043 |
super.setPendingIntentBackgroundActivityLaunchAllowed(allowed); |
| 1044 |
} |
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
@SystemApi |
| 1056 |
@Override |
| 1057 |
@Deprecated public boolean isPendingIntentBackgroundActivityLaunchAllowed() { |
| 1058 |
return super.isPendingIntentBackgroundActivityLaunchAllowed(); |
| 1059 |
} |
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
@SystemApi |
| 1073 |
@NonNull |
| 1074 |
|
| 1075 |
public BroadcastOptions setPendingIntentBackgroundActivityStartMode(int state) { |
| 1076 |
|
| 1077 |
return this; |
| 1078 |
} |
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
@SystemApi |
| 1088 |
|
| 1089 |
public int getPendingIntentBackgroundActivityStartMode() { |
| 1090 |
return 0; |
| 1091 |
|
| 1092 |
} |
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
@Override |
| 1107 |
public @NonNull Bundle toBundle() { |
| 1108 |
Bundle b = super.toBundle(); |
| 1109 |
if (mFlags != 0) { |
| 1110 |
b.putInt(KEY_FLAGS, mFlags); |
| 1111 |
} |
| 1112 |
if (isTemporaryAppAllowlistSet()) { |
| 1113 |
b.putLong(KEY_TEMPORARY_APP_ALLOWLIST_DURATION, mTemporaryAppAllowlistDuration); |
| 1114 |
b.putInt(KEY_TEMPORARY_APP_ALLOWLIST_TYPE, mTemporaryAppAllowlistType); |
| 1115 |
b.putInt(KEY_TEMPORARY_APP_ALLOWLIST_REASON_CODE, mTemporaryAppAllowlistReasonCode); |
| 1116 |
b.putString(KEY_TEMPORARY_APP_ALLOWLIST_REASON, mTemporaryAppAllowlistReason); |
| 1117 |
} |
| 1118 |
if (mMinManifestReceiverApiLevel != 0) { |
| 1119 |
b.putInt(KEY_MIN_MANIFEST_RECEIVER_API_LEVEL, mMinManifestReceiverApiLevel); |
| 1120 |
} |
| 1121 |
if (mMaxManifestReceiverApiLevel != Build.VERSION_CODES.CUR_DEVELOPMENT) { |
| 1122 |
b.putInt(KEY_MAX_MANIFEST_RECEIVER_API_LEVEL, mMaxManifestReceiverApiLevel); |
| 1123 |
} |
| 1124 |
if (mRequireAllOfPermissions != null) { |
| 1125 |
b.putStringArray(KEY_REQUIRE_ALL_OF_PERMISSIONS, mRequireAllOfPermissions); |
| 1126 |
} |
| 1127 |
if (mRequireNoneOfPermissions != null) { |
| 1128 |
b.putStringArray(KEY_REQUIRE_NONE_OF_PERMISSIONS, mRequireNoneOfPermissions); |
| 1129 |
} |
| 1130 |
if (mRequireCompatChangeId != CHANGE_INVALID) { |
| 1131 |
b.putLong(KEY_REQUIRE_COMPAT_CHANGE_ID, mRequireCompatChangeId); |
| 1132 |
} |
| 1133 |
if (mIdForResponseEvent != 0) { |
| 1134 |
b.putLong(KEY_ID_FOR_RESPONSE_EVENT, mIdForResponseEvent); |
| 1135 |
} |
| 1136 |
if (mDeliveryGroupPolicy != DELIVERY_GROUP_POLICY_ALL) { |
| 1137 |
b.putInt(KEY_DELIVERY_GROUP_POLICY, mDeliveryGroupPolicy); |
| 1138 |
} |
| 1139 |
if (mDeliveryGroupMatchingNamespaceFragment != null) { |
| 1140 |
b.putString(KEY_DELIVERY_GROUP_NAMESPACE, mDeliveryGroupMatchingNamespaceFragment); |
| 1141 |
} |
| 1142 |
if (mDeliveryGroupMatchingKeyFragment != null) { |
| 1143 |
b.putString(KEY_DELIVERY_GROUP_KEY, mDeliveryGroupMatchingKeyFragment); |
| 1144 |
} |
| 1145 |
if (mDeliveryGroupPolicy == DELIVERY_GROUP_POLICY_MERGED) { |
| 1146 |
if (mDeliveryGroupExtrasMerger != null) { |
| 1147 |
b.putParcelable(KEY_DELIVERY_GROUP_EXTRAS_MERGER, |
| 1148 |
mDeliveryGroupExtrasMerger); |
| 1149 |
} else { |
| 1150 |
throw new IllegalStateException("Extras merger cannot be empty " |
| 1151 |
+ "when delivery group policy is 'MERGED'"); |
| 1152 |
} |
| 1153 |
} |
| 1154 |
if (mDeliveryGroupMatchingFilter != null) { |
| 1155 |
b.putParcelable(KEY_DELIVERY_GROUP_MATCHING_FILTER, mDeliveryGroupMatchingFilter); |
| 1156 |
} |
| 1157 |
if (mDeferralPolicy != DEFERRAL_POLICY_DEFAULT) { |
| 1158 |
b.putInt(KEY_DEFERRAL_POLICY, mDeferralPolicy); |
| 1159 |
} |
| 1160 |
return b; |
| 1161 |
} |
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
public static @NonNull BroadcastOptions fromBundle(@NonNull Bundle options) { |
| 1168 |
return new BroadcastOptions(options); |
| 1169 |
} |
| 1170 |
|
| 1171 |
|
| 1172 |
public static @Nullable BroadcastOptions fromBundleNullable(@Nullable Bundle options) { |
| 1173 |
return (options != null) ? new BroadcastOptions(options) : null; |
| 1174 |
} |
| 1175 |
} |