From a7d76af9336f8b4e2b8d77a0dde0239342b4823f Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Wed, 23 Sep 2020 11:00:21 +0800 Subject: [PATCH] Guard against flickering of dynamic injection items The summary of injected items may flicker when the data is change from URI. Root cause: If an external app injects an entry to Settings with a dynamic summary, Settings will observe the summary change via the provideed URI. However, sometimes when Settings observes the data change and then refreshes the UI, the data doesn't really change and settings still gets the same summary. If it happens in a short period, the summary will seem flickering. Solution: Check if the data really changes before refresh UI. Guard both title and summary. Fixes: 168309941 Fixes: 166785977 Test: robotest Change-Id: I137fc317dcfd8919195c10fa8cf7d2559fe1029d --- .../settings/dashboard/DashboardFeatureProviderImpl.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java index 76400791a9c..e8ae85d4d6a 100644 --- a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java +++ b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java @@ -248,7 +248,9 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider { final Map providerMap = new ArrayMap<>(); final String titleFromUri = TileUtils.getTextFromUri( mContext, uri, providerMap, META_DATA_PREFERENCE_TITLE); - ThreadUtils.postOnMainThread(() -> preference.setTitle(titleFromUri)); + if (!TextUtils.equals(titleFromUri, preference.getTitle())) { + ThreadUtils.postOnMainThread(() -> preference.setTitle(titleFromUri)); + } }); } @@ -277,7 +279,9 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider { final Map providerMap = new ArrayMap<>(); final String summaryFromUri = TileUtils.getTextFromUri( mContext, uri, providerMap, META_DATA_PREFERENCE_SUMMARY); - ThreadUtils.postOnMainThread(() -> preference.setSummary(summaryFromUri)); + if (!TextUtils.equals(summaryFromUri, preference.getSummary())) { + ThreadUtils.postOnMainThread(() -> preference.setSummary(summaryFromUri)); + } }); }