Add a flag for calling old ChooserTargetService API & remove flags for Shortcuts.

This flag is temporary, just want to make sure we like the state of the world without these targets as we continue down this path.

Test: manual via adb: adb shell device_config get systemui share_use_service_targets false
Bug: 170144291
Change-Id: I8f1ef4b98e7068ff5ee7dbe12827ec4ec034e126
This commit is contained in:
Alison Cichowlas
2020-10-06 16:29:16 -04:00
parent 13f56b66b0
commit cef37d003a
4 changed files with 28 additions and 15 deletions

View File

@@ -1855,6 +1855,7 @@ public class ChooserActivity extends ResolverActivity implements
@VisibleForTesting
protected void queryTargetServices(ChooserListAdapter adapter) {
mQueriedTargetServicesTimeMs = System.currentTimeMillis();
Context selectedProfileContext = createContextAsUser(
@@ -1871,15 +1872,14 @@ public class ChooserActivity extends ResolverActivity implements
continue;
}
final ActivityInfo ai = dri.getResolveInfo().activityInfo;
if (ChooserFlags.USE_SHORTCUT_MANAGER_FOR_DIRECT_TARGETS
&& sm.hasShareTargets(ai.packageName)) {
if (sm.hasShareTargets(ai.packageName)) {
// Share targets will be queried from ShortcutManager
continue;
}
final Bundle md = ai.metaData;
final String serviceName = md != null ? convertServiceName(ai.packageName,
md.getString(ChooserTargetService.META_DATA_NAME)) : null;
if (serviceName != null) {
if (serviceName != null && ChooserFlags.USE_SERVICE_TARGETS_FOR_DIRECT_TARGETS) {
final ComponentName serviceComponent = new ComponentName(
ai.packageName, serviceName);
@@ -2883,8 +2883,7 @@ public class ChooserActivity extends ResolverActivity implements
return;
}
if (ChooserFlags.USE_SHORTCUT_MANAGER_FOR_DIRECT_TARGETS
|| ChooserFlags.USE_PREDICTION_MANAGER_FOR_DIRECT_TARGETS) {
if (ChooserFlags.USE_PREDICTION_MANAGER_FOR_DIRECT_TARGETS) {
if (DEBUG) {
Log.d(TAG, "querying direct share targets from ShortcutManager");
}

View File

@@ -17,22 +17,29 @@
package com.android.internal.app;
import android.app.prediction.AppPredictionManager;
import android.provider.DeviceConfig;
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
/**
* Common flags for {@link ChooserListAdapter} and {@link ChooserActivity}.
*/
public class ChooserFlags {
/**
* If set to true, use ShortcutManager to retrieve the matching direct share targets, instead of
* binding to every ChooserTargetService implementation.
*/
// TODO(b/121287573): Replace with a system flag (setprop?)
public static final boolean USE_SHORTCUT_MANAGER_FOR_DIRECT_TARGETS = true;
/**
* If {@link ChooserFlags#USE_SHORTCUT_MANAGER_FOR_DIRECT_TARGETS} and this is set to true,
* {@link AppPredictionManager} will be queried for direct share targets.
* Whether to use the deprecated {@link android.service.chooser.ChooserTargetService} API for
* direct share targets. If true, both CTS and Shortcuts will be used to find Direct Share
* targets. If false, only Shortcuts will be used.
*/
public static final boolean USE_SERVICE_TARGETS_FOR_DIRECT_TARGETS =
DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.SHARE_USE_SERVICE_TARGETS, true);
/**
* Whether to use {@link AppPredictionManager} to query for direct share targets (as opposed to
* talking directly to {@link android.content.pm.ShortcutManager}.
*/
// TODO(b/123089490): Replace with system flag
static final boolean USE_PREDICTION_MANAGER_FOR_DIRECT_TARGETS = true;
}

View File

@@ -38,7 +38,6 @@ import android.text.SpannableStringBuilder;
import android.util.Log;
import com.android.internal.app.ChooserActivity;
import com.android.internal.app.ChooserFlags;
import com.android.internal.app.ResolverActivity;
import com.android.internal.app.ResolverListAdapter.ActivityInfoPresentationGetter;
import com.android.internal.app.SimpleIconFactory;
@@ -147,7 +146,7 @@ public final class SelectableTargetInfo implements ChooserTargetInfo {
final Icon icon = target.getIcon();
if (icon != null) {
directShareIcon = icon.loadDrawable(mContext);
} else if (ChooserFlags.USE_SHORTCUT_MANAGER_FOR_DIRECT_TARGETS && shortcutInfo != null) {
} else if (shortcutInfo != null) {
LauncherApps launcherApps = (LauncherApps) mContext.getSystemService(
Context.LAUNCHER_APPS_SERVICE);
directShareIcon = launcherApps.getShortcutIconDrawable(shortcutInfo, 0);

View File

@@ -429,6 +429,14 @@ public final class SystemUiDeviceConfigFlags {
*/
public static final String BACK_GESTURE_ML_MODEL_THRESHOLD = "back_gesture_ml_model_threshold";
/**
* (boolean) Sharesheet - Whether to use the deprecated
* {@link android.service.chooser.ChooserTargetService} API for
* direct share targets. If true, both CTS and Shortcuts will be used to find Direct
* Share targets. If false, only Shortcuts will be used.
*/
public static final String SHARE_USE_SERVICE_TARGETS = "share_use_service_targets";
private SystemUiDeviceConfigFlags() {
}