Merge "Revert "Added a cmd to let system bind to a voice interaction service on instant apps."" into qt-dev

This commit is contained in:
TreeHugger Robot
2019-05-23 00:05:40 +00:00
committed by Android (Google) Code Review
4 changed files with 9 additions and 127 deletions

View File

@@ -51,8 +51,6 @@ import android.os.Parcel;
import android.os.RemoteCallback; import android.os.RemoteCallback;
import android.os.RemoteCallbackList; import android.os.RemoteCallbackList;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.ShellCallback;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.provider.Settings; import android.provider.Settings;
@@ -106,7 +104,6 @@ public class VoiceInteractionManagerService extends SystemService {
final ArraySet<Integer> mLoadedKeyphraseIds = new ArraySet<>(); final ArraySet<Integer> mLoadedKeyphraseIds = new ArraySet<>();
ShortcutServiceInternal mShortcutServiceInternal; ShortcutServiceInternal mShortcutServiceInternal;
SoundTriggerInternal mSoundTriggerInternal; SoundTriggerInternal mSoundTriggerInternal;
private boolean mAllowInstantService;
private final RemoteCallbackList<IVoiceInteractionSessionListener> private final RemoteCallbackList<IVoiceInteractionSessionListener>
mVoiceInteractionSessionListeners = new RemoteCallbackList<>(); mVoiceInteractionSessionListeners = new RemoteCallbackList<>();
@@ -173,14 +170,6 @@ public class VoiceInteractionManagerService extends SystemService {
mServiceStub.switchUser(userHandle); 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 { class LocalService extends VoiceInteractionManagerInternal {
@Override @Override
public void startLocalVoiceInteraction(IBinder callingActivity, Bundle options) { public void startLocalVoiceInteraction(IBinder callingActivity, Bundle options) {
@@ -234,7 +223,6 @@ public class VoiceInteractionManagerService extends SystemService {
new IVoiceInteractionSessionShowCallback.Stub() { new IVoiceInteractionSessionShowCallback.Stub() {
@Override @Override
public void onFailed() { public void onFailed() {
Slog.w(TAG, "startLocalVoiceInteraction() failed");
} }
@Override @Override
@@ -283,10 +271,7 @@ public class VoiceInteractionManagerService extends SystemService {
} }
public void initForUser(int userHandle) { public void initForUser(int userHandle) {
if (DEBUG) { if (DEBUG) Slog.d(TAG, "**************** initForUser user=" + userHandle);
Slog.d(TAG, "**************** initForUser user=" + userHandle
+ ", allowInstantService=" + mAllowInstantService);
}
String curInteractorStr = Settings.Secure.getStringForUser( String curInteractorStr = Settings.Secure.getStringForUser(
mContext.getContentResolver(), mContext.getContentResolver(),
Settings.Secure.VOICE_INTERACTION_SERVICE, userHandle); Settings.Secure.VOICE_INTERACTION_SERVICE, userHandle);
@@ -445,7 +430,6 @@ public class VoiceInteractionManagerService extends SystemService {
if (!mSafeMode) { if (!mSafeMode) {
String curService = Settings.Secure.getStringForUser( String curService = Settings.Secure.getStringForUser(
mResolver, Settings.Secure.VOICE_INTERACTION_SERVICE, mCurUser); mResolver, Settings.Secure.VOICE_INTERACTION_SERVICE, mCurUser);
if (DEBUG) Log.d(TAG, "Service for user " + mCurUser + ": " + curService);
ComponentName serviceComponent = null; ComponentName serviceComponent = null;
ServiceInfo serviceInfo = null; ServiceInfo serviceInfo = null;
if (curService != null && !curService.isEmpty()) { if (curService != null && !curService.isEmpty()) {
@@ -482,8 +466,7 @@ public class VoiceInteractionManagerService extends SystemService {
} }
if (hasComponent) { if (hasComponent) {
setImplLocked(new VoiceInteractionManagerServiceImpl(mContext, setImplLocked(new VoiceInteractionManagerServiceImpl(mContext,
UiThread.getHandler(), this, mCurUser, serviceComponent, UiThread.getHandler(), this, mCurUser, serviceComponent));
mAllowInstantService));
mImpl.startLocked(); mImpl.startLocked();
} else { } else {
setImplLocked(null); setImplLocked(null);
@@ -1244,25 +1227,15 @@ public class VoiceInteractionManagerService extends SystemService {
synchronized (this) { synchronized (this) {
pw.println("VOICE INTERACTION MANAGER (dumpsys voiceinteraction)"); pw.println("VOICE INTERACTION MANAGER (dumpsys voiceinteraction)");
pw.println(" mEnableService: " + mEnableService); pw.println(" mEnableService: " + mEnableService);
pw.println(" mAllowInstantService: " + mAllowInstantService);
if (mImpl == null) { if (mImpl == null) {
pw.println(" (No active implementation)"); pw.println(" (No active implementation)");
return; return;
} }
mImpl.dumpLocked(fd, pw, args); mImpl.dumpLocked(fd, pw, args);
} }
mSoundTriggerInternal.dump(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 @Override
public void setUiHints(IVoiceInteractionService service, Bundle hints) { public void setUiHints(IVoiceInteractionService service, Bundle hints) {
synchronized (this) { synchronized (this) {

View File

@@ -80,7 +80,6 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
final VoiceInteractionServiceInfo mInfo; final VoiceInteractionServiceInfo mInfo;
final ComponentName mSessionComponentName; final ComponentName mSessionComponentName;
final IWindowManager mIWindowManager; final IWindowManager mIWindowManager;
final boolean mAllowInstant;
boolean mBound = false; boolean mBound = false;
IVoiceInteractionService mService; IVoiceInteractionService mService;
@@ -126,7 +125,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
VoiceInteractionManagerServiceImpl(Context context, Handler handler, VoiceInteractionManagerServiceImpl(Context context, Handler handler,
VoiceInteractionManagerService.VoiceInteractionManagerServiceStub stub, VoiceInteractionManagerService.VoiceInteractionManagerServiceStub stub,
int userHandle, ComponentName service, boolean allowInstant) { int userHandle, ComponentName service) {
mContext = context; mContext = context;
mHandler = handler; mHandler = handler;
mServiceStub = stub; mServiceStub = stub;
@@ -134,7 +133,6 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
mComponent = service; mComponent = service;
mAm = ActivityManager.getService(); mAm = ActivityManager.getService();
mAtm = ActivityTaskManager.getService(); mAtm = ActivityTaskManager.getService();
mAllowInstant = allowInstant;
VoiceInteractionServiceInfo info; VoiceInteractionServiceInfo info;
try { try {
info = new VoiceInteractionServiceInfo(context.getPackageManager(), service, mUser); info = new VoiceInteractionServiceInfo(context.getPackageManager(), service, mUser);
@@ -169,7 +167,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
if (mActiveSession == null) { if (mActiveSession == null) {
mActiveSession = new VoiceInteractionSessionConnection(mServiceStub, mActiveSession = new VoiceInteractionSessionConnection(mServiceStub,
mSessionComponentName, mUser, mContext, this, mSessionComponentName, mUser, mContext, this,
mInfo.getServiceInfo().applicationInfo.uid, mHandler, mAllowInstant); mInfo.getServiceInfo().applicationInfo.uid, mHandler);
} }
List<IBinder> activityTokens = null; List<IBinder> activityTokens = null;
if (activityToken != null) { if (activityToken != null) {

View File

@@ -1,85 +0,0 @@
/*
* 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;
}
}
}

View File

@@ -138,8 +138,7 @@ final class VoiceInteractionSessionConnection implements ServiceConnection,
}; };
public VoiceInteractionSessionConnection(Object lock, ComponentName component, int user, 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; mLock = lock;
mSessionComponentName = component; mSessionComponentName = component;
mUser = user; mUser = user;
@@ -160,13 +159,10 @@ final class VoiceInteractionSessionConnection implements ServiceConnection,
mPermissionOwner = permOwner; mPermissionOwner = permOwner;
mBindIntent = new Intent(VoiceInteractionService.SERVICE_INTERFACE); mBindIntent = new Intent(VoiceInteractionService.SERVICE_INTERFACE);
mBindIntent.setComponent(mSessionComponentName); mBindIntent.setComponent(mSessionComponentName);
int flags = Context.BIND_AUTO_CREATE | Context.BIND_WAIVE_PRIORITY mBound = mContext.bindServiceAsUser(mBindIntent, this,
| Context.BIND_ALLOW_OOM_MANAGEMENT Context.BIND_AUTO_CREATE | Context.BIND_WAIVE_PRIORITY
| Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS; | Context.BIND_ALLOW_OOM_MANAGEMENT
if (allowInstant) { | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS, new UserHandle(mUser));
flags |= Context.BIND_ALLOW_INSTANT;
}
mBound = mContext.bindServiceAsUser(mBindIntent, this, flags, new UserHandle(mUser));
if (mBound) { if (mBound) {
try { try {
mIWindowManager.addWindowToken(mToken, TYPE_VOICE_INTERACTION, DEFAULT_DISPLAY); mIWindowManager.addWindowToken(mToken, TYPE_VOICE_INTERACTION, DEFAULT_DISPLAY);