1 /* 2 * Copyright (C) 2014 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 android.app.admin; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.UserIdInt; 22 import android.content.ComponentName; 23 import android.content.Intent; 24 import android.os.UserHandle; 25 26 import java.util.List; 27 import java.util.Set; 28 29 /** 30 * Device policy manager local system service interface. 31 * 32 * Maintenance note: if you need to expose information from DPMS to lower level services such as 33 * PM/UM/AM/etc, then exposing it from DevicePolicyManagerInternal is not safe because it may cause 34 * lock order inversion. Consider using {@link DevicePolicyCache} instead. 35 * 36 * @hide Only for use within the system server. 37 */ 38 public abstract class DevicePolicyManagerInternal { 39 40 /** 41 * Listener for changes in the allowlisted packages to show cross-profile 42 * widgets. 43 */ 44 public interface OnCrossProfileWidgetProvidersChangeListener { 45 46 /** 47 * Called when the allowlisted packages to show cross-profile widgets 48 * have changed for a given user. 49 * 50 * @param profileId The profile for which the allowlisted packages changed. 51 * @param packages The allowlisted packages. 52 */ onCrossProfileWidgetProvidersChanged(int profileId, List<String> packages)53 public void onCrossProfileWidgetProvidersChanged(int profileId, List<String> packages); 54 } 55 56 /** 57 * Gets the packages whose widget providers are allowlisted to be 58 * available in the parent user. 59 * 60 * <p>This takes the DPMS lock. DO NOT call from PM/UM/AM with their lock held. 61 * 62 * @param profileId The profile id. 63 * @return The list of packages if such or empty list if there are 64 * no allowlisted packages or the profile id is not a managed 65 * profile. 66 */ getCrossProfileWidgetProviders(int profileId)67 public abstract List<String> getCrossProfileWidgetProviders(int profileId); 68 69 /** 70 * Adds a listener for changes in the allowlisted packages to show 71 * cross-profile app widgets. 72 * 73 * <p>This takes the DPMS lock. DO NOT call from PM/UM/AM with their lock held. 74 * 75 * @param listener The listener to add. 76 */ addOnCrossProfileWidgetProvidersChangeListener( OnCrossProfileWidgetProvidersChangeListener listener)77 public abstract void addOnCrossProfileWidgetProvidersChangeListener( 78 OnCrossProfileWidgetProvidersChangeListener listener); 79 80 /** 81 * @param userHandle the handle of the user whose profile owner is being fetched. 82 * @return the configured supervision app if it exists and is the device owner or policy owner. 83 */ getProfileOwnerOrDeviceOwnerSupervisionComponent( @onNull UserHandle userHandle)84 public abstract @Nullable ComponentName getProfileOwnerOrDeviceOwnerSupervisionComponent( 85 @NonNull UserHandle userHandle); 86 87 /** 88 * Checks if an app with given uid is an active device owner of its user. 89 * 90 * <p>This takes the DPMS lock. DO NOT call from PM/UM/AM with their lock held. 91 * 92 * @param uid App uid. 93 * @return true if the uid is an active device owner. 94 */ isActiveDeviceOwner(int uid)95 public abstract boolean isActiveDeviceOwner(int uid); 96 97 /** 98 * Checks if an app with given uid is an active profile owner of its user. 99 * 100 * <p>This takes the DPMS lock. DO NOT call from PM/UM/AM with their lock held. 101 * 102 * @param uid App uid. 103 * @return true if the uid is an active profile owner. 104 */ isActiveProfileOwner(int uid)105 public abstract boolean isActiveProfileOwner(int uid); 106 107 /** 108 * Checks if an app with given uid is the active supervision admin. 109 * 110 * <p>This takes the DPMS lock. DO NOT call from PM/UM/AM with their lock held. 111 * 112 * @param uid App uid. 113 * @return true if the uid is the active supervision app. 114 */ isActiveSupervisionApp(int uid)115 public abstract boolean isActiveSupervisionApp(int uid); 116 117 /** 118 * Creates an intent to show the admin support dialog to say that an action is disallowed by 119 * the device/profile owner. 120 * 121 * <p>This method does not take the DPMS lock. Safe to be called from anywhere. 122 * @param userId The user where the action is disallowed. 123 * @param useDefaultIfNoAdmin If true, a non-null intent will be returned, even if we couldn't 124 * find a profile/device owner. 125 * @return The intent to trigger the admin support dialog. 126 */ createShowAdminSupportIntent(int userId, boolean useDefaultIfNoAdmin)127 public abstract Intent createShowAdminSupportIntent(int userId, boolean useDefaultIfNoAdmin); 128 129 /** 130 * Creates an intent to show the admin support dialog showing the admin who has set a user 131 * restriction. 132 * 133 * <p>This method does not take the DPMS lock. Safe to be called from anywhere. 134 * @param userId The user where the user restriction is set. 135 * @return The intent to trigger the admin support dialog, or null if the user restriction is 136 * not enforced by the profile/device owner. 137 */ createUserRestrictionSupportIntent(int userId, String userRestriction)138 public abstract Intent createUserRestrictionSupportIntent(int userId, String userRestriction); 139 140 /** 141 * Returns whether this user/profile is affiliated with the device. 142 * 143 * <p> 144 * By definition, the user that the device owner runs on is always affiliated with the device. 145 * Any other user/profile is considered affiliated with the device if the set specified by its 146 * profile owner via {@link DevicePolicyManager#setAffiliationIds} intersects with the device 147 * owner's. 148 * <p> 149 * Profile owner on the primary user will never be considered as affiliated as there is no 150 * device owner to be affiliated with. 151 */ isUserAffiliatedWithDevice(int userId)152 public abstract boolean isUserAffiliatedWithDevice(int userId); 153 154 /** 155 * Returns whether the calling package can install or uninstall packages without user 156 * interaction. 157 */ canSilentlyInstallPackage(String callerPackage, int callerUid)158 public abstract boolean canSilentlyInstallPackage(String callerPackage, int callerUid); 159 160 /** 161 * Reports that a profile has changed to use a unified or separate credential. 162 * 163 * @param userId User ID of the profile. 164 */ reportSeparateProfileChallengeChanged(@serIdInt int userId)165 public abstract void reportSeparateProfileChallengeChanged(@UserIdInt int userId); 166 167 /** 168 * Return text of error message if printing is disabled. 169 * Called by Print Service when printing is disabled by PO or DO when printing is attempted. 170 * 171 * @param userId The user in question 172 * @return localized error message 173 */ getPrintingDisabledReasonForUser(@serIdInt int userId)174 public abstract CharSequence getPrintingDisabledReasonForUser(@UserIdInt int userId); 175 176 /** 177 * @return cached version of DPM policies that can be accessed without risking deadlocks. 178 * Do not call it directly. Use {@link DevicePolicyCache#getInstance()} instead. 179 */ getDevicePolicyCache()180 protected abstract DevicePolicyCache getDevicePolicyCache(); 181 182 /** 183 * @return cached version of device state related to DPM that can be accessed without risking 184 * deadlocks. 185 * Do not call it directly. Use {@link DevicePolicyCache#getInstance()} instead. 186 */ getDeviceStateCache()187 protected abstract DeviceStateCache getDeviceStateCache(); 188 189 /** 190 * Returns the combined set of the following: 191 * <ul> 192 * <li>The package names that the admin has previously set as allowed to request user consent 193 * for cross-profile communication, via {@link 194 * DevicePolicyManager#setCrossProfilePackages(ComponentName, Set)}.</li> 195 * <li>The default package names that are allowed to request user consent for cross-profile 196 * communication without being explicitly enabled by the admin, via 197 * {@link com.android.internal.R.array#cross_profile_apps} and 198 * {@link com.android.internal.R.array#vendor_cross_profile_apps}.</li> 199 * </ul> 200 * 201 * @return the combined set of allowlisted package names set via 202 * {@link DevicePolicyManager#setCrossProfilePackages(ComponentName, Set)} and 203 * {@link com.android.internal.R.array#cross_profile_apps} and 204 * {@link com.android.internal.R.array#vendor_cross_profile_apps} 205 * 206 * @hide 207 */ getAllCrossProfilePackages()208 public abstract List<String> getAllCrossProfilePackages(); 209 210 /** 211 * Returns the default package names set by the OEM that are allowed to request user consent for 212 * cross-profile communication without being explicitly enabled by the admin, via 213 * {@link com.android.internal.R.array#cross_profile_apps} and 214 * {@link com.android.internal.R.array#vendor_cross_profile_apps}. 215 * 216 * @hide 217 */ getDefaultCrossProfilePackages()218 public abstract List<String> getDefaultCrossProfilePackages(); 219 220 /** 221 * Sends the {@code intent} to the packages with cross profile capabilities. 222 * 223 * <p>This means the application must have the {@code crossProfile} property and the 224 * corresponding permissions, defined by 225 * {@link 226 * android.content.pm.CrossProfileAppsInternal#verifyPackageHasInteractAcrossProfilePermission}. 227 * 228 * <p>Note: This method doesn't modify {@code intent} but copies it before use. 229 * 230 * @param intent Template for the intent sent to the package. 231 * @param parentHandle Handle of the user that will receive the intents. 232 * @param requiresPermission If false, all packages with the {@code crossProfile} property 233 * will receive the intent. 234 */ broadcastIntentToCrossProfileManifestReceiversAsUser(Intent intent, UserHandle parentHandle, boolean requiresPermission)235 public abstract void broadcastIntentToCrossProfileManifestReceiversAsUser(Intent intent, 236 UserHandle parentHandle, boolean requiresPermission); 237 238 /** 239 * Returns the profile owner component for the given user, or {@code null} if there is not one. 240 */ 241 @Nullable getProfileOwnerAsUser(@serIdInt int userId)242 public abstract ComponentName getProfileOwnerAsUser(@UserIdInt int userId); 243 244 /** 245 * Returns the user id of the device owner, or {@link UserHandle#USER_NULL} if there is not one. 246 */ 247 @UserIdInt getDeviceOwnerUserId()248 public abstract int getDeviceOwnerUserId(); 249 250 /** 251 * Returns whether the given package is a device owner or a profile owner in the calling user. 252 */ isDeviceOrProfileOwnerInCallingUser(String packageName)253 public abstract boolean isDeviceOrProfileOwnerInCallingUser(String packageName); 254 255 /** 256 * Returns whether this class supports being deferred the responsibility for resetting the given 257 * op. 258 */ supportsResetOp(int op)259 public abstract boolean supportsResetOp(int op); 260 261 /** 262 * Resets the given op across the profile group of the given user for the given package. Assumes 263 * {@link #supportsResetOp(int)} is true. 264 */ resetOp(int op, String packageName, @UserIdInt int userId)265 public abstract void resetOp(int op, String packageName, @UserIdInt int userId); 266 } 267