Add settings for apps that don't use full conversations
Test: make -j64 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.notification" Fixes: 155276427 Change-Id: Ie145b9cdc9555d4676a8bd225427abc9222f31c5
This commit is contained in:
@@ -8385,6 +8385,12 @@
|
||||
<!-- [CHAR LIMIT=100] Header for an individual conversation-->
|
||||
<string name="conversation_category_title">Conversation</string>
|
||||
|
||||
<!-- [CHAR LIMIT=100] Title for switch that says whether this app can appear in the conversation notification section-->
|
||||
<string name="conversation_section_switch_title">Conversation section</string>
|
||||
|
||||
<!-- [CHAR LIMIT=100] Summary for switch that says whether this app can appear in the conversation notification section-->
|
||||
<string name="conversation_section_switch_summary">Allow <xliff:g id="app">%1$s</xliff:g> to appear in the conversation section</string>
|
||||
|
||||
<!-- [CHAR LIMIT=NONE] Conversation preference summary, the parent channel this conversation was spawned from (separator) the parent channel group (e.g. an account name)-->
|
||||
<string name="notification_conversation_summary" translatable="false">"<xliff:g id="parent_category_name">%1$s</xliff:g> • <xliff:g id="parent_category_group_name">%2$s</xliff:g>"</string>
|
||||
|
||||
|
@@ -29,13 +29,6 @@
|
||||
<com.android.settings.notification.app.NotificationFooterPreference
|
||||
android:key="block_desc" />
|
||||
|
||||
<!--Bubbles -->
|
||||
<Preference
|
||||
android:key="bubble_pref_link"
|
||||
android:title="@string/notification_bubbles_title"
|
||||
android:icon="@drawable/ic_create_bubble"
|
||||
settings:controller="com.android.settings.notification.app.BubbleSummaryPreferenceController">
|
||||
</Preference>
|
||||
|
||||
<!-- Conversations added here -->
|
||||
<PreferenceCategory
|
||||
@@ -43,13 +36,28 @@
|
||||
android:key="conversations"
|
||||
android:visibility="gone"
|
||||
settings:allowDividerAbove="false"
|
||||
settings:allowDividerBelow="false" />
|
||||
settings:allowDividerBelow="false">
|
||||
<com.android.settingslib.RestrictedSwitchPreference
|
||||
android:key="invalid_conversation_switch"
|
||||
android:title="@string/conversation_section_switch_title" />
|
||||
<Preference
|
||||
android:key="invalid_conversation_info"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<!--Bubbles -->
|
||||
<Preference
|
||||
android:key="bubble_pref_link"
|
||||
android:title="@string/notification_bubbles_title"
|
||||
android:icon="@drawable/ic_create_bubble"
|
||||
settings:allowDividerAbove="false"
|
||||
settings:controller="com.android.settings.notification.app.BubbleSummaryPreferenceController">
|
||||
</Preference>
|
||||
|
||||
<!-- Channels/Channel groups added here -->
|
||||
<PreferenceCategory
|
||||
android:key="channels"
|
||||
android:layout="@layout/empty_view"
|
||||
settings:allowDividerAbove="false"
|
||||
settings:allowDividerAbove="true"
|
||||
settings:allowDividerBelow="false" />
|
||||
|
||||
<!-- Importance toggle -->
|
||||
|
@@ -268,15 +268,32 @@ public class NotificationBackend {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasSentMessage(String pkg, int uid) {
|
||||
public boolean isInInvalidMsgState(String pkg, int uid) {
|
||||
try {
|
||||
return sINM.hasSentMessage(pkg, uid);
|
||||
return sINM.isInInvalidMsgState(pkg, uid);
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Error calling NoMan", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasUserDemotedInvalidMsgApp(String pkg, int uid) {
|
||||
try {
|
||||
return sINM.hasUserDemotedInvalidMsgApp(pkg, uid);
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Error calling NoMan", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setInvalidMsgAppDemoted(String pkg, int uid, boolean isDemoted) {
|
||||
try {
|
||||
sINM.setInvalidMsgAppDemoted(pkg, uid, isDemoted);
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "Error calling NoMan", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all notification channels associated with the package and uid that will bypass DND
|
||||
*/
|
||||
|
@@ -46,7 +46,7 @@ public class AppConversationListPreferenceController extends NotificationPrefere
|
||||
|
||||
protected List<ConversationChannelWrapper> mConversations = new ArrayList<>();
|
||||
protected PreferenceCategory mPreference;
|
||||
private boolean mHasSentMsg;
|
||||
private boolean mIsInInvalidMsgState;
|
||||
|
||||
public AppConversationListPreferenceController(Context context, NotificationBackend backend) {
|
||||
super(context, backend);
|
||||
@@ -88,7 +88,7 @@ public class AppConversationListPreferenceController extends NotificationPrefere
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... unused) {
|
||||
mHasSentMsg = mBackend.hasSentMessage(mAppRow.pkg, mAppRow.uid);
|
||||
mIsInInvalidMsgState = mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid);
|
||||
ParceledListSlice<ConversationChannelWrapper> list =
|
||||
mBackend.getConversations(mAppRow.pkg, mAppRow.uid);
|
||||
if (list != null) {
|
||||
@@ -121,20 +121,10 @@ public class AppConversationListPreferenceController extends NotificationPrefere
|
||||
if (mPreference == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mIsInInvalidMsgState && !mConversations.isEmpty()) {
|
||||
// TODO: if preference has children, compare with newly loaded list
|
||||
mPreference.removeAll();
|
||||
if (mConversations.isEmpty()) {
|
||||
if (mHasSentMsg) {
|
||||
mPreference.setVisible(true);
|
||||
Preference notSupportedPref = new Preference(mContext);
|
||||
notSupportedPref.setSummary(mContext.getString(
|
||||
R.string.convo_not_supported_summary, mAppRow.label));
|
||||
mPreference.addPreference(notSupportedPref);
|
||||
} else {
|
||||
mPreference.setVisible(false);
|
||||
}
|
||||
} else {
|
||||
mPreference.setVisible(true);
|
||||
mPreference.setTitle(getTitleResId());
|
||||
populateConversations();
|
||||
}
|
||||
|
@@ -122,6 +122,8 @@ public class AppNotificationSettings extends NotificationSettings {
|
||||
mControllers.add(new DeletedChannelsPreferenceController(context, mBackend));
|
||||
mControllers.add(new ChannelListPreferenceController(context, mBackend));
|
||||
mControllers.add(new AppConversationListPreferenceController(context, mBackend));
|
||||
mControllers.add(new InvalidConversationInfoPreferenceController(context, mBackend));
|
||||
mControllers.add(new InvalidConversationPreferenceController(context, mBackend));
|
||||
mControllers.add(new BubbleSummaryPreferenceController(context, mBackend));
|
||||
return new ArrayList<>(mControllers);
|
||||
}
|
||||
|
@@ -86,7 +86,7 @@ public class BubblePreferenceController extends NotificationPreferenceController
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
if (mIsAppPage && mAppRow != null) {
|
||||
mHasSentInvalidMsg = mBackend.hasSentMessage(mAppRow.pkg, mAppRow.uid);
|
||||
mHasSentInvalidMsg = mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid);
|
||||
mNumConversations = mBackend.getConversations(
|
||||
mAppRow.pkg, mAppRow.uid).getList().size();
|
||||
// We're on the app specific bubble page which displays a tri-state
|
||||
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 android.app.NotificationChannel;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
|
||||
public class InvalidConversationInfoPreferenceController extends NotificationPreferenceController {
|
||||
|
||||
private static final String KEY = "invalid_conversation_info";
|
||||
|
||||
public InvalidConversationInfoPreferenceController(Context context,
|
||||
NotificationBackend backend) {
|
||||
super(context, backend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
if (mAppRow == null) {
|
||||
return false;
|
||||
}
|
||||
if (mAppRow.banned) {
|
||||
return false;
|
||||
}
|
||||
return mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
if (mAppRow == null) {
|
||||
return;
|
||||
}
|
||||
preference.setSummary(mContext.getString(
|
||||
R.string.convo_not_supported_summary, mAppRow.label));
|
||||
}
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 android.app.NotificationChannel;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
|
||||
public class InvalidConversationPreferenceController extends NotificationPreferenceController
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
private static final String KEY = "invalid_conversation_switch";
|
||||
|
||||
public InvalidConversationPreferenceController(Context context, NotificationBackend backend) {
|
||||
super(context, backend);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
if (mAppRow == null) {
|
||||
return false;
|
||||
}
|
||||
if (mAppRow.banned) {
|
||||
return false;
|
||||
}
|
||||
return mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
if (mAppRow == null) {
|
||||
return;
|
||||
}
|
||||
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
||||
pref.setDisabledByAdmin(mAdmin);
|
||||
pref.setEnabled(!pref.isDisabledByAdmin());
|
||||
pref.setChecked(!mBackend.hasUserDemotedInvalidMsgApp(mAppRow.pkg, mAppRow.uid));
|
||||
preference.setSummary(mContext.getString(
|
||||
R.string.conversation_section_switch_summary, mAppRow.label));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (mAppRow == null) {
|
||||
return false;
|
||||
}
|
||||
mBackend.setInvalidMsgAppDemoted(mAppRow.pkg, mAppRow.uid, !((Boolean) newValue));
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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 org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
|
||||
import org.junit.After;
|
||||
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.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = SettingsShadowResources.class)
|
||||
public class InvalidConversationInfoPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private NotificationBackend mBackend;
|
||||
@Mock
|
||||
private NotificationManager mNm;
|
||||
@Mock
|
||||
private UserManager mUm;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
private InvalidConversationInfoPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
||||
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
|
||||
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = spy(new InvalidConversationInfoPreferenceController(mContext, mBackend));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SettingsShadowResources.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoCrashIfNoOnResume() {
|
||||
mController.isAvailable();
|
||||
mController.updateState(mock(Preference.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_notIfAppBlocked() {
|
||||
when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(true);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.pkg = "hi";
|
||||
appRow.uid = 0;
|
||||
appRow.banned = true;
|
||||
mController.onResume(appRow, null, null, null, null, null);
|
||||
assertFalse(mController.isAvailable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_notIfInValidMsgState() {
|
||||
when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(false);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.pkg = "hi";
|
||||
appRow.uid = 0;
|
||||
mController.onResume(appRow, null, null, null, null, null);
|
||||
assertFalse(mController.isAvailable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable() {
|
||||
when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(true);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.pkg = "hi";
|
||||
appRow.uid = 0;
|
||||
mController.onResume(appRow, null, null, null, null, null);
|
||||
assertTrue(mController.isAvailable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState() {
|
||||
when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(true);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.pkg = "hi";
|
||||
appRow.uid = 0;
|
||||
appRow.label = "plum";
|
||||
mController.onResume(appRow, null, null, null, null, null);
|
||||
Preference pref = new Preference(mContext);
|
||||
mController.updateState(pref);
|
||||
assertTrue(pref.getSummary().toString().contains(appRow.label));
|
||||
}
|
||||
}
|
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* 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.NotificationChannel.DEFAULT_CHANNEL_ID;
|
||||
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
||||
import static android.app.NotificationManager.IMPORTANCE_HIGH;
|
||||
|
||||
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.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
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.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
|
||||
import org.junit.After;
|
||||
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.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = SettingsShadowResources.class)
|
||||
public class InvalidConversationPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private NotificationBackend mBackend;
|
||||
@Mock
|
||||
private NotificationManager mNm;
|
||||
@Mock
|
||||
private UserManager mUm;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
private InvalidConversationPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
||||
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
|
||||
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = spy(new InvalidConversationPreferenceController(mContext, mBackend));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SettingsShadowResources.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoCrashIfNoOnResume() {
|
||||
mController.isAvailable();
|
||||
mController.updateState(mock(RestrictedSwitchPreference.class));
|
||||
mController.onPreferenceChange(mock(RestrictedSwitchPreference.class), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_notIfAppBlocked() {
|
||||
when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(true);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.pkg = "hi";
|
||||
appRow.uid = 0;
|
||||
appRow.banned = true;
|
||||
mController.onResume(appRow, null, null, null, null, null);
|
||||
assertFalse(mController.isAvailable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_notIfInValidMsgState() {
|
||||
when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(false);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.pkg = "hi";
|
||||
appRow.uid = 0;
|
||||
mController.onResume(appRow, null, null, null, null, null);
|
||||
assertFalse(mController.isAvailable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable() {
|
||||
when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(true);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.pkg = "hi";
|
||||
appRow.uid = 0;
|
||||
mController.onResume(appRow, null, null, null, null, null);
|
||||
assertTrue(mController.isAvailable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_disabledByAdmin() {
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.pkg = "hi";
|
||||
appRow.uid = 0;
|
||||
mController.onResume(appRow, null, null,
|
||||
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
|
||||
|
||||
Preference pref = new RestrictedSwitchPreference(mContext);
|
||||
mController.updateState(pref);
|
||||
|
||||
assertFalse(pref.isEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_notChecked() {
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.pkg = "pkg";
|
||||
mController.onResume(appRow, null, null, null, null, null);
|
||||
|
||||
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(false);
|
||||
|
||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||
mController.updateState(pref);
|
||||
assertTrue(pref.isChecked());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_checked() {
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.pkg = "pkg";
|
||||
mController.onResume(appRow, null, null, null, null, null);
|
||||
|
||||
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(true);
|
||||
|
||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||
mController.updateState(pref);
|
||||
assertFalse(pref.isChecked());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnPreferenceChange_toggleEnabled() {
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.pkg = "pkg";
|
||||
mController.onResume(appRow, null, null, null, null, null);
|
||||
|
||||
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(true);
|
||||
|
||||
RestrictedSwitchPreference pref =
|
||||
new RestrictedSwitchPreference(mContext);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.updateState(pref);
|
||||
|
||||
mController.onPreferenceChange(pref, true);
|
||||
|
||||
verify(mBackend, times(1)).setInvalidMsgAppDemoted(any(), anyInt(), eq(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnPreferenceChange_toggleDisabled() {
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.pkg = "pkg";
|
||||
mController.onResume(appRow, null, null, null, null, null);
|
||||
|
||||
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(false);
|
||||
|
||||
RestrictedSwitchPreference pref =
|
||||
new RestrictedSwitchPreference(mContext);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.updateState(pref);
|
||||
|
||||
mController.onPreferenceChange(pref, false);
|
||||
|
||||
verify(mBackend, times(1)).setInvalidMsgAppDemoted(any(), anyInt(), eq(true));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user