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 android.app.admin; 17 18 import android.annotation.UserIdInt; 19 20 import com.android.server.LocalServices; 21 22 import java.util.Collections; 23 import java.util.Map; 24 25 /** 26 * Stores a copy of the set of device policies maintained by {@link DevicePolicyManager} that 27 * can be accessed from any place without risking dead locks. 28 * 29 * @hide 30 */ 31 public abstract class DevicePolicyCache { DevicePolicyCache()32 protected DevicePolicyCache() { 33 } 34 35 /** 36 * @return the instance. 37 */ getInstance()38 public static DevicePolicyCache getInstance() { 39 final DevicePolicyManagerInternal dpmi = 40 LocalServices.getService(DevicePolicyManagerInternal.class); 41 return (dpmi != null) ? dpmi.getDevicePolicyCache() : EmptyDevicePolicyCache.INSTANCE; 42 } 43 44 /** 45 * See {@link DevicePolicyManager#getScreenCaptureDisabled} 46 */ isScreenCaptureAllowed(@serIdInt int userHandle)47 public abstract boolean isScreenCaptureAllowed(@UserIdInt int userHandle); 48 49 /** 50 * Caches {@link DevicePolicyManager#getPasswordQuality(android.content.ComponentName)} of the 51 * given user with {@code null} passed in as argument. 52 */ getPasswordQuality(@serIdInt int userHandle)53 public abstract int getPasswordQuality(@UserIdInt int userHandle); 54 55 /** 56 * Caches {@link DevicePolicyManager#getPermissionPolicy(android.content.ComponentName)} of 57 * the given user. 58 */ getPermissionPolicy(@serIdInt int userHandle)59 public abstract int getPermissionPolicy(@UserIdInt int userHandle); 60 61 /** 62 * True if there is an admin on the device who can grant sensor permissions. 63 */ canAdminGrantSensorsPermissions()64 public abstract boolean canAdminGrantSensorsPermissions(); 65 66 /** 67 * Returns a map of package names to package names, for which all launcher shortcuts which 68 * match a key package name should be modified to launch the corresponding value package 69 * name in the managed profile. The overridden shortcut should be badged accordingly. 70 */ getLauncherShortcutOverrides()71 public abstract Map<String, String> getLauncherShortcutOverrides(); 72 73 /** 74 * Empty implementation. 75 */ 76 private static class EmptyDevicePolicyCache extends DevicePolicyCache { 77 private static final EmptyDevicePolicyCache INSTANCE = new EmptyDevicePolicyCache(); 78 79 @Override isScreenCaptureAllowed(int userHandle)80 public boolean isScreenCaptureAllowed(int userHandle) { 81 return true; 82 } 83 84 @Override getPasswordQuality(int userHandle)85 public int getPasswordQuality(int userHandle) { 86 return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; 87 } 88 89 @Override getPermissionPolicy(int userHandle)90 public int getPermissionPolicy(int userHandle) { 91 return DevicePolicyManager.PERMISSION_POLICY_PROMPT; 92 } 93 94 @Override canAdminGrantSensorsPermissions()95 public boolean canAdminGrantSensorsPermissions() { 96 return false; 97 } 98 @Override getLauncherShortcutOverrides()99 public Map<String, String> getLauncherShortcutOverrides() { 100 return Collections.EMPTY_MAP; 101 } 102 } 103 } 104