blob: 1f6c3cc76ddd105136837436e86968133f273190 [file] [log] [blame]
Makoto Onuki068c54a2015-10-13 14:34:03 -07001/*
Amith Yamasaniea1b9d72016-05-27 15:57:38 +00002 * Copyright (C) 2016 The Android Open Source Project
Makoto Onuki068c54a2015-10-13 14:34:03 -07003 *
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
Amith Yamasaniea1b9d72016-05-27 15:57:38 +000014 * limitations under the License
Makoto Onuki068c54a2015-10-13 14:34:03 -070015 */
16package android.os;
17
Makoto Onuki1a2cd742015-11-16 13:51:27 -080018import android.annotation.Nullable;
yuemingw1d13eae2018-01-30 17:27:54 +000019import android.content.Context;
phweisse9c44062016-02-10 12:57:38 +010020import android.content.pm.UserInfo;
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +010021import android.graphics.Bitmap;
Makoto Onuki1a2cd742015-11-16 13:51:27 -080022
Makoto Onuki068c54a2015-10-13 14:34:03 -070023/**
24 * @hide Only for use within the system server.
25 */
26public abstract class UserManagerInternal {
Pavel Grafov6a40f092016-10-25 15:46:51 +010027 public static final int CAMERA_NOT_DISABLED = 0;
28 public static final int CAMERA_DISABLED_LOCALLY = 1;
29 public static final int CAMERA_DISABLED_GLOBALLY = 2;
30
Makoto Onukid45a4a22015-11-02 17:17:38 -080031 public interface UserRestrictionsListener {
32 /**
33 * Called when a user restriction changes.
34 *
35 * @param userId target user id
36 * @param newRestrictions new user restrictions
37 * @param prevRestrictions user restrictions that were previously set
38 */
39 void onUserRestrictionsChanged(int userId, Bundle newRestrictions, Bundle prevRestrictions);
40 }
41
Makoto Onuki068c54a2015-10-13 14:34:03 -070042 /**
Pavel Grafov6a40f092016-10-25 15:46:51 +010043 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to set
44 * restrictions enforced by the user.
Makoto Onuki068c54a2015-10-13 14:34:03 -070045 *
Makoto Onuki1a2cd742015-11-16 13:51:27 -080046 * @param userId target user id for the local restrictions.
Pavel Grafov6a40f092016-10-25 15:46:51 +010047 * @param restrictions a bundle of user restrictions.
48 * @param isDeviceOwner whether {@code userId} corresponds to device owner user id.
49 * @param cameraRestrictionScope is camera disabled and if so what is the scope of restriction.
50 * Should be one of {@link #CAMERA_NOT_DISABLED}, {@link #CAMERA_DISABLED_LOCALLY} or
51 * {@link #CAMERA_DISABLED_GLOBALLY}
Makoto Onuki068c54a2015-10-13 14:34:03 -070052 */
Pavel Grafov6a40f092016-10-25 15:46:51 +010053 public abstract void setDevicePolicyUserRestrictions(int userId, @Nullable Bundle restrictions,
54 boolean isDeviceOwner, int cameraRestrictionScope);
55
Makoto Onuki068c54a2015-10-13 14:34:03 -070056 /**
57 * Returns the "base" user restrictions.
58 *
59 * Used by {@link com.android.server.devicepolicy.DevicePolicyManagerService} for upgrading
60 * from MNC.
61 */
62 public abstract Bundle getBaseUserRestrictions(int userId);
63
64 /**
65 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} for upgrading
66 * from MNC.
67 */
68 public abstract void setBaseUserRestrictionsByDpmsForMigration(int userId,
69 Bundle baseRestrictions);
Makoto Onukid45a4a22015-11-02 17:17:38 -080070
71 /** Return a user restriction. */
72 public abstract boolean getUserRestriction(int userId, String key);
73
74 /** Adds a listener to user restriction changes. */
75 public abstract void addUserRestrictionsListener(UserRestrictionsListener listener);
76
77 /** Remove a {@link UserRestrictionsListener}. */
78 public abstract void removeUserRestrictionsListener(UserRestrictionsListener listener);
Makoto Onukie7927da2015-11-25 10:05:17 -080079
80 /**
81 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to update
82 * whether the device is managed by device owner.
83 */
84 public abstract void setDeviceManaged(boolean isManaged);
85
86 /**
87 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to update
88 * whether the user is managed by profile owner.
89 */
90 public abstract void setUserManaged(int userId, boolean isManaged);
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +010091
92 /**
93 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to omit
94 * restriction check, because DevicePolicyManager must always be able to set user icon
95 * regardless of any restriction.
96 * Also called by {@link com.android.server.pm.UserManagerService} because the logic of setting
97 * the icon is in this method.
98 */
99 public abstract void setUserIcon(int userId, Bitmap bitmap);
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +0100100
101 /**
102 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to inform the
103 * user manager whether all users should be created ephemeral.
104 */
105 public abstract void setForceEphemeralUsers(boolean forceEphemeralUsers);
106
107 /**
108 * Switches to the system user and deletes all other users.
109 *
110 * <p>Called by the {@link com.android.server.devicepolicy.DevicePolicyManagerService} when
111 * the force-ephemeral-users policy is toggled on to make sure there are no pre-existing
112 * non-ephemeral users left.
113 */
114 public abstract void removeAllUsers();
phweisse9c44062016-02-10 12:57:38 +0100115
116 /**
Lenka Trochtova1ddda472016-02-12 10:42:12 +0100117 * Called by the activity manager when the ephemeral user goes to background and its removal
118 * starts as a result.
119 *
120 * <p>It marks the ephemeral user as disabled in order to prevent it from being re-entered
121 * before its removal finishes.
122 *
123 * @param userId the ID of the ephemeral user.
124 */
125 public abstract void onEphemeralUserStop(int userId);
126
127 /**
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000128 * Same as UserManager.createUser(), but bypasses the check for
129 * {@link UserManager#DISALLOW_ADD_USER} and {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}
phweisse9c44062016-02-10 12:57:38 +0100130 *
131 * <p>Called by the {@link com.android.server.devicepolicy.DevicePolicyManagerService} when
132 * createAndManageUser is called by the device owner.
133 */
Alex Chaub6a9f942017-11-07 11:28:56 +0800134 public abstract UserInfo createUserEvenWhenDisallowed(String name, int flags,
135 String[] disallowedPackages);
Fyodor Kupolov6c915ea2016-05-09 19:10:53 -0700136
137 /**
Nicolas Prevotdf1b87d2016-10-25 13:57:08 +0100138 * Same as {@link UserManager#removeUser(int userHandle)}, but bypasses the check for
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000139 * {@link UserManager#DISALLOW_REMOVE_USER} and
140 * {@link UserManager#DISALLOW_REMOVE_MANAGED_PROFILE} and does not require the
Nicolas Prevotdf1b87d2016-10-25 13:57:08 +0100141 * {@link android.Manifest.permission#MANAGE_USERS} permission.
142 */
143 public abstract boolean removeUserEvenWhenDisallowed(int userId);
144
145 /**
Fyodor Kupolov6c915ea2016-05-09 19:10:53 -0700146 * Return whether the given user is running in an
Amith Yamasaniea1b9d72016-05-27 15:57:38 +0000147 * {@code UserState.STATE_RUNNING_UNLOCKING} or
148 * {@code UserState.STATE_RUNNING_UNLOCKED} state.
Fyodor Kupolov6c915ea2016-05-09 19:10:53 -0700149 */
150 public abstract boolean isUserUnlockingOrUnlocked(int userId);
151
152 /**
Fyodor Kupolov2e7e0962016-12-01 18:09:17 -0800153 * Return whether the given user is running in an
154 * {@code UserState.STATE_RUNNING_UNLOCKED} state.
155 */
156 public abstract boolean isUserUnlocked(int userId);
157
158 /**
Todd Kennedy0eb97382017-10-03 16:57:22 -0700159 * Returns whether the given user is running
Fyodor Kupolov6c915ea2016-05-09 19:10:53 -0700160 */
Amith Yamasaniea1b9d72016-05-27 15:57:38 +0000161 public abstract boolean isUserRunning(int userId);
162
163 /**
Todd Kennedy0eb97382017-10-03 16:57:22 -0700164 * Returns whether the given user is initialized
165 */
166 public abstract boolean isUserInitialized(int userId);
167
168 /**
169 * Returns whether the given user exists
170 */
171 public abstract boolean exists(int userId);
172
173 /**
Amith Yamasaniea1b9d72016-05-27 15:57:38 +0000174 * Set user's running state
175 */
176 public abstract void setUserState(int userId, int userState);
177
178 /**
179 * Remove user's running state
180 */
181 public abstract void removeUserState(int userId);
Michael Wachenschwanz3f2b6552017-05-15 13:53:09 -0700182
183 /**
184 * Returns an array of user ids. This array is cached in UserManagerService and passed as a
185 * reference, so do not modify the returned array.
186 *
187 * @return the array of user ids.
188 */
189 public abstract int[] getUserIds();
Sunny Goyal145c8f82018-02-15 14:27:09 -0800190
191 /**
192 * Checks if the {@code callingUserId} and {@code targetUserId} are same or in same group
193 * and that the {@code callingUserId} is not a managed profile and
194 * {@code targetUserId} is enabled.
195 *
196 * @return TRUE if the {@code callingUserId} can access {@code targetUserId}. FALSE
197 * otherwise
198 *
199 * @throws SecurityException if the calling user and {@code targetUser} are not in the same
200 * group and {@code throwSecurityException} is true, otherwise if will simply return false.
201 */
202 public abstract boolean isProfileAccessible(int callingUserId, int targetUserId,
203 String debugMsg, boolean throwSecurityException);
204
205 /**
206 * If {@code userId} is of a managed profile, return the parent user ID. Otherwise return
207 * itself.
208 */
209 public abstract int getProfileParentId(int userId);
yuemingw1d13eae2018-01-30 17:27:54 +0000210
211 /**
212 * Checks whether changing a setting to a value is prohibited by the corresponding user
213 * restriction.
214 *
215 * <p>See also {@link com.android.server.pm.UserRestrictionsUtils#applyUserRestriction(
216 * Context, int, String, boolean)}, which should be in sync with this method.
217 *
218 * @return {@code true} if the change is prohibited, {@code false} if the change is allowed.
219 *
220 * @hide
221 */
222 public abstract boolean isSettingRestrictedForUser(String setting, int userId, String value,
223 int callingUid);
Makoto Onuki068c54a2015-10-13 14:34:03 -0700224}