1 /* 2 * Copyright (C) 2024 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 package com.android.settings.accessibility; 17 18 import static com.android.settings.accessibility.AccessibilityUtil.State.OFF; 19 import static com.android.settings.accessibility.AccessibilityUtil.State.ON; 20 21 import android.content.ContentResolver; 22 import android.provider.Settings; 23 import android.view.accessibility.AccessibilityManager; 24 25 import com.google.common.primitives.Ints; 26 27 /** 28 * Utility class for retrieving accessibility daltonizer related values in secure settings. 29 */ 30 public class DaltonizerPreferenceUtil { 31 32 /** 33 * Return the daltonizer display mode stored in 34 * {@link Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER}. 35 * By default it returns {@link DALTONIZER_CORRECT_DEUTERANOMALY}. 36 */ getSecureAccessibilityDaltonizerValue(ContentResolver resolver)37 public static int getSecureAccessibilityDaltonizerValue(ContentResolver resolver) { 38 final String daltonizerStringValue = Settings.Secure.getString( 39 resolver, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER); 40 if (daltonizerStringValue == null) { 41 return AccessibilityManager.DALTONIZER_CORRECT_DEUTERANOMALY; 42 } 43 final Integer daltonizerIntValue = Ints.tryParse(daltonizerStringValue); 44 return daltonizerIntValue == null ? AccessibilityManager.DALTONIZER_CORRECT_DEUTERANOMALY 45 : daltonizerIntValue; 46 } 47 48 /** 49 * Returns the daltonizer enabled value in 50 * {@link Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED}. 51 * By default it returns false. 52 */ isSecureAccessibilityDaltonizerEnabled(ContentResolver resolver)53 public static boolean isSecureAccessibilityDaltonizerEnabled(ContentResolver resolver) { 54 return Settings.Secure.getInt( 55 resolver, 56 Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 57 OFF) == ON; 58 } 59 } 60