Reduce the flickering of injected items when package is changed

Root cause:
Settings listens to four package-related broadcasts in order to refresh
injected items because UI data may change. However, when the system is
updating apps on the first boot, it triggers a burst of broadcasts. For
each broadcast Settings will reload and then redraw all injected items,
which leads to the flickering.

Solution:
1. When Settings recieves a broadcast, check if there are already two
reloading tasks to avoid redundant updates.
2. In the reloading task, check if any injected item is changed, added,
or removed to notify categories changed.
3. Only refresh the UI when any of the changed items belongs to the
current page.

Bug: 166785977
Bug: 168309941
Test: manual, robotest
Change-Id: I77745b60f84510554bff1870a5bb7a8013eab528
This commit is contained in:
Jason Chiu
2020-09-30 14:08:33 +08:00
parent 25afb1a010
commit 20df25e6b9
3 changed files with 126 additions and 20 deletions

View File

@@ -56,6 +56,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ExecutionException;
/**
@@ -160,13 +161,21 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
}
@Override
public void onCategoriesChanged() {
final DashboardCategory category =
mDashboardFeatureProvider.getTilesForCategory(getCategoryKey());
if (category == null) {
public void onCategoriesChanged(Set<String> categories) {
final String categoryKey = getCategoryKey();
final DashboardCategory dashboardCategory =
mDashboardFeatureProvider.getTilesForCategory(categoryKey);
if (dashboardCategory == null) {
return;
}
refreshDashboardTiles(getLogTag());
if (categories == null) {
// force refreshing
refreshDashboardTiles(getLogTag());
} else if (categories.contains(categoryKey)) {
Log.i(TAG, "refresh tiles for " + categoryKey);
refreshDashboardTiles(getLogTag());
}
}
@Override