blob: 17f00c24988d7993339bcc81e025085777a9cdb3 [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;
phweisse9c44062016-02-10 12:57:38 +010019import android.content.pm.UserInfo;
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +010020import android.graphics.Bitmap;
Makoto Onuki1a2cd742015-11-16 13:51:27 -080021
Makoto Onuki068c54a2015-10-13 14:34:03 -070022/**
23 * @hide Only for use within the system server.
24 */
25public abstract class UserManagerInternal {
Pavel Grafov6a40f092016-10-25 15:46:51 +010026 public static final int CAMERA_NOT_DISABLED = 0;
27 public static final int CAMERA_DISABLED_LOCALLY = 1;
28 public static final int CAMERA_DISABLED_GLOBALLY = 2;
29
Makoto Onukid45a4a22015-11-02 17:17:38 -080030 public interface UserRestrictionsListener {
31 /**
32 * Called when a user restriction changes.
33 *
34 * @param userId target user id
35 * @param newRestrictions new user restrictions
36 * @param prevRestrictions user restrictions that were previously set
37 */
38 void onUserRestrictionsChanged(int userId, Bundle newRestrictions, Bundle prevRestrictions);
39 }
40
Makoto Onuki068c54a2015-10-13 14:34:03 -070041 /**
Pavel Grafov6a40f092016-10-25 15:46:51 +010042 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to set
43 * restrictions enforced by the user.
Makoto Onuki068c54a2015-10-13 14:34:03 -070044 *
Makoto Onuki1a2cd742015-11-16 13:51:27 -080045 * @param userId target user id for the local restrictions.
Pavel Grafov6a40f092016-10-25 15:46:51 +010046 * @param restrictions a bundle of user restrictions.
47 * @param isDeviceOwner whether {@code userId} corresponds to device owner user id.
48 * @param cameraRestrictionScope is camera disabled and if so what is the scope of restriction.
49 * Should be one of {@link #CAMERA_NOT_DISABLED}, {@link #CAMERA_DISABLED_LOCALLY} or
50 * {@link #CAMERA_DISABLED_GLOBALLY}
Makoto Onuki068c54a2015-10-13 14:34:03 -070051 */
Pavel Grafov6a40f092016-10-25 15:46:51 +010052 public abstract void setDevicePolicyUserRestrictions(int userId, @Nullable Bundle restrictions,
53 boolean isDeviceOwner, int cameraRestrictionScope);
54
Makoto Onuki068c54a2015-10-13 14:34:03 -070055 /**
56 * Returns the "base" user restrictions.
57 *
58 * Used by {@link com.android.server.devicepolicy.DevicePolicyManagerService} for upgrading
59 * from MNC.
60 */
61 public abstract Bundle getBaseUserRestrictions(int userId);
62
63 /**
64 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} for upgrading
65 * from MNC.
66 */
67 public abstract void setBaseUserRestrictionsByDpmsForMigration(int userId,
68 Bundle baseRestrictions);
Makoto Onukid45a4a22015-11-02 17:17:38 -080069
70 /** Return a user restriction. */
71 public abstract boolean getUserRestriction(int userId, String key);
72
73 /** Adds a listener to user restriction changes. */
74 public abstract void addUserRestrictionsListener(UserRestrictionsListener listener);
75
76 /** Remove a {@link UserRestrictionsListener}. */
77 public abstract void removeUserRestrictionsListener(UserRestrictionsListener listener);
Makoto Onukie7927da2015-11-25 10:05:17 -080078
79 /**
80 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to update
81 * whether the device is managed by device owner.
82 */
83 public abstract void setDeviceManaged(boolean isManaged);
84
85 /**
86 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to update
87 * whether the user is managed by profile owner.
88 */
89 public abstract void setUserManaged(int userId, boolean isManaged);
Oleksandr Peletskyi7f1f1df2016-01-18 15:40:21 +010090
91 /**
92 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to omit
93 * restriction check, because DevicePolicyManager must always be able to set user icon
94 * regardless of any restriction.
95 * Also called by {@link com.android.server.pm.UserManagerService} because the logic of setting
96 * the icon is in this method.
97 */
98 public abstract void setUserIcon(int userId, Bitmap bitmap);
Lenka Trochtovaf348e8e2016-01-07 17:20:34 +010099
100 /**
101 * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} to inform the
102 * user manager whether all users should be created ephemeral.
103 */
104 public abstract void setForceEphemeralUsers(boolean forceEphemeralUsers);
105
106 /**
107 * Switches to the system user and deletes all other users.
108 *
109 * <p>Called by the {@link com.android.server.devicepolicy.DevicePolicyManagerService} when
110 * the force-ephemeral-users policy is toggled on to make sure there are no pre-existing
111 * non-ephemeral users left.
112 */
113 public abstract void removeAllUsers();
phweisse9c44062016-02-10 12:57:38 +0100114
115 /**
Lenka Trochtova1ddda472016-02-12 10:42:12 +0100116 * Called by the activity manager when the ephemeral user goes to background and its removal
117 * starts as a result.
118 *
119 * <p>It marks the ephemeral user as disabled in order to prevent it from being re-entered
120 * before its removal finishes.
121 *
122 * @param userId the ID of the ephemeral user.
123 */
124 public abstract void onEphemeralUserStop(int userId);
125
126 /**
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000127 * Same as UserManager.createUser(), but bypasses the check for
128 * {@link UserManager#DISALLOW_ADD_USER} and {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}
phweisse9c44062016-02-10 12:57:38 +0100129 *
130 * <p>Called by the {@link com.android.server.devicepolicy.DevicePolicyManagerService} when
131 * createAndManageUser is called by the device owner.
132 */
133 public abstract UserInfo createUserEvenWhenDisallowed(String name, int flags);
Fyodor Kupolov6c915ea2016-05-09 19:10:53 -0700134
135 /**
Nicolas Prevotdf1b87d2016-10-25 13:57:08 +0100136 * Same as {@link UserManager#removeUser(int userHandle)}, but bypasses the check for
Esteban Talavera6c9116a2016-11-24 16:12:44 +0000137 * {@link UserManager#DISALLOW_REMOVE_USER} and
138 * {@link UserManager#DISALLOW_REMOVE_MANAGED_PROFILE} and does not require the
Nicolas Prevotdf1b87d2016-10-25 13:57:08 +0100139 * {@link android.Manifest.permission#MANAGE_USERS} permission.
140 */
141 public abstract boolean removeUserEvenWhenDisallowed(int userId);
142
143 /**
Fyodor Kupolov6c915ea2016-05-09 19:10:53 -0700144 * Return whether the given user is running in an
Amith Yamasaniea1b9d72016-05-27 15:57:38 +0000145 * {@code UserState.STATE_RUNNING_UNLOCKING} or
146 * {@code UserState.STATE_RUNNING_UNLOCKED} state.
Fyodor Kupolov6c915ea2016-05-09 19:10:53 -0700147 */
148 public abstract boolean isUserUnlockingOrUnlocked(int userId);
149
150 /**
Fyodor Kupolov2e7e0962016-12-01 18:09:17 -0800151 * Return whether the given user is running in an
152 * {@code UserState.STATE_RUNNING_UNLOCKED} state.
153 */
154 public abstract boolean isUserUnlocked(int userId);
155
156 /**
Amith Yamasaniea1b9d72016-05-27 15:57:38 +0000157 * Return whether the given user is running
Fyodor Kupolov6c915ea2016-05-09 19:10:53 -0700158 */
Amith Yamasaniea1b9d72016-05-27 15:57:38 +0000159 public abstract boolean isUserRunning(int userId);
160
161 /**
162 * Set user's running state
163 */
164 public abstract void setUserState(int userId, int userState);
165
166 /**
167 * Remove user's running state
168 */
169 public abstract void removeUserState(int userId);
Michael Wachenschwanz3f2b6552017-05-15 13:53:09 -0700170
171 /**
172 * Returns an array of user ids. This array is cached in UserManagerService and passed as a
173 * reference, so do not modify the returned array.
174 *
175 * @return the array of user ids.
176 */
177 public abstract int[] getUserIds();
Makoto Onuki068c54a2015-10-13 14:34:03 -0700178}