Merge "RestrictedLockUtils was split into ...Internal"
This commit is contained in:
committed by
Android (Google) Code Review
commit
8a33bd5947
@@ -41,7 +41,7 @@ import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowAccountManager;
|
||||
import com.android.settings.testutils.shadow.ShadowContentResolver;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -54,7 +54,7 @@ import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class,
|
||||
ShadowRestrictedLockUtils.class})
|
||||
ShadowRestrictedLockUtilsInternal.class})
|
||||
public class ChooseAccountPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
@@ -77,7 +77,7 @@ public class ChooseAccountPreferenceControllerTest {
|
||||
public void tearDown() {
|
||||
ShadowContentResolver.reset();
|
||||
ShadowAccountManager.resetAuthenticator();
|
||||
ShadowRestrictedLockUtils.clearDisabledTypes();
|
||||
ShadowRestrictedLockUtilsInternal.clearDisabledTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -115,9 +115,9 @@ public class ChooseAccountPreferenceControllerTest {
|
||||
true /* supportsUploading */)};
|
||||
ShadowContentResolver.setSyncAdapterTypes(syncAdapters);
|
||||
|
||||
ShadowRestrictedLockUtils.setHasSystemFeature(true);
|
||||
ShadowRestrictedLockUtils.setDevicePolicyManager(mock(DevicePolicyManager.class));
|
||||
ShadowRestrictedLockUtils.setDisabledTypes(new String[] {"test_type"});
|
||||
ShadowRestrictedLockUtilsInternal.setHasSystemFeature(true);
|
||||
ShadowRestrictedLockUtilsInternal.setDevicePolicyManager(mock(DevicePolicyManager.class));
|
||||
ShadowRestrictedLockUtilsInternal.setDisabledTypes(new String[] {"test_type"});
|
||||
|
||||
doReturn("label").when(mController).getLabelForType(anyString());
|
||||
|
||||
@@ -140,9 +140,9 @@ public class ChooseAccountPreferenceControllerTest {
|
||||
true /* supportsUploading */)};
|
||||
ShadowContentResolver.setSyncAdapterTypes(syncAdapters);
|
||||
|
||||
ShadowRestrictedLockUtils.setHasSystemFeature(true);
|
||||
ShadowRestrictedLockUtils.setDevicePolicyManager(mock(DevicePolicyManager.class));
|
||||
ShadowRestrictedLockUtils.setDisabledTypes(new String[] {"com.acct1"});
|
||||
ShadowRestrictedLockUtilsInternal.setHasSystemFeature(true);
|
||||
ShadowRestrictedLockUtilsInternal.setDevicePolicyManager(mock(DevicePolicyManager.class));
|
||||
ShadowRestrictedLockUtilsInternal.setDisabledTypes(new String[] {"com.acct1"});
|
||||
|
||||
doReturn("label").when(mController).getLabelForType(anyString());
|
||||
|
||||
|
@@ -40,7 +40,7 @@ import androidx.preference.PreferenceScreen;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settingslib.AppItem;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
@@ -58,7 +58,7 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowEntityHeaderController.class, ShadowRestrictedLockUtils.class})
|
||||
@Config(shadows = {ShadowEntityHeaderController.class, ShadowRestrictedLockUtilsInternal.class})
|
||||
public class AppDataUsageTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
@@ -163,7 +163,7 @@ public class AppDataUsageTest {
|
||||
ReflectionHelpers.setField(mFragment, "mDataSaverBackend", dataSaverBackend);
|
||||
ReflectionHelpers.setField(mFragment.services, "mPolicyManager", networkPolicyManager);
|
||||
|
||||
ShadowRestrictedLockUtils.setRestricted(true);
|
||||
ShadowRestrictedLockUtilsInternal.setRestricted(true);
|
||||
doReturn(NetworkPolicyManager.POLICY_NONE).when(networkPolicyManager)
|
||||
.getUidPolicy(testUid);
|
||||
|
||||
|
@@ -43,6 +43,7 @@ import com.android.settings.datausage.AppStateDataUsageBridge.DataUsageState;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
||||
|
||||
@@ -61,6 +62,7 @@ import java.util.ArrayList;
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {
|
||||
ShadowRestrictedLockUtils.class,
|
||||
ShadowRestrictedLockUtilsInternal.class,
|
||||
UnrestrictedDataAccessPreferenceControllerTest.ShadowAppStateBaseBridge.class
|
||||
})
|
||||
public class UnrestrictedDataAccessPreferenceControllerTest {
|
||||
@@ -127,7 +129,7 @@ public class UnrestrictedDataAccessPreferenceControllerTest {
|
||||
|
||||
final String testPkg1 = "com.example.one";
|
||||
final String testPkg2 = "com.example.two";
|
||||
ShadowRestrictedLockUtils.setRestrictedPkgs(testPkg2);
|
||||
ShadowRestrictedLockUtilsInternal.setRestrictedPkgs(testPkg2);
|
||||
|
||||
doAnswer((invocation) -> {
|
||||
final UnrestrictedDataAccessPreference preference = invocation.getArgument(0);
|
||||
|
@@ -34,7 +34,7 @@ import android.provider.Settings;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowDevicePolicyManager;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -78,7 +78,7 @@ public class TimeoutPreferenceControllerTest {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowRestrictedLockUtils.reset();
|
||||
ShadowRestrictedLockUtilsInternal.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,13 +139,13 @@ public class TimeoutPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowRestrictedLockUtils.class)
|
||||
@Config(shadows = ShadowRestrictedLockUtilsInternal.class)
|
||||
public void updateState_selectedTimeoutLargerThanAdminMax_shouldSetSummaryToUpdatedPrefValue() {
|
||||
final int profileUserId = UserHandle.myUserId();
|
||||
final long allowedTimeout = 480000L; // 8 minutes
|
||||
when(mUserManager.getProfiles(profileUserId)).thenReturn(Collections.emptyList());
|
||||
ShadowDevicePolicyManager.getShadow().setMaximumTimeToLock(profileUserId, allowedTimeout);
|
||||
ShadowRestrictedLockUtils.setMaximumTimeToLockIsSet(true);
|
||||
ShadowRestrictedLockUtilsInternal.setMaximumTimeToLockIsSet(true);
|
||||
final CharSequence[] timeouts = {"15000", "30000", "60000", "120000", "300000", "600000"};
|
||||
final CharSequence[] summaries = {"15s", "30s", "1m", "2m", "5m", "10m"};
|
||||
// set current timeout to be 10 minutes, which is longer than the allowed 8 minutes
|
||||
|
@@ -23,7 +23,7 @@ import static org.mockito.Mockito.when;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
|
||||
import com.android.settings.wifi.WifiMasterSwitchPreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -36,7 +36,7 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowRestrictedLockUtils.class)
|
||||
@Config(shadows = ShadowRestrictedLockUtilsInternal.class)
|
||||
public class TopLevelNetworkEntryPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
|
@@ -31,7 +31,7 @@ import android.provider.Settings;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -69,7 +69,7 @@ public class AndroidBeamPreferenceControllerTest {
|
||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
when(mContext.getSystemService(Context.NFC_SERVICE)).thenReturn(mManager);
|
||||
when(RestrictedLockUtils.hasBaseUserRestriction(mContext,
|
||||
when(RestrictedLockUtilsInternal.hasBaseUserRestriction(mContext,
|
||||
UserManager.DISALLOW_OUTGOING_BEAM, UserHandle.myUserId())).thenReturn(false);
|
||||
when(NfcAdapter.getDefaultAdapter(mContext)).thenReturn(mNfcAdapter);
|
||||
|
||||
@@ -104,7 +104,7 @@ public class AndroidBeamPreferenceControllerTest {
|
||||
public void isBeamEnable_disAllowBeam_shouldReturnFalse() {
|
||||
when(mNfcAdapter.getAdapterState()).thenReturn(NfcAdapter.STATE_OFF);
|
||||
|
||||
when(RestrictedLockUtils.hasBaseUserRestriction(mContext,
|
||||
when(RestrictedLockUtilsInternal.hasBaseUserRestriction(mContext,
|
||||
UserManager.DISALLOW_OUTGOING_BEAM, UserHandle.myUserId())).thenReturn(true);
|
||||
mAndroidBeamController.displayPreference(mScreen);
|
||||
|
||||
|
@@ -22,7 +22,7 @@ import com.android.settings.notification.RedactionInterstitial.RedactionIntersti
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.robolectric.annotation.Config;
|
||||
SettingsShadowResourcesImpl.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class,
|
||||
ShadowUtils.class,
|
||||
ShadowRestrictedLockUtils.class,
|
||||
ShadowRestrictedLockUtilsInternal.class,
|
||||
ShadowUserManager.class,
|
||||
})
|
||||
public class RedactionInterstitialTest {
|
||||
@@ -49,7 +49,7 @@ public class RedactionInterstitialTest {
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowUserManager.getShadow().reset();
|
||||
ShadowRestrictedLockUtils.reset();
|
||||
ShadowRestrictedLockUtilsInternal.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,7 +85,7 @@ public class RedactionInterstitialTest {
|
||||
@Test
|
||||
public void primaryUserUnredactedRestrictionTest() {
|
||||
setupSettings(1 /* show */, 1 /* showUnredacted */);
|
||||
ShadowRestrictedLockUtils.setKeyguardDisabledFeatures(
|
||||
ShadowRestrictedLockUtilsInternal.setKeyguardDisabledFeatures(
|
||||
KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
|
||||
setupActivity();
|
||||
|
||||
@@ -97,7 +97,7 @@ public class RedactionInterstitialTest {
|
||||
@Test
|
||||
public void primaryUserNotificationRestrictionTest() {
|
||||
setupSettings(1 /* show */, 1 /* showUnredacted */);
|
||||
ShadowRestrictedLockUtils.setKeyguardDisabledFeatures(
|
||||
ShadowRestrictedLockUtilsInternal.setKeyguardDisabledFeatures(
|
||||
KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
|
||||
setupActivity();
|
||||
|
||||
@@ -121,7 +121,7 @@ public class RedactionInterstitialTest {
|
||||
public void managedProfileUnredactedRestrictionTest() {
|
||||
setupSettings(1 /* show */, 1 /* showUnredacted */);
|
||||
ShadowUserManager.getShadow().addManagedProfile(UserHandle.myUserId());
|
||||
ShadowRestrictedLockUtils.setKeyguardDisabledFeatures(
|
||||
ShadowRestrictedLockUtilsInternal.setKeyguardDisabledFeatures(
|
||||
KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
|
||||
setupActivity();
|
||||
|
||||
|
@@ -35,7 +35,7 @@ import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowDevicePolicyManager;
|
||||
import com.android.settings.testutils.shadow.ShadowLockPatternUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -55,7 +55,7 @@ import java.util.List;
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {
|
||||
ShadowLockPatternUtils.class,
|
||||
ShadowRestrictedLockUtils.class,
|
||||
ShadowRestrictedLockUtilsInternal.class,
|
||||
ShadowDevicePolicyManager.class,
|
||||
ShadowApplicationPackageManager.class,
|
||||
TrustAgentsPreferenceControllerTest.ShadowTrustAgentManager.class
|
||||
@@ -145,7 +145,7 @@ public class TrustAgentsPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void onStart_hasUnrestrictedTrustAgent_shouldAddThreeChangeablePreferences() {
|
||||
ShadowRestrictedLockUtils.setKeyguardDisabledFeatures(0);
|
||||
ShadowRestrictedLockUtilsInternal.setKeyguardDisabledFeatures(0);
|
||||
final List<ResolveInfo> availableAgents = createFakeAvailableAgents();
|
||||
for (ResolveInfo rInfo : availableAgents) {
|
||||
ShadowTrustAgentManager.grantPermissionToResolveInfo(rInfo);
|
||||
@@ -170,7 +170,7 @@ public class TrustAgentsPreferenceControllerTest {
|
||||
ShadowTrustAgentManager.grantPermissionToResolveInfo(rInfo);
|
||||
}
|
||||
mPackageManager.addResolveInfoForIntent(TEST_INTENT, availableAgents);
|
||||
ShadowRestrictedLockUtils.setKeyguardDisabledFeatures(
|
||||
ShadowRestrictedLockUtilsInternal.setKeyguardDisabledFeatures(
|
||||
DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS);
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
@@ -15,99 +15,24 @@
|
||||
*/
|
||||
package com.android.settings.testutils.shadow;
|
||||
|
||||
import android.annotation.UserIdInt;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
|
||||
@Implements(RestrictedLockUtils.class)
|
||||
public class ShadowRestrictedLockUtils {
|
||||
|
||||
private static boolean sIsRestricted;
|
||||
private static boolean sAdminSupportDetailsIntentLaunched;
|
||||
private static boolean sHasSystemFeature;
|
||||
private static boolean sMaximumTimeToLockIsSet;
|
||||
private static String[] sRestrictedPkgs;
|
||||
private static DevicePolicyManager sDevicePolicyManager;
|
||||
private static String[] sDisabledTypes;
|
||||
private static int sKeyguardDisabledFeatures;
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
sIsRestricted = false;
|
||||
sRestrictedPkgs = null;
|
||||
sAdminSupportDetailsIntentLaunched = false;
|
||||
sKeyguardDisabledFeatures = 0;
|
||||
sDisabledTypes = new String[0];
|
||||
sMaximumTimeToLockIsSet = false;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static EnforcedAdmin checkIfMeteredDataRestricted(Context context,
|
||||
String packageName, int userId) {
|
||||
if (sIsRestricted) {
|
||||
return new EnforcedAdmin();
|
||||
}
|
||||
if (ArrayUtils.contains(sRestrictedPkgs, packageName)) {
|
||||
return new EnforcedAdmin();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static void sendShowAdminSupportDetailsIntent(Context context, EnforcedAdmin admin) {
|
||||
sAdminSupportDetailsIntentLaunched = true;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static EnforcedAdmin checkIfAccountManagementDisabled(Context context,
|
||||
String accountType, int userId) {
|
||||
if (accountType == null) {
|
||||
return null;
|
||||
}
|
||||
if (!sHasSystemFeature || sDevicePolicyManager == null) {
|
||||
return null;
|
||||
}
|
||||
boolean isAccountTypeDisabled = false;
|
||||
if (ArrayUtils.contains(sDisabledTypes, accountType)) {
|
||||
isAccountTypeDisabled = true;
|
||||
}
|
||||
if (!isAccountTypeDisabled) {
|
||||
return null;
|
||||
}
|
||||
return new EnforcedAdmin();
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static EnforcedAdmin checkIfKeyguardFeaturesDisabled(Context context,
|
||||
int features, final @UserIdInt int userId) {
|
||||
return (sKeyguardDisabledFeatures & features) == 0 ? null : new EnforcedAdmin();
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static boolean hasBaseUserRestriction(Context context,
|
||||
String userRestriction, int userId) {
|
||||
return sIsRestricted;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static EnforcedAdmin checkIfRestrictionEnforced(Context context,
|
||||
String userRestriction, int userId) {
|
||||
return sIsRestricted ? new EnforcedAdmin() : null;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static EnforcedAdmin checkIfMaximumTimeToLockIsSet(Context context) {
|
||||
return sMaximumTimeToLockIsSet ? new EnforcedAdmin() : null;
|
||||
}
|
||||
|
||||
public static boolean hasAdminSupportDetailsIntentLaunched() {
|
||||
return sAdminSupportDetailsIntentLaunched;
|
||||
}
|
||||
@@ -116,36 +41,5 @@ public class ShadowRestrictedLockUtils {
|
||||
sAdminSupportDetailsIntentLaunched = false;
|
||||
}
|
||||
|
||||
public static void setRestricted(boolean restricted) {
|
||||
sIsRestricted = restricted;
|
||||
}
|
||||
|
||||
public static void setRestrictedPkgs(String... pkgs) {
|
||||
sRestrictedPkgs = pkgs;
|
||||
}
|
||||
|
||||
public static void setHasSystemFeature(boolean hasSystemFeature) {
|
||||
sHasSystemFeature = hasSystemFeature;
|
||||
}
|
||||
|
||||
public static void setDevicePolicyManager(DevicePolicyManager dpm) {
|
||||
sDevicePolicyManager = dpm;
|
||||
}
|
||||
|
||||
public static void setDisabledTypes(String[] disabledTypes) {
|
||||
sDisabledTypes = disabledTypes;
|
||||
}
|
||||
|
||||
public static void clearDisabledTypes() {
|
||||
sDisabledTypes = new String[0];
|
||||
}
|
||||
|
||||
public static void setKeyguardDisabledFeatures(int features) {
|
||||
sKeyguardDisabledFeatures = features;
|
||||
}
|
||||
|
||||
public static void setMaximumTimeToLockIsSet(boolean isSet) {
|
||||
sMaximumTimeToLockIsSet = isSet;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* 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.annotation.UserIdInt;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
|
||||
@Implements(RestrictedLockUtilsInternal.class)
|
||||
public class ShadowRestrictedLockUtilsInternal {
|
||||
|
||||
private static boolean sIsRestricted;
|
||||
private static boolean sHasSystemFeature;
|
||||
private static boolean sMaximumTimeToLockIsSet;
|
||||
private static String[] sRestrictedPkgs;
|
||||
private static DevicePolicyManager sDevicePolicyManager;
|
||||
private static String[] sDisabledTypes;
|
||||
private static int sKeyguardDisabledFeatures;
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
sIsRestricted = false;
|
||||
sRestrictedPkgs = null;
|
||||
sKeyguardDisabledFeatures = 0;
|
||||
sDisabledTypes = new String[0];
|
||||
sMaximumTimeToLockIsSet = false;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static EnforcedAdmin checkIfMeteredDataRestricted(Context context,
|
||||
String packageName, int userId) {
|
||||
if (sIsRestricted) {
|
||||
return new EnforcedAdmin();
|
||||
}
|
||||
if (ArrayUtils.contains(sRestrictedPkgs, packageName)) {
|
||||
return new EnforcedAdmin();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static EnforcedAdmin checkIfAccountManagementDisabled(Context context,
|
||||
String accountType, int userId) {
|
||||
if (accountType == null) {
|
||||
return null;
|
||||
}
|
||||
if (!sHasSystemFeature || sDevicePolicyManager == null) {
|
||||
return null;
|
||||
}
|
||||
boolean isAccountTypeDisabled = false;
|
||||
if (ArrayUtils.contains(sDisabledTypes, accountType)) {
|
||||
isAccountTypeDisabled = true;
|
||||
}
|
||||
if (!isAccountTypeDisabled) {
|
||||
return null;
|
||||
}
|
||||
return new EnforcedAdmin();
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static EnforcedAdmin checkIfKeyguardFeaturesDisabled(Context context,
|
||||
int features, final @UserIdInt int userId) {
|
||||
return (sKeyguardDisabledFeatures & features) == 0 ? null : new EnforcedAdmin();
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static boolean hasBaseUserRestriction(Context context,
|
||||
String userRestriction, int userId) {
|
||||
return sIsRestricted;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static EnforcedAdmin checkIfRestrictionEnforced(Context context,
|
||||
String userRestriction, int userId) {
|
||||
return sIsRestricted ? new EnforcedAdmin() : null;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static EnforcedAdmin checkIfMaximumTimeToLockIsSet(Context context) {
|
||||
return sMaximumTimeToLockIsSet ? new EnforcedAdmin() : null;
|
||||
}
|
||||
|
||||
public static void setRestricted(boolean restricted) {
|
||||
sIsRestricted = restricted;
|
||||
}
|
||||
|
||||
public static void setRestrictedPkgs(String... pkgs) {
|
||||
sRestrictedPkgs = pkgs;
|
||||
}
|
||||
|
||||
public static void setHasSystemFeature(boolean hasSystemFeature) {
|
||||
sHasSystemFeature = hasSystemFeature;
|
||||
}
|
||||
|
||||
public static void setDevicePolicyManager(DevicePolicyManager dpm) {
|
||||
sDevicePolicyManager = dpm;
|
||||
}
|
||||
|
||||
public static void setDisabledTypes(String[] disabledTypes) {
|
||||
sDisabledTypes = disabledTypes;
|
||||
}
|
||||
|
||||
public static void clearDisabledTypes() {
|
||||
sDisabledTypes = new String[0];
|
||||
}
|
||||
|
||||
public static void setKeyguardDisabledFeatures(int features) {
|
||||
sKeyguardDisabledFeatures = features;
|
||||
}
|
||||
|
||||
public static void setMaximumTimeToLockIsSet(boolean isSet) {
|
||||
sMaximumTimeToLockIsSet = isSet;
|
||||
}
|
||||
|
||||
}
|
@@ -79,6 +79,15 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager
|
||||
return mUserProfileInfos;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public int[] getProfileIds(@UserIdInt int userHandle, boolean enabledOnly) {
|
||||
int[] ids = new int[mUserProfileInfos.size()];
|
||||
for (int i = 0; i < mUserProfileInfos.size(); i++) {
|
||||
ids[i] = mUserProfileInfos.get(i).id;
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public int getCredentialOwnerProfile(@UserIdInt int userHandle) {
|
||||
return userHandle;
|
||||
|
@@ -26,7 +26,7 @@ import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
|
||||
import com.android.settings.widget.SwitchWidgetController;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowRestrictedLockUtils.class)
|
||||
@Config(shadows = ShadowRestrictedLockUtilsInternal.class)
|
||||
public class WifiEnablerTest {
|
||||
|
||||
@Mock
|
||||
|
@@ -37,7 +37,7 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
|
||||
import com.android.settings.widget.MasterSwitchPreference;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
@@ -50,7 +50,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowRestrictedLockUtils.class)
|
||||
@Config(shadows = ShadowRestrictedLockUtilsInternal.class)
|
||||
public class WifiMasterSwitchPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
|
Reference in New Issue
Block a user