Remove more wrappers
Bug: 76167422 Test: make RunSettingsRoboTests -j40 Change-Id: I0dc42c483ae92d508dec94e42573b55ced0e4bb0
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothManager;
|
||||
@@ -27,6 +29,7 @@ import android.net.Uri;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.RecoverySystem;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
@@ -41,13 +44,9 @@ import android.widget.Toast;
|
||||
import com.android.ims.ImsManager;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.internal.telephony.PhoneConstants;
|
||||
import com.android.settings.enterprise.ActionDisabledByAdminDialogHelper;
|
||||
import com.android.settings.wrapper.RecoverySystemWrapper;
|
||||
import com.android.settings.core.InstrumentedFragment;
|
||||
import com.android.settings.enterprise.ActionDisabledByAdminDialogHelper;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
/**
|
||||
* Confirm and execute a reset of the network settings to a clean "just out of the box"
|
||||
@@ -65,7 +64,6 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
|
||||
private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
@VisibleForTesting boolean mEraseEsim;
|
||||
@VisibleForTesting EraseEsimAsyncTask mEraseEsimTask;
|
||||
@VisibleForTesting static RecoverySystemWrapper mRecoverySystem;
|
||||
|
||||
/**
|
||||
* Async task used to erase all the eSIM profiles from the phone. If error happens during
|
||||
@@ -82,7 +80,7 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
return mRecoverySystem.wipeEuiccData(mContext, mPackageName);
|
||||
return RecoverySystem.wipeEuiccData(mContext, mPackageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -218,7 +216,6 @@ public class ResetNetworkConfirm extends InstrumentedFragment {
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
mEraseEsim = args.getBoolean(MasterClear.ERASE_ESIMS_EXTRA);
|
||||
}
|
||||
mRecoverySystem = new RecoverySystemWrapper();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -40,7 +40,6 @@ import com.android.settings.R;
|
||||
import com.android.settings.applications.AppInfoBase;
|
||||
import com.android.settings.notification.EmptyTextSettings;
|
||||
import com.android.settings.widget.AppPreference;
|
||||
import com.android.settings.wrapper.ActivityInfoWrapper;
|
||||
import com.android.settings.wrapper.UserManagerWrapper;
|
||||
import com.android.settingslib.wrapper.PackageManagerWrapper;
|
||||
|
||||
@@ -96,25 +95,9 @@ public class PictureInPictureSettings extends EmptyTextSettings {
|
||||
* @return true if the package has any activities that declare that they support
|
||||
* picture-in-picture.
|
||||
*/
|
||||
|
||||
public static boolean checkPackageHasPictureInPictureActivities(String packageName,
|
||||
ActivityInfo[] activities) {
|
||||
ActivityInfoWrapper[] wrappedActivities = null;
|
||||
if (activities != null) {
|
||||
wrappedActivities = new ActivityInfoWrapper[activities.length];
|
||||
for (int i = 0; i < activities.length; i++) {
|
||||
wrappedActivities[i] = new ActivityInfoWrapper(activities[i]);
|
||||
}
|
||||
}
|
||||
return checkPackageHasPictureInPictureActivities(packageName, wrappedActivities);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the package has any activities that declare that they support
|
||||
* picture-in-picture.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static boolean checkPackageHasPictureInPictureActivities(String packageName,
|
||||
ActivityInfoWrapper[] activities) {
|
||||
// Skip if it's in the ignored list
|
||||
if (IGNORE_PACKAGE_LIST.contains(packageName)) {
|
||||
return false;
|
||||
|
@@ -34,7 +34,6 @@ import android.view.WindowManagerGlobal;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.internal.app.LocalePicker;
|
||||
import com.android.settings.wrapper.IWindowManagerWrapper;
|
||||
import com.android.settingslib.development.SystemPropPoker;
|
||||
|
||||
public abstract class DevelopmentTiles extends TileService {
|
||||
@@ -150,14 +149,13 @@ public abstract class DevelopmentTiles extends TileService {
|
||||
@VisibleForTesting
|
||||
static final int SURFACE_FLINGER_LAYER_TRACE_STATUS_CODE = 1026;
|
||||
private IBinder mSurfaceFlinger;
|
||||
private IWindowManagerWrapper mWindowManager;
|
||||
private IWindowManager mWindowManager;
|
||||
private Toast mToast;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
mWindowManager = new IWindowManagerWrapper(WindowManagerGlobal
|
||||
.getWindowManagerService());
|
||||
mWindowManager = WindowManagerGlobal.getWindowManagerService();
|
||||
mSurfaceFlinger = ServiceManager.getService("SurfaceFlinger");
|
||||
Context context = getApplicationContext();
|
||||
CharSequence text = "Trace files written to /data/misc/wmtrace";
|
||||
|
@@ -24,8 +24,6 @@ import android.text.format.DateUtils;
|
||||
import android.util.KeyValueListParser;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.wrapper.KeyValueListParserWrapper;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -118,37 +116,32 @@ public class AnomalyDetectionPolicy {
|
||||
*/
|
||||
public final long bluetoothScanThreshold;
|
||||
|
||||
private final KeyValueListParserWrapper mParserWrapper;
|
||||
private final KeyValueListParser mParser;
|
||||
|
||||
public AnomalyDetectionPolicy(Context context) {
|
||||
this(context, new KeyValueListParserWrapper(new KeyValueListParser(',')));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
AnomalyDetectionPolicy(Context context, KeyValueListParserWrapper parserWrapper) {
|
||||
mParserWrapper = parserWrapper;
|
||||
mParser = new KeyValueListParser(',');
|
||||
final String value = Settings.Global.getString(context.getContentResolver(),
|
||||
Settings.Global.ANOMALY_DETECTION_CONSTANTS);
|
||||
|
||||
try {
|
||||
mParserWrapper.setString(value);
|
||||
mParser.setString(value);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.e(TAG, "Bad anomaly detection constants");
|
||||
}
|
||||
|
||||
anomalyDetectionEnabled =
|
||||
mParserWrapper.getBoolean(KEY_ANOMALY_DETECTION_ENABLED, false);
|
||||
mParser.getBoolean(KEY_ANOMALY_DETECTION_ENABLED, false);
|
||||
wakeLockDetectionEnabled =
|
||||
mParserWrapper.getBoolean(KEY_WAKELOCK_DETECTION_ENABLED,false);
|
||||
mParser.getBoolean(KEY_WAKELOCK_DETECTION_ENABLED,false);
|
||||
wakeupAlarmDetectionEnabled =
|
||||
mParserWrapper.getBoolean(KEY_WAKEUP_ALARM_DETECTION_ENABLED,false);
|
||||
bluetoothScanDetectionEnabled = mParserWrapper.getBoolean(
|
||||
mParser.getBoolean(KEY_WAKEUP_ALARM_DETECTION_ENABLED,false);
|
||||
bluetoothScanDetectionEnabled = mParser.getBoolean(
|
||||
KEY_BLUETOOTH_SCAN_DETECTION_ENABLED, false);
|
||||
wakeLockThreshold = mParserWrapper.getLong(KEY_WAKELOCK_THRESHOLD,
|
||||
wakeLockThreshold = mParser.getLong(KEY_WAKELOCK_THRESHOLD,
|
||||
DateUtils.HOUR_IN_MILLIS);
|
||||
wakeupAlarmThreshold = mParserWrapper.getLong(KEY_WAKEUP_ALARM_THRESHOLD, 10);
|
||||
wakeupAlarmThreshold = mParser.getLong(KEY_WAKEUP_ALARM_THRESHOLD, 10);
|
||||
wakeupBlacklistedTags = parseStringSet(KEY_WAKEUP_BLACKLISTED_TAGS, null);
|
||||
bluetoothScanThreshold = mParserWrapper.getLong(KEY_BLUETOOTH_SCAN_THRESHOLD,
|
||||
bluetoothScanThreshold = mParser.getLong(KEY_BLUETOOTH_SCAN_THRESHOLD,
|
||||
30 * DateUtils.MINUTE_IN_MILLIS);
|
||||
}
|
||||
|
||||
@@ -170,7 +163,7 @@ public class AnomalyDetectionPolicy {
|
||||
}
|
||||
|
||||
private Set<String> parseStringSet(final String key, final Set<String> defaultSet) {
|
||||
final String value = mParserWrapper.getString(key, null);
|
||||
final String value = mParser.getString(key, null);
|
||||
if (value != null) {
|
||||
return Arrays.stream(value.split(":"))
|
||||
.map(String::trim).map(Uri::decode).collect(Collectors.toSet());
|
||||
|
@@ -32,7 +32,7 @@ import android.telephony.ServiceState;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.wrapper.RestrictedLockUtilsWrapper;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
@@ -74,9 +74,8 @@ public class MobileNetworkPreferenceController extends AbstractPreferenceControl
|
||||
}
|
||||
|
||||
public boolean isUserRestricted() {
|
||||
final RestrictedLockUtilsWrapper wrapper = new RestrictedLockUtilsWrapper();
|
||||
return mIsSecondaryUser ||
|
||||
wrapper.hasBaseUserRestriction(
|
||||
RestrictedLockUtils.hasBaseUserRestriction(
|
||||
mContext,
|
||||
DISALLOW_CONFIG_MOBILE_NETWORKS,
|
||||
myUserId());
|
||||
|
@@ -1,40 +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.content.pm.ActivityInfo;
|
||||
|
||||
/**
|
||||
* This class replicates a subset of the android.content.pm.ActivityInfo. The class
|
||||
* exists so that we can use a thin wrapper around the ActivityInfo in production code and a mock in
|
||||
* tests.
|
||||
*/
|
||||
public class ActivityInfoWrapper {
|
||||
|
||||
private final ActivityInfo mInfo;
|
||||
|
||||
public ActivityInfoWrapper(ActivityInfo info) {
|
||||
mInfo = info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this activity supports picture-in-picture.
|
||||
*/
|
||||
public boolean supportsPictureInPicture() {
|
||||
return mInfo.supportsPictureInPicture();
|
||||
}
|
||||
}
|
@@ -1,55 +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.os.RemoteException;
|
||||
import android.view.IWindowManager;
|
||||
|
||||
/**
|
||||
* This class replicates a subset of the android.view.IWindowManager. The class
|
||||
* exists so that we can use a thin wrapper around the IWindowManager in production code
|
||||
* and a mock in tests.
|
||||
*/
|
||||
public class IWindowManagerWrapper {
|
||||
|
||||
private final IWindowManager mWindowManager;
|
||||
|
||||
public IWindowManagerWrapper(IWindowManager wm) {
|
||||
mWindowManager = wm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if window trace is enabled.
|
||||
*/
|
||||
public boolean isWindowTraceEnabled() throws RemoteException {
|
||||
return mWindowManager.isWindowTraceEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a window trace.
|
||||
*/
|
||||
public void startWindowTrace() throws RemoteException {
|
||||
mWindowManager.startWindowTrace();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops a window trace.
|
||||
*/
|
||||
public void stopWindowTrace() throws RemoteException {
|
||||
mWindowManager.stopWindowTrace();
|
||||
}
|
||||
}
|
@@ -1,85 +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.util.KeyValueListParser;
|
||||
|
||||
/**
|
||||
* This class replicates a subset of the {@link KeyValueListParser}. The class
|
||||
* exists so that we can use a thin wrapper around the PM in production code and a mock in tests.
|
||||
* We cannot directly mock or shadow the {@link KeyValueListParser}, because some of the methods
|
||||
* we rely on are newer than the API version supported by Robolectric.
|
||||
*/
|
||||
public class KeyValueListParserWrapper {
|
||||
private KeyValueListParser mParser;
|
||||
|
||||
public KeyValueListParserWrapper(KeyValueListParser parser) {
|
||||
mParser = parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get real {@link KeyValueListParser}
|
||||
*/
|
||||
public KeyValueListParser getKeyValueListParser() {
|
||||
return mParser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the parser with a new string to parse. The string is expected to be in the following
|
||||
* format:
|
||||
* <pre>key1=value,key2=value,key3=value</pre>
|
||||
*
|
||||
* where the delimiter is a comma.
|
||||
*
|
||||
* @param str the string to parse.
|
||||
* @throws IllegalArgumentException if the string is malformed.
|
||||
*/
|
||||
public void setString(String str) throws IllegalArgumentException {
|
||||
mParser.setString(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value for key as a boolean.
|
||||
* @param key The key to lookup.
|
||||
* @param defaultValue The value to return if the key was not found.
|
||||
* @return the boolean value associated with the key.
|
||||
*/
|
||||
public boolean getBoolean(String key, boolean defaultValue) {
|
||||
return mParser.getBoolean(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value for key as a string.
|
||||
* @param key The key to lookup.
|
||||
* @param defaultValue The value to return if the key was not found.
|
||||
* @return the string value associated with the key.
|
||||
*/
|
||||
public String getString(String key, String defaultValue) {
|
||||
return mParser.getString(key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value for key as a long.
|
||||
* @param key The key to lookup.
|
||||
* @param defaultValue The value to return if the key was not found, or the value was not a
|
||||
* long.
|
||||
* @return the long value associated with the key.
|
||||
*/
|
||||
public long getLong(String key, long defaultValue) {
|
||||
return mParser.getLong(key, defaultValue);
|
||||
}
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
package com.android.settings.wrapper;
|
||||
|
||||
import android.content.Context;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
|
||||
/**
|
||||
* Wrapper class needed to be able to test classes which use RestrictedLockUtils methods.
|
||||
* Unfortunately there is no way to deal with this until robolectric is updated due to the fact
|
||||
* that it is a static method and it uses new API's.
|
||||
*/
|
||||
public class RestrictedLockUtilsWrapper {
|
||||
public boolean hasBaseUserRestriction(Context context, String userRestriction, int userId) {
|
||||
return RestrictedLockUtils.hasBaseUserRestriction(context, userRestriction, userId);
|
||||
}
|
||||
}
|
@@ -16,55 +16,53 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wrapper.RecoverySystemWrapper;
|
||||
import com.android.settings.testutils.shadow.ShadowRecoverySystem;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowRecoverySystem.class})
|
||||
public class ResetNetworkConfirmTest {
|
||||
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private ResetNetworkConfirm mResetNetworkConfirm;
|
||||
@Mock
|
||||
private RecoverySystemWrapper mRecoverySystem;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mResetNetworkConfirm = spy(new ResetNetworkConfirm());
|
||||
mRecoverySystem = spy(new RecoverySystemWrapper());
|
||||
ResetNetworkConfirm.mRecoverySystem = mRecoverySystem;
|
||||
mActivity = Robolectric.setupActivity(Activity.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowRecoverySystem.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResetNetworkData_resetEsim() {
|
||||
mResetNetworkConfirm.mEraseEsim = true;
|
||||
doReturn(true).when(mRecoverySystem).wipeEuiccData(any(Context.class), anyString());
|
||||
|
||||
mResetNetworkConfirm.esimFactoryReset(mActivity, "" /* packageName */);
|
||||
Robolectric.getBackgroundThreadScheduler().advanceToLastPostedRunnable();
|
||||
|
||||
Assert.assertNotNull(mResetNetworkConfirm.mEraseEsimTask);
|
||||
verify(mRecoverySystem).wipeEuiccData(any(Context.class), anyString());
|
||||
assertThat(mResetNetworkConfirm.mEraseEsimTask).isNotNull();
|
||||
assertThat(ShadowRecoverySystem.getWipeEuiccCalledCount())
|
||||
.isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +71,8 @@ public class ResetNetworkConfirmTest {
|
||||
|
||||
mResetNetworkConfirm.esimFactoryReset(mActivity, "" /* packageName */);
|
||||
|
||||
Assert.assertNull(mResetNetworkConfirm.mEraseEsimTask);
|
||||
verify(mRecoverySystem, never()).wipeEuiccData(any(Context.class), anyString());
|
||||
assertThat(mResetNetworkConfirm.mEraseEsimTask).isNull();
|
||||
assertThat(ShadowRecoverySystem.getWipeEuiccCalledCount())
|
||||
.isEqualTo(0);
|
||||
}
|
||||
}
|
||||
|
@@ -22,11 +22,11 @@ import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wrapper.ActivityInfoWrapper;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -84,9 +84,9 @@ public class PictureInPictureDetailsTest {
|
||||
|
||||
private boolean checkPackageHasPictureInPictureActivities(String packageName,
|
||||
boolean... resizeableActivityState) {
|
||||
ActivityInfoWrapper[] activities = null;
|
||||
ActivityInfo[] activities = null;
|
||||
if (resizeableActivityState.length > 0) {
|
||||
activities = new ActivityInfoWrapper[resizeableActivityState.length];
|
||||
activities = new ActivityInfo[resizeableActivityState.length];
|
||||
for (int i = 0; i < activities.length; i++) {
|
||||
activities[i] = new MockActivityInfo(resizeableActivityState[i]);
|
||||
}
|
||||
@@ -95,12 +95,11 @@ public class PictureInPictureDetailsTest {
|
||||
activities);
|
||||
}
|
||||
|
||||
private class MockActivityInfo extends ActivityInfoWrapper {
|
||||
private class MockActivityInfo extends ActivityInfo {
|
||||
|
||||
private boolean mSupportsPictureInPicture;
|
||||
|
||||
private MockActivityInfo(boolean supportsPictureInPicture) {
|
||||
super(null);
|
||||
mSupportsPictureInPicture = supportsPictureInPicture;
|
||||
}
|
||||
|
||||
|
@@ -16,8 +16,10 @@
|
||||
|
||||
package com.android.settings.development.qstile;
|
||||
|
||||
import static com.android.settings.development.qstile.DevelopmentTiles.WinscopeTrace.SURFACE_FLINGER_LAYER_TRACE_CONTROL_CODE;
|
||||
import static com.android.settings.development.qstile.DevelopmentTiles.WinscopeTrace.SURFACE_FLINGER_LAYER_TRACE_STATUS_CODE;
|
||||
import static com.android.settings.development.qstile.DevelopmentTiles.WinscopeTrace
|
||||
.SURFACE_FLINGER_LAYER_TRACE_CONTROL_CODE;
|
||||
import static com.android.settings.development.qstile.DevelopmentTiles.WinscopeTrace
|
||||
.SURFACE_FLINGER_LAYER_TRACE_STATUS_CODE;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
@@ -30,11 +32,11 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.view.IWindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowParcel;
|
||||
import com.android.settings.wrapper.IWindowManagerWrapper;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -49,7 +51,7 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
public class WinscopeTraceTest {
|
||||
|
||||
@Mock
|
||||
private IWindowManagerWrapper mWindowManager;
|
||||
private IWindowManager mWindowManager;
|
||||
@Mock
|
||||
private IBinder mSurfaceFlinger;
|
||||
@Mock
|
||||
|
@@ -28,12 +28,12 @@ import android.text.format.DateUtils;
|
||||
import android.util.KeyValueListParser;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.wrapper.KeyValueListParserWrapper;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class AnomalyDetectionPolicyTest {
|
||||
@@ -48,13 +48,12 @@ public class AnomalyDetectionPolicyTest {
|
||||
+ ",bluetooth_scan_enabled=true"
|
||||
+ ",bluetooth_scan_threshold=2000";
|
||||
private Context mContext;
|
||||
private KeyValueListParserWrapper mKeyValueListParserWrapper;
|
||||
private KeyValueListParser mKeyValueListParser;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mKeyValueListParserWrapper = spy(
|
||||
new KeyValueListParserWrapper(new KeyValueListParser(',')));
|
||||
mKeyValueListParser = spy((new KeyValueListParser(',')));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,11 +76,11 @@ public class AnomalyDetectionPolicyTest {
|
||||
Settings.Global.putString(mContext.getContentResolver(),
|
||||
Settings.Global.ANOMALY_DETECTION_CONSTANTS, "");
|
||||
// Mock it to avoid noSuchMethodError
|
||||
doReturn(true).when(mKeyValueListParserWrapper).getBoolean(anyString(), eq(true));
|
||||
doReturn(false).when(mKeyValueListParserWrapper).getBoolean(anyString(), eq(false));
|
||||
doReturn(true).when(mKeyValueListParser).getBoolean(anyString(), eq(true));
|
||||
doReturn(false).when(mKeyValueListParser).getBoolean(anyString(), eq(false));
|
||||
|
||||
AnomalyDetectionPolicy anomalyDetectionPolicy =
|
||||
new AnomalyDetectionPolicy(mContext, mKeyValueListParserWrapper);
|
||||
AnomalyDetectionPolicy anomalyDetectionPolicy = new AnomalyDetectionPolicy(mContext);
|
||||
ReflectionHelpers.setField(anomalyDetectionPolicy, "mParser", mKeyValueListParser);
|
||||
|
||||
assertThat(anomalyDetectionPolicy.anomalyDetectionEnabled).isFalse();
|
||||
assertThat(anomalyDetectionPolicy.wakeLockDetectionEnabled).isFalse();
|
||||
@@ -108,11 +107,11 @@ public class AnomalyDetectionPolicyTest {
|
||||
Settings.Global.putString(mContext.getContentResolver(),
|
||||
Settings.Global.ANOMALY_DETECTION_CONSTANTS, "");
|
||||
// Mock it to avoid noSuchMethodError
|
||||
doReturn(true).when(mKeyValueListParserWrapper).getBoolean(anyString(), eq(true));
|
||||
doReturn(false).when(mKeyValueListParserWrapper).getBoolean(anyString(), eq(false));
|
||||
doReturn(true).when(mKeyValueListParser).getBoolean(anyString(), eq(true));
|
||||
doReturn(false).when(mKeyValueListParser).getBoolean(anyString(), eq(false));
|
||||
|
||||
AnomalyDetectionPolicy policy = new AnomalyDetectionPolicy(mContext,
|
||||
mKeyValueListParserWrapper);
|
||||
AnomalyDetectionPolicy policy = new AnomalyDetectionPolicy(mContext);
|
||||
ReflectionHelpers.setField(policy, "mParser", mKeyValueListParser);
|
||||
|
||||
assertThat(policy.isAnomalyDetectorEnabled(Anomaly.AnomalyType.WAKE_LOCK)).isFalse();
|
||||
assertThat(policy.isAnomalyDetectorEnabled(Anomaly.AnomalyType.WAKEUP_ALARM)).isFalse();
|
||||
@@ -123,15 +122,17 @@ public class AnomalyDetectionPolicyTest {
|
||||
Settings.Global.putString(mContext.getContentResolver(),
|
||||
Settings.Global.ANOMALY_DETECTION_CONSTANTS, ANOMALY_DETECTION_CONSTANTS_VALUE);
|
||||
// Mock it to avoid noSuchMethodError
|
||||
doReturn(true).when(mKeyValueListParserWrapper)
|
||||
doReturn(true).when(mKeyValueListParser)
|
||||
.getBoolean(AnomalyDetectionPolicy.KEY_ANOMALY_DETECTION_ENABLED, false);
|
||||
doReturn(false).when(mKeyValueListParserWrapper)
|
||||
doReturn(false).when(mKeyValueListParser)
|
||||
.getBoolean(AnomalyDetectionPolicy.KEY_WAKELOCK_DETECTION_ENABLED, false);
|
||||
doReturn(true).when(mKeyValueListParserWrapper)
|
||||
doReturn(true).when(mKeyValueListParser)
|
||||
.getBoolean(AnomalyDetectionPolicy.KEY_WAKEUP_ALARM_DETECTION_ENABLED, false);
|
||||
doReturn(true).when(mKeyValueListParserWrapper)
|
||||
doReturn(true).when(mKeyValueListParser)
|
||||
.getBoolean(AnomalyDetectionPolicy.KEY_BLUETOOTH_SCAN_DETECTION_ENABLED, false);
|
||||
|
||||
return new AnomalyDetectionPolicy(mContext, mKeyValueListParserWrapper);
|
||||
final AnomalyDetectionPolicy policy = new AnomalyDetectionPolicy(mContext);
|
||||
ReflectionHelpers.setField(policy, "mParser", mKeyValueListParser);
|
||||
return policy;
|
||||
}
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ import com.android.settings.fuelgauge.anomaly.action.StopAndBackgroundCheckActio
|
||||
import com.android.settings.fuelgauge.anomaly.checker.WakeLockAnomalyDetector;
|
||||
import com.android.settings.fuelgauge.anomaly.checker.WakeupAlarmAnomalyDetector;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowKeyValueListParserWrapperImpl;
|
||||
import com.android.settings.testutils.shadow.ShadowKeyValueListParser;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -43,7 +43,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowKeyValueListParserWrapperImpl.class)
|
||||
@Config(shadows = ShadowKeyValueListParser.class)
|
||||
public class AnomalyUtilsTest {
|
||||
|
||||
private static final String PACKAGE_NAME_WAKEUP = "com.android.app1";
|
||||
|
@@ -38,7 +38,6 @@ import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsWrapper;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
@@ -54,9 +53,8 @@ import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {
|
||||
ShadowRestrictedLockUtilsWrapper.class,
|
||||
ShadowConnectivityManager.class,
|
||||
ShadowUserManager.class}
|
||||
ShadowConnectivityManager.class,
|
||||
ShadowUserManager.class}
|
||||
)
|
||||
public class MobileNetworkPreferenceControllerTest {
|
||||
|
||||
@@ -146,7 +144,7 @@ public class MobileNetworkPreferenceControllerTest {
|
||||
@Test
|
||||
public void airplaneModeTurnedOn_shouldDisablePreference() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Global.AIRPLANE_MODE_ON, 1);
|
||||
Global.AIRPLANE_MODE_ON, 1);
|
||||
mController = spy(new MobileNetworkPreferenceController(mContext));
|
||||
final RestrictedPreference mPreference = new RestrictedPreference(mContext);
|
||||
mController.updateState(mPreference);
|
||||
@@ -156,7 +154,7 @@ public class MobileNetworkPreferenceControllerTest {
|
||||
@Test
|
||||
public void airplaneModeTurnedOffAndNoUserRestriction_shouldEnablePreference() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Global.AIRPLANE_MODE_ON, 0);
|
||||
Global.AIRPLANE_MODE_ON, 0);
|
||||
mController = spy(new MobileNetworkPreferenceController(mContext));
|
||||
final RestrictedPreference mPreference = new RestrictedPreference(mContext);
|
||||
mPreference.setDisabledByAdmin(null);
|
||||
@@ -167,7 +165,7 @@ public class MobileNetworkPreferenceControllerTest {
|
||||
@Test
|
||||
public void airplaneModeTurnedOffAndHasUserRestriction_shouldDisablePreference() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Global.AIRPLANE_MODE_ON, 0);
|
||||
Global.AIRPLANE_MODE_ON, 0);
|
||||
mController = spy(new MobileNetworkPreferenceController(mContext));
|
||||
final RestrictedPreference mPreference = new RestrictedPreference(mContext);
|
||||
mPreference.setDisabledByAdmin(EnforcedAdmin.MULTIPLE_ENFORCED_ADMIN);
|
||||
|
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.testutils.shadow;
|
||||
|
||||
import android.util.KeyValueListParser;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
/**
|
||||
* Shadow for {@link KeyValueListParser} so we could implement
|
||||
* {@link #getBoolean(String, boolean)} that doesn't support in the current
|
||||
* robolectric
|
||||
*/
|
||||
@Implements(KeyValueListParser.class)
|
||||
public class ShadowKeyValueListParser {
|
||||
|
||||
@Implementation
|
||||
public boolean getBoolean(String key, boolean defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
package com.android.settings.testutils.shadow;
|
||||
|
||||
import com.android.settings.wrapper.KeyValueListParserWrapper;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
/**
|
||||
* Shadow for {@link KeyValueListParserWrapperImpl} so we could implement
|
||||
* {@link #getBoolean(String, boolean)} that doesn't support in the current
|
||||
* robolectric
|
||||
*/
|
||||
@Implements(KeyValueListParserWrapper.class)
|
||||
public class ShadowKeyValueListParserWrapperImpl {
|
||||
|
||||
@Implementation
|
||||
public boolean getBoolean(String key, boolean defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
@@ -14,25 +14,32 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wrapper;
|
||||
package com.android.settings.testutils.shadow;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.RecoverySystem;
|
||||
|
||||
/**
|
||||
* This class replicates a subset of the {@link RecoverySystem}.
|
||||
* The interface exists so that we can use a thin wrapper around the RecoverySystem in
|
||||
* production code and a mock in tests.
|
||||
*/
|
||||
public class RecoverySystemWrapper {
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
|
||||
/**
|
||||
* Returns whether wipe Euicc data successfully or not.
|
||||
*
|
||||
* @param packageName the package name of the caller app.
|
||||
*/
|
||||
public boolean wipeEuiccData(
|
||||
Context context, final String packageName) {
|
||||
return RecoverySystem.wipeEuiccData(context, packageName);
|
||||
@Implements(RecoverySystem.class)
|
||||
public class ShadowRecoverySystem {
|
||||
|
||||
private static int sWipeEuiccCalledCount;
|
||||
|
||||
@Implementation
|
||||
public static boolean wipeEuiccData(Context context, final String packageName) {
|
||||
sWipeEuiccCalledCount++;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
sWipeEuiccCalledCount = 0;
|
||||
}
|
||||
|
||||
public static int getWipeEuiccCalledCount() {
|
||||
return sWipeEuiccCalledCount;
|
||||
}
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
package com.android.settings.testutils.shadow;
|
||||
|
||||
import android.content.Context;
|
||||
import com.android.settings.wrapper.RestrictedLockUtilsWrapper;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
/**
|
||||
* Shadow for the wrapper around RestrictedLockUtils. Should be removed/updated once robolectric is
|
||||
* updated to allow usage of new UserManager API's. see
|
||||
* {@link com.android.settingslib.RestrictedLockUtils} and
|
||||
* {@link com.android.settings.network.RestrictedLockUtilsWrapper}
|
||||
*/
|
||||
@Implements(RestrictedLockUtilsWrapper.class)
|
||||
public class ShadowRestrictedLockUtilsWrapper {
|
||||
|
||||
private boolean isRestricted;
|
||||
|
||||
public boolean hasBaseUserRestriction(Context context, String userRestriction, int userId) {
|
||||
return isRestricted;
|
||||
}
|
||||
|
||||
public void setRestricted(boolean restricted) {
|
||||
isRestricted = restricted;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user