Merge "Call ColorDisplayManager for Extra Dim/RBC state" into sc-dev
This commit is contained in:
@@ -42,6 +42,7 @@ public class ReduceBrightColorsPreferenceController extends TogglePreferenceCont
|
|||||||
private ContentObserver mSettingsContentObserver;
|
private ContentObserver mSettingsContentObserver;
|
||||||
private PrimarySwitchPreference mPreference;
|
private PrimarySwitchPreference mPreference;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
private final ColorDisplayManager mColorDisplayManager;
|
||||||
|
|
||||||
public ReduceBrightColorsPreferenceController(Context context,
|
public ReduceBrightColorsPreferenceController(Context context,
|
||||||
String preferenceKey) {
|
String preferenceKey) {
|
||||||
@@ -56,21 +57,17 @@ public class ReduceBrightColorsPreferenceController extends TogglePreferenceCont
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
mColorDisplayManager = mContext.getSystemService(ColorDisplayManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChecked() {
|
public boolean isChecked() {
|
||||||
return Settings.Secure.getIntForUser(mContext.getContentResolver(),
|
return mColorDisplayManager.isReduceBrightColorsActivated();
|
||||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED,
|
|
||||||
0,
|
|
||||||
UserHandle.USER_CURRENT) == 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setChecked(boolean isChecked) {
|
public boolean setChecked(boolean isChecked) {
|
||||||
return Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
return mColorDisplayManager.setReduceBrightColorsActivated(isChecked);
|
||||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, isChecked ? 1 : 0,
|
|
||||||
UserHandle.USER_CURRENT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -16,9 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.accessibility;
|
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.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -57,6 +54,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
|
|||||||
private SettingsContentObserver mSettingsContentObserver;
|
private SettingsContentObserver mSettingsContentObserver;
|
||||||
private ReduceBrightColorsIntensityPreferenceController mRbcIntensityPreferenceController;
|
private ReduceBrightColorsIntensityPreferenceController mRbcIntensityPreferenceController;
|
||||||
private ReduceBrightColorsPersistencePreferenceController mRbcPersistencePreferenceController;
|
private ReduceBrightColorsPersistencePreferenceController mRbcPersistencePreferenceController;
|
||||||
|
private ColorDisplayManager mColorDisplayManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
@@ -83,7 +81,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
|
|||||||
updateSwitchBarToggleSwitch();
|
updateSwitchBarToggleSwitch();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
mColorDisplayManager = getContext().getSystemService(ColorDisplayManager.class);
|
||||||
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
// Parent sets the title when creating the view, so set it after calling super
|
// Parent sets the title when creating the view, so set it after calling super
|
||||||
mToggleServiceSwitchPreference.setTitle(R.string.reduce_bright_colors_switch_title);
|
mToggleServiceSwitchPreference.setTitle(R.string.reduce_bright_colors_switch_title);
|
||||||
@@ -141,8 +139,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
|
|||||||
@Override
|
@Override
|
||||||
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
|
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
|
||||||
AccessibilityStatsLogUtils.logAccessibilityServiceEnabled(mComponentName, enabled);
|
AccessibilityStatsLogUtils.logAccessibilityServiceEnabled(mComponentName, enabled);
|
||||||
Settings.Secure.putInt(getContentResolver(),
|
mColorDisplayManager.setReduceBrightColorsActivated(enabled);
|
||||||
REDUCE_BRIGHT_COLORS_ACTIVATED_KEY, enabled ? ON : OFF);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -165,8 +162,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateSwitchBarToggleSwitch() {
|
protected void updateSwitchBarToggleSwitch() {
|
||||||
final boolean checked = Settings.Secure.getInt(getContentResolver(),
|
final boolean checked = mColorDisplayManager.isReduceBrightColorsActivated();
|
||||||
REDUCE_BRIGHT_COLORS_ACTIVATED_KEY, OFF) == ON;
|
|
||||||
mRbcIntensityPreferenceController.updateState(getPreferenceScreen()
|
mRbcIntensityPreferenceController.updateState(getPreferenceScreen()
|
||||||
.findPreference(KEY_INTENSITY));
|
.findPreference(KEY_INTENSITY));
|
||||||
mRbcPersistencePreferenceController.updateState(getPreferenceScreen()
|
mRbcPersistencePreferenceController.updateState(getPreferenceScreen()
|
||||||
|
@@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 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.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
public class ReduceBrightColorsPreferenceControllerTest {
|
|
||||||
private static final String PREF_KEY = "rbc_preference";
|
|
||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
|
||||||
private final ReduceBrightColorsPreferenceController mController =
|
|
||||||
new ReduceBrightColorsPreferenceController(mContext, PREF_KEY);
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSummary_returnSummary() {
|
|
||||||
assertThat(mController.getSummary().toString().contains(
|
|
||||||
mContext.getText(R.string.reduce_bright_colors_preference_summary))).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isChecked_reduceBrightColorsIsActivated_returnTrue() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
|
||||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isChecked_reduceBrightColorsIsNotActivated_returnFalse() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
|
||||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0);
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 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.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.internal.R;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class ReduceBrightColorsPreferenceControllerTest {
|
||||||
|
private static final String PREF_KEY = "rbc_preference";
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private Resources mResources;;
|
||||||
|
private ReduceBrightColorsPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
|
mResources = spy(mContext.getResources());
|
||||||
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
|
mController = new ReduceBrightColorsPreferenceController(mContext,
|
||||||
|
PREF_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSummary_returnSummary() {
|
||||||
|
assertThat(mController.getSummary().toString().contains(
|
||||||
|
resourceString("reduce_bright_colors_preference_summary"))).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Ignore("ColorDisplayManager runs in a different thread which results in a race condition")
|
||||||
|
@Test
|
||||||
|
public void isChecked_reduceBrightColorsIsActivated_returnTrue() {
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
|
||||||
|
assertThat(mController.isChecked()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Ignore("ColorDisplayManager runs in a different thread which results in a race condition")
|
||||||
|
@Test
|
||||||
|
public void isChecked_reduceBrightColorsIsNotActivated_returnFalse() {
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0);
|
||||||
|
assertThat(mController.isChecked()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_configuredRbcAvailable_shouldReturnTrue() {
|
||||||
|
doReturn(true).when(mResources).getBoolean(
|
||||||
|
R.bool.config_reduceBrightColorsAvailable);
|
||||||
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void isAvailable_configuredRbcUnAvailable_shouldReturnFalse() {
|
||||||
|
doReturn(false).when(mResources).getBoolean(
|
||||||
|
R.bool.config_reduceBrightColorsAvailable);
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int resourceId(String type, String name) {
|
||||||
|
return mContext.getResources().getIdentifier(name, type, mContext.getPackageName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resourceString(String name) {
|
||||||
|
return mContext.getResources().getString(resourceId("string", name));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user