| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 208 | public abstract List<String> getAllCrossProfilePackages(); |
| 209 | |
| 210 | /** |
| 211 | * Returns the default package names set by the OEM that are allowed to communicate |
| 212 | * cross-profile without being explicitly enabled by the admin, via {@link |
| 213 | * com.android.internal.R.array#cross_profile_apps} and {@link |
| 214 | * com.android.internal.R.array#vendor_cross_profile_apps}. |
| 215 | * |
| 216 | * @hide |
| 217 | */ |
| 218 | public abstract List<String> getDefaultCrossProfilePackages(); |
| 219 | |
| 220 | /** |
| 221 | * Sends the {@code intent} to the package holding the |
| 222 | * {@link android.app.role.RoleManager#ROLE_DEVICE_MANAGER} role and packages with cross |
| 223 | * profile capabilities, meaning the application must have the {@code crossProfile} |
| 224 | * property and at least one of the following permissions: |
| 225 | * |
| 226 | * <ul> |
| 227 | * <li>{@link android.Manifest.permission.INTERACT_ACROSS_PROFILES} |
| 228 | * <li>{@link android.Manifest.permission.INTERACT_ACROSS_USERS} |
| 229 | * <li>{@link android.Manifest.permission.INTERACT_ACROSS_USERS_FULL} |
| 230 | * <li>{@link AppOpsManager.OP_INTERACT_ACROSS_PROFILES} appop |
| 231 | * </ul> |
| 232 | * |
| 233 | * <p>Note: The intent itself is not modified but copied before use. |
| 234 | *` |
| 235 | * @param intent Template for the intent sent to the packages. |
| 236 | * @param parentHandle Handle of the user that will receive the intents. |
| 237 | * @param requiresPermission If false, all packages with the {@code crossProfile} property |
| 238 | * will receive the intent without requiring the additional |
| 239 | * permissions. |
| 240 | */ |
| 241 | public abstract void broadcastIntentToManifestReceivers(Intent intent, |
| 242 | UserHandle parentHandle, boolean requiresPermission); |
| 243 | |
| 244 | /** |
| 245 | * Returns the profile owner component for the given user, or {@code null} if there is not one. |
| 246 | */ |
| 247 | @Nullable |
| 248 | public abstract ComponentName getProfileOwnerAsUser(@UserIdInt int userId); |
| 249 | |
| 250 | /** |
| 251 | * Returns the user id of the device owner, or {@link UserHandle#USER_NULL} if there is not one. |
| 252 | */ |
| 253 | @UserIdInt |
| 254 | public abstract int getDeviceOwnerUserId(); |
| 255 | |
| 256 | /** |
| 257 | * Returns whether the given package is a device owner or a profile owner in the calling user. |
| 258 | */ |
| 259 | public abstract boolean isDeviceOrProfileOwnerInCallingUser(String packageName); |
| 260 | |
| 261 | /** |
| 262 | * Returns whether this class supports being deferred the responsibility for resetting the given |
| 263 | * op. |
| 264 | */ |
| 265 | public abstract boolean supportsResetOp(int op); |
| 266 | |
| 267 | /** |
| 268 | * Resets the given op across the profile group of the given user for the given package. Assumes |
| 269 | * {@link #supportsResetOp(int)} is true. |
| 270 | */ |
| 271 | public abstract void resetOp(int op, String packageName, @UserIdInt int userId); |
| 272 | } |