Remove wrapper class for NotificationGroup.
It's no longer needed as Robolectric can natively support framework classes Bug: 76167422 Test: robotests Change-Id: If0ac597370240b8efaa8df8783a5c309a2322a3f
This commit is contained in:
@@ -56,7 +56,7 @@ public class BlockPreferenceController extends NotificationPreferenceController
|
|||||||
}
|
}
|
||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
return isChannelBlockable();
|
return isChannelBlockable();
|
||||||
} else if (mChannelGroup != null && mChannelGroup.getGroup() != null) {
|
} else if (mChannelGroup != null) {
|
||||||
return isChannelGroupBlockable();
|
return isChannelGroupBlockable();
|
||||||
} else {
|
} else {
|
||||||
return !mAppRow.systemApp || (mAppRow.systemApp && mAppRow.banned);
|
return !mAppRow.systemApp || (mAppRow.systemApp && mAppRow.banned);
|
||||||
@@ -80,7 +80,7 @@ public class BlockPreferenceController extends NotificationPreferenceController
|
|||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
bar.setChecked(!mAppRow.banned
|
bar.setChecked(!mAppRow.banned
|
||||||
&& mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE);
|
&& mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE);
|
||||||
} else if (mChannelGroup != null && mChannelGroup.getGroup() != null) {
|
} else if (mChannelGroup != null) {
|
||||||
bar.setChecked(!mAppRow.banned && !mChannelGroup.isBlocked());
|
bar.setChecked(!mAppRow.banned && !mChannelGroup.isBlocked());
|
||||||
} else {
|
} else {
|
||||||
bar.setChecked(!mAppRow.banned);
|
bar.setChecked(!mAppRow.banned);
|
||||||
@@ -107,9 +107,9 @@ public class BlockPreferenceController extends NotificationPreferenceController
|
|||||||
mAppRow.banned = blocked;
|
mAppRow.banned = blocked;
|
||||||
mBackend.setNotificationsEnabledForPackage(mAppRow.pkg, mAppRow.uid, !blocked);
|
mBackend.setNotificationsEnabledForPackage(mAppRow.pkg, mAppRow.uid, !blocked);
|
||||||
}
|
}
|
||||||
} else if (mChannelGroup != null && mChannelGroup.getGroup() != null) {
|
} else if (mChannelGroup != null) {
|
||||||
mChannelGroup.setBlocked(blocked);
|
mChannelGroup.setBlocked(blocked);
|
||||||
mBackend.updateChannelGroup(mAppRow.pkg, mAppRow.uid, mChannelGroup.getGroup());
|
mBackend.updateChannelGroup(mAppRow.pkg, mAppRow.uid, mChannelGroup);
|
||||||
} else if (mAppRow != null) {
|
} else if (mAppRow != null) {
|
||||||
mAppRow.banned = blocked;
|
mAppRow.banned = blocked;
|
||||||
mBackend.setNotificationsEnabledForPackage(mAppRow.pkg, mAppRow.uid, !blocked);
|
mBackend.setNotificationsEnabledForPackage(mAppRow.pkg, mAppRow.uid, !blocked);
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class ChannelGroupNotificationSettings extends NotificationSettingsBase {
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if (mAppRow == null || mChannelGroup == null || mChannelGroup.getGroup() == null) {
|
if (mAppRow == null || mChannelGroup == null) {
|
||||||
Log.w(TAG, "Missing package or uid or packageinfo or group");
|
Log.w(TAG, "Missing package or uid or packageinfo or group");
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
@@ -85,7 +85,7 @@ public class ChannelGroupNotificationSettings extends NotificationSettingsBase {
|
|||||||
getPreferenceScreen().removePreference(p);
|
getPreferenceScreen().removePreference(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mChannelGroup.getGroup().getChannels().isEmpty()) {
|
if (mChannelGroup.getChannels().isEmpty()) {
|
||||||
Preference empty = new Preference(getPrefContext());
|
Preference empty = new Preference(getPrefContext());
|
||||||
empty.setTitle(R.string.no_channels);
|
empty.setTitle(R.string.no_channels);
|
||||||
empty.setEnabled(false);
|
empty.setEnabled(false);
|
||||||
@@ -93,7 +93,7 @@ public class ChannelGroupNotificationSettings extends NotificationSettingsBase {
|
|||||||
mDynamicPreferences.add(empty);
|
mDynamicPreferences.add(empty);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
final List<NotificationChannel> channels = mChannelGroup.getGroup().getChannels();
|
final List<NotificationChannel> channels = mChannelGroup.getChannels();
|
||||||
Collections.sort(channels, mChannelComparator);
|
Collections.sort(channels, mChannelComparator);
|
||||||
for (NotificationChannel channel : channels) {
|
for (NotificationChannel channel : channels) {
|
||||||
mDynamicPreferences.add(populateSingleChannelPrefs(
|
mDynamicPreferences.add(populateSingleChannelPrefs(
|
||||||
|
|||||||
@@ -73,27 +73,27 @@ public class HeaderPreferenceController extends NotificationPreferenceController
|
|||||||
|
|
||||||
CharSequence getLabel() {
|
CharSequence getLabel() {
|
||||||
return mChannel != null ? mChannel.getName()
|
return mChannel != null ? mChannel.getName()
|
||||||
: mChannelGroup != null && mChannelGroup.getGroup() != null
|
: mChannelGroup != null
|
||||||
? mChannelGroup.getGroup().getName()
|
? mChannelGroup.getName()
|
||||||
: mAppRow.label;
|
: mAppRow.label;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getSummary() {
|
public CharSequence getSummary() {
|
||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
if (mChannelGroup != null && mChannelGroup.getGroup() != null
|
if (mChannelGroup != null
|
||||||
&& !TextUtils.isEmpty(mChannelGroup.getGroup().getName())) {
|
&& !TextUtils.isEmpty(mChannelGroup.getName())) {
|
||||||
final SpannableStringBuilder summary = new SpannableStringBuilder();
|
final SpannableStringBuilder summary = new SpannableStringBuilder();
|
||||||
BidiFormatter bidi = BidiFormatter.getInstance();
|
BidiFormatter bidi = BidiFormatter.getInstance();
|
||||||
summary.append(bidi.unicodeWrap(mAppRow.label.toString()));
|
summary.append(bidi.unicodeWrap(mAppRow.label.toString()));
|
||||||
summary.append(bidi.unicodeWrap(mContext.getText(
|
summary.append(bidi.unicodeWrap(mContext.getText(
|
||||||
R.string.notification_header_divider_symbol_with_spaces)));
|
R.string.notification_header_divider_symbol_with_spaces)));
|
||||||
summary.append(bidi.unicodeWrap(mChannelGroup.getGroup().getName().toString()));
|
summary.append(bidi.unicodeWrap(mChannelGroup.getName().toString()));
|
||||||
return summary.toString();
|
return summary.toString();
|
||||||
} else {
|
} else {
|
||||||
return mAppRow.label.toString();
|
return mAppRow.label.toString();
|
||||||
}
|
}
|
||||||
} else if (mChannelGroup != null && mChannelGroup.getGroup() != null) {
|
} else if (mChannelGroup != null) {
|
||||||
return mAppRow.label.toString();
|
return mAppRow.label.toString();
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@@ -25,13 +25,11 @@ import android.app.NotificationManager;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.support.annotation.VisibleForTesting;
|
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceGroup;
|
import android.support.v7.preference.PreferenceGroup;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
|
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
@@ -41,11 +39,12 @@ import java.util.Objects;
|
|||||||
* Parent class for preferences appearing on notification setting pages at the app,
|
* Parent class for preferences appearing on notification setting pages at the app,
|
||||||
* notification channel group, or notification channel level.
|
* notification channel group, or notification channel level.
|
||||||
*/
|
*/
|
||||||
public abstract class NotificationPreferenceController extends AbstractPreferenceController
|
public abstract class NotificationPreferenceController extends AbstractPreferenceController {
|
||||||
{
|
|
||||||
private static final String TAG = "ChannelPrefContr";
|
private static final String TAG = "ChannelPrefContr";
|
||||||
@Nullable protected NotificationChannel mChannel;
|
@Nullable
|
||||||
@Nullable protected NotificationChannelGroupWrapper mChannelGroup;
|
protected NotificationChannel mChannel;
|
||||||
|
@Nullable
|
||||||
|
protected NotificationChannelGroup mChannelGroup;
|
||||||
protected RestrictedLockUtils.EnforcedAdmin mAdmin;
|
protected RestrictedLockUtils.EnforcedAdmin mAdmin;
|
||||||
protected NotificationBackend.AppRow mAppRow;
|
protected NotificationBackend.AppRow mAppRow;
|
||||||
protected final NotificationManager mNm;
|
protected final NotificationManager mNm;
|
||||||
@@ -78,7 +77,7 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
|
|||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
return mChannel.getImportance() != IMPORTANCE_NONE;
|
return mChannel.getImportance() != IMPORTANCE_NONE;
|
||||||
}
|
}
|
||||||
if (mChannelGroup != null && mChannelGroup.getGroup() == null) {
|
if (mChannelGroup != null) {
|
||||||
return !mChannelGroup.isBlocked();
|
return !mChannelGroup.isBlocked();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -125,7 +124,7 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void onResume(NotificationBackend.AppRow appRow,
|
protected void onResume(NotificationBackend.AppRow appRow,
|
||||||
@Nullable NotificationChannel channel, @Nullable NotificationChannelGroupWrapper group,
|
@Nullable NotificationChannel channel, @Nullable NotificationChannelGroup group,
|
||||||
RestrictedLockUtils.EnforcedAdmin admin) {
|
RestrictedLockUtils.EnforcedAdmin admin) {
|
||||||
mAppRow = appRow;
|
mAppRow = appRow;
|
||||||
mChannel = channel;
|
mChannel = channel;
|
||||||
@@ -172,7 +171,7 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isChannelGroupBlockable() {
|
protected boolean isChannelGroupBlockable() {
|
||||||
if (mChannelGroup != null && mChannelGroup.getGroup() != null && mAppRow != null) {
|
if (mChannelGroup != null && mAppRow != null) {
|
||||||
if (!mAppRow.systemApp) {
|
if (!mAppRow.systemApp) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -183,6 +182,6 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected boolean hasValidGroup() {
|
protected boolean hasValidGroup() {
|
||||||
return mChannelGroup != null && mChannelGroup.getGroup() != null;
|
return mChannelGroup != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import com.android.settings.applications.AppInfoBase;
|
|||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.widget.MasterCheckBoxPreference;
|
import com.android.settings.widget.MasterCheckBoxPreference;
|
||||||
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
|
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -70,7 +69,7 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
|
|||||||
protected String mPkg;
|
protected String mPkg;
|
||||||
protected PackageInfo mPkgInfo;
|
protected PackageInfo mPkgInfo;
|
||||||
protected EnforcedAdmin mSuspendedAppsAdmin;
|
protected EnforcedAdmin mSuspendedAppsAdmin;
|
||||||
protected NotificationChannelGroupWrapper mChannelGroup;
|
protected NotificationChannelGroup mChannelGroup;
|
||||||
protected NotificationChannel mChannel;
|
protected NotificationChannel mChannel;
|
||||||
protected NotificationBackend.AppRow mAppRow;
|
protected NotificationBackend.AppRow mAppRow;
|
||||||
|
|
||||||
@@ -168,7 +167,7 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
|
|||||||
if (mChannel != null && !TextUtils.isEmpty(mChannel.getGroup())) {
|
if (mChannel != null && !TextUtils.isEmpty(mChannel.getGroup())) {
|
||||||
group = mBackend.getGroup(mPkg, mUid, mChannel.getGroup());
|
group = mBackend.getGroup(mPkg, mUid, mChannel.getGroup());
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
mChannelGroup = new NotificationChannelGroupWrapper(group);
|
mChannelGroup = group;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,7 +208,7 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
|
|||||||
}
|
}
|
||||||
if (mChannelGroup != null) {
|
if (mChannelGroup != null) {
|
||||||
mAppRow.settingsIntent.putExtra(
|
mAppRow.settingsIntent.putExtra(
|
||||||
Notification.EXTRA_CHANNEL_GROUP_ID, mChannelGroup.getGroup().getId());
|
Notification.EXTRA_CHANNEL_GROUP_ID, mChannelGroup.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import android.support.v7.preference.Preference;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settingslib.widget.FooterPreference;
|
|
||||||
|
|
||||||
public class NotificationsOffPreferenceController extends NotificationPreferenceController
|
public class NotificationsOffPreferenceController extends NotificationPreferenceController
|
||||||
implements PreferenceControllerMixin {
|
implements PreferenceControllerMixin {
|
||||||
@@ -51,7 +50,7 @@ public class NotificationsOffPreferenceController extends NotificationPreference
|
|||||||
if (mAppRow != null) {
|
if (mAppRow != null) {
|
||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
preference.setTitle(R.string.channel_notifications_off_desc);
|
preference.setTitle(R.string.channel_notifications_off_desc);
|
||||||
} else if (mChannelGroup != null && mChannelGroup.getGroup() == null) {
|
} else if (mChannelGroup != null) {
|
||||||
preference.setTitle(R.string.channel_group_notifications_off_desc);
|
preference.setTitle(R.string.channel_group_notifications_off_desc);
|
||||||
} else {
|
} else {
|
||||||
preference.setTitle(R.string.app_notifications_off_desc);
|
preference.setTitle(R.string.app_notifications_off_desc);
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.wrapper;
|
|
||||||
|
|
||||||
import android.app.NotificationChannelGroup;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper for {@link NotificationChannelGroup} until roboletric supports O MR1.
|
|
||||||
*/
|
|
||||||
public class NotificationChannelGroupWrapper {
|
|
||||||
|
|
||||||
private final NotificationChannelGroup mGroup;
|
|
||||||
|
|
||||||
public NotificationChannelGroupWrapper(NotificationChannelGroup group) {
|
|
||||||
mGroup = group;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the real group object so we can call APIs directly on it.
|
|
||||||
*/
|
|
||||||
public NotificationChannelGroup getGroup() {
|
|
||||||
return mGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
if (mGroup != null) {
|
|
||||||
return mGroup.getDescription();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription(String desc) {
|
|
||||||
if (mGroup != null) {
|
|
||||||
mGroup.setDescription(desc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isBlocked() {
|
|
||||||
if (mGroup != null) {
|
|
||||||
return mGroup.isBlocked();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBlocked(boolean blocked) {
|
|
||||||
if (mGroup != null) {
|
|
||||||
mGroup.setBlocked(blocked);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -46,7 +46,6 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.applications.LayoutPreference;
|
import com.android.settings.applications.LayoutPreference;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.widget.SwitchBar;
|
import com.android.settings.widget.SwitchBar;
|
||||||
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -113,7 +112,7 @@ public class BlockPreferenceControllerTest {
|
|||||||
public void testIsAvailable_notIfGroupNotBlockable() {
|
public void testIsAvailable_notIfGroupNotBlockable() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.systemApp = true;
|
appRow.systemApp = true;
|
||||||
mController.onResume(appRow, null, mock(NotificationChannelGroupWrapper.class), null);
|
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,8 +165,7 @@ public class BlockPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateState_group() {
|
public void testUpdateState_group() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.getGroup()).thenReturn(mock(NotificationChannelGroup.class));
|
|
||||||
when(group.isBlocked()).thenReturn(true);
|
when(group.isBlocked()).thenReturn(true);
|
||||||
mController.onResume(appRow, null, group, null);
|
mController.onResume(appRow, null, group, null);
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|||||||
@@ -26,13 +26,12 @@ import static org.mockito.Mockito.verify;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
|
import android.app.NotificationChannelGroup;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
|
|
||||||
|
|
||||||
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;
|
||||||
@@ -82,7 +81,7 @@ public class DeletedChannelsPreferenceControllerTest {
|
|||||||
@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(NotificationChannelGroupWrapper.class), null);
|
mController.onResume(appRow, null, mock(NotificationChannelGroup.class), null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ import android.os.UserManager;
|
|||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -79,8 +78,7 @@ public class DescriptionPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_notIfChannelGroupBlocked() {
|
public void testIsAvailable_notIfChannelGroupBlocked() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.isBlocked()).thenReturn(true);
|
|
||||||
mController.onResume(appRow, null, group, null);
|
mController.onResume(appRow, null, group, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
@@ -106,8 +104,7 @@ public class DescriptionPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_notIfNoChannelGroupDesc() {
|
public void testIsAvailable_notIfNoChannelGroupDesc() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.getGroup()).thenReturn(mock(NotificationChannelGroup.class));
|
|
||||||
mController.onResume(appRow, null, group, null);
|
mController.onResume(appRow, null, group, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
@@ -125,8 +122,7 @@ public class DescriptionPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_channelGroup() {
|
public void testIsAvailable_channelGroup() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.getGroup()).thenReturn(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);
|
mController.onResume(appRow, null, group, null);
|
||||||
@@ -152,8 +148,7 @@ public class DescriptionPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateState_channelGroup() {
|
public void testUpdateState_channelGroup() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.getGroup()).thenReturn(mock(NotificationChannelGroup.class));
|
|
||||||
when(group.getDescription()).thenReturn("something");
|
when(group.getDescription()).thenReturn("something");
|
||||||
mController.onResume(appRow, null, group, null);
|
mController.onResume(appRow, null, group, null);
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import android.view.View;
|
|||||||
|
|
||||||
import com.android.settings.applications.LayoutPreference;
|
import com.android.settings.applications.LayoutPreference;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -104,12 +103,11 @@ public class HeaderPreferenceControllerTest {
|
|||||||
assertEquals(appRow.label, mController.getLabel());
|
assertEquals(appRow.label, mController.getLabel());
|
||||||
|
|
||||||
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
|
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
|
||||||
NotificationChannelGroupWrapper gWrapper = new NotificationChannelGroupWrapper(group);
|
mController.onResume(appRow, null, group, null);
|
||||||
mController.onResume(appRow, null, gWrapper, 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, gWrapper, null);
|
mController.onResume(appRow, channel, group, null);
|
||||||
assertEquals(channel.getName(), mController.getLabel());
|
assertEquals(channel.getName(), mController.getLabel());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,12 +119,11 @@ public class HeaderPreferenceControllerTest {
|
|||||||
assertEquals("", mController.getSummary());
|
assertEquals("", mController.getSummary());
|
||||||
|
|
||||||
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
|
NotificationChannelGroup group = new NotificationChannelGroup("id", "name");
|
||||||
NotificationChannelGroupWrapper gWrapper = new NotificationChannelGroupWrapper(group);
|
mController.onResume(appRow, null, group, null);
|
||||||
mController.onResume(appRow, null, gWrapper, 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, gWrapper, null);
|
mController.onResume(appRow, channel, group, 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));
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ import android.os.UserManager;
|
|||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
|
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -76,7 +75,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noCrashIfNoOnResume() throws Exception {
|
public void noCrashIfNoOnResume() {
|
||||||
mController.isAvailable();
|
mController.isAvailable();
|
||||||
mController.updateState(mock(Preference.class));
|
mController.updateState(mock(Preference.class));
|
||||||
assertFalse(mController.checkCanBeVisible(IMPORTANCE_UNSPECIFIED));
|
assertFalse(mController.checkCanBeVisible(IMPORTANCE_UNSPECIFIED));
|
||||||
@@ -87,22 +86,22 @@ public class NotificationPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_notIfNull() throws Exception {
|
public void isAvailable_notIfNull() {
|
||||||
mController.onResume(null, null, null, null);
|
mController.onResume(null, null, null, null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_notIfAppBlocked() throws Exception {
|
public void isAvailable_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),
|
mController.onResume(appRow, mock(NotificationChannel.class),
|
||||||
mock(NotificationChannelGroupWrapper.class), null);
|
mock(NotificationChannelGroup.class), null);
|
||||||
assertFalse(mController.isAvailable());
|
assertFalse(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_notIfChannelBlocked() throws Exception {
|
public void isAvailable_notIfChannelBlocked() {
|
||||||
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);
|
||||||
@@ -112,10 +111,10 @@ public class NotificationPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_notIfChannelGroupBlocked() throws Exception {
|
public void isAvailable_notIfChannelGroupBlocked() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, group, null);
|
mController.onResume(appRow, channel, group, null);
|
||||||
when(group.isBlocked()).thenReturn(true);
|
when(group.isBlocked()).thenReturn(true);
|
||||||
@@ -123,11 +122,11 @@ public class NotificationPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable() throws Exception {
|
public void isAvailable() {
|
||||||
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);
|
||||||
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.isBlocked()).thenReturn(false);
|
when(group.isBlocked()).thenReturn(false);
|
||||||
|
|
||||||
mController.onResume(appRow, channel, group, null);
|
mController.onResume(appRow, channel, group, null);
|
||||||
@@ -135,10 +134,10 @@ public class NotificationPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnResume() throws Exception {
|
public void testOnResume() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.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, admin);
|
mController.onResume(appRow, channel, group, admin);
|
||||||
@@ -266,8 +265,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
public void testIsChannelGroupBlockable_nonSystemBlockable() {
|
public void testIsChannelGroupBlockable_nonSystemBlockable() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.systemApp = false;
|
appRow.systemApp = false;
|
||||||
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.getGroup()).thenReturn(mock(NotificationChannelGroup.class));
|
|
||||||
when(group.isBlocked()).thenReturn(false);
|
when(group.isBlocked()).thenReturn(false);
|
||||||
|
|
||||||
mController.onResume(appRow, null, group, null);
|
mController.onResume(appRow, null, group, null);
|
||||||
@@ -278,8 +276,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
public void testIsChannelGroupBlockable_SystemNotBlockable() {
|
public void testIsChannelGroupBlockable_SystemNotBlockable() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.systemApp = true;
|
appRow.systemApp = true;
|
||||||
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.getGroup()).thenReturn(mock(NotificationChannelGroup.class));
|
|
||||||
when(group.isBlocked()).thenReturn(false);
|
when(group.isBlocked()).thenReturn(false);
|
||||||
|
|
||||||
mController.onResume(appRow, null, group, null);
|
mController.onResume(appRow, null, group, null);
|
||||||
@@ -290,8 +287,7 @@ public class NotificationPreferenceControllerTest {
|
|||||||
public void testIsChannelGroupBlockable_canUndoSystemBlock() {
|
public void testIsChannelGroupBlockable_canUndoSystemBlock() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.systemApp = true;
|
appRow.systemApp = true;
|
||||||
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.getGroup()).thenReturn(mock(NotificationChannelGroup.class));
|
|
||||||
when(group.isBlocked()).thenReturn(true);
|
when(group.isBlocked()).thenReturn(true);
|
||||||
|
|
||||||
mController.onResume(appRow, null, group, null);
|
mController.onResume(appRow, null, group, null);
|
||||||
|
|||||||
@@ -17,20 +17,19 @@
|
|||||||
package com.android.settings.notification;
|
package com.android.settings.notification;
|
||||||
|
|
||||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
||||||
import static junit.framework.Assert.assertFalse;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static junit.framework.Assert.assertTrue;
|
|
||||||
import static org.mockito.Mockito.mock;
|
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.NotificationChannel;
|
||||||
|
import android.app.NotificationChannelGroup;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -70,16 +69,16 @@ public class NotificationsOffPreferenceControllerTest {
|
|||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
appRow.banned = true;
|
appRow.banned = true;
|
||||||
mController.onResume(appRow, null, null, null);
|
mController.onResume(appRow, null, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_yesIfChannelGroupBlocked() {
|
public void testIsAvailable_yesIfChannelGroupBlocked() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.isBlocked()).thenReturn(true);
|
when(group.isBlocked()).thenReturn(true);
|
||||||
mController.onResume(appRow, null, group, null);
|
mController.onResume(appRow, null, group, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -88,7 +87,7 @@ public class NotificationsOffPreferenceControllerTest {
|
|||||||
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);
|
mController.onResume(appRow, channel, null, null);
|
||||||
assertTrue(mController.isAvailable());
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -101,22 +100,22 @@ public class NotificationsOffPreferenceControllerTest {
|
|||||||
Preference pref = new Preference(RuntimeEnvironment.application);
|
Preference pref = new Preference(RuntimeEnvironment.application);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
assertTrue(pref.getTitle().toString().contains("category"));
|
assertThat(pref.getTitle().toString()).contains("category");
|
||||||
assertFalse(pref.isSelectable());
|
assertThat(pref.isSelectable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_channelGroup() {
|
public void testUpdateState_channelGroup() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
NotificationChannelGroupWrapper group = mock(NotificationChannelGroupWrapper.class);
|
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
|
||||||
when(group.isBlocked()).thenReturn(true);
|
when(group.isBlocked()).thenReturn(true);
|
||||||
mController.onResume(appRow, null, group, null);
|
mController.onResume(appRow, null, group, null);
|
||||||
|
|
||||||
Preference pref = new Preference(RuntimeEnvironment.application);
|
Preference pref = new Preference(RuntimeEnvironment.application);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
assertTrue(pref.getTitle().toString().contains("group"));
|
assertThat(pref.getTitle().toString()).contains("group");
|
||||||
assertFalse(pref.isSelectable());
|
assertThat(pref.isSelectable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -128,7 +127,7 @@ public class NotificationsOffPreferenceControllerTest {
|
|||||||
Preference pref = new Preference(RuntimeEnvironment.application);
|
Preference pref = new Preference(RuntimeEnvironment.application);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
assertTrue(pref.getTitle().toString().contains("app"));
|
assertThat(pref.getTitle().toString()).contains("app");
|
||||||
assertFalse(pref.isSelectable());
|
assertThat(pref.isSelectable()).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user