Lin Guo | c1133ca | 2019-01-28 22:27:37 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.car.settings.testutils; |
| 18 | |
| 19 | import android.annotation.Nullable; |
| 20 | import android.app.admin.DevicePolicyManager; |
davidln | afe538d | 2019-02-06 15:58:57 -0800 | [diff] [blame] | 21 | import android.util.ArraySet; |
Lin Guo | c1133ca | 2019-01-28 22:27:37 -0800 | [diff] [blame] | 22 | |
| 23 | import org.robolectric.annotation.Implementation; |
| 24 | import org.robolectric.annotation.Implements; |
| 25 | import org.robolectric.annotation.Resetter; |
| 26 | |
| 27 | import java.util.List; |
davidln | afe538d | 2019-02-06 15:58:57 -0800 | [diff] [blame] | 28 | import java.util.Set; |
Lin Guo | c1133ca | 2019-01-28 22:27:37 -0800 | [diff] [blame] | 29 | |
| 30 | @Implements(value = DevicePolicyManager.class) |
| 31 | public class ShadowDevicePolicyManager extends org.robolectric.shadows.ShadowDevicePolicyManager { |
| 32 | @Nullable |
| 33 | private static List<String> sPermittedInputMethods; |
| 34 | |
davidln | afe538d | 2019-02-06 15:58:57 -0800 | [diff] [blame] | 35 | private Set<String> mActiveAdminsPackages = new ArraySet<>(); |
| 36 | private boolean mIsInstallInQueue; |
| 37 | |
| 38 | @Resetter |
| 39 | public static void reset() { |
| 40 | sPermittedInputMethods = null; |
| 41 | } |
| 42 | |
Lin Guo | c1133ca | 2019-01-28 22:27:37 -0800 | [diff] [blame] | 43 | @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 | |
davidln | afe538d | 2019-02-06 15:58:57 -0800 | [diff] [blame] | 53 | @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 Guo | c1133ca | 2019-01-28 22:27:37 -0800 | [diff] [blame] | 73 | } |
| 74 | } |