Added zen settings messages and calls preferences.
- Made ZenModeSettings and ZenModeBehaviorSettings a DashboardFragment - Switches in ZenModeBehaviorSettings all have their own preference controllers - Instead of a dropdown, messages & calls have their own pages & preference controllers - Added basic turn on/off DND button in settings (dialog not yet implemented) Bug: 63077372 Fixes: 69057767 Test: make -j40 RunSettingsRoboTests Change-Id: I1c70f77053713f66f873ee578477f23cfd7985bb
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
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.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class ZenModeCallsTest {
|
||||
private ZenModeCallsSettings mCalls;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private ZenModeBackend mBackend;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private NotificationManager mNotificationManager;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
when(mActivity.getSystemService(Context.NOTIFICATION_SERVICE))
|
||||
.thenReturn(mNotificationManager);
|
||||
FakeFeatureFactory.setupForTest(mActivity);
|
||||
|
||||
mCalls = new ZenModeCallsSettings();
|
||||
mCalls.onAttach((Context)mActivity);
|
||||
|
||||
ReflectionHelpers.setField(mCalls, "mBackend", mBackend);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultKeyReturnsBasedOnZen() {
|
||||
when(mBackend.getSendersKey(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
|
||||
.thenCallRealMethod();
|
||||
when(mBackend.getZenMode()).thenReturn(Settings.Global.ZEN_MODE_NO_INTERRUPTIONS);
|
||||
assertThat(mCalls.getDefaultKey())
|
||||
.isEqualTo(mBackend.getKeyFromSetting(mBackend.SOURCE_NONE));
|
||||
|
||||
when(mBackend.getZenMode()).thenReturn(Settings.Global.ZEN_MODE_ALARMS);
|
||||
assertThat(mCalls.getDefaultKey())
|
||||
.isEqualTo(mBackend.getKeyFromSetting(mBackend.SOURCE_NONE));
|
||||
|
||||
when(mBackend.getZenMode()).thenReturn(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
||||
when(mBackend.isPriorityCategoryEnabled(
|
||||
NotificationManager.Policy.PRIORITY_CATEGORY_CALLS))
|
||||
.thenReturn(true);
|
||||
when(mBackend.getPriorityMessageSenders())
|
||||
.thenReturn(NotificationManager.Policy.PRIORITY_SENDERS_ANY);
|
||||
assertThat(mCalls.getDefaultKey())
|
||||
.isEqualTo(mBackend.getKeyFromSetting(
|
||||
NotificationManager.Policy.PRIORITY_SENDERS_ANY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAnySender() {
|
||||
String key = mBackend.getKeyFromSetting(NotificationManager.Policy.PRIORITY_SENDERS_ANY);
|
||||
mCalls.setDefaultKey(key);
|
||||
verify(mBackend).saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS,
|
||||
mBackend.getSettingFromPrefKey(key));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNoSender() {
|
||||
String key = mBackend.getKeyFromSetting(ZenModeBackend.SOURCE_NONE);
|
||||
mCalls.setDefaultKey(key);
|
||||
verify(mBackend).saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS,
|
||||
mBackend.getSettingFromPrefKey(key));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setStarredSenders() {
|
||||
String key = mBackend.getKeyFromSetting(
|
||||
NotificationManager.Policy.PRIORITY_SENDERS_STARRED);
|
||||
mCalls.setDefaultKey(key);
|
||||
verify(mBackend).saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS,
|
||||
mBackend.getSettingFromPrefKey(key));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setContactsOnlySenders() {
|
||||
String key = mBackend.getKeyFromSetting(
|
||||
NotificationManager.Policy.PRIORITY_SENDERS_CONTACTS);
|
||||
mCalls.setDefaultKey(key);
|
||||
verify(mBackend).saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS,
|
||||
mBackend.getSettingFromPrefKey(key));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user