From ccb3e7aa51cedff782a57caf80af2b0862b02009 Mon Sep 17 00:00:00 2001 From: Joshua Trask Date: Tue, 15 Mar 2022 18:40:21 -0400 Subject: [PATCH] DeviceConfig for Chooser update-delay duration. For more information, see go/sharesheet-list-view-update-delay. Bug: 224816815 Test: `atest ChooserActivityTest`. The duration can be manually configured by `adb shell device_config put systemui sharesheet_list_view_update_delay n` to set a delay of n milliseconds. With a timeout of 250 (as it was before this change), all the tests still pass. With a timeout of 0, all tests pass but one (as described in the doc linked above) -- a potential fix for that test will follow in a subsequent CL. Change-Id: Ia5edfe391b135659d2fd8126069c5cd6ce15653b --- .../android/internal/app/ChooserActivity.java | 12 ++++++++---- .../sysui/SystemUiDeviceConfigFlags.java | 7 +++++++ .../internal/app/ChooserActivityTest.java | 19 ++++++++++--------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index 70506ccaebb8e..2ea4142850584 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -220,9 +220,6 @@ public class ChooserActivity extends ResolverActivity implements private static final String PLURALS_COUNT = "count"; private static final String PLURALS_FILE_NAME = "file_name"; - @VisibleForTesting - public static final int LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS = 250; - private boolean mIsAppPredictorComponentAvailable; private Map mDirectShareAppTargetCache; private Map mDirectShareShortcutInfoCache; @@ -279,6 +276,13 @@ public class ChooserActivity extends ResolverActivity implements SystemUiDeviceConfigFlags.IS_NEARBY_SHARE_FIRST_TARGET_IN_RANKED_APP, DEFAULT_IS_NEARBY_SHARE_FIRST_TARGET_IN_RANKED_APP); + private static final int DEFAULT_LIST_VIEW_UPDATE_DELAY_MS = 250; + + @VisibleForTesting + int mListViewUpdateDelayMs = DeviceConfig.getInt(DeviceConfig.NAMESPACE_SYSTEMUI, + SystemUiDeviceConfigFlags.SHARESHEET_LIST_VIEW_UPDATE_DELAY, + DEFAULT_LIST_VIEW_UPDATE_DELAY_MS); + private Bundle mReplacementExtras; private IntentSender mChosenComponentSender; private IntentSender mRefinementIntentSender; @@ -2710,7 +2714,7 @@ public class ChooserActivity extends ResolverActivity implements Message msg = Message.obtain(); msg.what = ChooserHandler.LIST_VIEW_UPDATE_MESSAGE; msg.obj = userHandle; - mChooserHandler.sendMessageDelayed(msg, LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS); + mChooserHandler.sendMessageDelayed(msg, mListViewUpdateDelayMs); } @Override diff --git a/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java b/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java index 0ada13a73ad23..8e110792fae56 100644 --- a/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java +++ b/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java @@ -518,6 +518,13 @@ public final class SystemUiDeviceConfigFlags { */ public static final String USE_DELEGATE_CHOOSER = "use_delegate_chooser"; + /** + * (int) The delay (in ms) before refreshing the Sharesheet UI after a change to the share + * target data model. For more info see go/sharesheet-list-view-update-delay. + */ + public static final String SHARESHEET_LIST_VIEW_UPDATE_DELAY = + "sharesheet_list_view_update_delay"; + /** * (string) Name of the default QR code scanner activity. On the eligible devices this activity * is provided by GMS core. 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 29ab4acb05ff3..1da8eb2c811e3 100644 --- a/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java +++ b/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java @@ -622,7 +622,7 @@ public class ChooserActivityTest { List stableCopy = createResolvedComponentsForTestWithOtherProfile(2, /* userId= */ 10); waitForIdle(); - Thread.sleep(ChooserActivity.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS); + Thread.sleep(((ChooserActivity) activity).mListViewUpdateDelayMs); onView(first(withText(stableCopy.get(1).getResolveInfoAt(0).activityInfo.name))) .perform(click()); @@ -1436,7 +1436,7 @@ public class ChooserActivityTest { // 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.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS); + Thread.sleep(((ChooserActivity) activity).mListViewUpdateDelayMs); assertThat("Chooser should have 3 targets (2 apps, 1 direct)", activity.getAdapter().getCount(), is(3)); @@ -1512,7 +1512,7 @@ public class ChooserActivityTest { // 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.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS); + Thread.sleep(((ChooserActivity) activity).mListViewUpdateDelayMs); assertThat("Chooser should have 3 targets (2 apps, 1 direct)", activity.getAdapter().getCount(), is(3)); @@ -1594,7 +1594,7 @@ public class ChooserActivityTest { // 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.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS); + Thread.sleep(((ChooserActivity) activity).mListViewUpdateDelayMs); assertThat("Chooser should have 3 targets (2 apps, 1 direct)", wrapper.getAdapter().getCount(), is(3)); @@ -1666,7 +1666,7 @@ public class ChooserActivityTest { // 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.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS); + Thread.sleep(((ChooserActivity) activity).mListViewUpdateDelayMs); assertThat("Chooser should have 4 targets (2 apps, 2 direct)", wrapper.getAdapter().getCount(), is(4)); @@ -1753,7 +1753,7 @@ public class ChooserActivityTest { // 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.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS); + Thread.sleep(((ChooserActivity) activity).mListViewUpdateDelayMs); assertThat( String.format("Chooser should have %d targets (%d apps, 1 direct, 15 A-Z)", @@ -1878,12 +1878,13 @@ public class ChooserActivityTest { return true; }; - mActivityRule.launchActivity(Intent.createChooser(sendIntent, "work tab test")); + final IChooserWrapper activity = (IChooserWrapper) + mActivityRule.launchActivity(Intent.createChooser(sendIntent, "work tab test")); waitForIdle(); onView(withTextFromRuntimeResource("resolver_work_tab")).perform(click()); waitForIdle(); // wait for the share sheet to expand - Thread.sleep(ChooserActivity.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS); + Thread.sleep(((ChooserActivity) activity).mListViewUpdateDelayMs); onView(first(allOf( withText(workResolvedComponentInfos.get(0) @@ -2146,7 +2147,7 @@ public class ChooserActivityTest { // 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.LIST_VIEW_UPDATE_INTERVAL_IN_MILLIS); + Thread.sleep(((ChooserActivity) activity).mListViewUpdateDelayMs); assertThat("Chooser should have 3 targets (2 apps, 1 direct)", activity.getAdapter().getCount(), is(3));