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
diff --git a/src/com/android/settings/core/BasePreferenceController.java b/src/com/android/settings/core/BasePreferenceController.java
index 6cc09e2..5763d3b 100644
--- a/src/com/android/settings/core/BasePreferenceController.java
+++ b/src/com/android/settings/core/BasePreferenceController.java
@@ -126,7 +126,6 @@
     @Nullable
     private UserHandle mWorkProfileUser;
     private int mMetricsCategory;
-    private boolean mIsFirstLaunch;
     private boolean mPrefVisibility;
 
     /**
@@ -198,7 +197,6 @@
     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");
@@ -332,13 +330,6 @@
     }
 
     /**
-     * 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 @@
      * preference visibility.
      */
     protected void updatePreferenceVisibilityDelegate(Preference preference, boolean isVisible) {
-        if (mUiBlockerFinished || !mIsFirstLaunch) {
+        if (mUiBlockerFinished) {
             preference.setVisible(isVisible);
             return;
         }
diff --git a/src/com/android/settings/dashboard/DashboardFragment.java b/src/com/android/settings/dashboard/DashboardFragment.java
index 256a620..aaa9b3d 100644
--- a/src/com/android/settings/dashboard/DashboardFragment.java
+++ b/src/com/android/settings/dashboard/DashboardFragment.java
@@ -132,17 +132,22 @@
     @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 @@
             }
             mListeningToCategoryChange = false;
         }
-        mControllers.forEach(controller -> {
-            if (controller instanceof BasePreferenceController.UiBlocker) {
-                ((BasePreferenceController) controller).revokeFirstLaunch();
-            }
-        });
     }
 
     @Override