Merge "Grant visibility of voice interaction to the client app" into tm-dev am: b92b97dd6d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17730109

Change-Id: I98fc38862aa3806fd5ba08035f4d29aa4b7f2d1d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Jack Wang
2022-05-25 00:06:14 +00:00
committed by Automerger Merge Worker

View File

@@ -35,6 +35,7 @@ import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager; import android.content.pm.IPackageManager;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo; import android.content.pm.ServiceInfo;
import android.content.pm.ShortcutServiceInternal; import android.content.pm.ShortcutServiceInternal;
@@ -104,6 +105,7 @@ import com.android.server.pm.permission.LegacyPermissionManagerInternal;
import com.android.server.soundtrigger.SoundTriggerInternal; import com.android.server.soundtrigger.SoundTriggerInternal;
import com.android.server.utils.TimingsTraceAndSlog; import com.android.server.utils.TimingsTraceAndSlog;
import com.android.server.wm.ActivityTaskManagerInternal; import com.android.server.wm.ActivityTaskManagerInternal;
import com.android.server.wm.ActivityTaskManagerInternal.ActivityTokens;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.PrintWriter; import java.io.PrintWriter;
@@ -126,6 +128,7 @@ public class VoiceInteractionManagerService extends SystemService {
final ActivityManagerInternal mAmInternal; final ActivityManagerInternal mAmInternal;
final ActivityTaskManagerInternal mAtmInternal; final ActivityTaskManagerInternal mAtmInternal;
final UserManagerInternal mUserManagerInternal; final UserManagerInternal mUserManagerInternal;
final PackageManagerInternal mPackageManagerInternal;
final ArrayMap<Integer, VoiceInteractionManagerServiceStub.SoundTriggerSession> final ArrayMap<Integer, VoiceInteractionManagerServiceStub.SoundTriggerSession>
mLoadedKeyphraseIds = new ArrayMap<>(); mLoadedKeyphraseIds = new ArrayMap<>();
ShortcutServiceInternal mShortcutServiceInternal; ShortcutServiceInternal mShortcutServiceInternal;
@@ -146,6 +149,8 @@ public class VoiceInteractionManagerService extends SystemService {
LocalServices.getService(ActivityTaskManagerInternal.class)); LocalServices.getService(ActivityTaskManagerInternal.class));
mUserManagerInternal = Objects.requireNonNull( mUserManagerInternal = Objects.requireNonNull(
LocalServices.getService(UserManagerInternal.class)); LocalServices.getService(UserManagerInternal.class));
mPackageManagerInternal = Objects.requireNonNull(
LocalServices.getService(PackageManagerInternal.class));
LegacyPermissionManagerInternal permissionManagerInternal = LocalServices.getService( LegacyPermissionManagerInternal permissionManagerInternal = LocalServices.getService(
LegacyPermissionManagerInternal.class); LegacyPermissionManagerInternal.class);
@@ -369,6 +374,21 @@ public class VoiceInteractionManagerService extends SystemService {
return new SoundTriggerSessionBinderProxy(session); return new SoundTriggerSessionBinderProxy(session);
} }
@GuardedBy("this")
private void grantImplicitAccessLocked(int grantRecipientUid, @Nullable Intent intent) {
if (mImpl == null) {
Slog.w(TAG, "Cannot grant implicit access because mImpl is null.");
return;
}
final int grantRecipientAppId = UserHandle.getAppId(grantRecipientUid);
final int grantRecipientUserId = UserHandle.getUserId(grantRecipientUid);
final int voiceInteractionUid = mImpl.mInfo.getServiceInfo().applicationInfo.uid;
mPackageManagerInternal.grantImplicitAccess(
grantRecipientUserId, intent, grantRecipientAppId, voiceInteractionUid,
/* direct= */ true);
}
private IVoiceInteractionSoundTriggerSession createSoundTriggerSessionForSelfIdentity( private IVoiceInteractionSoundTriggerSession createSoundTriggerSessionForSelfIdentity(
IBinder client) { IBinder client) {
Identity identity = new Identity(); Identity identity = new Identity();
@@ -386,6 +406,7 @@ public class VoiceInteractionManagerService extends SystemService {
void startLocalVoiceInteraction(final IBinder token, Bundle options) { void startLocalVoiceInteraction(final IBinder token, Bundle options) {
if (mImpl == null) return; if (mImpl == null) return;
final int callingUid = Binder.getCallingUid();
final long caller = Binder.clearCallingIdentity(); final long caller = Binder.clearCallingIdentity();
try { try {
mImpl.showSessionLocked(options, mImpl.showSessionLocked(options,
@@ -397,6 +418,11 @@ public class VoiceInteractionManagerService extends SystemService {
@Override @Override
public void onShown() { public void onShown() {
synchronized (VoiceInteractionManagerServiceStub.this) {
VoiceInteractionManagerServiceStub.this
.grantImplicitAccessLocked(callingUid,
/* intent= */ null);
}
mAtmInternal.onLocalVoiceInteractionStarted(token, mAtmInternal.onLocalVoiceInteractionStarted(token,
mImpl.mActiveSession.mSession, mImpl.mActiveSession.mSession,
mImpl.mActiveSession.mInteractor); mImpl.mActiveSession.mInteractor);
@@ -965,8 +991,16 @@ public class VoiceInteractionManagerService extends SystemService {
final int callingUid = Binder.getCallingUid(); final int callingUid = Binder.getCallingUid();
final long caller = Binder.clearCallingIdentity(); final long caller = Binder.clearCallingIdentity();
try { try {
return mImpl.startVoiceActivityLocked(callingFeatureId, callingPid, callingUid, final ActivityInfo activityInfo = intent.resolveActivityInfo(
token, intent, resolvedType); mContext.getPackageManager(), PackageManager.MATCH_ALL);
if (activityInfo != null) {
final int activityUid = activityInfo.applicationInfo.uid;
grantImplicitAccessLocked(activityUid, intent);
} else {
Slog.w(TAG, "Cannot find ActivityInfo in startVoiceActivity.");
}
return mImpl.startVoiceActivityLocked(
callingFeatureId, callingPid, callingUid, token, intent, resolvedType);
} finally { } finally {
Binder.restoreCallingIdentity(caller); Binder.restoreCallingIdentity(caller);
} }
@@ -1005,6 +1039,15 @@ public class VoiceInteractionManagerService extends SystemService {
} }
final long caller = Binder.clearCallingIdentity(); final long caller = Binder.clearCallingIdentity();
try { try {
// Getting the UID corresponding to the taskId, and grant the visibility to it.
final ActivityTokens tokens = mAtmInternal
.getAttachedNonFinishingActivityForTask(taskId, /* token= */ null);
final ComponentName componentName = mAtmInternal.getActivityName(
tokens.getActivityToken());
grantImplicitAccessLocked(mPackageManagerInternal.getPackageUid(
componentName.getPackageName(), PackageManager.MATCH_ALL,
UserHandle.myUserId()), /* intent= */ null);
mImpl.requestDirectActionsLocked(token, taskId, assistToken, mImpl.requestDirectActionsLocked(token, taskId, assistToken,
cancellationCallback, resultCallback); cancellationCallback, resultCallback);
} finally { } finally {