Merge "Fix tests" into rvc-dev am: 6d8e0fed61
am: f08d965b53
Change-Id: Ic71e492c19a700e05654cb6b1dfb526fff012e7e
This commit is contained in:
@@ -27,11 +27,6 @@
|
|||||||
<Preference
|
<Preference
|
||||||
android:key="behavior"
|
android:key="behavior"
|
||||||
android:summary="@string/important_conversation_behavior_summary"/>
|
android:summary="@string/important_conversation_behavior_summary"/>
|
||||||
<SwitchPreference
|
|
||||||
android:key="important_bubble"
|
|
||||||
android:title="@string/important_bubble"
|
|
||||||
android:icon="@drawable/ic_create_bubble"
|
|
||||||
settings:controller="com.android.settings.notification.app.ImportantConversationBubblePreferenceController"/>
|
|
||||||
<!-- Important conversations added here -->
|
<!-- Important conversations added here -->
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="important_conversations_list"
|
android:key="important_conversations_list"
|
||||||
|
@@ -43,7 +43,6 @@
|
|||||||
<Preference
|
<Preference
|
||||||
android:key="zen_mode_behavior_apps"
|
android:key="zen_mode_behavior_apps"
|
||||||
android:title="@string/zen_category_apps"
|
android:title="@string/zen_category_apps"
|
||||||
settings:controller="com.android.settings.notification.zen.ZenModeBypassingAppsPreferenceController"
|
|
||||||
android:fragment="com.android.settings.notification.zen.ZenModeBypassingAppsSettings" />
|
android:fragment="com.android.settings.notification.zen.ZenModeBypassingAppsSettings" />
|
||||||
|
|
||||||
<!-- All sounds -->
|
<!-- All sounds -->
|
||||||
|
@@ -1,71 +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.notification.app;
|
|
||||||
|
|
||||||
import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
|
|
||||||
import static android.provider.Settings.Secure.BUBBLE_IMPORTANT_CONVERSATIONS;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
|
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
|
||||||
|
|
||||||
public class ImportantConversationBubblePreferenceController extends TogglePreferenceController
|
|
||||||
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
|
|
||||||
|
|
||||||
private static final String TAG = "ImpConvBubPrefContr";
|
|
||||||
@VisibleForTesting
|
|
||||||
static final int ON = 1;
|
|
||||||
@VisibleForTesting
|
|
||||||
static final int OFF = 0;
|
|
||||||
|
|
||||||
|
|
||||||
public ImportantConversationBubblePreferenceController(Context context, String preferenceKey) {
|
|
||||||
super(context, preferenceKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isGloballyEnabled() {
|
|
||||||
return Settings.Global.getInt(mContext.getContentResolver(),
|
|
||||||
NOTIFICATION_BUBBLES, OFF) == ON;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getAvailabilityStatus() {
|
|
||||||
return isGloballyEnabled() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSliceable() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isChecked() {
|
|
||||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
|
||||||
BUBBLE_IMPORTANT_CONVERSATIONS, ON) == ON;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setChecked(boolean isChecked) {
|
|
||||||
return Settings.Secure.putInt(mContext.getContentResolver(),
|
|
||||||
BUBBLE_IMPORTANT_CONVERSATIONS, isChecked ? ON : OFF);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,140 +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.notification.app;
|
|
||||||
|
|
||||||
import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
|
|
||||||
import static android.provider.Settings.Secure.BUBBLE_IMPORTANT_CONVERSATIONS;
|
|
||||||
|
|
||||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
|
||||||
import static com.android.settings.core.BasePreferenceController.DISABLED_DEPENDENT_SETTING;
|
|
||||||
import static com.android.settings.notification.app.ImportantConversationBubblePreferenceController.OFF;
|
|
||||||
import static com.android.settings.notification.app.ImportantConversationBubblePreferenceController.ON;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
import androidx.preference.TwoStatePreference;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Answers;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class ImportantConversationBubblePreferenceControllerTest {
|
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
||||||
private Context mContext;
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
||||||
private PreferenceScreen mScreen;
|
|
||||||
|
|
||||||
private ImportantConversationBubblePreferenceController mController;
|
|
||||||
@Mock
|
|
||||||
private TwoStatePreference mPreference;
|
|
||||||
|
|
||||||
private static final String KEY = "important_bubble";
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mController = new ImportantConversationBubblePreferenceController(mContext, KEY);
|
|
||||||
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
|
|
||||||
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetAvailabilityStatus_globallyOn() {
|
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, ON);
|
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetAvailabilityStatus_globallyOff() {
|
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF);
|
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateState_preferenceSetCheckedWhenSettingIsOn() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), BUBBLE_IMPORTANT_CONVERSATIONS, ON);
|
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
|
||||||
|
|
||||||
verify(mPreference).setChecked(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), BUBBLE_IMPORTANT_CONVERSATIONS, OFF);
|
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
|
||||||
|
|
||||||
verify(mPreference).setChecked(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isChecked_settingIsOff_shouldReturnFalse() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), BUBBLE_IMPORTANT_CONVERSATIONS, OFF);
|
|
||||||
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isChecked_settingIsOn_shouldReturnTrue() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), BUBBLE_IMPORTANT_CONVERSATIONS, ON);
|
|
||||||
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setChecked_setFalse_disablesSetting() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), BUBBLE_IMPORTANT_CONVERSATIONS, ON);
|
|
||||||
|
|
||||||
mController.setChecked(false);
|
|
||||||
int updatedValue = Settings.Secure.getInt(mContext.getContentResolver(),
|
|
||||||
BUBBLE_IMPORTANT_CONVERSATIONS, -1);
|
|
||||||
|
|
||||||
assertThat(updatedValue).isEqualTo(OFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setChecked_setTrue_enablesSetting() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), BUBBLE_IMPORTANT_CONVERSATIONS, OFF);
|
|
||||||
|
|
||||||
mController.setChecked(true);
|
|
||||||
int updatedValue = Settings.Secure.getInt(mContext.getContentResolver(),
|
|
||||||
BUBBLE_IMPORTANT_CONVERSATIONS, -1);
|
|
||||||
|
|
||||||
assertThat(updatedValue).isEqualTo(ON);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isSliceable_returnsFalse() {
|
|
||||||
assertThat(mController.isSliceable()).isFalse();
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user