Merge "Grant client app visibility with UID from activity record" into tm-dev am: 7a1dd2e61c

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

Change-Id: If6735ff596faa17d4576cf2181a41b8bdb1361fc
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Jack Wang
2022-06-06 18:17:43 +00:00
committed by Automerger Merge Worker
4 changed files with 34 additions and 36 deletions

View File

@@ -338,14 +338,16 @@ public abstract class ActivityTaskManagerInternal {
private final @NonNull IBinder mAssistToken; private final @NonNull IBinder mAssistToken;
private final @NonNull IBinder mShareableActivityToken; private final @NonNull IBinder mShareableActivityToken;
private final @NonNull IApplicationThread mAppThread; private final @NonNull IApplicationThread mAppThread;
private final int mUid;
public ActivityTokens(@NonNull IBinder activityToken, public ActivityTokens(@NonNull IBinder activityToken,
@NonNull IBinder assistToken, @NonNull IApplicationThread appThread, @NonNull IBinder assistToken, @NonNull IApplicationThread appThread,
@NonNull IBinder shareableActivityToken) { @NonNull IBinder shareableActivityToken, int uid) {
mActivityToken = activityToken; mActivityToken = activityToken;
mAssistToken = assistToken; mAssistToken = assistToken;
mAppThread = appThread; mAppThread = appThread;
mShareableActivityToken = shareableActivityToken; mShareableActivityToken = shareableActivityToken;
mUid = uid;
} }
/** /**
@@ -375,6 +377,13 @@ public abstract class ActivityTaskManagerInternal {
public @NonNull IApplicationThread getApplicationThread() { public @NonNull IApplicationThread getApplicationThread() {
return mAppThread; return mAppThread;
} }
/**
* @return The UID of the activity
*/
public int getUid() {
return mUid;
}
} }
public abstract void sendActivityResult(int callingUid, IBinder activityToken, public abstract void sendActivityResult(int callingUid, IBinder activityToken,

View File

@@ -5820,14 +5820,16 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
if (token == null && list.get(0).attachedToProcess()) { if (token == null && list.get(0).attachedToProcess()) {
ActivityRecord topRecord = list.get(0); ActivityRecord topRecord = list.get(0);
return new ActivityTokens(topRecord.token, topRecord.assistToken, return new ActivityTokens(topRecord.token, topRecord.assistToken,
topRecord.app.getThread(), topRecord.shareableActivityToken); topRecord.app.getThread(), topRecord.shareableActivityToken,
topRecord.getUid());
} }
// find the expected Activity // find the expected Activity
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
ActivityRecord record = list.get(i); ActivityRecord record = list.get(i);
if (record.shareableActivityToken == token && record.attachedToProcess()) { if (record.shareableActivityToken == token && record.attachedToProcess()) {
return new ActivityTokens(record.token, record.assistToken, return new ActivityTokens(record.token, record.assistToken,
record.app.getThread(), record.shareableActivityToken); record.app.getThread(), record.shareableActivityToken,
record.getUid());
} }
} }
return null; return null;

View File

@@ -35,7 +35,6 @@ 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;
@@ -105,7 +104,6 @@ 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;
@@ -128,7 +126,6 @@ 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;
@@ -149,8 +146,6 @@ 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);
@@ -374,21 +369,6 @@ 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();
@@ -419,9 +399,10 @@ public class VoiceInteractionManagerService extends SystemService {
@Override @Override
public void onShown() { public void onShown() {
synchronized (VoiceInteractionManagerServiceStub.this) { synchronized (VoiceInteractionManagerServiceStub.this) {
VoiceInteractionManagerServiceStub.this if (mImpl != null) {
.grantImplicitAccessLocked(callingUid, mImpl.grantImplicitAccessLocked(callingUid,
/* intent= */ null); /* intent= */ null);
}
} }
mAtmInternal.onLocalVoiceInteractionStarted(token, mAtmInternal.onLocalVoiceInteractionStarted(token,
mImpl.mActiveSession.mSession, mImpl.mActiveSession.mSession,
@@ -995,7 +976,7 @@ public class VoiceInteractionManagerService extends SystemService {
mContext.getPackageManager(), PackageManager.MATCH_ALL); mContext.getPackageManager(), PackageManager.MATCH_ALL);
if (activityInfo != null) { if (activityInfo != null) {
final int activityUid = activityInfo.applicationInfo.uid; final int activityUid = activityInfo.applicationInfo.uid;
grantImplicitAccessLocked(activityUid, intent); mImpl.grantImplicitAccessLocked(activityUid, intent);
} else { } else {
Slog.w(TAG, "Cannot find ActivityInfo in startVoiceActivity."); Slog.w(TAG, "Cannot find ActivityInfo in startVoiceActivity.");
} }
@@ -1039,15 +1020,6 @@ 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 {

View File

@@ -39,6 +39,7 @@ import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.ParceledListSlice; import android.content.pm.ParceledListSlice;
import android.content.pm.ServiceInfo; import android.content.pm.ServiceInfo;
import android.hardware.soundtrigger.IRecognitionStatusCallback; import android.hardware.soundtrigger.IRecognitionStatusCallback;
@@ -80,6 +81,7 @@ import java.io.FileDescriptor;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConnection.Callback { class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConnection.Callback {
final static String TAG = "VoiceInteractionServiceManager"; final static String TAG = "VoiceInteractionServiceManager";
@@ -100,6 +102,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
final ComponentName mComponent; final ComponentName mComponent;
final IActivityManager mAm; final IActivityManager mAm;
final IActivityTaskManager mAtm; final IActivityTaskManager mAtm;
final PackageManagerInternal mPackageManagerInternal;
final VoiceInteractionServiceInfo mInfo; final VoiceInteractionServiceInfo mInfo;
final ComponentName mSessionComponentName; final ComponentName mSessionComponentName;
final IWindowManager mIWindowManager; final IWindowManager mIWindowManager;
@@ -195,6 +198,8 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
mComponent = service; mComponent = service;
mAm = ActivityManager.getService(); mAm = ActivityManager.getService();
mAtm = ActivityTaskManager.getService(); mAtm = ActivityTaskManager.getService();
mPackageManagerInternal = Objects.requireNonNull(
LocalServices.getService(PackageManagerInternal.class));
VoiceInteractionServiceInfo info; VoiceInteractionServiceInfo info;
try { try {
info = new VoiceInteractionServiceInfo(context.getPackageManager(), service, mUser); info = new VoiceInteractionServiceInfo(context.getPackageManager(), service, mUser);
@@ -230,6 +235,15 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
Context.RECEIVER_EXPORTED); Context.RECEIVER_EXPORTED);
} }
public void grantImplicitAccessLocked(int grantRecipientUid, @Nullable Intent intent) {
final int grantRecipientAppId = UserHandle.getAppId(grantRecipientUid);
final int grantRecipientUserId = UserHandle.getUserId(grantRecipientUid);
final int voiceInteractionUid = mInfo.getServiceInfo().applicationInfo.uid;
mPackageManagerInternal.grantImplicitAccess(
grantRecipientUserId, intent, grantRecipientAppId, voiceInteractionUid,
/* direct= */ true);
}
public boolean showSessionLocked(Bundle args, int flags, public boolean showSessionLocked(Bundle args, int flags,
IVoiceInteractionSessionShowCallback showCallback, IBinder activityToken) { IVoiceInteractionSessionShowCallback showCallback, IBinder activityToken) {
if (mActiveSession == null) { if (mActiveSession == null) {
@@ -354,6 +368,7 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
VoiceInteractionManagerServiceImpl.this, token, taskId, assistToken, VoiceInteractionManagerServiceImpl.this, token, taskId, assistToken,
cancellationCallback, callback), REQUEST_DIRECT_ACTIONS_RETRY_TIME_MS); cancellationCallback, callback), REQUEST_DIRECT_ACTIONS_RETRY_TIME_MS);
} else { } else {
grantImplicitAccessLocked(tokens.getUid(), /* intent= */ null);
try { try {
tokens.getApplicationThread().requestDirectActions(tokens.getActivityToken(), tokens.getApplicationThread().requestDirectActions(tokens.getActivityToken(),
mActiveSession.mInteractor, cancellationCallback, callback); mActiveSession.mInteractor, cancellationCallback, callback);