diff options
author | Nicholas Sauer <nicksauer@google.com> | 2018-06-19 15:04:04 -0700 |
---|---|---|
committer | Nicholas Sauer <nicksauer@google.com> | 2018-06-28 08:46:33 -0700 |
commit | dcb3caa81426207d26efce85cb4555b0b7691f65 (patch) | |
tree | b39d5989b54f8eaf01dff7e13fcc16ec355092ab /service/src/com/android | |
parent | 1ab32b66ef7467e536df727b0b9419dd31556a8e (diff) | |
download | Car-dcb3caa81426207d26efce85cb4555b0b7691f65.tar.gz |
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
Diffstat (limited to 'service/src/com/android')
-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 1f67259ea8..2b97221ee3 100644 --- a/service/src/com/android/car/CarInputService.java +++ b/service/src/com/android/car/CarInputService.java @@ -16,7 +16,9 @@ package com.android.car; import static android.hardware.input.InputManager.INJECT_INPUT_EVENT_MODE_ASYNC; +import static android.service.voice.VoiceInteractionSession.SHOW_SOURCE_ASSIST_GESTURE; +import android.app.ActivityManager; import android.car.input.CarInputHandlingService; import android.car.input.CarInputHandlingService.InputFilter; import android.car.input.ICarInputListener; @@ -30,19 +32,18 @@ import android.os.Binder; import android.os.Bundle; import android.os.IBinder; import android.os.Parcel; -import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.os.SystemClock; import android.os.UserHandle; import android.provider.CallLog.Calls; -import android.speech.RecognizerIntent; import android.telecom.TelecomManager; import android.text.TextUtils; import android.util.Log; import android.view.KeyEvent; import com.android.car.hal.InputHalService; -import com.android.car.hal.VehicleHal; +import com.android.internal.app.AssistUtils; +import com.android.internal.app.IVoiceInteractionSessionShowCallback; import java.io.PrintWriter; import java.util.HashMap; @@ -83,12 +84,30 @@ public class CarInputService implements CarServiceBase, InputHalService.InputLis } } + private IVoiceInteractionSessionShowCallback mShowCallback = + new IVoiceInteractionSessionShowCallback.Stub() { + @Override + public void onFailed() { + Log.w(CarLog.TAG_INPUT, "Failed to show VoiceInteractionSession"); + } + + @Override + public void onShown() { + if (DBG) { + Log.d(CarLog.TAG_INPUT, "IVoiceInteractionSessionShowCallback onShown()"); + } + } + }; + private static final boolean DBG = false; + private static final String EXTRA_CAR_PUSH_TO_TALK = + "com.android.car.input.EXTRA_CAR_PUSH_TO_TALK"; private final Context mContext; private final InputHalService mInputHalService; private final TelecomManager mTelecomManager; private final InputManager mInputManager; + private final AssistUtils mAssistUtils; private KeyEventListener mVoiceAssistantKeyListener; private KeyEventListener mLongVoiceAssistantKeyListener; @@ -153,6 +172,7 @@ public class CarInputService implements CarServiceBase, InputHalService.InputLis mInputHalService = inputHalService; mTelecomManager = context.getSystemService(TelecomManager.class); mInputManager = context.getSystemService(InputManager.class); + mAssistUtils = new AssistUtils(context); } private synchronized void setHandledKeys(InputFilter[] handledKeys) { @@ -324,10 +344,18 @@ public class CarInputService implements CarServiceBase, InputHalService.InputLis } private void launchDefaultVoiceAssistantHandler() { - Log.i(CarLog.TAG_INPUT, "voice key, launch default intent"); - Intent voiceIntent = - new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE); - mContext.startActivityAsUser(voiceIntent, null, UserHandle.CURRENT_OR_SELF); + Log.i(CarLog.TAG_INPUT, "voice key, invoke AssistUtils"); + + if (mAssistUtils.getAssistComponentForUser(ActivityManager.getCurrentUser()) == null) { + Log.w(CarLog.TAG_INPUT, "Unable to retrieve assist component for current user"); + return; + } + + final Bundle args = new Bundle(); + args.putBoolean(EXTRA_CAR_PUSH_TO_TALK, true); + + mAssistUtils.showSessionForActiveService(args, + SHOW_SOURCE_ASSIST_GESTURE, mShowCallback, null /*activityToken*/); } private void handleInstrumentClusterKey(KeyEvent event) { |