diff options
author | Dianne Hackborn <hackbod@google.com> | 2014-04-25 17:06:18 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2014-04-28 10:54:15 -0700 |
commit | 18f0d357f9693fe787a3e3777d8fdf01357a6e3f (patch) | |
tree | 87ffa17a98fa81355a37e25b2c7fc649ffc4e9be /tests | |
parent | 01c70711d5e4f1c3405bcd169be70605e92166f2 (diff) | |
download | frameworks_base-18f0d357f9693fe787a3e3777d8fdf01357a6e3f.zip frameworks_base-18f0d357f9693fe787a3e3777d8fdf01357a6e3f.tar.gz frameworks_base-18f0d357f9693fe787a3e3777d8fdf01357a6e3f.tar.bz2 |
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
Diffstat (limited to 'tests')
6 files changed, 73 insertions, 14 deletions
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 @@ <service android:name="MainInteractionService" android:permission="android.permission.BIND_VOICE_INTERACTION" android:process=":interactor"> + <meta-data android:name="android.voice_interaction" + android:resource="@xml/interaction_service" /> <intent-filter> <action android:name="android.service.voice.VoiceInteractionService" /> </intent-filter> </service> + <service android:name="MainInteractionSessionService" + android:permission="android.permission.BIND_VOICE_INTERACTION" + android:process=":session"> + </service> <activity android:name="TestInteractionActivity" android:label="Voice Interaction Target"> <intent-filter> <action android:name="android.intent.action.MAIN" /> 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * 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. + */ +--> + +<voice-interaction-service xmlns:android="http://schemas.android.com/apk/res/android" + android:sessionService="com.android.test.voiceinteraction.MainInteractionSessionService" /> 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 |