From 578b259bd38d2a75fc7b1ecca1bfeb2009d99e07 Mon Sep 17 00:00:00 2001 From: Andrey Epin Date: Fri, 28 Oct 2022 14:16:24 -0700 Subject: Remove ChooserListAdapter notifyDataSetChange throttling ChooserListAdapter notifyDataSetChange throttling period has been, practically, reduced to 0 and this change removes the logic completely. The remaining ChooserHandler's message turned into posting on the UI thread and thus ChooserHandler is also removed. Safety Check All ChooserListAdapter#notifyDataSetChanged invocations I've found (posted below) are originated by some posting on the main thread i.e. not initiated from a view binding in the adapter. Invocations - ChooserActivity.onHandlePackageChanged (and - ResolverActivity.onHandlePackageChanged) - ChooserListAdapter.onListRebuilt - ChooserListAdapter.updateAlphabeticalList - ChooserListAdapter.addServiceResults - ChooserListAdapter.completeServiceTargetLoading - ChooserListAdapter$ from #createSortingTask - ChooserListAdapter.LoadDirectShareIconTask - ResolverListAdapter.LoadIconTask - ResolverListAdapter.LoadLabelTask Fix: 257285237 Test: manual test Test: atest IntentResolverUnitTests Change-Id: I70eeababa2fa684f0a160ff6ed9ab0900e3c9648 --- .../UnbundledChooserActivityTest.java | 51 +++++----------------- 1 file changed, 10 insertions(+), 41 deletions(-) (limited to 'java/tests') diff --git a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java index ee801101..dfdbeda7 100644 --- a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java +++ b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java @@ -636,7 +636,7 @@ public class UnbundledChooserActivityTest { } @Test @Ignore - public void hasOtherProfileOneOption() throws Exception { + public void hasOtherProfileOneOption() { List personalResolvedComponentInfos = createResolvedComponentsForTestWithOtherProfile(2, /* userId */ 10); List workResolvedComponentInfos = createResolvedComponentsForTest(4); @@ -662,7 +662,6 @@ public class UnbundledChooserActivityTest { List stableCopy = createResolvedComponentsForTestWithOtherProfile(2, /* userId= */ 10); waitForIdle(); - Thread.sleep(((ChooserActivity) activity).mListViewUpdateDelayMs); onView(first(withText(stableCopy.get(1).getResolveInfoAt(0).activityInfo.name))) .perform(click()); @@ -1278,7 +1277,7 @@ public class UnbundledChooserActivityTest { // This test is too long and too slow and should not be taken as an example for future tests. @Test @Ignore - public void testDirectTargetSelectionLogging() throws InterruptedException { + public void testDirectTargetSelectionLogging() { Intent sendIntent = createSendTextIntent(); // We need app targets for direct targets to get displayed List resolvedComponentInfos = createResolvedComponentsForTest(2); @@ -1321,11 +1320,6 @@ public class UnbundledChooserActivityTest { /* directShareToAppTargets */ null) ); - // 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", @@ -1356,7 +1350,7 @@ public class UnbundledChooserActivityTest { // This test is too long and too slow and should not be taken as an example for future tests. @Test @Ignore - public void testDirectTargetLoggingWithRankedAppTarget() throws InterruptedException { + public void testDirectTargetLoggingWithRankedAppTarget() { Intent sendIntent = createSendTextIntent(); // We need app targets for direct targets to get displayed List resolvedComponentInfos = createResolvedComponentsForTest(2); @@ -1399,10 +1393,6 @@ public class UnbundledChooserActivityTest { directShareToShortcutInfos, /* directShareToAppTargets */ null) ); - // 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)); @@ -1429,7 +1419,7 @@ public class UnbundledChooserActivityTest { } @Test @Ignore - public void testShortcutTargetWithApplyAppLimits() throws InterruptedException { + public void testShortcutTargetWithApplyAppLimits() { // Set up resources ChooserActivityOverrideData.getInstance().resources = Mockito.spy( InstrumentationRegistry.getInstrumentation().getContext().getResources()); @@ -1482,10 +1472,6 @@ public class UnbundledChooserActivityTest { directShareToShortcutInfos, /* directShareToAppTargets */ null) ); - // 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)", wrapper.getAdapter().getCount(), is(3)); @@ -1498,7 +1484,7 @@ public class UnbundledChooserActivityTest { } @Test @Ignore - public void testShortcutTargetWithoutApplyAppLimits() throws InterruptedException { + public void testShortcutTargetWithoutApplyAppLimits() { setDeviceConfigProperty( SystemUiDeviceConfigFlags.APPLY_SHARING_APP_LIMITS_IN_SYSUI, Boolean.toString(false)); @@ -1554,10 +1540,6 @@ public class UnbundledChooserActivityTest { directShareToShortcutInfos, /* directShareToAppTargets */ null) ); - // 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 4 targets (2 apps, 2 direct)", wrapper.getAdapter().getCount(), is(4)); @@ -1604,8 +1586,7 @@ public class UnbundledChooserActivityTest { } private void testDirectTargetLoggingWithAppTargetNotRanked( - int orientation, int appTargetsExpected - ) throws InterruptedException { + int orientation, int appTargetsExpected) { Configuration configuration = new Configuration(InstrumentationRegistry.getInstrumentation().getContext() .getResources().getConfiguration()); @@ -1643,9 +1624,8 @@ public class UnbundledChooserActivityTest { ResolveInfo ri = ResolverDataProvider.createResolveInfo(16, 0); // Start activity - final IChooserWrapper activity = (IChooserWrapper) + final IChooserWrapper wrapper = (IChooserWrapper) mActivityRule.launchActivity(Intent.createChooser(sendIntent, null)); - final IChooserWrapper wrapper = (IChooserWrapper) activity; // Insert the direct share target Map directShareToShortcutInfos = new HashMap<>(); directShareToShortcutInfos.put(serviceTargets.get(0), null); @@ -1662,10 +1642,6 @@ public class UnbundledChooserActivityTest { directShareToShortcutInfos, /* directShareToAppTargets */ null) ); - // 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( String.format("Chooser should have %d targets (%d apps, 1 direct, 15 A-Z)", @@ -1764,7 +1740,7 @@ public class UnbundledChooserActivityTest { } @Test @Ignore - public void testWorkTab_selectingWorkTabAppOpensAppInWorkProfile() throws InterruptedException { + public void testWorkTab_selectingWorkTabAppOpensAppInWorkProfile() { markWorkProfileUserAvailable(); List personalResolvedComponentInfos = createResolvedComponentsForTestWithOtherProfile(3, /* userId */ 10); @@ -1780,13 +1756,10 @@ public class UnbundledChooserActivityTest { return true; }; - final IChooserWrapper activity = (IChooserWrapper) - mActivityRule.launchActivity(Intent.createChooser(sendIntent, "work tab test")); + mActivityRule.launchActivity(Intent.createChooser(sendIntent, "work tab test")); waitForIdle(); onView(withText(R.string.resolver_work_tab)).perform(click()); waitForIdle(); - // wait for the share sheet to expand - Thread.sleep(((ChooserActivity) activity).mListViewUpdateDelayMs); onView(first(allOf( withText(workResolvedComponentInfos.get(0) @@ -1957,7 +1930,7 @@ public class UnbundledChooserActivityTest { } @Test @Ignore - public void testDirectTargetLogging() throws InterruptedException { + public void testDirectTargetLogging() { Intent sendIntent = createSendTextIntent(); // We need app targets for direct targets to get displayed List resolvedComponentInfos = createResolvedComponentsForTest(2); @@ -1997,10 +1970,6 @@ public class UnbundledChooserActivityTest { directShareToShortcutInfos, /* directShareToAppTargets */ null) ); - // 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)); -- cgit v1.2.3-59-g8ed1b