Merge changes from topic "remove_wrappers" into pi-dev

* changes:
  Remove wrapper class for NotificationGroup.
  Remove more wrappers in favor of new Robolectric support
This commit is contained in:
TreeHugger Robot
2018-03-31 01:26:16 +00:00
committed by Android (Google) Code Review
32 changed files with 160 additions and 501 deletions

View File

@@ -25,7 +25,6 @@ import android.net.ConnectivityManager;
import android.os.UserManager; import android.os.UserManager;
import android.support.annotation.VisibleForTesting; import android.support.annotation.VisibleForTesting;
import com.android.settings.wrapper.UsbManagerWrapper;
import com.android.settings.wrapper.UserManagerWrapper; import com.android.settings.wrapper.UserManagerWrapper;
/** /**
@@ -44,7 +43,6 @@ public class UsbBackend {
private final boolean mTetheringSupported; private final boolean mTetheringSupported;
private UsbManager mUsbManager; private UsbManager mUsbManager;
private UsbManagerWrapper mUsbManagerWrapper;
@Nullable @Nullable
private UsbPort mPort; private UsbPort mPort;
@@ -52,19 +50,13 @@ public class UsbBackend {
private UsbPortStatus mPortStatus; private UsbPortStatus mPortStatus;
public UsbBackend(Context context) { public UsbBackend(Context context) {
this(context, new UserManagerWrapper(UserManager.get(context)), null); this(context, new UserManagerWrapper(UserManager.get(context)));
} }
@VisibleForTesting @VisibleForTesting
public UsbBackend(Context context, UserManagerWrapper userManagerWrapper, public UsbBackend(Context context, UserManagerWrapper userManagerWrapper) {
UsbManagerWrapper usbManagerWrapper) {
mUsbManager = context.getSystemService(UsbManager.class); mUsbManager = context.getSystemService(UsbManager.class);
mUsbManagerWrapper = usbManagerWrapper;
if (mUsbManagerWrapper == null) {
mUsbManagerWrapper = new UsbManagerWrapper(mUsbManager);
}
mFileTransferRestricted = userManagerWrapper.isUsbFileTransferRestricted(); mFileTransferRestricted = userManagerWrapper.isUsbFileTransferRestricted();
mFileTransferRestrictedBySystem = userManagerWrapper.isUsbFileTransferRestrictedBySystem(); mFileTransferRestrictedBySystem = userManagerWrapper.isUsbFileTransferRestrictedBySystem();
mTetheringRestricted = userManagerWrapper.isUsbTetheringRestricted(); mTetheringRestricted = userManagerWrapper.isUsbTetheringRestricted();
@@ -79,7 +71,7 @@ public class UsbBackend {
} }
public long getCurrentFunctions() { public long getCurrentFunctions() {
return mUsbManagerWrapper.getCurrentFunctions(); return mUsbManager.getCurrentFunctions();
} }
public void setCurrentFunctions(long functions) { public void setCurrentFunctions(long functions) {

View File

@@ -31,7 +31,6 @@ import android.support.v7.preference.PreferenceScreen;
import android.util.Log; import android.util.Log;
import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.wrapper.PowerManagerWrapper;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -72,21 +71,15 @@ public class BrightnessLevelPreferenceController extends AbstractPreferenceContr
}; };
public BrightnessLevelPreferenceController(Context context, Lifecycle lifecycle) { public BrightnessLevelPreferenceController(Context context, Lifecycle lifecycle) {
this(context, lifecycle, new PowerManagerWrapper(
(PowerManager) context.getSystemService(Context.POWER_SERVICE)));
}
@VisibleForTesting
public BrightnessLevelPreferenceController(Context context, Lifecycle lifecycle,
PowerManagerWrapper powerManagerWrapper) {
super(context); super(context);
if (lifecycle != null) { if (lifecycle != null) {
lifecycle.addObserver(this); lifecycle.addObserver(this);
} }
mMinBrightness = powerManagerWrapper.getMinimumScreenBrightnessSetting(); PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
mMaxBrightness = powerManagerWrapper.getMaximumScreenBrightnessSetting(); mMinBrightness = powerManager.getMinimumScreenBrightnessSetting();
mMinVrBrightness = powerManagerWrapper.getMinimumScreenBrightnessForVrSetting(); mMaxBrightness = powerManager.getMaximumScreenBrightnessSetting();
mMaxVrBrightness = powerManagerWrapper.getMaximumScreenBrightnessForVrSetting(); mMinVrBrightness = powerManager.getMinimumScreenBrightnessForVrSetting();
mMaxVrBrightness = powerManager.getMaximumScreenBrightnessForVrSetting();
mContentResolver = mContext.getContentResolver(); mContentResolver = mContext.getContentResolver();
} }

View File

@@ -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);

View File

@@ -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(

View File

@@ -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 "";

View File

@@ -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;
} }
} }

View File

@@ -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());
} }
} }
} }

View File

@@ -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);

View File

@@ -29,7 +29,6 @@ import android.support.v7.preference.PreferenceScreen;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
import com.android.settings.wrapper.PrintManagerWrapper;
import com.android.settingslib.RestrictedPreference; import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStart;
@@ -46,13 +45,15 @@ public class PrintSettingPreferenceController extends BasePreferenceController i
private static final String KEY_PRINTING_SETTINGS = "connected_device_printing"; private static final String KEY_PRINTING_SETTINGS = "connected_device_printing";
private final PackageManager mPackageManager; private final PackageManager mPackageManager;
private PrintManagerWrapper mPrintManager; private final PrintManager mPrintManager;
private Preference mPreference; private Preference mPreference;
public PrintSettingPreferenceController(Context context) { public PrintSettingPreferenceController(Context context) {
super(context, KEY_PRINTING_SETTINGS); super(context, KEY_PRINTING_SETTINGS);
mPackageManager = context.getPackageManager(); mPackageManager = context.getPackageManager();
mPrintManager = new PrintManagerWrapper(context); mPrintManager = ((PrintManager) context.getSystemService(Context.PRINT_SERVICE))
.getGlobalPrintManagerForUser(context.getUserId());
} }
@Override @Override
@@ -69,7 +70,7 @@ public class PrintSettingPreferenceController extends BasePreferenceController i
@Override @Override
public void onStart() { public void onStart() {
mPrintManager.addPrintJobStateChanegListener(this); mPrintManager.addPrintJobStateChangeListener(this);
} }
@Override @Override

View File

@@ -28,14 +28,13 @@ import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen; import android.support.v7.preference.PreferenceScreen;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import com.android.internal.logging.nano.MetricsProto; import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment; import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.search.Indexable; import com.android.settings.search.Indexable;
import com.android.settings.wrapper.WifiManagerWrapper;
import com.android.settingslib.wifi.AccessPoint; import com.android.settingslib.wifi.AccessPoint;
import com.android.settingslib.wifi.AccessPointPreference; import com.android.settingslib.wifi.AccessPointPreference;
import com.android.settingslib.wifi.WifiSavedConfigUtils; import com.android.settingslib.wifi.WifiSavedConfigUtils;
@@ -107,7 +106,7 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
}; };
private WifiDialog mDialog; private WifiDialog mDialog;
private WifiManagerWrapper mWifiManager; private WifiManager mWifiManager;
private AccessPoint mDlgAccessPoint; private AccessPoint mDlgAccessPoint;
private Bundle mAccessPointSavedState; private Bundle mAccessPointSavedState;
private AccessPoint mSelectedAccessPoint; private AccessPoint mSelectedAccessPoint;
@@ -139,7 +138,7 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
mWifiManager = new WifiManagerWrapper((WifiManager) getSystemService(Context.WIFI_SERVICE)); mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if (savedInstanceState != null) { if (savedInstanceState != null) {
if (savedInstanceState.containsKey(SAVE_DIALOG_ACCESS_POINT_STATE)) { if (savedInstanceState.containsKey(SAVE_DIALOG_ACCESS_POINT_STATE)) {
@@ -154,7 +153,7 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
final Context context = getPrefContext(); final Context context = getPrefContext();
final List<AccessPoint> accessPoints = final List<AccessPoint> accessPoints =
WifiSavedConfigUtils.getAllConfigs(context, mWifiManager.getWifiManager()); WifiSavedConfigUtils.getAllConfigs(context, mWifiManager);
Collections.sort(accessPoints, SAVED_NETWORK_COMPARATOR); Collections.sort(accessPoints, SAVED_NETWORK_COMPARATOR);
cacheRemoveAllPrefs(preferenceScreen); cacheRemoveAllPrefs(preferenceScreen);

View File

@@ -65,7 +65,6 @@ import com.android.settings.widget.SummaryUpdater.OnSummaryChangeListener;
import com.android.settings.widget.SwitchBarController; import com.android.settings.widget.SwitchBarController;
import com.android.settings.wifi.details.WifiNetworkDetailsFragment; import com.android.settings.wifi.details.WifiNetworkDetailsFragment;
import com.android.settings.wrapper.ConnectivityManagerWrapper; import com.android.settings.wrapper.ConnectivityManagerWrapper;
import com.android.settings.wrapper.WifiManagerWrapper;
import com.android.settingslib.RestrictedLockUtils; import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.wifi.AccessPoint; import com.android.settingslib.wifi.AccessPoint;
import com.android.settingslib.wifi.AccessPoint.AccessPointListener; import com.android.settingslib.wifi.AccessPoint.AccessPointListener;
@@ -136,7 +135,7 @@ public class WifiSettings extends RestrictedSettingsFragment
private boolean mIsRestricted; private boolean mIsRestricted;
private WifiEnabler mWifiEnabler; private WifiEnabler mWifiEnabler;
// An access point being editted is stored here. // An access point being edited is stored here.
private AccessPoint mSelectedAccessPoint; private AccessPoint mSelectedAccessPoint;
private WifiDialog mDialog; private WifiDialog mDialog;
@@ -608,11 +607,10 @@ public class WifiSettings extends RestrictedSettingsFragment
if (mSelectedAccessPoint != null) { if (mSelectedAccessPoint != null) {
mWifiToNfcDialog = new WriteWifiConfigToNfcDialog( mWifiToNfcDialog = new WriteWifiConfigToNfcDialog(
getActivity(), getActivity(),
mSelectedAccessPoint.getSecurity(), mSelectedAccessPoint.getSecurity());
new WifiManagerWrapper(mWifiManager));
} else if (mWifiNfcDialogSavedState != null) { } else if (mWifiNfcDialogSavedState != null) {
mWifiToNfcDialog = new WriteWifiConfigToNfcDialog(getActivity(), mWifiToNfcDialog = new WriteWifiConfigToNfcDialog(getActivity(),
mWifiNfcDialogSavedState, new WifiManagerWrapper(mWifiManager)); mWifiNfcDialogSavedState);
} }
return mWifiToNfcDialog; return mWifiToNfcDialog;

View File

@@ -20,6 +20,7 @@ import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.net.wifi.WifiManager;
import android.nfc.FormatException; import android.nfc.FormatException;
import android.nfc.NdefMessage; import android.nfc.NdefMessage;
import android.nfc.NdefRecord; import android.nfc.NdefRecord;
@@ -27,7 +28,6 @@ import android.nfc.NfcAdapter;
import android.nfc.Tag; import android.nfc.Tag;
import android.nfc.tech.Ndef; import android.nfc.tech.Ndef;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager; import android.os.PowerManager;
import android.text.Editable; import android.text.Editable;
import android.text.InputType; import android.text.InputType;
@@ -42,7 +42,6 @@ import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.wrapper.WifiManagerWrapper;
import com.android.settingslib.wifi.AccessPoint; import com.android.settingslib.wifi.AccessPoint;
import java.io.IOException; import java.io.IOException;
@@ -67,29 +66,29 @@ class WriteWifiConfigToNfcDialog extends AlertDialog
private TextView mLabelView; private TextView mLabelView;
private CheckBox mPasswordCheckBox; private CheckBox mPasswordCheckBox;
private ProgressBar mProgressBar; private ProgressBar mProgressBar;
private WifiManagerWrapper mWifiManager; private WifiManager mWifiManager;
private String mWpsNfcConfigurationToken; private String mWpsNfcConfigurationToken;
private Context mContext; private Context mContext;
private int mSecurity; private int mSecurity;
WriteWifiConfigToNfcDialog(Context context, int security, WifiManagerWrapper wifiManager) { WriteWifiConfigToNfcDialog(Context context, int security) {
super(context); super(context);
mContext = context; mContext = context;
mWakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE)) mWakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE))
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WriteWifiConfigToNfcDialog:wakeLock"); .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WriteWifiConfigToNfcDialog:wakeLock");
mSecurity = security; mSecurity = security;
mWifiManager = wifiManager; mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
} }
WriteWifiConfigToNfcDialog(Context context, Bundle savedState, WifiManagerWrapper wifiManager) { WriteWifiConfigToNfcDialog(Context context, Bundle savedState) {
super(context); super(context);
mContext = context; mContext = context;
mWakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE)) mWakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE))
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WriteWifiConfigToNfcDialog:wakeLock"); .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WriteWifiConfigToNfcDialog:wakeLock");
mSecurity = savedState.getInt(SECURITY); mSecurity = savedState.getInt(SECURITY);
mWifiManager = wifiManager; mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
} }
@Override @Override

View File

@@ -1,47 +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.accessibilityservice.AccessibilityServiceInfo;
import android.content.ComponentName;
/**
* This class replicates a subset of the
* {@link android.accessibilityservice.AccessibilityServiceInfo}. The class
* exists so that we can use a thin wrapper around it in production code and a mock in tests.
* We cannot directly mock or shadow it, because some of the methods we rely on are newer than
* the API version supported by Robolectric.
*/
public class AccessibilityServiceInfoWrapper {
private final AccessibilityServiceInfo mServiceInfo;
public AccessibilityServiceInfoWrapper(AccessibilityServiceInfo serviceInfo) {
mServiceInfo = serviceInfo;
}
/**
* Returns the real {@code AccessibilityServiceInfo} object.
*/
public AccessibilityServiceInfo getAccessibilityServiceInfo() {
return mServiceInfo;
}
public ComponentName getComponentName() {
return mServiceInfo.getComponentName();
}
}

View File

@@ -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);
}
}
}

View File

@@ -1,49 +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.os.PowerManager;
/**
* This class replicates a subset of the android.os.PowerManager. The class exists so that we can
* use a thin wrapper around the PowerManager in production code and a mock in tests. We cannot
* directly mock or shadow the PowerManager, because some of the methods we rely on are newer than
* the API version supported by Robolectric or are hidden.
*/
public class PowerManagerWrapper {
private final PowerManager mPowerManager;
public PowerManagerWrapper(PowerManager powerManager) {
mPowerManager = powerManager;
}
public int getMinimumScreenBrightnessSetting() {
return mPowerManager.getMinimumScreenBrightnessSetting();
}
public int getMaximumScreenBrightnessSetting() {
return mPowerManager.getMaximumScreenBrightnessSetting();
}
public int getMinimumScreenBrightnessForVrSetting() {
return mPowerManager.getMinimumScreenBrightnessForVrSetting();
}
public int getMaximumScreenBrightnessForVrSetting() {
return mPowerManager.getMaximumScreenBrightnessForVrSetting();
}
}

View File

@@ -1,54 +0,0 @@
/*
* Copyright (C) 2018 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.content.Context;
import android.print.PrintJob;
import android.print.PrintManager;
import android.printservice.PrintServiceInfo;
import java.util.List;
/**
* Wrapper class for {@link PrintManager}. This is necessary to increase testability in Robolectric.
*/
public class PrintManagerWrapper {
private final PrintManager mPrintManager;
public PrintManagerWrapper(Context context) {
mPrintManager = ((PrintManager) context.getSystemService(Context.PRINT_SERVICE))
.getGlobalPrintManagerForUser(context.getUserId());
}
public List<PrintServiceInfo> getPrintServices(int selectionFlags) {
return mPrintManager.getPrintServices(selectionFlags);
}
public void addPrintJobStateChanegListener(PrintManager.PrintJobStateChangeListener listener) {
mPrintManager.addPrintJobStateChangeListener(listener);
}
public void removePrintJobStateChangeListener(
PrintManager.PrintJobStateChangeListener listener) {
mPrintManager.removePrintJobStateChangeListener(listener);
}
public List<PrintJob> getPrintJobs() {
return mPrintManager.getPrintJobs();
}
}

View File

@@ -1,30 +0,0 @@
/*
* Copyright (C) 2018 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.hardware.usb.UsbManager;
public class UsbManagerWrapper {
private UsbManager mUsbManager;
public UsbManagerWrapper(UsbManager manager) {
mUsbManager = manager;
}
public long getCurrentFunctions() {
return mUsbManager.getCurrentFunctions();
}
}

View File

@@ -1,53 +0,0 @@
package com.android.settings.wrapper;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
/**
* Wrapper around {@link WifiManager} to facilitate unit testing.
*
* TODO: delete this class once robolectric supports Android O
*/
public class WifiManagerWrapper {
private final WifiManager mWifiManager;
public WifiManagerWrapper(WifiManager wifiManager) {
mWifiManager = wifiManager;
}
/**
* Gets the real WifiManager
* @return the real WifiManager
*/
public WifiManager getWifiManager() {
return mWifiManager;
}
/**
* {@link WifiManager#getCurrentNetworkWpsNfcConfigurationToken}
*/
public String getCurrentNetworkWpsNfcConfigurationToken() {
return mWifiManager.getCurrentNetworkWpsNfcConfigurationToken();
}
/**
* {@link WifiManager#removePasspointConfiguration}
*/
public void removePasspointConfiguration(String fqdn) {
mWifiManager.removePasspointConfiguration(fqdn);
}
/**
* {@link WifiManager#forget}
*/
public void forget(int netId, WifiManager.ActionListener listener) {
mWifiManager.forget(netId, listener);
}
/**
* {@link WifiManager#save}
*/
public void save(WifiConfiguration config, WifiManager.ActionListener listener) {
mWifiManager.save(config, listener);
}
}

View File

@@ -6,7 +6,7 @@ import android.content.Context;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.XmlTestUtils; import com.android.settings.testutils.XmlTestUtils;
import com.android.settings.testutils.shadow.ShadowPowerManagerWrapper; import com.android.settings.testutils.shadow.ShadowPowerManager;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
import org.junit.Test; import org.junit.Test;
@@ -21,7 +21,7 @@ import java.util.List;
public class DisplaySettingsTest { public class DisplaySettingsTest {
@Test @Test
@Config(shadows = ShadowPowerManagerWrapper.class) @Config(shadows = ShadowPowerManager.class)
public void testPreferenceControllers_getPreferenceKeys_existInPreferenceScreen() { public void testPreferenceControllers_getPreferenceKeys_existInPreferenceScreen() {
final Context context = RuntimeEnvironment.application; final Context context = RuntimeEnvironment.application;
final DisplaySettings fragment = new DisplaySettings(); final DisplaySettings fragment = new DisplaySettings();

View File

@@ -17,7 +17,6 @@
package com.android.settings.connecteddevice.usb; package com.android.settings.connecteddevice.usb;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Answers.RETURNS_DEEP_STUBS; import static org.mockito.Answers.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@@ -30,8 +29,6 @@ import android.hardware.usb.UsbPortStatus;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.wrapper.UsbManagerWrapper;
import com.android.settings.wrapper.UserManagerWrapper; import com.android.settings.wrapper.UserManagerWrapper;
import org.junit.Before; import org.junit.Before;
@@ -50,8 +47,6 @@ public class UsbBackendTest {
@Mock @Mock
private UserManagerWrapper mUserManagerWrapper; private UserManagerWrapper mUserManagerWrapper;
@Mock @Mock
private UsbManagerWrapper mUsbManagerWrapper;
@Mock
private ConnectivityManager mConnectivityManager; private ConnectivityManager mConnectivityManager;
@Mock @Mock
private UsbPort mUsbPort; private UsbPort mUsbPort;
@@ -62,26 +57,18 @@ public class UsbBackendTest {
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI)) when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI))
.thenReturn(true); .thenReturn(true);
when((Object)mContext.getSystemService(UsbManager.class)).thenReturn(mUsbManager); when((Object) mContext.getSystemService(UsbManager.class)).thenReturn(mUsbManager);
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)) when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
.thenReturn(mConnectivityManager); .thenReturn(mConnectivityManager);
when(mUsbManager.getPorts()).thenReturn(new UsbPort[]{ mUsbPort }); when(mUsbManager.getPorts()).thenReturn(new UsbPort[] {mUsbPort});
when(mUsbPortStatus.isConnected()).thenReturn(true); when(mUsbPortStatus.isConnected()).thenReturn(true);
when(mUsbManager.getPortStatus(mUsbPort)).thenReturn(mUsbPortStatus); when(mUsbManager.getPortStatus(mUsbPort)).thenReturn(mUsbPortStatus);
} }
@Test
public void constructor_noUsbPort_shouldNotCrash() {
final UsbBackend usbBackend =
new UsbBackend(mContext, mUserManagerWrapper, mUsbManagerWrapper);
// Should not crash
}
@Test @Test
public void setDataRole_allRolesSupported_shouldSetDataRole() { public void setDataRole_allRolesSupported_shouldSetDataRole() {
final UsbBackend usbBackend = final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
new UsbBackend(mContext, mUserManagerWrapper, mUsbManagerWrapper);
when(mUsbPortStatus when(mUsbPortStatus
.isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE)) .isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE))
@@ -104,8 +91,7 @@ public class UsbBackendTest {
@Test @Test
public void setDataRole_notAllRolesSupported_shouldSetDataAndPowerRole() { public void setDataRole_notAllRolesSupported_shouldSetDataAndPowerRole() {
final UsbBackend usbBackend = final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
new UsbBackend(mContext, mUserManagerWrapper, mUsbManagerWrapper);
when(mUsbPortStatus when(mUsbPortStatus
.isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE)) .isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE))
@@ -123,8 +109,7 @@ public class UsbBackendTest {
@Test @Test
public void setPowerRole_allRolesSupported_shouldSetPowerRole() { public void setPowerRole_allRolesSupported_shouldSetPowerRole() {
final UsbBackend usbBackend = final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
new UsbBackend(mContext, mUserManagerWrapper, mUsbManagerWrapper);
when(mUsbPortStatus when(mUsbPortStatus
.isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE)) .isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE))
@@ -148,8 +133,7 @@ public class UsbBackendTest {
@Test @Test
public void setPowerRole_notAllRolesSupported_shouldSetDataAndPowerRole() { public void setPowerRole_notAllRolesSupported_shouldSetDataAndPowerRole() {
final UsbBackend usbBackend = final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
new UsbBackend(mContext, mUserManagerWrapper, mUsbManagerWrapper);
when(mUsbPortStatus when(mUsbPortStatus
.isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE)) .isRoleCombinationSupported(UsbPort.POWER_ROLE_SINK, UsbPort.DATA_ROLE_DEVICE))
@@ -170,8 +154,7 @@ public class UsbBackendTest {
when(mUserManagerWrapper.isUsbFileTransferRestricted()).thenReturn(true); when(mUserManagerWrapper.isUsbFileTransferRestricted()).thenReturn(true);
when(mUserManagerWrapper.isUsbFileTransferRestrictedBySystem()).thenReturn(true); when(mUserManagerWrapper.isUsbFileTransferRestrictedBySystem()).thenReturn(true);
final UsbBackend usbBackend = final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
new UsbBackend(mContext, mUserManagerWrapper, mUsbManagerWrapper);
assertThat(usbBackend.areFunctionsSupported(UsbManager.FUNCTION_MTP)).isFalse(); assertThat(usbBackend.areFunctionsSupported(UsbManager.FUNCTION_MTP)).isFalse();
} }
@@ -181,8 +164,7 @@ public class UsbBackendTest {
when(mUserManagerWrapper.isUsbFileTransferRestricted()).thenReturn(false); when(mUserManagerWrapper.isUsbFileTransferRestricted()).thenReturn(false);
when(mUserManagerWrapper.isUsbFileTransferRestrictedBySystem()).thenReturn(false); when(mUserManagerWrapper.isUsbFileTransferRestrictedBySystem()).thenReturn(false);
final UsbBackend usbBackend = final UsbBackend usbBackend = new UsbBackend(mContext, mUserManagerWrapper);
new UsbBackend(mContext, mUserManagerWrapper, mUsbManagerWrapper);
assertThat(usbBackend.areFunctionsSupported(UsbManager.FUNCTION_MTP)).isTrue(); assertThat(usbBackend.areFunctionsSupported(UsbManager.FUNCTION_MTP)).isTrue();
} }

View File

@@ -16,6 +16,7 @@
package com.android.settings.display; package com.android.settings.display;
import static android.content.Context.POWER_SERVICE;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
@@ -26,12 +27,12 @@ import static org.mockito.Mockito.when;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.os.PowerManager;
import android.provider.Settings.System; import android.provider.Settings.System;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen; import android.support.v7.preference.PreferenceScreen;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.wrapper.PowerManagerWrapper;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -40,13 +41,14 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadow.api.Shadow; import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.shadows.ShadowContentResolver; import org.robolectric.shadows.ShadowContentResolver;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
public class BrightnessLevelPreferenceControllerTest { public class BrightnessLevelPreferenceControllerTest {
@Mock @Mock
private PowerManagerWrapper mPowerManager; private PowerManager mPowerManager;
@Mock @Mock
private PreferenceScreen mScreen; private PreferenceScreen mScreen;
@Mock @Mock
@@ -67,8 +69,10 @@ public class BrightnessLevelPreferenceControllerTest {
when(mPowerManager.getMaximumScreenBrightnessSetting()).thenReturn(100); when(mPowerManager.getMaximumScreenBrightnessSetting()).thenReturn(100);
when(mPowerManager.getMinimumScreenBrightnessForVrSetting()).thenReturn(0); when(mPowerManager.getMinimumScreenBrightnessForVrSetting()).thenReturn(0);
when(mPowerManager.getMaximumScreenBrightnessForVrSetting()).thenReturn(100); when(mPowerManager.getMaximumScreenBrightnessForVrSetting()).thenReturn(100);
ShadowApplication.getInstance().setSystemService(POWER_SERVICE,
mPowerManager);
when(mScreen.findPreference(anyString())).thenReturn(mPreference); when(mScreen.findPreference(anyString())).thenReturn(mPreference);
mController = spy(new BrightnessLevelPreferenceController(mContext, null, mPowerManager)); mController = spy(new BrightnessLevelPreferenceController(mContext, null));
doReturn(false).when(mController).isInVrMode(); doReturn(false).when(mController).isInVrMode();
} }
@@ -80,23 +84,23 @@ public class BrightnessLevelPreferenceControllerTest {
@Test @Test
public void onStart_shouldRegisterObserver() { public void onStart_shouldRegisterObserver() {
BrightnessLevelPreferenceController controller = BrightnessLevelPreferenceController controller =
new BrightnessLevelPreferenceController(mContext, null, mPowerManager); new BrightnessLevelPreferenceController(mContext, null);
ShadowContentResolver shadowContentResolver = Shadow.extract(mContentResolver); ShadowContentResolver shadowContentResolver = Shadow.extract(mContentResolver);
controller.onStart(); controller.onStart();
assertThat(shadowContentResolver.getContentObservers( assertThat(shadowContentResolver.getContentObservers(
System.getUriFor(System.SCREEN_BRIGHTNESS))).isNotEmpty(); System.getUriFor(System.SCREEN_BRIGHTNESS))).isNotEmpty();
assertThat(shadowContentResolver.getContentObservers( assertThat(shadowContentResolver.getContentObservers(
System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR))).isNotEmpty(); System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR))).isNotEmpty();
assertThat(shadowContentResolver.getContentObservers( assertThat(shadowContentResolver.getContentObservers(
System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ))).isNotEmpty(); System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ))).isNotEmpty();
} }
@Test @Test
public void onStop_shouldUnregisterObserver() { public void onStop_shouldUnregisterObserver() {
BrightnessLevelPreferenceController controller = BrightnessLevelPreferenceController controller =
new BrightnessLevelPreferenceController(mContext, null, mPowerManager); new BrightnessLevelPreferenceController(mContext, null);
ShadowContentResolver shadowContentResolver = Shadow.extract(mContext.getContentResolver()); ShadowContentResolver shadowContentResolver = Shadow.extract(mContext.getContentResolver());
controller.displayPreference(mScreen); controller.displayPreference(mScreen);
@@ -104,11 +108,11 @@ public class BrightnessLevelPreferenceControllerTest {
controller.onStop(); controller.onStop();
assertThat(shadowContentResolver.getContentObservers( assertThat(shadowContentResolver.getContentObservers(
System.getUriFor(System.SCREEN_BRIGHTNESS))).isEmpty(); System.getUriFor(System.SCREEN_BRIGHTNESS))).isEmpty();
assertThat(shadowContentResolver.getContentObservers( assertThat(shadowContentResolver.getContentObservers(
System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR))).isEmpty(); System.getUriFor(System.SCREEN_BRIGHTNESS_FOR_VR))).isEmpty();
assertThat(shadowContentResolver.getContentObservers( assertThat(shadowContentResolver.getContentObservers(
System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ))).isEmpty(); System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ))).isEmpty();
} }
@Test @Test
@@ -125,7 +129,7 @@ public class BrightnessLevelPreferenceControllerTest {
public void updateState_autoBrightness_shouldSetSummaryToAutoBrightness() { public void updateState_autoBrightness_shouldSetSummaryToAutoBrightness() {
doReturn(false).when(mController).isInVrMode(); doReturn(false).when(mController).isInVrMode();
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE, System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE,
System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC); System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS, 31); System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS, 31);
@@ -138,7 +142,7 @@ public class BrightnessLevelPreferenceControllerTest {
public void updateState_manualBrightness_shouldSetSummaryToScreenBrightness() { public void updateState_manualBrightness_shouldSetSummaryToScreenBrightness() {
doReturn(false).when(mController).isInVrMode(); doReturn(false).when(mController).isInVrMode();
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE, System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS_MODE,
System.SCREEN_BRIGHTNESS_MODE_MANUAL); System.SCREEN_BRIGHTNESS_MODE_MANUAL);
System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS, 45); System.putInt(mContentResolver, System.SCREEN_BRIGHTNESS, 45);

View File

@@ -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);

View File

@@ -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());
} }

View File

@@ -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);

View File

@@ -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));

View File

@@ -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);

View File

@@ -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();
} }
} }

View File

@@ -34,14 +34,12 @@ import android.printservice.PrintServiceInfo;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.wrapper.PrintManagerWrapper;
import com.android.settingslib.RestrictedPreference; import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
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;
import org.mockito.Answers;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
@@ -55,12 +53,13 @@ import java.util.List;
public class PrintSettingsPreferenceControllerTest { public class PrintSettingsPreferenceControllerTest {
@Mock @Mock
private PrintManagerWrapper mPrintManager; private PrintManager mPrintManager;
@Mock @Mock
private UserManager mUserManager; private UserManager mUserManager;
private Context mContext;
@Mock @Mock
private RestrictedPreference mPreference; private RestrictedPreference mPreference;
private Context mContext;
private PrintSettingPreferenceController mController; private PrintSettingPreferenceController mController;
private LifecycleOwner mLifecycleOwner; private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle; private Lifecycle mLifecycle;
@@ -83,7 +82,7 @@ public class PrintSettingsPreferenceControllerTest {
mLifecycle.handleLifecycleEvent(ON_START); mLifecycle.handleLifecycleEvent(ON_START);
mLifecycle.handleLifecycleEvent(ON_STOP); mLifecycle.handleLifecycleEvent(ON_STOP);
verify(mPrintManager).addPrintJobStateChanegListener(mController); verify(mPrintManager).addPrintJobStateChangeListener(mController);
verify(mPrintManager).removePrintJobStateChangeListener(mController); verify(mPrintManager).removePrintJobStateChangeListener(mController);
} }

View File

@@ -16,18 +16,18 @@
package com.android.settings.testutils.shadow; package com.android.settings.testutils.shadow;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.ComponentName; import android.content.ComponentName;
import com.android.settings.wrapper.AccessibilityServiceInfoWrapper;
import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements; import org.robolectric.annotation.Implements;
@Implements(AccessibilityServiceInfoWrapper.class)
public class ShadowAccessibilityServiceInfoWrapperImpl { @Implements(AccessibilityServiceInfo.class)
public class ShadowAccessibilityServiceInfo {
private static ComponentName sComponentName; private static ComponentName sComponentName;
public static void setComponentName(String componentName) { public static void setComponentName(String componentName) {
sComponentName = ComponentName.unflattenFromString(componentName);; sComponentName = ComponentName.unflattenFromString(componentName);
} }
@Implementation @Implementation

View File

@@ -17,12 +17,13 @@
package com.android.settings.testutils.shadow; package com.android.settings.testutils.shadow;
import com.android.settings.wrapper.PowerManagerWrapper; import android.os.PowerManager;
import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements; import org.robolectric.annotation.Implements;
@Implements(PowerManagerWrapper.class) @Implements(PowerManager.class)
public class ShadowPowerManagerWrapper { public class ShadowPowerManager {
@Implementation @Implementation
public int getMinimumScreenBrightnessSetting() { public int getMinimumScreenBrightnessSetting() {

View File

@@ -23,11 +23,11 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager.ActionListener; import android.net.wifi.WifiManager.ActionListener;
import android.os.Handler; import android.os.Handler;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.wrapper.WifiManagerWrapper;
import com.android.settingslib.wifi.AccessPoint; import com.android.settingslib.wifi.AccessPoint;
import org.junit.Before; import org.junit.Before;
@@ -40,12 +40,18 @@ import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
public class SavedAccessPointsWifiSettingsTest { public class SavedAccessPointsWifiSettingsTest {
@Mock private WifiManagerWrapper mockWifiManager; @Mock
@Mock private WifiDialog mockWifiDialog; private WifiManager mockWifiManager;
@Mock private WifiConfigController mockConfigController; @Mock
@Mock private WifiConfiguration mockWifiConfiguration; private WifiDialog mockWifiDialog;
@Mock private AccessPoint mockAccessPoint; @Mock
@Mock private Handler mHandler; private WifiConfigController mockConfigController;
@Mock
private WifiConfiguration mockWifiConfiguration;
@Mock
private AccessPoint mockAccessPoint;
@Mock
private Handler mHandler;
private SavedAccessPointsWifiSettings mSettings; private SavedAccessPointsWifiSettings mSettings;
@@ -97,6 +103,6 @@ public class SavedAccessPointsWifiSettingsTest {
when(mockAccessPoint.getConfig()).thenReturn(mockWifiConfiguration); when(mockAccessPoint.getConfig()).thenReturn(mockWifiConfiguration);
mSettings.onForget(mockWifiDialog); mSettings.onForget(mockWifiDialog);
verify(mockWifiManager) verify(mockWifiManager)
.forget(eq(mockWifiConfiguration.networkId), any(ActionListener.class)); .forget(eq(mockWifiConfiguration.networkId), any(ActionListener.class));
} }
} }

View File

@@ -21,11 +21,11 @@ import static org.mockito.Mockito.when;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.net.wifi.WifiManager;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowNfcAdapter; import com.android.settings.testutils.shadow.ShadowNfcAdapter;
import com.android.settings.wrapper.WifiManagerWrapper;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@@ -42,9 +42,9 @@ import org.robolectric.util.ReflectionHelpers;
public class WriteWifiConfigToNfcDialogTest { public class WriteWifiConfigToNfcDialogTest {
@Mock @Mock
Activity mActivity; private Activity mActivity;
@Mock @Mock
WifiManagerWrapper mWifiManager; private WifiManager mWifiManager;
private WriteWifiConfigToNfcDialog mWriteWifiConfigToNfcDialog; private WriteWifiConfigToNfcDialog mWriteWifiConfigToNfcDialog;
@@ -56,7 +56,8 @@ public class WriteWifiConfigToNfcDialogTest {
.thenReturn(ReflectionHelpers.newInstance(InputMethodManager.class)); .thenReturn(ReflectionHelpers.newInstance(InputMethodManager.class));
mWriteWifiConfigToNfcDialog = new WriteWifiConfigToNfcDialog(RuntimeEnvironment.application, mWriteWifiConfigToNfcDialog = new WriteWifiConfigToNfcDialog(RuntimeEnvironment.application,
0 /* security */, mWifiManager); 0 /* security */);
ReflectionHelpers.setField(mWriteWifiConfigToNfcDialog, "mWifiManager", mWifiManager);
mWriteWifiConfigToNfcDialog.setOwnerActivity(mActivity); mWriteWifiConfigToNfcDialog.setOwnerActivity(mActivity);
mWriteWifiConfigToNfcDialog.onCreate(null /* savedInstanceState */); mWriteWifiConfigToNfcDialog.onCreate(null /* savedInstanceState */);
} }