Merge "Update javadoc of the newly introduced CarrirConfigManager APIs"
diff --git a/core/api/current.txt b/core/api/current.txt
index f2a48c0..729d8df 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -5003,6 +5003,31 @@
field @NonNull public static final android.os.Parcelable.Creator<android.app.BackgroundServiceStartNotAllowedException> CREATOR;
}
+ public class BroadcastOptions {
+ method public void clearDeferralPolicy();
+ method public void clearDeliveryGroupMatchingFilter();
+ method public void clearDeliveryGroupMatchingKey();
+ method public void clearDeliveryGroupPolicy();
+ method @NonNull public static android.app.BroadcastOptions fromBundle(@NonNull android.os.Bundle);
+ method public int getDeferralPolicy();
+ method @Nullable public android.content.IntentFilter getDeliveryGroupMatchingFilter();
+ method @Nullable public String getDeliveryGroupMatchingKey();
+ method public int getDeliveryGroupPolicy();
+ method public boolean isShareIdentityEnabled();
+ method @NonNull public static android.app.BroadcastOptions makeBasic();
+ method @NonNull public android.app.BroadcastOptions setDeferralPolicy(int);
+ method @NonNull public android.app.BroadcastOptions setDeliveryGroupMatchingFilter(@NonNull android.content.IntentFilter);
+ method @NonNull public android.app.BroadcastOptions setDeliveryGroupMatchingKey(@NonNull String, @NonNull String);
+ method @NonNull public android.app.BroadcastOptions setDeliveryGroupPolicy(int);
+ method @NonNull public android.app.BroadcastOptions setShareIdentityEnabled(boolean);
+ method @NonNull public android.os.Bundle toBundle();
+ field public static final int DEFERRAL_POLICY_DEFAULT = 0; // 0x0
+ field public static final int DEFERRAL_POLICY_NONE = 1; // 0x1
+ field public static final int DEFERRAL_POLICY_UNTIL_ACTIVE = 2; // 0x2
+ field public static final int DELIVERY_GROUP_POLICY_ALL = 0; // 0x0
+ field public static final int DELIVERY_GROUP_POLICY_MOST_RECENT = 1; // 0x1
+ }
+
public class DatePickerDialog extends android.app.AlertDialog implements android.widget.DatePicker.OnDateChangedListener android.content.DialogInterface.OnClickListener {
ctor public DatePickerDialog(@NonNull android.content.Context);
ctor public DatePickerDialog(@NonNull android.content.Context, @StyleRes int);
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 89cae4b..7eedbc3 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -761,25 +761,20 @@
public class BroadcastOptions {
method public void clearRequireCompatChange();
- method public boolean isDeferUntilActive();
- method public boolean isPendingIntentBackgroundActivityLaunchAllowed();
- method public static android.app.BroadcastOptions makeBasic();
+ method public int getPendingIntentBackgroundActivityStartMode();
+ method @Deprecated public boolean isDeferUntilActive();
+ method @Deprecated public boolean isPendingIntentBackgroundActivityLaunchAllowed();
method @RequiresPermission(android.Manifest.permission.ACCESS_BROADCAST_RESPONSE_STATS) public void recordResponseEventWhileInBackground(@IntRange(from=0) long);
method @RequiresPermission(android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND) public void setBackgroundActivityStartsAllowed(boolean);
- method @NonNull public android.app.BroadcastOptions setDeferUntilActive(boolean);
- method public void setDeliveryGroupMatchingFilter(@NonNull android.content.IntentFilter);
- method public void setDeliveryGroupMatchingKey(@NonNull String, @NonNull String);
- method public void setDeliveryGroupPolicy(int);
+ method @Deprecated @NonNull public android.app.BroadcastOptions setDeferUntilActive(boolean);
method public void setDontSendToRestrictedApps(boolean);
- method public void setPendingIntentBackgroundActivityLaunchAllowed(boolean);
+ method @Deprecated public void setPendingIntentBackgroundActivityLaunchAllowed(boolean);
+ method @NonNull public android.app.BroadcastOptions setPendingIntentBackgroundActivityStartMode(int);
method public void setRequireAllOfPermissions(@Nullable String[]);
method public void setRequireCompatChange(long, boolean);
method public void setRequireNoneOfPermissions(@Nullable String[]);
method @RequiresPermission(anyOf={android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST, android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND, android.Manifest.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND}) public void setTemporaryAppAllowlist(long, int, int, @Nullable String);
method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST, android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND, android.Manifest.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND}) public void setTemporaryAppWhitelistDuration(long);
- method public android.os.Bundle toBundle();
- field public static final int DELIVERY_GROUP_POLICY_ALL = 0; // 0x0
- field public static final int DELIVERY_GROUP_POLICY_MOST_RECENT = 1; // 0x1
}
public class DownloadManager {
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index 2d86051d..11ae86e 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -264,6 +264,7 @@
}
public class BroadcastOptions {
+ ctor public BroadcastOptions();
ctor public BroadcastOptions(@NonNull android.os.Bundle);
method @Deprecated public int getMaxManifestReceiverApiLevel();
method public long getTemporaryAppAllowlistDuration();
diff --git a/core/java/android/app/BroadcastOptions.java b/core/java/android/app/BroadcastOptions.java
index 16c5b08..aa253f2 100644
--- a/core/java/android/app/BroadcastOptions.java
+++ b/core/java/android/app/BroadcastOptions.java
@@ -27,10 +27,12 @@
import android.compat.annotation.ChangeId;
import android.compat.annotation.Disabled;
import android.compat.annotation.EnabledSince;
+import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Bundle;
+import android.os.BundleMerger;
import android.os.PowerExemptionManager;
import android.os.PowerExemptionManager.ReasonCode;
import android.os.PowerExemptionManager.TempAllowListType;
@@ -45,28 +47,43 @@
* Helper class for building an options Bundle that can be used with
* {@link android.content.Context#sendBroadcast(android.content.Intent)
* Context.sendBroadcast(Intent)} and related methods.
- * {@hide}
*/
-@SystemApi
public class BroadcastOptions extends ComponentOptions {
+ private @Flags int mFlags;
private long mTemporaryAppAllowlistDuration;
private @TempAllowListType int mTemporaryAppAllowlistType;
private @ReasonCode int mTemporaryAppAllowlistReasonCode;
private @Nullable String mTemporaryAppAllowlistReason;
private int mMinManifestReceiverApiLevel = 0;
private int mMaxManifestReceiverApiLevel = Build.VERSION_CODES.CUR_DEVELOPMENT;
- private boolean mDontSendToRestrictedApps = false;
- private boolean mAllowBackgroundActivityStarts;
private String[] mRequireAllOfPermissions;
private String[] mRequireNoneOfPermissions;
private long mRequireCompatChangeId = CHANGE_INVALID;
- private boolean mRequireCompatChangeEnabled = true;
- private boolean mIsAlarmBroadcast = false;
private long mIdForResponseEvent;
private @DeliveryGroupPolicy int mDeliveryGroupPolicy;
private @Nullable String mDeliveryGroupMatchingKey;
+ private @Nullable BundleMerger mDeliveryGroupExtrasMerger;
private @Nullable IntentFilter mDeliveryGroupMatchingFilter;
- private boolean mIsDeferUntilActive = false;
+ private @DeferralPolicy int mDeferralPolicy;
+
+ /** @hide */
+ @IntDef(flag = true, prefix = { "FLAG_" }, value = {
+ FLAG_DONT_SEND_TO_RESTRICTED_APPS,
+ FLAG_ALLOW_BACKGROUND_ACTIVITY_STARTS,
+ FLAG_REQUIRE_COMPAT_CHANGE_ENABLED,
+ FLAG_IS_ALARM_BROADCAST,
+ FLAG_SHARE_IDENTITY,
+ FLAG_INTERACTIVE,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface Flags {}
+
+ private static final int FLAG_DONT_SEND_TO_RESTRICTED_APPS = 1 << 0;
+ private static final int FLAG_ALLOW_BACKGROUND_ACTIVITY_STARTS = 1 << 1;
+ private static final int FLAG_REQUIRE_COMPAT_CHANGE_ENABLED = 1 << 2;
+ private static final int FLAG_IS_ALARM_BROADCAST = 1 << 3;
+ private static final int FLAG_SHARE_IDENTITY = 1 << 4;
+ private static final int FLAG_INTERACTIVE = 1 << 5;
/**
* Change ID which is invalid.
@@ -96,6 +113,11 @@
public static final long CHANGE_ALWAYS_DISABLED = 210856463L;
/**
+ * Corresponds to {@link #mFlags}.
+ */
+ private static final String KEY_FLAGS = "android:broadcast.flags";
+
+ /**
* How long to temporarily put an app on the power allowlist when executing this broadcast
* to it.
*/
@@ -124,18 +146,6 @@
= "android:broadcast.maxManifestReceiverApiLevel";
/**
- * Corresponds to {@link #setDontSendToRestrictedApps}.
- */
- private static final String KEY_DONT_SEND_TO_RESTRICTED_APPS =
- "android:broadcast.dontSendToRestrictedApps";
-
- /**
- * Corresponds to {@link #setBackgroundActivityStartsAllowed}.
- */
- private static final String KEY_ALLOW_BACKGROUND_ACTIVITY_STARTS =
- "android:broadcast.allowBackgroundActivityStarts";
-
- /**
* Corresponds to {@link #setRequireAllOfPermissions}
* @hide
*/
@@ -193,13 +203,44 @@
"android:broadcast.idForResponseEvent";
/**
+ * Corresponds to {@link #setDeliveryGroupPolicy(int)}.
+ */
+ private static final String KEY_DELIVERY_GROUP_POLICY =
+ "android:broadcast.deliveryGroupPolicy";
+
+ /**
+ * Corresponds to {@link #setDeliveryGroupMatchingKey(String, String)}.
+ */
+ private static final String KEY_DELIVERY_GROUP_KEY =
+ "android:broadcast.deliveryGroupMatchingKey";
+
+ /**
+ * Corresponds to {@link #setDeliveryGroupExtrasMerger(BundleMerger)}.
+ */
+ private static final String KEY_DELIVERY_GROUP_EXTRAS_MERGER =
+ "android:broadcast.deliveryGroupExtrasMerger";
+
+ /**
+ * Corresponds to {@link #setDeliveryGroupMatchingFilter(IntentFilter)}.
+ */
+ private static final String KEY_DELIVERY_GROUP_MATCHING_FILTER =
+ "android:broadcast.deliveryGroupMatchingFilter";
+
+ /**
+ * Corresponds to {@link #setDeferralPolicy(int)}
+ */
+ private static final String KEY_DEFERRAL_POLICY =
+ "android:broadcast.deferralPolicy";
+
+ /**
* The list of delivery group policies which specify how multiple broadcasts belonging to
* the same delivery group has to be handled.
* @hide
*/
- @IntDef(flag = true, prefix = { "DELIVERY_GROUP_POLICY_" }, value = {
+ @IntDef(prefix = { "DELIVERY_GROUP_POLICY_" }, value = {
DELIVERY_GROUP_POLICY_ALL,
DELIVERY_GROUP_POLICY_MOST_RECENT,
+ DELIVERY_GROUP_POLICY_MERGED,
})
@Retention(RetentionPolicy.SOURCE)
public @interface DeliveryGroupPolicy {}
@@ -207,27 +248,80 @@
/**
* Delivery group policy that indicates that all the broadcasts in the delivery group
* need to be delivered as is.
- *
- * @hide
*/
- @SystemApi
public static final int DELIVERY_GROUP_POLICY_ALL = 0;
/**
* Delivery group policy that indicates that only the most recent broadcast in the delivery
* group need to be delivered and the rest can be dropped.
+ */
+ public static final int DELIVERY_GROUP_POLICY_MOST_RECENT = 1;
+
+ /**
+ * Delivery group policy that indicates that the extras data from the broadcasts in the
+ * delivery group need to be merged into a single broadcast and the rest can be dropped.
*
* @hide
*/
- @SystemApi
- public static final int DELIVERY_GROUP_POLICY_MOST_RECENT = 1;
+ public static final int DELIVERY_GROUP_POLICY_MERGED = 2;
- public static BroadcastOptions makeBasic() {
+ /** {@hide} */
+ @IntDef(prefix = { "DEFERRAL_POLICY_" }, value = {
+ DEFERRAL_POLICY_DEFAULT,
+ DEFERRAL_POLICY_NONE,
+ DEFERRAL_POLICY_UNTIL_ACTIVE,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface DeferralPolicy {}
+
+ /**
+ * Deferral policy that indicates no desire has been expressed, and that the
+ * system should use a reasonable default behavior.
+ */
+ public static final int DEFERRAL_POLICY_DEFAULT = 0;
+
+ /**
+ * Deferral policy that indicates a strong desire that no receiver of this
+ * broadcast should be deferred.
+ */
+ public static final int DEFERRAL_POLICY_NONE = 1;
+
+ /**
+ * Deferral policy that indicates a strong desire that each receiver of this
+ * broadcast should be deferred until that receiver's process is in an
+ * active (non-cached) state. Whether an app's process state is considered
+ * active is independent of its standby bucket.
+ * <p>
+ * This policy only applies to runtime registered receivers of a broadcast,
+ * and does not apply to ordered broadcasts, alarm broadcasts, interactive
+ * broadcasts, or manifest broadcasts.
+ * <p>
+ * This policy means that a runtime registered receiver will not typically
+ * execute until that receiver's process is brought to an active state by
+ * some other action, such as a job, alarm, or service binding. As a result,
+ * the receiver may be delayed indefinitely.
+ * <p>
+ * When this policy is set on an unordered broadcast with a completion
+ * callback, the completion callback will run once all eligible processes
+ * have finished receiving the broadcast. Processes in inactive process
+ * state are not considered eligible and may not receive the broadcast prior
+ * to the completion callback.
+ */
+ public static final int DEFERRAL_POLICY_UNTIL_ACTIVE = 2;
+
+ /**
+ * Creates a basic {@link BroadcastOptions} with no options initially set.
+ *
+ * @return an instance of {@code BroadcastOptions} against which options can be set
+ */
+ public static @NonNull BroadcastOptions makeBasic() {
BroadcastOptions opts = new BroadcastOptions();
return opts;
}
- private BroadcastOptions() {
+ /** @hide */
+ @TestApi
+ public BroadcastOptions() {
super();
resetTemporaryAppAllowlist();
}
@@ -237,6 +331,7 @@
public BroadcastOptions(@NonNull Bundle opts) {
super(opts);
// Match the logic in toBundle().
+ mFlags = opts.getInt(KEY_FLAGS, 0);
if (opts.containsKey(KEY_TEMPORARY_APP_ALLOWLIST_DURATION)) {
mTemporaryAppAllowlistDuration = opts.getLong(KEY_TEMPORARY_APP_ALLOWLIST_DURATION);
mTemporaryAppAllowlistType = opts.getInt(KEY_TEMPORARY_APP_ALLOWLIST_TYPE);
@@ -249,15 +344,18 @@
mMinManifestReceiverApiLevel = opts.getInt(KEY_MIN_MANIFEST_RECEIVER_API_LEVEL, 0);
mMaxManifestReceiverApiLevel = opts.getInt(KEY_MAX_MANIFEST_RECEIVER_API_LEVEL,
Build.VERSION_CODES.CUR_DEVELOPMENT);
- mDontSendToRestrictedApps = opts.getBoolean(KEY_DONT_SEND_TO_RESTRICTED_APPS, false);
- mAllowBackgroundActivityStarts = opts.getBoolean(KEY_ALLOW_BACKGROUND_ACTIVITY_STARTS,
- false);
mRequireAllOfPermissions = opts.getStringArray(KEY_REQUIRE_ALL_OF_PERMISSIONS);
mRequireNoneOfPermissions = opts.getStringArray(KEY_REQUIRE_NONE_OF_PERMISSIONS);
mRequireCompatChangeId = opts.getLong(KEY_REQUIRE_COMPAT_CHANGE_ID, CHANGE_INVALID);
- mRequireCompatChangeEnabled = opts.getBoolean(KEY_REQUIRE_COMPAT_CHANGE_ENABLED, true);
mIdForResponseEvent = opts.getLong(KEY_ID_FOR_RESPONSE_EVENT);
- mIsAlarmBroadcast = opts.getBoolean(KEY_ALARM_BROADCAST, false);
+ mDeliveryGroupPolicy = opts.getInt(KEY_DELIVERY_GROUP_POLICY,
+ DELIVERY_GROUP_POLICY_ALL);
+ mDeliveryGroupMatchingKey = opts.getString(KEY_DELIVERY_GROUP_KEY);
+ mDeliveryGroupExtrasMerger = opts.getParcelable(KEY_DELIVERY_GROUP_EXTRAS_MERGER,
+ BundleMerger.class);
+ mDeliveryGroupMatchingFilter = opts.getParcelable(KEY_DELIVERY_GROUP_MATCHING_FILTER,
+ IntentFilter.class);
+ mDeferralPolicy = opts.getInt(KEY_DEFERRAL_POLICY, DEFERRAL_POLICY_DEFAULT);
}
/**
@@ -265,8 +363,10 @@
* power allowlist when this broadcast is being delivered to it.
* @param duration The duration in milliseconds; 0 means to not place on allowlist.
* @deprecated use {@link #setTemporaryAppAllowlist(long, int, int, String)} instead.
+ * @hide
*/
@Deprecated
+ @SystemApi
@RequiresPermission(anyOf = {android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST,
android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND,
android.Manifest.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND})
@@ -280,6 +380,8 @@
* Set a duration for which the system should temporary place an application on the
* power allowlist when this broadcast is being delivered to it, specify the temp allowlist
* type.
+ * @hide
+ *
* @param duration the duration in milliseconds.
* 0 means to not place on allowlist, and clears previous call to this method.
* @param type one of {@link TempAllowListType}.
@@ -290,6 +392,7 @@
* @param reason A human-readable reason explaining why the app is temp allowlisted. Only
* used for logging purposes. Could be null or empty string.
*/
+ @SystemApi
@RequiresPermission(anyOf = {android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST,
android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND,
android.Manifest.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND})
@@ -319,26 +422,6 @@
}
/**
- * Set PendingIntent activity is allowed to be started in the background if the caller
- * can start background activities.
- * @hide
- */
- @SystemApi(client = SystemApi.Client.PRIVILEGED_APPS)
- public void setPendingIntentBackgroundActivityLaunchAllowed(boolean allowed) {
- super.setPendingIntentBackgroundActivityLaunchAllowed(allowed);
- }
-
- /**
- * Get PendingIntent activity is allowed to be started in the background if the caller
- * can start background activities.
- * @hide
- */
- @SystemApi(client = SystemApi.Client.PRIVILEGED_APPS)
- public boolean isPendingIntentBackgroundActivityLaunchAllowed() {
- return super.isPendingIntentBackgroundActivityLaunchAllowed();
- }
-
- /**
* Return {@link #setTemporaryAppAllowlist}.
* @hide
*/
@@ -450,9 +533,15 @@
* Sets whether pending intent can be sent for an application with background restrictions
* @param dontSendToRestrictedApps if true, pending intent will not be sent for an application
* with background restrictions. Default value is {@code false}
+ * @hide
*/
+ @SystemApi
public void setDontSendToRestrictedApps(boolean dontSendToRestrictedApps) {
- mDontSendToRestrictedApps = dontSendToRestrictedApps;
+ if (dontSendToRestrictedApps) {
+ mFlags |= FLAG_DONT_SEND_TO_RESTRICTED_APPS;
+ } else {
+ mFlags &= ~FLAG_DONT_SEND_TO_RESTRICTED_APPS;
+ }
}
/**
@@ -460,24 +549,31 @@
* @return #setDontSendToRestrictedApps
*/
public boolean isDontSendToRestrictedApps() {
- return mDontSendToRestrictedApps;
+ return (mFlags & FLAG_DONT_SEND_TO_RESTRICTED_APPS) != 0;
}
/**
* Sets the process will be able to start activities from background for the duration of
* the broadcast dispatch. Default value is {@code false}
+ * @hide
*/
+ @SystemApi
@RequiresPermission(android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND)
public void setBackgroundActivityStartsAllowed(boolean allowBackgroundActivityStarts) {
- mAllowBackgroundActivityStarts = allowBackgroundActivityStarts;
+ if (allowBackgroundActivityStarts) {
+ mFlags |= FLAG_ALLOW_BACKGROUND_ACTIVITY_STARTS;
+ } else {
+ mFlags &= ~FLAG_ALLOW_BACKGROUND_ACTIVITY_STARTS;
+ }
}
/**
* @hide
* @return #setAllowBackgroundActivityStarts
*/
+ @Deprecated
public boolean allowsBackgroundActivityStarts() {
- return mAllowBackgroundActivityStarts;
+ return (mFlags & FLAG_ALLOW_BACKGROUND_ACTIVITY_STARTS) != 0;
}
/**
@@ -528,6 +624,7 @@
* <p>
* This requirement applies to both manifest registered and runtime
* registered receivers.
+ * @hide
*
* @param changeId the {@link ChangeId} to inspect
* @param enabled the required enabled state of the inspected
@@ -535,18 +632,24 @@
* @see CompatChanges#isChangeEnabled
* @see #clearRequireCompatChange()
*/
+ @SystemApi
public void setRequireCompatChange(long changeId, boolean enabled) {
mRequireCompatChangeId = changeId;
- mRequireCompatChangeEnabled = enabled;
+ if (enabled) {
+ mFlags |= FLAG_REQUIRE_COMPAT_CHANGE_ENABLED;
+ } else {
+ mFlags &= ~FLAG_REQUIRE_COMPAT_CHANGE_ENABLED;
+ }
}
/**
* Clear any previously defined requirement for this broadcast requested via
* {@link #setRequireCompatChange(long, boolean)}.
+ * @hide
*/
+ @SystemApi
public void clearRequireCompatChange() {
- mRequireCompatChangeId = CHANGE_INVALID;
- mRequireCompatChangeEnabled = true;
+ setRequireCompatChange(CHANGE_INVALID, true);
}
/**
@@ -558,7 +661,11 @@
* @param senderIsAlarm Whether the broadcast is alarm-triggered.
*/
public void setAlarmBroadcast(boolean senderIsAlarm) {
- mIsAlarmBroadcast = senderIsAlarm;
+ if (senderIsAlarm) {
+ mFlags |= FLAG_IS_ALARM_BROADCAST;
+ } else {
+ mFlags &= ~FLAG_IS_ALARM_BROADCAST;
+ }
}
/**
@@ -567,7 +674,44 @@
* @hide
*/
public boolean isAlarmBroadcast() {
- return mIsAlarmBroadcast;
+ return (mFlags & FLAG_IS_ALARM_BROADCAST) != 0;
+ }
+
+ /**
+ * Sets whether the identity of the broadcasting app should be shared with all receivers
+ * that will receive this broadcast.
+ *
+ * <p>Use this option when broadcasting to a receiver that needs to know the identity of the
+ * broadcaster; with this set to {@code true}, the receiver will have access to the broadcasting
+ * app's package name and uid.
+ *
+ * <p>Defaults to {@code false} if not set.
+ *
+ * @param shareIdentityEnabled whether the broadcasting app's identity should be shared with the
+ * receiver
+ * @return {@code this} {@link BroadcastOptions} instance
+ * @see BroadcastReceiver#getSentFromUid()
+ * @see BroadcastReceiver#getSentFromPackage()
+ */
+ public @NonNull BroadcastOptions setShareIdentityEnabled(boolean shareIdentityEnabled) {
+ if (shareIdentityEnabled) {
+ mFlags |= FLAG_SHARE_IDENTITY;
+ } else {
+ mFlags &= ~FLAG_SHARE_IDENTITY;
+ }
+ return this;
+ }
+
+ /**
+ * Returns whether the broadcasting app has opted-in to sharing its identity with the receiver.
+ *
+ * @return {@code true} if the broadcasting app has opted in to sharing its identity
+ * @see #setShareIdentityEnabled(boolean)
+ * @see BroadcastReceiver#getSentFromUid()
+ * @see BroadcastReceiver#getSentFromPackage()
+ */
+ public boolean isShareIdentityEnabled() {
+ return (mFlags & FLAG_SHARE_IDENTITY) != 0;
}
/**
@@ -606,8 +750,8 @@
@TestApi
public boolean testRequireCompatChange(int uid) {
if (mRequireCompatChangeId != CHANGE_INVALID) {
- return CompatChanges.isChangeEnabled(mRequireCompatChangeId,
- uid) == mRequireCompatChangeEnabled;
+ final boolean requireEnabled = (mFlags & FLAG_REQUIRE_COMPAT_CHANGE_ENABLED) != 0;
+ return CompatChanges.isChangeEnabled(mRequireCompatChangeId, uid) == requireEnabled;
} else {
return true;
}
@@ -637,15 +781,77 @@
return mIdForResponseEvent;
}
+ /** {@hide} */
+ @SystemApi
+ @Deprecated
+ // STOPSHIP: remove entirely after this API change lands in AOSP
+ public @NonNull BroadcastOptions setDeferUntilActive(boolean shouldDefer) {
+ if (shouldDefer) {
+ setDeferralPolicy(DEFERRAL_POLICY_UNTIL_ACTIVE);
+ } else {
+ setDeferralPolicy(DEFERRAL_POLICY_NONE);
+ }
+ return this;
+ }
+
+ /** {@hide} */
+ @SystemApi
+ @Deprecated
+ // STOPSHIP: remove entirely after this API change lands in AOSP
+ public boolean isDeferUntilActive() {
+ return (mDeferralPolicy == DEFERRAL_POLICY_UNTIL_ACTIVE);
+ }
+
+ /**
+ * Sets deferral policy for this broadcast that specifies how this broadcast
+ * can be deferred for delivery at some future point.
+ */
+ public @NonNull BroadcastOptions setDeferralPolicy(@DeferralPolicy int deferralPolicy) {
+ mDeferralPolicy = deferralPolicy;
+ return this;
+ }
+
+ /**
+ * Gets deferral policy for this broadcast that specifies how this broadcast
+ * can be deferred for delivery at some future point.
+ */
+ public @DeferralPolicy int getDeferralPolicy() {
+ return mDeferralPolicy;
+ }
+
+ /**
+ * Clears any deferral policy for this broadcast that specifies how this
+ * broadcast can be deferred for delivery at some future point.
+ */
+ public void clearDeferralPolicy() {
+ mDeferralPolicy = DEFERRAL_POLICY_DEFAULT;
+ }
+
/**
* Set delivery group policy for this broadcast to specify how multiple broadcasts belonging to
* the same delivery group has to be handled.
- *
- * @hide
*/
- @SystemApi
- public void setDeliveryGroupPolicy(@DeliveryGroupPolicy int policy) {
+ @NonNull
+ public BroadcastOptions setDeliveryGroupPolicy(@DeliveryGroupPolicy int policy) {
mDeliveryGroupPolicy = policy;
+ return this;
+ }
+
+ /**
+ * Get the delivery group policy for this broadcast that specifies how multiple broadcasts
+ * belonging to the same delivery group has to be handled.
+ */
+ public @DeliveryGroupPolicy int getDeliveryGroupPolicy() {
+ return mDeliveryGroupPolicy;
+ }
+
+ /**
+ * Clears any previously set delivery group policies using
+ * {@link #setDeliveryGroupMatchingKey(String, String)} and resets the delivery group policy to
+ * the default value ({@link #DELIVERY_GROUP_POLICY_ALL}).
+ */
+ public void clearDeliveryGroupPolicy() {
+ mDeliveryGroupPolicy = DELIVERY_GROUP_POLICY_ALL;
}
/**
@@ -658,16 +864,36 @@
* <p> If neither matching key using this API nor matching filter using
* {@link #setDeliveryGroupMatchingFilter(IntentFilter)} is specified, then by default
* {@link Intent#filterEquals(Intent)} will be used to identify the delivery group.
- *
- * @hide
*/
- @SystemApi
- public void setDeliveryGroupMatchingKey(@NonNull String namespace, @NonNull String key) {
- Preconditions.checkArgument(!namespace.contains("/"),
- "namespace should not contain '/'");
- Preconditions.checkArgument(!key.contains("/"),
- "key should not contain '/'");
- mDeliveryGroupMatchingKey = namespace + "/" + key;
+ @NonNull
+ public BroadcastOptions setDeliveryGroupMatchingKey(@NonNull String namespace,
+ @NonNull String key) {
+ Preconditions.checkArgument(!namespace.contains(":"),
+ "namespace should not contain ':'");
+ Preconditions.checkArgument(!key.contains(":"),
+ "key should not contain ':'");
+ mDeliveryGroupMatchingKey = namespace + ":" + key;
+ return this;
+ }
+
+ /**
+ * Return the namespace and key that is used to identify the delivery group that this
+ * broadcast belongs to.
+ *
+ * @return the delivery group namespace and key that was previously set using
+ * {@link #setDeliveryGroupMatchingKey(String, String)}, concatenated with a {@code :}.
+ */
+ @Nullable
+ public String getDeliveryGroupMatchingKey() {
+ return mDeliveryGroupMatchingKey;
+ }
+
+ /**
+ * Clears the namespace and key that was previously set using
+ * {@link #setDeliveryGroupMatchingKey(String, String)}.
+ */
+ public void clearDeliveryGroupMatchingKey() {
+ mDeliveryGroupMatchingKey = null;
}
/**
@@ -680,47 +906,158 @@
* <p> If neither matching key using {@link #setDeliveryGroupMatchingKey(String, String)} nor
* matching filter using this API is specified, then by default
* {@link Intent#filterEquals(Intent)} will be used to identify the delivery group.
- *
- * @hide
*/
- @SystemApi
- public void setDeliveryGroupMatchingFilter(@NonNull IntentFilter matchingFilter) {
+ @NonNull
+ public BroadcastOptions setDeliveryGroupMatchingFilter(@NonNull IntentFilter matchingFilter) {
mDeliveryGroupMatchingFilter = Objects.requireNonNull(matchingFilter);
- }
-
- /**
- * Sets whether the broadcast should not run until the process is in an active process state
- * (ie, a process exists for the app and the app is not in a cached process state).
- *
- * Whether an app's process state is considered active is independent of its standby bucket.
- *
- * A broadcast that is deferred until the process is active will not execute until the process
- * is brought to an active state by some other action, like a job, alarm, or service binding. As
- * a result, the broadcast may be delayed indefinitely. This deferral only applies to runtime
- * registered receivers of a broadcast. Any manifest receivers will run immediately, similar to
- * how a manifest receiver would start a new process in order to run a broadcast receiver.
- *
- * Ordered broadcasts, alarm broadcasts, interactive broadcasts, and manifest broadcasts are
- * never deferred.
- *
- * Unordered broadcasts and unordered broadcasts with completion callbacks may be
- * deferred. Completion callbacks for broadcasts deferred until active are
- * best-effort. Completion callbacks will run when all eligible processes have finished
- * executing the broadcast. Processes in inactive process states that defer the broadcast are
- * not considered eligible and may not execute the broadcast prior to the completion callback.
- *
- * @hide
- */
- @SystemApi
- public @NonNull BroadcastOptions setDeferUntilActive(boolean shouldDefer) {
- mIsDeferUntilActive = shouldDefer;
return this;
}
- /** @hide */
+ /**
+ * Return the {@link IntentFilter} object that is used to identify the delivery group
+ * that this broadcast belongs to.
+ *
+ * @return the {@link IntentFilter} object that was previously set using
+ * {@link #setDeliveryGroupMatchingFilter(IntentFilter)}.
+ */
+ @Nullable
+ public IntentFilter getDeliveryGroupMatchingFilter() {
+ return mDeliveryGroupMatchingFilter;
+ }
+
+ /**
+ * Clears the {@link IntentFilter} object that was previously set using
+ * {@link #setDeliveryGroupMatchingFilter(IntentFilter)}.
+ */
+ public void clearDeliveryGroupMatchingFilter() {
+ mDeliveryGroupMatchingFilter = null;
+ }
+
+ /**
+ * Set the {@link BundleMerger} that specifies how to merge the extras data from
+ * broadcasts in a delivery group.
+ *
+ * <p>Note that this value will be ignored if the delivery group policy is not set as
+ * {@link #DELIVERY_GROUP_POLICY_MERGED}.
+ *
+ * @hide
+ */
+ @NonNull
+ public BroadcastOptions setDeliveryGroupExtrasMerger(@NonNull BundleMerger extrasMerger) {
+ mDeliveryGroupExtrasMerger = Objects.requireNonNull(extrasMerger);
+ return this;
+ }
+
+ /**
+ * Return the {@link BundleMerger} that specifies how to merge the extras data from
+ * broadcasts in a delivery group.
+ *
+ * @return the {@link BundleMerger} object that was previously set using
+ * {@link #setDeliveryGroupExtrasMerger(BundleMerger)}.
+ * @hide
+ */
+ @Nullable
+ public BundleMerger getDeliveryGroupExtrasMerger() {
+ return mDeliveryGroupExtrasMerger;
+ }
+
+ /**
+ * Clear the {@link BundleMerger} object that was previously set using
+ * {@link #setDeliveryGroupExtrasMerger(BundleMerger)}.
+ * @hide
+ */
+ public void clearDeliveryGroupExtrasMerger() {
+ mDeliveryGroupExtrasMerger = null;
+ }
+
+ /**
+ * Sets whether the broadcast should be considered as having originated from
+ * some direct interaction by the user such as a notification tap or button
+ * press. This signal is used internally to ensure the broadcast is
+ * delivered quickly with low latency.
+ *
+ * @hide
+ */
+ public @NonNull BroadcastOptions setInteractive(boolean interactive) {
+ if (interactive) {
+ mFlags |= FLAG_INTERACTIVE;
+ } else {
+ mFlags &= ~FLAG_INTERACTIVE;
+ }
+ return this;
+ }
+
+ /**
+ * Returns whether the broadcast should be considered as having originated
+ * from some direct interaction by the user such as a notification tap or
+ * button press.
+ *
+ * @hide
+ */
+ public boolean isInteractive() {
+ return (mFlags & FLAG_INTERACTIVE) != 0;
+ }
+
+ /**
+ * Set PendingIntent activity is allowed to be started in the background if the caller
+ * can start background activities.
+ *
+ * @deprecated use #setPendingIntentBackgroundActivityStartMode(int) to set the full range
+ * of states
+ * @hide
+ */
@SystemApi
- public boolean isDeferUntilActive() {
- return mIsDeferUntilActive;
+ @Override
+ @Deprecated public void setPendingIntentBackgroundActivityLaunchAllowed(boolean allowed) {
+ super.setPendingIntentBackgroundActivityLaunchAllowed(allowed);
+ }
+
+ /**
+ * Get PendingIntent activity is allowed to be started in the background if the caller can start
+ * background activities.
+ *
+ * @deprecated use {@link #getPendingIntentBackgroundActivityStartMode()} since for apps
+ * targeting {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} or higher this value might
+ * not match the actual behavior if the value was not explicitly set.
+ * @hide
+ */
+ @SystemApi
+ @Override
+ @Deprecated public boolean isPendingIntentBackgroundActivityLaunchAllowed() {
+ return super.isPendingIntentBackgroundActivityLaunchAllowed();
+ }
+
+
+ /**
+ * Sets the mode for allowing or denying the senders privileges to start background activities
+ * to the PendingIntent.
+ *
+ * This is typically used when executing {@link PendingIntent#send(Bundle)} or similar
+ * methods. A privileged sender of a PendingIntent should only grant
+ * MODE_BACKGROUND_ACTIVITY_START_ALLOWED if the PendingIntent is from a trusted source and/or
+ * executed on behalf the user.
+ * @hide
+ */
+ @SystemApi
+ @NonNull
+ // @Override // to narrow down the return type
+ public BroadcastOptions setPendingIntentBackgroundActivityStartMode(int state) {
+ // super.setPendingIntentBackgroundActivityStartMode(state);
+ return this;
+ }
+
+ /**
+ * Gets the mode for allowing or denying the senders privileges to start background activities
+ * to the PendingIntent.
+ *
+ * @see #setPendingIntentBackgroundActivityStartMode(int)
+ * @hide
+ */
+ @SystemApi
+ // @Override // to narrow down the return type
+ public int getPendingIntentBackgroundActivityStartMode() {
+ return 0;
+ // return super.getPendingIntentBackgroundActivityStartMode();
}
/**
@@ -730,31 +1067,29 @@
* Note that the returned Bundle is still owned by the BroadcastOptions
* object; you must not modify it, but can supply it to the sendBroadcast
* methods that take an options Bundle.
+ *
+ * @throws IllegalStateException if the broadcast option values are inconsistent. For example,
+ * if the delivery group policy is specified as "MERGED" but no
+ * extras merger is supplied.
*/
@Override
- public Bundle toBundle() {
+ public @NonNull Bundle toBundle() {
Bundle b = super.toBundle();
+ if (mFlags != 0) {
+ b.putInt(KEY_FLAGS, mFlags);
+ }
if (isTemporaryAppAllowlistSet()) {
b.putLong(KEY_TEMPORARY_APP_ALLOWLIST_DURATION, mTemporaryAppAllowlistDuration);
b.putInt(KEY_TEMPORARY_APP_ALLOWLIST_TYPE, mTemporaryAppAllowlistType);
b.putInt(KEY_TEMPORARY_APP_ALLOWLIST_REASON_CODE, mTemporaryAppAllowlistReasonCode);
b.putString(KEY_TEMPORARY_APP_ALLOWLIST_REASON, mTemporaryAppAllowlistReason);
}
- if (mIsAlarmBroadcast) {
- b.putBoolean(KEY_ALARM_BROADCAST, true);
- }
if (mMinManifestReceiverApiLevel != 0) {
b.putInt(KEY_MIN_MANIFEST_RECEIVER_API_LEVEL, mMinManifestReceiverApiLevel);
}
if (mMaxManifestReceiverApiLevel != Build.VERSION_CODES.CUR_DEVELOPMENT) {
b.putInt(KEY_MAX_MANIFEST_RECEIVER_API_LEVEL, mMaxManifestReceiverApiLevel);
}
- if (mDontSendToRestrictedApps) {
- b.putBoolean(KEY_DONT_SEND_TO_RESTRICTED_APPS, true);
- }
- if (mAllowBackgroundActivityStarts) {
- b.putBoolean(KEY_ALLOW_BACKGROUND_ACTIVITY_STARTS, true);
- }
if (mRequireAllOfPermissions != null) {
b.putStringArray(KEY_REQUIRE_ALL_OF_PERMISSIONS, mRequireAllOfPermissions);
}
@@ -763,11 +1098,44 @@
}
if (mRequireCompatChangeId != CHANGE_INVALID) {
b.putLong(KEY_REQUIRE_COMPAT_CHANGE_ID, mRequireCompatChangeId);
- b.putBoolean(KEY_REQUIRE_COMPAT_CHANGE_ENABLED, mRequireCompatChangeEnabled);
}
if (mIdForResponseEvent != 0) {
b.putLong(KEY_ID_FOR_RESPONSE_EVENT, mIdForResponseEvent);
}
- return b.isEmpty() ? null : b;
+ if (mDeliveryGroupPolicy != DELIVERY_GROUP_POLICY_ALL) {
+ b.putInt(KEY_DELIVERY_GROUP_POLICY, mDeliveryGroupPolicy);
+ }
+ if (mDeliveryGroupMatchingKey != null) {
+ b.putString(KEY_DELIVERY_GROUP_KEY, mDeliveryGroupMatchingKey);
+ }
+ if (mDeliveryGroupPolicy == DELIVERY_GROUP_POLICY_MERGED) {
+ if (mDeliveryGroupExtrasMerger != null) {
+ b.putParcelable(KEY_DELIVERY_GROUP_EXTRAS_MERGER,
+ mDeliveryGroupExtrasMerger);
+ } else {
+ throw new IllegalStateException("Extras merger cannot be empty "
+ + "when delivery group policy is 'MERGED'");
+ }
+ }
+ if (mDeliveryGroupMatchingFilter != null) {
+ b.putParcelable(KEY_DELIVERY_GROUP_MATCHING_FILTER, mDeliveryGroupMatchingFilter);
+ }
+ if (mDeferralPolicy != DEFERRAL_POLICY_DEFAULT) {
+ b.putInt(KEY_DEFERRAL_POLICY, mDeferralPolicy);
+ }
+ return b;
+ }
+
+ /**
+ * Returns a {@link BroadcastOptions} parsed from the given {@link Bundle},
+ * typically generated from {@link #toBundle()}.
+ */
+ public static @NonNull BroadcastOptions fromBundle(@NonNull Bundle options) {
+ return new BroadcastOptions(options);
+ }
+
+ /** {@hide} */
+ public static @Nullable BroadcastOptions fromBundleNullable(@Nullable Bundle options) {
+ return (options != null) ? new BroadcastOptions(options) : null;
}
}
diff --git a/core/java/android/os/BundleMerger.java b/core/java/android/os/BundleMerger.java
new file mode 100644
index 0000000..857aaf5
--- /dev/null
+++ b/core/java/android/os/BundleMerger.java
@@ -0,0 +1,388 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.os;
+
+import android.annotation.IntDef;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.util.ArrayMap;
+import android.util.ArraySet;
+import android.util.Log;
+
+import com.android.internal.annotations.VisibleForTesting;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Objects;
+import java.util.function.BinaryOperator;
+
+/**
+ * Configured rules for merging two {@link Bundle} instances.
+ * <p>
+ * By default, values from both {@link Bundle} instances are blended together on
+ * a key-wise basis, and conflicting value definitions for a key are dropped.
+ * <p>
+ * Nuanced strategies for handling conflicting value definitions can be applied
+ * using {@link #setMergeStrategy(String, int)} and
+ * {@link #setDefaultMergeStrategy(int)}.
+ * <p>
+ * When conflicting values have <em>inconsistent</em> data types (such as trying
+ * to merge a {@link String} and a {@link Integer}), both conflicting values are
+ * rejected and the key becomes undefined, regardless of the requested strategy.
+ *
+ * @hide
+ */
+public class BundleMerger implements Parcelable {
+ private static final String TAG = "BundleMerger";
+
+ private @Strategy int mDefaultStrategy = STRATEGY_REJECT;
+
+ private final ArrayMap<String, Integer> mStrategies = new ArrayMap<>();
+
+ /**
+ * Merge strategy that rejects both conflicting values.
+ */
+ public static final int STRATEGY_REJECT = 0;
+
+ /**
+ * Merge strategy that selects the first of conflicting values.
+ */
+ public static final int STRATEGY_FIRST = 1;
+
+ /**
+ * Merge strategy that selects the last of conflicting values.
+ */
+ public static final int STRATEGY_LAST = 2;
+
+ /**
+ * Merge strategy that selects the "minimum" of conflicting values which are
+ * {@link Comparable} with each other.
+ */
+ public static final int STRATEGY_COMPARABLE_MIN = 3;
+
+ /**
+ * Merge strategy that selects the "maximum" of conflicting values which are
+ * {@link Comparable} with each other.
+ */
+ public static final int STRATEGY_COMPARABLE_MAX = 4;
+
+ /**
+ * Merge strategy that numerically adds both conflicting values.
+ */
+ public static final int STRATEGY_NUMBER_ADD = 10;
+
+ /**
+ * Merge strategy that numerically increments the first conflicting value by
+ * {@code 1} and ignores the last conflicting value.
+ */
+ public static final int STRATEGY_NUMBER_INCREMENT_FIRST = 20;
+
+ /**
+ * Merge strategy that numerically increments the first conflicting value by
+ * {@code 1} and also numerically adds both conflicting values.
+ */
+ public static final int STRATEGY_NUMBER_INCREMENT_FIRST_AND_ADD = 25;
+
+ /**
+ * Merge strategy that combines conflicting values using a boolean "and"
+ * operation.
+ */
+ public static final int STRATEGY_BOOLEAN_AND = 30;
+
+ /**
+ * Merge strategy that combines conflicting values using a boolean "or"
+ * operation.
+ */
+ public static final int STRATEGY_BOOLEAN_OR = 40;
+
+ /**
+ * Merge strategy that combines two conflicting array values by appending
+ * the last array after the first array.
+ */
+ public static final int STRATEGY_ARRAY_APPEND = 50;
+
+ /**
+ * Merge strategy that combines two conflicting {@link ArrayList} values by
+ * appending the last {@link ArrayList} after the first {@link ArrayList}.
+ */
+ public static final int STRATEGY_ARRAY_LIST_APPEND = 60;
+
+ @IntDef(flag = false, prefix = { "STRATEGY_" }, value = {
+ STRATEGY_REJECT,
+ STRATEGY_FIRST,
+ STRATEGY_LAST,
+ STRATEGY_COMPARABLE_MIN,
+ STRATEGY_COMPARABLE_MAX,
+ STRATEGY_NUMBER_ADD,
+ STRATEGY_NUMBER_INCREMENT_FIRST,
+ STRATEGY_NUMBER_INCREMENT_FIRST_AND_ADD,
+ STRATEGY_BOOLEAN_AND,
+ STRATEGY_BOOLEAN_OR,
+ STRATEGY_ARRAY_APPEND,
+ STRATEGY_ARRAY_LIST_APPEND,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface Strategy {}
+
+ /**
+ * Create a empty set of rules for merging two {@link Bundle} instances.
+ */
+ public BundleMerger() {
+ }
+
+ private BundleMerger(@NonNull Parcel in) {
+ mDefaultStrategy = in.readInt();
+ final int N = in.readInt();
+ for (int i = 0; i < N; i++) {
+ mStrategies.put(in.readString(), in.readInt());
+ }
+ }
+
+ @Override
+ public void writeToParcel(@NonNull Parcel out, int flags) {
+ out.writeInt(mDefaultStrategy);
+ final int N = mStrategies.size();
+ out.writeInt(N);
+ for (int i = 0; i < N; i++) {
+ out.writeString(mStrategies.keyAt(i));
+ out.writeInt(mStrategies.valueAt(i));
+ }
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ /**
+ * Configure the default merge strategy to be used when there isn't a
+ * more-specific strategy defined for a particular key via
+ * {@link #setMergeStrategy(String, int)}.
+ */
+ public void setDefaultMergeStrategy(@Strategy int strategy) {
+ mDefaultStrategy = strategy;
+ }
+
+ /**
+ * Configure the merge strategy to be used for the given key.
+ * <p>
+ * Subsequent calls for the same key will overwrite any previously
+ * configured strategy.
+ */
+ public void setMergeStrategy(@NonNull String key, @Strategy int strategy) {
+ mStrategies.put(key, strategy);
+ }
+
+ /**
+ * Return the merge strategy to be used for the given key, as defined by
+ * {@link #setMergeStrategy(String, int)}.
+ * <p>
+ * If no specific strategy has been configured for the given key, this
+ * returns {@link #setDefaultMergeStrategy(int)}.
+ */
+ public @Strategy int getMergeStrategy(@NonNull String key) {
+ return (int) mStrategies.getOrDefault(key, mDefaultStrategy);
+ }
+
+ /**
+ * Return a {@link BinaryOperator} which applies the strategies configured
+ * in this object to merge the two given {@link Bundle} arguments.
+ */
+ public BinaryOperator<Bundle> asBinaryOperator() {
+ return this::merge;
+ }
+
+ /**
+ * Apply the strategies configured in this object to merge the two given
+ * {@link Bundle} arguments.
+ *
+ * @return the merged {@link Bundle} result. If one argument is {@code null}
+ * it will return the other argument. If both arguments are null it
+ * will return {@code null}.
+ */
+ @SuppressWarnings("deprecation")
+ public @Nullable Bundle merge(@Nullable Bundle first, @Nullable Bundle last) {
+ if (first == null && last == null) {
+ return null;
+ }
+ if (first == null) {
+ first = Bundle.EMPTY;
+ }
+ if (last == null) {
+ last = Bundle.EMPTY;
+ }
+
+ // Start by bulk-copying all values without attempting to unpack any
+ // custom parcelables; we'll circle back to handle conflicts below
+ final Bundle res = new Bundle();
+ res.putAll(first);
+ res.putAll(last);
+
+ final ArraySet<String> conflictingKeys = new ArraySet<>();
+ conflictingKeys.addAll(first.keySet());
+ conflictingKeys.retainAll(last.keySet());
+ for (int i = 0; i < conflictingKeys.size(); i++) {
+ final String key = conflictingKeys.valueAt(i);
+ final int strategy = getMergeStrategy(key);
+ final Object firstValue = first.get(key);
+ final Object lastValue = last.get(key);
+ try {
+ res.putObject(key, merge(strategy, firstValue, lastValue));
+ } catch (Exception e) {
+ Log.w(TAG, "Failed to merge key " + key + " with " + firstValue + " and "
+ + lastValue + " using strategy " + strategy, e);
+ }
+ }
+ return res;
+ }
+
+ /**
+ * Merge the two given values. If only one of the values is defined, it
+ * always wins, otherwise the given strategy is applied.
+ *
+ * @hide
+ */
+ @VisibleForTesting
+ public static @Nullable Object merge(@Strategy int strategy,
+ @Nullable Object first, @Nullable Object last) {
+ if (first == null) return last;
+ if (last == null) return first;
+
+ if (first.getClass() != last.getClass()) {
+ throw new IllegalArgumentException("Merging requires consistent classes; first "
+ + first.getClass() + " last " + last.getClass());
+ }
+
+ switch (strategy) {
+ case STRATEGY_REJECT:
+ // Only actually reject when the values are different
+ if (Objects.deepEquals(first, last)) {
+ return first;
+ } else {
+ return null;
+ }
+ case STRATEGY_FIRST:
+ return first;
+ case STRATEGY_LAST:
+ return last;
+ case STRATEGY_COMPARABLE_MIN:
+ return comparableMin(first, last);
+ case STRATEGY_COMPARABLE_MAX:
+ return comparableMax(first, last);
+ case STRATEGY_NUMBER_ADD:
+ return numberAdd(first, last);
+ case STRATEGY_NUMBER_INCREMENT_FIRST:
+ return numberIncrementFirst(first, last);
+ case STRATEGY_NUMBER_INCREMENT_FIRST_AND_ADD:
+ return numberAdd(numberIncrementFirst(first, last), last);
+ case STRATEGY_BOOLEAN_AND:
+ return booleanAnd(first, last);
+ case STRATEGY_BOOLEAN_OR:
+ return booleanOr(first, last);
+ case STRATEGY_ARRAY_APPEND:
+ return arrayAppend(first, last);
+ case STRATEGY_ARRAY_LIST_APPEND:
+ return arrayListAppend(first, last);
+ default:
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private static @NonNull Object comparableMin(@NonNull Object first, @NonNull Object last) {
+ return ((Comparable<Object>) first).compareTo(last) < 0 ? first : last;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static @NonNull Object comparableMax(@NonNull Object first, @NonNull Object last) {
+ return ((Comparable<Object>) first).compareTo(last) >= 0 ? first : last;
+ }
+
+ private static @NonNull Object numberAdd(@NonNull Object first, @NonNull Object last) {
+ if (first instanceof Integer) {
+ return ((Integer) first) + ((Integer) last);
+ } else if (first instanceof Long) {
+ return ((Long) first) + ((Long) last);
+ } else if (first instanceof Float) {
+ return ((Float) first) + ((Float) last);
+ } else if (first instanceof Double) {
+ return ((Double) first) + ((Double) last);
+ } else {
+ throw new IllegalArgumentException("Unable to add " + first.getClass());
+ }
+ }
+
+ private static @NonNull Number numberIncrementFirst(@NonNull Object first,
+ @NonNull Object last) {
+ if (first instanceof Integer) {
+ return ((Integer) first) + 1;
+ } else if (first instanceof Long) {
+ return ((Long) first) + 1L;
+ } else {
+ throw new IllegalArgumentException("Unable to add " + first.getClass());
+ }
+ }
+
+ private static @NonNull Object booleanAnd(@NonNull Object first, @NonNull Object last) {
+ return ((Boolean) first) && ((Boolean) last);
+ }
+
+ private static @NonNull Object booleanOr(@NonNull Object first, @NonNull Object last) {
+ return ((Boolean) first) || ((Boolean) last);
+ }
+
+ private static @NonNull Object arrayAppend(@NonNull Object first, @NonNull Object last) {
+ if (!first.getClass().isArray()) {
+ throw new IllegalArgumentException("Unable to append " + first.getClass());
+ }
+ final Class<?> clazz = first.getClass().getComponentType();
+ final int firstLength = Array.getLength(first);
+ final int lastLength = Array.getLength(last);
+ final Object res = Array.newInstance(clazz, firstLength + lastLength);
+ System.arraycopy(first, 0, res, 0, firstLength);
+ System.arraycopy(last, 0, res, firstLength, lastLength);
+ return res;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static @NonNull Object arrayListAppend(@NonNull Object first, @NonNull Object last) {
+ if (!(first instanceof ArrayList)) {
+ throw new IllegalArgumentException("Unable to append " + first.getClass());
+ }
+ final ArrayList<Object> firstList = (ArrayList<Object>) first;
+ final ArrayList<Object> lastList = (ArrayList<Object>) last;
+ final ArrayList<Object> res = new ArrayList<>(firstList.size() + lastList.size());
+ res.addAll(firstList);
+ res.addAll(lastList);
+ return res;
+ }
+
+ public static final @android.annotation.NonNull Parcelable.Creator<BundleMerger> CREATOR =
+ new Parcelable.Creator<BundleMerger>() {
+ @Override
+ public BundleMerger createFromParcel(Parcel in) {
+ return new BundleMerger(in);
+ }
+
+ @Override
+ public BundleMerger[] newArray(int size) {
+ return new BundleMerger[size];
+ }
+ };
+}
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 8764906..2c2993b 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -6336,4 +6336,7 @@
<!-- Title for preference of the system default locale. [CHAR LIMIT=50]-->
<string name="system_locale_title">System default</string>
+
+ <!-- Display content to tell the user the sim card name and number-->
+ <string name="default_card_name">CARD <xliff:g id="cardNumber" example="1">%d</xliff:g></string>
</resources>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 8477afa..b16d9e5 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -4884,4 +4884,5 @@
<java-symbol type="dimen" name="status_bar_height_default" />
<java-symbol type="bool" name="system_server_plays_face_haptics" />
+ <java-symbol type="string" name="default_card_name"/>
</resources>
diff --git a/services/core/java/com/android/server/camera/CameraServiceProxy.java b/services/core/java/com/android/server/camera/CameraServiceProxy.java
index aec60de..96fcd9d 100644
--- a/services/core/java/com/android/server/camera/CameraServiceProxy.java
+++ b/services/core/java/com/android/server/camera/CameraServiceProxy.java
@@ -487,7 +487,8 @@
if ((recentTasks != null) && (!recentTasks.getList().isEmpty())) {
for (ActivityManager.RecentTaskInfo task : recentTasks.getList()) {
- if (packageName.equals(task.topActivityInfo.packageName)) {
+ if (task.topActivityInfo != null && packageName.equals(
+ task.topActivityInfo.packageName)) {
taskInfo = new TaskInfo();
taskInfo.frontTaskId = task.taskId;
taskInfo.isResizeable =
diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java
index 1ce917c..6d3f8fd 100644
--- a/services/core/java/com/android/server/connectivity/Vpn.java
+++ b/services/core/java/com/android/server/connectivity/Vpn.java
@@ -21,6 +21,7 @@
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_METERED;
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VPN;
+import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
import static android.net.NetworkCapabilities.TRANSPORT_VPN;
import static android.net.RouteInfo.RTN_THROW;
import static android.net.RouteInfo.RTN_UNREACHABLE;
@@ -29,6 +30,7 @@
import static android.net.ipsec.ike.IkeSessionParams.ESP_IP_VERSION_AUTO;
import static android.os.PowerWhitelistManager.REASON_VPN;
import static android.os.UserHandle.PER_USER_RANGE;
+import static android.telephony.CarrierConfigManager.KEY_MIN_UDP_PORT_4500_NAT_TIMEOUT_SEC_INT;
import static com.android.net.module.util.NetworkStackConstants.IPV6_MIN_MTU;
import static com.android.server.vcn.util.PersistableBundleUtils.STRING_DESERIALIZER;
@@ -79,7 +81,9 @@
import android.net.NetworkProvider;
import android.net.NetworkRequest;
import android.net.NetworkScore;
+import android.net.NetworkSpecifier;
import android.net.RouteInfo;
+import android.net.TelephonyNetworkSpecifier;
import android.net.UidRangeParcel;
import android.net.UnderlyingNetworkInfo;
import android.net.Uri;
@@ -127,12 +131,16 @@
import android.system.keystore2.Domain;
import android.system.keystore2.KeyDescriptor;
import android.system.keystore2.KeyPermission;
+import android.telephony.CarrierConfigManager;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.IndentingPrintWriter;
import android.util.LocalLog;
import android.util.Log;
import android.util.Range;
+import android.util.SparseArray;
import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
@@ -268,6 +276,10 @@
private final ConnectivityManager mConnectivityManager;
private final AppOpsManager mAppOpsManager;
private final ConnectivityDiagnosticsManager mConnectivityDiagnosticsManager;
+ private final TelephonyManager mTelephonyManager;
+ private final CarrierConfigManager mCarrierConfigManager;
+ private final SubscriptionManager mSubscriptionManager;
+
// The context is for specific user which is created from mUserId
private final Context mUserIdContext;
@VisibleForTesting final Dependencies mDeps;
@@ -314,6 +326,14 @@
private final LocalLog mVpnManagerEvents = new LocalLog(MAX_EVENTS_LOGS);
/**
+ * Cached Map of <subscription ID, keepalive delay ms> since retrieving the PersistableBundle
+ * and the target value from CarrierConfigManager is somewhat expensive as it has hundreds of
+ * fields. This cache is cleared when the carrier config changes to ensure data freshness.
+ */
+ @GuardedBy("this")
+ private final SparseArray<Integer> mCachedKeepalivePerSubId = new SparseArray<>();
+
+ /**
* Whether to keep the connection active after rebooting, or upgrading or reinstalling. This
* only applies to {@link VpnService} connections.
*/
@@ -626,6 +646,10 @@
mUserIdContext = context.createContextAsUser(UserHandle.of(userId), 0 /* flags */);
mConnectivityDiagnosticsManager =
mContext.getSystemService(ConnectivityDiagnosticsManager.class);
+ mCarrierConfigManager = mContext.getSystemService(CarrierConfigManager.class);
+ mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
+ mSubscriptionManager = mContext.getSystemService(SubscriptionManager.class);
+
mDeps = deps;
mNms = netService;
mNetd = netd;
@@ -2893,6 +2917,24 @@
*/
private int mRetryCount = 0;
+ private CarrierConfigManager.CarrierConfigChangeListener mCarrierConfigChangeListener =
+ new CarrierConfigManager.CarrierConfigChangeListener() {
+ @Override
+ public void onCarrierConfigChanged(int slotIndex, int subId, int carrierId,
+ int specificCarrierId) {
+ synchronized (Vpn.this) {
+ mCachedKeepalivePerSubId.remove(subId);
+
+ // Ignore stale runner.
+ if (mVpnRunner != Vpn.IkeV2VpnRunner.this) return;
+
+ maybeMigrateIkeSession(mActiveNetwork);
+ }
+ // TODO: update the longLivedTcpConnectionsExpensive value in the
+ // networkcapabilities of the VPN network.
+ }
+ };
+
IkeV2VpnRunner(
@NonNull Ikev2VpnProfile profile, @NonNull ScheduledThreadPoolExecutor executor) {
super(TAG);
@@ -2918,6 +2960,9 @@
setVpnNetworkPreference(mSessionKey,
createUserAndRestrictedProfilesRanges(mUserId,
mConfig.allowedApplications, mConfig.disallowedApplications));
+
+ mCarrierConfigManager.registerCarrierConfigChangeListener(mExecutor,
+ mCarrierConfigChangeListener);
}
@Override
@@ -3257,8 +3302,6 @@
mUnderlyingLinkProperties = null;
mUnderlyingNetworkCapabilities = null;
mRetryCount = 0;
-
- startOrMigrateIkeSession(network);
}
@NonNull
@@ -3356,9 +3399,36 @@
}
private int guessNattKeepaliveTimerForNetwork() {
- // TODO : guess the keepalive delay based on carrier if auto keepalive timer is
- // enabled
- return AUTOMATIC_KEEPALIVE_DELAY_SECONDS;
+ final int subId = getCellSubIdForNetworkCapabilities(mUnderlyingNetworkCapabilities);
+ if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ Log.d(TAG, "Underlying network is not a cellular network");
+ return AUTOMATIC_KEEPALIVE_DELAY_SECONDS;
+ }
+
+ synchronized (Vpn.this) {
+ if (mCachedKeepalivePerSubId.contains(subId)) {
+ Log.d(TAG, "Get cached keepalive config");
+ return mCachedKeepalivePerSubId.get(subId);
+ }
+
+ final TelephonyManager perSubTm = mTelephonyManager.createForSubscriptionId(subId);
+ if (perSubTm.getSimApplicationState() != TelephonyManager.SIM_STATE_LOADED) {
+ Log.d(TAG, "SIM card is not ready on sub " + subId);
+ return AUTOMATIC_KEEPALIVE_DELAY_SECONDS;
+ }
+
+ final PersistableBundle carrierConfig =
+ mCarrierConfigManager.getConfigForSubId(subId);
+ if (!CarrierConfigManager.isConfigForIdentifiedCarrier(carrierConfig)) {
+ return AUTOMATIC_KEEPALIVE_DELAY_SECONDS;
+ }
+
+ final int natKeepalive =
+ carrierConfig.getInt(KEY_MIN_UDP_PORT_4500_NAT_TIMEOUT_SEC_INT);
+ mCachedKeepalivePerSubId.put(subId, natKeepalive);
+ Log.d(TAG, "Get customized keepalive=" + natKeepalive);
+ return natKeepalive;
+ }
}
boolean maybeMigrateIkeSession(@NonNull Network underlyingNetwork) {
@@ -3456,7 +3526,15 @@
/** Called when the NetworkCapabilities of underlying network is changed */
public void onDefaultNetworkCapabilitiesChanged(@NonNull NetworkCapabilities nc) {
+ final NetworkCapabilities oldNc = mUnderlyingNetworkCapabilities;
mUnderlyingNetworkCapabilities = nc;
+ if (oldNc == null) {
+ // A new default network is available.
+ startOrMigrateIkeSession(mActiveNetwork);
+ } else if (!nc.getSubscriptionIds().equals(oldNc.getSubscriptionIds())) {
+ // Renew carrierConfig values.
+ maybeMigrateIkeSession(mActiveNetwork);
+ }
}
/** Called when the LinkProperties of underlying network is changed */
@@ -3812,6 +3890,8 @@
resetIkeState();
+ mCarrierConfigManager.unregisterCarrierConfigChangeListener(
+ mCarrierConfigChangeListener);
mConnectivityManager.unregisterNetworkCallback(mNetworkCallback);
mConnectivityDiagnosticsManager.unregisterConnectivityDiagnosticsCallback(
mDiagnosticsCallback);
@@ -4804,6 +4884,8 @@
pw.println("Reset session scheduled");
}
}
+ pw.println("mCachedKeepalivePerSubId=" + mCachedKeepalivePerSubId);
+
pw.println("mUnderlyNetworkChanges (most recent first):");
pw.increaseIndent();
mUnderlyNetworkChanges.reverseDump(pw);
@@ -4815,4 +4897,19 @@
pw.decreaseIndent();
}
}
+
+ private static int getCellSubIdForNetworkCapabilities(@Nullable NetworkCapabilities nc) {
+ if (nc == null) return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
+
+ if (!nc.hasTransport(TRANSPORT_CELLULAR)) {
+ return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
+ }
+
+ final NetworkSpecifier specifier = nc.getNetworkSpecifier();
+ if (specifier instanceof TelephonyNetworkSpecifier) {
+ return ((TelephonyNetworkSpecifier) specifier).getSubscriptionId();
+ }
+
+ return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
+ }
}
diff --git a/services/core/java/com/android/server/notification/OWNERS b/services/core/java/com/android/server/notification/OWNERS
index 5a19656..6c4dd6d 100644
--- a/services/core/java/com/android/server/notification/OWNERS
+++ b/services/core/java/com/android/server/notification/OWNERS
@@ -1,4 +1,6 @@
-dsandler@android.com
+# Bug component: 34005
+
juliacr@google.com
-beverlyt@google.com
-pixel@google.com
+yurilin@google.com
+jeffdq@google.com
+dsandler@android.com
\ No newline at end of file
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index cae0234..49cab3d 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -1711,7 +1711,7 @@
: null;
}
- private void clearLastParentBeforePip() {
+ void clearLastParentBeforePip() {
if (mLastParentBeforePip != null) {
mLastParentBeforePip.mChildPipActivity = null;
mLastParentBeforePip = null;
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 8993840..a7c2733 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -2569,6 +2569,9 @@
EventLogTags.writeWmTaskRemoved(mTaskId, reason);
clearPinnedTaskIfNeed();
+ if (mChildPipActivity != null) {
+ mChildPipActivity.clearLastParentBeforePip();
+ }
// If applicable let the TaskOrganizer know the Task is vanishing.
setTaskOrganizer(null);
diff --git a/services/tests/servicestests/src/com/android/server/dreams/OWNERS b/services/tests/servicestests/src/com/android/server/dreams/OWNERS
new file mode 100644
index 0000000..2f19cf5
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/dreams/OWNERS
@@ -0,0 +1 @@
+include /core/java/android/service/dreams/OWNERS
diff --git a/telephony/java/android/service/euicc/EuiccService.java b/telephony/java/android/service/euicc/EuiccService.java
index dc695d6..e19117b 100644
--- a/telephony/java/android/service/euicc/EuiccService.java
+++ b/telephony/java/android/service/euicc/EuiccService.java
@@ -730,6 +730,25 @@
}
/**
+ * Result code to string
+ *
+ * @param result The result code.
+ * @return The result code in string format.
+ *
+ * @hide
+ */
+ public static String resultToString(@Result int result) {
+ switch (result) {
+ case RESULT_OK: return "OK";
+ case RESULT_MUST_DEACTIVATE_SIM : return "MUST_DEACTIVATE_SIM";
+ case RESULT_RESOLVABLE_ERRORS: return "RESOLVABLE_ERRORS";
+ case RESULT_FIRST_USER: return "FIRST_USER";
+ default:
+ return "UNKNOWN(" + result + ")";
+ }
+ }
+
+ /**
* Wrapper around IEuiccService that forwards calls to implementations of {@link EuiccService}.
*/
private class IEuiccServiceWrapper extends IEuiccService.Stub {
diff --git a/telephony/java/android/service/euicc/GetEuiccProfileInfoListResult.java b/telephony/java/android/service/euicc/GetEuiccProfileInfoListResult.java
index 9add38e..46a049c 100644
--- a/telephony/java/android/service/euicc/GetEuiccProfileInfoListResult.java
+++ b/telephony/java/android/service/euicc/GetEuiccProfileInfoListResult.java
@@ -123,4 +123,16 @@
public int describeContents() {
return 0;
}
+
+ /**
+ * @hide
+ *
+ * @return String representation of {@link GetEuiccProfileInfoListResult}
+ */
+ @Override
+ public String toString() {
+ return "[GetEuiccProfileInfoListResult: result=" + EuiccService.resultToString(result)
+ + ", isRemovable=" + mIsRemovable + ", mProfiles=" + Arrays.toString(mProfiles)
+ + "]";
+ }
}