From 18f0d357f9693fe787a3e3777d8fdf01357a6e3f Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Fri, 25 Apr 2014 17:06:18 -0700 Subject: Rework some of the voice interaction APIs. On the app side, requests are now composed by subclassing from various types of Request objects. On the service side, starting a voice interaction session involves starting another service that will then manage the session. This leads the service design much more to what we want, where the long-running main service is very tiny and all the heavy-weight transient session work is elsewhere in another process. Change-Id: I46c074c6fe27b6c1cf2583c6d216aed1de2f1143 --- tests/VoiceInteraction/AndroidManifest.xml | 6 +++++ .../res/xml/interaction_service.xml | 21 ++++++++++++++++ .../voiceinteraction/MainInteractionService.java | 3 +-- .../voiceinteraction/MainInteractionSession.java | 7 ++++-- .../MainInteractionSessionService.java | 28 ++++++++++++++++++++++ .../voiceinteraction/TestInteractionActivity.java | 22 +++++++++-------- 6 files changed, 73 insertions(+), 14 deletions(-) create mode 100644 tests/VoiceInteraction/res/xml/interaction_service.xml create mode 100644 tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSessionService.java (limited to 'tests') diff --git a/tests/VoiceInteraction/AndroidManifest.xml b/tests/VoiceInteraction/AndroidManifest.xml index 9c5acf9..ac0f701 100644 --- a/tests/VoiceInteraction/AndroidManifest.xml +++ b/tests/VoiceInteraction/AndroidManifest.xml @@ -12,10 +12,16 @@ + + + diff --git a/tests/VoiceInteraction/res/xml/interaction_service.xml b/tests/VoiceInteraction/res/xml/interaction_service.xml new file mode 100644 index 0000000..45bd994d --- /dev/null +++ b/tests/VoiceInteraction/res/xml/interaction_service.xml @@ -0,0 +1,21 @@ + + + + diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java index 35702f1..008d97b 100644 --- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java @@ -31,8 +31,7 @@ public class MainInteractionService extends VoiceInteractionService { @Override public int onStartCommand(Intent intent, int flags, int startId) { - startVoiceActivity(new Intent(this, TestInteractionActivity.class), - new MainInteractionSession(this)); + startVoiceActivity(new Intent(this, TestInteractionActivity.class), null); stopSelf(startId); return START_NOT_STICKY; } diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java index adc0df4..0fc563b 100644 --- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSession.java @@ -24,8 +24,11 @@ import android.util.Log; public class MainInteractionSession extends VoiceInteractionSession { static final String TAG = "MainInteractionSession"; - MainInteractionSession(Context context) { + final Bundle mArgs; + + MainInteractionSession(Context context, Bundle args) { super(context); + mArgs = args; } @Override @@ -42,7 +45,7 @@ public class MainInteractionSession extends VoiceInteractionSession { @Override public void onCommand(Caller caller, Request request, String command, Bundle extras) { Log.i(TAG, "onCommand: command=" + command + " extras=" + extras); - request.sendCommandResult(null); + request.sendCommandResult(true, null); } @Override diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSessionService.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSessionService.java new file mode 100644 index 0000000..8864d71 --- /dev/null +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionSessionService.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2014 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 com.android.test.voiceinteraction; + +import android.os.Bundle; +import android.service.voice.VoiceInteractionSession; +import android.service.voice.VoiceInteractionSessionService; + +public class MainInteractionSessionService extends VoiceInteractionSessionService { + @Override + public VoiceInteractionSession onNewSession(Bundle args) { + return new MainInteractionSession(this, args); + } +} diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java index 016a80e..9c772ff 100644 --- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/TestInteractionActivity.java @@ -30,28 +30,30 @@ public class TestInteractionActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.test_interaction); if (!isVoiceInteraction()) { Log.w(TAG, "Not running as a voice interaction!"); finish(); return; } + setContentView(R.layout.test_interaction); + mInteractor = getVoiceInteractor(); - mInteractor.startConfirmation(new VoiceInteractor.Callback() { + VoiceInteractor.ConfirmationRequest req = new VoiceInteractor.ConfirmationRequest( + "This is a confirmation", null) { @Override - public void onConfirmationResult(VoiceInteractor.Request request, boolean confirmed, - Bundle result) { - Log.i(TAG, "Confirmation result: confirmed=" + confirmed + " result=" + result); - finish(); + public void onCancel() { + Log.i(TAG, "Canceled!"); + getActivity().finish(); } @Override - public void onCancel(VoiceInteractor.Request request) { - Log.i(TAG, "Canceled!"); - finish(); + public void onConfirmationResult(boolean confirmed, Bundle result) { + Log.i(TAG, "Confirmation result: confirmed=" + confirmed + " result=" + result); + getActivity().finish(); } - }, "This is a confirmation", null); + }; + mInteractor.submitRequest(req); } @Override -- cgit v1.1