From cd70c64f50be9e20c926a82bab3e9a737b05e464 Mon Sep 17 00:00:00 2001 From: Adam Skory Date: Fri, 5 Jun 2015 11:41:55 -0600 Subject: [PATCH] Record provision of custom Intents in AssistContent Simplifies behavior wrt automatically setting the web URI for ACTION_VIEW Intents, by not doing so for custom Intents. Adds a boolean isAppProvidedIntent() as a signal for recepients of the AssistContent that a custom Intent was provided. Custom Intents are more likely to be relevant. Change-Id: Ibe4bfa040eba904411b9820ab4ddfcf509413829 --- api/current.txt | 3 +- api/system-current.txt | 3 +- core/java/android/app/ActivityThread.java | 4 +-- core/java/android/app/AssistContent.java | 40 ++++++++++++++++++----- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/api/current.txt b/api/current.txt index 1d445cfc67041..03850b5c9f9e8 100644 --- a/api/current.txt +++ b/api/current.txt @@ -4000,6 +4000,7 @@ package android.app { ctor public AssistContent(); method public android.content.ClipData getClipData(); method public android.net.Uri getWebUri(); + method public boolean isAppProvidedIntent(); method public void setClipData(android.content.ClipData); method public void setIntent(android.content.Intent); method public void setWebUri(android.net.Uri); @@ -24488,10 +24489,10 @@ package android.provider { public final class AlarmClock { ctor public AlarmClock(); + field public static final java.lang.String ACTION_DISMISS_ALARM = "android.intent.action.DISMISS_ALARM"; field public static final java.lang.String ACTION_SET_ALARM = "android.intent.action.SET_ALARM"; field public static final java.lang.String ACTION_SET_TIMER = "android.intent.action.SET_TIMER"; field public static final java.lang.String ACTION_SHOW_ALARMS = "android.intent.action.SHOW_ALARMS"; - field public static final java.lang.String ACTION_DISMISS_ALARM = "android.intent.action.DISMISS_ALARM"; field public static final java.lang.String ACTION_SNOOZE_ALARM = "android.intent.action.SNOOZE_ALARM"; field public static final java.lang.String ALARM_SEARCH_MODE_ALL = "android.all"; field public static final java.lang.String ALARM_SEARCH_MODE_LABEL = "android.label"; diff --git a/api/system-current.txt b/api/system-current.txt index ae4bae6bb3bfe..5ce6319215199 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -4096,6 +4096,7 @@ package android.app { ctor public AssistContent(); method public android.content.ClipData getClipData(); method public android.net.Uri getWebUri(); + method public boolean isAppProvidedIntent(); method public void setClipData(android.content.ClipData); method public void setIntent(android.content.Intent); method public void setWebUri(android.net.Uri); @@ -26418,10 +26419,10 @@ package android.provider { public final class AlarmClock { ctor public AlarmClock(); + field public static final java.lang.String ACTION_DISMISS_ALARM = "android.intent.action.DISMISS_ALARM"; field public static final java.lang.String ACTION_SET_ALARM = "android.intent.action.SET_ALARM"; field public static final java.lang.String ACTION_SET_TIMER = "android.intent.action.SET_TIMER"; field public static final java.lang.String ACTION_SHOW_ALARMS = "android.intent.action.SHOW_ALARMS"; - field public static final java.lang.String ACTION_DISMISS_ALARM = "android.intent.action.DISMISS_ALARM"; field public static final java.lang.String ACTION_SNOOZE_ALARM = "android.intent.action.SNOOZE_ALARM"; field public static final java.lang.String ALARM_SEARCH_MODE_ALL = "android.all"; field public static final java.lang.String ALARM_SEARCH_MODE_LABEL = "android.label"; diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 10d76f750ac5c..3d26ccd6cc806 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -2584,9 +2584,9 @@ public final class ActivityThread { intent.setFlags(intent.getFlags() & ~(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)); intent.removeUnsafeExtras(); - content.setIntent(intent); + content.setDefaultIntent(intent); } else { - content.setIntent(new Intent()); + content.setDefaultIntent(new Intent()); } r.activity.onProvideAssistContent(content); } diff --git a/core/java/android/app/AssistContent.java b/core/java/android/app/AssistContent.java index 4cb89a81005eb..8c98aa9d76059 100644 --- a/core/java/android/app/AssistContent.java +++ b/core/java/android/app/AssistContent.java @@ -31,6 +31,7 @@ import android.os.Parcelable; */ @Deprecated public class AssistContent { + private boolean mIsAppProvidedIntent = false; private Intent mIntent; private ClipData mClipData; private Uri mUri; @@ -55,12 +56,14 @@ public class AssistContent { } /** - * Sets the Intent associated with the content, describing the current top-level context of - * the activity. If this contains a reference to a piece of data related to the activity, - * be sure to set {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} so the accessibility - * service can access it. + * @hide + * Called by {@link android.app.ActivityThread} to set the default Intent based on + * {@link android.app.Activity#getIntent Activity.getIntent}. + * + *

Automatically populates {@link #mUri} if that Intent is an {@link Intent#ACTION_VIEW} + * of a web (http or https scheme) URI.

*/ - public void setIntent(Intent intent) { + public void setDefaultIntent(Intent intent) { mIntent = intent; setWebUri(null); if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) { @@ -72,13 +75,35 @@ public class AssistContent { } /** - * Return the current {@link #setIntent}, which you can modify in-place. + * Sets the Intent associated with the content, describing the current top-level context of + * the activity. If this contains a reference to a piece of data related to the activity, + * be sure to set {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} so the accessibility + * service can access it. + */ + public void setIntent(Intent intent) { + mIsAppProvidedIntent = true; + mIntent = intent; + } + + /** + * Returns the current {@link #setIntent} if one is set, else the default Intent obtained from + * {@link android.app.Activity#getIntent Activity.getIntent}. Can be modified in-place. * @hide */ public Intent getIntent() { return mIntent; } + /** + * Returns whether or not the current Intent was explicitly provided in + * {@link android.app.Activity#onProvideAssistContent Activity.onProvideAssistContent}. If not, + * the Intent was automatically set based on + * {@link android.app.Activity#getIntent Activity.getIntent}. + */ + public boolean isAppProvidedIntent() { + return mIsAppProvidedIntent; + } + /** * Optional additional content items that are involved with * the current UI. Access to this content will be granted to the assistant as if you @@ -103,9 +128,6 @@ public class AssistContent { * off the device into other environments to acesss the same data as is currently * being shown in the app; if the app does not have such a representation, it should * leave the null and only report the local intent and clip data. - * - *

This will be automatically populated for you from {@link #setIntent} if that Intent - * is an {@link Intent#ACTION_VIEW} of a web (http or https scheme) URI.

*/ public void setWebUri(Uri uri) { mUri = uri;