1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.privacy; 18 19 import android.annotation.NonNull; 20 import android.content.Context; 21 import android.os.UserHandle; 22 import android.os.UserManager; 23 24 import com.android.settings.R; 25 import com.android.settings.core.TogglePreferenceController; 26 import com.android.settings.utils.ContentCaptureUtils; 27 28 public final class EnableContentCapturePreferenceController extends TogglePreferenceController { 29 EnableContentCapturePreferenceController(@onNull Context context, @NonNull String key)30 public EnableContentCapturePreferenceController(@NonNull Context context, @NonNull String key) { 31 super(context, key); 32 } 33 34 @Override isChecked()35 public boolean isChecked() { 36 return ContentCaptureUtils.isEnabledForUser(mContext); 37 } 38 39 @Override setChecked(boolean isChecked)40 public boolean setChecked(boolean isChecked) { 41 ContentCaptureUtils.setEnabledForUser(mContext, isChecked); 42 return true; 43 } 44 45 @Override getAvailabilityStatus()46 public int getAvailabilityStatus() { 47 if (!ContentCaptureUtils.isFeatureAvailable() 48 || ContentCaptureUtils.getServiceSettingsComponentName() != null) { 49 return UNSUPPORTED_ON_DEVICE; 50 } 51 if (UserManager.get(mContext).hasUserRestrictionForUser( 52 UserManager.DISALLOW_CONTENT_CAPTURE, UserHandle.of(UserHandle.myUserId()))) { 53 return DISABLED_FOR_USER; 54 } 55 return AVAILABLE; 56 } 57 58 @Override getSliceHighlightMenuRes()59 public int getSliceHighlightMenuRes() { 60 return R.string.menu_key_privacy; 61 } 62 } 63