fix(Color correction): Display default value in slider to match the radio button
The default value for display in the radio buttons were hard-coded and was not being reflected to the slider correctly. Bug: 359379399 Test: locally tested + unit tests added Flag: com.android.server.accessibility.enable_color_correction_saturation Change-Id: I95bd0ae1d32561dbbf6b4e87efe70595c9566de8
This commit is contained in:
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
|
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
|
||||||
|
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
|
||||||
|
import com.google.common.primitives.Ints;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class for retrieving accessibility daltonizer related values in secure settings.
|
||||||
|
*/
|
||||||
|
public class DaltonizerPreferenceUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the daltonizer display mode stored in
|
||||||
|
* {@link Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER}.
|
||||||
|
* By default it returns {@link DALTONIZER_CORRECT_DEUTERANOMALY}.
|
||||||
|
*/
|
||||||
|
public static int getSecureAccessibilityDaltonizerValue(ContentResolver resolver) {
|
||||||
|
final String daltonizerStringValue = Settings.Secure.getString(
|
||||||
|
resolver, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER);
|
||||||
|
if (daltonizerStringValue == null) {
|
||||||
|
return AccessibilityManager.DALTONIZER_CORRECT_DEUTERANOMALY;
|
||||||
|
}
|
||||||
|
final Integer daltonizerIntValue = Ints.tryParse(daltonizerStringValue);
|
||||||
|
return daltonizerIntValue == null ? AccessibilityManager.DALTONIZER_CORRECT_DEUTERANOMALY
|
||||||
|
: daltonizerIntValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the daltonizer enabled value in
|
||||||
|
* {@link Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED}.
|
||||||
|
* By default it returns false.
|
||||||
|
*/
|
||||||
|
public static boolean isSecureAccessibilityDaltonizerEnabled(ContentResolver resolver) {
|
||||||
|
return Settings.Secure.getInt(
|
||||||
|
resolver,
|
||||||
|
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED,
|
||||||
|
OFF) == ON;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,7 +24,6 @@ import android.os.Handler;
|
|||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.accessibility.AccessibilityManager;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.lifecycle.DefaultLifecycleObserver;
|
import androidx.lifecycle.DefaultLifecycleObserver;
|
||||||
@@ -36,8 +35,6 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
||||||
|
|
||||||
import com.google.common.primitives.Ints;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -70,17 +67,6 @@ public class DaltonizerRadioButtonPreferenceController extends BasePreferenceCon
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static int getSecureAccessibilityDaltonizerValue(ContentResolver resolver) {
|
|
||||||
final String daltonizerStringValue = Settings.Secure.getString(
|
|
||||||
resolver, DALTONIZER_TYPE_SETTINGS_KEY);
|
|
||||||
if (daltonizerStringValue == null) {
|
|
||||||
return AccessibilityManager.DALTONIZER_CORRECT_DEUTERANOMALY;
|
|
||||||
}
|
|
||||||
final Integer daltonizerIntValue = Ints.tryParse(daltonizerStringValue);
|
|
||||||
return daltonizerIntValue == null ? AccessibilityManager.DALTONIZER_CORRECT_DEUTERANOMALY
|
|
||||||
: daltonizerIntValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, Integer> getDaltonizerValueToKeyMap() {
|
private Map<String, Integer> getDaltonizerValueToKeyMap() {
|
||||||
if (mAccessibilityDaltonizerKeyToValueMap.isEmpty()) {
|
if (mAccessibilityDaltonizerKeyToValueMap.isEmpty()) {
|
||||||
|
|
||||||
@@ -123,7 +109,8 @@ public class DaltonizerRadioButtonPreferenceController extends BasePreferenceCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getAccessibilityDaltonizerValue() {
|
private int getAccessibilityDaltonizerValue() {
|
||||||
final int daltonizerValue = getSecureAccessibilityDaltonizerValue(mContentResolver);
|
final int daltonizerValue =
|
||||||
|
DaltonizerPreferenceUtil.getSecureAccessibilityDaltonizerValue(mContentResolver);
|
||||||
return daltonizerValue;
|
return daltonizerValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.accessibility;
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
|
import static com.android.settings.accessibility.DaltonizerPreferenceUtil.isSecureAccessibilityDaltonizerEnabled;
|
||||||
|
import static com.android.settings.accessibility.DaltonizerPreferenceUtil.getSecureAccessibilityDaltonizerValue;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
@@ -158,14 +161,11 @@ public class DaltonizerSaturationSeekbarPreferenceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldSeekBarEnabled() {
|
private boolean shouldSeekBarEnabled() {
|
||||||
int enabled = Settings.Secure.getInt(
|
boolean enabled = isSecureAccessibilityDaltonizerEnabled(mContentResolver);
|
||||||
mContentResolver, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0);
|
int mode = getSecureAccessibilityDaltonizerValue(mContentResolver);
|
||||||
int mode = Settings.Secure.getInt(
|
|
||||||
mContentResolver, Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, -1);
|
|
||||||
|
|
||||||
// enabled == 0 is disabled and also default.
|
|
||||||
// mode == 0 is gray scale where saturation level isn't applicable.
|
// mode == 0 is gray scale where saturation level isn't applicable.
|
||||||
// mode == -1 is disabled and also default.
|
// mode == -1 is disabled and also default.
|
||||||
return enabled != 0 && mode != -1 && mode != 0;
|
return enabled && mode != -1 && mode != 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import static com.android.internal.accessibility.AccessibilityShortcutController
|
|||||||
import static com.android.settings.accessibility.AccessibilityStatsLogUtils.logAccessibilityServiceEnabled;
|
import static com.android.settings.accessibility.AccessibilityStatsLogUtils.logAccessibilityServiceEnabled;
|
||||||
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
|
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
|
||||||
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||||
|
import static com.android.settings.accessibility.DaltonizerPreferenceUtil.isSecureAccessibilityDaltonizerEnabled;
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
@@ -145,7 +146,8 @@ public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceF
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
|
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
|
||||||
final boolean isEnabled = Settings.Secure.getInt(getContentResolver(), ENABLED, OFF) == ON;
|
final boolean isEnabled =
|
||||||
|
isSecureAccessibilityDaltonizerEnabled(getContentResolver());
|
||||||
if (enabled == isEnabled) {
|
if (enabled == isEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,8 +58,6 @@ public class DaltonizerSaturationSeekbarPreferenceControllerTest {
|
|||||||
private ContentResolver mContentResolver;
|
private ContentResolver mContentResolver;
|
||||||
private DaltonizerSaturationSeekbarPreferenceController mController;
|
private DaltonizerSaturationSeekbarPreferenceController mController;
|
||||||
|
|
||||||
private int mOriginalSaturationLevel = -1;
|
|
||||||
|
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
private LifecycleOwner mLifecycleOwner;
|
private LifecycleOwner mLifecycleOwner;
|
||||||
private Lifecycle mLifecycle;
|
private Lifecycle mLifecycle;
|
||||||
@@ -73,10 +71,6 @@ public class DaltonizerSaturationSeekbarPreferenceControllerTest {
|
|||||||
public void setup() {
|
public void setup() {
|
||||||
Context context = ApplicationProvider.getApplicationContext();
|
Context context = ApplicationProvider.getApplicationContext();
|
||||||
mContentResolver = context.getContentResolver();
|
mContentResolver = context.getContentResolver();
|
||||||
mOriginalSaturationLevel = Settings.Secure.getInt(
|
|
||||||
mContentResolver,
|
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_SATURATION_LEVEL,
|
|
||||||
7);
|
|
||||||
|
|
||||||
mPreference = new SeekBarPreference(context);
|
mPreference = new SeekBarPreference(context);
|
||||||
mPreference.setKey(ToggleDaltonizerPreferenceFragment.KEY_SATURATION);
|
mPreference.setKey(ToggleDaltonizerPreferenceFragment.KEY_SATURATION);
|
||||||
@@ -92,10 +86,18 @@ public class DaltonizerSaturationSeekbarPreferenceControllerTest {
|
|||||||
|
|
||||||
@After
|
@After
|
||||||
public void cleanup() {
|
public void cleanup() {
|
||||||
Settings.Secure.putInt(
|
Settings.Secure.putString(
|
||||||
|
mContentResolver,
|
||||||
|
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER,
|
||||||
|
null);
|
||||||
|
Settings.Secure.putString(
|
||||||
|
mContentResolver,
|
||||||
|
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED,
|
||||||
|
null);
|
||||||
|
Settings.Secure.putString(
|
||||||
mContentResolver,
|
mContentResolver,
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_SATURATION_LEVEL,
|
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_SATURATION_LEVEL,
|
||||||
mOriginalSaturationLevel);
|
null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -111,6 +113,22 @@ public class DaltonizerSaturationSeekbarPreferenceControllerTest {
|
|||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_ENABLE_COLOR_CORRECTION_SATURATION)
|
||||||
|
public void getAvailabilityStatus_defaultSettings_unavailable() {
|
||||||
|
// By default enabled == false.
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_ENABLE_COLOR_CORRECTION_SATURATION)
|
||||||
|
public void getAvailabilityStatus_enabledDefaultDisplayMode_available() {
|
||||||
|
setDaltonizerEnabled(1);
|
||||||
|
|
||||||
|
// By default display mode is deuteranomaly.
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableFlags(Flags.FLAG_ENABLE_COLOR_CORRECTION_SATURATION)
|
@EnableFlags(Flags.FLAG_ENABLE_COLOR_CORRECTION_SATURATION)
|
||||||
public void getAvailabilityStatus_flagEnabledProtanEnabled_available() {
|
public void getAvailabilityStatus_flagEnabledProtanEnabled_available() {
|
||||||
@@ -306,10 +324,7 @@ public class DaltonizerSaturationSeekbarPreferenceControllerTest {
|
|||||||
mLifecycle.addObserver(mController);
|
mLifecycle.addObserver(mController);
|
||||||
mLifecycle.handleLifecycleEvent(ON_RESUME);
|
mLifecycle.handleLifecycleEvent(ON_RESUME);
|
||||||
|
|
||||||
Settings.Secure.putInt(
|
setDaltonizerEnabled(1);
|
||||||
mContentResolver,
|
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED,
|
|
||||||
1);
|
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
|
|
||||||
assertThat(mPreference.isEnabled()).isTrue();
|
assertThat(mPreference.isEnabled()).isTrue();
|
||||||
@@ -324,10 +339,7 @@ public class DaltonizerSaturationSeekbarPreferenceControllerTest {
|
|||||||
mLifecycle.addObserver(mController);
|
mLifecycle.addObserver(mController);
|
||||||
mLifecycle.handleLifecycleEvent(ON_RESUME);
|
mLifecycle.handleLifecycleEvent(ON_RESUME);
|
||||||
|
|
||||||
Settings.Secure.putInt(
|
setDaltonizerEnabled(0);
|
||||||
mContentResolver,
|
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED,
|
|
||||||
0);
|
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
|
|
||||||
assertThat(mPreference.isEnabled()).isFalse();
|
assertThat(mPreference.isEnabled()).isFalse();
|
||||||
@@ -342,10 +354,7 @@ public class DaltonizerSaturationSeekbarPreferenceControllerTest {
|
|||||||
mLifecycle.addObserver(mController);
|
mLifecycle.addObserver(mController);
|
||||||
mLifecycle.handleLifecycleEvent(ON_RESUME);
|
mLifecycle.handleLifecycleEvent(ON_RESUME);
|
||||||
|
|
||||||
Settings.Secure.putInt(
|
setDaltonizerDisplay(0);
|
||||||
mContentResolver,
|
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER,
|
|
||||||
0);
|
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
|
|
||||||
assertThat(mPreference.isEnabled()).isFalse();
|
assertThat(mPreference.isEnabled()).isFalse();
|
||||||
@@ -361,23 +370,28 @@ public class DaltonizerSaturationSeekbarPreferenceControllerTest {
|
|||||||
mLifecycle.handleLifecycleEvent(ON_STOP);
|
mLifecycle.handleLifecycleEvent(ON_STOP);
|
||||||
|
|
||||||
// enabled.
|
// enabled.
|
||||||
Settings.Secure.putInt(
|
setDaltonizerEnabled(1);
|
||||||
mContentResolver,
|
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED,
|
|
||||||
1);
|
|
||||||
shadowOf(Looper.getMainLooper()).idle();
|
shadowOf(Looper.getMainLooper()).idle();
|
||||||
|
|
||||||
assertThat(mPreference.isEnabled()).isFalse();
|
assertThat(mPreference.isEnabled()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDaltonizerMode(int enabled, int mode) {
|
private void setDaltonizerMode(int enabled, int mode) {
|
||||||
|
setDaltonizerEnabled(enabled);
|
||||||
|
setDaltonizerDisplay(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setDaltonizerEnabled(int enabled) {
|
||||||
Settings.Secure.putInt(
|
Settings.Secure.putInt(
|
||||||
mContentResolver,
|
mContentResolver,
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED,
|
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED,
|
||||||
enabled);
|
enabled);
|
||||||
Settings.Secure.putInt(
|
}
|
||||||
|
|
||||||
|
private void setDaltonizerDisplay(int mode) {
|
||||||
|
Settings.Secure.putString(
|
||||||
mContentResolver,
|
mContentResolver,
|
||||||
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER,
|
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER,
|
||||||
mode);
|
Integer.toString(mode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user