blob: 5a6e7139372825548c2146886aff45ee63b743c1 [file] [log] [blame]
Lin Guoc1133ca2019-01-28 22:27:37 -08001/*
2 * Copyright (C) 2019 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
17package com.android.car.settings.testutils;
18
19import android.annotation.Nullable;
20import android.app.admin.DevicePolicyManager;
davidlnafe538d2019-02-06 15:58:57 -080021import android.util.ArraySet;
Lin Guoc1133ca2019-01-28 22:27:37 -080022
23import org.robolectric.annotation.Implementation;
24import org.robolectric.annotation.Implements;
25import org.robolectric.annotation.Resetter;
26
27import java.util.List;
davidlnafe538d2019-02-06 15:58:57 -080028import java.util.Set;
Lin Guoc1133ca2019-01-28 22:27:37 -080029
30@Implements(value = DevicePolicyManager.class)
31public class ShadowDevicePolicyManager extends org.robolectric.shadows.ShadowDevicePolicyManager {
32 @Nullable
33 private static List<String> sPermittedInputMethods;
34
davidlnafe538d2019-02-06 15:58:57 -080035 private Set<String> mActiveAdminsPackages = new ArraySet<>();
36 private boolean mIsInstallInQueue;
37
38 @Resetter
39 public static void reset() {
40 sPermittedInputMethods = null;
41 }
42
Lin Guoc1133ca2019-01-28 22:27:37 -080043 @Implementation
44 @Nullable
45 protected List<String> getPermittedInputMethodsForCurrentUser() {
46 return sPermittedInputMethods;
47 }
48
49 public static void setPermittedInputMethodsForCurrentUser(@Nullable List<String> inputMethods) {
50 sPermittedInputMethods = inputMethods;
51 }
52
davidlnafe538d2019-02-06 15:58:57 -080053 @Implementation
54 protected boolean packageHasActiveAdmins(String packageName) {
55 return mActiveAdminsPackages.contains(packageName);
56 }
57
58 public void setPackageHasActiveAdmins(String packageName, boolean hasActiveAdmins) {
59 if (hasActiveAdmins) {
60 mActiveAdminsPackages.add(packageName);
61 } else {
62 mActiveAdminsPackages.remove(packageName);
63 }
64 }
65
66 @Implementation
67 protected boolean isUninstallInQueue(String packageName) {
68 return mIsInstallInQueue;
69 }
70
71 public void setIsUninstallInQueue(boolean isUninstallInQueue) {
72 mIsInstallInQueue = isUninstallInQueue;
Lin Guoc1133ca2019-01-28 22:27:37 -080073 }
74}