diff options
author | Dianne Hackborn <hackbod@google.com> | 2015-02-25 11:08:11 -0800 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2015-02-25 17:36:17 -0800 |
commit | ffeecb1bfb9b71f4b62c9ef1fbf7b58a7a63f655 (patch) | |
tree | 79ce65f76cff29d67abc6b867f0f79795be7a38b /core/java/android/service | |
parent | 6e53931f49f49245deef8622eb8e7dc6ccf04536 (diff) | |
download | frameworks_base-ffeecb1bfb9b71f4b62c9ef1fbf7b58a7a63f655.zip frameworks_base-ffeecb1bfb9b71f4b62c9ef1fbf7b58a7a63f655.tar.gz frameworks_base-ffeecb1bfb9b71f4b62c9ef1fbf7b58a7a63f655.tar.bz2 |
Rework voice interaction session lifecycle.
We now have a formal concept of the session being shown and
hidden, with it being able to continue running while hidden
as long as there is enough RAM.
This changes the flow that a VoiceInteractionSession will
see: onCreate() is when it is first created, onCreateContentView()
is when its UI first needs to be built, onShow() is called each
time it needs to be shown and has the arguments given when the
show request was made (which has been renamed from startSession to
showSession), and then onHide() will be called when the UI is
no longer shown.
The methods show() and hide() now allow a VoiceInteractionSession
subclass to control when it is shown and hidden, working with the
shown state being maintained by the system.
Change-Id: Ic4a430ec7e8bf76a5441fd0425e2932806170fcc
Diffstat (limited to 'core/java/android/service')
3 files changed, 118 insertions, 47 deletions
diff --git a/core/java/android/service/voice/IVoiceInteractionSession.aidl b/core/java/android/service/voice/IVoiceInteractionSession.aidl index a8c0c4c..797457a 100644 --- a/core/java/android/service/voice/IVoiceInteractionSession.aidl +++ b/core/java/android/service/voice/IVoiceInteractionSession.aidl @@ -23,6 +23,8 @@ import android.os.Bundle; * @hide */ oneway interface IVoiceInteractionSession { + void show(in Bundle sessionArgs, int flags); + void hide(); void handleAssist(in Bundle assistData); void taskStarted(in Intent intent, int taskId); void taskFinished(in Intent intent, int taskId); diff --git a/core/java/android/service/voice/VoiceInteractionService.java b/core/java/android/service/voice/VoiceInteractionService.java index 54a3a0a..0c01b25 100644 --- a/core/java/android/service/voice/VoiceInteractionService.java +++ b/core/java/android/service/voice/VoiceInteractionService.java @@ -71,7 +71,7 @@ public class VoiceInteractionService extends Service { public static final String SERVICE_META_DATA = "android.voice_interaction"; /** - * Flag for use with {@link #startSession}: request that the session be started with + * Flag for use with {@link #showSession: request that the session be started with * assist data from the currently focused activity. */ public static final int START_WITH_ASSIST = 1<<0; @@ -139,20 +139,25 @@ public class VoiceInteractionService extends Service { } /** - * Initiate the execution of a new {@link android.service.voice.VoiceInteractionSession}. + * Request that the associated {@link android.service.voice.VoiceInteractionSession} be + * shown to the user, starting it if necessary. * @param args Arbitrary arguments that will be propagated to the session. */ - public void startSession(Bundle args, int flags) { + public void showSession(Bundle args, int flags) { if (mSystemService == null) { throw new IllegalStateException("Not available until onReady() is called"); } try { - mSystemService.startSession(mInterface, args, flags); + mSystemService.showSession(mInterface, args, flags); } catch (RemoteException e) { } } /** @hide */ + public void startSession(Bundle args, int flags) { + showSession(args, flags); + } + /** @hide */ public void startSession(Bundle args) { startSession(args, 0); } @@ -174,7 +179,7 @@ public class VoiceInteractionService extends Service { /** * Called during service initialization to tell you when the system is ready * to receive interaction from it. You should generally do initialization here - * rather than in {@link #onCreate}. Methods such as {@link #startSession} and + * rather than in {@link #onCreate}. Methods such as {@link #showSession} and * {@link #createAlwaysOnHotwordDetector} * will not be operational until this point. */ diff --git a/core/java/android/service/voice/VoiceInteractionSession.java b/core/java/android/service/voice/VoiceInteractionSession.java index a3a2ca1..4cf0e4c 100644 --- a/core/java/android/service/voice/VoiceInteractionSession.java +++ b/core/java/android/service/voice/VoiceInteractionSession.java @@ -53,10 +53,9 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; /** * An active voice interaction session, providing a facility for the implementation - * to interact with the user in the voice interaction layer. This interface is no shown - * by default, but you can request that it be shown with {@link #showWindow()}, which - * will result in a later call to {@link #onCreateContentView()} in which the UI can be - * built + * to interact with the user in the voice interaction layer. The user interface is + * initially shown by default, and can be created be overriding {@link #onCreateContentView()} + * in which the UI can be built. * * <p>A voice interaction session can be self-contained, ultimately calling {@link #finish} * when done. It can also initiate voice interactions with applications by calling @@ -151,6 +150,17 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback { final IVoiceInteractionSession mSession = new IVoiceInteractionSession.Stub() { @Override + public void show(Bundle sessionArgs, int flags) { + mHandlerCaller.sendMessage(mHandlerCaller.obtainMessageIO(MSG_SHOW, + flags, sessionArgs)); + } + + @Override + public void hide() { + mHandlerCaller.sendMessage(mHandlerCaller.obtainMessage(MSG_HIDE)); + } + + @Override public void handleAssist(Bundle assistBundle) { mHandlerCaller.sendMessage(mHandlerCaller.obtainMessageO(MSG_HANDLE_ASSIST, assistBundle)); @@ -284,6 +294,8 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback { static final int MSG_CLOSE_SYSTEM_DIALOGS = 102; static final int MSG_DESTROY = 103; static final int MSG_HANDLE_ASSIST = 104; + static final int MSG_SHOW = 105; + static final int MSG_HIDE = 106; class MyCallbacks implements HandlerCaller.Callback, SoftInputWindow.Callback { @Override @@ -324,9 +336,8 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback { args.arg1 = onGetSupportedCommands((Caller) args.arg1, (String[]) args.arg2); break; case MSG_CANCEL: - args = (SomeArgs)msg.obj; - if (DEBUG) Log.d(TAG, "onCancel: req=" + ((Request) args.arg1).mInterface); - onCancel((Request)args.arg1); + if (DEBUG) Log.d(TAG, "onCancel: req=" + ((Request)msg.obj)); + onCancel((Request)msg.obj); break; case MSG_TASK_STARTED: if (DEBUG) Log.d(TAG, "onTaskStarted: intent=" + msg.obj @@ -350,6 +361,15 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback { if (DEBUG) Log.d(TAG, "onHandleAssist: " + (Bundle)msg.obj); onHandleAssist((Bundle) msg.obj); break; + case MSG_SHOW: + if (DEBUG) Log.d(TAG, "doShow: args=" + msg.obj + + " flags=" + msg.arg1); + doShow((Bundle) msg.obj, msg.arg1); + break; + case MSG_HIDE: + if (DEBUG) Log.d(TAG, "doHide"); + doHide(); + break; } } @@ -457,6 +477,45 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback { onCreate(args, startFlags); } + void doShow(Bundle args, int flags) { + if (DEBUG) Log.v(TAG, "Showing window: mWindowAdded=" + mWindowAdded + + " mWindowVisible=" + mWindowVisible); + + if (mInShowWindow) { + Log.w(TAG, "Re-entrance in to showWindow"); + return; + } + + try { + mInShowWindow = true; + if (!mWindowVisible) { + if (!mWindowAdded) { + mWindowAdded = true; + View v = onCreateContentView(); + if (v != null) { + setContentView(v); + } + } + } + onShow(args, flags); + if (!mWindowVisible) { + mWindowVisible = true; + mWindow.show(); + } + } finally { + mWindowWasVisible = true; + mInShowWindow = false; + } + } + + void doHide() { + if (mWindowVisible) { + mWindow.hide(); + mWindowVisible = false; + onHide(); + } + } + void doDestroy() { onDestroy(); if (mInitialized) { @@ -484,39 +543,26 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback { mContentFrame = (FrameLayout)mRootView.findViewById(android.R.id.content); } - public void showWindow() { - if (DEBUG) Log.v(TAG, "Showing window: mWindowAdded=" + mWindowAdded - + " mWindowVisible=" + mWindowVisible); - - if (mInShowWindow) { - Log.w(TAG, "Re-entrance in to showWindow"); - return; + public void show() { + try { + mSystemService.showSessionFromSession(mToken, null, 0); + } catch (RemoteException e) { } + } + public void hide() { try { - mInShowWindow = true; - if (!mWindowVisible) { - mWindowVisible = true; - if (!mWindowAdded) { - mWindowAdded = true; - View v = onCreateContentView(); - if (v != null) { - setContentView(v); - } - } - mWindow.show(); - } - } finally { - mWindowWasVisible = true; - mInShowWindow = false; + mSystemService.hideSessionFromSession(mToken); + } catch (RemoteException e) { } } + /** TODO: remove */ + public void showWindow() { + } + + /** TODO: remove */ public void hideWindow() { - if (mWindowVisible) { - mWindow.hide(); - mWindowVisible = false; - } } /** @@ -611,15 +657,33 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback { } /** - * Initiatize a new session. + * Initiatize a new session. The given args and showFlags are the initial values + * passed to {@link VoiceInteractionService#showSession VoiceInteractionService.showSession}, + * if possible. Normally you should handle these in {@link #onShow}. + */ + public void onCreate(Bundle args, int showFlags) { + onCreate(args); + } + + /** + * Called when the session UI is going to be shown. This is called after + * {@link #onCreateContentView} (if the session's content UI needed to be created) and + * immediately prior to the window being shown. This may be called while the window + * is already shown, if a show request has come in while it is shown, to allow you to + * update the UI to match the new show arguments. * * @param args The arguments that were supplied to - * {@link VoiceInteractionService#startSession VoiceInteractionService.startSession}. - * @param startFlags The start flags originally provided to - * {@link VoiceInteractionService#startSession VoiceInteractionService.startSession}. + * {@link VoiceInteractionService#showSession VoiceInteractionService.showSession}. + * @param showFlags The show flags originally provided to + * {@link VoiceInteractionService#showSession VoiceInteractionService.showSession}. */ - public void onCreate(Bundle args, int startFlags) { - onCreate(args); + public void onShow(Bundle args, int showFlags) { + } + + /** + * Called immediately after stopping to show the session UI. + */ + public void onHide() { } /** @@ -663,7 +727,7 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback { } public void onBackPressed() { - finish(); + hide(); } /** @@ -672,7 +736,7 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback { * calls {@link #finish}. */ public void onCloseSystemDialogs() { - finish(); + hide(); } /** @@ -717,7 +781,7 @@ public abstract class VoiceInteractionSession implements KeyEvent.Callback { * @param taskId Unique ID of the finished task. */ public void onTaskFinished(Intent intent, int taskId) { - finish(); + hide(); } /** |