Fix Content Capture service starting after restriction

When a device owner and a profile owner restrict Content Capture,
there should be no toggle setting to turn on Content Capture.

Bug: 250573776
Test: Manual. Use setps on the comment#3,
      make sure no toggle setting in the Privacy page.
Change-Id: Ia17f852b224c67b9c1cf5846ee9ad5592a485bab
diff --git a/src/com/android/settings/privacy/EnableContentCapturePreferenceController.java b/src/com/android/settings/privacy/EnableContentCapturePreferenceController.java
index 3cf72b2..5377f15 100644
--- a/src/com/android/settings/privacy/EnableContentCapturePreferenceController.java
+++ b/src/com/android/settings/privacy/EnableContentCapturePreferenceController.java
@@ -18,6 +18,8 @@
 
 import android.annotation.NonNull;
 import android.content.Context;
+import android.os.UserHandle;
+import android.os.UserManager;
 
 import com.android.settings.R;
 import com.android.settings.core.TogglePreferenceController;
@@ -42,9 +44,15 @@
 
     @Override
     public int getAvailabilityStatus() {
-        boolean available = ContentCaptureUtils.isFeatureAvailable()
-                && ContentCaptureUtils.getServiceSettingsComponentName() == null;
-        return available ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+        if (!ContentCaptureUtils.isFeatureAvailable()
+                || ContentCaptureUtils.getServiceSettingsComponentName() != null) {
+            return UNSUPPORTED_ON_DEVICE;
+        }
+        if (UserManager.get(mContext).hasUserRestrictionForUser(
+                UserManager.DISALLOW_CONTENT_CAPTURE, UserHandle.of(UserHandle.myUserId()))) {
+            return DISABLED_FOR_USER;
+        }
+        return AVAILABLE;
     }
 
     @Override