Merge "Add filtering to notification channel settings" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
6c70707655
@@ -65,11 +65,6 @@
|
|||||||
android:summary="@string/promote_conversation_summary"
|
android:summary="@string/promote_conversation_summary"
|
||||||
settings:allowDividerAbove="true"/>
|
settings:allowDividerAbove="true"/>
|
||||||
|
|
||||||
<PreferenceCategory
|
|
||||||
android:key="channel_advanced"
|
|
||||||
android:order="50"
|
|
||||||
settings:initialExpandedChildrenCount="0">
|
|
||||||
|
|
||||||
<!-- Default ringtone -->
|
<!-- Default ringtone -->
|
||||||
<com.android.settings.notification.app.NotificationSoundPreference
|
<com.android.settings.notification.app.NotificationSoundPreference
|
||||||
android:key="ringtone"
|
android:key="ringtone"
|
||||||
@@ -120,7 +115,6 @@
|
|||||||
android:order="18"
|
android:order="18"
|
||||||
android:title="@string/app_settings_link"
|
android:title="@string/app_settings_link"
|
||||||
settings:allowDividerAbove="true"/>
|
settings:allowDividerAbove="true"/>
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
<com.android.settings.notification.app.NotificationFooterPreference
|
<com.android.settings.notification.app.NotificationFooterPreference
|
||||||
android:key="desc"
|
android:key="desc"
|
||||||
|
@@ -32,7 +32,6 @@ import android.view.View;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceCategory;
|
|
||||||
import androidx.preference.PreferenceViewHolder;
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -67,8 +66,10 @@ public class AppBubbleListPreferenceController extends AppConversationListPrefer
|
|||||||
@Nullable NotificationChannel channel, @Nullable NotificationChannelGroup group,
|
@Nullable NotificationChannel channel, @Nullable NotificationChannelGroup group,
|
||||||
Drawable conversationDrawable,
|
Drawable conversationDrawable,
|
||||||
ShortcutInfo conversationInfo,
|
ShortcutInfo conversationInfo,
|
||||||
RestrictedLockUtils.EnforcedAdmin admin) {
|
RestrictedLockUtils.EnforcedAdmin admin,
|
||||||
super.onResume(appRow, channel, group, conversationDrawable, conversationInfo, admin);
|
List<String> preferenceFilter) {
|
||||||
|
super.onResume(appRow, channel, group, conversationDrawable, conversationInfo, admin,
|
||||||
|
preferenceFilter);
|
||||||
// In case something changed in the foreground (e.g. via bubble button on notification)
|
// In case something changed in the foreground (e.g. via bubble button on notification)
|
||||||
loadConversationsAndPopulate();
|
loadConversationsAndPopulate();
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.app;
|
package com.android.settings.notification.app;
|
||||||
|
|
||||||
|
import android.app.NotificationChannel;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
|
||||||
@@ -47,6 +48,11 @@ public class AddToHomeScreenPreferenceController extends NotificationPreferenceC
|
|||||||
return mConversationInfo != null;
|
return mConversationInfo != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_LAUNCHER);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
if (KEY.equals(preference.getKey())) {
|
if (KEY.equals(preference.getKey())) {
|
||||||
|
@@ -58,6 +58,11 @@ public class AllowSoundPreferenceController extends NotificationPreferenceContro
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_SOUND);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
|
@@ -90,7 +90,7 @@ public class AppBubbleNotificationSettings extends NotificationSettings implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (NotificationPreferenceController controller : mControllers) {
|
for (NotificationPreferenceController controller : mControllers) {
|
||||||
controller.onResume(mAppRow, null, null, null, null, mSuspendedAppsAdmin);
|
controller.onResume(mAppRow, null, null, null, null, mSuspendedAppsAdmin, null);
|
||||||
controller.displayPreference(getPreferenceScreen());
|
controller.displayPreference(getPreferenceScreen());
|
||||||
}
|
}
|
||||||
updatePreferenceStates();
|
updatePreferenceStates();
|
||||||
|
@@ -114,6 +114,11 @@ public class AppChannelsBypassingDndPreferenceController extends NotificationPre
|
|||||||
return mAppRow != null;
|
return mAppRow != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow != null) {
|
if (mAppRow != null) {
|
||||||
|
@@ -53,7 +53,7 @@ public class AppChannelsBypassingDndSettings extends NotificationSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (NotificationPreferenceController controller : mControllers) {
|
for (NotificationPreferenceController controller : mControllers) {
|
||||||
controller.onResume(mAppRow, null, null, null, null, mSuspendedAppsAdmin);
|
controller.onResume(mAppRow, null, null, null, null, mSuspendedAppsAdmin, null);
|
||||||
controller.displayPreference(getPreferenceScreen());
|
controller.displayPreference(getPreferenceScreen());
|
||||||
}
|
}
|
||||||
updatePreferenceStates();
|
updatePreferenceStates();
|
||||||
|
@@ -74,6 +74,11 @@ public class AppConversationListPreferenceController extends NotificationPrefere
|
|||||||
mAppRow.pkg, mAppRow.uid);
|
mAppRow.pkg, mAppRow.uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
mPreference = (PreferenceCategory) preference;
|
mPreference = (PreferenceCategory) preference;
|
||||||
|
@@ -48,6 +48,11 @@ public class AppLinkPreferenceController extends NotificationPreferenceControlle
|
|||||||
return mAppRow.settingsIntent != null;
|
return mAppRow.settingsIntent != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow != null) {
|
if (mAppRow != null) {
|
||||||
preference.setIntent(mAppRow.settingsIntent);
|
preference.setIntent(mAppRow.settingsIntent);
|
||||||
|
@@ -79,7 +79,8 @@ public class AppNotificationSettings extends NotificationSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (NotificationPreferenceController controller : mControllers) {
|
for (NotificationPreferenceController controller : mControllers) {
|
||||||
controller.onResume(mAppRow, mChannel, mChannelGroup, null, null, mSuspendedAppsAdmin);
|
controller.onResume(mAppRow, mChannel, mChannelGroup, null, null, mSuspendedAppsAdmin,
|
||||||
|
null);
|
||||||
controller.displayPreference(getPreferenceScreen());
|
controller.displayPreference(getPreferenceScreen());
|
||||||
}
|
}
|
||||||
updatePreferenceStates();
|
updatePreferenceStates();
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.settings.notification.app;
|
|||||||
|
|
||||||
import static android.provider.Settings.Secure.NOTIFICATION_BADGING;
|
import static android.provider.Settings.Secure.NOTIFICATION_BADGING;
|
||||||
|
|
||||||
|
import android.app.NotificationChannel;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
@@ -67,6 +68,11 @@ public class BadgePreferenceController extends NotificationPreferenceController
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_LAUNCHER);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow != null) {
|
if (mAppRow != null) {
|
||||||
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
||||||
|
@@ -20,6 +20,7 @@ import static android.app.NotificationManager.IMPORTANCE_LOW;
|
|||||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
||||||
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
|
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
|
||||||
|
|
||||||
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.widget.Switch;
|
import android.widget.Switch;
|
||||||
@@ -55,9 +56,17 @@ public class BlockPreferenceController extends NotificationPreferenceController
|
|||||||
if (mAppRow == null) {
|
if (mAppRow == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (mPreferenceFilter != null && !isIncludedInFilter()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_IMPORTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
SettingsMainSwitchPreference bar = (SettingsMainSwitchPreference) preference;
|
SettingsMainSwitchPreference bar = (SettingsMainSwitchPreference) preference;
|
||||||
if (bar != null) {
|
if (bar != null) {
|
||||||
|
@@ -43,6 +43,11 @@ public class BubbleCategoryPreferenceController extends NotificationPreferenceCo
|
|||||||
return areBubblesEnabled();
|
return areBubblesEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return KEY;
|
return KEY;
|
||||||
|
@@ -43,6 +43,11 @@ public class BubbleLinkPreferenceController extends NotificationPreferenceContro
|
|||||||
return areBubblesEnabled();
|
return areBubblesEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return KEY;
|
return KEY;
|
||||||
|
@@ -21,6 +21,7 @@ import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
|
|||||||
|
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
|
import android.app.NotificationChannel;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
@@ -84,6 +85,11 @@ public class BubblePreferenceController extends NotificationPreferenceController
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_CONVERSATION);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mIsAppPage && mAppRow != null) {
|
if (mIsAppPage && mAppRow != null) {
|
||||||
|
@@ -66,6 +66,11 @@ public class BubbleSummaryPreferenceController extends NotificationPreferenceCon
|
|||||||
return isGloballyEnabled() && mBackend.hasSentValidMsg(mAppRow.pkg, mAppRow.uid);
|
return isGloballyEnabled() && mBackend.hasSentValidMsg(mAppRow.pkg, mAppRow.uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return KEY;
|
return KEY;
|
||||||
|
@@ -84,6 +84,11 @@ public class ChannelListPreferenceController extends NotificationPreferenceContr
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
mPreference = (PreferenceCategory) preference;
|
mPreference = (PreferenceCategory) preference;
|
||||||
|
@@ -79,7 +79,8 @@ public class ChannelNotificationSettings extends NotificationSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (NotificationPreferenceController controller : mControllers) {
|
for (NotificationPreferenceController controller : mControllers) {
|
||||||
controller.onResume(mAppRow, mChannel, mChannelGroup, null, null, mSuspendedAppsAdmin);
|
controller.onResume(mAppRow, mChannel, mChannelGroup, null, null, mSuspendedAppsAdmin,
|
||||||
|
mPreferenceFilter);
|
||||||
controller.displayPreference(getPreferenceScreen());
|
controller.displayPreference(getPreferenceScreen());
|
||||||
}
|
}
|
||||||
updatePreferenceStates();
|
updatePreferenceStates();
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.app;
|
package com.android.settings.notification.app;
|
||||||
|
|
||||||
|
import android.app.NotificationChannel;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
@@ -56,6 +57,11 @@ public class ConversationDemotePreferenceController extends NotificationPreferen
|
|||||||
return !TextUtils.isEmpty(mChannel.getConversationId()) && !mChannel.isDemoted();
|
return !TextUtils.isEmpty(mChannel.getConversationId()) && !mChannel.isDemoted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_CONVERSATION);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
preference.setEnabled(mAdmin == null);
|
preference.setEnabled(mAdmin == null);
|
||||||
}
|
}
|
||||||
|
@@ -59,6 +59,11 @@ public class ConversationHeaderPreferenceController extends NotificationPreferen
|
|||||||
return mAppRow != null;
|
return mAppRow != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow != null && mFragment != null) {
|
if (mAppRow != null && mFragment != null) {
|
||||||
|
@@ -49,7 +49,7 @@ public class ConversationNotificationSettings extends NotificationSettings {
|
|||||||
|
|
||||||
for (NotificationPreferenceController controller : mControllers) {
|
for (NotificationPreferenceController controller : mControllers) {
|
||||||
controller.onResume(mAppRow, mChannel, mChannelGroup, mConversationDrawable,
|
controller.onResume(mAppRow, mChannel, mChannelGroup, mConversationDrawable,
|
||||||
mConversationInfo, mSuspendedAppsAdmin);
|
mConversationInfo, mSuspendedAppsAdmin, null);
|
||||||
controller.displayPreference(getPreferenceScreen());
|
controller.displayPreference(getPreferenceScreen());
|
||||||
}
|
}
|
||||||
updatePreferenceStates();
|
updatePreferenceStates();
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.app;
|
package com.android.settings.notification.app;
|
||||||
|
|
||||||
|
import android.app.NotificationChannel;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
@@ -53,6 +54,12 @@ public class ConversationPriorityPreferenceController extends NotificationPrefer
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_IMPORTANCE)
|
||||||
|
|| mPreferenceFilter.contains(NotificationChannel.EDIT_CONVERSATION);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow != null) {
|
if (mAppRow != null) {
|
||||||
preference.setEnabled(mAdmin == null && !mChannel.isImportanceLockedByOEM());
|
preference.setEnabled(mAdmin == null && !mChannel.isImportanceLockedByOEM());
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.app;
|
package com.android.settings.notification.app;
|
||||||
|
|
||||||
|
import android.app.NotificationChannel;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
@@ -56,6 +57,11 @@ public class ConversationPromotePreferenceController extends NotificationPrefere
|
|||||||
return !TextUtils.isEmpty(mChannel.getConversationId()) && mChannel.isDemoted();
|
return !TextUtils.isEmpty(mChannel.getConversationId()) && mChannel.isDemoted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_CONVERSATION);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
preference.setEnabled(mAdmin == null);
|
preference.setEnabled(mAdmin == null);
|
||||||
}
|
}
|
||||||
|
@@ -51,6 +51,11 @@ public class DeletedChannelsPreferenceController extends NotificationPreferenceC
|
|||||||
return mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid) > 0;
|
return mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow != null) {
|
if (mAppRow != null) {
|
||||||
int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid);
|
int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid);
|
||||||
|
@@ -54,6 +54,11 @@ public class DescriptionPreferenceController extends NotificationPreferenceContr
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow != null) {
|
if (mAppRow != null) {
|
||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
|
@@ -47,6 +47,11 @@ public class DndPreferenceController extends NotificationPreferenceController
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_ZEN);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
||||||
|
@@ -59,6 +59,11 @@ public class HeaderPreferenceController extends NotificationPreferenceController
|
|||||||
return mAppRow != null;
|
return mAppRow != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow != null && mFragment != null) {
|
if (mAppRow != null && mFragment != null) {
|
||||||
|
@@ -22,12 +22,12 @@ import static android.app.NotificationManager.IMPORTANCE_HIGH;
|
|||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settings.notification.NotificationBackend;
|
import com.android.settings.notification.NotificationBackend;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
|
|
||||||
public class HighImportancePreferenceController extends NotificationPreferenceController
|
public class HighImportancePreferenceController extends NotificationPreferenceController
|
||||||
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
|
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
@@ -60,6 +60,11 @@ public class HighImportancePreferenceController extends NotificationPreferenceCo
|
|||||||
return mChannel.getImportance() >= IMPORTANCE_DEFAULT;
|
return mChannel.getImportance() >= IMPORTANCE_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_IMPORTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow != null && mChannel != null) {
|
if (mAppRow != null && mChannel != null) {
|
||||||
|
@@ -58,6 +58,11 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
|
|||||||
return !isDefaultChannel();
|
return !isDefaultChannel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_IMPORTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow!= null && mChannel != null) {
|
if (mAppRow!= null && mChannel != null) {
|
||||||
|
@@ -47,9 +47,17 @@ public class InvalidConversationInfoPreferenceController extends NotificationPre
|
|||||||
if (mAppRow.banned) {
|
if (mAppRow.banned) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (mPreferenceFilter != null && !isIncludedInFilter()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid);
|
return mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_CONVERSATION);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow == null) {
|
if (mAppRow == null) {
|
||||||
|
@@ -47,9 +47,17 @@ public class InvalidConversationPreferenceController extends NotificationPrefere
|
|||||||
if (mAppRow.banned) {
|
if (mAppRow.banned) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (mPreferenceFilter != null && !isIncludedInFilter()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid);
|
return mBackend.isInInvalidMsgState(mAppRow.pkg, mAppRow.uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_CONVERSATION);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow == null) {
|
if (mAppRow == null) {
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.app;
|
package com.android.settings.notification.app;
|
||||||
|
|
||||||
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -53,6 +54,11 @@ public class LightsPreferenceController extends NotificationPreferenceController
|
|||||||
&& !isDefaultChannel();
|
&& !isDefaultChannel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_LOCKED_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
||||||
|
@@ -60,6 +60,11 @@ public class MinImportancePreferenceController extends NotificationPreferenceCon
|
|||||||
return mChannel.getImportance() <= IMPORTANCE_LOW;
|
return mChannel.getImportance() <= IMPORTANCE_LOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_IMPORTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow != null && mChannel != null) {
|
if (mAppRow != null && mChannel != null) {
|
||||||
|
@@ -36,6 +36,7 @@ import com.android.settingslib.RestrictedLockUtils;
|
|||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,6 +61,7 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
|
|||||||
protected Drawable mConversationDrawable;
|
protected Drawable mConversationDrawable;
|
||||||
@Nullable
|
@Nullable
|
||||||
protected ShortcutInfo mConversationInfo;
|
protected ShortcutInfo mConversationInfo;
|
||||||
|
protected List<String> mPreferenceFilter;
|
||||||
|
|
||||||
public NotificationPreferenceController(Context context, NotificationBackend backend) {
|
public NotificationPreferenceController(Context context, NotificationBackend backend) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -87,6 +89,9 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
|
if (mPreferenceFilter != null && !isIncludedInFilter()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return mChannel.getImportance() != IMPORTANCE_NONE;
|
return mChannel.getImportance() != IMPORTANCE_NONE;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -96,15 +101,19 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
|
|||||||
@Nullable NotificationChannel channel, @Nullable NotificationChannelGroup group,
|
@Nullable NotificationChannel channel, @Nullable NotificationChannelGroup group,
|
||||||
Drawable conversationDrawable,
|
Drawable conversationDrawable,
|
||||||
ShortcutInfo conversationInfo,
|
ShortcutInfo conversationInfo,
|
||||||
RestrictedLockUtils.EnforcedAdmin admin) {
|
RestrictedLockUtils.EnforcedAdmin admin,
|
||||||
|
List<String> preferenceFilter) {
|
||||||
mAppRow = appRow;
|
mAppRow = appRow;
|
||||||
mChannel = channel;
|
mChannel = channel;
|
||||||
mChannelGroup = group;
|
mChannelGroup = group;
|
||||||
mAdmin = admin;
|
mAdmin = admin;
|
||||||
mConversationDrawable = conversationDrawable;
|
mConversationDrawable = conversationDrawable;
|
||||||
mConversationInfo = conversationInfo;
|
mConversationInfo = conversationInfo;
|
||||||
|
mPreferenceFilter = preferenceFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract boolean isIncludedInFilter();
|
||||||
|
|
||||||
protected boolean checkCanBeVisible(int minImportanceVisible) {
|
protected boolean checkCanBeVisible(int minImportanceVisible) {
|
||||||
if (mChannel == null) {
|
if (mChannel == null) {
|
||||||
Log.w(TAG, "No channel");
|
Log.w(TAG, "No channel");
|
||||||
|
@@ -74,6 +74,7 @@ abstract public class NotificationSettings extends DashboardFragment {
|
|||||||
protected NotificationBackend.AppRow mAppRow;
|
protected NotificationBackend.AppRow mAppRow;
|
||||||
protected Drawable mConversationDrawable;
|
protected Drawable mConversationDrawable;
|
||||||
protected ShortcutInfo mConversationInfo;
|
protected ShortcutInfo mConversationInfo;
|
||||||
|
protected List<String> mPreferenceFilter;
|
||||||
|
|
||||||
protected boolean mShowLegacyChannelConfig = false;
|
protected boolean mShowLegacyChannelConfig = false;
|
||||||
protected boolean mListeningToPackageRemove;
|
protected boolean mListeningToPackageRemove;
|
||||||
@@ -119,6 +120,7 @@ abstract public class NotificationSettings extends DashboardFragment {
|
|||||||
loadChannel();
|
loadChannel();
|
||||||
loadAppRow();
|
loadAppRow();
|
||||||
loadChannelGroup();
|
loadChannelGroup();
|
||||||
|
loadPreferencesFilter();
|
||||||
collectConfigActivities();
|
collectConfigActivities();
|
||||||
|
|
||||||
if (use(HeaderPreferenceController.class) != null) {
|
if (use(HeaderPreferenceController.class) != null) {
|
||||||
@@ -131,7 +133,7 @@ abstract public class NotificationSettings extends DashboardFragment {
|
|||||||
|
|
||||||
for (NotificationPreferenceController controller : mControllers) {
|
for (NotificationPreferenceController controller : mControllers) {
|
||||||
controller.onResume(mAppRow, mChannel, mChannelGroup, null, null,
|
controller.onResume(mAppRow, mChannel, mChannelGroup, null, null,
|
||||||
mSuspendedAppsAdmin);
|
mSuspendedAppsAdmin, mPreferenceFilter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,9 +183,17 @@ abstract public class NotificationSettings extends DashboardFragment {
|
|||||||
loadChannel();
|
loadChannel();
|
||||||
loadConversation();
|
loadConversation();
|
||||||
loadChannelGroup();
|
loadChannelGroup();
|
||||||
|
loadPreferencesFilter();
|
||||||
collectConfigActivities();
|
collectConfigActivities();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadPreferencesFilter() {
|
||||||
|
Intent intent = getActivity().getIntent();
|
||||||
|
mPreferenceFilter = intent != null
|
||||||
|
? intent.getStringArrayListExtra(Settings.EXTRA_CHANNEL_FILTER_LIST)
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
private void loadChannel() {
|
private void loadChannel() {
|
||||||
Intent intent = getActivity().getIntent();
|
Intent intent = getActivity().getIntent();
|
||||||
String channelId = intent != null ? intent.getStringExtra(Settings.EXTRA_CHANNEL_ID) : null;
|
String channelId = intent != null ? intent.getStringExtra(Settings.EXTRA_CHANNEL_ID) : null;
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.app;
|
package com.android.settings.notification.app;
|
||||||
|
|
||||||
|
import android.app.NotificationChannel;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
@@ -42,11 +43,19 @@ public class NotificationsOffPreferenceController extends NotificationPreference
|
|||||||
if (mAppRow == null) {
|
if (mAppRow == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (mPreferenceFilter != null && !isIncludedInFilter()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// Available only when other controllers are unavailable - this UI replaces the UI that
|
// Available only when other controllers are unavailable - this UI replaces the UI that
|
||||||
// would give more detailed notification controls.
|
// would give more detailed notification controls.
|
||||||
return !super.isAvailable();
|
return !super.isAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_IMPORTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow != null) {
|
if (mAppRow != null) {
|
||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
|
@@ -68,6 +68,11 @@ public class SoundPreferenceController extends NotificationPreferenceController
|
|||||||
return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) && !isDefaultChannel();
|
return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) && !isDefaultChannel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_SOUND);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.app;
|
package com.android.settings.notification.app;
|
||||||
|
|
||||||
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
@@ -54,6 +55,11 @@ public class VibrationPreferenceController extends NotificationPreferenceControl
|
|||||||
&& mVibrator.hasVibrator();
|
&& mVibrator.hasVibrator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_VIBRATION);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
||||||
|
@@ -68,6 +68,11 @@ public class VisibilityPreferenceController extends NotificationPreferenceContro
|
|||||||
return checkCanBeVisible(NotificationManager.IMPORTANCE_LOW) && isLockScreenSecure();
|
return checkCanBeVisible(NotificationManager.IMPORTANCE_LOW) && isLockScreenSecure();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return mPreferenceFilter.contains(NotificationChannel.EDIT_LOCKED_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mChannel != null && mAppRow != null) {
|
if (mChannel != null && mAppRow != null) {
|
||||||
RestrictedListPreference pref = (RestrictedListPreference) preference;
|
RestrictedListPreference pref = (RestrictedListPreference) preference;
|
||||||
|
@@ -22,7 +22,9 @@ import static org.mockito.ArgumentMatchers.any;
|
|||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.NotificationChannel;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ShortcutInfo;
|
import android.content.pm.ShortcutInfo;
|
||||||
|
|
||||||
@@ -30,6 +32,8 @@ import androidx.preference.Preference;
|
|||||||
|
|
||||||
import com.android.settings.notification.NotificationBackend;
|
import com.android.settings.notification.NotificationBackend;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -38,12 +42,16 @@ import org.mockito.MockitoAnnotations;
|
|||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class AddToHomeScreenPreferenceControllerTest {
|
public class AddToHomeScreenPreferenceControllerTest {
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@Mock
|
@Mock
|
||||||
private NotificationBackend mBackend;
|
private NotificationBackend mBackend;
|
||||||
|
@Mock
|
||||||
|
private NotificationChannel mNc;
|
||||||
|
|
||||||
private AddToHomeScreenPreferenceController mController;
|
private AddToHomeScreenPreferenceController mController;
|
||||||
|
|
||||||
@@ -52,6 +60,7 @@ public class AddToHomeScreenPreferenceControllerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
mController = new AddToHomeScreenPreferenceController(mContext, mBackend);
|
mController = new AddToHomeScreenPreferenceController(mContext, mBackend);
|
||||||
|
when(mNc.getImportance()).thenReturn(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -62,21 +71,41 @@ public class AddToHomeScreenPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_notIfNull() {
|
public void testIsAvailable_notIfNull() {
|
||||||
mController.onResume(null, null, null, null, null, null);
|
mController.onResume(null, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable() {
|
public void testIsAvailable() {
|
||||||
ShortcutInfo si = mock(ShortcutInfo.class);
|
ShortcutInfo si = mock(ShortcutInfo.class);
|
||||||
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, si, null);
|
mController.onResume(mock(NotificationBackend.AppRow.class),
|
||||||
|
mNc, null, null, si, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredIn() {
|
||||||
|
ShortcutInfo si = mock(ShortcutInfo.class);
|
||||||
|
mController.onResume(mock(NotificationBackend.AppRow.class),
|
||||||
|
mNc, null, null, si, null,
|
||||||
|
ImmutableList.of(NotificationChannel.EDIT_LAUNCHER));
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredOut() {
|
||||||
|
ShortcutInfo si = mock(ShortcutInfo.class);
|
||||||
|
mController.onResume(mock(NotificationBackend.AppRow.class),
|
||||||
|
mNc, null, null, si, null, new ArrayList<>());
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandlePreferenceTreeClick() {
|
public void testHandlePreferenceTreeClick() {
|
||||||
ShortcutInfo si = mock(ShortcutInfo.class);
|
ShortcutInfo si = mock(ShortcutInfo.class);
|
||||||
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, si, null);
|
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, si, null,
|
||||||
|
null);
|
||||||
|
|
||||||
Preference pref = new Preference(RuntimeEnvironment.application);
|
Preference pref = new Preference(RuntimeEnvironment.application);
|
||||||
pref.setKey("add_to_home");
|
pref.setKey("add_to_home");
|
||||||
|
@@ -44,6 +44,8 @@ import com.android.settings.notification.NotificationBackend;
|
|||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -54,6 +56,8 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class AllowSoundPreferenceControllerTest {
|
public class AllowSoundPreferenceControllerTest {
|
||||||
|
|
||||||
@@ -92,10 +96,11 @@ public class AllowSoundPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_notIfNull() {
|
public void testIsAvailable_notIfNull() {
|
||||||
mController.onResume(null, mock(NotificationChannel.class), null, null, null, null);
|
mController.onResume(null, mock(NotificationChannel.class), null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
|
|
||||||
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, null, null);
|
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, null, null,
|
||||||
|
null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +108,7 @@ public class AllowSoundPreferenceControllerTest {
|
|||||||
public void testIsAvailable_notIfAppBlocked() {
|
public void testIsAvailable_notIfAppBlocked() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
|
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +117,7 @@ public class AllowSoundPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn("something new");
|
when(channel.getId()).thenReturn("something new");
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,16 +127,37 @@ public class AllowSoundPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredIn() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
|
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null, ImmutableList.of(
|
||||||
|
NotificationChannel.EDIT_SOUND));
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredOut() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
|
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_disabledByAdmin() {
|
public void testUpdateState_disabledByAdmin() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn("something");
|
when(channel.getId()).thenReturn("something");
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
||||||
RestrictedLockUtils.EnforcedAdmin.class));
|
RestrictedLockUtils.EnforcedAdmin.class), null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext);
|
Preference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -145,7 +171,7 @@ public class AllowSoundPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn("");
|
when(channel.getId()).thenReturn("");
|
||||||
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext);
|
Preference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -158,7 +184,7 @@ public class AllowSoundPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn("something");
|
when(channel.getId()).thenReturn("something");
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext);
|
Preference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -170,7 +196,8 @@ public class AllowSoundPreferenceControllerTest {
|
|||||||
public void testUpdateState_checkedForHighImportanceChannel() {
|
public void testUpdateState_checkedForHighImportanceChannel() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -181,7 +208,8 @@ public class AllowSoundPreferenceControllerTest {
|
|||||||
public void testUpdateState_checkedForUnspecifiedImportanceChannel() {
|
public void testUpdateState_checkedForUnspecifiedImportanceChannel() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_UNSPECIFIED);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_UNSPECIFIED);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -192,7 +220,8 @@ public class AllowSoundPreferenceControllerTest {
|
|||||||
public void testUpdateState_notCheckedForLowImportanceChannel() {
|
public void testUpdateState_notCheckedForLowImportanceChannel() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -203,7 +232,8 @@ public class AllowSoundPreferenceControllerTest {
|
|||||||
public void testOnPreferenceChange_on() {
|
public void testOnPreferenceChange_on() {
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
@@ -220,7 +250,8 @@ public class AllowSoundPreferenceControllerTest {
|
|||||||
public void testOnPreferenceChange_off() {
|
public void testOnPreferenceChange_off() {
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
|
@@ -104,7 +104,7 @@ public class AppBubbleListPreferenceControllerTest {
|
|||||||
public void isAvailable_BUBBLE_PREFERENCE_NONE_false() {
|
public void isAvailable_BUBBLE_PREFERENCE_NONE_false() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ public class AppBubbleListPreferenceControllerTest {
|
|||||||
public void isAvailable_BUBBLE_PREFERENCE_SELECTED_true() {
|
public void isAvailable_BUBBLE_PREFERENCE_SELECTED_true() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
@@ -122,7 +122,7 @@ public class AppBubbleListPreferenceControllerTest {
|
|||||||
public void isAvailable_BUBBLE_PREFERENCE_ALL_true() {
|
public void isAvailable_BUBBLE_PREFERENCE_ALL_true() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ public class AppBubbleListPreferenceControllerTest {
|
|||||||
public void filterAndSortConversations_BUBBLE_PREFERENCE_SELECTED_filtersAllowedBubbles() {
|
public void filterAndSortConversations_BUBBLE_PREFERENCE_SELECTED_filtersAllowedBubbles() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
List<ConversationChannelWrapper> result =
|
List<ConversationChannelWrapper> result =
|
||||||
mController.filterAndSortConversations(mConvoList.getList());
|
mController.filterAndSortConversations(mConvoList.getList());
|
||||||
@@ -144,7 +144,7 @@ public class AppBubbleListPreferenceControllerTest {
|
|||||||
public void filterAndSortConversations_BUBBLE_PREFERENCE_ALL_filtersExcludedBubbles() {
|
public void filterAndSortConversations_BUBBLE_PREFERENCE_ALL_filtersExcludedBubbles() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
List<ConversationChannelWrapper> result =
|
List<ConversationChannelWrapper> result =
|
||||||
mController.filterAndSortConversations(mConvoList.getList());
|
mController.filterAndSortConversations(mConvoList.getList());
|
||||||
@@ -158,7 +158,7 @@ public class AppBubbleListPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
||||||
appRow.pkg = "PKG";
|
appRow.pkg = "PKG";
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
mController.mPreference = new PreferenceCategory(mContext);
|
mController.mPreference = new PreferenceCategory(mContext);
|
||||||
|
|
||||||
ConversationChannelWrapper ccw = mConvoList.getList().get(0);
|
ConversationChannelWrapper ccw = mConvoList.getList().get(0);
|
||||||
|
@@ -75,7 +75,7 @@ public class AppLinkPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_notIfNull() {
|
public void testIsAvailable_notIfNull() {
|
||||||
mController.onResume(null, null, null, null, null, null);
|
mController.onResume(null, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ public class AppLinkPreferenceControllerTest {
|
|||||||
public void testIsAvailable_notIfAppBlocked() {
|
public void testIsAvailable_notIfAppBlocked() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ public class AppLinkPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ public class AppLinkPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,16 +113,21 @@ public class AppLinkPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_alwaysFiltered() {
|
||||||
|
assertFalse(mController.isIncludedInFilter());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState() {
|
public void testUpdateState() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
Intent intent = new Intent("action");
|
Intent intent = new Intent("action");
|
||||||
appRow.settingsIntent = intent;
|
appRow.settingsIntent = intent;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new Preference(RuntimeEnvironment.application);
|
Preference pref = new Preference(RuntimeEnvironment.application);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
@@ -47,6 +47,8 @@ import com.android.settings.notification.NotificationBackend;
|
|||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -57,6 +59,9 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class BadgePreferenceControllerTest {
|
public class BadgePreferenceControllerTest {
|
||||||
|
|
||||||
@@ -93,7 +98,7 @@ public class BadgePreferenceControllerTest {
|
|||||||
public void testIsAvailable_notIfAppBlocked() {
|
public void testIsAvailable_notIfAppBlocked() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
|
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +107,7 @@ public class BadgePreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +117,7 @@ public class BadgePreferenceControllerTest {
|
|||||||
appRow.showBadge = false;
|
appRow.showBadge = false;
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
@@ -122,7 +127,7 @@ public class BadgePreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 0);
|
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 0);
|
||||||
|
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
@@ -131,7 +136,7 @@ public class BadgePreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_app() {
|
public void testIsAvailable_app() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
|
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
|
||||||
|
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
@@ -144,7 +149,7 @@ public class BadgePreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
|
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
|
||||||
|
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
@@ -156,7 +161,7 @@ public class BadgePreferenceControllerTest {
|
|||||||
appRow.showBadge = true;
|
appRow.showBadge = true;
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
|
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
|
||||||
|
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
@@ -168,18 +173,43 @@ public class BadgePreferenceControllerTest {
|
|||||||
appRow.showBadge = false;
|
appRow.showBadge = false;
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
|
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
|
||||||
|
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredOut() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
appRow.showBadge = true;
|
||||||
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
|
||||||
|
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredIn() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
appRow.showBadge = true;
|
||||||
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null,
|
||||||
|
ImmutableList.of(NotificationChannel.EDIT_LAUNCHER));
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1);
|
||||||
|
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_disabledByAdmin() {
|
public void testUpdateState_disabledByAdmin() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn("something");
|
when(channel.getId()).thenReturn("something");
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null,
|
mController.onResume(new NotificationBackend.AppRow(), channel, null,
|
||||||
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
|
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class), null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext);
|
Preference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -193,7 +223,7 @@ public class BadgePreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn("");
|
when(channel.getId()).thenReturn("");
|
||||||
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext);
|
Preference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -206,7 +236,7 @@ public class BadgePreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.canShowBadge()).thenReturn(true);
|
when(channel.canShowBadge()).thenReturn(true);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -214,7 +244,7 @@ public class BadgePreferenceControllerTest {
|
|||||||
assertTrue(pref.isChecked());
|
assertTrue(pref.isChecked());
|
||||||
|
|
||||||
when(channel.canShowBadge()).thenReturn(false);
|
when(channel.canShowBadge()).thenReturn(false);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
assertFalse(pref.isChecked());
|
assertFalse(pref.isChecked());
|
||||||
@@ -224,14 +254,14 @@ public class BadgePreferenceControllerTest {
|
|||||||
public void testUpdateState_app() {
|
public void testUpdateState_app() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.showBadge = true;
|
appRow.showBadge = true;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
assertTrue(pref.isChecked());
|
assertTrue(pref.isChecked());
|
||||||
|
|
||||||
appRow.showBadge = false;
|
appRow.showBadge = false;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
assertFalse(pref.isChecked());
|
assertFalse(pref.isChecked());
|
||||||
@@ -244,7 +274,7 @@ public class BadgePreferenceControllerTest {
|
|||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
||||||
channel.setShowBadge(false);
|
channel.setShowBadge(false);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
@@ -263,7 +293,7 @@ public class BadgePreferenceControllerTest {
|
|||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
||||||
channel.setShowBadge(true);
|
channel.setShowBadge(true);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
@@ -279,7 +309,7 @@ public class BadgePreferenceControllerTest {
|
|||||||
public void testOnPreferenceChange_on_app() {
|
public void testOnPreferenceChange_on_app() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.showBadge = false;
|
appRow.showBadge = false;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
@@ -296,7 +326,7 @@ public class BadgePreferenceControllerTest {
|
|||||||
public void testOnPreferenceChange_off_app() {
|
public void testOnPreferenceChange_off_app() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.showBadge = true;
|
appRow.showBadge = true;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
|
@@ -59,6 +59,8 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class BlockPreferenceControllerTest {
|
public class BlockPreferenceControllerTest {
|
||||||
|
|
||||||
@@ -102,7 +104,7 @@ public class BlockPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_notIfNull() {
|
public void testIsAvailable_notIfNull() {
|
||||||
mController.onResume(null, null, null, null, null, null);
|
mController.onResume(null, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +114,7 @@ public class BlockPreferenceControllerTest {
|
|||||||
appRow.systemApp = true;
|
appRow.systemApp = true;
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +124,7 @@ public class BlockPreferenceControllerTest {
|
|||||||
appRow.systemApp = true;
|
appRow.systemApp = true;
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +134,7 @@ public class BlockPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +142,8 @@ public class BlockPreferenceControllerTest {
|
|||||||
public void testIsAvailable_GroupNotBlockable() {
|
public void testIsAvailable_GroupNotBlockable() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.systemApp = true;
|
appRow.systemApp = true;
|
||||||
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null);
|
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null,
|
||||||
|
null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +151,7 @@ public class BlockPreferenceControllerTest {
|
|||||||
public void testIsAvailable_AppNotBlockable() {
|
public void testIsAvailable_AppNotBlockable() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.systemApp = true;
|
appRow.systemApp = true;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,17 +161,41 @@ public class BlockPreferenceControllerTest {
|
|||||||
appRow.systemApp = true;
|
appRow.systemApp = true;
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_nonSystemApp() {
|
public void testIsAvailable_nonSystemApp_noFilter() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.systemApp = false;
|
appRow.systemApp = false;
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredOut() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
appRow.systemApp = false;
|
||||||
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
|
ArrayList<String> filter = new ArrayList<>();
|
||||||
|
filter.add("no");
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null, filter);
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredIn() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
appRow.systemApp = false;
|
||||||
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
|
ArrayList<String> filter = new ArrayList<>();
|
||||||
|
filter.add(NotificationChannel.EDIT_IMPORTANCE);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null, filter);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +204,7 @@ public class BlockPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.lockedImportance = true;
|
appRow.lockedImportance = true;
|
||||||
appRow.systemApp = true;
|
appRow.systemApp = true;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
assertFalse(mPreference.getSwitchBar().isEnabled());
|
assertFalse(mPreference.getSwitchBar().isEnabled());
|
||||||
}
|
}
|
||||||
@@ -186,7 +213,8 @@ public class BlockPreferenceControllerTest {
|
|||||||
public void testIsEnabled_GroupNotBlockable() {
|
public void testIsEnabled_GroupNotBlockable() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.systemApp = true;
|
appRow.systemApp = true;
|
||||||
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null);
|
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null,
|
||||||
|
null);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
assertFalse(mPreference.getSwitchBar().isEnabled());
|
assertFalse(mPreference.getSwitchBar().isEnabled());
|
||||||
}
|
}
|
||||||
@@ -195,7 +223,7 @@ public class BlockPreferenceControllerTest {
|
|||||||
public void testIsEnabled_systemAppNotBlockable() {
|
public void testIsEnabled_systemAppNotBlockable() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.systemApp = true;
|
appRow.systemApp = true;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
assertFalse(mPreference.getSwitchBar().isEnabled());
|
assertFalse(mPreference.getSwitchBar().isEnabled());
|
||||||
}
|
}
|
||||||
@@ -206,7 +234,7 @@ public class BlockPreferenceControllerTest {
|
|||||||
appRow.systemApp = true;
|
appRow.systemApp = true;
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
channel.setBlockable(true);
|
channel.setBlockable(true);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
assertTrue(mPreference.getSwitchBar().isEnabled());
|
assertTrue(mPreference.getSwitchBar().isEnabled());
|
||||||
}
|
}
|
||||||
@@ -217,7 +245,7 @@ public class BlockPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
@@ -230,7 +258,7 @@ public class BlockPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
|
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
@@ -242,7 +270,7 @@ public class BlockPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
@@ -252,7 +280,7 @@ public class BlockPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testIsEnabled_app() {
|
public void testIsEnabled_app() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
@@ -263,13 +291,13 @@ public class BlockPreferenceControllerTest {
|
|||||||
public void testUpdateState_app() {
|
public void testUpdateState_app() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertFalse(mPreference.isChecked());
|
assertFalse(mPreference.isChecked());
|
||||||
|
|
||||||
appRow.banned = false;
|
appRow.banned = false;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertTrue(mPreference.isChecked());
|
assertTrue(mPreference.isChecked());
|
||||||
@@ -280,20 +308,20 @@ public class BlockPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.isBlocked()).thenReturn(true);
|
when(group.isBlocked()).thenReturn(true);
|
||||||
mController.onResume(appRow, null, group, null, null, null);
|
mController.onResume(appRow, null, group, null, null, null, null);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertFalse(mPreference.isChecked());
|
assertFalse(mPreference.isChecked());
|
||||||
|
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, null, group, null, null, null);
|
mController.onResume(appRow, null, group, null, null, null, null);
|
||||||
when(group.isBlocked()).thenReturn(true);
|
when(group.isBlocked()).thenReturn(true);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertFalse(mPreference.isChecked());
|
assertFalse(mPreference.isChecked());
|
||||||
|
|
||||||
appRow.banned = false;
|
appRow.banned = false;
|
||||||
mController.onResume(appRow, null, group, null, null, null);
|
mController.onResume(appRow, null, group, null, null, null, null);
|
||||||
when(group.isBlocked()).thenReturn(false);
|
when(group.isBlocked()).thenReturn(false);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
@@ -304,21 +332,21 @@ public class BlockPreferenceControllerTest {
|
|||||||
public void testUpdateState_channelBlocked() {
|
public void testUpdateState_channelBlocked() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_NONE);
|
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_NONE);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertFalse(mPreference.isChecked());
|
assertFalse(mPreference.isChecked());
|
||||||
|
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
|
channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertFalse(mPreference.isChecked());
|
assertFalse(mPreference.isChecked());
|
||||||
|
|
||||||
appRow.banned = false;
|
appRow.banned = false;
|
||||||
channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
|
channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertTrue(mPreference.isChecked());
|
assertTrue(mPreference.isChecked());
|
||||||
@@ -328,7 +356,7 @@ public class BlockPreferenceControllerTest {
|
|||||||
public void testUpdateState_noCrashIfCalledTwice() {
|
public void testUpdateState_noCrashIfCalledTwice() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW);
|
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
}
|
}
|
||||||
@@ -337,7 +365,7 @@ public class BlockPreferenceControllerTest {
|
|||||||
public void testUpdateState_doesNotResetImportance() {
|
public void testUpdateState_doesNotResetImportance() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW);
|
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
assertEquals(IMPORTANCE_LOW, channel.getImportance());
|
assertEquals(IMPORTANCE_LOW, channel.getImportance());
|
||||||
@@ -350,7 +378,7 @@ public class BlockPreferenceControllerTest {
|
|||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_UNSPECIFIED);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_UNSPECIFIED);
|
||||||
when(mBackend.onlyHasDefaultChannel(anyString(), anyInt())).thenReturn(true);
|
when(mBackend.onlyHasDefaultChannel(anyString(), anyInt())).thenReturn(true);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
mController.onSwitchChanged(null, false);
|
mController.onSwitchChanged(null, false);
|
||||||
@@ -372,7 +400,7 @@ public class BlockPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
|
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_HIGH);
|
||||||
channel.setOriginalImportance(IMPORTANCE_HIGH);
|
channel.setOriginalImportance(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
mController.onSwitchChanged(null, false);
|
mController.onSwitchChanged(null, false);
|
||||||
|
@@ -60,6 +60,8 @@ import com.android.settings.notification.NotificationBackend;
|
|||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -125,7 +127,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
|
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +137,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +148,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
@@ -154,7 +156,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void isNotAvailable_ifOffGlobally_app() {
|
public void isNotAvailable_ifOffGlobally_app() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
Settings.Global.putInt(mContext.getContentResolver(),
|
||||||
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
|
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
|
||||||
|
|
||||||
@@ -164,7 +166,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void isNotAvailable_ifLowRam() {
|
public void isNotAvailable_ifLowRam() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
final ShadowActivityManager activityManager =
|
final ShadowActivityManager activityManager =
|
||||||
Shadow.extract(mContext.getSystemService(ActivityManager.class));
|
Shadow.extract(mContext.getSystemService(ActivityManager.class));
|
||||||
@@ -178,7 +180,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
Settings.Global.putInt(mContext.getContentResolver(),
|
||||||
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
|
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
|
||||||
|
|
||||||
@@ -188,7 +190,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void isAvailable_ifNotLowRam() {
|
public void isAvailable_ifNotLowRam() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||||
|
|
||||||
final ShadowActivityManager activityManager =
|
final ShadowActivityManager activityManager =
|
||||||
@@ -200,7 +202,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void isAvailable_app_evenIfOffGlobally() {
|
public void isAvailable_app_evenIfOffGlobally() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
mAppPageController.onResume(appRow, null, null, null, null, null);
|
mAppPageController.onResume(appRow, null, null, null, null, null, null);
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
Settings.Global.putInt(mContext.getContentResolver(),
|
||||||
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
|
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
|
||||||
|
|
||||||
@@ -210,7 +212,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void isAvailable_app() {
|
public void isAvailable_app() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||||
|
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
@@ -223,7 +225,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||||
|
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
@@ -235,18 +237,43 @@ public class BubblePreferenceControllerTest {
|
|||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||||
|
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_filteredIn() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
||||||
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null,
|
||||||
|
ImmutableList.of(NotificationChannel.EDIT_CONVERSATION));
|
||||||
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||||
|
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_filteredOut() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
||||||
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
|
||||||
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||||
|
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_disabledByAdmin() {
|
public void updateState_disabledByAdmin() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn("something");
|
when(channel.getId()).thenReturn("something");
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null,
|
mController.onResume(new NotificationBackend.AppRow(), channel, null,
|
||||||
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
|
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class), null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext);
|
Preference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -261,7 +288,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.pkg = "a";
|
appRow.pkg = "a";
|
||||||
mAppPageController.onResume(appRow, channel, null,
|
mAppPageController.onResume(appRow, channel, null,
|
||||||
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
|
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class), null);
|
||||||
|
|
||||||
BubblePreference pref = new BubblePreference(mContext);
|
BubblePreference pref = new BubblePreference(mContext);
|
||||||
mAppPageController.updateState(pref);
|
mAppPageController.updateState(pref);
|
||||||
@@ -276,7 +303,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
appRow.pkg = "a";
|
appRow.pkg = "a";
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
|
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext);
|
Preference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -291,7 +318,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
appRow.pkg = "a";
|
appRow.pkg = "a";
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.canBubble()).thenReturn(true);
|
when(channel.canBubble()).thenReturn(true);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -299,7 +326,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
assertTrue(pref.isChecked());
|
assertTrue(pref.isChecked());
|
||||||
|
|
||||||
when(channel.canBubble()).thenReturn(false);
|
when(channel.canBubble()).thenReturn(false);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
assertFalse(pref.isChecked());
|
assertFalse(pref.isChecked());
|
||||||
@@ -312,20 +339,20 @@ public class BubblePreferenceControllerTest {
|
|||||||
appRow.pkg = "a";
|
appRow.pkg = "a";
|
||||||
appRow.label = "App!";
|
appRow.label = "App!";
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
||||||
mAppPageController.onResume(appRow, null, null, null, null, null);
|
mAppPageController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
BubblePreference pref = new BubblePreference(mContext);
|
BubblePreference pref = new BubblePreference(mContext);
|
||||||
mAppPageController.updateState(pref);
|
mAppPageController.updateState(pref);
|
||||||
assertEquals(BUBBLE_PREFERENCE_ALL, pref.getSelectedPreference());
|
assertEquals(BUBBLE_PREFERENCE_ALL, pref.getSelectedPreference());
|
||||||
|
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
|
||||||
mAppPageController.onResume(appRow, null, null, null, null, null);
|
mAppPageController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
mAppPageController.updateState(pref);
|
mAppPageController.updateState(pref);
|
||||||
assertEquals(BUBBLE_PREFERENCE_NONE, pref.getSelectedPreference());
|
assertEquals(BUBBLE_PREFERENCE_NONE, pref.getSelectedPreference());
|
||||||
|
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
|
||||||
mAppPageController.onResume(appRow, null, null, null, null, null);
|
mAppPageController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
mAppPageController.updateState(pref);
|
mAppPageController.updateState(pref);
|
||||||
assertEquals(BUBBLE_PREFERENCE_SELECTED, pref.getSelectedPreference());
|
assertEquals(BUBBLE_PREFERENCE_SELECTED, pref.getSelectedPreference());
|
||||||
@@ -339,7 +366,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
appRow.pkg = "a";
|
appRow.pkg = "a";
|
||||||
appRow.label = "App!";
|
appRow.label = "App!";
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
||||||
mAppPageController.onResume(appRow, null, null, null, null, null);
|
mAppPageController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
BubblePreference pref = new BubblePreference(mContext);
|
BubblePreference pref = new BubblePreference(mContext);
|
||||||
mAppPageController.updateState(pref);
|
mAppPageController.updateState(pref);
|
||||||
@@ -354,7 +381,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
@@ -374,7 +401,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
@@ -393,7 +420,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.pkg = "a";
|
appRow.pkg = "a";
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
|
||||||
mAppPageController.onResume(appRow, null, null, null, null, null);
|
mAppPageController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
BubblePreference pref = new BubblePreference(mContext);
|
BubblePreference pref = new BubblePreference(mContext);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
@@ -413,7 +440,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.pkg = "a";
|
appRow.pkg = "a";
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
|
||||||
mAppPageController.onResume(appRow, null, null, null, null, null);
|
mAppPageController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
BubblePreference pref = new BubblePreference(mContext);
|
BubblePreference pref = new BubblePreference(mContext);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
@@ -433,7 +460,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.pkg = "a";
|
appRow.pkg = "a";
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
||||||
mAppPageController.onResume(appRow, null, null, null, null, null);
|
mAppPageController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
BubblePreference pref = new BubblePreference(mContext);
|
BubblePreference pref = new BubblePreference(mContext);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
@@ -452,7 +479,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.pkg = "a";
|
appRow.pkg = "a";
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
||||||
mAppPageController.onResume(appRow, null, null, null, null, null);
|
mAppPageController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
BubblePreference pref = new BubblePreference(mContext);
|
BubblePreference pref = new BubblePreference(mContext);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
@@ -471,7 +498,7 @@ public class BubblePreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.pkg = "a";
|
appRow.pkg = "a";
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
||||||
mAppPageController.onResume(appRow, null, null, null, null, null);
|
mAppPageController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
BubblePreference pref = new BubblePreference(mContext);
|
BubblePreference pref = new BubblePreference(mContext);
|
||||||
mAppPageController.onPreferenceChange(pref, BUBBLE_PREFERENCE_NONE);
|
mAppPageController.onPreferenceChange(pref, BUBBLE_PREFERENCE_NONE);
|
||||||
|
@@ -23,8 +23,6 @@ import static android.app.NotificationManager.BUBBLE_PREFERENCE_SELECTED;
|
|||||||
import static android.app.NotificationManager.IMPORTANCE_HIGH;
|
import static android.app.NotificationManager.IMPORTANCE_HIGH;
|
||||||
import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
|
import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
|
||||||
|
|
||||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
|
||||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
|
||||||
import static com.android.settings.notification.app.BubblePreferenceController.SYSTEM_WIDE_OFF;
|
import static com.android.settings.notification.app.BubblePreferenceController.SYSTEM_WIDE_OFF;
|
||||||
import static com.android.settings.notification.app.BubblePreferenceController.SYSTEM_WIDE_ON;
|
import static com.android.settings.notification.app.BubblePreferenceController.SYSTEM_WIDE_ON;
|
||||||
|
|
||||||
@@ -92,14 +90,14 @@ public class BubbleSummaryPreferenceControllerTest {
|
|||||||
public void isAvailable_appBlocked_shouldReturnFalse() {
|
public void isAvailable_appBlocked_shouldReturnFalse() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
|
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_NOTIFICATION_BUBBLESisOn_shouldReturnTrue() {
|
public void isAvailable_NOTIFICATION_BUBBLESisOn_shouldReturnTrue() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||||
mController.onResume(mAppRow, null, null, null, null, null);
|
mController.onResume(mAppRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
@@ -107,7 +105,7 @@ public class BubbleSummaryPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void isAvailable_NOTIFICATION_BUBBLESisOn_neverSentMsg_shouldReturnFalse() {
|
public void isAvailable_NOTIFICATION_BUBBLESisOn_neverSentMsg_shouldReturnFalse() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||||
mController.onResume(mAppRow, null, null, null, null, null);
|
mController.onResume(mAppRow, null, null, null, null, null, null);
|
||||||
when(mBackend.hasSentValidMsg(anyString(), anyInt())).thenReturn(false);
|
when(mBackend.hasSentValidMsg(anyString(), anyInt())).thenReturn(false);
|
||||||
|
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
@@ -117,7 +115,7 @@ public class BubbleSummaryPreferenceControllerTest {
|
|||||||
public void isAvailable_NOTIFICATION_BUBBLESisOff_shouldReturnFalse() {
|
public void isAvailable_NOTIFICATION_BUBBLESisOff_shouldReturnFalse() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
|
||||||
SYSTEM_WIDE_OFF);
|
SYSTEM_WIDE_OFF);
|
||||||
mController.onResume(mAppRow, null, null, null, null, null);
|
mController.onResume(mAppRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
@@ -128,7 +126,7 @@ public class BubbleSummaryPreferenceControllerTest {
|
|||||||
SYSTEM_WIDE_OFF);
|
SYSTEM_WIDE_OFF);
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(mAppRow, channel, null, null, null, null);
|
mController.onResume(mAppRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
@@ -139,7 +137,7 @@ public class BubbleSummaryPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
||||||
mController.onResume(mAppRow, channel, null, null, null, null);
|
mController.onResume(mAppRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
@@ -147,7 +145,7 @@ public class BubbleSummaryPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void isAvailable_lowRam_shouldReturnFalse() {
|
public void isAvailable_lowRam_shouldReturnFalse() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||||
mController.onResume(mAppRow, null, null, null, null, null);
|
mController.onResume(mAppRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
final ShadowActivityManager activityManager =
|
final ShadowActivityManager activityManager =
|
||||||
Shadow.extract(mContext.getSystemService(ActivityManager.class));
|
Shadow.extract(mContext.getSystemService(ActivityManager.class));
|
||||||
@@ -158,7 +156,7 @@ public class BubbleSummaryPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void isAvailable_notLowRam_shouldReturnTrue() {
|
public void isAvailable_notLowRam_shouldReturnTrue() {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
|
||||||
mController.onResume(mAppRow, null, null, null, null, null);
|
mController.onResume(mAppRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
final ShadowActivityManager activityManager =
|
final ShadowActivityManager activityManager =
|
||||||
Shadow.extract(mContext.getSystemService(ActivityManager.class));
|
Shadow.extract(mContext.getSystemService(ActivityManager.class));
|
||||||
@@ -169,7 +167,7 @@ public class BubbleSummaryPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void updateState_setsIntent() {
|
public void updateState_setsIntent() {
|
||||||
mAppRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
mAppRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
||||||
mController.onResume(mAppRow, null, null, null, null, null);
|
mController.onResume(mAppRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new Preference(mContext);
|
Preference pref = new Preference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -182,7 +180,7 @@ public class BubbleSummaryPreferenceControllerTest {
|
|||||||
SYSTEM_WIDE_OFF);
|
SYSTEM_WIDE_OFF);
|
||||||
|
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
String noneString = mContext.getString(R.string.bubble_app_setting_none);
|
String noneString = mContext.getString(R.string.bubble_app_setting_none);
|
||||||
assertEquals(noneString, mController.getSummary());
|
assertEquals(noneString, mController.getSummary());
|
||||||
@@ -195,7 +193,7 @@ public class BubbleSummaryPreferenceControllerTest {
|
|||||||
|
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_NONE;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
String noneString = mContext.getString(R.string.bubble_app_setting_none);
|
String noneString = mContext.getString(R.string.bubble_app_setting_none);
|
||||||
assertEquals(noneString, mController.getSummary());
|
assertEquals(noneString, mController.getSummary());
|
||||||
@@ -208,7 +206,7 @@ public class BubbleSummaryPreferenceControllerTest {
|
|||||||
|
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_ALL;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
String allString = mContext.getString(R.string.bubble_app_setting_all);
|
String allString = mContext.getString(R.string.bubble_app_setting_all);
|
||||||
assertEquals(allString, mController.getSummary());
|
assertEquals(allString, mController.getSummary());
|
||||||
@@ -221,7 +219,7 @@ public class BubbleSummaryPreferenceControllerTest {
|
|||||||
|
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
|
appRow.bubblePreference = BUBBLE_PREFERENCE_SELECTED;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
String selectedString = mContext.getString(R.string.bubble_app_setting_selected);
|
String selectedString = mContext.getString(R.string.bubble_app_setting_selected);
|
||||||
assertEquals(selectedString, mController.getSummary());
|
assertEquals(selectedString, mController.getSummary());
|
||||||
|
@@ -36,6 +36,8 @@ import androidx.preference.Preference;
|
|||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.notification.NotificationBackend;
|
import com.android.settings.notification.NotificationBackend;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -46,6 +48,8 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class ConversationDemotePreferenceControllerTest {
|
public class ConversationDemotePreferenceControllerTest {
|
||||||
|
|
||||||
@@ -79,7 +83,7 @@ public class ConversationDemotePreferenceControllerTest {
|
|||||||
public void testIsAvailable_notConversation() {
|
public void testIsAvailable_notConversation() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +93,7 @@ public class ConversationDemotePreferenceControllerTest {
|
|||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
channel.setConversationId("a", "a");
|
channel.setConversationId("a", "a");
|
||||||
channel.setDemoted(true);
|
channel.setDemoted(true);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,17 +103,38 @@ public class ConversationDemotePreferenceControllerTest {
|
|||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
channel.setConversationId("a", "a");
|
channel.setConversationId("a", "a");
|
||||||
channel.setDemoted(false);
|
channel.setDemoted(false);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredIn() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
|
channel.setConversationId("a", "a");
|
||||||
|
channel.setDemoted(false);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null,
|
||||||
|
ImmutableList.of(NotificationChannel.EDIT_CONVERSATION));
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredOut() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
|
channel.setConversationId("a", "a");
|
||||||
|
channel.setDemoted(false);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandlePreferenceClick() {
|
public void testHandlePreferenceClick() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
channel.setConversationId("a", "a");
|
channel.setConversationId("a", "a");
|
||||||
channel.setDemoted(false);
|
channel.setDemoted(false);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = mock(Preference.class);
|
Preference pref = mock(Preference.class);
|
||||||
when(pref.getKey()).thenReturn("demote");
|
when(pref.getKey()).thenReturn("demote");
|
||||||
|
@@ -49,6 +49,8 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class ConversationHeaderPreferenceControllerTest {
|
public class ConversationHeaderPreferenceControllerTest {
|
||||||
|
|
||||||
@@ -88,7 +90,7 @@ public class ConversationHeaderPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_notIfNull() {
|
public void testIsAvailable_notIfNull() {
|
||||||
mController.onResume(null, null, null, null, null, null);
|
mController.onResume(null, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +98,15 @@ public class ConversationHeaderPreferenceControllerTest {
|
|||||||
public void testIsAvailable() {
|
public void testIsAvailable() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_ignoresFilter() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
appRow.banned = true;
|
||||||
|
mController.onResume(appRow, null, null, null, null, null, new ArrayList<>());
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,11 +115,11 @@ public class ConversationHeaderPreferenceControllerTest {
|
|||||||
ShortcutInfo si = mock(ShortcutInfo.class);
|
ShortcutInfo si = mock(ShortcutInfo.class);
|
||||||
when(si.getLabel()).thenReturn("hello");
|
when(si.getLabel()).thenReturn("hello");
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
mController.onResume(appRow, null, null, null, si, null);
|
mController.onResume(appRow, null, null, null, si, null, null);
|
||||||
assertEquals(si.getLabel(), mController.getLabel());
|
assertEquals(si.getLabel(), mController.getLabel());
|
||||||
|
|
||||||
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
|
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertEquals(channel.getName(), mController.getLabel());
|
assertEquals(channel.getName(), mController.getLabel());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,25 +127,25 @@ public class ConversationHeaderPreferenceControllerTest {
|
|||||||
public void testGetSummary() {
|
public void testGetSummary() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.label = "bananas";
|
appRow.label = "bananas";
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
assertEquals("", mController.getSummary());
|
assertEquals("", mController.getSummary());
|
||||||
|
|
||||||
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
|
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
|
||||||
mController.onResume(appRow, null, group, null, null, null);
|
mController.onResume(appRow, null, group, null, null, null, null);
|
||||||
assertEquals(appRow.label, mController.getSummary());
|
assertEquals(appRow.label, mController.getSummary());
|
||||||
|
|
||||||
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
|
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
|
||||||
mController.onResume(appRow, channel, group, null, null, null);
|
mController.onResume(appRow, channel, group, null, null, null, null);
|
||||||
assertTrue(mController.getSummary().toString().contains(group.getName()));
|
assertTrue(mController.getSummary().toString().contains(group.getName()));
|
||||||
assertTrue(mController.getSummary().toString().contains(appRow.label));
|
assertTrue(mController.getSummary().toString().contains(appRow.label));
|
||||||
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.getSummary().toString().contains(group.getName()));
|
assertFalse(mController.getSummary().toString().contains(group.getName()));
|
||||||
assertTrue(mController.getSummary().toString().contains(appRow.label));
|
assertTrue(mController.getSummary().toString().contains(appRow.label));
|
||||||
|
|
||||||
NotificationChannel defaultChannel = new NotificationChannel(
|
NotificationChannel defaultChannel = new NotificationChannel(
|
||||||
NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE);
|
NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE);
|
||||||
mController.onResume(appRow, defaultChannel, null, null, null, null);
|
mController.onResume(appRow, defaultChannel, null, null, null, null, null);
|
||||||
assertEquals("", mController.getSummary());
|
assertEquals("", mController.getSummary());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,7 +34,6 @@ import static org.mockito.Mockito.times;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.Notification;
|
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -47,6 +46,8 @@ import androidx.preference.PreferenceScreen;
|
|||||||
import com.android.settings.notification.NotificationBackend;
|
import com.android.settings.notification.NotificationBackend;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -57,6 +58,8 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class ConversationPriorityPreferenceControllerTest {
|
public class ConversationPriorityPreferenceControllerTest {
|
||||||
|
|
||||||
@@ -95,7 +98,7 @@ public class ConversationPriorityPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_notChannelNull() {
|
public void testIsAvailable_notChannelNull() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,16 +106,37 @@ public class ConversationPriorityPreferenceControllerTest {
|
|||||||
public void testIsAvailable() {
|
public void testIsAvailable() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredIn() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null,
|
||||||
|
ImmutableList.of(NotificationChannel.EDIT_IMPORTANCE));
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null,
|
||||||
|
ImmutableList.of(NotificationChannel.EDIT_CONVERSATION));
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredOut() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_disabledByAdmin() {
|
public void testUpdateState_disabledByAdmin() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
||||||
RestrictedLockUtils.EnforcedAdmin.class));
|
RestrictedLockUtils.EnforcedAdmin.class), null);
|
||||||
|
|
||||||
Preference pref = new ConversationPriorityPreference(mContext, null);
|
Preference pref = new ConversationPriorityPreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -126,7 +150,7 @@ public class ConversationPriorityPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new ConversationPriorityPreference(mContext, null);
|
Preference pref = new ConversationPriorityPreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -141,7 +165,7 @@ public class ConversationPriorityPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByOEM()).thenReturn(false);
|
when(channel.isImportanceLockedByOEM()).thenReturn(false);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new ConversationPriorityPreference(mContext, null);
|
Preference pref = new ConversationPriorityPreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -156,7 +180,7 @@ public class ConversationPriorityPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
|
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new ConversationPriorityPreference(mContext, null);
|
Preference pref = new ConversationPriorityPreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -170,7 +194,7 @@ public class ConversationPriorityPreferenceControllerTest {
|
|||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
||||||
channel.setImportantConversation(true);
|
channel.setImportantConversation(true);
|
||||||
channel.setOriginalImportance(IMPORTANCE_DEFAULT);
|
channel.setOriginalImportance(IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
ConversationPriorityPreference pref = mock(ConversationPriorityPreference.class);
|
ConversationPriorityPreference pref = mock(ConversationPriorityPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -185,7 +209,8 @@ public class ConversationPriorityPreferenceControllerTest {
|
|||||||
public void testImportanceLowToImportant() {
|
public void testImportanceLowToImportant() {
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
|
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
@@ -203,7 +228,8 @@ public class ConversationPriorityPreferenceControllerTest {
|
|||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
||||||
channel.setAllowBubbles(false);
|
channel.setAllowBubbles(false);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
|
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
@@ -222,7 +248,8 @@ public class ConversationPriorityPreferenceControllerTest {
|
|||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
|
||||||
channel.setAllowBubbles(false);
|
channel.setAllowBubbles(false);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
|
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
@@ -241,7 +268,8 @@ public class ConversationPriorityPreferenceControllerTest {
|
|||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
||||||
channel.setAllowBubbles(true);
|
channel.setAllowBubbles(true);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
|
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
@@ -261,7 +289,8 @@ public class ConversationPriorityPreferenceControllerTest {
|
|||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
||||||
channel.setAllowBubbles(true);
|
channel.setAllowBubbles(true);
|
||||||
channel.setImportantConversation(true);
|
channel.setImportantConversation(true);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
|
ConversationPriorityPreference pref = new ConversationPriorityPreference(mContext, null);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
|
@@ -38,6 +38,8 @@ import androidx.preference.Preference;
|
|||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.notification.NotificationBackend;
|
import com.android.settings.notification.NotificationBackend;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -48,6 +50,9 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.sql.Array;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class ConversationPromotePreferenceControllerTest {
|
public class ConversationPromotePreferenceControllerTest {
|
||||||
|
|
||||||
@@ -81,7 +86,7 @@ public class ConversationPromotePreferenceControllerTest {
|
|||||||
public void testIsAvailable_notConversation() {
|
public void testIsAvailable_notConversation() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +95,7 @@ public class ConversationPromotePreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
channel.setConversationId("a", "a");
|
channel.setConversationId("a", "a");
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,10 +105,31 @@ public class ConversationPromotePreferenceControllerTest {
|
|||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
channel.setConversationId("a", "a");
|
channel.setConversationId("a", "a");
|
||||||
channel.setDemoted(true);
|
channel.setDemoted(true);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredIn() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
|
channel.setConversationId("a", "a");
|
||||||
|
channel.setDemoted(true);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null,
|
||||||
|
ImmutableList.of(NotificationChannel.EDIT_CONVERSATION));
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredOut() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
|
channel.setConversationId("a", "a");
|
||||||
|
channel.setDemoted(true);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandlePreferenceClick() {
|
public void testHandlePreferenceClick() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
@@ -111,7 +137,7 @@ public class ConversationPromotePreferenceControllerTest {
|
|||||||
channel.setConversationId("a", "a");
|
channel.setConversationId("a", "a");
|
||||||
channel.setDemoted(true);
|
channel.setDemoted(true);
|
||||||
channel.setBypassDnd(true);
|
channel.setBypassDnd(true);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = mock(Preference.class);
|
Preference pref = mock(Preference.class);
|
||||||
when(pref.getKey()).thenReturn("convo_promote");
|
when(pref.getKey()).thenReturn("convo_promote");
|
||||||
@@ -133,7 +159,7 @@ public class ConversationPromotePreferenceControllerTest {
|
|||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
channel.setConversationId("a", "a");
|
channel.setConversationId("a", "a");
|
||||||
channel.setDemoted(true);
|
channel.setDemoted(true);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = mock(Preference.class);
|
Preference pref = mock(Preference.class);
|
||||||
when(pref.getKey()).thenReturn("wrong");
|
when(pref.getKey()).thenReturn("wrong");
|
||||||
|
@@ -46,6 +46,8 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class DeletedChannelsPreferenceControllerTest {
|
public class DeletedChannelsPreferenceControllerTest {
|
||||||
|
|
||||||
@@ -79,14 +81,15 @@ public class DeletedChannelsPreferenceControllerTest {
|
|||||||
public void isAvailable_appScreen_notIfAppBlocked() {
|
public void isAvailable_appScreen_notIfAppBlocked() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_groupScreen_never() {
|
public void isAvailable_groupScreen_never() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null);
|
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null, null, null,
|
||||||
|
null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,28 +97,29 @@ public class DeletedChannelsPreferenceControllerTest {
|
|||||||
public void isAvailable_channelScreen_never() {
|
public void isAvailable_channelScreen_never() {
|
||||||
mController.onResume(
|
mController.onResume(
|
||||||
new NotificationBackend.AppRow(), mock(NotificationChannel.class), null, null, null,
|
new NotificationBackend.AppRow(), mock(NotificationChannel.class), null, null, null,
|
||||||
null);
|
null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_appScreen_notIfNoDeletedChannels() {
|
public void isAvailable_appScreen_notIfNoDeletedChannels() {
|
||||||
when(mBackend.getDeletedChannelCount(any(), anyInt())).thenReturn(0);
|
when(mBackend.getDeletedChannelCount(any(), anyInt())).thenReturn(0);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), null, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_appScreen() {
|
public void isAvailable_appScreen() {
|
||||||
when(mBackend.getDeletedChannelCount(any(), anyInt())).thenReturn(1);
|
when(mBackend.getDeletedChannelCount(any(), anyInt())).thenReturn(1);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), null, null, null, null, null);
|
mController.onResume(
|
||||||
|
new NotificationBackend.AppRow(), null, null, null, null, null, new ArrayList<>());
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState() {
|
public void updateState() {
|
||||||
when(mBackend.getDeletedChannelCount(any(), anyInt())).thenReturn(1);
|
when(mBackend.getDeletedChannelCount(any(), anyInt())).thenReturn(1);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), null, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), null, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = mock(Preference.class);
|
Preference pref = mock(Preference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
@@ -74,7 +74,7 @@ public class DescriptionPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_notIfNull() {
|
public void testIsAvailable_notIfNull() {
|
||||||
mController.onResume(null, null, null, null, null, null);
|
mController.onResume(null, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ public class DescriptionPreferenceControllerTest {
|
|||||||
public void testIsAvailable_notIfChannelGroupBlocked() {
|
public void testIsAvailable_notIfChannelGroupBlocked() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
mController.onResume(appRow, null, group, null, null, null);
|
mController.onResume(appRow, null, group, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ public class DescriptionPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ public class DescriptionPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ public class DescriptionPreferenceControllerTest {
|
|||||||
public void testIsAvailable_notIfNoChannelGroupDesc() {
|
public void testIsAvailable_notIfNoChannelGroupDesc() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
mController.onResume(appRow, null, group, null, null, null);
|
mController.onResume(appRow, null, group, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ public class DescriptionPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
when(channel.getDescription()).thenReturn("AAA");
|
when(channel.getDescription()).thenReturn("AAA");
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,17 +128,22 @@ public class DescriptionPreferenceControllerTest {
|
|||||||
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.getDescription()).thenReturn("something");
|
when(group.getDescription()).thenReturn("something");
|
||||||
when(group.isBlocked()).thenReturn(false);
|
when(group.isBlocked()).thenReturn(false);
|
||||||
mController.onResume(appRow, null, group, null, null, null);
|
mController.onResume(appRow, null, group, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_alwaysFiltered() {
|
||||||
|
assertFalse(mController.isIncludedInFilter());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_channel() {
|
public void testUpdateState_channel() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
when(channel.getDescription()).thenReturn("AAA");
|
when(channel.getDescription()).thenReturn("AAA");
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new Preference(RuntimeEnvironment.application);
|
Preference pref = new Preference(RuntimeEnvironment.application);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -153,7 +158,7 @@ public class DescriptionPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.getDescription()).thenReturn("something");
|
when(group.getDescription()).thenReturn("something");
|
||||||
mController.onResume(appRow, null, group, null, null, null);
|
mController.onResume(appRow, null, group, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new Preference(RuntimeEnvironment.application);
|
Preference pref = new Preference(RuntimeEnvironment.application);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
@@ -44,6 +44,8 @@ import com.android.settings.notification.NotificationBackend;
|
|||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -54,6 +56,8 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class DndPreferenceControllerTest {
|
public class DndPreferenceControllerTest {
|
||||||
|
|
||||||
@@ -83,7 +87,7 @@ public class DndPreferenceControllerTest {
|
|||||||
public void testIsAvailable_app() {
|
public void testIsAvailable_app() {
|
||||||
when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 0));
|
when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 0));
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,16 +97,37 @@ public class DndPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_MIN);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_MIN);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredIn() {
|
||||||
|
when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 1));
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel =
|
||||||
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_MIN);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null,
|
||||||
|
ImmutableList.of(NotificationChannel.EDIT_ZEN));
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredOut() {
|
||||||
|
when(mNm.getNotificationPolicy()).thenReturn(new NotificationManager.Policy(0, 0, 0, 1));
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel =
|
||||||
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_MIN);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_disabledByAdmin() {
|
public void testUpdateState_disabledByAdmin() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn("something");
|
when(channel.getId()).thenReturn("something");
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
||||||
RestrictedLockUtils.EnforcedAdmin.class));
|
RestrictedLockUtils.EnforcedAdmin.class), null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -115,7 +140,7 @@ public class DndPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -128,7 +153,7 @@ public class DndPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn("something");
|
when(channel.getId()).thenReturn("something");
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -140,7 +165,8 @@ public class DndPreferenceControllerTest {
|
|||||||
public void testUpdateState_bypassDnd() {
|
public void testUpdateState_bypassDnd() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.canBypassDnd()).thenReturn(true);
|
when(channel.canBypassDnd()).thenReturn(true);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref =
|
RestrictedSwitchPreference pref =
|
||||||
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||||
@@ -152,7 +178,8 @@ public class DndPreferenceControllerTest {
|
|||||||
public void testUpdateState_noBypassDnd() {
|
public void testUpdateState_noBypassDnd() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.canBypassDnd()).thenReturn(false);
|
when(channel.canBypassDnd()).thenReturn(false);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref =
|
RestrictedSwitchPreference pref =
|
||||||
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||||
@@ -164,7 +191,8 @@ public class DndPreferenceControllerTest {
|
|||||||
public void testOnPreferenceChange_on() {
|
public void testOnPreferenceChange_on() {
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref =
|
RestrictedSwitchPreference pref =
|
||||||
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||||
@@ -182,7 +210,8 @@ public class DndPreferenceControllerTest {
|
|||||||
public void testOnPreferenceChange_off() {
|
public void testOnPreferenceChange_off() {
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref =
|
RestrictedSwitchPreference pref =
|
||||||
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||||
|
@@ -48,6 +48,8 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class HeaderPreferenceControllerTest {
|
public class HeaderPreferenceControllerTest {
|
||||||
|
|
||||||
@@ -87,7 +89,7 @@ public class HeaderPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_notIfNull() {
|
public void testIsAvailable_notIfNull() {
|
||||||
mController.onResume(null, null, null, null, null, null);
|
mController.onResume(null, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +97,15 @@ public class HeaderPreferenceControllerTest {
|
|||||||
public void testIsAvailable() {
|
public void testIsAvailable() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_ignoredFilter() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
appRow.banned = true;
|
||||||
|
mController.onResume(appRow, null, null, null, null, null, new ArrayList<>());
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,20 +113,20 @@ public class HeaderPreferenceControllerTest {
|
|||||||
public void testGetLabel() {
|
public void testGetLabel() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.label = "bananas";
|
appRow.label = "bananas";
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
assertEquals(appRow.label, mController.getLabel());
|
assertEquals(appRow.label, mController.getLabel());
|
||||||
|
|
||||||
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
|
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
|
||||||
mController.onResume(appRow, null, group, null, null, null);
|
mController.onResume(appRow, null, group, null, null, null, null);
|
||||||
assertEquals(group.getName(), mController.getLabel());
|
assertEquals(group.getName(), mController.getLabel());
|
||||||
|
|
||||||
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
|
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
|
||||||
mController.onResume(appRow, channel, group, null, null, null);
|
mController.onResume(appRow, channel, group, null, null, null, null);
|
||||||
assertEquals(channel.getName(), mController.getLabel());
|
assertEquals(channel.getName(), mController.getLabel());
|
||||||
|
|
||||||
NotificationChannel defaultChannel = new NotificationChannel(
|
NotificationChannel defaultChannel = new NotificationChannel(
|
||||||
NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE);
|
NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE);
|
||||||
mController.onResume(appRow, defaultChannel, null, null, null, null);
|
mController.onResume(appRow, defaultChannel, null, null, null, null, null);
|
||||||
assertEquals(appRow.label, mController.getLabel());
|
assertEquals(appRow.label, mController.getLabel());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,25 +134,25 @@ public class HeaderPreferenceControllerTest {
|
|||||||
public void testGetSummary() {
|
public void testGetSummary() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.label = "bananas";
|
appRow.label = "bananas";
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
assertEquals("", mController.getSummary());
|
assertEquals("", mController.getSummary());
|
||||||
|
|
||||||
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
|
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
|
||||||
mController.onResume(appRow, null, group, null, null, null);
|
mController.onResume(appRow, null, group, null, null, null, null);
|
||||||
assertEquals(appRow.label, mController.getSummary());
|
assertEquals(appRow.label, mController.getSummary());
|
||||||
|
|
||||||
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
|
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
|
||||||
mController.onResume(appRow, channel, group, null, null, null);
|
mController.onResume(appRow, channel, group, null, null, null, null);
|
||||||
assertTrue(mController.getSummary().toString().contains(group.getName()));
|
assertTrue(mController.getSummary().toString().contains(group.getName()));
|
||||||
assertTrue(mController.getSummary().toString().contains(appRow.label));
|
assertTrue(mController.getSummary().toString().contains(appRow.label));
|
||||||
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.getSummary().toString().contains(group.getName()));
|
assertFalse(mController.getSummary().toString().contains(group.getName()));
|
||||||
assertTrue(mController.getSummary().toString().contains(appRow.label));
|
assertTrue(mController.getSummary().toString().contains(appRow.label));
|
||||||
|
|
||||||
NotificationChannel defaultChannel = new NotificationChannel(
|
NotificationChannel defaultChannel = new NotificationChannel(
|
||||||
NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE);
|
NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE);
|
||||||
mController.onResume(appRow, defaultChannel, null, null, null, null);
|
mController.onResume(appRow, defaultChannel, null, null, null, null, null);
|
||||||
assertEquals("", mController.getSummary());
|
assertEquals("", mController.getSummary());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -52,6 +52,10 @@ import org.robolectric.shadows.ShadowApplication;
|
|||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class HighImportancePreferenceControllerTest {
|
public class HighImportancePreferenceControllerTest {
|
||||||
|
|
||||||
@@ -88,7 +92,7 @@ public class HighImportancePreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_notIfNull() {
|
public void testIsAvailable_notIfNull() {
|
||||||
mController.onResume(null, null, null, null, null, null);
|
mController.onResume(null, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +100,7 @@ public class HighImportancePreferenceControllerTest {
|
|||||||
public void testIsAvailable_ifAppBlocked() {
|
public void testIsAvailable_ifAppBlocked() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
|
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +109,7 @@ public class HighImportancePreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +119,7 @@ public class HighImportancePreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,16 +128,35 @@ public class HighImportancePreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredIn() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null,
|
||||||
|
ImmutableList.of(NotificationChannel.EDIT_IMPORTANCE));
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredOut() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_disabledByAdmin() {
|
public void testUpdateState_disabledByAdmin() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
||||||
RestrictedLockUtils.EnforcedAdmin.class));
|
RestrictedLockUtils.EnforcedAdmin.class), null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -147,7 +170,7 @@ public class HighImportancePreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -162,7 +185,7 @@ public class HighImportancePreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByOEM()).thenReturn(false);
|
when(channel.isImportanceLockedByOEM()).thenReturn(false);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -177,7 +200,7 @@ public class HighImportancePreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
|
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -189,7 +212,7 @@ public class HighImportancePreferenceControllerTest {
|
|||||||
public void testUpdateState_high() {
|
public void testUpdateState_high() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -201,7 +224,7 @@ public class HighImportancePreferenceControllerTest {
|
|||||||
public void testUpdateState_default() {
|
public void testUpdateState_default() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -213,7 +236,8 @@ public class HighImportancePreferenceControllerTest {
|
|||||||
public void onPreferenceChange() {
|
public void onPreferenceChange() {
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext, null);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext, null);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
|
@@ -48,6 +48,8 @@ import androidx.preference.PreferenceScreen;
|
|||||||
import com.android.settings.notification.NotificationBackend;
|
import com.android.settings.notification.NotificationBackend;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -58,6 +60,8 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class ImportancePreferenceControllerTest {
|
public class ImportancePreferenceControllerTest {
|
||||||
|
|
||||||
@@ -94,7 +98,7 @@ public class ImportancePreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_notIfNull() {
|
public void testIsAvailable_notIfNull() {
|
||||||
mController.onResume(null, null, null, null, null, null);
|
mController.onResume(null, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +106,7 @@ public class ImportancePreferenceControllerTest {
|
|||||||
public void testIsAvailable_ifAppBlocked() {
|
public void testIsAvailable_ifAppBlocked() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
|
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +117,7 @@ public class ImportancePreferenceControllerTest {
|
|||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
|
||||||
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.isBlocked()).thenReturn(true);
|
when(group.isBlocked()).thenReturn(true);
|
||||||
mController.onResume(appRow, channel, group, null, null, null);
|
mController.onResume(appRow, channel, group, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +126,7 @@ public class ImportancePreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +136,7 @@ public class ImportancePreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,16 +145,35 @@ public class ImportancePreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredIn() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null,
|
||||||
|
ImmutableList.of(NotificationChannel.EDIT_IMPORTANCE));
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredOut() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_disabledByAdmin() {
|
public void testUpdateState_disabledByAdmin() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
||||||
RestrictedLockUtils.EnforcedAdmin.class));
|
RestrictedLockUtils.EnforcedAdmin.class), null);
|
||||||
|
|
||||||
Preference pref = new ImportancePreference(mContext, null);
|
Preference pref = new ImportancePreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -164,7 +187,7 @@ public class ImportancePreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new ImportancePreference(mContext, null);
|
Preference pref = new ImportancePreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -179,7 +202,7 @@ public class ImportancePreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByOEM()).thenReturn(false);
|
when(channel.isImportanceLockedByOEM()).thenReturn(false);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new ImportancePreference(mContext, null);
|
Preference pref = new ImportancePreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -194,7 +217,7 @@ public class ImportancePreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
|
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new ImportancePreference(mContext, null);
|
Preference pref = new ImportancePreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -206,7 +229,7 @@ public class ImportancePreferenceControllerTest {
|
|||||||
public void testUpdateState() {
|
public void testUpdateState() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
ImportancePreference pref = mock(ImportancePreference.class);
|
ImportancePreference pref = mock(ImportancePreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -221,7 +244,8 @@ public class ImportancePreferenceControllerTest {
|
|||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
||||||
channel.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
|
channel.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
ImportancePreference pref = new ImportancePreference(mContext, null);
|
ImportancePreference pref = new ImportancePreference(mContext, null);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
@@ -239,7 +263,8 @@ public class ImportancePreferenceControllerTest {
|
|||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
||||||
channel.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
|
channel.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
ImportancePreference pref = new ImportancePreference(mContext, null);
|
ImportancePreference pref = new ImportancePreference(mContext, null);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
|
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.mock;
|
|||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
@@ -34,6 +35,8 @@ import androidx.preference.PreferenceScreen;
|
|||||||
import com.android.settings.notification.NotificationBackend;
|
import com.android.settings.notification.NotificationBackend;
|
||||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -46,6 +49,8 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = SettingsShadowResources.class)
|
@Config(shadows = SettingsShadowResources.class)
|
||||||
public class InvalidConversationInfoPreferenceControllerTest {
|
public class InvalidConversationInfoPreferenceControllerTest {
|
||||||
@@ -90,7 +95,7 @@ public class InvalidConversationInfoPreferenceControllerTest {
|
|||||||
appRow.pkg = "hi";
|
appRow.pkg = "hi";
|
||||||
appRow.uid = 0;
|
appRow.uid = 0;
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +105,7 @@ public class InvalidConversationInfoPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.pkg = "hi";
|
appRow.pkg = "hi";
|
||||||
appRow.uid = 0;
|
appRow.uid = 0;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,10 +115,31 @@ public class InvalidConversationInfoPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.pkg = "hi";
|
appRow.pkg = "hi";
|
||||||
appRow.uid = 0;
|
appRow.uid = 0;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredIn() {
|
||||||
|
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, ImmutableList.of(
|
||||||
|
NotificationChannel.EDIT_CONVERSATION));
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredOut() {
|
||||||
|
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, new ArrayList<>());
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState() {
|
public void testUpdateState() {
|
||||||
when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(true);
|
when(mBackend.isInInvalidMsgState(anyString(), anyInt())).thenReturn(true);
|
||||||
@@ -121,7 +147,7 @@ public class InvalidConversationInfoPreferenceControllerTest {
|
|||||||
appRow.pkg = "hi";
|
appRow.pkg = "hi";
|
||||||
appRow.uid = 0;
|
appRow.uid = 0;
|
||||||
appRow.label = "plum";
|
appRow.label = "plum";
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
Preference pref = new Preference(mContext);
|
Preference pref = new Preference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
assertTrue(pref.getSummary().toString().contains(appRow.label));
|
assertTrue(pref.getSummary().toString().contains(appRow.label));
|
||||||
|
@@ -16,10 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.app;
|
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.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
@@ -45,6 +41,8 @@ import com.android.settings.testutils.shadow.SettingsShadowResources;
|
|||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -57,6 +55,8 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = SettingsShadowResources.class)
|
@Config(shadows = SettingsShadowResources.class)
|
||||||
public class InvalidConversationPreferenceControllerTest {
|
public class InvalidConversationPreferenceControllerTest {
|
||||||
@@ -102,7 +102,7 @@ public class InvalidConversationPreferenceControllerTest {
|
|||||||
appRow.pkg = "hi";
|
appRow.pkg = "hi";
|
||||||
appRow.uid = 0;
|
appRow.uid = 0;
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ public class InvalidConversationPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.pkg = "hi";
|
appRow.pkg = "hi";
|
||||||
appRow.uid = 0;
|
appRow.uid = 0;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,17 +122,38 @@ public class InvalidConversationPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.pkg = "hi";
|
appRow.pkg = "hi";
|
||||||
appRow.uid = 0;
|
appRow.uid = 0;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredIn() {
|
||||||
|
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, ImmutableList.of(
|
||||||
|
NotificationChannel.EDIT_CONVERSATION));
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredOut() {
|
||||||
|
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, new ArrayList<>());
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_disabledByAdmin() {
|
public void testUpdateState_disabledByAdmin() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.pkg = "hi";
|
appRow.pkg = "hi";
|
||||||
appRow.uid = 0;
|
appRow.uid = 0;
|
||||||
mController.onResume(appRow, null, null,
|
mController.onResume(appRow, null, null,
|
||||||
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
|
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class), null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext);
|
Preference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -144,7 +165,7 @@ public class InvalidConversationPreferenceControllerTest {
|
|||||||
public void testUpdateState_notChecked() {
|
public void testUpdateState_notChecked() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.pkg = "pkg";
|
appRow.pkg = "pkg";
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(false);
|
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(false);
|
||||||
|
|
||||||
@@ -157,7 +178,7 @@ public class InvalidConversationPreferenceControllerTest {
|
|||||||
public void testUpdateState_checked() {
|
public void testUpdateState_checked() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.pkg = "pkg";
|
appRow.pkg = "pkg";
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(true);
|
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(true);
|
||||||
|
|
||||||
@@ -170,7 +191,7 @@ public class InvalidConversationPreferenceControllerTest {
|
|||||||
public void testOnPreferenceChange_toggleEnabled() {
|
public void testOnPreferenceChange_toggleEnabled() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.pkg = "pkg";
|
appRow.pkg = "pkg";
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(true);
|
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(true);
|
||||||
|
|
||||||
@@ -189,7 +210,7 @@ public class InvalidConversationPreferenceControllerTest {
|
|||||||
public void testOnPreferenceChange_toggleDisabled() {
|
public void testOnPreferenceChange_toggleDisabled() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.pkg = "pkg";
|
appRow.pkg = "pkg";
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(false);
|
when(mBackend.hasUserDemotedInvalidMsgApp(anyString(), anyInt())).thenReturn(false);
|
||||||
|
|
||||||
|
@@ -46,6 +46,8 @@ import com.android.settings.testutils.shadow.SettingsShadowResources;
|
|||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -58,6 +60,10 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = SettingsShadowResources.class)
|
@Config(shadows = SettingsShadowResources.class)
|
||||||
public class LightsPreferenceControllerTest {
|
public class LightsPreferenceControllerTest {
|
||||||
@@ -107,7 +113,7 @@ public class LightsPreferenceControllerTest {
|
|||||||
com.android.internal.R.bool.config_intrusiveNotificationLed, false);
|
com.android.internal.R.bool.config_intrusiveNotificationLed, false);
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +122,7 @@ public class LightsPreferenceControllerTest {
|
|||||||
Settings.System.putInt(mContext.getContentResolver(), NOTIFICATION_LIGHT_PULSE, 0);
|
Settings.System.putInt(mContext.getContentResolver(), NOTIFICATION_LIGHT_PULSE, 0);
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +130,7 @@ public class LightsPreferenceControllerTest {
|
|||||||
public void testIsAvailable_notIfNotImportant() {
|
public void testIsAvailable_notIfNotImportant() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +139,7 @@ public class LightsPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,16 +147,33 @@ public class LightsPreferenceControllerTest {
|
|||||||
public void testIsAvailable() {
|
public void testIsAvailable() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredIn() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null,
|
||||||
|
ImmutableList.of(NotificationChannel.EDIT_LOCKED_DEVICE));
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredOut() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_disabledByAdmin() {
|
public void testUpdateState_disabledByAdmin() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn("something");
|
when(channel.getId()).thenReturn("something");
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null,
|
mController.onResume(new NotificationBackend.AppRow(), channel, null,
|
||||||
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
|
null, null, mock(RestrictedLockUtils.EnforcedAdmin.class), null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext);
|
Preference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -163,7 +186,7 @@ public class LightsPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext);
|
Preference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -175,7 +198,8 @@ public class LightsPreferenceControllerTest {
|
|||||||
public void testUpdateState_lightsOn() {
|
public void testUpdateState_lightsOn() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.shouldShowLights()).thenReturn(true);
|
when(channel.shouldShowLights()).thenReturn(true);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -186,7 +210,8 @@ public class LightsPreferenceControllerTest {
|
|||||||
public void testUpdateState_lightsOff() {
|
public void testUpdateState_lightsOff() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.shouldShowLights()).thenReturn(false);
|
when(channel.shouldShowLights()).thenReturn(false);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -197,7 +222,8 @@ public class LightsPreferenceControllerTest {
|
|||||||
public void testOnPreferenceChange_on() {
|
public void testOnPreferenceChange_on() {
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
@@ -214,7 +240,8 @@ public class LightsPreferenceControllerTest {
|
|||||||
public void testOnPreferenceChange_off() {
|
public void testOnPreferenceChange_off() {
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref =
|
RestrictedSwitchPreference pref =
|
||||||
new RestrictedSwitchPreference(mContext);
|
new RestrictedSwitchPreference(mContext);
|
||||||
|
@@ -52,6 +52,10 @@ import org.robolectric.shadows.ShadowApplication;
|
|||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class MinImportancePreferenceControllerTest {
|
public class MinImportancePreferenceControllerTest {
|
||||||
|
|
||||||
@@ -88,7 +92,7 @@ public class MinImportancePreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_notIfNull() {
|
public void testIsAvailable_notIfNull() {
|
||||||
mController.onResume(null, null, null, null, null, null);
|
mController.onResume(null, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +100,7 @@ public class MinImportancePreferenceControllerTest {
|
|||||||
public void testIsAvailable_ifAppBlocked() {
|
public void testIsAvailable_ifAppBlocked() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null);
|
mController.onResume(appRow, mock(NotificationChannel.class), null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +109,7 @@ public class MinImportancePreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +119,7 @@ public class MinImportancePreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,16 +128,35 @@ public class MinImportancePreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredIn() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null,
|
||||||
|
ImmutableList.of(NotificationChannel.EDIT_IMPORTANCE));
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredOut() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_disabledByAdmin() {
|
public void testUpdateState_disabledByAdmin() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
||||||
RestrictedLockUtils.EnforcedAdmin.class));
|
RestrictedLockUtils.EnforcedAdmin.class), null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -147,7 +170,7 @@ public class MinImportancePreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -162,7 +185,7 @@ public class MinImportancePreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByOEM()).thenReturn(false);
|
when(channel.isImportanceLockedByOEM()).thenReturn(false);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -177,7 +200,7 @@ public class MinImportancePreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
|
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
Preference pref = new RestrictedSwitchPreference(mContext, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -189,7 +212,7 @@ public class MinImportancePreferenceControllerTest {
|
|||||||
public void testUpdateState_min() {
|
public void testUpdateState_min() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_MIN);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_MIN);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -201,7 +224,7 @@ public class MinImportancePreferenceControllerTest {
|
|||||||
public void testUpdateState_low() {
|
public void testUpdateState_low() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -213,7 +236,8 @@ public class MinImportancePreferenceControllerTest {
|
|||||||
public void onPreferenceChange() {
|
public void onPreferenceChange() {
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext, null);
|
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext, null);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||||
|
@@ -54,6 +54,8 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class NotificationPreferenceControllerTest {
|
public class NotificationPreferenceControllerTest {
|
||||||
|
|
||||||
@@ -90,7 +92,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_notIfNull() {
|
public void isAvailable_notIfNull() {
|
||||||
mController.onResume(null, null, null, null, null, null);
|
mController.onResume(null, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +101,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, mock(NotificationChannel.class),
|
mController.onResume(appRow, mock(NotificationChannel.class),
|
||||||
mock(NotificationChannelGroup.class), null, null, null);
|
mock(NotificationChannelGroup.class), null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +113,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, group, null, null, null);
|
mController.onResume(appRow, channel, group, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,11 +124,25 @@ public class NotificationPreferenceControllerTest {
|
|||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
|
||||||
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, group, null, null, null);
|
mController.onResume(appRow, channel, group, null, null, null, null);
|
||||||
when(group.isBlocked()).thenReturn(true);
|
when(group.isBlocked()).thenReturn(true);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_notIfFailsFilterCheck() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
|
||||||
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
|
when(group.isBlocked()).thenReturn(false);
|
||||||
|
ArrayList<String> filter = new ArrayList<>();
|
||||||
|
filter.add("something");
|
||||||
|
|
||||||
|
mController.onResume(appRow, channel, group, null, null, null, filter);
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable() {
|
public void isAvailable() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
@@ -135,7 +151,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.isBlocked()).thenReturn(false);
|
when(group.isBlocked()).thenReturn(false);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, group, null, null, null);
|
mController.onResume(appRow, channel, group, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +162,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
RestrictedLockUtils.EnforcedAdmin admin = mock(RestrictedLockUtils.EnforcedAdmin.class);
|
RestrictedLockUtils.EnforcedAdmin admin = mock(RestrictedLockUtils.EnforcedAdmin.class);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, group, null, null, admin);
|
mController.onResume(appRow, channel, group, null, null, admin, null);
|
||||||
|
|
||||||
assertEquals(appRow, mController.mAppRow);
|
assertEquals(appRow, mController.mAppRow);
|
||||||
assertEquals(channel, mController.mChannel);
|
assertEquals(channel, mController.mChannel);
|
||||||
@@ -160,7 +176,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_UNSPECIFIED);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_UNSPECIFIED);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.checkCanBeVisible(IMPORTANCE_MIN));
|
assertTrue(mController.checkCanBeVisible(IMPORTANCE_MIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +186,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.checkCanBeVisible(IMPORTANCE_LOW));
|
assertTrue(mController.checkCanBeVisible(IMPORTANCE_LOW));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +196,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.checkCanBeVisible(IMPORTANCE_MIN));
|
assertTrue(mController.checkCanBeVisible(IMPORTANCE_MIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +206,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.checkCanBeVisible(IMPORTANCE_DEFAULT));
|
assertFalse(mController.checkCanBeVisible(IMPORTANCE_DEFAULT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +216,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
mController.saveChannel();
|
mController.saveChannel();
|
||||||
verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
|
verify(mBackend, times(1)).updateChannel(any(), anyInt(), any());
|
||||||
}
|
}
|
||||||
@@ -212,11 +228,11 @@ public class NotificationPreferenceControllerTest {
|
|||||||
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isChannelBlockable());
|
assertFalse(mController.isChannelBlockable());
|
||||||
|
|
||||||
when(channel.isImportanceLockedByOEM()).thenReturn(false);
|
when(channel.isImportanceLockedByOEM()).thenReturn(false);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isChannelBlockable());
|
assertTrue(mController.isChannelBlockable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,7 +243,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
|
||||||
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
|
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isChannelBlockable());
|
assertFalse(mController.isChannelBlockable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +254,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isBlockable()).thenReturn(false);
|
when(channel.isBlockable()).thenReturn(false);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isChannelBlockable());
|
assertTrue(mController.isChannelBlockable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,7 +266,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
when(channel.isBlockable()).thenReturn(false);
|
when(channel.isBlockable()).thenReturn(false);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isChannelBlockable());
|
assertFalse(mController.isChannelBlockable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +277,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isBlockable()).thenReturn(true);
|
when(channel.isBlockable()).thenReturn(true);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isChannelBlockable());
|
assertTrue(mController.isChannelBlockable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,7 +289,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
when(channel.isBlockable()).thenReturn(false);
|
when(channel.isBlockable()).thenReturn(false);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isChannelBlockable());
|
assertTrue(mController.isChannelBlockable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,7 +300,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.isBlocked()).thenReturn(false);
|
when(group.isBlocked()).thenReturn(false);
|
||||||
|
|
||||||
mController.onResume(appRow, null, group, null, null, null);
|
mController.onResume(appRow, null, group, null, null, null, null);
|
||||||
assertTrue(mController.isChannelGroupBlockable());
|
assertTrue(mController.isChannelGroupBlockable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,7 +312,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isChannelBlockable());
|
assertFalse(mController.isChannelBlockable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,7 +324,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
|
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isChannelBlockable());
|
assertFalse(mController.isChannelBlockable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,7 +335,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.isBlocked()).thenReturn(false);
|
when(group.isBlocked()).thenReturn(false);
|
||||||
|
|
||||||
mController.onResume(appRow, null, group, null, null, null);
|
mController.onResume(appRow, null, group, null, null, null, null);
|
||||||
assertFalse(mController.isChannelGroupBlockable());
|
assertFalse(mController.isChannelGroupBlockable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,13 +346,14 @@ public class NotificationPreferenceControllerTest {
|
|||||||
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.isBlocked()).thenReturn(true);
|
when(group.isBlocked()).thenReturn(true);
|
||||||
|
|
||||||
mController.onResume(appRow, null, group, null, null, null);
|
mController.onResume(appRow, null, group, null, null, null, null);
|
||||||
assertTrue(mController.isChannelGroupBlockable());
|
assertTrue(mController.isChannelGroupBlockable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsDefaultChannel_noChannel() {
|
public void testIsDefaultChannel_noChannel() {
|
||||||
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, null, null);
|
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
assertFalse(mController.isDefaultChannel());
|
assertFalse(mController.isDefaultChannel());
|
||||||
}
|
}
|
||||||
@@ -344,7 +361,8 @@ public class NotificationPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testIsDefaultChannel_nonDefaultChannel() {
|
public void testIsDefaultChannel_nonDefaultChannel() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null, null, null);
|
mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null, null,
|
||||||
|
null, null);
|
||||||
|
|
||||||
assertFalse(mController.isDefaultChannel());
|
assertFalse(mController.isDefaultChannel());
|
||||||
}
|
}
|
||||||
@@ -353,7 +371,8 @@ public class NotificationPreferenceControllerTest {
|
|||||||
public void testIsDefaultChannel() {
|
public void testIsDefaultChannel() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn(NotificationChannel.DEFAULT_CHANNEL_ID);
|
when(channel.getId()).thenReturn(NotificationChannel.DEFAULT_CHANNEL_ID);
|
||||||
mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null, null, null);
|
mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null, null,
|
||||||
|
null, null);
|
||||||
|
|
||||||
assertTrue(mController.isDefaultChannel());
|
assertTrue(mController.isDefaultChannel());
|
||||||
}
|
}
|
||||||
@@ -364,6 +383,11 @@ public class NotificationPreferenceControllerTest {
|
|||||||
super(context, backend);
|
super(context, backend);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean isIncludedInFilter() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return null;
|
return null;
|
||||||
|
@@ -34,6 +34,8 @@ import androidx.preference.Preference;
|
|||||||
|
|
||||||
import com.android.settings.notification.NotificationBackend;
|
import com.android.settings.notification.NotificationBackend;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -43,6 +45,8 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class NotificationsOffPreferenceControllerTest {
|
public class NotificationsOffPreferenceControllerTest {
|
||||||
|
|
||||||
@@ -72,7 +76,7 @@ public class NotificationsOffPreferenceControllerTest {
|
|||||||
public void testIsAvailable_yesIfAppBlocked() {
|
public void testIsAvailable_yesIfAppBlocked() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +85,7 @@ public class NotificationsOffPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.isBlocked()).thenReturn(true);
|
when(group.isBlocked()).thenReturn(true);
|
||||||
mController.onResume(appRow, null, group, null, null, null);
|
mController.onResume(appRow, null, group, null, null, null, null);
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,16 +94,35 @@ public class NotificationsOffPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredIn() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null,
|
||||||
|
ImmutableList.of(NotificationChannel.EDIT_IMPORTANCE));
|
||||||
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredOut() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_channel() {
|
public void testUpdateState_channel() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new Preference(RuntimeEnvironment.application);
|
Preference pref = new Preference(RuntimeEnvironment.application);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -113,7 +136,7 @@ public class NotificationsOffPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.isBlocked()).thenReturn(true);
|
when(group.isBlocked()).thenReturn(true);
|
||||||
mController.onResume(appRow, null, group, null, null, null);
|
mController.onResume(appRow, null, group, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new Preference(RuntimeEnvironment.application);
|
Preference pref = new Preference(RuntimeEnvironment.application);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -126,7 +149,7 @@ public class NotificationsOffPreferenceControllerTest {
|
|||||||
public void testUpdateState_app() {
|
public void testUpdateState_app() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new Preference(RuntimeEnvironment.application);
|
Preference pref = new Preference(RuntimeEnvironment.application);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
@@ -53,6 +53,8 @@ import com.android.settings.SettingsPreferenceFragment;
|
|||||||
import com.android.settings.notification.NotificationBackend;
|
import com.android.settings.notification.NotificationBackend;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -65,6 +67,8 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class SoundPreferenceControllerTest {
|
public class SoundPreferenceControllerTest {
|
||||||
|
|
||||||
@@ -108,7 +112,7 @@ public class SoundPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_notIfChannelNull() {
|
public void testIsAvailable_notIfChannelNull() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
mController.onResume(appRow, null, null, null, null, null);
|
mController.onResume(appRow, null, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +120,7 @@ public class SoundPreferenceControllerTest {
|
|||||||
public void testIsAvailable_notIfNotImportant() {
|
public void testIsAvailable_notIfNotImportant() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +129,7 @@ public class SoundPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,10 +137,27 @@ public class SoundPreferenceControllerTest {
|
|||||||
public void testIsAvailable() {
|
public void testIsAvailable() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredIn() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null,
|
||||||
|
ImmutableList.of(NotificationChannel.EDIT_SOUND));
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredOut() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDisplayPreference_savesPreference() {
|
public void testDisplayPreference_savesPreference() {
|
||||||
NotificationSoundPreference pref = mock(NotificationSoundPreference.class);
|
NotificationSoundPreference pref = mock(NotificationSoundPreference.class);
|
||||||
@@ -152,7 +173,7 @@ public class SoundPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn("something");
|
when(channel.getId()).thenReturn("something");
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
||||||
RestrictedLockUtils.EnforcedAdmin.class));
|
RestrictedLockUtils.EnforcedAdmin.class), null);
|
||||||
|
|
||||||
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
||||||
Preference pref = new NotificationSoundPreference(mContext, attributeSet);
|
Preference pref = new NotificationSoundPreference(mContext, attributeSet);
|
||||||
@@ -166,7 +187,7 @@ public class SoundPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
||||||
Preference pref = new NotificationSoundPreference(mContext, attributeSet);
|
Preference pref = new NotificationSoundPreference(mContext, attributeSet);
|
||||||
@@ -182,7 +203,7 @@ public class SoundPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn("something");
|
when(channel.getId()).thenReturn("something");
|
||||||
when(channel.getSound()).thenReturn(sound);
|
when(channel.getSound()).thenReturn(sound);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
||||||
NotificationSoundPreference pref = new NotificationSoundPreference(mContext, attributeSet);
|
NotificationSoundPreference pref = new NotificationSoundPreference(mContext, attributeSet);
|
||||||
@@ -198,7 +219,7 @@ public class SoundPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
||||||
channel.setSound(sound, Notification.AUDIO_ATTRIBUTES_DEFAULT);
|
channel.setSound(sound, Notification.AUDIO_ATTRIBUTES_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
||||||
NotificationSoundPreference pref =
|
NotificationSoundPreference pref =
|
||||||
@@ -238,7 +259,7 @@ public class SoundPreferenceControllerTest {
|
|||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
||||||
channel.setSound(null, new AudioAttributes.Builder().setUsage(
|
channel.setSound(null, new AudioAttributes.Builder().setUsage(
|
||||||
AudioAttributes.USAGE_ALARM).build());
|
AudioAttributes.USAGE_ALARM).build());
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
||||||
NotificationSoundPreference pref =
|
NotificationSoundPreference pref =
|
||||||
@@ -259,7 +280,7 @@ public class SoundPreferenceControllerTest {
|
|||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
||||||
channel.setSound(null, new AudioAttributes.Builder().setUsage(
|
channel.setSound(null, new AudioAttributes.Builder().setUsage(
|
||||||
AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build());
|
AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build());
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
||||||
NotificationSoundPreference pref =
|
NotificationSoundPreference pref =
|
||||||
@@ -280,7 +301,7 @@ public class SoundPreferenceControllerTest {
|
|||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
||||||
channel.setSound(null, new AudioAttributes.Builder().setUsage(
|
channel.setSound(null, new AudioAttributes.Builder().setUsage(
|
||||||
AudioAttributes.USAGE_UNKNOWN).build());
|
AudioAttributes.USAGE_UNKNOWN).build());
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
||||||
NotificationSoundPreference pref =
|
NotificationSoundPreference pref =
|
||||||
|
@@ -45,6 +45,8 @@ import com.android.settings.notification.NotificationBackend;
|
|||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -55,6 +57,8 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class VibrationPreferenceControllerTest {
|
public class VibrationPreferenceControllerTest {
|
||||||
|
|
||||||
@@ -98,7 +102,7 @@ public class VibrationPreferenceControllerTest {
|
|||||||
when(mVibrator.hasVibrator()).thenReturn(false);
|
when(mVibrator.hasVibrator()).thenReturn(false);
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +110,7 @@ public class VibrationPreferenceControllerTest {
|
|||||||
public void testIsAvailable_notIfNotImportant() {
|
public void testIsAvailable_notIfNotImportant() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +119,7 @@ public class VibrationPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,16 +127,33 @@ public class VibrationPreferenceControllerTest {
|
|||||||
public void testIsAvailable() {
|
public void testIsAvailable() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredIn() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null,
|
||||||
|
ImmutableList.of(NotificationChannel.EDIT_VIBRATION));
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredOut() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_disabledByAdmin() {
|
public void testUpdateState_disabledByAdmin() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn("something");
|
when(channel.getId()).thenReturn("something");
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
||||||
RestrictedLockUtils.EnforcedAdmin.class));
|
RestrictedLockUtils.EnforcedAdmin.class), null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -145,7 +166,7 @@ public class VibrationPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
when(channel.isImportanceLockedByOEM()).thenReturn(true);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -158,7 +179,7 @@ public class VibrationPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn("something");
|
when(channel.getId()).thenReturn("something");
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -170,7 +191,8 @@ public class VibrationPreferenceControllerTest {
|
|||||||
public void testUpdateState_vibrateOn() {
|
public void testUpdateState_vibrateOn() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.shouldVibrate()).thenReturn(true);
|
when(channel.shouldVibrate()).thenReturn(true);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref =
|
RestrictedSwitchPreference pref =
|
||||||
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||||
@@ -182,7 +204,8 @@ public class VibrationPreferenceControllerTest {
|
|||||||
public void testUpdateState_vibrateOff() {
|
public void testUpdateState_vibrateOff() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.shouldVibrate()).thenReturn(false);
|
when(channel.shouldVibrate()).thenReturn(false);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref =
|
RestrictedSwitchPreference pref =
|
||||||
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||||
@@ -194,7 +217,8 @@ public class VibrationPreferenceControllerTest {
|
|||||||
public void testOnPreferenceChange_on() {
|
public void testOnPreferenceChange_on() {
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref =
|
RestrictedSwitchPreference pref =
|
||||||
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||||
@@ -210,7 +234,8 @@ public class VibrationPreferenceControllerTest {
|
|||||||
public void testOnPreferenceChange_off() {
|
public void testOnPreferenceChange_off() {
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null);
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
RestrictedSwitchPreference pref =
|
RestrictedSwitchPreference pref =
|
||||||
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||||
|
@@ -51,6 +51,8 @@ import com.android.settings.notification.NotificationBackend;
|
|||||||
import com.android.settings.testutils.shadow.ShadowRestrictionUtils;
|
import com.android.settings.testutils.shadow.ShadowRestrictionUtils;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -121,7 +123,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
when(mLockUtils.isSecure(anyInt())).thenReturn(false);
|
when(mLockUtils.isSecure(anyInt())).thenReturn(false);
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +131,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
public void testIsAvailable_notIfNotImportant() {
|
public void testIsAvailable_notIfNotImportant() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_MIN);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_MIN);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,14 +140,31 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel =
|
NotificationChannel channel =
|
||||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
|
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
|
|
||||||
channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredIn() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null,
|
||||||
|
ImmutableList.of(NotificationChannel.EDIT_LOCKED_DEVICE));
|
||||||
|
assertTrue(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_filteredOut() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||||
|
mController.onResume(appRow, channel, null, null, null, null, new ArrayList<>());
|
||||||
|
assertFalse(mController.isAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_disabledByAdmin_disableSecure() {
|
public void testUpdateState_disabledByAdmin_disableSecure() {
|
||||||
ShadowRestrictionUtils.setRestricted(true);
|
ShadowRestrictionUtils.setRestricted(true);
|
||||||
@@ -160,7 +179,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn("something");
|
when(channel.getId()).thenReturn("something");
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
||||||
RestrictedLockUtils.EnforcedAdmin.class));
|
RestrictedLockUtils.EnforcedAdmin.class), null);
|
||||||
|
|
||||||
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -182,7 +201,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn("something");
|
when(channel.getId()).thenReturn("something");
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, null, null, mock(
|
||||||
RestrictedLockUtils.EnforcedAdmin.class));
|
RestrictedLockUtils.EnforcedAdmin.class), null);
|
||||||
|
|
||||||
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -197,7 +216,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
|
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -222,7 +241,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
|
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -245,7 +264,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
|
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -262,7 +281,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
public void testUpdateState_noGlobalRestriction() {
|
public void testUpdateState_noGlobalRestriction() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -293,7 +312,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getLockscreenVisibility()).thenReturn(VISIBILITY_NO_OVERRIDE);
|
when(channel.getLockscreenVisibility()).thenReturn(VISIBILITY_NO_OVERRIDE);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -312,7 +331,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getLockscreenVisibility()).thenReturn(Notification.VISIBILITY_SECRET);
|
when(channel.getLockscreenVisibility()).thenReturn(Notification.VISIBILITY_SECRET);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -331,7 +350,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", 4);
|
NotificationChannel channel = new NotificationChannel("", "", 4);
|
||||||
channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
|
channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
@@ -350,7 +369,7 @@ public class VisibilityPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = new NotificationChannel("", "", 4);
|
NotificationChannel channel = new NotificationChannel("", "", 4);
|
||||||
channel.setLockscreenVisibility(VISIBILITY_NO_OVERRIDE);
|
channel.setLockscreenVisibility(VISIBILITY_NO_OVERRIDE);
|
||||||
mController.onResume(appRow, channel, null, null, null, null);
|
mController.onResume(appRow, channel, null, null, null, null, null);
|
||||||
|
|
||||||
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
RestrictedListPreference pref = mock(RestrictedListPreference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
Reference in New Issue
Block a user