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

Commit 8a09c7c0 authored by Mehdi Alizadeh's avatar Mehdi Alizadeh Committed by Android (Google) Code Review
Browse files

Merge "Filter disabled/suspended direct share targets in sharesheet" into qt-dev

parents 3893e5d9 3e3216f1
Loading
Loading
Loading
Loading
+34 −1
Original line number Diff line number Diff line
@@ -1434,6 +1434,22 @@ public class ChooserActivity extends ResolverActivity {
                List<ShortcutManager.ShareShortcutInfo> resultList,
                List<DisplayResolveInfo> driList,
                @Nullable List<AppTarget> appTargets) {
        if (appTargets != null && appTargets.size() != resultList.size()) {
            throw new RuntimeException("resultList and appTargets must have the same size."
                    + " resultList.size()=" + resultList.size()
                    + " appTargets.size()=" + appTargets.size());
        }

        for (int i = resultList.size() - 1; i >= 0; i--) {
            final String packageName = resultList.get(i).getTargetComponent().getPackageName();
            if (!isPackageEnabled(packageName)) {
                resultList.remove(i);
                if (appTargets != null) {
                    appTargets.remove(i);
                }
            }
        }

        // Match ShareShortcutInfos with DisplayResolveInfos to be able to use the old code path
        // for direct share targets. After ShareSheet is refactored we should use the
        // ShareShortcutInfos directly.
@@ -1447,7 +1463,6 @@ public class ChooserActivity extends ResolverActivity {
                    ChooserTarget chooserTarget = convertToChooserTarget(shareShortcutInfo);
                    chooserTargets.add(chooserTarget);
                    if (mDirectShareAppTargetCache != null && appTargets != null) {
                        // Note that appTargets.size() == resultList.size() is always true.
                        mDirectShareAppTargetCache.put(chooserTarget, appTargets.get(j));
                    }
                }
@@ -1473,6 +1488,24 @@ public class ChooserActivity extends ResolverActivity {
        mChooserHandler.sendMessage(msg);
    }

    private boolean isPackageEnabled(String packageName) {
        if (TextUtils.isEmpty(packageName)) {
            return false;
        }
        ApplicationInfo appInfo;
        try {
            appInfo = getPackageManager().getApplicationInfo(packageName, 0);
        } catch (NameNotFoundException e) {
            return false;
        }

        if (appInfo != null && appInfo.enabled
                && (appInfo.flags & ApplicationInfo.FLAG_SUSPENDED) == 0) {
            return true;
        }
        return false;
    }

    private ChooserTarget convertToChooserTarget(ShortcutManager.ShareShortcutInfo shareShortcut) {
        ShortcutInfo shortcutInfo = shareShortcut.getShortcutInfo();
        Bundle extras = new Bundle();