1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.settings.testutils.shadow; 17 18 import android.annotation.UserIdInt; 19 import android.content.Context; 20 21 import com.android.internal.util.ArrayUtils; 22 import com.android.settingslib.RestrictedLockUtils; 23 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; 24 25 import org.robolectric.annotation.Implementation; 26 import org.robolectric.annotation.Implements; 27 import org.robolectric.annotation.Resetter; 28 29 @Implements(RestrictedLockUtils.class) 30 public class ShadowRestrictedLockUtils { 31 private static boolean sIsRestricted; 32 private static String[] sRestrictedPkgs; 33 private static boolean sAdminSupportDetailsIntentLaunched; 34 private static int sKeyguardDisabledFeatures; 35 36 @Resetter 37 public static void reset() { 38 sIsRestricted = false; 39 sRestrictedPkgs = null; 40 sAdminSupportDetailsIntentLaunched = false; 41 sKeyguardDisabledFeatures = 0; 42 } 43 44 @Implementation 45 public static EnforcedAdmin checkIfMeteredDataRestricted(Context context, 46 String packageName, int userId) { 47 if (sIsRestricted) { 48 return new EnforcedAdmin(); 49 } 50 if (ArrayUtils.contains(sRestrictedPkgs, packageName)) { 51 return new EnforcedAdmin(); 52 } 53 return null; 54 } 55 56 @Implementation 57 public static void sendShowAdminSupportDetailsIntent(Context context, EnforcedAdmin admin) { 58 sAdminSupportDetailsIntentLaunched = true; 59 } 60 61 @Implementation 62 public static EnforcedAdmin checkIfKeyguardFeaturesDisabled(Context context, 63 int features, final @UserIdInt int userId) { 64 return (sKeyguardDisabledFeatures & features) == 0 ? null : new EnforcedAdmin(); 65 } 66 67 @Implementation 68 public static boolean hasBaseUserRestriction(Context context, 69 String userRestriction, int userId) { 70 return sIsRestricted; 71 } 72 73 @Implementation 74 public static EnforcedAdmin checkIfRestrictionEnforced(Context context, 75 String userRestriction, int userId) { 76 return sIsRestricted ? new EnforcedAdmin() : null; 77 } 78 79 public static boolean hasAdminSupportDetailsIntentLaunched() { 80 return sAdminSupportDetailsIntentLaunched; 81 } 82 83 public static void clearAdminSupportDetailsIntentLaunch() { 84 sAdminSupportDetailsIntentLaunched = false; 85 } 86 87 public static void setRestricted(boolean restricted) { 88 sIsRestricted = restricted; 89 } 90 91 public static void setRestrictedPkgs(String... pkgs) { 92 sRestrictedPkgs = pkgs; 93 } 94 95 public static void setKeyguardDisabledFeatures(int features) { 96 sKeyguardDisabledFeatures = features; 97 } 98 } 99