Merge changes from topics "jr-all-convo", "jr-default-vic"
* changes: Add a default behavior setting for VICs Add screen for all conversations
This commit is contained in:
committed by
Android (Google) Code Review
commit
cb9f444849
@@ -68,7 +68,7 @@ public class AllowSoundPreferenceControllerTest {
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
@Mock
|
||||
private NotificationSettings.ImportanceListener mImportanceListener;
|
||||
private NotificationSettings.DependentFieldListener mDependentFieldListener;
|
||||
|
||||
private AllowSoundPreferenceController mController;
|
||||
|
||||
@@ -80,7 +80,7 @@ public class AllowSoundPreferenceControllerTest {
|
||||
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController =
|
||||
spy(new AllowSoundPreferenceController(mContext, mImportanceListener, mBackend));
|
||||
spy(new AllowSoundPreferenceController(mContext, mDependentFieldListener, mBackend));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -213,7 +213,7 @@ public class AllowSoundPreferenceControllerTest {
|
||||
mController.onPreferenceChange(pref, true);
|
||||
|
||||
assertEquals(IMPORTANCE_UNSPECIFIED, mController.mChannel.getImportance());
|
||||
verify(mImportanceListener, times(1)).onImportanceChanged();
|
||||
verify(mDependentFieldListener, times(1)).onFieldValueChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -232,6 +232,6 @@ public class AllowSoundPreferenceControllerTest {
|
||||
|
||||
verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
|
||||
assertEquals(IMPORTANCE_LOW, mController.mChannel.getImportance());
|
||||
verify(mImportanceListener, times(1)).onImportanceChanged();
|
||||
verify(mDependentFieldListener, times(1)).onFieldValueChanged();
|
||||
}
|
||||
}
|
||||
|
@@ -69,7 +69,7 @@ public class BlockPreferenceControllerTest {
|
||||
private UserManager mUm;
|
||||
|
||||
@Mock
|
||||
private NotificationSettings.ImportanceListener mImportanceListener;
|
||||
private NotificationSettings.DependentFieldListener mDependentFieldListener;
|
||||
|
||||
private BlockPreferenceController mController;
|
||||
@Mock
|
||||
@@ -83,7 +83,7 @@ public class BlockPreferenceControllerTest {
|
||||
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
|
||||
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = spy(new BlockPreferenceController(mContext, mImportanceListener, mBackend));
|
||||
mController = spy(new BlockPreferenceController(mContext, mDependentFieldListener, mBackend));
|
||||
mSwitch = new SwitchBar(mContext);
|
||||
when(mPreference.findViewById(R.id.switch_bar)).thenReturn(mSwitch);
|
||||
}
|
||||
|
@@ -19,12 +19,14 @@ package com.android.settings.notification.app;
|
||||
import static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
|
||||
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
||||
import static android.app.NotificationManager.IMPORTANCE_HIGH;
|
||||
import static android.provider.Settings.Secure.BUBBLE_IMPORTANT_CONVERSATIONS;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -34,6 +36,7 @@ import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -64,6 +67,8 @@ public class ConversationImportantPreferenceControllerTest {
|
||||
private UserManager mUm;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private NotificationSettings.DependentFieldListener mDependentFieldListener;
|
||||
|
||||
private ConversationImportantPreferenceController mController;
|
||||
|
||||
@@ -74,7 +79,8 @@ public class ConversationImportantPreferenceControllerTest {
|
||||
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
|
||||
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = spy(new ConversationImportantPreferenceController(mContext, mBackend));
|
||||
mController = spy(new ConversationImportantPreferenceController(
|
||||
mContext, mBackend, mDependentFieldListener));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,9 +139,12 @@ public class ConversationImportantPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testOnPreferenceChange_on() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
BUBBLE_IMPORTANT_CONVERSATIONS, 0);
|
||||
NotificationChannel channel =
|
||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
|
||||
channel.setImportantConversation(false);
|
||||
channel.setAllowBubbles(false);
|
||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
||||
|
||||
RestrictedSwitchPreference pref =
|
||||
@@ -145,14 +154,41 @@ public class ConversationImportantPreferenceControllerTest {
|
||||
mController.onPreferenceChange(pref, true);
|
||||
|
||||
assertTrue(channel.isImportantConversation());
|
||||
assertFalse(channel.canBubble());
|
||||
verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
|
||||
verify(mDependentFieldListener, never()).onFieldValueChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnPreferenceChange_on_bubble() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
BUBBLE_IMPORTANT_CONVERSATIONS, 1);
|
||||
NotificationChannel channel =
|
||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
|
||||
channel.setImportantConversation(false);
|
||||
channel.setAllowBubbles(false);
|
||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
||||
|
||||
RestrictedSwitchPreference pref =
|
||||
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||
mController.updateState(pref);
|
||||
|
||||
mController.onPreferenceChange(pref, true);
|
||||
|
||||
assertTrue(channel.isImportantConversation());
|
||||
assertTrue(channel.canBubble());
|
||||
verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
|
||||
verify(mDependentFieldListener).onFieldValueChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnPreferenceChange_off() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
BUBBLE_IMPORTANT_CONVERSATIONS, 1);
|
||||
NotificationChannel channel =
|
||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
||||
channel.setImportantConversation(true);
|
||||
channel.setAllowBubbles(false);
|
||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
||||
|
||||
RestrictedSwitchPreference pref =
|
||||
@@ -164,6 +200,8 @@ public class ConversationImportantPreferenceControllerTest {
|
||||
mController.onPreferenceChange(pref, false);
|
||||
|
||||
assertFalse(channel.isImportantConversation());
|
||||
assertFalse(channel.canBubble());
|
||||
verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
|
||||
verify(mDependentFieldListener, never()).onFieldValueChanged();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,241 @@
|
||||
/*
|
||||
* 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.app.NotificationManager.IMPORTANCE_DEFAULT;
|
||||
import static android.app.NotificationManager.IMPORTANCE_HIGH;
|
||||
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||
import static android.app.NotificationManager.IMPORTANCE_MIN;
|
||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
||||
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationChannelGroup;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.ConversationChannelWrapper;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceGroup;
|
||||
|
||||
import com.android.settings.applications.AppInfoBase;
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
|
||||
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;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ConversationListPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private NotificationBackend mBackend;
|
||||
|
||||
private TestPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new TestPreferenceController(mContext, mBackend);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPopulateList_hideIfNoConversations() {
|
||||
PreferenceCategory outerContainer = mock(PreferenceCategory.class);
|
||||
PreferenceCategory innerContainer = mock(PreferenceCategory.class);
|
||||
|
||||
mController.populateList(new ArrayList<>(), outerContainer, innerContainer);
|
||||
|
||||
verify(outerContainer).setVisible(false);
|
||||
verify(innerContainer, never()).addPreference(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPopulateList_validConversations() {
|
||||
PreferenceCategory outerContainer = mock(PreferenceCategory.class);
|
||||
PreferenceCategory innerContainer = mock(PreferenceCategory.class);
|
||||
|
||||
ConversationChannelWrapper ccw = new ConversationChannelWrapper();
|
||||
ccw.setNotificationChannel(mock(NotificationChannel.class));
|
||||
ccw.setPkg("pkg");
|
||||
ccw.setUid(1);
|
||||
ccw.setShortcutInfo(mock(ShortcutInfo.class));
|
||||
|
||||
ArrayList<ConversationChannelWrapper> list = new ArrayList<>();
|
||||
list.add(ccw);
|
||||
|
||||
mController.populateList(list, outerContainer, innerContainer);
|
||||
|
||||
verify(outerContainer).setVisible(true);
|
||||
verify(innerContainer, times(1)).addPreference(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void populateConversations() {
|
||||
PreferenceCategory container = mock(PreferenceCategory.class);
|
||||
|
||||
ConversationChannelWrapper ccw = new ConversationChannelWrapper();
|
||||
ccw.setNotificationChannel(mock(NotificationChannel.class));
|
||||
ccw.setPkg("pkg");
|
||||
ccw.setUid(1);
|
||||
ccw.setShortcutInfo(mock(ShortcutInfo.class));
|
||||
|
||||
ConversationChannelWrapper ccwDemoted = new ConversationChannelWrapper();
|
||||
NotificationChannel demoted = new NotificationChannel("a", "a", 2);
|
||||
demoted.setDemoted(true);
|
||||
ccwDemoted.setNotificationChannel(demoted);
|
||||
ccwDemoted.setPkg("pkg");
|
||||
ccwDemoted.setUid(1);
|
||||
ccwDemoted.setShortcutInfo(mock(ShortcutInfo.class));
|
||||
|
||||
ArrayList<ConversationChannelWrapper> list = new ArrayList<>();
|
||||
list.add(ccw);
|
||||
list.add(ccwDemoted);
|
||||
|
||||
mController.populateConversations(list, container);
|
||||
|
||||
verify(container, times(1)).addPreference(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_withGroup() {
|
||||
ConversationChannelWrapper ccw = new ConversationChannelWrapper();
|
||||
NotificationChannel channel = new NotificationChannel("a", "child", 2);
|
||||
ccw.setNotificationChannel(channel);
|
||||
ccw.setPkg("pkg");
|
||||
ccw.setUid(1);
|
||||
ccw.setShortcutInfo(mock(ShortcutInfo.class));
|
||||
ccw.setGroupLabel("group");
|
||||
ccw.setParentChannelLabel("parent");
|
||||
|
||||
assertThat(mController.getSummary(ccw).toString()).contains(ccw.getGroupLabel());
|
||||
assertThat(mController.getSummary(ccw).toString()).contains(ccw.getParentChannelLabel());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_noGroup() {
|
||||
ConversationChannelWrapper ccw = new ConversationChannelWrapper();
|
||||
NotificationChannel channel = new NotificationChannel("a", "child", 2);
|
||||
ccw.setNotificationChannel(channel);
|
||||
ccw.setPkg("pkg");
|
||||
ccw.setUid(1);
|
||||
ccw.setShortcutInfo(mock(ShortcutInfo.class));
|
||||
ccw.setParentChannelLabel("parent");
|
||||
|
||||
assertThat(mController.getSummary(ccw).toString()).isEqualTo(ccw.getParentChannelLabel());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTitle_withShortcut() {
|
||||
ConversationChannelWrapper ccw = new ConversationChannelWrapper();
|
||||
NotificationChannel channel = new NotificationChannel("a", "child", 2);
|
||||
ccw.setNotificationChannel(channel);
|
||||
ccw.setPkg("pkg");
|
||||
ccw.setUid(1);
|
||||
ShortcutInfo si = mock(ShortcutInfo.class);
|
||||
when(si.getShortLabel()).thenReturn("conversation name");
|
||||
ccw.setShortcutInfo(si);
|
||||
ccw.setGroupLabel("group");
|
||||
ccw.setParentChannelLabel("parent");
|
||||
|
||||
assertThat(mController.getTitle(ccw).toString()).isEqualTo(si.getShortLabel());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTitle_noShortcut() {
|
||||
ConversationChannelWrapper ccw = new ConversationChannelWrapper();
|
||||
NotificationChannel channel = new NotificationChannel("a", "child", 2);
|
||||
ccw.setNotificationChannel(channel);
|
||||
ccw.setPkg("pkg");
|
||||
ccw.setUid(1);
|
||||
ccw.setParentChannelLabel("parent");
|
||||
|
||||
assertThat(mController.getTitle(ccw).toString()).isEqualTo(
|
||||
ccw.getNotificationChannel().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetIntent() {
|
||||
ConversationChannelWrapper ccw = new ConversationChannelWrapper();
|
||||
NotificationChannel channel = new NotificationChannel("a", "child", 2);
|
||||
channel.setConversationId("parent", "convo id");
|
||||
ccw.setNotificationChannel(channel);
|
||||
ccw.setPkg("pkg");
|
||||
ccw.setUid(1);
|
||||
ccw.setParentChannelLabel("parent label");
|
||||
Intent intent = mController.getIntent(ccw, "title");
|
||||
|
||||
Bundle extras = intent.getExtras();
|
||||
assertThat(extras.getString(AppInfoBase.ARG_PACKAGE_NAME)).isEqualTo(ccw.getPkg());
|
||||
assertThat(extras.getInt(AppInfoBase.ARG_PACKAGE_UID)).isEqualTo(ccw.getUid());
|
||||
assertThat(extras.getString(Settings.EXTRA_CHANNEL_ID)).isEqualTo(
|
||||
ccw.getNotificationChannel().getId());
|
||||
assertThat(extras.getString(Settings.EXTRA_CONVERSATION_ID)).isEqualTo(
|
||||
ccw.getNotificationChannel().getConversationId());
|
||||
}
|
||||
|
||||
private final class TestPreferenceController extends ConversationListPreferenceController {
|
||||
|
||||
private TestPreferenceController(Context context, NotificationBackend backend) {
|
||||
super(context, backend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return "test";
|
||||
}
|
||||
}
|
||||
}
|
@@ -62,7 +62,7 @@ public class DefaultImportancePreferenceControllerTest {
|
||||
@Mock
|
||||
private NotificationBackend mBackend;
|
||||
@Mock
|
||||
private NotificationSettings.ImportanceListener mImportanceListener;
|
||||
private NotificationSettings.DependentFieldListener mDependentFieldListener;
|
||||
@Mock
|
||||
private UserManager mUm;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
@@ -78,7 +78,7 @@ public class DefaultImportancePreferenceControllerTest {
|
||||
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = spy(new DefaultImportancePreferenceController(
|
||||
mContext, mImportanceListener, mBackend));
|
||||
mContext, mDependentFieldListener, mBackend));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -224,7 +224,7 @@ public class DefaultImportancePreferenceControllerTest {
|
||||
mController.onPreferenceChange(pref, false);
|
||||
|
||||
assertEquals(IMPORTANCE_LOW, channel.getImportance());
|
||||
verify(mImportanceListener, times(1)).onImportanceChanged();
|
||||
verify(mDependentFieldListener, times(1)).onFieldValueChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -241,6 +241,6 @@ public class DefaultImportancePreferenceControllerTest {
|
||||
mController.onPreferenceChange(pref, true);
|
||||
|
||||
assertEquals(IMPORTANCE_DEFAULT, channel.getImportance());
|
||||
verify(mImportanceListener, times(1)).onImportanceChanged();
|
||||
verify(mDependentFieldListener, times(1)).onFieldValueChanged();
|
||||
}
|
||||
}
|
||||
|
@@ -61,7 +61,7 @@ public class HighImportancePreferenceControllerTest {
|
||||
@Mock
|
||||
private NotificationBackend mBackend;
|
||||
@Mock
|
||||
private NotificationSettings.ImportanceListener mImportanceListener;
|
||||
private NotificationSettings.DependentFieldListener mDependentFieldListener;
|
||||
@Mock
|
||||
private UserManager mUm;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
@@ -77,7 +77,7 @@ public class HighImportancePreferenceControllerTest {
|
||||
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = spy(new HighImportancePreferenceController(
|
||||
mContext, mImportanceListener, mBackend));
|
||||
mContext, mDependentFieldListener, mBackend));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -223,6 +223,6 @@ public class HighImportancePreferenceControllerTest {
|
||||
mController.onPreferenceChange(pref, false);
|
||||
|
||||
assertEquals(IMPORTANCE_DEFAULT, channel.getImportance());
|
||||
verify(mImportanceListener, times(1)).onImportanceChanged();
|
||||
verify(mDependentFieldListener, times(1)).onFieldValueChanged();
|
||||
}
|
||||
}
|
||||
|
@@ -67,7 +67,7 @@ public class ImportancePreferenceControllerTest {
|
||||
@Mock
|
||||
private NotificationBackend mBackend;
|
||||
@Mock
|
||||
private NotificationSettings.ImportanceListener mImportanceListener;
|
||||
private NotificationSettings.DependentFieldListener mDependentFieldListener;
|
||||
@Mock
|
||||
private UserManager mUm;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
@@ -83,7 +83,7 @@ public class ImportancePreferenceControllerTest {
|
||||
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = spy(new ImportancePreferenceController(
|
||||
mContext, mImportanceListener, mBackend));
|
||||
mContext, mDependentFieldListener, mBackend));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
@@ -61,7 +61,7 @@ public class MinImportancePreferenceControllerTest {
|
||||
@Mock
|
||||
private NotificationBackend mBackend;
|
||||
@Mock
|
||||
private NotificationSettings.ImportanceListener mImportanceListener;
|
||||
private NotificationSettings.DependentFieldListener mDependentFieldListener;
|
||||
@Mock
|
||||
private UserManager mUm;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
@@ -77,7 +77,7 @@ public class MinImportancePreferenceControllerTest {
|
||||
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = spy(new MinImportancePreferenceController(
|
||||
mContext, mImportanceListener, mBackend));
|
||||
mContext, mDependentFieldListener, mBackend));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -223,6 +223,6 @@ public class MinImportancePreferenceControllerTest {
|
||||
mController.onPreferenceChange(pref, true);
|
||||
|
||||
assertEquals(IMPORTANCE_MIN, channel.getImportance());
|
||||
verify(mImportanceListener, times(1)).onImportanceChanged();
|
||||
verify(mDependentFieldListener, times(1)).onFieldValueChanged();
|
||||
}
|
||||
}
|
||||
|
@@ -80,7 +80,7 @@ public class SoundPreferenceControllerTest {
|
||||
@Mock
|
||||
private SettingsPreferenceFragment mFragment;
|
||||
@Mock
|
||||
private NotificationSettings.ImportanceListener mImportanceListener;
|
||||
private NotificationSettings.DependentFieldListener mDependentFieldListener;
|
||||
|
||||
private SoundPreferenceController mController;
|
||||
|
||||
@@ -92,7 +92,7 @@ public class SoundPreferenceControllerTest {
|
||||
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = spy(new SoundPreferenceController(
|
||||
mContext, mFragment, mImportanceListener, mBackend));
|
||||
mContext, mFragment, mDependentFieldListener, mBackend));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -303,7 +303,7 @@ public class SoundPreferenceControllerTest {
|
||||
|
||||
mController.onActivityResult(SoundPreferenceController.CODE, 1, new Intent("hi"));
|
||||
verify(pref, times(1)).onActivityResult(anyInt(), anyInt(), any());
|
||||
verify(mImportanceListener, times(1)).onImportanceChanged();
|
||||
verify(mDependentFieldListener, times(1)).onFieldValueChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user