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

Commit fed0dcd9 authored by Alex Mang's avatar Alex Mang Committed by Android (Google) Code Review
Browse files

Merge "Updating feedback setting to be global"

parents c865df82 04a75fb9
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package com.android.settings.notification;

import static android.provider.Settings.Secure.NOTIFICATION_FEEDBACK_ENABLED;
import static android.provider.Settings.Global.NOTIFICATION_FEEDBACK_ENABLED;

import android.content.ContentResolver;
import android.content.Context;
@@ -82,20 +82,20 @@ public class AssistantFeedbackPreferenceController extends TogglePreferenceContr

    @Override
    public boolean isChecked() {
        return Settings.Secure.getInt(mContext.getContentResolver(),
        return Settings.Global.getInt(mContext.getContentResolver(),
                NOTIFICATION_FEEDBACK_ENABLED, OFF) == ON;
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        return Settings.Secure.putInt(mContext.getContentResolver(),
        return Settings.Global.putInt(mContext.getContentResolver(),
                NOTIFICATION_FEEDBACK_ENABLED, isChecked ? ON : OFF);
    }

    class SettingObserver extends ContentObserver {

        private final Uri NOTIFICATION_URI =
                Settings.Secure.getUriFor(NOTIFICATION_FEEDBACK_ENABLED);
                Settings.Global.getUriFor(NOTIFICATION_FEEDBACK_ENABLED);

        private final Preference mPreference;

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

package com.android.settings.notification;

import static android.provider.Settings.Secure.NOTIFICATION_FEEDBACK_ENABLED;
import static android.provider.Settings.Global.NOTIFICATION_FEEDBACK_ENABLED;

import static com.android.settings.notification.AssistantFeedbackPreferenceController.OFF;
import static com.android.settings.notification.AssistantFeedbackPreferenceController.ON;
@@ -76,7 +76,7 @@ public class AssistantFeedbackPreferenceControllerTest {
    public void updateState_preferenceSetCheckedWhenSettingIsOn() {
        final TwoStatePreference preference = mock(TwoStatePreference.class);
        final Context context = RuntimeEnvironment.application;
        Settings.Secure.putInt(context.getContentResolver(), NOTIFICATION_FEEDBACK_ENABLED, ON);
        Settings.Global.putInt(context.getContentResolver(), NOTIFICATION_FEEDBACK_ENABLED, ON);

        mController = new AssistantFeedbackPreferenceController(context, KEY);
        mController.updateState(preference);
@@ -88,7 +88,7 @@ public class AssistantFeedbackPreferenceControllerTest {
    public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
        final TwoStatePreference preference = mock(TwoStatePreference.class);
        final Context context = RuntimeEnvironment.application;
        Settings.Secure.putInt(context.getContentResolver(), NOTIFICATION_FEEDBACK_ENABLED, OFF);
        Settings.Global.putInt(context.getContentResolver(), NOTIFICATION_FEEDBACK_ENABLED, OFF);

        mController = new AssistantFeedbackPreferenceController(context, KEY);
        mController.updateState(preference);
@@ -98,24 +98,24 @@ public class AssistantFeedbackPreferenceControllerTest {

    @Test
    public void isChecked_settingIsOff_shouldReturnFalse() {
        Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_FEEDBACK_ENABLED, OFF);
        Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_FEEDBACK_ENABLED, OFF);

        assertThat(mController.isChecked()).isFalse();
    }

    @Test
    public void isChecked_settingIsOn_shouldReturnTrue() {
        Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_FEEDBACK_ENABLED, ON);
        Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_FEEDBACK_ENABLED, ON);

        assertThat(mController.isChecked()).isTrue();
    }

    @Test
    public void setChecked_setFalse_disablesSetting() {
        Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_FEEDBACK_ENABLED, ON);
        Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_FEEDBACK_ENABLED, ON);

        mController.setChecked(false);
        int updatedValue = Settings.Secure.getInt(mContext.getContentResolver(),
        int updatedValue = Settings.Global.getInt(mContext.getContentResolver(),
                NOTIFICATION_FEEDBACK_ENABLED, -1);

        assertThat(updatedValue).isEqualTo(OFF);
@@ -123,10 +123,10 @@ public class AssistantFeedbackPreferenceControllerTest {

    @Test
    public void setChecked_setTrue_enablesSetting() {
        Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_FEEDBACK_ENABLED, OFF);
        Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_FEEDBACK_ENABLED, OFF);

        mController.setChecked(true);
        int updatedValue = Settings.Secure.getInt(mContext.getContentResolver(),
        int updatedValue = Settings.Global.getInt(mContext.getContentResolver(),
                NOTIFICATION_FEEDBACK_ENABLED, -1);

        assertThat(updatedValue).isEqualTo(ON);