summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java31
-rw-r--r--services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java8
-rw-r--r--services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceShellCommand.java85
-rw-r--r--services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java14
4 files changed, 127 insertions, 11 deletions
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
index d77ea6e41cc2..55159c3f33f1 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
@@ -51,6 +51,8 @@ import android.os.Parcel;
import android.os.RemoteCallback;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
+import android.os.ResultReceiver;
+import android.os.ShellCallback;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
@@ -104,6 +106,7 @@ public class VoiceInteractionManagerService extends SystemService {
final ArraySet<Integer> mLoadedKeyphraseIds = new ArraySet<>();
ShortcutServiceInternal mShortcutServiceInternal;
SoundTriggerInternal mSoundTriggerInternal;
+ private boolean mAllowInstantService;
private final RemoteCallbackList<IVoiceInteractionSessionListener>
mVoiceInteractionSessionListeners = new RemoteCallbackList<>();
@@ -170,6 +173,14 @@ public class VoiceInteractionManagerService extends SystemService {
mServiceStub.switchUser(userHandle);
}
+ // Called by Shell cmd
+ void setAllowInstantService(boolean allowed) {
+ Log.i(TAG, "setAllowInstantService(): " + allowed);
+ mContext.enforceCallingPermission(Manifest.permission.MANAGE_BIND_INSTANT_SERVICE,
+ "setAllowInstantService");
+ mAllowInstantService = allowed;
+ }
+
class LocalService extends VoiceInteractionManagerInternal {
@Override
public void startLocalVoiceInteraction(IBinder callingActivity, Bundle options) {
@@ -223,6 +234,7 @@ public class VoiceInteractionManagerService extends SystemService {
new IVoiceInteractionSessionShowCallback.Stub() {
@Override
public void onFailed() {
+ Slog.w(TAG, "startLocalVoiceInteraction() failed");
}
@Override
@@ -271,7 +283,10 @@ public class VoiceInteractionManagerService extends SystemService {
}
public void initForUser(int userHandle) {
- if (DEBUG) Slog.d(TAG, "**************** initForUser user=" + userHandle);
+ if (DEBUG) {
+ Slog.d(TAG, "**************** initForUser user=" + userHandle
+ + ", allowInstantService=" + mAllowInstantService);
+ }
String curInteractorStr = Settings.Secure.getStringForUser(
mContext.getContentResolver(),
Settings.Secure.VOICE_INTERACTION_SERVICE, userHandle);
@@ -430,6 +445,7 @@ public class VoiceInteractionManagerService extends SystemService {
if (!mSafeMode) {
String curService = Settings.Secure.getStringForUser(
mResolver, Settings.Secure.VOICE_INTERACTION_SERVICE, mCurUser);
+ if (DEBUG) Log.d(TAG, "Service for user " + mCurUser + ": " + curService);
ComponentName serviceComponent = null;
ServiceInfo serviceInfo = null;
if (curService != null && !curService.isEmpty()) {
@@ -466,7 +482,8 @@ public class VoiceInteractionManagerService extends SystemService {
}
if (hasComponent) {
setImplLocked(new VoiceInteractionManagerServiceImpl(mContext,
- UiThread.getHandler(), this, mCurUser, serviceComponent));
+ UiThread.getHandler(), this, mCurUser, serviceComponent,
+ mAllowInstantService));
mImpl.startLocked();
} else {
setImplLocked(null);
@@ -1227,16 +1244,26 @@ public class VoiceInteractionManagerService extends SystemService {
synchronized (this) {
pw.println("VOICE INTERACTION MANAGER (dumpsys voiceinteraction)");
pw.println(" mEnableService: " + mEnableService);
+ pw.println(" mAllowInstantService: " + mAllowInstantService);
if (mImpl == null) {
pw.println(" (No active implementation)");
return;
}
mImpl.dumpLocked(fd, pw, args);
}
+
mSoundTriggerInternal.dump(fd, pw, args);
}
@Override
+ public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
+ String[] args, ShellCallback callback, ResultReceiver resultReceiver)
+ throws RemoteException {
+ new VoiceInteractionManagerServiceShellCommand(VoiceInteractionManagerService.this)
+ .exec(this, in, out, err, args, callback, resultReceiver);
+ }
+
+ @Override
public void setUiHints(IVoiceInteractionService service, Bundle hints) {
synchronized (this) {
enforceIsCurrentVoiceInteractionService(service);
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java
index 2a5b70bf77f2..4881ade954c1 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceImpl.java
@@ -29,7 +29,6 @@ import android.app.ActivityOptions;
import android.app.ActivityTaskManager;
import android.app.IActivityManager;
import android.app.IActivityTaskManager;
-import android.app.IApplicationThread;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@@ -48,7 +47,6 @@ import android.service.voice.IVoiceInteractionService;
import android.service.voice.IVoiceInteractionSession;
import android.service.voice.VoiceInteractionService;
import android.service.voice.VoiceInteractionServiceInfo;
-import android.util.Pair;
import android.util.PrintWriterPrinter;
import android.util.Slog;
import android.view.IWindowManager;
@@ -82,6 +80,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
final VoiceInteractionServiceInfo mInfo;
final ComponentName mSessionComponentName;
final IWindowManager mIWindowManager;
+ final boolean mAllowInstant;
boolean mBound = false;
IVoiceInteractionService mService;
@@ -127,7 +126,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
VoiceInteractionManagerServiceImpl(Context context, Handler handler,
VoiceInteractionManagerService.VoiceInteractionManagerServiceStub stub,
- int userHandle, ComponentName service) {
+ int userHandle, ComponentName service, boolean allowInstant) {
mContext = context;
mHandler = handler;
mServiceStub = stub;
@@ -135,6 +134,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
mComponent = service;
mAm = ActivityManager.getService();
mAtm = ActivityTaskManager.getService();
+ mAllowInstant = allowInstant;
VoiceInteractionServiceInfo info;
try {
info = new VoiceInteractionServiceInfo(context.getPackageManager(), service, mUser);
@@ -169,7 +169,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
if (mActiveSession == null) {
mActiveSession = new VoiceInteractionSessionConnection(mServiceStub,
mSessionComponentName, mUser, mContext, this,
- mInfo.getServiceInfo().applicationInfo.uid, mHandler);
+ mInfo.getServiceInfo().applicationInfo.uid, mHandler, mAllowInstant);
}
List<IBinder> activityTokens = null;
if (activityToken != null) {
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceShellCommand.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceShellCommand.java
new file mode 100644
index 000000000000..de1191fe842a
--- /dev/null
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerServiceShellCommand.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.server.voiceinteraction;
+
+import android.annotation.NonNull;
+import android.os.ShellCommand;
+
+import java.io.PrintWriter;
+
+final class VoiceInteractionManagerServiceShellCommand extends ShellCommand {
+
+ private final VoiceInteractionManagerService mService;
+
+ VoiceInteractionManagerServiceShellCommand(@NonNull VoiceInteractionManagerService service) {
+ this.mService = service;
+ }
+
+ @Override
+ public int onCommand(String cmd) {
+ if (cmd == null) {
+ return handleDefaultCommands(cmd);
+ }
+ final PrintWriter pw = getOutPrintWriter();
+ switch (cmd) {
+ case "set bind-instant-service-allowed":
+ case "set":
+ return requestSet(pw);
+ default:
+ return handleDefaultCommands(cmd);
+ }
+ }
+
+ @Override
+ public void onHelp() {
+ try (PrintWriter pw = getOutPrintWriter();) {
+ pw.println("VoiceInteraction Service (voiceinteraction) commands:");
+ pw.println(" help");
+ pw.println(" Prints this help text.");
+ pw.println("");
+ pw.println(" set bind-instant-service-allowed [true | false]");
+ pw.println(" Sets whether binding to services provided by instant apps is allowed");
+ pw.println("");
+ }
+ }
+
+ private int requestSet(@NonNull PrintWriter pw) {
+ final String what = getNextArgRequired();
+
+ switch(what) {
+ case "bind-instant-service-allowed":
+ return setBindInstantService(pw);
+ default:
+ pw.println("Invalid set: " + what);
+ return -1;
+ }
+ }
+
+ private int setBindInstantService(@NonNull PrintWriter pw) {
+ final String mode = getNextArgRequired();
+ switch (mode.toLowerCase()) {
+ case "true":
+ mService.setAllowInstantService(true);
+ return 0;
+ case "false":
+ mService.setAllowInstantService(false);
+ return 0;
+ default:
+ pw.println("Invalid mode: " + mode);
+ return -1;
+ }
+ }
+}
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java
index f16dec6fb670..3c470449dc2c 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java
@@ -138,7 +138,8 @@ final class VoiceInteractionSessionConnection implements ServiceConnection,
};
public VoiceInteractionSessionConnection(Object lock, ComponentName component, int user,
- Context context, Callback callback, int callingUid, Handler handler) {
+ Context context, Callback callback, int callingUid, Handler handler,
+ boolean allowInstant) {
mLock = lock;
mSessionComponentName = component;
mUser = user;
@@ -159,10 +160,13 @@ final class VoiceInteractionSessionConnection implements ServiceConnection,
mPermissionOwner = permOwner;
mBindIntent = new Intent(VoiceInteractionService.SERVICE_INTERFACE);
mBindIntent.setComponent(mSessionComponentName);
- mBound = mContext.bindServiceAsUser(mBindIntent, this,
- Context.BIND_AUTO_CREATE | Context.BIND_WAIVE_PRIORITY
- | Context.BIND_ALLOW_OOM_MANAGEMENT
- | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS, new UserHandle(mUser));
+ int flags = Context.BIND_AUTO_CREATE | Context.BIND_WAIVE_PRIORITY
+ | Context.BIND_ALLOW_OOM_MANAGEMENT
+ | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS;
+ if (allowInstant) {
+ flags |= Context.BIND_ALLOW_INSTANT;
+ }
+ mBound = mContext.bindServiceAsUser(mBindIntent, this, flags, new UserHandle(mUser));
if (mBound) {
try {
mIWindowManager.addWindowToken(mToken, TYPE_VOICE_INTERACTION, DEFAULT_DISPLAY);