Merge "Enable a shortcut selection test." into tm-qpr-dev am: 36e32b3884 am: 14391d46c7
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19921604 Change-Id: I0a9b806c7680a00537caee8e5c1212011e6f87a2 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -2096,7 +2096,8 @@ public class ChooserActivity extends ResolverActivity implements
|
||||
return matchingShortcuts;
|
||||
}
|
||||
|
||||
private void sendShortcutManagerShareTargetResults(
|
||||
@VisibleForTesting
|
||||
protected void sendShortcutManagerShareTargetResults(
|
||||
int shortcutType, ServiceResultInfo[] results) {
|
||||
final Message msg = Message.obtain();
|
||||
msg.what = ChooserHandler.SHORTCUT_MANAGER_ALL_SHARE_TARGET_RESULTS;
|
||||
@@ -3873,7 +3874,11 @@ public class ChooserActivity extends ResolverActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
static class ServiceResultInfo {
|
||||
/**
|
||||
* Shortcuts grouped by application.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public static class ServiceResultInfo {
|
||||
public final DisplayResolveInfo originalTarget;
|
||||
public final List<ChooserTarget> resultTargets;
|
||||
public final UserHandle userHandle;
|
||||
|
||||
@@ -24,11 +24,13 @@ import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.internal.app.chooser.TargetInfo;
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
@@ -50,6 +52,9 @@ public class ChooserActivityOverrideData {
|
||||
public Function<PackageManager, PackageManager> createPackageManager;
|
||||
public Function<TargetInfo, Boolean> onSafelyStartCallback;
|
||||
public Function<ChooserListAdapter, Void> onQueryDirectShareTargets;
|
||||
public BiFunction<
|
||||
IChooserWrapper, ChooserListAdapter, Pair<Integer, ChooserActivity.ServiceResultInfo[]>>
|
||||
directShareTargets;
|
||||
public ResolverListController resolverListController;
|
||||
public ResolverListController workResolverListController;
|
||||
public Boolean isVoiceInteraction;
|
||||
@@ -72,6 +77,7 @@ public class ChooserActivityOverrideData {
|
||||
public void reset() {
|
||||
onSafelyStartCallback = null;
|
||||
onQueryDirectShareTargets = null;
|
||||
directShareTargets = null;
|
||||
isVoiceInteraction = null;
|
||||
createPackageManager = null;
|
||||
previewThumbnail = null;
|
||||
@@ -112,4 +118,3 @@ public class ChooserActivityOverrideData {
|
||||
|
||||
private ChooserActivityOverrideData() {}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ import android.net.Uri;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.service.chooser.ChooserTarget;
|
||||
import android.util.Pair;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.CallSuper;
|
||||
@@ -89,6 +90,7 @@ import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.app.ChooserActivity.ServiceResultInfo;
|
||||
import com.android.internal.app.ResolverActivity.ResolvedComponentInfo;
|
||||
import com.android.internal.app.chooser.DisplayResolveInfo;
|
||||
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
|
||||
@@ -2166,8 +2168,8 @@ public class ChooserActivityTest {
|
||||
assertThat(logger.numCalls(), is(6));
|
||||
}
|
||||
|
||||
@Test @Ignore
|
||||
public void testDirectTargetLogging() throws InterruptedException {
|
||||
@Test
|
||||
public void testDirectTargetLogging() {
|
||||
Intent sendIntent = createSendTextIntent();
|
||||
// We need app targets for direct targets to get displayed
|
||||
List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2);
|
||||
@@ -2187,30 +2189,35 @@ public class ChooserActivityTest {
|
||||
resolvedComponentInfos.get(0).getResolveInfoAt(0).activityInfo.packageName);
|
||||
ResolveInfo ri = ResolverDataProvider.createResolveInfo(3, 0);
|
||||
|
||||
ChooserActivityOverrideData
|
||||
.getInstance()
|
||||
.directShareTargets = (activity, adapter) -> {
|
||||
DisplayResolveInfo displayInfo = activity.createTestDisplayResolveInfo(
|
||||
sendIntent,
|
||||
ri,
|
||||
"testLabel",
|
||||
"testInfo",
|
||||
sendIntent,
|
||||
/* resolveInfoPresentationGetter */ null);
|
||||
ServiceResultInfo[] results = {
|
||||
new ServiceResultInfo(
|
||||
displayInfo,
|
||||
serviceTargets,
|
||||
adapter.getUserHandle())};
|
||||
// TODO: consider covering the other type.
|
||||
// Only 2 types are expected out of the shortcut loading logic:
|
||||
// - TARGET_TYPE_SHORTCUTS_FROM_SHORTCUT_MANAGER, if shortcuts were loaded from
|
||||
// the ShortcutManager, and;
|
||||
// - TARGET_TYPE_SHORTCUTS_FROM_PREDICTION_SERVICE, if shortcuts were loaded
|
||||
// from AppPredictor.
|
||||
// Ideally, our tests should cover all of them.
|
||||
return new Pair<>(TARGET_TYPE_SHORTCUTS_FROM_SHORTCUT_MANAGER, results);
|
||||
};
|
||||
|
||||
// Start activity
|
||||
final IChooserWrapper activity = (IChooserWrapper)
|
||||
mActivityRule.launchActivity(Intent.createChooser(sendIntent, null));
|
||||
|
||||
// Insert the direct share target
|
||||
Map<ChooserTarget, ShortcutInfo> directShareToShortcutInfos = new HashMap<>();
|
||||
directShareToShortcutInfos.put(serviceTargets.get(0), null);
|
||||
InstrumentationRegistry.getInstrumentation().runOnMainSync(
|
||||
() -> activity.getAdapter().addServiceResults(
|
||||
activity.createTestDisplayResolveInfo(sendIntent,
|
||||
ri,
|
||||
"testLabel",
|
||||
"testInfo",
|
||||
sendIntent,
|
||||
/* resolveInfoPresentationGetter */ null),
|
||||
serviceTargets,
|
||||
TARGET_TYPE_CHOOSER_TARGET,
|
||||
directShareToShortcutInfos)
|
||||
);
|
||||
// Thread.sleep shouldn't be a thing in an integration test but it's
|
||||
// necessary here because of the way the code is structured
|
||||
// TODO: restructure the tests b/129870719
|
||||
Thread.sleep(((ChooserActivity) activity).mListViewUpdateDelayMs);
|
||||
|
||||
assertThat("Chooser should have 3 targets (2 apps, 1 direct)",
|
||||
activity.getAdapter().getCount(), is(3));
|
||||
assertThat("Chooser should have exactly one selectable direct target",
|
||||
|
||||
@@ -31,6 +31,7 @@ import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Pair;
|
||||
import android.util.Size;
|
||||
|
||||
import com.android.internal.app.ResolverListAdapter.ResolveInfoPresentationGetter;
|
||||
@@ -239,6 +240,12 @@ public class ChooserWrapperActivity extends ChooserActivity implements IChooserW
|
||||
@Override
|
||||
protected void queryDirectShareTargets(ChooserListAdapter adapter,
|
||||
boolean skipAppPredictionService) {
|
||||
if (sOverrides.directShareTargets != null) {
|
||||
Pair<Integer, ServiceResultInfo[]> result =
|
||||
sOverrides.directShareTargets.apply(this, adapter);
|
||||
sendShortcutManagerShareTargetResults(result.first, result.second);
|
||||
return;
|
||||
}
|
||||
if (sOverrides.onQueryDirectShareTargets != null) {
|
||||
sOverrides.onQueryDirectShareTargets.apply(adapter);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user