Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1fc2a17b authored by Andy Wickham's avatar Andy Wickham
Browse files

Adds Contextual Search calling package name.

This is mostly useful for the self-invocation API, so the
designated ContextualSearch app can see which app invoked them.

Bug: 368653769
Test: Build and flash, invoke with SupportApp
Flag: android.app.contextualsearch.flags.self_invocation
Change-Id: I41c111f540c9f93c3bc989014faef8c5024090a0
parent 9e89253e
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -313,7 +313,8 @@ public class ContextualSearchManagerService extends SystemService {
            android.Manifest.permission.CREATE_USERS,
            android.Manifest.permission.QUERY_USERS
    })
    private Intent getContextualSearchIntent(int entrypoint, int userId, CallbackToken mToken) {
    private Intent getContextualSearchIntent(int entrypoint, int userId, String callingPackage,
            CallbackToken mToken) {
        final Intent launchIntent = getResolvedLaunchIntent(userId);
        if (launchIntent == null) {
            if (DEBUG) Log.w(TAG, "Failed getContextualSearchIntent: launchIntent is null");
@@ -332,6 +333,9 @@ public class ContextualSearchManagerService extends SystemService {
            launchIntent.putExtra(ContextualSearchManager.EXTRA_IS_AUDIO_PLAYING,
                    mAudioManager.isMusicActive());
        }
        if (Flags.selfInvocation()) {
            launchIntent.putExtra(Intent.EXTRA_CALLING_PACKAGE, callingPackage);
        }
        boolean isAssistDataAllowed = mAtmInternal.isAssistDataAllowed();
        final List<ActivityAssistInfo> records = mAtmInternal.getTopVisibleActivities();
        final List<IBinder> activityTokens = new ArrayList<>(records.size());
@@ -500,6 +504,7 @@ public class ContextualSearchManagerService extends SystemService {
        }

        private void startContextualSearchInternal(int entrypoint) {
            final String callingPackage = mPackageManager.getNameForUid(Binder.getCallingUid());
            final int callingUserId = Binder.getCallingUserHandle().getIdentifier();
            mAssistDataRequester.cancel();
            // Creates a new CallbackToken at mToken and an expiration handler.
@@ -508,7 +513,8 @@ public class ContextualSearchManagerService extends SystemService {
            // server has READ_FRAME_BUFFER permission to get the screenshot and because only
            // the system server can invoke non-exported activities.
            Binder.withCleanCallingIdentity(() -> {
                Intent launchIntent = getContextualSearchIntent(entrypoint, callingUserId, mToken);
                Intent launchIntent = getContextualSearchIntent(entrypoint, callingUserId,
                            callingPackage, mToken);
                if (launchIntent != null) {
                    int result = invokeContextualSearchIntent(launchIntent, callingUserId);
                    if (DEBUG) {