Merge "Filter disabled/suspended direct share targets in sharesheet" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
8a09c7c0ae
@@ -1434,6 +1434,22 @@ public class ChooserActivity extends ResolverActivity {
|
|||||||
List<ShortcutManager.ShareShortcutInfo> resultList,
|
List<ShortcutManager.ShareShortcutInfo> resultList,
|
||||||
List<DisplayResolveInfo> driList,
|
List<DisplayResolveInfo> driList,
|
||||||
@Nullable List<AppTarget> appTargets) {
|
@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
|
// 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
|
// for direct share targets. After ShareSheet is refactored we should use the
|
||||||
// ShareShortcutInfos directly.
|
// ShareShortcutInfos directly.
|
||||||
@@ -1447,7 +1463,6 @@ public class ChooserActivity extends ResolverActivity {
|
|||||||
ChooserTarget chooserTarget = convertToChooserTarget(shareShortcutInfo);
|
ChooserTarget chooserTarget = convertToChooserTarget(shareShortcutInfo);
|
||||||
chooserTargets.add(chooserTarget);
|
chooserTargets.add(chooserTarget);
|
||||||
if (mDirectShareAppTargetCache != null && appTargets != null) {
|
if (mDirectShareAppTargetCache != null && appTargets != null) {
|
||||||
// Note that appTargets.size() == resultList.size() is always true.
|
|
||||||
mDirectShareAppTargetCache.put(chooserTarget, appTargets.get(j));
|
mDirectShareAppTargetCache.put(chooserTarget, appTargets.get(j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1473,6 +1488,24 @@ public class ChooserActivity extends ResolverActivity {
|
|||||||
mChooserHandler.sendMessage(msg);
|
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) {
|
private ChooserTarget convertToChooserTarget(ShortcutManager.ShareShortcutInfo shareShortcut) {
|
||||||
ShortcutInfo shortcutInfo = shareShortcut.getShortcutInfo();
|
ShortcutInfo shortcutInfo = shareShortcut.getShortcutInfo();
|
||||||
Bundle extras = new Bundle();
|
Bundle extras = new Bundle();
|
||||||
|
|||||||
Reference in New Issue
Block a user