diff --git a/res/xml/accessibility_color_and_motion.xml b/res/xml/accessibility_color_and_motion.xml
index 1c27aaa5b81..e1cd83b3f27 100644
--- a/res/xml/accessibility_color_and_motion.xml
+++ b/res/xml/accessibility_color_and_motion.xml
@@ -14,6 +14,7 @@
limitations under the License.
-->
+
+ With catalyst, we're reusing the same preference. Will let the SettingsSearch
+ to determine how to resolve multi-entry on same preference. -->
+ settings:controller="com.android.settings.display.DarkUIPreferenceController" />
+
diff --git a/src/com/android/settings/accessibility/ColorAndMotionFragment.java b/src/com/android/settings/accessibility/ColorAndMotionFragment.java
index d5686b8a888..56bc143f17e 100644
--- a/src/com/android/settings/accessibility/ColorAndMotionFragment.java
+++ b/src/com/android/settings/accessibility/ColorAndMotionFragment.java
@@ -63,15 +63,17 @@ public class ColorAndMotionFragment extends DashboardFragment {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
- initializeAllPreferences();
- updateSystemPreferences();
- mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED);
- mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED);
+ if (!isCatalystEnabled()) {
+ initializeAllPreferences();
+ updateSystemPreferences();
+ mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED);
+ mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED);
- mSettingsContentObserver = new AccessibilitySettingsContentObserver(new Handler());
- mSettingsContentObserver.registerKeysToObserverCallback(mShortcutFeatureKeys,
- key -> updatePreferencesState());
+ mSettingsContentObserver = new AccessibilitySettingsContentObserver(new Handler());
+ mSettingsContentObserver.registerKeysToObserverCallback(mShortcutFeatureKeys,
+ key -> updatePreferencesState());
+ }
}
private void updatePreferencesState() {
@@ -84,15 +86,17 @@ public class ColorAndMotionFragment extends DashboardFragment {
@Override
public void onStart() {
super.onStart();
-
- mSettingsContentObserver.register(getContentResolver());
+ if (!isCatalystEnabled()) {
+ mSettingsContentObserver.register(getContentResolver());
+ }
}
@Override
public void onStop() {
super.onStop();
-
- mSettingsContentObserver.unregister(getContentResolver());
+ if (!isCatalystEnabled()) {
+ mSettingsContentObserver.unregister(getContentResolver());
+ }
}
@Override
@@ -116,9 +120,11 @@ public class ColorAndMotionFragment extends DashboardFragment {
/**
* Updates preferences related to system configurations.
*/
+ // LINT.IfChange(ui_hierarchy)
private void updateSystemPreferences() {
final PreferenceCategory experimentalCategory = getPreferenceScreen().findPreference(
CATEGORY_EXPERIMENTAL);
+
if (ColorDisplayManager.isColorTransformAccelerated(getContext())) {
getPreferenceScreen().removePreference(experimentalCategory);
} else {
@@ -130,6 +136,7 @@ public class ColorAndMotionFragment extends DashboardFragment {
experimentalCategory.addPreference(mToggleDisableAnimationsPreference);
}
}
+ // LINT.ThenChange(/src/com/android/settings/accessibility/ColorAndMotionScreen.kt:ui_hierarchy)
@Nullable
@Override
diff --git a/src/com/android/settings/accessibility/ColorAndMotionScreen.kt b/src/com/android/settings/accessibility/ColorAndMotionScreen.kt
index 7cb403bddf5..9d32d42673e 100644
--- a/src/com/android/settings/accessibility/ColorAndMotionScreen.kt
+++ b/src/com/android/settings/accessibility/ColorAndMotionScreen.kt
@@ -17,10 +17,15 @@
package com.android.settings.accessibility
import android.content.Context
+import android.hardware.display.ColorDisplayManager
import com.android.settings.R
import com.android.settings.Settings.ColorAndMotionActivity
+import com.android.settings.display.darkmode.DarkModeScreen
import com.android.settings.flags.Flags
import com.android.settings.utils.makeLaunchIntent
+import com.android.settingslib.metadata.PreferenceCategory
+import com.android.settingslib.metadata.PreferenceGroup
+import com.android.settingslib.metadata.PreferenceHierarchy
import com.android.settingslib.metadata.PreferenceMetadata
import com.android.settingslib.metadata.ProvidePreferenceScreen
import com.android.settingslib.metadata.preferenceHierarchy
@@ -39,14 +44,34 @@ class ColorAndMotionScreen : PreferenceScreenCreator {
override fun isFlagEnabled(context: Context) = Flags.catalystAccessibilityColorAndMotion()
- override fun hasCompleteHierarchy(): Boolean = false
+ override fun hasCompleteHierarchy(): Boolean = true
override fun fragmentClass() = ColorAndMotionFragment::class.java
- override fun getPreferenceHierarchy(context: Context) =
- preferenceHierarchy(context, this) {
- +RemoveAnimationsPreference()
+ override fun getPreferenceHierarchy(context: Context): PreferenceHierarchy {
+ // LINT.IfChange(ui_hierarchy)
+ if (ColorDisplayManager.isColorTransformAccelerated(context)) {
+ return preferenceHierarchy(context, this) {
+ +DaltonizerPreference()
+ +ColorInversionPreference()
+ +DarkModeScreen.KEY
+ +RemoveAnimationsPreference()
+ }
+ } else {
+ return preferenceHierarchy(context, this) {
+ +ColorInversionPreference()
+ +DarkModeScreen.KEY
+ +PreferenceCategory(
+ "experimental_category",
+ R.string.experimental_category_title
+ ) += {
+ +DaltonizerPreference()
+ +RemoveAnimationsPreference()
+ }
+ }
}
+ // LINT.ThenChange(/res/xml/accessibility_color_and_motion.xml, /src/com/android/settings/accessibility/ColorAndMotionFragment.java:ui_hierarchy)
+ }
override fun getLaunchIntent(context: Context, metadata: PreferenceMetadata?) =
makeLaunchIntent(context, ColorAndMotionActivity::class.java, metadata?.key)
diff --git a/src/com/android/settings/accessibility/ColorInversionPreference.kt b/src/com/android/settings/accessibility/ColorInversionPreference.kt
new file mode 100644
index 00000000000..d3b075a7331
--- /dev/null
+++ b/src/com/android/settings/accessibility/ColorInversionPreference.kt
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2025 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 android.app.settings.SettingsEnums
+import android.content.Context
+import android.provider.Settings
+import com.android.settings.R
+import com.android.settings.core.SubSettingLauncher
+import com.android.settingslib.datastore.HandlerExecutor
+import com.android.settingslib.datastore.KeyedObserver
+import com.android.settingslib.datastore.SettingsSecureStore
+import com.android.settingslib.metadata.PreferenceLifecycleContext
+import com.android.settingslib.metadata.PreferenceLifecycleProvider
+import com.android.settingslib.metadata.PreferenceMetadata
+import com.android.settingslib.metadata.PreferenceSummaryProvider
+
+class ColorInversionPreference : PreferenceMetadata, PreferenceSummaryProvider,
+ PreferenceLifecycleProvider {
+ override val key: String
+ get() = PREFERENCE_KEY
+ override val title: Int
+ get() = R.string.accessibility_display_inversion_preference_title
+
+ override val icon: Int
+ get() = R.drawable.ic_color_inversion
+
+ override val keywords: Int
+ get() = R.string.keywords_color_inversion
+
+ private var mSettingsKeyedObserver: KeyedObserver? = null
+
+ override fun intent(context: Context) =
+ SubSettingLauncher(context)
+ .setDestination(ToggleColorInversionPreferenceFragment::class.java.name)
+ .setSourceMetricsCategory(SettingsEnums.ACCESSIBILITY_COLOR_AND_MOTION)
+ .toIntent()
+
+ override fun getSummary(context: Context): CharSequence? {
+ return AccessibilityUtil.getSummary(
+ context,
+ SETTING_KEY,
+ R.string.color_inversion_state_on, R.string.color_inversion_state_off
+ )
+ }
+
+ override fun onStart(context: PreferenceLifecycleContext) {
+ val observer =
+ KeyedObserver { _, _ -> context.notifyPreferenceChange(PREFERENCE_KEY) }
+ mSettingsKeyedObserver = observer
+ val storage = SettingsSecureStore.get(context)
+ storage.addObserver(SETTING_KEY, observer, HandlerExecutor.main)
+ }
+
+ override fun onStop(context: PreferenceLifecycleContext) {
+ mSettingsKeyedObserver?.let {
+ val storage = SettingsSecureStore.get(context)
+ storage.removeObserver(SETTING_KEY, it)
+ mSettingsKeyedObserver = null
+ }
+ }
+
+ companion object {
+ const val PREFERENCE_KEY = "toggle_inversion_preference"
+ const val SETTING_KEY = Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED
+ }
+}
diff --git a/src/com/android/settings/accessibility/ColorInversionPreferenceController.java b/src/com/android/settings/accessibility/ColorInversionPreferenceController.java
index 5b20714cba4..3258c858c43 100644
--- a/src/com/android/settings/accessibility/ColorInversionPreferenceController.java
+++ b/src/com/android/settings/accessibility/ColorInversionPreferenceController.java
@@ -22,6 +22,7 @@ import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
+// LINT.IfChange
/** Controller that shows the color inversion summary. */
public class ColorInversionPreferenceController extends BasePreferenceController {
@@ -45,3 +46,4 @@ public class ColorInversionPreferenceController extends BasePreferenceController
return AVAILABLE;
}
}
+// LINT.ThenChange(/src/com/android/settings/accessibility/ColorInversionPreference.kt)
diff --git a/src/com/android/settings/accessibility/DaltonizerPreference.kt b/src/com/android/settings/accessibility/DaltonizerPreference.kt
new file mode 100644
index 00000000000..23c9b615160
--- /dev/null
+++ b/src/com/android/settings/accessibility/DaltonizerPreference.kt
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2025 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 android.app.settings.SettingsEnums
+import android.content.Context
+import android.provider.Settings
+import com.android.settings.R
+import com.android.settings.core.SubSettingLauncher
+import com.android.settingslib.datastore.HandlerExecutor
+import com.android.settingslib.datastore.KeyedObserver
+import com.android.settingslib.datastore.SettingsSecureStore
+import com.android.settingslib.metadata.PreferenceLifecycleContext
+import com.android.settingslib.metadata.PreferenceLifecycleProvider
+import com.android.settingslib.metadata.PreferenceMetadata
+import com.android.settingslib.metadata.PreferenceSummaryProvider
+
+class DaltonizerPreference : PreferenceMetadata, PreferenceSummaryProvider,
+ PreferenceLifecycleProvider {
+ override val key: String
+ get() = PREFERENCE_KEY
+
+ override val title: Int
+ get() = com.android.settingslib.R.string.accessibility_display_daltonizer_preference_title
+
+ override val icon: Int
+ get() = R.drawable.ic_daltonizer
+
+ override val keywords: Int
+ get() = R.string.keywords_color_correction
+
+ private var mSettingsKeyedObserver: KeyedObserver? = null
+
+ override fun intent(context: Context) =
+ SubSettingLauncher(context)
+ .setDestination(ToggleDaltonizerPreferenceFragment::class.java.name)
+ .setSourceMetricsCategory(SettingsEnums.ACCESSIBILITY_COLOR_AND_MOTION)
+ .toIntent()
+
+ override fun getSummary(context: Context): CharSequence? {
+ return AccessibilityUtil.getSummary(
+ context,
+ SETTING_KEY,
+ R.string.daltonizer_state_on, R.string.daltonizer_state_off
+ )
+ }
+
+ override fun onStart(context: PreferenceLifecycleContext) {
+ val observer =
+ KeyedObserver { _, _ -> context.notifyPreferenceChange(PREFERENCE_KEY) }
+ mSettingsKeyedObserver = observer
+ val storage = SettingsSecureStore.get(context)
+ storage.addObserver(SETTING_KEY, observer, HandlerExecutor.main)
+ }
+
+ override fun onStop(context: PreferenceLifecycleContext) {
+ mSettingsKeyedObserver?.let {
+ val storage = SettingsSecureStore.get(context)
+ storage.removeObserver(SETTING_KEY, it)
+ mSettingsKeyedObserver = null
+ }
+ }
+
+ companion object {
+ const val PREFERENCE_KEY = "daltonizer_preference"
+ const val SETTING_KEY = Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/accessibility/DaltonizerPreferenceController.java b/src/com/android/settings/accessibility/DaltonizerPreferenceController.java
index f89cb546630..949900b7f60 100644
--- a/src/com/android/settings/accessibility/DaltonizerPreferenceController.java
+++ b/src/com/android/settings/accessibility/DaltonizerPreferenceController.java
@@ -22,6 +22,7 @@ import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
+// LINT.IfChange
/** Controller that shows and updates the color correction summary. */
public class DaltonizerPreferenceController extends BasePreferenceController {
private static final String DALTONIZER_ENABLED =
@@ -44,3 +45,4 @@ public class DaltonizerPreferenceController extends BasePreferenceController {
R.string.daltonizer_state_on, R.string.daltonizer_state_off);
}
}
+// LINT.ThenChange(/src/com/android/settings/accessibility/DaltonizerPreference.kt)
diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
index 7c34283a5f7..93672516339 100644
--- a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
@@ -308,7 +308,10 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
getActivity().setTitle(title);
}
- protected void onProcessArguments(Bundle arguments) {
+ protected void onProcessArguments(@Nullable Bundle arguments) {
+ if (arguments == null) {
+ return;
+ }
// Key.
mPreferenceKey = arguments.getString(AccessibilitySettings.EXTRA_PREFERENCE_KEY);
@@ -432,7 +435,8 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
private void initToggleServiceSwitchPreference() {
mToggleServiceSwitchPreference = new SettingsMainSwitchPreference(getPrefContext());
mToggleServiceSwitchPreference.setKey(getUseServicePreferenceKey());
- if (getArguments().containsKey(AccessibilitySettings.EXTRA_CHECKED)) {
+ if (getArguments() != null
+ && getArguments().containsKey(AccessibilitySettings.EXTRA_CHECKED)) {
final boolean enabled = getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED);
mToggleServiceSwitchPreference.setChecked(enabled);
}
diff --git a/tests/robotests/src/com/android/settings/accessibility/ColorInversionPreferenceTest.kt b/tests/robotests/src/com/android/settings/accessibility/ColorInversionPreferenceTest.kt
new file mode 100644
index 00000000000..d1cd14b5800
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/ColorInversionPreferenceTest.kt
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2025 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 android.app.settings.SettingsEnums
+import android.content.ComponentName
+import android.content.Context
+import android.content.Intent
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settings.R
+import com.android.settings.SettingsActivity
+import com.android.settings.SubSettings
+import com.android.settings.accessibility.ColorInversionPreference.Companion.PREFERENCE_KEY
+import com.android.settings.accessibility.ColorInversionPreference.Companion.SETTING_KEY
+import com.android.settingslib.core.instrumentation.MetricsFeatureProvider
+import com.android.settingslib.datastore.SettingsSecureStore
+import com.android.settingslib.metadata.PreferenceLifecycleContext
+import com.google.common.truth.Truth.assertThat
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.kotlin.any
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.never
+import org.mockito.kotlin.times
+import org.mockito.kotlin.verify
+import org.robolectric.shadows.ShadowLooper
+
+@RunWith(AndroidJUnit4::class)
+class ColorInversionPreferenceTest {
+ private val mockLifecycleContext = mock()
+ private val appContext: Context = ApplicationProvider.getApplicationContext()
+
+ private val colorInversionPreference = ColorInversionPreference()
+
+ @Before
+ fun setUp() {
+ SettingsSecureStore.get(appContext).setInt(SETTING_KEY, AccessibilityUtil.State.OFF)
+ }
+
+ @Test
+ fun getIntent_returnColorInversionScreenIntent() {
+ val intent = colorInversionPreference.intent(appContext)
+
+ assertThat(intent).isNotNull()
+ assertThat(intent!!.action).isEqualTo(Intent.ACTION_MAIN)
+ assertThat(intent.component).isEqualTo(ComponentName(appContext, SubSettings::class.java))
+ assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(
+ ToggleColorInversionPreferenceFragment::class.java.name
+ )
+ assertThat(
+ intent.getIntExtra(
+ MetricsFeatureProvider.EXTRA_SOURCE_METRICS_CATEGORY,
+ 0
+ )
+ ).isEqualTo(
+ SettingsEnums.ACCESSIBILITY_COLOR_AND_MOTION
+ )
+ }
+
+ @Test
+ fun onStart_settingChanges_notifyPrefChange() {
+ colorInversionPreference.onStart(mockLifecycleContext)
+ SettingsSecureStore.get(appContext).setInt(SETTING_KEY, AccessibilityUtil.State.ON)
+ ShadowLooper.runUiThreadTasksIncludingDelayedTasks()
+
+ verify(mockLifecycleContext, times(1)).notifyPreferenceChange(PREFERENCE_KEY)
+ }
+
+ @Test
+ fun onStop_settingChanges_doNotNotifyPrefChange() {
+ colorInversionPreference.onStop(mockLifecycleContext)
+ SettingsSecureStore.get(appContext).setInt(SETTING_KEY, AccessibilityUtil.State.ON)
+ ShadowLooper.runUiThreadTasksIncludingDelayedTasks()
+
+ verify(mockLifecycleContext, never()).notifyPreferenceChange(any())
+ }
+
+ @Test
+ fun getSummary_colorInversionOn_verifySummary() {
+ SettingsSecureStore.get(appContext).setInt(SETTING_KEY, AccessibilityUtil.State.ON)
+
+ assertThat(colorInversionPreference.getPreferenceSummary(appContext)).isEqualTo(
+ appContext.getText(
+ R.string.color_inversion_state_on
+ )
+ )
+ }
+
+ @Test
+ fun getSummary_colorInversionOff_verifySummary() {
+ SettingsSecureStore.get(appContext).setInt(SETTING_KEY, AccessibilityUtil.State.OFF)
+
+ assertThat(colorInversionPreference.getPreferenceSummary(appContext)).isEqualTo(
+ appContext.getText(
+ R.string.color_inversion_state_off
+ )
+ )
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/accessibility/DaltonizerPreferenceTest.kt b/tests/robotests/src/com/android/settings/accessibility/DaltonizerPreferenceTest.kt
new file mode 100644
index 00000000000..c7fa70344db
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/DaltonizerPreferenceTest.kt
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2025 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 android.app.settings.SettingsEnums
+import android.content.ComponentName
+import android.content.Context
+import android.content.Intent
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.settings.R
+import com.android.settings.SettingsActivity
+import com.android.settings.SubSettings
+import com.android.settings.accessibility.DaltonizerPreference.Companion.PREFERENCE_KEY
+import com.android.settings.accessibility.DaltonizerPreference.Companion.SETTING_KEY
+import com.android.settingslib.core.instrumentation.MetricsFeatureProvider
+import com.android.settingslib.datastore.SettingsSecureStore
+import com.android.settingslib.metadata.PreferenceLifecycleContext
+import com.google.common.truth.Truth.assertThat
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.kotlin.any
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.never
+import org.mockito.kotlin.times
+import org.mockito.kotlin.verify
+import org.robolectric.shadows.ShadowLooper
+
+@RunWith(AndroidJUnit4::class)
+class DaltonizerPreferenceTest {
+ private val mockLifecycleContext = mock()
+ private val appContext: Context = ApplicationProvider.getApplicationContext()
+
+ private val daltonizerPreference = DaltonizerPreference()
+
+ @Before
+ fun setUp() {
+ SettingsSecureStore.get(appContext).setInt(SETTING_KEY, AccessibilityUtil.State.OFF)
+ }
+
+ @Test
+ fun getIntent_returnDaltonizerScreenIntent() {
+ val intent = daltonizerPreference.intent(appContext)
+
+ assertThat(intent).isNotNull()
+ assertThat(intent!!.action).isEqualTo(Intent.ACTION_MAIN)
+ assertThat(intent.component).isEqualTo(ComponentName(appContext, SubSettings::class.java))
+ assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT)).isEqualTo(
+ ToggleDaltonizerPreferenceFragment::class.java.name
+ )
+ assertThat(
+ intent.getIntExtra(
+ MetricsFeatureProvider.EXTRA_SOURCE_METRICS_CATEGORY,
+ 0
+ )
+ ).isEqualTo(
+ SettingsEnums.ACCESSIBILITY_COLOR_AND_MOTION
+ )
+ }
+
+ @Test
+ fun onStart_settingChanges_notifyPrefChange() {
+ daltonizerPreference.onStart(mockLifecycleContext)
+ SettingsSecureStore.get(appContext).setInt(SETTING_KEY, AccessibilityUtil.State.ON)
+ ShadowLooper.runUiThreadTasksIncludingDelayedTasks()
+
+ verify(mockLifecycleContext, times(1)).notifyPreferenceChange(PREFERENCE_KEY)
+ }
+
+ @Test
+ fun onStop_settingChanges_doNotNotifyPrefChange() {
+ daltonizerPreference.onStop(mockLifecycleContext)
+ SettingsSecureStore.get(appContext).setInt(SETTING_KEY, AccessibilityUtil.State.ON)
+ ShadowLooper.runUiThreadTasksIncludingDelayedTasks()
+
+ verify(mockLifecycleContext, never()).notifyPreferenceChange(any())
+ }
+
+ @Test
+ fun getSummary_daltonizerOn_verifySummary() {
+ SettingsSecureStore.get(appContext).setInt(SETTING_KEY, AccessibilityUtil.State.ON)
+
+ assertThat(daltonizerPreference.getPreferenceSummary(appContext)).isEqualTo(
+ appContext.getText(
+ R.string.daltonizer_state_on
+ )
+ )
+ }
+
+ @Test
+ fun getSummary_daltonizerOff_verifySummary() {
+ SettingsSecureStore.get(appContext).setInt(SETTING_KEY, AccessibilityUtil.State.OFF)
+
+ assertThat(daltonizerPreference.getPreferenceSummary(appContext)).isEqualTo(
+ appContext.getText(
+ R.string.daltonizer_state_off
+ )
+ )
+ }
+}