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
This commit is contained in:
TYM Tsai
2023-01-07 02:39:03 +08:00
parent 30783964b3
commit a1ca72224d

View File

@@ -18,6 +18,8 @@ package com.android.settings.privacy;
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 @@ public final class EnableContentCapturePreferenceController extends TogglePrefer
@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