Enforce BaseUserRestriction for DISALLOW_CONFIG_BRIGHTNESS

Bug: 329205638
Test: pm set-user-restriction --user 0 no_config_brightness 1
Flag: ACONFIG com.android.systemui.enforce_brightness_base_user_restriction DEVELOPMENT
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:f9f3fdba4b4995b0ca45732b95de64318642e210)
Merged-In: I47b8b72a5a5c4098b46f0b5dbbf0654513b03aee
Change-Id: I47b8b72a5a5c4098b46f0b5dbbf0654513b03aee
diff --git a/packages/SystemUI/aconfig/systemui.aconfig b/packages/SystemUI/aconfig/systemui.aconfig
index d3cd176..bb7e9ac 100644
--- a/packages/SystemUI/aconfig/systemui.aconfig
+++ b/packages/SystemUI/aconfig/systemui.aconfig
@@ -611,3 +611,13 @@
     description: "Refactors media code to follow the recommended architecture"
     bug: "326408371"
 }
+
+flag {
+    name: "enforce_brightness_base_user_restriction"
+    namespace: "systemui"
+    description: "Enforce BaseUserRestriction for DISALLOW_CONFIG_BRIGHTNESS."
+    bug: "329205638"
+    metadata {
+        purpose: PURPOSE_BUGFIX
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessController.java b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessController.java
index e92630f..db92205 100644
--- a/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessController.java
+++ b/packages/SystemUI/src/com/android/systemui/settings/brightness/BrightnessController.java
@@ -47,7 +47,9 @@
 import com.android.internal.display.BrightnessSynchronizer;
 import com.android.internal.logging.MetricsLogger;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settingslib.RestrictedLockUtils;
 import com.android.settingslib.RestrictedLockUtilsInternal;
+import com.android.systemui.Flags;
 import com.android.systemui.dagger.qualifiers.Background;
 import com.android.systemui.dagger.qualifiers.Main;
 import com.android.systemui.settings.DisplayTracker;
@@ -369,10 +371,18 @@
         mBackgroundHandler.post(new Runnable() {
             @Override
             public void run() {
-                mControl.setEnforcedAdmin(
+                int userId = mUserTracker.getUserId();
+                RestrictedLockUtils.EnforcedAdmin enforcedAdmin =
                         RestrictedLockUtilsInternal.checkIfRestrictionEnforced(mContext,
                                 UserManager.DISALLOW_CONFIG_BRIGHTNESS,
-                                mUserTracker.getUserId()));
+                                userId);
+                if (Flags.enforceBrightnessBaseUserRestriction() && enforcedAdmin == null
+                        && RestrictedLockUtilsInternal.hasBaseUserRestriction(mContext,
+                        UserManager.DISALLOW_CONFIG_BRIGHTNESS,
+                        userId)) {
+                    enforcedAdmin = new RestrictedLockUtils.EnforcedAdmin();
+                }
+                mControl.setEnforcedAdmin(enforcedAdmin);
             }
         });
     }