diff options
author | Dianne Hackborn <hackbod@google.com> | 2015-06-30 14:38:17 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2015-06-30 16:59:41 -0700 |
commit | 593334ab70a8341c7d24d71a377ab5617e3f4ab7 (patch) | |
tree | 7005af1c583f459a8ce7a02a30f65502258ba015 /tests | |
parent | 1aaad610dfc7445ec29fd906974677515c3a9f87 (diff) | |
download | frameworks_base-593334ab70a8341c7d24d71a377ab5617e3f4ab7.zip frameworks_base-593334ab70a8341c7d24d71a377ab5617e3f4ab7.tar.gz frameworks_base-593334ab70a8341c7d24d71a377ab5617e3f4ab7.tar.bz2 |
Fix issue #22124996: VI: Command Request not Active
Just forgot to add the request to the active set.
Also eradicate a bunch of old cruft that has been replaced
by the final APIs, and improve voice interaction test to
sit fully on top of the final APIs and have a test for
command request.
Change-Id: Ieff7a6165ebf2a4c5fb80c1ebd020511a2ae63ee
Diffstat (limited to 'tests')
6 files changed, 130 insertions, 59 deletions
diff --git a/tests/Assist/src/com/android/test/assist/AssistInteractionSession.java b/tests/Assist/src/com/android/test/assist/AssistInteractionSession.java index e4ea0bc..43f1e32 100644 --- a/tests/Assist/src/com/android/test/assist/AssistInteractionSession.java +++ b/tests/Assist/src/com/android/test/assist/AssistInteractionSession.java @@ -52,28 +52,23 @@ public class AssistInteractionSession extends VoiceInteractionSession { } @Override - public void onConfirm(Caller caller, - Request request, CharSequence prompt, Bundle extras) { - + public void onRequestConfirmation(ConfirmationRequest request) { } @Override - public void onPickOption(Caller caller, - Request request, CharSequence prompt, - VoiceInteractor.PickOptionRequest.Option[] options, Bundle extras) { - + public void onRequestPickOption(PickOptionRequest request) { } @Override - public void onCommand(Caller caller, - Request request, String command, Bundle extras) { - + public void onRequestCommand(CommandRequest request) { } @Override - public void onCreate(Bundle args) { - super.onCreate(args); + public void onCancelRequest(Request request) { + } + @Override + public void onCreate() { // Simulate slowness of Assist app try { Thread.sleep(1000); @@ -83,11 +78,6 @@ public class AssistInteractionSession extends VoiceInteractionSession { } @Override - public void onCancel(Request request) { - - } - - @Override public View onCreateContentView() { View v = getLayoutInflater().inflate(R.layout.assist, null); mScrim = v.findViewById(R.id.scrim); diff --git a/tests/VoiceInteraction/res/layout/test_interaction.xml b/tests/VoiceInteraction/res/layout/test_interaction.xml index 6209bd0..d1a7ad5 100644 --- a/tests/VoiceInteraction/res/layout/test_interaction.xml +++ b/tests/VoiceInteraction/res/layout/test_interaction.xml @@ -51,6 +51,19 @@ android:text="@string/abortVoice" /> + </LinearLayout> + + <LinearLayout android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="16dp" + android:orientation="horizontal"> + + <Button android:id="@+id/command" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/commandVoice" + /> + <Button android:id="@+id/pick" android:layout_width="wrap_content" android:layout_height="wrap_content" diff --git a/tests/VoiceInteraction/res/values/strings.xml b/tests/VoiceInteraction/res/values/strings.xml index 4cf4104..cf660e6 100644 --- a/tests/VoiceInteraction/res/values/strings.xml +++ b/tests/VoiceInteraction/res/values/strings.xml @@ -24,6 +24,7 @@ <string name="abort">Abort</string> <string name="complete">Complete</string> <string name="abortVoice">Abort Voice</string> + <string name="commandVoice">Command</string> <string name="completeVoice">Complete Voice</string> <string name="pickVoice">Pick Voice</string> <string name="cancelVoice">Cancel</string> diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java index 578e356..8381aa1 100644 --- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java @@ -80,7 +80,8 @@ public class MainInteractionService extends VoiceInteractionService { Bundle args = new Bundle(); args.putParcelable("intent", new Intent(this, TestInteractionActivity.class)); args.putBundle("assist", intent.getExtras()); - startSession(args, VoiceInteractionSession.SHOW_WITH_ASSIST | VoiceInteractionSession.SHOW_WITH_SCREENSHOT); + showSession(args, VoiceInteractionSession.SHOW_WITH_ASSIST + | VoiceInteractionSession.SHOW_WITH_SCREENSHOT); } else { Log.w(TAG, "Not starting -- not current voice interaction service"); } diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java index 97c1e85..a6585ba 100644 --- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java @@ -60,7 +60,7 @@ public class MainInteractionSession extends VoiceInteractionSession static final int STATE_COMMAND = 4; static final int STATE_ABORT_VOICE = 5; static final int STATE_COMPLETE_VOICE = 6; - static final int STATE_DONE=7; + static final int STATE_DONE = 7; int mState = STATE_IDLE; VoiceInteractor.PickOptionRequest.Option[] mPendingOptions; @@ -72,8 +72,8 @@ public class MainInteractionSession extends VoiceInteractionSession } @Override - public void onCreate(Bundle args, int startFlags) { - super.onCreate(args, startFlags); + public void onCreate() { + super.onCreate(); ActivityManager am = getContext().getSystemService(ActivityManager.class); am.setWatchHeapLimit(40 * 1024 * 1024); } @@ -163,8 +163,8 @@ public class MainInteractionSession extends VoiceInteractionSession if (screenshot != null) { mScreenshot.setImageBitmap(screenshot); mScreenshot.setAdjustViewBounds(true); - mScreenshot.setMaxWidth(screenshot.getWidth()/3); - mScreenshot.setMaxHeight(screenshot.getHeight()/3); + mScreenshot.setMaxWidth(screenshot.getWidth() / 3); + mScreenshot.setMaxHeight(screenshot.getHeight() / 3); mFullScreenshot.setImageBitmap(screenshot); } else { mScreenshot.setImageDrawable(null); @@ -207,11 +207,12 @@ public class MainInteractionSession extends VoiceInteractionSession updateState(); startVoiceActivity(mStartIntent); } else if (v == mConfirmButton) { - if (mState == STATE_CONFIRM) { - mPendingRequest.sendConfirmResult(true, null); + if (mPendingRequest instanceof ConfirmationRequest) { + ((ConfirmationRequest)mPendingRequest).sendConfirmationResult(true, null); mPendingRequest = null; mState = STATE_LAUNCHING; - } else if (mState == STATE_PICK_OPTION) { + } else if (mPendingRequest instanceof PickOptionRequest) { + PickOptionRequest pick = (PickOptionRequest)mPendingRequest; int numReturn = mPendingOptions.length/2; if (numReturn <= 0) { numReturn = 1; @@ -223,23 +224,25 @@ public class MainInteractionSession extends VoiceInteractionSession } mPendingOptions = picked; if (picked.length <= 1) { - mPendingRequest.sendPickOptionResult(true, picked, null); + pick.sendPickOptionResult(picked, null); mPendingRequest = null; mState = STATE_LAUNCHING; } else { - mPendingRequest.sendPickOptionResult(false, picked, null); + pick.sendIntermediatePickOptionResult(picked, null); updatePickText(); } - } else if (mPendingRequest != null) { - mPendingRequest.sendCommandResult(true, null); + } else if (mPendingRequest instanceof CommandRequest) { + Bundle result = new Bundle(); + result.putString("key", "a result!"); + ((CommandRequest)mPendingRequest).sendResult(result); mPendingRequest = null; mState = STATE_LAUNCHING; } - } else if (v == mAbortButton) { - mPendingRequest.sendAbortVoiceResult(null); + } else if (v == mAbortButton && mPendingRequest instanceof AbortVoiceRequest) { + ((AbortVoiceRequest)mPendingRequest).sendAbortResult(null); mPendingRequest = null; - } else if (v == mCompleteButton) { - mPendingRequest.sendCompleteVoiceResult(null); + } else if (v == mCompleteButton && mPendingRequest instanceof CompleteVoiceRequest) { + ((CompleteVoiceRequest)mPendingRequest).sendCompleteResult(null); mPendingRequest = null; } else if (v == mScreenshot) { if (mFullScreenshot.getVisibility() != View.VISIBLE) { @@ -261,29 +264,45 @@ public class MainInteractionSession extends VoiceInteractionSession } @Override - public boolean[] onGetSupportedCommands(Caller caller, String[] commands) { - return new boolean[commands.length]; + public boolean[] onGetSupportedCommands(String[] commands) { + boolean[] res = new boolean[commands.length]; + for (int i=0; i<commands.length; i++) { + if ("com.android.test.voiceinteraction.COMMAND".equals(commands[i])) { + res[i] = true; + } + } + return res; } + void setPrompt(VoiceInteractor.Prompt prompt) { + if (prompt == null) { + mText.setText("(null)"); + mPendingPrompt = ""; + } else { + mText.setText(prompt.getVisualPrompt()); + mPendingPrompt = prompt.getVisualPrompt(); + } + } + @Override - public void onConfirm(Caller caller, Request request, CharSequence prompt, Bundle extras) { - Log.i(TAG, "onConfirm: prompt=" + prompt + " extras=" + extras); - mText.setText(prompt); + public void onRequestConfirmation(ConfirmationRequest request) { + Log.i(TAG, "onConfirm: prompt=" + request.getVoicePrompt() + " extras=" + + request.getExtras()); + setPrompt(request.getVoicePrompt()); mConfirmButton.setText("Confirm"); mPendingRequest = request; - mPendingPrompt = prompt; mState = STATE_CONFIRM; updateState(); } @Override - public void onPickOption(Caller caller, Request request, CharSequence prompt, - VoiceInteractor.PickOptionRequest.Option[] options, Bundle extras) { - Log.i(TAG, "onPickOption: prompt=" + prompt + " options=" + options + " extras=" + extras); + public void onRequestPickOption(PickOptionRequest request) { + Log.i(TAG, "onPickOption: prompt=" + request.getVoicePrompt() + " options=" + + request.getOptions() + " extras=" + request.getExtras()); mConfirmButton.setText("Pick Option"); mPendingRequest = request; - mPendingPrompt = prompt; - mPendingOptions = options; + setPrompt(request.getVoicePrompt()); + mPendingOptions = request.getOptions(); mState = STATE_PICK_OPTION; updatePickText(); updateState(); @@ -303,27 +322,33 @@ public class MainInteractionSession extends VoiceInteractionSession } @Override - public void onCompleteVoice(Caller caller, Request request, CharSequence message, Bundle extras) { - Log.i(TAG, "onCompleteVoice: message=" + message + " extras=" + extras); - mText.setText(message); + public void onRequestCompleteVoice(CompleteVoiceRequest request) { + Log.i(TAG, "onCompleteVoice: message=" + request.getVoicePrompt() + " extras=" + + request.getExtras()); + setPrompt(request.getVoicePrompt()); mPendingRequest = request; mState = STATE_COMPLETE_VOICE; updateState(); } @Override - public void onAbortVoice(Caller caller, Request request, CharSequence message, Bundle extras) { - Log.i(TAG, "onAbortVoice: message=" + message + " extras=" + extras); - mText.setText(message); + public void onRequestAbortVoice(AbortVoiceRequest request) { + Log.i(TAG, "onAbortVoice: message=" + request.getVoicePrompt() + " extras=" + + request.getExtras()); + setPrompt(request.getVoicePrompt()); mPendingRequest = request; mState = STATE_ABORT_VOICE; updateState(); } @Override - public void onCommand(Caller caller, Request request, String command, Bundle extras) { - Log.i(TAG, "onCommand: command=" + command + " extras=" + extras); - mText.setText("Command: " + command); + public void onRequestCommand(CommandRequest request) { + Bundle extras = request.getExtras(); + if (extras != null) { + extras.getString("arg"); + } + Log.i(TAG, "onCommand: command=" + request.getCommand() + " extras=" + extras); + mText.setText("Command: " + request.getCommand() + ", " + extras); mConfirmButton.setText("Finish Command"); mPendingRequest = request; mState = STATE_COMMAND; @@ -331,8 +356,13 @@ public class MainInteractionSession extends VoiceInteractionSession } @Override - public void onCancel(Request request) { + public void onCancelRequest(Request request) { Log.i(TAG, "onCancel"); - request.sendCancelResult(); + if (mPendingRequest == request) { + mPendingRequest = null; + mState = STATE_LAUNCHING; + updateState(); + } + request.cancel(); } } diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java index 943c647..2487e1ca 100644 --- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java @@ -33,6 +33,7 @@ public class TestInteractionActivity extends Activity implements View.OnClickLis static final String REQUEST_ABORT = "abort"; static final String REQUEST_COMPLETE = "complete"; + static final String REQUEST_COMMAND = "command"; static final String REQUEST_PICK = "pick"; static final String REQUEST_CONFIRM = "confirm"; @@ -41,6 +42,7 @@ public class TestInteractionActivity extends Activity implements View.OnClickLis TextView mLog; Button mAbortButton; Button mCompleteButton; + Button mCommandButton; Button mPickButton; Button mJumpOutButton; Button mCancelButton; @@ -68,6 +70,8 @@ public class TestInteractionActivity extends Activity implements View.OnClickLis mAbortButton.setOnClickListener(this); mCompleteButton = (Button)findViewById(R.id.complete); mCompleteButton.setOnClickListener(this); + mCommandButton = (Button)findViewById(R.id.command); + mCommandButton.setOnClickListener(this); mPickButton = (Button)findViewById(R.id.pick); mPickButton.setOnClickListener(this); mJumpOutButton = (Button)findViewById(R.id.jump); @@ -117,6 +121,9 @@ public class TestInteractionActivity extends Activity implements View.OnClickLis } else if (v == mCompleteButton) { VoiceInteractor.CompleteVoiceRequest req = new TestCompleteVoice(); mInteractor.submitRequest(req, REQUEST_COMPLETE); + } else if (v == mCommandButton) { + VoiceInteractor.CommandRequest req = new TestCommand("Some arg"); + mInteractor.submitRequest(req, REQUEST_COMMAND); } else if (v == mPickButton) { VoiceInteractor.PickOptionRequest.Option[] options = new VoiceInteractor.PickOptionRequest.Option[5]; @@ -176,6 +183,37 @@ public class TestInteractionActivity extends Activity implements View.OnClickLis } } + static class TestCommand extends VoiceInteractor.CommandRequest { + public TestCommand(String arg) { + super("com.android.test.voiceinteraction.COMMAND", makeBundle(arg)); + } + @Override public void onCancel() { + Log.i(TAG, "Canceled!"); + ((TestInteractionActivity)getActivity()).mLog.append("Canceled command\n"); + } + @Override + public void onCommandResult(boolean finished, Bundle result) { + Log.i(TAG, "Command result: finished=" + finished + " result=" + result); + StringBuilder sb = new StringBuilder(); + if (finished) { + sb.append("Command final result: "); + } else { + sb.append("Command intermediate result: "); + } + if (result != null) { + result.getString("key"); + } + sb.append(result); + sb.append("\n"); + ((TestInteractionActivity)getActivity()).mLog.append(sb.toString()); + } + static Bundle makeBundle(String arg) { + Bundle b = new Bundle(); + b.putString("key", arg); + return b; + } + } + static class TestPickOption extends VoiceInteractor.PickOptionRequest { public TestPickOption(Option[] options) { super(new VoiceInteractor.Prompt("Need to pick something"), options, null); @@ -200,10 +238,8 @@ public class TestInteractionActivity extends Activity implements View.OnClickLis } sb.append(selections[i].getLabel()); } + sb.append("\n"); ((TestInteractionActivity)getActivity()).mLog.append(sb.toString()); - if (finished) { - getActivity().finish(); - } } } } |