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:
committed by
Android (Google) Code Review
commit
334a082671
@@ -51,8 +51,6 @@ 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;
|
||||
@@ -106,7 +104,6 @@ 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<>();
|
||||
@@ -173,14 +170,6 @@ 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) {
|
||||
@@ -234,7 +223,6 @@ public class VoiceInteractionManagerService extends SystemService {
|
||||
new IVoiceInteractionSessionShowCallback.Stub() {
|
||||
@Override
|
||||
public void onFailed() {
|
||||
Slog.w(TAG, "startLocalVoiceInteraction() failed");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -283,10 +271,7 @@ public class VoiceInteractionManagerService extends SystemService {
|
||||
}
|
||||
|
||||
public void initForUser(int userHandle) {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "**************** initForUser user=" + userHandle
|
||||
+ ", allowInstantService=" + mAllowInstantService);
|
||||
}
|
||||
if (DEBUG) Slog.d(TAG, "**************** initForUser user=" + userHandle);
|
||||
String curInteractorStr = Settings.Secure.getStringForUser(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.VOICE_INTERACTION_SERVICE, userHandle);
|
||||
@@ -445,7 +430,6 @@ 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()) {
|
||||
@@ -482,8 +466,7 @@ public class VoiceInteractionManagerService extends SystemService {
|
||||
}
|
||||
if (hasComponent) {
|
||||
setImplLocked(new VoiceInteractionManagerServiceImpl(mContext,
|
||||
UiThread.getHandler(), this, mCurUser, serviceComponent,
|
||||
mAllowInstantService));
|
||||
UiThread.getHandler(), this, mCurUser, serviceComponent));
|
||||
mImpl.startLocked();
|
||||
} else {
|
||||
setImplLocked(null);
|
||||
@@ -1244,25 +1227,15 @@ 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) {
|
||||
|
||||
@@ -80,7 +80,6 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
|
||||
final VoiceInteractionServiceInfo mInfo;
|
||||
final ComponentName mSessionComponentName;
|
||||
final IWindowManager mIWindowManager;
|
||||
final boolean mAllowInstant;
|
||||
boolean mBound = false;
|
||||
IVoiceInteractionService mService;
|
||||
|
||||
@@ -126,7 +125,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
|
||||
|
||||
VoiceInteractionManagerServiceImpl(Context context, Handler handler,
|
||||
VoiceInteractionManagerService.VoiceInteractionManagerServiceStub stub,
|
||||
int userHandle, ComponentName service, boolean allowInstant) {
|
||||
int userHandle, ComponentName service) {
|
||||
mContext = context;
|
||||
mHandler = handler;
|
||||
mServiceStub = stub;
|
||||
@@ -134,7 +133,6 @@ 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 +167,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
|
||||
if (mActiveSession == null) {
|
||||
mActiveSession = new VoiceInteractionSessionConnection(mServiceStub,
|
||||
mSessionComponentName, mUser, mContext, this,
|
||||
mInfo.getServiceInfo().applicationInfo.uid, mHandler, mAllowInstant);
|
||||
mInfo.getServiceInfo().applicationInfo.uid, mHandler);
|
||||
}
|
||||
List<IBinder> activityTokens = null;
|
||||
if (activityToken != null) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,8 +138,7 @@ final class VoiceInteractionSessionConnection implements ServiceConnection,
|
||||
};
|
||||
|
||||
public VoiceInteractionSessionConnection(Object lock, ComponentName component, int user,
|
||||
Context context, Callback callback, int callingUid, Handler handler,
|
||||
boolean allowInstant) {
|
||||
Context context, Callback callback, int callingUid, Handler handler) {
|
||||
mLock = lock;
|
||||
mSessionComponentName = component;
|
||||
mUser = user;
|
||||
@@ -160,13 +159,10 @@ final class VoiceInteractionSessionConnection implements ServiceConnection,
|
||||
mPermissionOwner = permOwner;
|
||||
mBindIntent = new Intent(VoiceInteractionService.SERVICE_INTERFACE);
|
||||
mBindIntent.setComponent(mSessionComponentName);
|
||||
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));
|
||||
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));
|
||||
if (mBound) {
|
||||
try {
|
||||
mIWindowManager.addWindowToken(mToken, TYPE_VOICE_INTERACTION, DEFAULT_DISPLAY);
|
||||
|
||||
Reference in New Issue
Block a user