summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Sauer2018-06-28 14:00:14 -0500
committerandroid-build-merger2018-06-28 14:00:14 -0500
commit711a1d88df32e2e96029da42240dd14c14f056f1 (patch)
tree5b0cdc9807594259e329324dd69109ce8f2bcec1 /service
parent20439ee06ffd7e59355adf208f6c2a39866c4cb1 (diff)
parentb1b7956934aaa87f40be27092e92f46d1e8fe214 (diff)
downloadplatform-packages-services-car-711a1d88df32e2e96029da42240dd14c14f056f1.tar.gz
platform-packages-services-car-711a1d88df32e2e96029da42240dd14c14f056f1.tar.xz
platform-packages-services-car-711a1d88df32e2e96029da42240dd14c14f056f1.zip
Merge "Invoke Assistant via VoiceInteractionSession." into pi-dev
am: b1b7956934 Change-Id: Ia137fa48c2850a954016fc8287a7a597d99ac12e
Diffstat (limited to 'service')
-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) {