Allow shortcuts to be pinned by unbundled chooser

Originally ShareSheet was part of android system, so shortcuts pinned by
ShareSheet are pinned by the system process. Since we are moving
ShareSheet into a separate module, this means shortcuts should not be
pinned by the system process, but by unbundled chooser process, when
that module is enabled.

This CL change the package name that pins the shortcut to corresponding
package in respect to whether intent resolver module is enabled.

Bug: 258072921
Test: Steps to verify
1. Open Chrome, go to any website.
2. Click on the search box, click share to share the URL
3. Click on more to bring up system ShareSheet.
4. Long-press on a direct sharing shortcut, then pin the shortcut.
5. Verify the direct sharing shortcut is pinned in the share sheet.
6. adb shell pm enable --user 0 com.android.intentresolver/.ChooserActivity
7. repeat 1-5

Change-Id: Id7c5b9d7cb17aa0dc8e5293bba9de29f8197e182
This commit is contained in:
Pinyao Ting
2023-01-30 17:48:53 -08:00
parent a96800911c
commit 81d0988803
2 changed files with 15 additions and 5 deletions

View File

@@ -885,7 +885,12 @@ class ShortcutPackage extends ShortcutPackageItem {
* available ShareTarget definitions in this package.
*/
public List<ShortcutManager.ShareShortcutInfo> getMatchingShareTargets(
@NonNull IntentFilter filter) {
@NonNull final IntentFilter filter) {
return getMatchingShareTargets(filter, null);
}
List<ShortcutManager.ShareShortcutInfo> getMatchingShareTargets(
@NonNull final IntentFilter filter, @Nullable final String pkgName) {
synchronized (mLock) {
final List<ShareTargetInfo> matchedTargets = new ArrayList<>();
for (int i = 0; i < mShareTargets.size(); i++) {
@@ -909,8 +914,7 @@ class ShortcutPackage extends ShortcutPackageItem {
// included in the result
findAll(shortcuts, ShortcutInfo::isNonManifestVisible,
ShortcutInfo.CLONE_REMOVE_FOR_APP_PREDICTION,
mShortcutUser.mService.mContext.getPackageName(),
0, /*getPinnedByAnyLauncher=*/ false);
pkgName, 0, /*getPinnedByAnyLauncher=*/ false);
final List<ShortcutManager.ShareShortcutInfo> result = new ArrayList<>();
for (int i = 0; i < shortcuts.size(); i++) {
@@ -1108,7 +1112,7 @@ class ShortcutPackage extends ShortcutPackageItem {
// Now prepare to publish manifest shortcuts.
List<ShortcutInfo> newManifestShortcutList = null;
final int shareTargetSize;
int shareTargetSize = 0;
synchronized (mLock) {
try {
shareTargetSize = mShareTargets.size();

View File

@@ -2512,11 +2512,17 @@ public class ShortcutService extends IShortcutService.Stub {
}
enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APP_PREDICTIONS,
"getShareTargets");
final ComponentName chooser = injectChooserActivity();
final String pkg = (chooser != null
&& mPackageManagerInternal.getComponentEnabledSetting(chooser,
injectBinderCallingUid(), userId) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED)
? chooser.getPackageName() : mContext.getPackageName();
synchronized (mLock) {
throwIfUserLockedL(userId);
final List<ShortcutManager.ShareShortcutInfo> shortcutInfoList = new ArrayList<>();
final ShortcutUser user = getUserShortcutsLocked(userId);
user.forAllPackages(p -> shortcutInfoList.addAll(p.getMatchingShareTargets(filter)));
user.forAllPackages(p -> shortcutInfoList.addAll(
p.getMatchingShareTargets(filter, pkg)));
return new ParceledListSlice<>(shortcutInfoList);
}
}