diff options
| -rw-r--r-- | api/current.txt | 4 | ||||
| -rw-r--r-- | core/java/android/content/Intent.java | 95 | ||||
| -rw-r--r-- | core/res/res/values/attrs_manifest.xml | 3 | ||||
| -rw-r--r-- | core/res/res/values/public.xml | 1 |
4 files changed, 98 insertions, 5 deletions
diff --git a/api/current.txt b/api/current.txt index a26df166c994..d3b5f531d4dd 100644 --- a/api/current.txt +++ b/api/current.txt @@ -734,6 +734,7 @@ package android { field public static final int iconTintMode = 16844127; // 0x101055f field public static final int iconifiedByDefault = 16843514; // 0x10102fa field public static final int id = 16842960; // 0x10100d0 + field public static final int identifier = 16844204; // 0x10105ac field public static final int ignoreGravity = 16843263; // 0x10101ff field public static final int imageButtonStyle = 16842866; // 0x1010072 field public static final int imageWellStyle = 16842867; // 0x1010073 @@ -10085,6 +10086,7 @@ package android.content { method public int getFlags(); method @Nullable public float[] getFloatArrayExtra(String); method public float getFloatExtra(String, float); + method @Nullable public String getIdentifier(); method @Nullable public int[] getIntArrayExtra(String); method public int getIntExtra(String, int); method @Nullable public java.util.ArrayList<java.lang.Integer> getIntegerArrayListExtra(String); @@ -10168,6 +10170,7 @@ package android.content { method @NonNull public android.content.Intent setDataAndTypeAndNormalize(@NonNull android.net.Uri, @Nullable String); method public void setExtrasClassLoader(@Nullable ClassLoader); method @NonNull public android.content.Intent setFlags(int); + method @NonNull public android.content.Intent setIdentifier(@Nullable String); method @NonNull public android.content.Intent setPackage(@Nullable String); method public void setSelector(@Nullable android.content.Intent); method public void setSourceBounds(@Nullable android.graphics.Rect); @@ -10428,6 +10431,7 @@ package android.content { field public static final int FILL_IN_CLIP_DATA = 128; // 0x80 field public static final int FILL_IN_COMPONENT = 8; // 0x8 field public static final int FILL_IN_DATA = 2; // 0x2 + field public static final int FILL_IN_IDENTIFIER = 256; // 0x100 field public static final int FILL_IN_PACKAGE = 16; // 0x10 field public static final int FILL_IN_SELECTOR = 64; // 0x40 field public static final int FILL_IN_SOURCE_BOUNDS = 32; // 0x20 diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java index 8628d32123bc..e66cd31a0641 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -643,6 +643,7 @@ public class Intent implements Parcelable, Cloneable { private static final String ATTR_CATEGORY = "category"; private static final String TAG_EXTRA = "extra"; private static final String ATTR_TYPE = "type"; + private static final String ATTR_IDENTIFIER = "ident"; private static final String ATTR_COMPONENT = "component"; private static final String ATTR_DATA = "data"; private static final String ATTR_FLAGS = "flags"; @@ -6314,6 +6315,7 @@ public class Intent implements Parcelable, Cloneable { private String mAction; private Uri mData; private String mType; + private String mIdentifier; private String mPackage; private ComponentName mComponent; private int mFlags; @@ -6359,6 +6361,7 @@ public class Intent implements Parcelable, Cloneable { this.mAction = o.mAction; this.mData = o.mData; this.mType = o.mType; + this.mIdentifier = o.mIdentifier; this.mPackage = o.mPackage; this.mComponent = o.mComponent; @@ -6678,6 +6681,11 @@ public class Intent implements Parcelable, Cloneable { intent.mType = value; } + // identifier + else if (uri.startsWith("identifier=", i)) { + intent.mIdentifier = value; + } + // launch flags else if (uri.startsWith("launchFlags=", i)) { intent.mFlags = Integer.decode(value).intValue(); @@ -7017,6 +7025,12 @@ public class Intent implements Parcelable, Cloneable { hasIntentInfo = true; } break; + case "-i": + intent.setIdentifier(cmd.getNextArgRequired()); + if (intent == baseIntent) { + hasIntentInfo = true; + } + break; case "-c": intent.addCategory(cmd.getNextArgRequired()); if (intent == baseIntent) { @@ -7375,7 +7389,7 @@ public class Intent implements Parcelable, Cloneable { public static void printIntentArgsHelp(PrintWriter pw, String prefix) { final String[] lines = new String[] { "<INTENT> specifications include these flags and arguments:", - " [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]", + " [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>] [-i <IDENTIFIER>]", " [-c <CATEGORY> [-c <CATEGORY>] ...]", " [-n <COMPONENT_NAME>]", " [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]", @@ -7557,6 +7571,18 @@ public class Intent implements Parcelable, Cloneable { } /** + * Retrieve the identifier for this Intent. If non-null, this is an arbitrary identity + * of the Intent to distinguish it from other Intents. + * + * @return The identifier of this intent or null if none is specified. + * + * @see #setIdentifier + */ + public @Nullable String getIdentifier() { + return mIdentifier; + } + + /** * Check if a category exists in the intent. * * @param category The category to check. @@ -8576,6 +8602,28 @@ public class Intent implements Parcelable, Cloneable { } /** + * Set an identifier for this Intent. If set, this provides a unique identity for this Intent, + * allowing it to be unique from other Intents that would otherwise look the same. In + * particular, this will be used by {@link #filterEquals(Intent)} to determine if two + * Intents are the same as with other fields like {@link #setAction}. However, unlike those + * fields, the identifier is <em>never</em> used for matching against an {@link IntentFilter}; + * it is as if the identifier has not been set on the Intent. + * + * @param identifier The identifier for this Intent. The contents of the string have no + * meaning to the system, except whether they are exactly the same as + * another identifier. + * + * @return Returns the same Intent object, for chaining multiple calls + * into a single statement. + * + * @see #getIdentifier + */ + public @NonNull Intent setIdentifier(@Nullable String identifier) { + mIdentifier = identifier; + return this; + } + + /** * Add a new category to the intent. Categories provide additional detail * about the action the intent performs. When resolving an intent, only * activities that provide <em>all</em> of the requested categories will be @@ -9693,6 +9741,12 @@ public class Intent implements Parcelable, Cloneable { public static final int FILL_IN_CLIP_DATA = 1<<7; /** + * Use with {@link #fillIn} to allow the current identifier value to be + * overwritten, even if it is already set. + */ + public static final int FILL_IN_IDENTIFIER = 1<<8; + + /** * Copy the contents of <var>other</var> in to this object, but only * where fields are not defined by this object. For purposes of a field * being defined, the following pieces of data in the Intent are @@ -9702,6 +9756,7 @@ public class Intent implements Parcelable, Cloneable { * <li> action, as set by {@link #setAction}. * <li> data Uri and MIME type, as set by {@link #setData(Uri)}, * {@link #setType(String)}, or {@link #setDataAndType(Uri, String)}. + * <li> identifier, as set by {@link #setIdentifier}. * <li> categories, as set by {@link #addCategory}. * <li> package, as set by {@link #setPackage}. * <li> component, as set by {@link #setComponent(ComponentName)} or @@ -9713,8 +9768,8 @@ public class Intent implements Parcelable, Cloneable { * </ul> * * <p>In addition, you can use the {@link #FILL_IN_ACTION}, - * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, {@link #FILL_IN_PACKAGE}, - * {@link #FILL_IN_COMPONENT}, {@link #FILL_IN_SOURCE_BOUNDS}, + * {@link #FILL_IN_DATA}, {@link #FILL_IN_IDENTIFIER}, {@link #FILL_IN_CATEGORIES}, + * {@link #FILL_IN_PACKAGE}, {@link #FILL_IN_COMPONENT}, {@link #FILL_IN_SOURCE_BOUNDS}, * {@link #FILL_IN_SELECTOR}, and {@link #FILL_IN_CLIP_DATA} to override * the restriction where the corresponding field will not be replaced if * it is already set. @@ -9758,6 +9813,11 @@ public class Intent implements Parcelable, Cloneable { changes |= FILL_IN_DATA; mayHaveCopiedUris = true; } + if (other.mIdentifier != null + && (mIdentifier == null || (flags&FILL_IN_IDENTIFIER) != 0)) { + mIdentifier = other.mIdentifier; + changes |= FILL_IN_IDENTIFIER; + } if (other.mCategories != null && (mCategories == null || (flags&FILL_IN_CATEGORIES) != 0)) { if (other.mCategories != null) { @@ -9871,9 +9931,11 @@ public class Intent implements Parcelable, Cloneable { /** * Determine if two intents are the same for the purposes of intent - * resolution (filtering). That is, if their action, data, type, + * resolution (filtering). That is, if their action, data, type, identity, * class, and categories are the same. This does <em>not</em> compare - * any extra data included in the intents. + * any extra data included in the intents. Note that technically when actually + * matching against an {@link IntentFilter} the identifier is ignored, while here + * it is directly compared for equality like the other fields. * * @param other The other Intent to compare against. * @@ -9887,6 +9949,7 @@ public class Intent implements Parcelable, Cloneable { if (!Objects.equals(this.mAction, other.mAction)) return false; if (!Objects.equals(this.mData, other.mData)) return false; if (!Objects.equals(this.mType, other.mType)) return false; + if (!Objects.equals(this.mIdentifier, other.mIdentifier)) return false; if (!Objects.equals(this.mPackage, other.mPackage)) return false; if (!Objects.equals(this.mComponent, other.mComponent)) return false; if (!Objects.equals(this.mCategories, other.mCategories)) return false; @@ -9913,6 +9976,9 @@ public class Intent implements Parcelable, Cloneable { if (mType != null) { code += mType.hashCode(); } + if (mIdentifier != null) { + code += mIdentifier.hashCode(); + } if (mPackage != null) { code += mPackage.hashCode(); } @@ -10005,6 +10071,13 @@ public class Intent implements Parcelable, Cloneable { first = false; b.append("typ=").append(mType); } + if (mIdentifier != null) { + if (!first) { + b.append(' '); + } + first = false; + b.append("id=").append(mIdentifier); + } if (mFlags != 0) { if (!first) { b.append(' '); @@ -10276,6 +10349,9 @@ public class Intent implements Parcelable, Cloneable { if (mType != null) { uri.append("type=").append(Uri.encode(mType, "/")).append(';'); } + if (mIdentifier != null) { + uri.append("identifier=").append(Uri.encode(mIdentifier, "/")).append(';'); + } if (mFlags != 0) { uri.append("launchFlags=0x").append(Integer.toHexString(mFlags)).append(';'); } @@ -10326,6 +10402,7 @@ public class Intent implements Parcelable, Cloneable { out.writeString(mAction); Uri.writeToParcel(out, mData); out.writeString(mType); + out.writeString(mIdentifier); out.writeInt(mFlags); out.writeString(mPackage); ComponentName.writeToParcel(mComponent, out); @@ -10383,6 +10460,7 @@ public class Intent implements Parcelable, Cloneable { setAction(in.readString()); mData = Uri.CREATOR.createFromParcel(in); mType = in.readString(); + mIdentifier = in.readString(); mFlags = in.readInt(); mPackage = in.readString(); mComponent = ComponentName.readFromParcel(in); @@ -10445,6 +10523,8 @@ public class Intent implements Parcelable, Cloneable { String mimeType = sa.getString(com.android.internal.R.styleable.Intent_mimeType); intent.setDataAndType(data != null ? Uri.parse(data) : null, mimeType); + intent.setIdentifier(sa.getString(com.android.internal.R.styleable.Intent_identifier)); + String packageName = sa.getString(com.android.internal.R.styleable.Intent_targetPackage); String className = sa.getString(com.android.internal.R.styleable.Intent_targetClass); if (packageName != null && className != null) { @@ -10499,6 +10579,9 @@ public class Intent implements Parcelable, Cloneable { if (mType != null) { out.attribute(null, ATTR_TYPE, mType); } + if (mIdentifier != null) { + out.attribute(null, ATTR_IDENTIFIER, mIdentifier); + } if (mComponent != null) { out.attribute(null, ATTR_COMPONENT, mComponent.flattenToShortString()); } @@ -10529,6 +10612,8 @@ public class Intent implements Parcelable, Cloneable { intent.setData(Uri.parse(attrValue)); } else if (ATTR_TYPE.equals(attrName)) { intent.setType(attrValue); + } else if (ATTR_IDENTIFIER.equals(attrName)) { + intent.setIdentifier(attrValue); } else if (ATTR_COMPONENT.equals(attrName)) { intent.setComponent(ComponentName.unflattenFromString(attrValue)); } else if (ATTR_FLAGS.equals(attrName)) { diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml index 47c243ca1e04..2635dab497db 100644 --- a/core/res/res/values/attrs_manifest.xml +++ b/core/res/res/values/attrs_manifest.xml @@ -2814,6 +2814,9 @@ case-sensitive, unlike formal RFC MIME types. As a result, MIME types here should always use lower case letters.</em></p> --> <attr name="mimeType" /> + <!-- The identifier to assign to the intent, as per + {@link android.content.Intent#setIdentifier Intent.setIdentifier()}. --> + <attr name="identifier" format="string" /> <!-- The package part of the ComponentName to assign to the Intent, as per {@link android.content.Intent#setComponent Intent.setComponent()}. --> <attr name="targetPackage" /> diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index 626518c97ac1..b95e6ea6fe0e 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -2945,6 +2945,7 @@ <public name="allowExternalStorageSandbox"/> <public name="ensuringStatusBarContrastWhenTransparent" /> <public name="ensuringNavigationBarContrastWhenTransparent" /> + <public name="identifier" /> </public-group> <public-group type="drawable" first-id="0x010800b4"> |