blob: e6c89d9071e669ae6b3388e29e467f96d1a9f0bc [file] [log] [blame]
Svetoslav976e8bd2014-07-16 15:12:03 -07001/*
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
17package android.app.admin;
18
Pavel Grafov28939982017-10-03 15:11:52 +010019import android.annotation.UserIdInt;
kholoud mohamed946df392019-12-12 17:43:32 +000020import android.content.ComponentName;
Sudheer Shanka7a9c34b2016-03-11 12:25:51 -080021import android.content.Intent;
kholoud mohamed946df392019-12-12 17:43:32 +000022import android.os.UserHandle;
Suprabh Shukla8bea73e2016-03-09 13:01:18 -080023
Svetoslav976e8bd2014-07-16 15:12:03 -070024import java.util.List;
kholoud mohamed946df392019-12-12 17:43:32 +000025import java.util.Set;
Svetoslav976e8bd2014-07-16 15:12:03 -070026
27/**
28 * Device policy manager local system service interface.
29 *
Varun Shahb472b8f2019-09-23 23:01:06 -070030 * Maintenance note: if you need to expose information from DPMS to lower level services such as
31 * PM/UM/AM/etc, then exposing it from DevicePolicyManagerInternal is not safe because it may cause
32 * lock order inversion. Consider using {@link DevicePolicyCache} instead.
33 *
Svetoslav976e8bd2014-07-16 15:12:03 -070034 * @hide Only for use within the system server.
35 */
36public abstract class DevicePolicyManagerInternal {
37
38 /**
Svet Ganov6bd70252014-08-20 09:47:47 -070039 * Listener for changes in the white-listed packages to show cross-profile
40 * widgets.
41 */
42 public interface OnCrossProfileWidgetProvidersChangeListener {
43
44 /**
45 * Called when the white-listed packages to show cross-profile widgets
46 * have changed for a given user.
47 *
48 * @param profileId The profile for which the white-listed packages changed.
49 * @param packages The white-listed packages.
50 */
51 public void onCrossProfileWidgetProvidersChanged(int profileId, List<String> packages);
52 }
53
54 /**
Svetoslav976e8bd2014-07-16 15:12:03 -070055 * Gets the packages whose widget providers are white-listed to be
56 * available in the parent user.
57 *
Makoto Onuki26704952016-06-13 14:50:11 -070058 * <p>This takes the DPMS lock. DO NOT call from PM/UM/AM with their lock held.
59 *
Svetoslav976e8bd2014-07-16 15:12:03 -070060 * @param profileId The profile id.
61 * @return The list of packages if such or empty list if there are
62 * no white-listed packages or the profile id is not a managed
63 * profile.
64 */
65 public abstract List<String> getCrossProfileWidgetProviders(int profileId);
Svet Ganov6bd70252014-08-20 09:47:47 -070066
67 /**
68 * Adds a listener for changes in the white-listed packages to show
69 * cross-profile app widgets.
70 *
Makoto Onuki26704952016-06-13 14:50:11 -070071 * <p>This takes the DPMS lock. DO NOT call from PM/UM/AM with their lock held.
72 *
Svet Ganov6bd70252014-08-20 09:47:47 -070073 * @param listener The listener to add.
74 */
75 public abstract void addOnCrossProfileWidgetProvidersChangeListener(
76 OnCrossProfileWidgetProvidersChangeListener listener);
Zoltan Szatmary-Ban1181ed82015-02-23 17:20:20 +000077
78 /**
79 * Checks if an app with given uid is an active device admin of its user and has the policy
80 * specified.
Makoto Onuki26704952016-06-13 14:50:11 -070081 *
82 * <p>This takes the DPMS lock. DO NOT call from PM/UM/AM with their lock held.
83 *
Zoltan Szatmary-Ban1181ed82015-02-23 17:20:20 +000084 * @param uid App uid.
85 * @param reqPolicy Required policy, for policies see {@link DevicePolicyManager}.
86 * @return true if the uid is an active admin with the given policy.
87 */
88 public abstract boolean isActiveAdminWithPolicy(int uid, int reqPolicy);
Suprabh Shuklad0452522016-03-02 14:33:10 -080089
90 /**
Varun Shahb472b8f2019-09-23 23:01:06 -070091 * Checks if an app with given uid is the active supervision admin.
92 *
93 * <p>This takes the DPMS lock. DO NOT call from PM/UM/AM with their lock held.
94 *
95 * @param uid App uid.
96 * @return true if the uid is the active supervision app.
97 */
98 public abstract boolean isActiveSupervisionApp(int uid);
99
100 /**
Nicolas Prevot709a63d2016-06-09 13:14:00 +0100101 * Creates an intent to show the admin support dialog to say that an action is disallowed by
102 * the device/profile owner.
Sudheer Shanka7a9c34b2016-03-11 12:25:51 -0800103 *
Makoto Onuki26704952016-06-13 14:50:11 -0700104 * <p>This method does not take the DPMS lock. Safe to be called from anywhere.
Nicolas Prevot709a63d2016-06-09 13:14:00 +0100105 * @param userId The user where the action is disallowed.
106 * @param useDefaultIfNoAdmin If true, a non-null intent will be returned, even if we couldn't
107 * find a profile/device owner.
Sudheer Shanka7a9c34b2016-03-11 12:25:51 -0800108 * @return The intent to trigger the admin support dialog.
109 */
Nicolas Prevot709a63d2016-06-09 13:14:00 +0100110 public abstract Intent createShowAdminSupportIntent(int userId, boolean useDefaultIfNoAdmin);
111
112 /**
113 * Creates an intent to show the admin support dialog showing the admin who has set a user
114 * restriction.
115 *
116 * <p>This method does not take the DPMS lock. Safe to be called from anywhere.
117 * @param userId The user where the user restriction is set.
118 * @return The intent to trigger the admin support dialog, or null if the user restriction is
119 * not enforced by the profile/device owner.
120 */
121 public abstract Intent createUserRestrictionSupportIntent(int userId, String userRestriction);
Benjamin Franzdabae882017-08-08 12:33:19 +0100122
123 /**
124 * Returns whether this user/profile is affiliated with the device.
125 *
126 * <p>
127 * By definition, the user that the device owner runs on is always affiliated with the device.
128 * Any other user/profile is considered affiliated with the device if the set specified by its
129 * profile owner via {@link DevicePolicyManager#setAffiliationIds} intersects with the device
130 * owner's.
131 * <p>
132 * Profile owner on the primary user will never be considered as affiliated as there is no
133 * device owner to be affiliated with.
134 */
135 public abstract boolean isUserAffiliatedWithDevice(int userId);
Pavel Grafov28939982017-10-03 15:11:52 +0100136
137 /**
Rubin Xufd4a3b42018-12-05 16:03:27 +0000138 * Returns whether the calling package can install or uninstall packages without user
139 * interaction.
140 */
141 public abstract boolean canSilentlyInstallPackage(String callerPackage, int callerUid);
142
143 /**
Pavel Grafov28939982017-10-03 15:11:52 +0100144 * Reports that a profile has changed to use a unified or separate credential.
145 *
146 * @param userId User ID of the profile.
147 */
148 public abstract void reportSeparateProfileChallengeChanged(@UserIdInt int userId);
Andrew Scull1416bd02018-01-05 18:33:58 +0000149
150 /**
Vladislav Kuzkokovfef75ee2018-01-22 23:37:14 +0100151 * Return text of error message if printing is disabled.
152 * Called by Print Service when printing is disabled by PO or DO when printing is attempted.
153 *
154 * @param userId The user in question
155 * @return localized error message
156 */
157 public abstract CharSequence getPrintingDisabledReasonForUser(@UserIdInt int userId);
Makoto Onuki04ef4472018-03-12 17:29:49 -0700158
159 /**
160 * @return cached version of DPM policies that can be accessed without risking deadlocks.
161 * Do not call it directly. Use {@link DevicePolicyCache#getInstance()} instead.
162 */
163 protected abstract DevicePolicyCache getDevicePolicyCache();
Rubin Xu0f1e56d2019-08-23 13:34:25 +0100164
165 /**
166 * @return cached version of device state related to DPM that can be accessed without risking
167 * deadlocks.
168 * Do not call it directly. Use {@link DevicePolicyCache#getInstance()} instead.
169 */
170 protected abstract DeviceStateCache getDeviceStateCache();
kholoud mohamed946df392019-12-12 17:43:32 +0000171
172 /**
173 * Returns the combined set of the following:
174 * <ul>
175 * <li>The package names that the admin has previously set as allowed to request user consent
176 * for cross-profile communication, via {@link
177 * DevicePolicyManager#setCrossProfilePackages(ComponentName, Set)}.</li>
178 * <li>The default package names that are allowed to request user consent for cross-profile
179 * communication without being explicitly enabled by the admin , via {@link
180 * DevicePolicyManager#setDefaultCrossProfilePackages(ComponentName, UserHandle, Set)}.</li>
181 * </ul>
182 *
183 * @return the combined set of whitelisted package names set via
184 * {@link DevicePolicyManager#setCrossProfilePackages(ComponentName, Set)} and
185 * {@link DevicePolicyManager#setDefaultCrossProfilePackages(ComponentName, UserHandle, Set)}
186 *
187 * @hide
188 */
189 public abstract List<String> getAllCrossProfilePackages();
Svetoslav976e8bd2014-07-16 15:12:03 -0700190}