Fix UiBlcoker regression

We determine if the visibility should be updated by mIsFirstLaunch, and
mIsFirstLaunch is set to false in onStop(). This breaks the updatability
if there's a change before onStop() gets called.

So we move the value assignment to the end of checkUiBlocker() because
at that time, all blocker work should be either finished or timeout.
Also remove mIsFirstLaunch since mUiBlockerFinished can cover the
determination with the new design.

Fixes: 229565193
Test: Toggle Use Location in the location page and see the Recent used
section react accordingly.

Change-Id: Id6005e5b8b29cb8a6309068d0a2177489a3fb2f4
This commit is contained in:
Yi-Ling Chuang
2022-04-18 15:35:52 +08:00
parent 4dc79d92f0
commit 61022c6419
2 changed files with 7 additions and 16 deletions

View File

@@ -126,7 +126,6 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
@Nullable
private UserHandle mWorkProfileUser;
private int mMetricsCategory;
private boolean mIsFirstLaunch;
private boolean mPrefVisibility;
/**
@@ -198,7 +197,6 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
public BasePreferenceController(Context context, String preferenceKey) {
super(context);
mPreferenceKey = preferenceKey;
mIsFirstLaunch = true;
mPrefVisibility = true;
if (TextUtils.isEmpty(mPreferenceKey)) {
throw new IllegalArgumentException("Preference key must be set");
@@ -331,13 +329,6 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
}
}
/**
* Set back the value of whether this is the first launch.
*/
public void revokeFirstLaunch() {
mIsFirstLaunch = false;
}
/**
* Launches the specified fragment for the work profile user if the associated
* {@link Preference} is clicked. Otherwise just forward it to the super class.
@@ -454,7 +445,7 @@ public abstract class BasePreferenceController extends AbstractPreferenceControl
* preference visibility.
*/
protected void updatePreferenceVisibilityDelegate(Preference preference, boolean isVisible) {
if (mUiBlockerFinished || !mIsFirstLaunch) {
if (mUiBlockerFinished) {
preference.setVisible(isVisible);
return;
}

View File

@@ -132,17 +132,22 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
@VisibleForTesting
void checkUiBlocker(List<AbstractPreferenceController> controllers) {
final List<String> keys = new ArrayList<>();
final List<BasePreferenceController> baseControllers = new ArrayList<>();
controllers.forEach(controller -> {
if (controller instanceof BasePreferenceController.UiBlocker
&& controller.isAvailable()) {
((BasePreferenceController) controller).setUiBlockListener(this);
keys.add(controller.getPreferenceKey());
baseControllers.add((BasePreferenceController) controller);
}
});
if (!keys.isEmpty()) {
mBlockerController = new UiBlockerController(keys);
mBlockerController.start(() -> updatePreferenceVisibility(mPreferenceControllers));
mBlockerController.start(() -> {
updatePreferenceVisibility(mPreferenceControllers);
baseControllers.forEach(controller -> controller.setUiBlockerFinished(true));
});
}
}
@@ -250,11 +255,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
}
mListeningToCategoryChange = false;
}
mControllers.forEach(controller -> {
if (controller instanceof BasePreferenceController.UiBlocker) {
((BasePreferenceController) controller).revokeFirstLaunch();
}
});
}
@Override