From 16036f26847f3f1a88a093fb776bf081008ff8d8 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Mon, 22 Jun 2015 14:05:51 -0700 Subject: Fix issue #20654534: API Review: android.app.assist Remove the old classes. Change-Id: I949350cadc5fc304e2651d7db0ffd38e45db9b6e --- api/current.txt | 146 ++- api/system-current.txt | 146 ++- core/java/android/app/AssistContent.java | 219 ---- core/java/android/app/AssistStructure.java | 1075 -------------------- core/java/android/app/VoiceInteractor.java | 3 + core/java/android/app/assist/AssistContent.java | 172 +++- core/java/android/app/assist/AssistStructure.java | 1024 ++++++++++++++++++- .../service/voice/VoiceInteractionSession.java | 13 - core/java/android/view/ViewStructure.java | 2 +- core/java/android/widget/TextView.java | 2 +- .../test/voiceinteraction/AssistVisualizer.java | 2 +- .../voiceinteraction/MainInteractionSession.java | 41 +- .../voiceinteraction/TestInteractionActivity.java | 126 +-- 13 files changed, 1405 insertions(+), 1566 deletions(-) delete mode 100644 core/java/android/app/AssistContent.java delete mode 100644 core/java/android/app/AssistStructure.java diff --git a/api/current.txt b/api/current.txt index 1287c74e370b..cd726a8f7fb8 100644 --- a/api/current.txt +++ b/api/current.txt @@ -4016,79 +4016,6 @@ package android.app { field public java.lang.String serviceDetails; } - public deprecated class AssistContent { - ctor public AssistContent(); - method public android.content.ClipData getClipData(); - method public android.os.Bundle getExtras(); - method public java.lang.String getStructuredData(); - 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 setStructuredData(java.lang.String); - method public void setWebUri(android.net.Uri); - } - - public deprecated class AssistStructure { - ctor public AssistStructure(); - method public android.content.ComponentName getActivityComponent(); - method public int getWindowNodeCount(); - } - - public static class AssistStructure.ViewNode { - method public android.app.AssistStructure.ViewNode getChildAt(int); - method public int getChildCount(); - method public java.lang.String getClassName(); - method public java.lang.CharSequence getContentDescription(); - method public android.os.Bundle getExtras(); - method public int getHeight(); - method public java.lang.String getHint(); - method public int getId(); - method public java.lang.String getIdEntry(); - method public java.lang.String getIdPackage(); - method public java.lang.String getIdType(); - method public int getLeft(); - method public int getScrollX(); - method public int getScrollY(); - method public java.lang.CharSequence getText(); - method public int getTextBackgroundColor(); - method public int getTextColor(); - method public int getTextSelectionEnd(); - method public int getTextSelectionStart(); - method public float getTextSize(); - method public int getTextStyle(); - method public int getTop(); - method public int getVisibility(); - method public int getWidth(); - method public boolean isAccessibilityFocused(); - method public boolean isActivated(); - method public boolean isAssistBlocked(); - method public boolean isCheckable(); - method public boolean isChecked(); - method public boolean isClickable(); - method public boolean isContextClickable(); - method public boolean isEnabled(); - method public boolean isFocusable(); - method public boolean isFocused(); - method public boolean isLongClickable(); - method public boolean isSelected(); - field public static final int TEXT_COLOR_UNDEFINED = 1; // 0x1 - field public static final int TEXT_STYLE_BOLD = 1; // 0x1 - field public static final int TEXT_STYLE_ITALIC = 2; // 0x2 - field public static final int TEXT_STYLE_STRIKE_THRU = 8; // 0x8 - field public static final int TEXT_STYLE_UNDERLINE = 4; // 0x4 - } - - public static class AssistStructure.WindowNode { - method public int getDisplayId(); - method public int getHeight(); - method public int getLeft(); - method public android.app.AssistStructure.ViewNode getRootViewNode(); - method public java.lang.CharSequence getTitle(); - method public int getTop(); - method public int getWidth(); - } - public class DatePickerDialog extends android.app.AlertDialog implements android.widget.DatePicker.OnDateChangedListener android.content.DialogInterface.OnClickListener { ctor public DatePickerDialog(android.content.Context, android.app.DatePickerDialog.OnDateSetListener, int, int, int); ctor public DatePickerDialog(android.content.Context, int, android.app.DatePickerDialog.OnDateSetListener, int, int, int); @@ -5900,22 +5827,87 @@ package android.app.admin { package android.app.assist { - public final class AssistContent extends android.app.AssistContent implements android.os.Parcelable { - ctor public AssistContent(android.os.Parcel); + public deprecated class AssistContent implements android.os.Parcelable { + ctor public AssistContent(); method public int describeContents(); + method public android.content.ClipData getClipData(); + method public android.os.Bundle getExtras(); method public android.content.Intent getIntent(); + method public java.lang.String getStructuredData(); + 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 setStructuredData(java.lang.String); + method public void setWebUri(android.net.Uri); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } - public final class AssistStructure extends android.app.AssistStructure implements android.os.Parcelable { + public class AssistStructure implements android.os.Parcelable { ctor public AssistStructure(); method public int describeContents(); - method public android.app.AssistStructure.WindowNode getWindowNodeAt(int); + method public android.content.ComponentName getActivityComponent(); + method public android.app.assist.AssistStructure.WindowNode getWindowNodeAt(int); + method public int getWindowNodeCount(); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } + public static class AssistStructure.ViewNode { + method public android.app.assist.AssistStructure.ViewNode getChildAt(int); + method public int getChildCount(); + method public java.lang.String getClassName(); + method public java.lang.CharSequence getContentDescription(); + method public android.os.Bundle getExtras(); + method public int getHeight(); + method public java.lang.String getHint(); + method public int getId(); + method public java.lang.String getIdEntry(); + method public java.lang.String getIdPackage(); + method public java.lang.String getIdType(); + method public int getLeft(); + method public int getScrollX(); + method public int getScrollY(); + method public java.lang.CharSequence getText(); + method public int getTextBackgroundColor(); + method public int getTextColor(); + method public int getTextSelectionEnd(); + method public int getTextSelectionStart(); + method public float getTextSize(); + method public int getTextStyle(); + method public int getTop(); + method public int getVisibility(); + method public int getWidth(); + method public boolean isAccessibilityFocused(); + method public boolean isActivated(); + method public boolean isAssistBlocked(); + method public boolean isCheckable(); + method public boolean isChecked(); + method public boolean isClickable(); + method public boolean isContextClickable(); + method public boolean isEnabled(); + method public boolean isFocusable(); + method public boolean isFocused(); + method public boolean isLongClickable(); + method public boolean isSelected(); + field public static final int TEXT_COLOR_UNDEFINED = 1; // 0x1 + field public static final int TEXT_STYLE_BOLD = 1; // 0x1 + field public static final int TEXT_STYLE_ITALIC = 2; // 0x2 + field public static final int TEXT_STYLE_STRIKE_THRU = 8; // 0x8 + field public static final int TEXT_STYLE_UNDERLINE = 4; // 0x4 + } + + public static class AssistStructure.WindowNode { + method public int getDisplayId(); + method public int getHeight(); + method public int getLeft(); + method public android.app.assist.AssistStructure.ViewNode getRootViewNode(); + method public java.lang.CharSequence getTitle(); + method public int getTop(); + method public int getWidth(); + } + } package android.app.backup { diff --git a/api/system-current.txt b/api/system-current.txt index 1f8f7a39c6c5..65f6ca5a9610 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -4112,79 +4112,6 @@ package android.app { field public java.lang.String serviceDetails; } - public deprecated class AssistContent { - ctor public AssistContent(); - method public android.content.ClipData getClipData(); - method public android.os.Bundle getExtras(); - method public java.lang.String getStructuredData(); - 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 setStructuredData(java.lang.String); - method public void setWebUri(android.net.Uri); - } - - public deprecated class AssistStructure { - ctor public AssistStructure(); - method public android.content.ComponentName getActivityComponent(); - method public int getWindowNodeCount(); - } - - public static class AssistStructure.ViewNode { - method public android.app.AssistStructure.ViewNode getChildAt(int); - method public int getChildCount(); - method public java.lang.String getClassName(); - method public java.lang.CharSequence getContentDescription(); - method public android.os.Bundle getExtras(); - method public int getHeight(); - method public java.lang.String getHint(); - method public int getId(); - method public java.lang.String getIdEntry(); - method public java.lang.String getIdPackage(); - method public java.lang.String getIdType(); - method public int getLeft(); - method public int getScrollX(); - method public int getScrollY(); - method public java.lang.CharSequence getText(); - method public int getTextBackgroundColor(); - method public int getTextColor(); - method public int getTextSelectionEnd(); - method public int getTextSelectionStart(); - method public float getTextSize(); - method public int getTextStyle(); - method public int getTop(); - method public int getVisibility(); - method public int getWidth(); - method public boolean isAccessibilityFocused(); - method public boolean isActivated(); - method public boolean isAssistBlocked(); - method public boolean isCheckable(); - method public boolean isChecked(); - method public boolean isClickable(); - method public boolean isContextClickable(); - method public boolean isEnabled(); - method public boolean isFocusable(); - method public boolean isFocused(); - method public boolean isLongClickable(); - method public boolean isSelected(); - field public static final int TEXT_COLOR_UNDEFINED = 1; // 0x1 - field public static final int TEXT_STYLE_BOLD = 1; // 0x1 - field public static final int TEXT_STYLE_ITALIC = 2; // 0x2 - field public static final int TEXT_STYLE_STRIKE_THRU = 8; // 0x8 - field public static final int TEXT_STYLE_UNDERLINE = 4; // 0x4 - } - - public static class AssistStructure.WindowNode { - method public int getDisplayId(); - method public int getHeight(); - method public int getLeft(); - method public android.app.AssistStructure.ViewNode getRootViewNode(); - method public java.lang.CharSequence getTitle(); - method public int getTop(); - method public int getWidth(); - } - public class BroadcastOptions { method public static android.app.BroadcastOptions makeBasic(); method public void setTemporaryAppWhitelistDuration(long); @@ -6018,22 +5945,87 @@ package android.app.admin { package android.app.assist { - public final class AssistContent extends android.app.AssistContent implements android.os.Parcelable { - ctor public AssistContent(android.os.Parcel); + public deprecated class AssistContent implements android.os.Parcelable { + ctor public AssistContent(); method public int describeContents(); + method public android.content.ClipData getClipData(); + method public android.os.Bundle getExtras(); method public android.content.Intent getIntent(); + method public java.lang.String getStructuredData(); + 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 setStructuredData(java.lang.String); + method public void setWebUri(android.net.Uri); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } - public final class AssistStructure extends android.app.AssistStructure implements android.os.Parcelable { + public class AssistStructure implements android.os.Parcelable { ctor public AssistStructure(); method public int describeContents(); - method public android.app.AssistStructure.WindowNode getWindowNodeAt(int); + method public android.content.ComponentName getActivityComponent(); + method public android.app.assist.AssistStructure.WindowNode getWindowNodeAt(int); + method public int getWindowNodeCount(); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } + public static class AssistStructure.ViewNode { + method public android.app.assist.AssistStructure.ViewNode getChildAt(int); + method public int getChildCount(); + method public java.lang.String getClassName(); + method public java.lang.CharSequence getContentDescription(); + method public android.os.Bundle getExtras(); + method public int getHeight(); + method public java.lang.String getHint(); + method public int getId(); + method public java.lang.String getIdEntry(); + method public java.lang.String getIdPackage(); + method public java.lang.String getIdType(); + method public int getLeft(); + method public int getScrollX(); + method public int getScrollY(); + method public java.lang.CharSequence getText(); + method public int getTextBackgroundColor(); + method public int getTextColor(); + method public int getTextSelectionEnd(); + method public int getTextSelectionStart(); + method public float getTextSize(); + method public int getTextStyle(); + method public int getTop(); + method public int getVisibility(); + method public int getWidth(); + method public boolean isAccessibilityFocused(); + method public boolean isActivated(); + method public boolean isAssistBlocked(); + method public boolean isCheckable(); + method public boolean isChecked(); + method public boolean isClickable(); + method public boolean isContextClickable(); + method public boolean isEnabled(); + method public boolean isFocusable(); + method public boolean isFocused(); + method public boolean isLongClickable(); + method public boolean isSelected(); + field public static final int TEXT_COLOR_UNDEFINED = 1; // 0x1 + field public static final int TEXT_STYLE_BOLD = 1; // 0x1 + field public static final int TEXT_STYLE_ITALIC = 2; // 0x2 + field public static final int TEXT_STYLE_STRIKE_THRU = 8; // 0x8 + field public static final int TEXT_STYLE_UNDERLINE = 4; // 0x4 + } + + public static class AssistStructure.WindowNode { + method public int getDisplayId(); + method public int getHeight(); + method public int getLeft(); + method public android.app.assist.AssistStructure.ViewNode getRootViewNode(); + method public java.lang.CharSequence getTitle(); + method public int getTop(); + method public int getWidth(); + } + } package android.app.backup { diff --git a/core/java/android/app/AssistContent.java b/core/java/android/app/AssistContent.java deleted file mode 100644 index ad2ba39761da..000000000000 --- a/core/java/android/app/AssistContent.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (C) 2015 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.app; - -import android.content.ClipData; -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.os.Parcel; -import android.os.Parcelable; - -/** - * Holds information about the content an application is viewing, to hand to an - * assistant at the user's request. This is filled in by - * {@link android.app.Activity#onProvideAssistContent Activity.onProvideAssistContent}. - * @deprecated use {@link android.app.assist.AssistContent}. - */ -@Deprecated -public class AssistContent { - private boolean mIsAppProvidedIntent = false; - private Intent mIntent; - private String mStructuredData; - private ClipData mClipData; - private Uri mUri; - private final Bundle mExtras; - - /** - * @hide - * Key name this data structure is stored in the Bundle generated by - * {@link android.app.Activity#onProvideAssistData}. - */ - public static final String ASSIST_KEY = "android:assist_content"; - - /** - * @hide - * Retrieve the framework-generated AssistContent that is stored within - * the Bundle filled in by {@link android.app.Activity#onProvideAssistContent}. - */ - public static android.app.assist.AssistContent getAssistContent(Bundle assistBundle) { - return assistBundle.getParcelable(ASSIST_KEY); - } - - public AssistContent() { - mExtras = new Bundle(); - } - - /** - * @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 setDefaultIntent(Intent intent) { - mIntent = intent; - setWebUri(null); - if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) { - Uri uri = intent.getData(); - if (uri != null) { - if ("http".equals(uri.getScheme()) || "https".equals(uri.getScheme())) { - setWebUri(uri); - } - } - } - } - - /** - * 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 - * are sending it through an Intent with {@link Intent#FLAG_GRANT_READ_URI_PERMISSION}. - */ - public void setClipData(ClipData clip) { - mClipData = clip; - } - - /** - * Return the current {@link #setClipData}, which you can modify in-place. - */ - public ClipData getClipData() { - return mClipData; - } - - /** - * Sets optional structured data regarding the content being viewed. The provided data - * must be a string represented with JSON-LD using the - * schema.org vocabulary. - */ - public void setStructuredData(String structuredData) { - mStructuredData = structuredData; - } - - /** - * Returns the current {@link #setStructuredData}. - */ - public String getStructuredData() { - return mStructuredData; - } - - /** - * Set a web URI associated with the current data being shown to the user. - * This URI could be opened in a web browser, or in the app as an - * {@link Intent#ACTION_VIEW} Intent, to show the same data that is currently - * being displayed by it. The URI here should be something that is transportable - * 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. - */ - public void setWebUri(Uri uri) { - mUri = uri; - } - - /** - * Return the content's web URI as per {@link #setWebUri(android.net.Uri)}, or null if - * there is none. - */ - public Uri getWebUri() { - return mUri; - } - - /** - * Return Bundle for extra vendor-specific data that can be modified and examined. - */ - public Bundle getExtras() { - return mExtras; - } - - /** @hide */ - public AssistContent(Parcel in) { - if (in.readInt() != 0) { - mIntent = Intent.CREATOR.createFromParcel(in); - } - if (in.readInt() != 0) { - mClipData = ClipData.CREATOR.createFromParcel(in); - } - if (in.readInt() != 0) { - mUri = Uri.CREATOR.createFromParcel(in); - } - if (in.readInt() != 0) { - mStructuredData = in.readString(); - } - mIsAppProvidedIntent = in.readInt() == 1; - mExtras = in.readBundle(); - } - - /** @hide */ - public void writeToParcelInternal(Parcel dest, int flags) { - if (mIntent != null) { - dest.writeInt(1); - mIntent.writeToParcel(dest, flags); - } else { - dest.writeInt(0); - } - if (mClipData != null) { - dest.writeInt(1); - mClipData.writeToParcel(dest, flags); - } else { - dest.writeInt(0); - } - if (mUri != null) { - dest.writeInt(1); - mUri.writeToParcel(dest, flags); - } else { - dest.writeInt(0); - } - if (mStructuredData != null) { - dest.writeInt(1); - dest.writeString(mStructuredData); - } else { - dest.writeInt(0); - } - dest.writeInt(mIsAppProvidedIntent ? 1 : 0); - dest.writeBundle(mExtras); - } -} diff --git a/core/java/android/app/AssistStructure.java b/core/java/android/app/AssistStructure.java deleted file mode 100644 index 7f6dae5aa585..000000000000 --- a/core/java/android/app/AssistStructure.java +++ /dev/null @@ -1,1075 +0,0 @@ -/* - * Copyright (C) 2015 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.app; - -import android.content.ComponentName; -import android.graphics.Rect; -import android.os.Binder; -import android.os.Bundle; -import android.os.IBinder; -import android.os.Parcel; -import android.os.Parcelable; -import android.os.PooledStringReader; -import android.os.PooledStringWriter; -import android.os.RemoteException; -import android.os.SystemClock; -import android.text.TextUtils; -import android.util.Log; -import android.view.View; -import android.view.ViewAssistStructure; -import android.view.ViewRootImpl; -import android.view.WindowManager; -import android.view.WindowManagerGlobal; - -import java.util.ArrayList; - -/** - * Assist data automatically created by the platform's implementation - * of {@link android.app.Activity#onProvideAssistData}. - * @deprecated use {@link android.app.assist.AssistStructure}. - */ -@Deprecated -public class AssistStructure { - static final String TAG = "AssistStructure"; - - /** - * @hide - * Key name this data structure is stored in the Bundle generated by - * {@link android.app.Activity#onProvideAssistData}. - */ - public static final String ASSIST_KEY = "android:assist_structure"; - - /** @hide */ - public boolean mHaveData; - - ComponentName mActivityComponent; - - final ArrayList mWindowNodes = new ArrayList<>(); - - final ArrayList mPendingAsyncChildren = new ArrayList<>(); - - /** @hide */ - public SendChannel mSendChannel; - /** @hide */ - public IBinder mReceiveChannel; - - Rect mTmpRect = new Rect(); - - static final int TRANSACTION_XFER = Binder.FIRST_CALL_TRANSACTION+1; - static final String DESCRIPTOR = "android.app.AssistStructure"; - - /** @hide */ - public final class SendChannel extends Binder { - @Override protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) - throws RemoteException { - if (code == TRANSACTION_XFER) { - data.enforceInterface(DESCRIPTOR); - writeContentToParcel(reply, Parcelable.PARCELABLE_WRITE_RETURN_VALUE); - return true; - } else { - return super.onTransact(code, data, reply, flags); - } - } - } - - final static class ViewNodeText { - CharSequence mText; - int mTextSelectionStart; - int mTextSelectionEnd; - int mTextColor; - int mTextBackgroundColor; - float mTextSize; - int mTextStyle; - String mHint; - - ViewNodeText() { - } - - ViewNodeText(Parcel in) { - mText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); - mTextSelectionStart = in.readInt(); - mTextSelectionEnd = in.readInt(); - mTextColor = in.readInt(); - mTextBackgroundColor = in.readInt(); - mTextSize = in.readFloat(); - mTextStyle = in.readInt(); - mHint = in.readString(); - } - - void writeToParcel(Parcel out) { - TextUtils.writeToParcel(mText, out, 0); - out.writeInt(mTextSelectionStart); - out.writeInt(mTextSelectionEnd); - out.writeInt(mTextColor); - out.writeInt(mTextBackgroundColor); - out.writeFloat(mTextSize); - out.writeInt(mTextStyle); - out.writeString(mHint); - } - } - - /** - * Describes a window in the assist data. - */ - static public class WindowNode { - final int mX; - final int mY; - final int mWidth; - final int mHeight; - final CharSequence mTitle; - final int mDisplayId; - final ViewNode mRoot; - - WindowNode(AssistStructure assist, ViewRootImpl root) { - View view = root.getView(); - Rect rect = new Rect(); - view.getBoundsOnScreen(rect); - mX = rect.left - view.getLeft(); - mY = rect.top - view.getTop(); - mWidth = rect.width(); - mHeight = rect.height(); - mTitle = root.getTitle(); - mDisplayId = root.getDisplayId(); - mRoot = new ViewNode(); - ViewNodeBuilder builder = new ViewNodeBuilder(assist, mRoot, false); - if ((root.getWindowFlags()&WindowManager.LayoutParams.FLAG_SECURE) != 0) { - // This is a secure window, so it doesn't want a screenshot, and that - // means we should also not copy out its view hierarchy. - view.onProvideStructure(builder); - builder.setAssistBlocked(true); - return; - } - view.dispatchProvideStructure(builder); - } - - WindowNode(Parcel in, PooledStringReader preader) { - mX = in.readInt(); - mY = in.readInt(); - mWidth = in.readInt(); - mHeight = in.readInt(); - mTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); - mDisplayId = in.readInt(); - mRoot = new ViewNode(in, preader); - } - - void writeToParcel(Parcel out, PooledStringWriter pwriter) { - out.writeInt(mX); - out.writeInt(mY); - out.writeInt(mWidth); - out.writeInt(mHeight); - TextUtils.writeToParcel(mTitle, out, 0); - out.writeInt(mDisplayId); - mRoot.writeToParcel(out, pwriter); - } - - /** - * Returns the left edge of the window, in pixels, relative to the left - * edge of the screen. - */ - public int getLeft() { - return mX; - } - - /** - * Returns the top edge of the window, in pixels, relative to the top - * edge of the screen. - */ - public int getTop() { - return mY; - } - - /** - * Returns the total width of the window in pixels. - */ - public int getWidth() { - return mWidth; - } - - /** - * Returns the total height of the window in pixels. - */ - public int getHeight() { - return mHeight; - } - - /** - * Returns the title associated with the window, if it has one. - */ - public CharSequence getTitle() { - return mTitle; - } - - /** - * Returns the ID of the display this window is on, for use with - * {@link android.hardware.display.DisplayManager#getDisplay DisplayManager.getDisplay()}. - */ - public int getDisplayId() { - return mDisplayId; - } - - /** - * Returns the {@link ViewNode} containing the root content of the window. - */ - public ViewNode getRootViewNode() { - return mRoot; - } - } - - /** - * Describes a single view in the assist data. - */ - static public class ViewNode { - /** - * Magic value for text color that has not been defined, which is very unlikely - * to be confused with a real text color. - */ - public static final int TEXT_COLOR_UNDEFINED = 1; - - public static final int TEXT_STYLE_BOLD = 1<<0; - public static final int TEXT_STYLE_ITALIC = 1<<1; - public static final int TEXT_STYLE_UNDERLINE = 1<<2; - public static final int TEXT_STYLE_STRIKE_THRU = 1<<3; - - int mId; - String mIdPackage; - String mIdType; - String mIdEntry; - int mX; - int mY; - int mScrollX; - int mScrollY; - int mWidth; - int mHeight; - - static final int FLAGS_DISABLED = 0x00000001; - static final int FLAGS_VISIBILITY_MASK = View.VISIBLE|View.INVISIBLE|View.GONE; - static final int FLAGS_FOCUSABLE = 0x00000010; - static final int FLAGS_FOCUSED = 0x00000020; - static final int FLAGS_ACCESSIBILITY_FOCUSED = 0x04000000; - static final int FLAGS_SELECTED = 0x00000040; - static final int FLAGS_ASSIST_BLOCKED = 0x00000080; - static final int FLAGS_ACTIVATED = 0x40000000; - static final int FLAGS_CHECKABLE = 0x00000100; - static final int FLAGS_CHECKED = 0x00000200; - static final int FLAGS_CLICKABLE = 0x00004000; - static final int FLAGS_LONG_CLICKABLE = 0x00200000; - static final int FLAGS_CONTEXT_CLICKABLE = 0x00400000; - - int mFlags; - - String mClassName; - CharSequence mContentDescription; - - ViewNodeText mText; - Bundle mExtras; - - ViewNode[] mChildren; - - ViewNode() { - } - - ViewNode(Parcel in, PooledStringReader preader) { - mId = in.readInt(); - if (mId != 0) { - mIdEntry = preader.readString(); - if (mIdEntry != null) { - mIdType = preader.readString(); - mIdPackage = preader.readString(); - } else { - mIdPackage = mIdType = null; - } - } else { - mIdPackage = mIdType = mIdEntry = null; - } - mX = in.readInt(); - mY = in.readInt(); - mScrollX = in.readInt(); - mScrollY = in.readInt(); - mWidth = in.readInt(); - mHeight = in.readInt(); - mFlags = in.readInt(); - mClassName = preader.readString(); - mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); - if (in.readInt() != 0) { - mText = new ViewNodeText(in); - } else { - mText = null; - } - mExtras = in.readBundle(); - final int NCHILDREN = in.readInt(); - if (NCHILDREN > 0) { - mChildren = new ViewNode[NCHILDREN]; - for (int i=0; i views = WindowManagerGlobal.getInstance().getRootViews( - activity.getActivityToken()); - for (int i=0; i 0) { - Log.i(TAG, prefix + " Children:"); - String cprefix = prefix + " "; - for (int i=0; i 0 && (now=SystemClock.uptimeMillis()) < endTime) { - try { - wait(endTime-now); - } catch (InterruptedException e) { - } - } - if (mPendingAsyncChildren.size() > 0) { - // We waited too long, assume none of the assist structure is valid. - skipStructure = true; - } - } - int start = out.dataPosition(); - PooledStringWriter pwriter = new PooledStringWriter(out); - ComponentName.writeToParcel(mActivityComponent, out); - final int N = skipStructure ? 0 : mWindowNodes.size(); - out.writeInt(N); - for (int i=0; iAutomatically populates {@link #mUri} if that Intent is an {@link Intent#ACTION_VIEW} + * of a web (http or https scheme) URI.

+ */ + public void setDefaultIntent(Intent intent) { + mIntent = intent; + setWebUri(null); + if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) { + Uri uri = intent.getData(); + if (uri != null) { + if ("http".equals(uri.getScheme()) || "https".equals(uri.getScheme())) { + setWebUri(uri); + } + } + } + } + + /** + * 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. + */ public Intent getIntent() { - return super.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 + * are sending it through an Intent with {@link Intent#FLAG_GRANT_READ_URI_PERMISSION}. + */ + public void setClipData(ClipData clip) { + mClipData = clip; + } + + /** + * Return the current {@link #setClipData}, which you can modify in-place. + */ + public ClipData getClipData() { + return mClipData; + } + + /** + * Sets optional structured data regarding the content being viewed. The provided data + * must be a string represented with JSON-LD using the + * schema.org vocabulary. + */ + public void setStructuredData(String structuredData) { + mStructuredData = structuredData; + } + + /** + * Returns the current {@link #setStructuredData}. + */ + public String getStructuredData() { + return mStructuredData; + } + + /** + * Set a web URI associated with the current data being shown to the user. + * This URI could be opened in a web browser, or in the app as an + * {@link Intent#ACTION_VIEW} Intent, to show the same data that is currently + * being displayed by it. The URI here should be something that is transportable + * 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. + */ + public void setWebUri(Uri uri) { + mUri = uri; + } + + /** + * Return the content's web URI as per {@link #setWebUri(android.net.Uri)}, or null if + * there is none. + */ + public Uri getWebUri() { + return mUri; + } + + /** + * Return Bundle for extra vendor-specific data that can be modified and examined. + */ + public Bundle getExtras() { + return mExtras; + } + + AssistContent(Parcel in) { + if (in.readInt() != 0) { + mIntent = Intent.CREATOR.createFromParcel(in); + } + if (in.readInt() != 0) { + mClipData = ClipData.CREATOR.createFromParcel(in); + } + if (in.readInt() != 0) { + mUri = Uri.CREATOR.createFromParcel(in); + } + if (in.readInt() != 0) { + mStructuredData = in.readString(); + } + mIsAppProvidedIntent = in.readInt() == 1; + mExtras = in.readBundle(); + } + + void writeToParcelInternal(Parcel dest, int flags) { + if (mIntent != null) { + dest.writeInt(1); + mIntent.writeToParcel(dest, flags); + } else { + dest.writeInt(0); + } + if (mClipData != null) { + dest.writeInt(1); + mClipData.writeToParcel(dest, flags); + } else { + dest.writeInt(0); + } + if (mUri != null) { + dest.writeInt(1); + mUri.writeToParcel(dest, flags); + } else { + dest.writeInt(0); + } + if (mStructuredData != null) { + dest.writeInt(1); + dest.writeString(mStructuredData); + } else { + dest.writeInt(0); + } + dest.writeInt(mIsAppProvidedIntent ? 1 : 0); + dest.writeBundle(mExtras); } @Override diff --git a/core/java/android/app/assist/AssistStructure.java b/core/java/android/app/assist/AssistStructure.java index 1677e9576b6e..1a0489525131 100644 --- a/core/java/android/app/assist/AssistStructure.java +++ b/core/java/android/app/assist/AssistStructure.java @@ -1,28 +1,1038 @@ package android.app.assist; import android.app.Activity; +import android.content.ComponentName; +import android.graphics.Rect; +import android.os.Binder; +import android.os.Bundle; +import android.os.IBinder; import android.os.Parcel; import android.os.Parcelable; +import android.os.PooledStringReader; +import android.os.PooledStringWriter; +import android.os.RemoteException; +import android.os.SystemClock; +import android.text.TextUtils; +import android.util.Log; +import android.view.View; +import android.view.ViewAssistStructure; +import android.view.ViewRootImpl; +import android.view.WindowManager; +import android.view.WindowManagerGlobal; + +import java.util.ArrayList; /** - * New home for AssistStructure. + * Assist data automatically created by the platform's implementation + * of {@link android.app.Activity#onProvideAssistData}. */ -public final class AssistStructure extends android.app.AssistStructure implements Parcelable { +public class AssistStructure implements Parcelable { + static final String TAG = "AssistStructure"; - public AssistStructure() { + boolean mHaveData; + + ComponentName mActivityComponent; + + final ArrayList mWindowNodes = new ArrayList<>(); + + final ArrayList mPendingAsyncChildren = new ArrayList<>(); + + SendChannel mSendChannel; + IBinder mReceiveChannel; + + Rect mTmpRect = new Rect(); + + static final int TRANSACTION_XFER = Binder.FIRST_CALL_TRANSACTION+1; + static final String DESCRIPTOR = "android.app.AssistStructure"; + + final class SendChannel extends Binder { + @Override protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) + throws RemoteException { + if (code == TRANSACTION_XFER) { + data.enforceInterface(DESCRIPTOR); + writeContentToParcel(reply, Parcelable.PARCELABLE_WRITE_RETURN_VALUE); + return true; + } else { + return super.onTransact(code, data, reply, flags); + } + } + } + + final static class ViewNodeText { + CharSequence mText; + int mTextSelectionStart; + int mTextSelectionEnd; + int mTextColor; + int mTextBackgroundColor; + float mTextSize; + int mTextStyle; + String mHint; + + ViewNodeText() { + } + + ViewNodeText(Parcel in) { + mText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); + mTextSelectionStart = in.readInt(); + mTextSelectionEnd = in.readInt(); + mTextColor = in.readInt(); + mTextBackgroundColor = in.readInt(); + mTextSize = in.readFloat(); + mTextStyle = in.readInt(); + mHint = in.readString(); + } + + void writeToParcel(Parcel out) { + TextUtils.writeToParcel(mText, out, 0); + out.writeInt(mTextSelectionStart); + out.writeInt(mTextSelectionEnd); + out.writeInt(mTextColor); + out.writeInt(mTextBackgroundColor); + out.writeFloat(mTextSize); + out.writeInt(mTextStyle); + out.writeString(mHint); + } + } + + /** + * Describes a window in the assist data. + */ + static public class WindowNode { + final int mX; + final int mY; + final int mWidth; + final int mHeight; + final CharSequence mTitle; + final int mDisplayId; + final ViewNode mRoot; + + WindowNode(AssistStructure assist, ViewRootImpl root) { + View view = root.getView(); + Rect rect = new Rect(); + view.getBoundsOnScreen(rect); + mX = rect.left - view.getLeft(); + mY = rect.top - view.getTop(); + mWidth = rect.width(); + mHeight = rect.height(); + mTitle = root.getTitle(); + mDisplayId = root.getDisplayId(); + mRoot = new ViewNode(); + ViewNodeBuilder builder = new ViewNodeBuilder(assist, mRoot, false); + if ((root.getWindowFlags()& WindowManager.LayoutParams.FLAG_SECURE) != 0) { + // This is a secure window, so it doesn't want a screenshot, and that + // means we should also not copy out its view hierarchy. + view.onProvideStructure(builder); + builder.setAssistBlocked(true); + return; + } + view.dispatchProvideStructure(builder); + } + + WindowNode(Parcel in, PooledStringReader preader) { + mX = in.readInt(); + mY = in.readInt(); + mWidth = in.readInt(); + mHeight = in.readInt(); + mTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); + mDisplayId = in.readInt(); + mRoot = new ViewNode(in, preader); + } + + void writeToParcel(Parcel out, PooledStringWriter pwriter) { + out.writeInt(mX); + out.writeInt(mY); + out.writeInt(mWidth); + out.writeInt(mHeight); + TextUtils.writeToParcel(mTitle, out, 0); + out.writeInt(mDisplayId); + mRoot.writeToParcel(out, pwriter); + } + + /** + * Returns the left edge of the window, in pixels, relative to the left + * edge of the screen. + */ + public int getLeft() { + return mX; + } + + /** + * Returns the top edge of the window, in pixels, relative to the top + * edge of the screen. + */ + public int getTop() { + return mY; + } + + /** + * Returns the total width of the window in pixels. + */ + public int getWidth() { + return mWidth; + } + + /** + * Returns the total height of the window in pixels. + */ + public int getHeight() { + return mHeight; + } + + /** + * Returns the title associated with the window, if it has one. + */ + public CharSequence getTitle() { + return mTitle; + } + + /** + * Returns the ID of the display this window is on, for use with + * {@link android.hardware.display.DisplayManager#getDisplay DisplayManager.getDisplay()}. + */ + public int getDisplayId() { + return mDisplayId; + } + + /** + * Returns the {@link ViewNode} containing the root content of the window. + */ + public ViewNode getRootViewNode() { + return mRoot; + } + } + + /** + * Describes a single view in the assist data. + */ + static public class ViewNode { + /** + * Magic value for text color that has not been defined, which is very unlikely + * to be confused with a real text color. + */ + public static final int TEXT_COLOR_UNDEFINED = 1; + + public static final int TEXT_STYLE_BOLD = 1<<0; + public static final int TEXT_STYLE_ITALIC = 1<<1; + public static final int TEXT_STYLE_UNDERLINE = 1<<2; + public static final int TEXT_STYLE_STRIKE_THRU = 1<<3; + + int mId; + String mIdPackage; + String mIdType; + String mIdEntry; + int mX; + int mY; + int mScrollX; + int mScrollY; + int mWidth; + int mHeight; + + static final int FLAGS_DISABLED = 0x00000001; + static final int FLAGS_VISIBILITY_MASK = View.VISIBLE|View.INVISIBLE|View.GONE; + static final int FLAGS_FOCUSABLE = 0x00000010; + static final int FLAGS_FOCUSED = 0x00000020; + static final int FLAGS_ACCESSIBILITY_FOCUSED = 0x04000000; + static final int FLAGS_SELECTED = 0x00000040; + static final int FLAGS_ASSIST_BLOCKED = 0x00000080; + static final int FLAGS_ACTIVATED = 0x40000000; + static final int FLAGS_CHECKABLE = 0x00000100; + static final int FLAGS_CHECKED = 0x00000200; + static final int FLAGS_CLICKABLE = 0x00004000; + static final int FLAGS_LONG_CLICKABLE = 0x00200000; + static final int FLAGS_CONTEXT_CLICKABLE = 0x00400000; + + int mFlags; + + String mClassName; + CharSequence mContentDescription; + + ViewNodeText mText; + Bundle mExtras; + + ViewNode[] mChildren; + + ViewNode() { + } + + ViewNode(Parcel in, PooledStringReader preader) { + mId = in.readInt(); + if (mId != 0) { + mIdEntry = preader.readString(); + if (mIdEntry != null) { + mIdType = preader.readString(); + mIdPackage = preader.readString(); + } else { + mIdPackage = mIdType = null; + } + } else { + mIdPackage = mIdType = mIdEntry = null; + } + mX = in.readInt(); + mY = in.readInt(); + mScrollX = in.readInt(); + mScrollY = in.readInt(); + mWidth = in.readInt(); + mHeight = in.readInt(); + mFlags = in.readInt(); + mClassName = preader.readString(); + mContentDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); + if (in.readInt() != 0) { + mText = new ViewNodeText(in); + } else { + mText = null; + } + mExtras = in.readBundle(); + final int NCHILDREN = in.readInt(); + if (NCHILDREN > 0) { + mChildren = new ViewNode[NCHILDREN]; + for (int i=0; i views = WindowManagerGlobal.getInstance().getRootViews( + activity.getActivityToken()); + for (int i=0; i 0) { + Log.i(TAG, prefix + " Children:"); + String cprefix = prefix + " "; + for (int i=0; i 0 && (now=SystemClock.uptimeMillis()) < endTime) { + try { + wait(endTime-now); + } catch (InterruptedException e) { + } + } + if (mPendingAsyncChildren.size() > 0) { + // We waited too long, assume none of the assist structure is valid. + skipStructure = true; + } + } + int start = out.dataPosition(); + PooledStringWriter pwriter = new PooledStringWriter(out); + ComponentName.writeToParcel(mActivityComponent, out); + final int N = skipStructure ? 0 : mWindowNodes.size(); + out.writeInt(N); + for (int i=0; i= 1) { - sb.append(", "); - } - sb.append(selections[i].getLabel()); - } - mLog.append(sb.toString()); - if (finished) { - getActivity().finish(); - } - } - }; + VoiceInteractor.PickOptionRequest req = new TestPickOption(options); mInteractor.submitRequest(req, REQUEST_PICK); } else if (v == mJumpOutButton) { Log.i(TAG, "Jump out"); @@ -200,4 +144,66 @@ public class TestInteractionActivity extends Activity implements View.OnClickLis public void onDestroy() { super.onDestroy(); } + + static class TestAbortVoice extends VoiceInteractor.AbortVoiceRequest { + public TestAbortVoice() { + super(new VoiceInteractor.Prompt("Dammit, we suck :("), null); + } + @Override public void onCancel() { + Log.i(TAG, "Canceled!"); + ((TestInteractionActivity)getActivity()).mLog.append("Canceled abort\n"); + } + @Override public void onAbortResult(Bundle result) { + Log.i(TAG, "Abort result: result=" + result); + ((TestInteractionActivity)getActivity()).mLog.append("Abort: result=" + result + "\n"); + getActivity().finish(); + } + } + + static class TestCompleteVoice extends VoiceInteractor.CompleteVoiceRequest { + public TestCompleteVoice() { + super(new VoiceInteractor.Prompt("Woohoo, completed!"), null); + } + @Override public void onCancel() { + Log.i(TAG, "Canceled!"); + ((TestInteractionActivity)getActivity()).mLog.append("Canceled complete\n"); + } + @Override public void onCompleteResult(Bundle result) { + Log.i(TAG, "Complete result: result=" + result); + ((TestInteractionActivity)getActivity()).mLog.append("Complete: result=" + + result + "\n"); + getActivity().finish(); + } + } + + static class TestPickOption extends VoiceInteractor.PickOptionRequest { + public TestPickOption(Option[] options) { + super(new VoiceInteractor.Prompt("Need to pick something"), options, null); + } + @Override public void onCancel() { + Log.i(TAG, "Canceled!"); + ((TestInteractionActivity)getActivity()).mLog.append("Canceled pick\n"); + } + @Override + public void onPickOptionResult(boolean finished, Option[] selections, Bundle result) { + Log.i(TAG, "Pick result: finished=" + finished + " selections=" + selections + + " result=" + result); + StringBuilder sb = new StringBuilder(); + if (finished) { + sb.append("Pick final result: "); + } else { + sb.append("Pick intermediate result: "); + } + for (int i=0; i= 1) { + sb.append(", "); + } + sb.append(selections[i].getLabel()); + } + ((TestInteractionActivity)getActivity()).mLog.append(sb.toString()); + if (finished) { + getActivity().finish(); + } + } + } } -- cgit v1.2.3-59-g8ed1b