From 0567baa76883b45b8a3376f4d906bf0f3a64f960 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Date: Tue, 6 Jun 2023 09:02:19 +0000 Subject: Fixes type resolving in ActivityManagerShellCommand - There are 2 reasons for this change 1. make it non-async, because the type may still be null while it's being used in the below codes 2. Ams.mimeTypeFilterAsync is now used only when the caller does not hold the permission. So replacing it with ContentResolver.getType - Also granting shell special permission to access all provider mime types. Bug: b/284407686 Test: The intended behavior was reproduced on local testing. Change-Id: I9add06ffe8c0e7c185f0947f0695be259513bd13 --- packages/Shell/AndroidManifest.xml | 2 ++ .../android/server/am/ActivityManagerShellCommand.java | 17 ++++------------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/packages/Shell/AndroidManifest.xml b/packages/Shell/AndroidManifest.xml index 43f98c38715d..56e0643b1e20 100644 --- a/packages/Shell/AndroidManifest.xml +++ b/packages/Shell/AndroidManifest.xml @@ -839,6 +839,8 @@ + + mimeType = new AtomicReference<>(intent.getType()); - - if (mimeType.get() == null && intent.getData() != null - && "content".equals(intent.getData().getScheme())) { - mInterface.getMimeTypeFilterAsync(intent.getData(), mUserId, - new RemoteCallback(result -> { - mimeType.set(result.getPairValue()); - })); - } + final String mimeType = intent.resolveType(mInternal.mContext); do { if (mStopOption) { @@ -627,7 +618,7 @@ final class ActivityManagerShellCommand extends ShellCommand { int userIdForQuery = mInternal.mUserController.handleIncomingUser( Binder.getCallingPid(), Binder.getCallingUid(), mUserId, false, ALLOW_NON_FULL, "ActivityManagerShellCommand", null); - List activities = mPm.queryIntentActivities(intent, mimeType.get(), + List activities = mPm.queryIntentActivities(intent, mimeType, 0, userIdForQuery).getList(); if (activities == null || activities.size() <= 0) { getErrPrintWriter().println("Error: Intent does not match any activities: " @@ -724,12 +715,12 @@ final class ActivityManagerShellCommand extends ShellCommand { } if (mWaitOption) { result = mInternal.startActivityAndWait(null, SHELL_PACKAGE_NAME, null, intent, - mimeType.get(), null, null, 0, mStartFlags, profilerInfo, + mimeType, null, null, 0, mStartFlags, profilerInfo, options != null ? options.toBundle() : null, mUserId); res = result.result; } else { res = mInternal.startActivityAsUserWithFeature(null, SHELL_PACKAGE_NAME, null, - intent, mimeType.get(), null, null, 0, mStartFlags, profilerInfo, + intent, mimeType, null, null, 0, mStartFlags, profilerInfo, options != null ? options.toBundle() : null, mUserId); } final long endTime = SystemClock.uptimeMillis(); -- cgit v1.2.3-59-g8ed1b