Fix that device isn't responding for a while when resetting all settings on “Display size and text” page.
Goal: Probably has the race condition issue between "Bold text" and the other features including "Display Size", “Font Size” if they would be enabled at the same time, so our workaround is that the “Bold text” would be reset first and then do the remaining to avoid flickering problem. Bug: 223747686 Bug: 220082104 Bug: 220070773 Test: make RunSettingsRoboTests ROBOTEST_FILTER=TextReadingPreferenceFragmentTest Change-Id: If1425fe2579bec8dded69680ac73fbfb03c37321
This commit is contained in:
@@ -22,6 +22,7 @@ import android.app.Dialog;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
@@ -32,6 +33,8 @@ import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -49,6 +52,26 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
|
||||
private static final String RESET_KEY = "reset";
|
||||
private static final String BOLD_TEXT_KEY = "toggle_force_bold_text";
|
||||
private static final String HIGHT_TEXT_CONTRAST_KEY = "toggle_high_text_contrast_preference";
|
||||
private static final String NEED_RESET_SETTINGS = "need_reset_settings";
|
||||
private FontWeightAdjustmentPreferenceController mFontWeightAdjustmentController;
|
||||
|
||||
@VisibleForTesting
|
||||
List<ResetStateListener> mResetStateListeners;
|
||||
|
||||
@VisibleForTesting
|
||||
boolean mNeedResetSettings;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
mNeedResetSettings = false;
|
||||
mResetStateListeners = getResetStateListeners();
|
||||
|
||||
if (icicle != null && icicle.getBoolean(NEED_RESET_SETTINGS)) {
|
||||
mResetStateListeners.forEach(ResetStateListener::resetState);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
@@ -69,7 +92,7 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
final FontSizeData fontSizeData = new FontSizeData(context);
|
||||
final DisplaySizeData displaySizeData = new DisplaySizeData(context);
|
||||
final DisplaySizeData displaySizeData = createDisplaySizeData(context);
|
||||
|
||||
final TextReadingPreviewController previewController = new TextReadingPreviewController(
|
||||
context, PREVIEW_KEY, fontSizeData, displaySizeData);
|
||||
@@ -85,9 +108,9 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
|
||||
displaySizeController.setInteractionListener(previewController);
|
||||
controllers.add(displaySizeController);
|
||||
|
||||
final FontWeightAdjustmentPreferenceController fontWeightController =
|
||||
mFontWeightAdjustmentController =
|
||||
new FontWeightAdjustmentPreferenceController(context, BOLD_TEXT_KEY);
|
||||
controllers.add(fontWeightController);
|
||||
controllers.add(mFontWeightAdjustmentController);
|
||||
|
||||
final HighTextContrastPreferenceController highTextContrastController =
|
||||
new HighTextContrastPreferenceController(context, HIGHT_TEXT_CONTRAST_KEY);
|
||||
@@ -126,12 +149,35 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
|
||||
return super.getDialogMetricsCategory(dialogId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
if (mNeedResetSettings) {
|
||||
outState.putBoolean(NEED_RESET_SETTINGS, true);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
DisplaySizeData createDisplaySizeData(Context context) {
|
||||
return new DisplaySizeData(context);
|
||||
}
|
||||
|
||||
private void onPositiveButtonClicked(DialogInterface dialog, int which) {
|
||||
// To avoid showing the dialog again, probably the onDetach() of SettingsDialogFragment
|
||||
// was interrupted by unexpectedly recreating the activity.
|
||||
removeDialog(DialogEnums.DIALOG_RESET_SETTINGS);
|
||||
|
||||
getResetStateListeners().forEach(ResetStateListener::resetState);
|
||||
if (mFontWeightAdjustmentController.isChecked()) {
|
||||
// TODO(b/228956791): Consider replacing or removing it once the root cause is
|
||||
// clarified and the better method is available.
|
||||
// Probably has the race condition issue between "Bold text" and the other features
|
||||
// including "Display Size", “Font Size” if they would be enabled at the same time,
|
||||
// so our workaround is that the “Bold text” would be reset first and then do the
|
||||
// remaining to avoid flickering problem.
|
||||
mNeedResetSettings = true;
|
||||
mFontWeightAdjustmentController.resetState();
|
||||
} else {
|
||||
mResetStateListeners.forEach(ResetStateListener::resetState);
|
||||
}
|
||||
}
|
||||
|
||||
private List<ResetStateListener> getResetStateListeners() {
|
||||
|
Reference in New Issue
Block a user