summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Sauer2018-06-19 17:04:04 -0500
committerNicholas Sauer2018-06-28 10:46:33 -0500
commitdcb3caa81426207d26efce85cb4555b0b7691f65 (patch)
treeb39d5989b54f8eaf01dff7e13fcc16ec355092ab
parent1ab32b66ef7467e536df727b0b9419dd31556a8e (diff)
downloadplatform-packages-services-car-dcb3caa81426207d26efce85cb4555b0b7691f65.tar.gz
platform-packages-services-car-dcb3caa81426207d26efce85cb4555b0b7691f65.tar.xz
platform-packages-services-car-dcb3caa81426207d26efce85cb4555b0b7691f65.zip
Invoke Assistant via VoiceInteractionSession.
bug: 110378156 Test: lunch bat_land-userdbyg && m; deploy and use the input activity in kitchen sink to verify voice. Change-Id: I96ff5377560a5698290a082eb6eb3b4e8017e3bb
-rw-r--r--service/src/com/android/car/CarInputService.java42
1 files changed, 35 insertions, 7 deletions
diff --git a/service/src/com/android/car/CarInputService.java b/service/src/com/android/car/CarInputService.java
index 1f67259e..2b97221e 100644
--- a/service/src/com/android/car/CarInputService.java
+++ b/service/src/com/android/car/CarInputService.java
@@ -16,7 +16,9 @@
16package com.android.car; 16package com.android.car;
17 17
18import static android.hardware.input.InputManager.INJECT_INPUT_EVENT_MODE_ASYNC; 18import static android.hardware.input.InputManager.INJECT_INPUT_EVENT_MODE_ASYNC;
19import static android.service.voice.VoiceInteractionSession.SHOW_SOURCE_ASSIST_GESTURE;
19 20
21import android.app.ActivityManager;
20import android.car.input.CarInputHandlingService; 22import android.car.input.CarInputHandlingService;
21import android.car.input.CarInputHandlingService.InputFilter; 23import android.car.input.CarInputHandlingService.InputFilter;
22import android.car.input.ICarInputListener; 24import android.car.input.ICarInputListener;
@@ -30,19 +32,18 @@ import android.os.Binder;
30import android.os.Bundle; 32import android.os.Bundle;
31import android.os.IBinder; 33import android.os.IBinder;
32import android.os.Parcel; 34import android.os.Parcel;
33import android.os.ParcelFileDescriptor;
34import android.os.RemoteException; 35import android.os.RemoteException;
35import android.os.SystemClock; 36import android.os.SystemClock;
36import android.os.UserHandle; 37import android.os.UserHandle;
37import android.provider.CallLog.Calls; 38import android.provider.CallLog.Calls;
38import android.speech.RecognizerIntent;
39import android.telecom.TelecomManager; 39import android.telecom.TelecomManager;
40import android.text.TextUtils; 40import android.text.TextUtils;
41import android.util.Log; 41import android.util.Log;
42import android.view.KeyEvent; 42import android.view.KeyEvent;
43 43
44import com.android.car.hal.InputHalService; 44import com.android.car.hal.InputHalService;
45import com.android.car.hal.VehicleHal; 45import com.android.internal.app.AssistUtils;
46import com.android.internal.app.IVoiceInteractionSessionShowCallback;
46 47
47import java.io.PrintWriter; 48import java.io.PrintWriter;
48import java.util.HashMap; 49import java.util.HashMap;
@@ -83,12 +84,30 @@ public class CarInputService implements CarServiceBase, InputHalService.InputLis
83 } 84 }
84 } 85 }
85 86
87 private IVoiceInteractionSessionShowCallback mShowCallback =
88 new IVoiceInteractionSessionShowCallback.Stub() {
89 @Override
90 public void onFailed() {
91 Log.w(CarLog.TAG_INPUT, "Failed to show VoiceInteractionSession");
92 }
93
94 @Override
95 public void onShown() {
96 if (DBG) {
97 Log.d(CarLog.TAG_INPUT, "IVoiceInteractionSessionShowCallback onShown()");
98 }
99 }
100 };
101
86 private static final boolean DBG = false; 102 private static final boolean DBG = false;
103 private static final String EXTRA_CAR_PUSH_TO_TALK =
104 "com.android.car.input.EXTRA_CAR_PUSH_TO_TALK";
87 105
88 private final Context mContext; 106 private final Context mContext;
89 private final InputHalService mInputHalService; 107 private final InputHalService mInputHalService;
90 private final TelecomManager mTelecomManager; 108 private final TelecomManager mTelecomManager;
91 private final InputManager mInputManager; 109 private final InputManager mInputManager;
110 private final AssistUtils mAssistUtils;
92 111
93 private KeyEventListener mVoiceAssistantKeyListener; 112 private KeyEventListener mVoiceAssistantKeyListener;
94 private KeyEventListener mLongVoiceAssistantKeyListener; 113 private KeyEventListener mLongVoiceAssistantKeyListener;
@@ -153,6 +172,7 @@ public class CarInputService implements CarServiceBase, InputHalService.InputLis
153 mInputHalService = inputHalService; 172 mInputHalService = inputHalService;
154 mTelecomManager = context.getSystemService(TelecomManager.class); 173 mTelecomManager = context.getSystemService(TelecomManager.class);
155 mInputManager = context.getSystemService(InputManager.class); 174 mInputManager = context.getSystemService(InputManager.class);
175 mAssistUtils = new AssistUtils(context);
156 } 176 }
157 177
158 private synchronized void setHandledKeys(InputFilter[] handledKeys) { 178 private synchronized void setHandledKeys(InputFilter[] handledKeys) {
@@ -324,10 +344,18 @@ public class CarInputService implements CarServiceBase, InputHalService.InputLis
324 } 344 }
325 345
326 private void launchDefaultVoiceAssistantHandler() { 346 private void launchDefaultVoiceAssistantHandler() {
327 Log.i(CarLog.TAG_INPUT, "voice key, launch default intent"); 347 Log.i(CarLog.TAG_INPUT, "voice key, invoke AssistUtils");
328 Intent voiceIntent = 348
329 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); 349 if (mAssistUtils.getAssistComponentForUser(ActivityManager.getCurrentUser()) == null) {
330 mContext.startActivityAsUser(voiceIntent, null, UserHandle.CURRENT_OR_SELF); 350 Log.w(CarLog.TAG_INPUT, "Unable to retrieve assist component for current user");
351 return;
352 }
353
354 final Bundle args = new Bundle();
355 args.putBoolean(EXTRA_CAR_PUSH_TO_TALK, true);
356
357 mAssistUtils.showSessionForActiveService(args,
358 SHOW_SOURCE_ASSIST_GESTURE, mShowCallback, null /*activityToken*/);
331 } 359 }
332 360
333 private void handleInstrumentClusterKey(KeyEvent event) { 361 private void handleInstrumentClusterKey(KeyEvent event) {