Merge "Make Changes to VoiceInteraction API for supporting System checking an assistant voice action availability on AAE."
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package android.service.voice;
|
||||
|
||||
import com.android.internal.app.IVoiceActionCheckCallback;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
@@ -24,4 +26,6 @@ oneway interface IVoiceInteractionService {
|
||||
void soundModelsChanged();
|
||||
void shutdown();
|
||||
void launchVoiceAssistFromKeyguard();
|
||||
void getActiveServiceSupportedActions(in List<String> voiceActions,
|
||||
in IVoiceActionCheckCallback callback);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package android.service.voice;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.SdkConstant;
|
||||
import android.annotation.UnsupportedAppUsage;
|
||||
import android.app.Service;
|
||||
@@ -26,17 +28,22 @@ import android.hardware.soundtrigger.KeyphraseEnrollmentInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.provider.Settings;
|
||||
import android.util.ArraySet;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.app.IVoiceActionCheckCallback;
|
||||
import com.android.internal.app.IVoiceInteractionManagerService;
|
||||
import com.android.internal.util.function.pooled.PooledLambda;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Top-level service of the current global voice interactor, which is providing
|
||||
@@ -71,23 +78,43 @@ public class VoiceInteractionService extends Service {
|
||||
public static final String SERVICE_META_DATA = "android.voice_interaction";
|
||||
|
||||
IVoiceInteractionService mInterface = new IVoiceInteractionService.Stub() {
|
||||
@Override public void ready() {
|
||||
mHandler.sendEmptyMessage(MSG_READY);
|
||||
}
|
||||
@Override public void shutdown() {
|
||||
mHandler.sendEmptyMessage(MSG_SHUTDOWN);
|
||||
}
|
||||
@Override public void soundModelsChanged() {
|
||||
mHandler.sendEmptyMessage(MSG_SOUND_MODELS_CHANGED);
|
||||
}
|
||||
@Override
|
||||
public void launchVoiceAssistFromKeyguard() throws RemoteException {
|
||||
mHandler.sendEmptyMessage(MSG_LAUNCH_VOICE_ASSIST_FROM_KEYGUARD);
|
||||
public void ready() {
|
||||
Handler.getMain().executeOrSendMessage(PooledLambda.obtainMessage(
|
||||
VoiceInteractionService::onReady, VoiceInteractionService.this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
Handler.getMain().executeOrSendMessage(PooledLambda.obtainMessage(
|
||||
VoiceInteractionService::onShutdownInternal, VoiceInteractionService.this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void soundModelsChanged() {
|
||||
Handler.getMain().executeOrSendMessage(PooledLambda.obtainMessage(
|
||||
VoiceInteractionService::onSoundModelsChangedInternal,
|
||||
VoiceInteractionService.this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launchVoiceAssistFromKeyguard() {
|
||||
Handler.getMain().executeOrSendMessage(PooledLambda.obtainMessage(
|
||||
VoiceInteractionService::onLaunchVoiceAssistFromKeyguard,
|
||||
VoiceInteractionService.this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getActiveServiceSupportedActions(List<String> voiceActions,
|
||||
IVoiceActionCheckCallback callback) {
|
||||
Handler.getMain().executeOrSendMessage(
|
||||
PooledLambda.obtainMessage(VoiceInteractionService::onHandleVoiceActionCheck,
|
||||
VoiceInteractionService.this,
|
||||
voiceActions,
|
||||
callback));
|
||||
}
|
||||
};
|
||||
|
||||
MyHandler mHandler;
|
||||
|
||||
IVoiceInteractionManagerService mSystemService;
|
||||
|
||||
private final Object mLock = new Object();
|
||||
@@ -96,33 +123,6 @@ public class VoiceInteractionService extends Service {
|
||||
|
||||
private AlwaysOnHotwordDetector mHotwordDetector;
|
||||
|
||||
static final int MSG_READY = 1;
|
||||
static final int MSG_SHUTDOWN = 2;
|
||||
static final int MSG_SOUND_MODELS_CHANGED = 3;
|
||||
static final int MSG_LAUNCH_VOICE_ASSIST_FROM_KEYGUARD = 4;
|
||||
|
||||
class MyHandler extends Handler {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case MSG_READY:
|
||||
onReady();
|
||||
break;
|
||||
case MSG_SHUTDOWN:
|
||||
onShutdownInternal();
|
||||
break;
|
||||
case MSG_SOUND_MODELS_CHANGED:
|
||||
onSoundModelsChangedInternal();
|
||||
break;
|
||||
case MSG_LAUNCH_VOICE_ASSIST_FROM_KEYGUARD:
|
||||
onLaunchVoiceAssistFromKeyguard();
|
||||
break;
|
||||
default:
|
||||
super.handleMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a user has activated an affordance to launch voice assist from the Keyguard.
|
||||
*
|
||||
@@ -186,7 +186,7 @@ public class VoiceInteractionService extends Service {
|
||||
* be any combination of
|
||||
* {@link VoiceInteractionSession#SHOW_WITH_ASSIST VoiceInteractionSession.SHOW_WITH_ASSIST} and
|
||||
* {@link VoiceInteractionSession#SHOW_WITH_SCREENSHOT
|
||||
* VoiceInteractionSession.SHOW_WITH_SCREENSHOT}
|
||||
* VoiceInteractionSession.SHOW_WITH_SCREENSHOT}
|
||||
* to request that the system generate and deliver assist data on the current foreground
|
||||
* app as part of showing the session UI.
|
||||
*/
|
||||
@@ -200,10 +200,22 @@ public class VoiceInteractionService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
mHandler = new MyHandler();
|
||||
/**
|
||||
* Request to query for what extended voice actions this service supports. This method will
|
||||
* be called when the system checks the supported actions of this
|
||||
* {@link VoiceInteractionService}. Supported actions may be delivered to
|
||||
* {@link VoiceInteractionSession} later to request a session to perform an action.
|
||||
*
|
||||
* <p>Voice actions are defined in support libraries and could vary based on platform context.
|
||||
* For example, car related voice actions will be defined in car support libraries.
|
||||
*
|
||||
* @param voiceActions A set of checked voice actions.
|
||||
* @return Returns a subset of checked voice actions. Additional voice actions in the
|
||||
* returned set will be ignored. Returns null or empty set if no actions are supported.
|
||||
*/
|
||||
@Nullable
|
||||
public Set<String> onGetSupportedVoiceActions(@NonNull Set<String> voiceActions) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -254,6 +266,18 @@ public class VoiceInteractionService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private void onHandleVoiceActionCheck(List<String> voiceActions,
|
||||
IVoiceActionCheckCallback callback) {
|
||||
if (callback != null) {
|
||||
try {
|
||||
Set<String> voiceActionsSet = new ArraySet<>(voiceActions);
|
||||
Set<String> resultSet = onGetSupportedVoiceActions(voiceActionsSet);
|
||||
callback.onComplete(resultSet == null ? null : new ArrayList<>(resultSet));
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@link AlwaysOnHotwordDetector} for the given keyphrase and locale.
|
||||
* This instance must be retained and used by the client.
|
||||
@@ -289,12 +313,12 @@ public class VoiceInteractionService extends Service {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given keyphrase and locale are supported to create an
|
||||
* {@link AlwaysOnHotwordDetector}.
|
||||
*
|
||||
* @return true if the keyphrase and locale combination is supported, false otherwise.
|
||||
* @hide
|
||||
*/
|
||||
* Checks if a given keyphrase and locale are supported to create an
|
||||
* {@link AlwaysOnHotwordDetector}.
|
||||
*
|
||||
* @return true if the keyphrase and locale combination is supported, false otherwise.
|
||||
* @hide
|
||||
*/
|
||||
@UnsupportedAppUsage
|
||||
public final boolean isKeyphraseAndLocaleSupportedForHotword(String keyphrase, Locale locale) {
|
||||
if (mKeyphraseEnrollmentInfo == null) {
|
||||
|
||||
Reference in New Issue
Block a user