Initialize injected Security preferences.

Previously a default "G" icon was loaded before the injected ones and
this would be visually jarring. Also the text summary would cause the
titles to shift up, so now load an empty icon and empty summary so no
more jarring visual effects.

Bug: 35994047
Test: make RunSettingsRoboTests
Change-Id: Ia06535215432fe350a3bb06f541e817a566772e0
This commit is contained in:
William Luh
2017-03-08 11:44:54 -08:00
parent 2437d3c64a
commit 91eaa85c52
2 changed files with 50 additions and 6 deletions

View File

@@ -46,9 +46,24 @@ public class SecurityFeatureProviderImpl implements SecurityFeatureProvider {
private TrustAgentManager mTrustAgentManager;
@VisibleForTesting
static final Drawable DEFAULT_ICON = null;
@VisibleForTesting
static final String DEFAULT_SUMMARY = " ";
/** Update preferences with data from associated tiles. */
public void updatePreferences(final Context context, final PreferenceScreen preferenceScreen,
final DashboardCategory dashboardCategory) {
if (preferenceScreen == null) {
return;
}
int tilesCount = (dashboardCategory != null) ? dashboardCategory.getTilesCount() : 0;
if (tilesCount == 0) {
return;
}
initPreferences(context, preferenceScreen, dashboardCategory);
// Fetching the summary and icon from the provider introduces latency, so do this on a
// separate thread.
Executors.newSingleThreadExecutor().execute(new Runnable() {
@@ -59,17 +74,34 @@ public class SecurityFeatureProviderImpl implements SecurityFeatureProvider {
});
}
@VisibleForTesting
static void initPreferences(Context context, PreferenceScreen preferenceScreen,
DashboardCategory dashboardCategory) {
int tilesCount = (dashboardCategory != null) ? dashboardCategory.getTilesCount() : 0;
for (int i = 0; i < tilesCount; i++) {
Tile tile = dashboardCategory.getTile(i);
// If the tile does not have a key or appropriate meta data, skip it.
if (TextUtils.isEmpty(tile.key) || (tile.metaData == null)) {
continue;
}
Preference matchingPref = preferenceScreen.findPreference(tile.key);
// If the tile does not have a matching preference, skip it.
if (matchingPref == null) {
continue;
}
// Remove any icons that may be loaded before we inject the final icon.
matchingPref.setIcon(DEFAULT_ICON);
// Reserve room for the summary. This prevents the title from having to shift when the
// final title is injected.
matchingPref.setSummary(DEFAULT_SUMMARY);
}
}
@VisibleForTesting
void updatePreferencesToRunOnWorkerThread(Context context, PreferenceScreen preferenceScreen,
DashboardCategory dashboardCategory) {
if (preferenceScreen == null) {
return;
}
int tilesCount = (dashboardCategory != null) ? dashboardCategory.getTilesCount() : 0;
if (tilesCount == 0) {
return;
}
Map<String, IContentProvider> providerMap = new ArrayMap<>();
for (int i = 0; i < tilesCount; i++) {
Tile tile = dashboardCategory.getTile(i);