Merge changes from topic "remove_wrappers" into pi-dev am: e6a18f8105

am: c04dcd01c1

Change-Id: I14e92ac2141c08bb22bd6d88f7159967f60f144c
This commit is contained in:
Fan Zhang
2018-03-31 07:47:30 +00:00
committed by android-build-merger
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.support.annotation.VisibleForTesting;
import com.android.settings.wrapper.UsbManagerWrapper;
import com.android.settings.wrapper.UserManagerWrapper;
/**
@@ -44,7 +43,6 @@ public class UsbBackend {
private final boolean mTetheringSupported;
private UsbManager mUsbManager;
private UsbManagerWrapper mUsbManagerWrapper;
@Nullable
private UsbPort mPort;
@@ -52,19 +50,13 @@ public class UsbBackend {
private UsbPortStatus mPortStatus;
public UsbBackend(Context context) {
this(context, new UserManagerWrapper(UserManager.get(context)), null);
this(context, new UserManagerWrapper(UserManager.get(context)));
}
@VisibleForTesting
public UsbBackend(Context context, UserManagerWrapper userManagerWrapper,
UsbManagerWrapper usbManagerWrapper) {
public UsbBackend(Context context, UserManagerWrapper userManagerWrapper) {
mUsbManager = context.getSystemService(UsbManager.class);
mUsbManagerWrapper = usbManagerWrapper;
if (mUsbManagerWrapper == null) {
mUsbManagerWrapper = new UsbManagerWrapper(mUsbManager);
}
mFileTransferRestricted = userManagerWrapper.isUsbFileTransferRestricted();
mFileTransferRestrictedBySystem = userManagerWrapper.isUsbFileTransferRestrictedBySystem();
mTetheringRestricted = userManagerWrapper.isUsbTetheringRestricted();
@@ -79,7 +71,7 @@ public class UsbBackend {
}
public long getCurrentFunctions() {
return mUsbManagerWrapper.getCurrentFunctions();
return mUsbManager.getCurrentFunctions();
}
public void setCurrentFunctions(long functions) {

View File

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

View File

@@ -56,7 +56,7 @@ public class BlockPreferenceController extends NotificationPreferenceController
}
if (mChannel != null) {
return isChannelBlockable();
} else if (mChannelGroup != null && mChannelGroup.getGroup() != null) {
} else if (mChannelGroup != null) {
return isChannelGroupBlockable();
} else {
return !mAppRow.systemApp || (mAppRow.systemApp && mAppRow.banned);
@@ -80,7 +80,7 @@ public class BlockPreferenceController extends NotificationPreferenceController
if (mChannel != null) {
bar.setChecked(!mAppRow.banned
&& mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE);
} else if (mChannelGroup != null && mChannelGroup.getGroup() != null) {
} else if (mChannelGroup != null) {
bar.setChecked(!mAppRow.banned && !mChannelGroup.isBlocked());
} else {
bar.setChecked(!mAppRow.banned);
@@ -107,9 +107,9 @@ public class BlockPreferenceController extends NotificationPreferenceController
mAppRow.banned = blocked;
mBackend.setNotificationsEnabledForPackage(mAppRow.pkg, mAppRow.uid, !blocked);
}
} else if (mChannelGroup != null && mChannelGroup.getGroup() != null) {
} else if (mChannelGroup != null) {
mChannelGroup.setBlocked(blocked);
mBackend.updateChannelGroup(mAppRow.pkg, mAppRow.uid, mChannelGroup.getGroup());
mBackend.updateChannelGroup(mAppRow.pkg, mAppRow.uid, mChannelGroup);
} else if (mAppRow != null) {
mAppRow.banned = blocked;
mBackend.setNotificationsEnabledForPackage(mAppRow.pkg, mAppRow.uid, !blocked);

View File

@@ -40,7 +40,7 @@ public class ChannelGroupNotificationSettings extends NotificationSettingsBase {
@Override
public void 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");
finish();
return;
@@ -85,7 +85,7 @@ public class ChannelGroupNotificationSettings extends NotificationSettingsBase {
getPreferenceScreen().removePreference(p);
}
}
if (mChannelGroup.getGroup().getChannels().isEmpty()) {
if (mChannelGroup.getChannels().isEmpty()) {
Preference empty = new Preference(getPrefContext());
empty.setTitle(R.string.no_channels);
empty.setEnabled(false);
@@ -93,7 +93,7 @@ public class ChannelGroupNotificationSettings extends NotificationSettingsBase {
mDynamicPreferences.add(empty);
} else {
final List<NotificationChannel> channels = mChannelGroup.getGroup().getChannels();
final List<NotificationChannel> channels = mChannelGroup.getChannels();
Collections.sort(channels, mChannelComparator);
for (NotificationChannel channel : channels) {
mDynamicPreferences.add(populateSingleChannelPrefs(

View File

@@ -73,27 +73,27 @@ public class HeaderPreferenceController extends NotificationPreferenceController
CharSequence getLabel() {
return mChannel != null ? mChannel.getName()
: mChannelGroup != null && mChannelGroup.getGroup() != null
? mChannelGroup.getGroup().getName()
: mChannelGroup != null
? mChannelGroup.getName()
: mAppRow.label;
}
@Override
public CharSequence getSummary() {
if (mChannel != null) {
if (mChannelGroup != null && mChannelGroup.getGroup() != null
&& !TextUtils.isEmpty(mChannelGroup.getGroup().getName())) {
final SpannableStringBuilder summary = new SpannableStringBuilder();
BidiFormatter bidi = BidiFormatter.getInstance();
summary.append(bidi.unicodeWrap(mAppRow.label.toString()));
summary.append(bidi.unicodeWrap(mContext.getText(
R.string.notification_header_divider_symbol_with_spaces)));
summary.append(bidi.unicodeWrap(mChannelGroup.getGroup().getName().toString()));
return summary.toString();
} else {
return mAppRow.label.toString();
}
} else if (mChannelGroup != null && mChannelGroup.getGroup() != null) {
if (mChannelGroup != null
&& !TextUtils.isEmpty(mChannelGroup.getName())) {
final SpannableStringBuilder summary = new SpannableStringBuilder();
BidiFormatter bidi = BidiFormatter.getInstance();
summary.append(bidi.unicodeWrap(mAppRow.label.toString()));
summary.append(bidi.unicodeWrap(mContext.getText(
R.string.notification_header_divider_symbol_with_spaces)));
summary.append(bidi.unicodeWrap(mChannelGroup.getName().toString()));
return summary.toString();
} else {
return mAppRow.label.toString();
}
} else if (mChannelGroup != null) {
return mAppRow.label.toString();
} else {
return "";

View File

@@ -25,13 +25,11 @@ import android.app.NotificationManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
import android.util.Log;
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
import com.android.settingslib.RestrictedLockUtils;
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,
* 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";
@Nullable protected NotificationChannel mChannel;
@Nullable protected NotificationChannelGroupWrapper mChannelGroup;
@Nullable
protected NotificationChannel mChannel;
@Nullable
protected NotificationChannelGroup mChannelGroup;
protected RestrictedLockUtils.EnforcedAdmin mAdmin;
protected NotificationBackend.AppRow mAppRow;
protected final NotificationManager mNm;
@@ -78,7 +77,7 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
if (mChannel != null) {
return mChannel.getImportance() != IMPORTANCE_NONE;
}
if (mChannelGroup != null && mChannelGroup.getGroup() == null) {
if (mChannelGroup != null) {
return !mChannelGroup.isBlocked();
}
return true;
@@ -125,7 +124,7 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
}
protected void onResume(NotificationBackend.AppRow appRow,
@Nullable NotificationChannel channel, @Nullable NotificationChannelGroupWrapper group,
@Nullable NotificationChannel channel, @Nullable NotificationChannelGroup group,
RestrictedLockUtils.EnforcedAdmin admin) {
mAppRow = appRow;
mChannel = channel;
@@ -172,7 +171,7 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
}
protected boolean isChannelGroupBlockable() {
if (mChannelGroup != null && mChannelGroup.getGroup() != null && mAppRow != null) {
if (mChannelGroup != null && mAppRow != null) {
if (!mAppRow.systemApp) {
return true;
}
@@ -183,6 +182,6 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
}
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.dashboard.DashboardFragment;
import com.android.settings.widget.MasterCheckBoxPreference;
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
import com.android.settingslib.RestrictedLockUtils;
import java.util.ArrayList;
@@ -70,7 +69,7 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
protected String mPkg;
protected PackageInfo mPkgInfo;
protected EnforcedAdmin mSuspendedAppsAdmin;
protected NotificationChannelGroupWrapper mChannelGroup;
protected NotificationChannelGroup mChannelGroup;
protected NotificationChannel mChannel;
protected NotificationBackend.AppRow mAppRow;
@@ -168,7 +167,7 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
if (mChannel != null && !TextUtils.isEmpty(mChannel.getGroup())) {
group = mBackend.getGroup(mPkg, mUid, mChannel.getGroup());
if (group != null) {
mChannelGroup = new NotificationChannelGroupWrapper(group);
mChannelGroup = group;
}
}
}
@@ -209,7 +208,7 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
}
if (mChannelGroup != null) {
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.core.PreferenceControllerMixin;
import com.android.settingslib.widget.FooterPreference;
public class NotificationsOffPreferenceController extends NotificationPreferenceController
implements PreferenceControllerMixin {
@@ -51,7 +50,7 @@ public class NotificationsOffPreferenceController extends NotificationPreference
if (mAppRow != null) {
if (mChannel != null) {
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);
} else {
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.core.BasePreferenceController;
import com.android.settings.wrapper.PrintManagerWrapper;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
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 final PackageManager mPackageManager;
private PrintManagerWrapper mPrintManager;
private final PrintManager mPrintManager;
private Preference mPreference;
public PrintSettingPreferenceController(Context context) {
super(context, KEY_PRINTING_SETTINGS);
mPackageManager = context.getPackageManager();
mPrintManager = new PrintManagerWrapper(context);
mPrintManager = ((PrintManager) context.getSystemService(Context.PRINT_SERVICE))
.getGlobalPrintManagerForUser(context.getUserId());
}
@Override
@@ -69,7 +70,7 @@ public class PrintSettingPreferenceController extends BasePreferenceController i
@Override
public void onStart() {
mPrintManager.addPrintJobStateChanegListener(this);
mPrintManager.addPrintJobStateChangeListener(this);
}
@Override

View File

@@ -28,14 +28,13 @@ import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.util.Log;
import android.widget.Toast;
import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.search.Indexable;
import com.android.settings.wrapper.WifiManagerWrapper;
import com.android.settingslib.wifi.AccessPoint;
import com.android.settingslib.wifi.AccessPointPreference;
import com.android.settingslib.wifi.WifiSavedConfigUtils;
@@ -107,7 +106,7 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
};
private WifiDialog mDialog;
private WifiManagerWrapper mWifiManager;
private WifiManager mWifiManager;
private AccessPoint mDlgAccessPoint;
private Bundle mAccessPointSavedState;
private AccessPoint mSelectedAccessPoint;
@@ -139,7 +138,7 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mWifiManager = new WifiManagerWrapper((WifiManager) getSystemService(Context.WIFI_SERVICE));
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if (savedInstanceState != null) {
if (savedInstanceState.containsKey(SAVE_DIALOG_ACCESS_POINT_STATE)) {
@@ -154,7 +153,7 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
final Context context = getPrefContext();
final List<AccessPoint> accessPoints =
WifiSavedConfigUtils.getAllConfigs(context, mWifiManager.getWifiManager());
WifiSavedConfigUtils.getAllConfigs(context, mWifiManager);
Collections.sort(accessPoints, SAVED_NETWORK_COMPARATOR);
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.wifi.details.WifiNetworkDetailsFragment;
import com.android.settings.wrapper.ConnectivityManagerWrapper;
import com.android.settings.wrapper.WifiManagerWrapper;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.wifi.AccessPoint;
import com.android.settingslib.wifi.AccessPoint.AccessPointListener;
@@ -136,7 +135,7 @@ public class WifiSettings extends RestrictedSettingsFragment
private boolean mIsRestricted;
private WifiEnabler mWifiEnabler;
// An access point being editted is stored here.
// An access point being edited is stored here.
private AccessPoint mSelectedAccessPoint;
private WifiDialog mDialog;
@@ -608,11 +607,10 @@ public class WifiSettings extends RestrictedSettingsFragment
if (mSelectedAccessPoint != null) {
mWifiToNfcDialog = new WriteWifiConfigToNfcDialog(
getActivity(),
mSelectedAccessPoint.getSecurity(),
new WifiManagerWrapper(mWifiManager));
mSelectedAccessPoint.getSecurity());
} else if (mWifiNfcDialogSavedState != null) {
mWifiToNfcDialog = new WriteWifiConfigToNfcDialog(getActivity(),
mWifiNfcDialogSavedState, new WifiManagerWrapper(mWifiManager));
mWifiNfcDialogSavedState);
}
return mWifiToNfcDialog;

View File

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