Merge "Remove more wrappers" into pi-dev am: a1c7bd0640
am: 483ad78026
Change-Id: Ic5fc39baf1511bf4b786720e647e66c73d543496
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.content.Context;
|
||||
import android.os.RecoverySystem;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
|
||||
@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