diff options
author | Nicholas Sauer | 2018-06-19 17:04:04 -0500 |
---|---|---|
committer | Nicholas Sauer | 2018-06-28 10:46:33 -0500 |
commit | dcb3caa81426207d26efce85cb4555b0b7691f65 (patch) | |
tree | b39d5989b54f8eaf01dff7e13fcc16ec355092ab | |
parent | 1ab32b66ef7467e536df727b0b9419dd31556a8e (diff) | |
download | platform-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.java | 42 |
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 @@ | |||
16 | package com.android.car; | 16 | package com.android.car; |
17 | 17 | ||
18 | import static android.hardware.input.InputManager.INJECT_INPUT_EVENT_MODE_ASYNC; | 18 | import static android.hardware.input.InputManager.INJECT_INPUT_EVENT_MODE_ASYNC; |
19 | import static android.service.voice.VoiceInteractionSession.SHOW_SOURCE_ASSIST_GESTURE; | ||
19 | 20 | ||
21 | import android.app.ActivityManager; | ||
20 | import android.car.input.CarInputHandlingService; | 22 | import android.car.input.CarInputHandlingService; |
21 | import android.car.input.CarInputHandlingService.InputFilter; | 23 | import android.car.input.CarInputHandlingService.InputFilter; |
22 | import android.car.input.ICarInputListener; | 24 | import android.car.input.ICarInputListener; |
@@ -30,19 +32,18 @@ import android.os.Binder; | |||
30 | import android.os.Bundle; | 32 | import android.os.Bundle; |
31 | import android.os.IBinder; | 33 | import android.os.IBinder; |
32 | import android.os.Parcel; | 34 | import android.os.Parcel; |
33 | import android.os.ParcelFileDescriptor; | ||
34 | import android.os.RemoteException; | 35 | import android.os.RemoteException; |
35 | import android.os.SystemClock; | 36 | import android.os.SystemClock; |
36 | import android.os.UserHandle; | 37 | import android.os.UserHandle; |
37 | import android.provider.CallLog.Calls; | 38 | import android.provider.CallLog.Calls; |
38 | import android.speech.RecognizerIntent; | ||
39 | import android.telecom.TelecomManager; | 39 | import android.telecom.TelecomManager; |
40 | import android.text.TextUtils; | 40 | import android.text.TextUtils; |
41 | import android.util.Log; | 41 | import android.util.Log; |
42 | import android.view.KeyEvent; | 42 | import android.view.KeyEvent; |
43 | 43 | ||
44 | import com.android.car.hal.InputHalService; | 44 | import com.android.car.hal.InputHalService; |
45 | import com.android.car.hal.VehicleHal; | 45 | import com.android.internal.app.AssistUtils; |
46 | import com.android.internal.app.IVoiceInteractionSessionShowCallback; | ||
46 | 47 | ||
47 | import java.io.PrintWriter; | 48 | import java.io.PrintWriter; |
48 | import java.util.HashMap; | 49 | import 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) { |