Updates to use flash notification settings keys in settings provider

Previously we hard-coded the settings key in FlashNotificationUtils. Change to use internal system settings key for retrieving flash notification settings from the database.

Bug: 266775683
Test: make RunSettingsRoboTests ROBOTEST_FILTER=CameraFlashNotificationPreferenceControllerTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=ScreenFlashNotificationPreferenceControllerTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=FlashNotificationsPreviewPreferenceControllerTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=FlashNotificationsUtilTest
Change-Id: I1e7a0c4ed58505cfb3c06e43af866744fa1b2d41
This commit is contained in:
Angela Wang
2023-02-15 03:00:24 +00:00
parent 410fa6cfc5
commit aa54f1b32b
8 changed files with 58 additions and 72 deletions

View File

@@ -18,7 +18,6 @@ package com.android.settings.accessibility;
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.FlashNotificationsUtil.SETTING_KEY_CAMERA_FLASH_NOTIFICATION;
import android.content.Context; import android.content.Context;
import android.provider.Settings; import android.provider.Settings;
@@ -45,13 +44,13 @@ public class CameraFlashNotificationPreferenceController extends TogglePreferenc
@Override @Override
public boolean isChecked() { public boolean isChecked() {
return Settings.System.getInt(mContext.getContentResolver(), return Settings.System.getInt(mContext.getContentResolver(),
SETTING_KEY_CAMERA_FLASH_NOTIFICATION, OFF) != OFF; Settings.System.CAMERA_FLASH_NOTIFICATION, OFF) != OFF;
} }
@Override @Override
public boolean setChecked(boolean isChecked) { public boolean setChecked(boolean isChecked) {
return Settings.System.putInt(mContext.getContentResolver(), return Settings.System.putInt(mContext.getContentResolver(),
SETTING_KEY_CAMERA_FLASH_NOTIFICATION, (isChecked ? ON : OFF)); Settings.System.CAMERA_FLASH_NOTIFICATION, (isChecked ? ON : OFF));
} }
@Override @Override

View File

@@ -19,8 +19,6 @@ package com.android.settings.accessibility;
import static com.android.settings.accessibility.FlashNotificationsUtil.ACTION_FLASH_NOTIFICATION_START_PREVIEW; import static com.android.settings.accessibility.FlashNotificationsUtil.ACTION_FLASH_NOTIFICATION_START_PREVIEW;
import static com.android.settings.accessibility.FlashNotificationsUtil.EXTRA_FLASH_NOTIFICATION_PREVIEW_TYPE; import static com.android.settings.accessibility.FlashNotificationsUtil.EXTRA_FLASH_NOTIFICATION_PREVIEW_TYPE;
import static com.android.settings.accessibility.FlashNotificationsUtil.SETTING_KEY_CAMERA_FLASH_NOTIFICATION;
import static com.android.settings.accessibility.FlashNotificationsUtil.SETTING_KEY_SCREEN_FLASH_NOTIFICATION;
import static com.android.settings.accessibility.FlashNotificationsUtil.TYPE_SHORT_PREVIEW; import static com.android.settings.accessibility.FlashNotificationsUtil.TYPE_SHORT_PREVIEW;
import android.content.ContentResolver; import android.content.ContentResolver;
@@ -95,10 +93,10 @@ public class FlashNotificationsPreviewPreferenceController extends
@NonNull Lifecycle.Event event) { @NonNull Lifecycle.Event event) {
if (event == Lifecycle.Event.ON_RESUME) { if (event == Lifecycle.Event.ON_RESUME) {
mContentResolver.registerContentObserver( mContentResolver.registerContentObserver(
Settings.System.getUriFor(SETTING_KEY_CAMERA_FLASH_NOTIFICATION), Settings.System.getUriFor(Settings.System.CAMERA_FLASH_NOTIFICATION),
/* notifyForDescendants= */ false, mContentObserver); /* notifyForDescendants= */ false, mContentObserver);
mContentResolver.registerContentObserver( mContentResolver.registerContentObserver(
Settings.System.getUriFor(SETTING_KEY_SCREEN_FLASH_NOTIFICATION), Settings.System.getUriFor(Settings.System.SCREEN_FLASH_NOTIFICATION),
/* notifyForDescendants= */ false, mContentObserver); /* notifyForDescendants= */ false, mContentObserver);
} else if (event == Lifecycle.Event.ON_PAUSE) { } else if (event == Lifecycle.Event.ON_PAUSE) {
mContentResolver.unregisterContentObserver(mContentObserver); mContentResolver.unregisterContentObserver(mContentObserver);

View File

@@ -16,8 +16,6 @@
package com.android.settings.accessibility; package com.android.settings.accessibility;
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
import android.content.Context; import android.content.Context;
import android.hardware.camera2.CameraAccessException; import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCharacteristics; import android.hardware.camera2.CameraCharacteristics;
@@ -43,19 +41,10 @@ class FlashNotificationsUtil {
static final String EXTRA_FLASH_NOTIFICATION_PREVIEW_TYPE = static final String EXTRA_FLASH_NOTIFICATION_PREVIEW_TYPE =
"com.android.internal.intent.extra.FLASH_NOTIFICATION_PREVIEW_TYPE"; "com.android.internal.intent.extra.FLASH_NOTIFICATION_PREVIEW_TYPE";
static final String SETTING_KEY_CAMERA_FLASH_NOTIFICATION =
"camera_flash_notification";
static final String SETTING_KEY_SCREEN_FLASH_NOTIFICATION =
"screen_flash_notification";
static final String SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR =
"screen_flash_notification_color_global";
static final int TYPE_SHORT_PREVIEW = 0; static final int TYPE_SHORT_PREVIEW = 0;
static final int TYPE_LONG_PREVIEW = 1; static final int TYPE_LONG_PREVIEW = 1;
static final int DEFAULT_SCREEN_FLASH_COLOR = static final int DEFAULT_SCREEN_FLASH_COLOR = ScreenFlashNotificationColor.YELLOW.mColorInt;
ScreenFlashNotificationColor.YELLOW.mColorInt;
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@IntDef({ @IntDef({
@@ -128,9 +117,9 @@ class FlashNotificationsUtil {
final boolean isTorchAvailable = FlashNotificationsUtil.isTorchAvailable(context); final boolean isTorchAvailable = FlashNotificationsUtil.isTorchAvailable(context);
final boolean isCameraFlashEnabled = Settings.System.getInt(context.getContentResolver(), final boolean isCameraFlashEnabled = Settings.System.getInt(context.getContentResolver(),
SETTING_KEY_CAMERA_FLASH_NOTIFICATION, State.OFF) != State.OFF; Settings.System.CAMERA_FLASH_NOTIFICATION, State.OFF) != State.OFF;
final boolean isScreenFlashEnabled = Settings.System.getInt(context.getContentResolver(), final boolean isScreenFlashEnabled = Settings.System.getInt(context.getContentResolver(),
SETTING_KEY_SCREEN_FLASH_NOTIFICATION, State.OFF) != State.OFF; Settings.System.SCREEN_FLASH_NOTIFICATION, State.OFF) != State.OFF;
return ((isTorchAvailable && isCameraFlashEnabled) ? State.CAMERA : State.OFF) return ((isTorchAvailable && isCameraFlashEnabled) ? State.CAMERA : State.OFF)
| (isScreenFlashEnabled ? State.SCREEN : State.OFF); | (isScreenFlashEnabled ? State.SCREEN : State.OFF);

View File

@@ -19,8 +19,6 @@ package com.android.settings.accessibility;
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.FlashNotificationsUtil.DEFAULT_SCREEN_FLASH_COLOR; import static com.android.settings.accessibility.FlashNotificationsUtil.DEFAULT_SCREEN_FLASH_COLOR;
import static com.android.settings.accessibility.FlashNotificationsUtil.SETTING_KEY_SCREEN_FLASH_NOTIFICATION;
import static com.android.settings.accessibility.FlashNotificationsUtil.SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR;
import android.content.Context; import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
@@ -59,7 +57,7 @@ public class ScreenFlashNotificationPreferenceController extends TogglePreferenc
@Override @Override
public boolean isChecked() { public boolean isChecked() {
return Settings.System.getInt(mContext.getContentResolver(), return Settings.System.getInt(mContext.getContentResolver(),
SETTING_KEY_SCREEN_FLASH_NOTIFICATION, OFF) != OFF; Settings.System.SCREEN_FLASH_NOTIFICATION, OFF) != OFF;
} }
@Override @Override
@@ -67,7 +65,7 @@ public class ScreenFlashNotificationPreferenceController extends TogglePreferenc
if (isChecked) checkAndSetInitialColor(); if (isChecked) checkAndSetInitialColor();
return Settings.System.putInt(mContext.getContentResolver(), return Settings.System.putInt(mContext.getContentResolver(),
SETTING_KEY_SCREEN_FLASH_NOTIFICATION, (isChecked ? ON : OFF)); Settings.System.SCREEN_FLASH_NOTIFICATION, (isChecked ? ON : OFF));
} }
@Override @Override
@@ -79,7 +77,8 @@ public class ScreenFlashNotificationPreferenceController extends TogglePreferenc
public CharSequence getSummary() { public CharSequence getSummary() {
return FlashNotificationsUtil.getColorDescriptionText(mContext, return FlashNotificationsUtil.getColorDescriptionText(mContext,
Settings.System.getInt(mContext.getContentResolver(), Settings.System.getInt(mContext.getContentResolver(),
SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR, DEFAULT_SCREEN_FLASH_COLOR)); Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR,
DEFAULT_SCREEN_FLASH_COLOR));
} }
@Override @Override
@@ -94,12 +93,12 @@ public class ScreenFlashNotificationPreferenceController extends TogglePreferenc
if (getPreferenceKey().equals(preference.getKey()) && mParentFragment != null) { if (getPreferenceKey().equals(preference.getKey()) && mParentFragment != null) {
final int initialColor = Settings.System.getInt(mContext.getContentResolver(), final int initialColor = Settings.System.getInt(mContext.getContentResolver(),
SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR, Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR,
DEFAULT_SCREEN_FLASH_COLOR); DEFAULT_SCREEN_FLASH_COLOR);
final Consumer<Integer> consumer = color -> { final Consumer<Integer> consumer = color -> {
Settings.System.putInt(mContext.getContentResolver(), Settings.System.putInt(mContext.getContentResolver(),
SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR, color); Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, color);
refreshColorSummary(); refreshColorSummary();
}; };
@@ -115,10 +114,10 @@ public class ScreenFlashNotificationPreferenceController extends TogglePreferenc
private void checkAndSetInitialColor() { private void checkAndSetInitialColor() {
if (Settings.System.getInt(mContext.getContentResolver(), if (Settings.System.getInt(mContext.getContentResolver(),
SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR, Color.TRANSPARENT) Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, Color.TRANSPARENT)
== Color.TRANSPARENT) { == Color.TRANSPARENT) {
Settings.System.putInt(mContext.getContentResolver(), Settings.System.putInt(mContext.getContentResolver(),
SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR, DEFAULT_SCREEN_FLASH_COLOR); Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, DEFAULT_SCREEN_FLASH_COLOR);
} }
} }

View File

@@ -16,7 +16,8 @@
package com.android.settings.accessibility; package com.android.settings.accessibility;
import static com.android.settings.accessibility.FlashNotificationsUtil.SETTING_KEY_CAMERA_FLASH_NOTIFICATION; import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
import static com.android.settings.core.BasePreferenceController.AVAILABLE; import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE; import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
@@ -81,28 +82,30 @@ public class CameraFlashNotificationPreferenceControllerTest {
@Test @Test
public void isChecked_setOff_assertFalse() { public void isChecked_setOff_assertFalse() {
Settings.System.putInt(mContentResolver, SETTING_KEY_CAMERA_FLASH_NOTIFICATION, 0); Settings.System.putInt(mContentResolver, Settings.System.CAMERA_FLASH_NOTIFICATION, OFF);
assertThat(mController.isChecked()).isFalse(); assertThat(mController.isChecked()).isFalse();
} }
@Test @Test
public void isChecked_setOn_assertTrue() { public void isChecked_setOn_assertTrue() {
Settings.System.putInt(mContentResolver, SETTING_KEY_CAMERA_FLASH_NOTIFICATION, 1); Settings.System.putInt(mContentResolver, Settings.System.CAMERA_FLASH_NOTIFICATION, ON);
assertThat(mController.isChecked()).isTrue(); assertThat(mController.isChecked()).isTrue();
} }
@Test @Test
public void setChecked_setTrue_assertNotZero() { public void setChecked_setTrue_assertNotOff() {
mController.setChecked(true); mController.setChecked(true);
assertThat(Settings.System.getInt(mContentResolver, SETTING_KEY_CAMERA_FLASH_NOTIFICATION, assertThat(
0)).isNotEqualTo(0); Settings.System.getInt(mContentResolver, Settings.System.CAMERA_FLASH_NOTIFICATION,
OFF)).isNotEqualTo(OFF);
} }
@Test @Test
public void setChecked_setFalse_assertNotOne() { public void setChecked_setFalse_assertNotOn() {
mController.setChecked(false); mController.setChecked(false);
assertThat(Settings.System.getInt(mContentResolver, SETTING_KEY_CAMERA_FLASH_NOTIFICATION, assertThat(
1)).isNotEqualTo(1); Settings.System.getInt(mContentResolver, Settings.System.CAMERA_FLASH_NOTIFICATION,
OFF)).isNotEqualTo(ON);
} }
@Test @Test

View File

@@ -18,8 +18,6 @@ package com.android.settings.accessibility;
import static com.android.settings.accessibility.FlashNotificationsUtil.ACTION_FLASH_NOTIFICATION_START_PREVIEW; import static com.android.settings.accessibility.FlashNotificationsUtil.ACTION_FLASH_NOTIFICATION_START_PREVIEW;
import static com.android.settings.accessibility.FlashNotificationsUtil.EXTRA_FLASH_NOTIFICATION_PREVIEW_TYPE; import static com.android.settings.accessibility.FlashNotificationsUtil.EXTRA_FLASH_NOTIFICATION_PREVIEW_TYPE;
import static com.android.settings.accessibility.FlashNotificationsUtil.SETTING_KEY_CAMERA_FLASH_NOTIFICATION;
import static com.android.settings.accessibility.FlashNotificationsUtil.SETTING_KEY_SCREEN_FLASH_NOTIFICATION;
import static com.android.settings.accessibility.FlashNotificationsUtil.TYPE_LONG_PREVIEW; import static com.android.settings.accessibility.FlashNotificationsUtil.TYPE_LONG_PREVIEW;
import static com.android.settings.accessibility.FlashNotificationsUtil.TYPE_SHORT_PREVIEW; import static com.android.settings.accessibility.FlashNotificationsUtil.TYPE_SHORT_PREVIEW;
import static com.android.settings.accessibility.ShadowFlashNotificationsUtils.setFlashNotificationsState; import static com.android.settings.accessibility.ShadowFlashNotificationsUtils.setFlashNotificationsState;
@@ -48,7 +46,6 @@ import androidx.test.core.app.ApplicationProvider;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@@ -131,7 +128,6 @@ public class FlashNotificationsPreviewPreferenceControllerTest {
verify(mPreference).setEnabled(eq(true)); verify(mPreference).setEnabled(eq(true));
} }
@Ignore
@Test @Test
public void testHandlePreferenceTreeClick_invalidPreference() { public void testHandlePreferenceTreeClick_invalidPreference() {
mController.handlePreferenceTreeClick(mock(Preference.class)); mController.handlePreferenceTreeClick(mock(Preference.class));
@@ -165,16 +161,16 @@ public class FlashNotificationsPreviewPreferenceControllerTest {
public void onStateChanged_onResume_cameraUri_verifyRegister() { public void onStateChanged_onResume_cameraUri_verifyRegister() {
mController.onStateChanged(mock(LifecycleOwner.class), Lifecycle.Event.ON_RESUME); mController.onStateChanged(mock(LifecycleOwner.class), Lifecycle.Event.ON_RESUME);
verify(mContentResolver).registerContentObserver( verify(mContentResolver).registerContentObserver(
eq(Settings.System.getUriFor(SETTING_KEY_CAMERA_FLASH_NOTIFICATION)), anyBoolean(), eq(Settings.System.getUriFor(Settings.System.CAMERA_FLASH_NOTIFICATION)),
eq(mController.mContentObserver)); anyBoolean(), eq(mController.mContentObserver));
} }
@Test @Test
public void onStateChanged_onResume_screenUri_verifyRegister() { public void onStateChanged_onResume_screenUri_verifyRegister() {
mController.onStateChanged(mock(LifecycleOwner.class), Lifecycle.Event.ON_RESUME); mController.onStateChanged(mock(LifecycleOwner.class), Lifecycle.Event.ON_RESUME);
verify(mContentResolver).registerContentObserver( verify(mContentResolver).registerContentObserver(
eq(Settings.System.getUriFor(SETTING_KEY_SCREEN_FLASH_NOTIFICATION)), anyBoolean(), eq(Settings.System.getUriFor(Settings.System.SCREEN_FLASH_NOTIFICATION)),
eq(mController.mContentObserver)); anyBoolean(), eq(mController.mContentObserver));
} }
@Test @Test

View File

@@ -21,8 +21,8 @@ import static android.hardware.camera2.CameraCharacteristics.LENS_FACING;
import static android.hardware.camera2.CameraCharacteristics.LENS_FACING_BACK; import static android.hardware.camera2.CameraCharacteristics.LENS_FACING_BACK;
import static android.hardware.camera2.CameraMetadata.LENS_FACING_FRONT; import static android.hardware.camera2.CameraMetadata.LENS_FACING_FRONT;
import static com.android.settings.accessibility.FlashNotificationsUtil.SETTING_KEY_CAMERA_FLASH_NOTIFICATION; import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.FlashNotificationsUtil.SETTING_KEY_SCREEN_FLASH_NOTIFICATION; import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
import static com.android.settings.accessibility.FlashNotificationsUtil.getColorDescriptionText; import static com.android.settings.accessibility.FlashNotificationsUtil.getColorDescriptionText;
import static com.android.settings.accessibility.FlashNotificationsUtil.getFlashNotificationsState; import static com.android.settings.accessibility.FlashNotificationsUtil.getFlashNotificationsState;
import static com.android.settings.accessibility.FlashNotificationsUtil.getScreenColor; import static com.android.settings.accessibility.FlashNotificationsUtil.getScreenColor;
@@ -156,8 +156,8 @@ public class FlashNotificationsUtilTest {
@Test @Test
public void getFlashNotificationsState_torchPresent_cameraOff_screenOff_assertOff() { public void getFlashNotificationsState_torchPresent_cameraOff_screenOff_assertOff() {
setTorchPresent(); setTorchPresent();
Settings.System.putInt(mContentResolver, SETTING_KEY_CAMERA_FLASH_NOTIFICATION, 0); Settings.System.putInt(mContentResolver, Settings.System.CAMERA_FLASH_NOTIFICATION, OFF);
Settings.System.putInt(mContentResolver, SETTING_KEY_SCREEN_FLASH_NOTIFICATION, 0); Settings.System.putInt(mContentResolver, Settings.System.SCREEN_FLASH_NOTIFICATION, OFF);
assertThat(getFlashNotificationsState(mContext)) assertThat(getFlashNotificationsState(mContext))
.isEqualTo(FlashNotificationsUtil.State.OFF); .isEqualTo(FlashNotificationsUtil.State.OFF);
@@ -166,8 +166,8 @@ public class FlashNotificationsUtilTest {
@Test @Test
public void getFlashNotificationsState_torchNotPresent_cameraOn_screenOff_assertOff() { public void getFlashNotificationsState_torchNotPresent_cameraOn_screenOff_assertOff() {
setTorchNotPresent(); setTorchNotPresent();
Settings.System.putInt(mContentResolver, SETTING_KEY_CAMERA_FLASH_NOTIFICATION, 1); Settings.System.putInt(mContentResolver, Settings.System.CAMERA_FLASH_NOTIFICATION, ON);
Settings.System.putInt(mContentResolver, SETTING_KEY_SCREEN_FLASH_NOTIFICATION, 0); Settings.System.putInt(mContentResolver, Settings.System.SCREEN_FLASH_NOTIFICATION, OFF);
assertThat(getFlashNotificationsState(mContext)) assertThat(getFlashNotificationsState(mContext))
.isEqualTo(FlashNotificationsUtil.State.OFF); .isEqualTo(FlashNotificationsUtil.State.OFF);
@@ -176,8 +176,8 @@ public class FlashNotificationsUtilTest {
@Test @Test
public void getFlashNotificationsState_torchPresent_cameraOn_screenOff_assertCamera() { public void getFlashNotificationsState_torchPresent_cameraOn_screenOff_assertCamera() {
setTorchPresent(); setTorchPresent();
Settings.System.putInt(mContentResolver, SETTING_KEY_CAMERA_FLASH_NOTIFICATION, 1); Settings.System.putInt(mContentResolver, Settings.System.CAMERA_FLASH_NOTIFICATION, ON);
Settings.System.putInt(mContentResolver, SETTING_KEY_SCREEN_FLASH_NOTIFICATION, 0); Settings.System.putInt(mContentResolver, Settings.System.SCREEN_FLASH_NOTIFICATION, OFF);
assertThat(getFlashNotificationsState(mContext)) assertThat(getFlashNotificationsState(mContext))
.isEqualTo(FlashNotificationsUtil.State.CAMERA); .isEqualTo(FlashNotificationsUtil.State.CAMERA);
@@ -186,8 +186,8 @@ public class FlashNotificationsUtilTest {
@Test @Test
public void getFlashNotificationsState_torchPresent_cameraOff_screenOn_assertScreen() { public void getFlashNotificationsState_torchPresent_cameraOff_screenOn_assertScreen() {
setTorchPresent(); setTorchPresent();
Settings.System.putInt(mContentResolver, SETTING_KEY_CAMERA_FLASH_NOTIFICATION, 0); Settings.System.putInt(mContentResolver, Settings.System.CAMERA_FLASH_NOTIFICATION, OFF);
Settings.System.putInt(mContentResolver, SETTING_KEY_SCREEN_FLASH_NOTIFICATION, 1); Settings.System.putInt(mContentResolver, Settings.System.SCREEN_FLASH_NOTIFICATION, ON);
assertThat(getFlashNotificationsState(mContext)) assertThat(getFlashNotificationsState(mContext))
.isEqualTo(FlashNotificationsUtil.State.SCREEN); .isEqualTo(FlashNotificationsUtil.State.SCREEN);
@@ -196,8 +196,8 @@ public class FlashNotificationsUtilTest {
@Test @Test
public void testGetFlashNotificationsState_torchPresent_cameraOn_screenOn_assertCameraScreen() { public void testGetFlashNotificationsState_torchPresent_cameraOn_screenOn_assertCameraScreen() {
setTorchPresent(); setTorchPresent();
Settings.System.putInt(mContentResolver, SETTING_KEY_CAMERA_FLASH_NOTIFICATION, 1); Settings.System.putInt(mContentResolver, Settings.System.CAMERA_FLASH_NOTIFICATION, ON);
Settings.System.putInt(mContentResolver, SETTING_KEY_SCREEN_FLASH_NOTIFICATION, 1); Settings.System.putInt(mContentResolver, Settings.System.SCREEN_FLASH_NOTIFICATION, ON);
assertThat(getFlashNotificationsState(mContext)) assertThat(getFlashNotificationsState(mContext))
.isEqualTo(FlashNotificationsUtil.State.CAMERA_SCREEN); .isEqualTo(FlashNotificationsUtil.State.CAMERA_SCREEN);

View File

@@ -16,9 +16,9 @@
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 static com.android.settings.accessibility.FlashNotificationsUtil.DEFAULT_SCREEN_FLASH_COLOR; import static com.android.settings.accessibility.FlashNotificationsUtil.DEFAULT_SCREEN_FLASH_COLOR;
import static com.android.settings.accessibility.FlashNotificationsUtil.SETTING_KEY_SCREEN_FLASH_NOTIFICATION;
import static com.android.settings.accessibility.FlashNotificationsUtil.SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR;
import static com.android.settings.core.BasePreferenceController.AVAILABLE; import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@@ -114,48 +114,50 @@ public class ScreenFlashNotificationPreferenceControllerTest {
@Test @Test
public void isChecked_setOff_assertFalse() { public void isChecked_setOff_assertFalse() {
Settings.System.putInt(mContentResolver, SETTING_KEY_SCREEN_FLASH_NOTIFICATION, 0); Settings.System.putInt(mContentResolver, Settings.System.SCREEN_FLASH_NOTIFICATION, OFF);
assertThat(mController.isChecked()).isFalse(); assertThat(mController.isChecked()).isFalse();
} }
@Test @Test
public void isChecked_setOn_assertTrue() { public void isChecked_setOn_assertTrue() {
Settings.System.putInt(mContentResolver, SETTING_KEY_SCREEN_FLASH_NOTIFICATION, 1); Settings.System.putInt(mContentResolver, Settings.System.SCREEN_FLASH_NOTIFICATION, ON);
assertThat(mController.isChecked()).isTrue(); assertThat(mController.isChecked()).isTrue();
} }
@Test @Test
public void setChecked_whenTransparentColor_setTrue_assertNotTransparentColor() { public void setChecked_whenTransparentColor_setTrue_assertNotTransparentColor() {
Settings.System.putInt(mContentResolver, Settings.System.putInt(mContentResolver,
SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR, Color.TRANSPARENT); Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, Color.TRANSPARENT);
mController.setChecked(true); mController.setChecked(true);
assertThat(Settings.System.getInt(mContentResolver, assertThat(Settings.System.getInt(mContentResolver,
SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR, 0)) Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, 0)).isEqualTo(
.isEqualTo(DEFAULT_SCREEN_FLASH_COLOR); DEFAULT_SCREEN_FLASH_COLOR);
} }
@Test @Test
public void setChecked_whenNotTransparent_setTrue_assertSameColor() { public void setChecked_whenNotTransparent_setTrue_assertSameColor() {
Settings.System.putInt(mContentResolver, Settings.System.putInt(mContentResolver,
SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR, 0x4D0000FF); Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, 0x4D0000FF);
mController.setChecked(true); mController.setChecked(true);
assertThat(Settings.System.getInt(mContentResolver, assertThat(Settings.System.getInt(mContentResolver,
SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR, 0)) Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, 0))
.isEqualTo(0x4D0000FF); .isEqualTo(0x4D0000FF);
} }
@Test @Test
public void setChecked_setTrue_assertOn() { public void setChecked_setTrue_assertOn() {
mController.setChecked(true); mController.setChecked(true);
assertThat(Settings.System.getInt(mContentResolver, SETTING_KEY_SCREEN_FLASH_NOTIFICATION, assertThat(
0)).isEqualTo(1); Settings.System.getInt(mContentResolver, Settings.System.SCREEN_FLASH_NOTIFICATION,
OFF)).isEqualTo(ON);
} }
@Test @Test
public void setChecked_setFalse_assertOff() { public void setChecked_setFalse_assertOff() {
mController.setChecked(false); mController.setChecked(false);
assertThat(Settings.System.getInt(mContentResolver, SETTING_KEY_SCREEN_FLASH_NOTIFICATION, assertThat(
1)).isEqualTo(0); Settings.System.getInt(mContentResolver, Settings.System.SCREEN_FLASH_NOTIFICATION,
OFF)).isEqualTo(OFF);
} }
@Test @Test