summaryrefslogtreecommitdiffstats
path: root/core/java/android/service
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2015-07-08 17:36:37 -0700
committerDianne Hackborn <hackbod@google.com>2015-07-09 14:06:47 -0700
commit782d49826862cbdc9d020fc9d85f8a6f64675dcb (patch)
tree2f8336faca55d4b71a70ca52d7aa2b80ca1f3b61 /core/java/android/service
parent2a67840c3c35a6267663e5d3ae921ee9ac614db9 (diff)
downloadframeworks_base-782d49826862cbdc9d020fc9d85f8a6f64675dcb.zip
frameworks_base-782d49826862cbdc9d020fc9d85f8a6f64675dcb.tar.gz
frameworks_base-782d49826862cbdc9d020fc9d85f8a6f64675dcb.tar.bz2
Fix issue #22328792: Fix scalability issues in AssistStructure
We can now stream the AssistStructure across processes, avoiding IPC size limitations for large structures. There is also a new API that gets called on the VoiceInteractionSession if there is a failure retrieving the assist data. Also fix issue #22351981: Runtime restart due to ANR in system server, getting rid of a deadlock. And also tweak object lifecycles to try to avoid keeping around in an app the previous AssistStructure after we request a new one. Change-Id: Ifb136a0d31a14e56a8db6b90768d9fc65557a17f
Diffstat (limited to 'core/java/android/service')
-rw-r--r--core/java/android/service/voice/VoiceInteractionSession.java72
1 files changed, 61 insertions, 11 deletions
diff --git a/core/java/android/service/voice/VoiceInteractionSession.java b/core/java/android/service/voice/VoiceInteractionSession.java
index a7e0e08..e408b36 100644
--- a/core/java/android/service/voice/VoiceInteractionSession.java
+++ b/core/java/android/service/voice/VoiceInteractionSession.java
@@ -209,16 +209,30 @@ public class VoiceInteractionSession implements KeyEvent.Callback, ComponentCall
}
@Override
- public void handleAssist(Bundle data, AssistStructure structure,
- AssistContent content) {
+ public void handleAssist(final Bundle data, final AssistStructure structure,
+ final AssistContent content) {
// We want to pre-warm the AssistStructure before handing it off to the main
- // thread. There is a strong argument to be made that it should be handed
- // through as a separate param rather than part of the assistBundle.
- if (structure != null) {
- structure.ensureData();
- }
- mHandlerCaller.sendMessage(mHandlerCaller.obtainMessageOOO(MSG_HANDLE_ASSIST,
- data, structure, content));
+ // thread. We also want to do this on a separate thread, so that if the app
+ // is for some reason slow (due to slow filling in of async children in the
+ // structure), we don't block other incoming IPCs (such as the screenshot) to
+ // us (since we are a oneway interface, they get serialized). (Okay?)
+ Thread retriever = new Thread("AssistStructure retriever") {
+ @Override
+ public void run() {
+ Throwable failure = null;
+ if (structure != null) {
+ try {
+ structure.ensureData();
+ } catch (Throwable e) {
+ Log.w(TAG, "Failure retrieving AssistStructure", e);
+ failure = e;
+ }
+ }
+ mHandlerCaller.sendMessage(mHandlerCaller.obtainMessageOOOO(MSG_HANDLE_ASSIST,
+ data, failure == null ? structure : null, failure, content));
+ }
+ };
+ retriever.start();
}
@Override
@@ -689,8 +703,8 @@ public class VoiceInteractionSession implements KeyEvent.Callback, ComponentCall
args = (SomeArgs)msg.obj;
if (DEBUG) Log.d(TAG, "onHandleAssist: data=" + args.arg1
+ " structure=" + args.arg2 + " content=" + args.arg3);
- onHandleAssist((Bundle) args.arg1, (AssistStructure) args.arg2,
- (AssistContent) args.arg3);
+ doOnHandleAssist((Bundle) args.arg1, (AssistStructure) args.arg2,
+ (Throwable) args.arg3, (AssistContent) args.arg4);
break;
case MSG_HANDLE_SCREENSHOT:
if (DEBUG) Log.d(TAG, "onHandleScreenshot: " + msg.obj);
@@ -1111,9 +1125,45 @@ public class VoiceInteractionSession implements KeyEvent.Callback, ComponentCall
mContentFrame.requestApplyInsets();
}
+ void doOnHandleAssist(Bundle data, AssistStructure structure, Throwable failure,
+ AssistContent content) {
+ if (failure != null) {
+ onAssistStructureFailure(failure);
+ }
+ onHandleAssist(data, structure, content);
+ }
+
+ /**
+ * Called when there has been a failure transferring the {@link AssistStructure} to
+ * the assistant. This may happen, for example, if the data is too large and results
+ * in an out of memory exception, or the client has provided corrupt data. This will
+ * be called immediately before {@link #onHandleAssist} and the AssistStructure supplied
+ * there afterwards will be null.
+ *
+ * @param failure The failure exception that was thrown when building the
+ * {@link AssistStructure}.
+ */
+ public void onAssistStructureFailure(Throwable failure) {
+ }
+
+ /**
+ * Called to receive data from the application that the user was currently viewing when
+ * an assist session is started.
+ *
+ * @param data Arbitrary data supplied by the app through
+ * {@link android.app.Activity#onProvideAssistData Activity.onProvideAssistData}.
+ * @param structure If available, the structure definition of all windows currently
+ * displayed by the app; if structure has been turned off by the user, will be null.
+ * @param content Additional content data supplied by the app through
+ * {@link android.app.Activity#onProvideAssistContent Activity.onProvideAssistContent}.
+ */
public void onHandleAssist(Bundle data, AssistStructure structure, AssistContent content) {
}
+ /**
+ * Called to receive a screenshot of what the user was currently viewing when an assist
+ * session is started. Will be null if screenshots are disabled by the user.
+ */
public void onHandleScreenshot(Bitmap screenshot) {
}