Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4efb1f47 authored by Angela Wang's avatar Angela Wang Committed by Automerger Merge Worker
Browse files

Merge "Updates to use flash notification settings keys in settings provider"...

Merge "Updates to use flash notification settings keys in settings provider" into udc-dev am: ccb009c3

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/21507358



Change-Id: Id824e4ebb5c9701db8af67e155d242a89c5160ea
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 1d2a29ac ccb009c3
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -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.ON;
import static com.android.settings.accessibility.FlashNotificationsUtil.SETTING_KEY_CAMERA_FLASH_NOTIFICATION;

import android.content.Context;
import android.provider.Settings;
@@ -45,13 +44,13 @@ public class CameraFlashNotificationPreferenceController extends TogglePreferenc
    @Override
    public boolean isChecked() {
        return Settings.System.getInt(mContext.getContentResolver(),
                SETTING_KEY_CAMERA_FLASH_NOTIFICATION, OFF) != OFF;
                Settings.System.CAMERA_FLASH_NOTIFICATION, OFF) != OFF;
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        return Settings.System.putInt(mContext.getContentResolver(),
                SETTING_KEY_CAMERA_FLASH_NOTIFICATION, (isChecked ? ON : OFF));
                Settings.System.CAMERA_FLASH_NOTIFICATION, (isChecked ? ON : OFF));
    }

    @Override
+2 −4
Original line number Diff line number Diff line
@@ -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.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 android.content.ContentResolver;
@@ -95,10 +93,10 @@ public class FlashNotificationsPreviewPreferenceController extends
            @NonNull Lifecycle.Event event) {
        if (event == Lifecycle.Event.ON_RESUME) {
            mContentResolver.registerContentObserver(
                    Settings.System.getUriFor(SETTING_KEY_CAMERA_FLASH_NOTIFICATION),
                    Settings.System.getUriFor(Settings.System.CAMERA_FLASH_NOTIFICATION),
                    /* notifyForDescendants= */ false, mContentObserver);
            mContentResolver.registerContentObserver(
                    Settings.System.getUriFor(SETTING_KEY_SCREEN_FLASH_NOTIFICATION),
                    Settings.System.getUriFor(Settings.System.SCREEN_FLASH_NOTIFICATION),
                    /* notifyForDescendants= */ false, mContentObserver);
        } else if (event == Lifecycle.Event.ON_PAUSE) {
            mContentResolver.unregisterContentObserver(mContentObserver);
+3 −14
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.settings.accessibility;

import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;

import android.content.Context;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCharacteristics;
@@ -43,19 +41,10 @@ class FlashNotificationsUtil {
    static final String 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_LONG_PREVIEW = 1;

    static final int DEFAULT_SCREEN_FLASH_COLOR =
            ScreenFlashNotificationColor.YELLOW.mColorInt;

    static final int DEFAULT_SCREEN_FLASH_COLOR = ScreenFlashNotificationColor.YELLOW.mColorInt;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({
@@ -128,9 +117,9 @@ class FlashNotificationsUtil {

        final boolean isTorchAvailable = FlashNotificationsUtil.isTorchAvailable(context);
        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(),
                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)
                | (isScreenFlashEnabled ? State.SCREEN : State.OFF);
+8 −9
Original line number Diff line number Diff line
@@ -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.ON;
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.graphics.Color;
@@ -59,7 +57,7 @@ public class ScreenFlashNotificationPreferenceController extends TogglePreferenc
    @Override
    public boolean isChecked() {
        return Settings.System.getInt(mContext.getContentResolver(),
                SETTING_KEY_SCREEN_FLASH_NOTIFICATION, OFF) != OFF;
                Settings.System.SCREEN_FLASH_NOTIFICATION, OFF) != OFF;
    }

    @Override
@@ -67,7 +65,7 @@ public class ScreenFlashNotificationPreferenceController extends TogglePreferenc
        if (isChecked) checkAndSetInitialColor();

        return Settings.System.putInt(mContext.getContentResolver(),
                SETTING_KEY_SCREEN_FLASH_NOTIFICATION, (isChecked ? ON : OFF));
                Settings.System.SCREEN_FLASH_NOTIFICATION, (isChecked ? ON : OFF));
    }

    @Override
@@ -79,7 +77,8 @@ public class ScreenFlashNotificationPreferenceController extends TogglePreferenc
    public CharSequence getSummary() {
        return FlashNotificationsUtil.getColorDescriptionText(mContext,
                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
@@ -94,12 +93,12 @@ public class ScreenFlashNotificationPreferenceController extends TogglePreferenc
        if (getPreferenceKey().equals(preference.getKey()) && mParentFragment != null) {

            final int initialColor = Settings.System.getInt(mContext.getContentResolver(),
                    SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR,
                    Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR,
                    DEFAULT_SCREEN_FLASH_COLOR);

            final Consumer<Integer> consumer = color -> {
                Settings.System.putInt(mContext.getContentResolver(),
                        SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR, color);
                        Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, color);
                refreshColorSummary();
            };

@@ -115,10 +114,10 @@ public class ScreenFlashNotificationPreferenceController extends TogglePreferenc

    private void checkAndSetInitialColor() {
        if (Settings.System.getInt(mContext.getContentResolver(),
                SETTING_KEY_SCREEN_FLASH_NOTIFICATION_COLOR, Color.TRANSPARENT)
                Settings.System.SCREEN_FLASH_NOTIFICATION_COLOR, Color.TRANSPARENT)
                == Color.TRANSPARENT) {
            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);
        }
    }

+12 −9
Original line number Diff line number Diff line
@@ -16,7 +16,8 @@

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.UNSUPPORTED_ON_DEVICE;

@@ -81,28 +82,30 @@ public class CameraFlashNotificationPreferenceControllerTest {

    @Test
    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();
    }

    @Test
    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();
    }

    @Test
    public void setChecked_setTrue_assertNotZero() {
    public void setChecked_setTrue_assertNotOff() {
        mController.setChecked(true);
        assertThat(Settings.System.getInt(mContentResolver, SETTING_KEY_CAMERA_FLASH_NOTIFICATION,
                0)).isNotEqualTo(0);
        assertThat(
                Settings.System.getInt(mContentResolver, Settings.System.CAMERA_FLASH_NOTIFICATION,
                        OFF)).isNotEqualTo(OFF);
    }

    @Test
    public void setChecked_setFalse_assertNotOne() {
    public void setChecked_setFalse_assertNotOn() {
        mController.setChecked(false);
        assertThat(Settings.System.getInt(mContentResolver, SETTING_KEY_CAMERA_FLASH_NOTIFICATION,
                1)).isNotEqualTo(1);
        assertThat(
                Settings.System.getInt(mContentResolver, Settings.System.CAMERA_FLASH_NOTIFICATION,
                        OFF)).isNotEqualTo(ON);
    }

    @Test
Loading