1 /* 2 * Copyright (C) 2016 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.settings.enterprise; 18 19 import android.annotation.NonNull; 20 import android.content.ComponentName; 21 import android.os.UserHandle; 22 import android.support.annotation.Nullable; 23 24 import java.util.List; 25 26 /** 27 * This interface replicates a subset of the android.app.admin.DevicePolicyManager (DPM). The 28 * interface exists so that we can use a thin wrapper around the DPM in production code and a mock 29 * in tests. We cannot directly mock or shadow the DPM, because some of the methods we rely on are 30 * newer than the API version supported by Robolectric. 31 */ 32 public interface DevicePolicyManagerWrapper { 33 /** 34 * Calls {@code DevicePolicyManager.getActiveAdminsAsUser()}. 35 * 36 * @see android.app.admin.DevicePolicyManager#getActiveAdminsAsUser 37 */ getActiveAdminsAsUser(int userId)38 public @Nullable List<ComponentName> getActiveAdminsAsUser(int userId); 39 40 /** 41 * Calls {@code DevicePolicyManager.getMaximumFailedPasswordsForWipe()}. 42 * 43 * @see android.app.admin.DevicePolicyManager#getMaximumFailedPasswordsForWipe 44 */ getMaximumFailedPasswordsForWipe(@ullable ComponentName admin, int userHandle)45 int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle); 46 47 /** 48 * Calls {@code DevicePolicyManager.getDeviceOwnerComponentOnAnyUser()}. 49 * 50 * @see android.app.admin.DevicePolicyManager#getDeviceOwnerComponentOnAnyUser 51 */ getDeviceOwnerComponentOnAnyUser()52 ComponentName getDeviceOwnerComponentOnAnyUser(); 53 54 /** 55 * Calls {@code DevicePolicyManager.getProfileOwnerAsUser()}. 56 * 57 * @see android.app.admin.DevicePolicyManager#getProfileOwnerAsUser 58 */ getProfileOwnerAsUser(final int userId)59 @Nullable ComponentName getProfileOwnerAsUser(final int userId); 60 61 /** 62 * Calls {@code DevicePolicyManager.getDeviceOwnerNameOnAnyUser()}. 63 * 64 * @see android.app.admin.DevicePolicyManager#getDeviceOwnerNameOnAnyUser 65 */ getDeviceOwnerOrganizationName()66 CharSequence getDeviceOwnerOrganizationName(); 67 68 /** 69 * Calls {@code DevicePolicyManager.getPermissionGrantState()}. 70 * 71 * @see android.app.admin.DevicePolicyManager#getPermissionGrantState 72 */ getPermissionGrantState(@ullable ComponentName admin, String packageName, String permission)73 int getPermissionGrantState(@Nullable ComponentName admin, String packageName, 74 String permission); 75 76 /** 77 * Calls {@code DevicePolicyManager.isSecurityLoggingEnabled()}. 78 * 79 * @see android.app.admin.DevicePolicyManager#isSecurityLoggingEnabled 80 */ isSecurityLoggingEnabled(@ullable ComponentName admin)81 boolean isSecurityLoggingEnabled(@Nullable ComponentName admin); 82 83 /** 84 * Calls {@code DevicePolicyManager.isNetworkLoggingEnabled()}. 85 * 86 * @see android.app.admin.DevicePolicyManager#isNetworkLoggingEnabled 87 */ isNetworkLoggingEnabled(@ullable ComponentName admin)88 boolean isNetworkLoggingEnabled(@Nullable ComponentName admin); 89 90 /** 91 * Calls {@code DevicePolicyManager.getLastSecurityLogRetrievalTime()}. 92 * 93 * @see android.app.admin.DevicePolicyManager#getLastSecurityLogRetrievalTime 94 */ getLastSecurityLogRetrievalTime()95 long getLastSecurityLogRetrievalTime(); 96 97 /** 98 * Calls {@code DevicePolicyManager.getLastBugReportRequestTime()}. 99 * 100 * @see android.app.admin.DevicePolicyManager#getLastBugReportRequestTime 101 */ getLastBugReportRequestTime()102 long getLastBugReportRequestTime(); 103 104 /** 105 * Calls {@code DevicePolicyManager.getLastNetworkLogRetrievalTime()}. 106 * 107 * @see android.app.admin.DevicePolicyManager#getLastNetworkLogRetrievalTime 108 */ getLastNetworkLogRetrievalTime()109 long getLastNetworkLogRetrievalTime(); 110 111 /** 112 * Calls {@code DevicePolicyManager.isCurrentInputMethodSetByOwner()}. 113 * 114 * @see android.app.admin.DevicePolicyManager#isCurrentInputMethodSetByOwner 115 */ isCurrentInputMethodSetByOwner()116 boolean isCurrentInputMethodSetByOwner(); 117 118 119 /** 120 * Calls {@code DevicePolicyManager.getOwnerInstalledCaCerts()}. 121 * 122 * @see android.app.admin.DevicePolicyManager#getOwnerInstalledCaCerts 123 */ getOwnerInstalledCaCerts(@onNull UserHandle user)124 List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user); 125 126 /** 127 * Calls {@code DevicePolicyManager.isDeviceOwnerAppOnAnyUser()}. 128 * 129 * @see android.app.admin.DevicePolicyManager#isDeviceOwnerAppOnAnyUser 130 */ isDeviceOwnerAppOnAnyUser(String packageName)131 boolean isDeviceOwnerAppOnAnyUser(String packageName); 132 133 /** 134 * Calls {@code DevicePolicyManager.packageHasActiveAdmins()}. 135 * 136 * @see android.app.admin.DevicePolicyManager#packageHasActiveAdmins 137 */ packageHasActiveAdmins(String packageName)138 boolean packageHasActiveAdmins(String packageName); 139 140 /** 141 * Calls {@code DevicePolicyManager.isUninstallInQueue()}. 142 * 143 * @see android.app.admin.DevicePolicyManager#isUninstallInQueue 144 */ isUninstallInQueue(String packageName)145 boolean isUninstallInQueue(String packageName); 146 } 147