Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 com.android.server; |
| 18 | |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 19 | import com.android.internal.os.storage.ExternalStorageFormatter; |
Dianne Hackborn | 2269d157 | 2010-02-24 19:54:22 -0800 | [diff] [blame] | 20 | import com.android.internal.util.FastXmlSerializer; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 21 | import com.android.internal.util.JournaledFile; |
Dianne Hackborn | 2269d157 | 2010-02-24 19:54:22 -0800 | [diff] [blame] | 22 | import com.android.internal.util.XmlUtils; |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 23 | import com.android.internal.widget.LockPatternUtils; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 24 | |
| 25 | import org.xmlpull.v1.XmlPullParser; |
| 26 | import org.xmlpull.v1.XmlPullParserException; |
| 27 | import org.xmlpull.v1.XmlSerializer; |
| 28 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 29 | import android.app.Activity; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 30 | import android.app.ActivityManagerNative; |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 31 | import android.app.AlarmManager; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 32 | import android.app.AppGlobals; |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 33 | import android.app.PendingIntent; |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 34 | import android.app.admin.DeviceAdminInfo; |
| 35 | import android.app.admin.DeviceAdminReceiver; |
| 36 | import android.app.admin.DevicePolicyManager; |
| 37 | import android.app.admin.IDevicePolicyManager; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 38 | import android.content.BroadcastReceiver; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 39 | import android.content.ComponentName; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 40 | import android.content.ContentResolver; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 41 | import android.content.Context; |
| 42 | import android.content.Intent; |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 43 | import android.content.IntentFilter; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 44 | import android.content.pm.IPackageManager; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 45 | import android.content.pm.PackageManager; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 46 | import android.content.pm.PackageManager.NameNotFoundException; |
Andy Stadler | 1f35d48 | 2010-11-19 15:39:41 -0800 | [diff] [blame] | 47 | import android.content.pm.ResolveInfo; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 48 | import android.os.Binder; |
Ben Komalo | ed48c8b | 2011-10-17 17:30:21 -0700 | [diff] [blame] | 49 | import android.os.Environment; |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 50 | import android.os.Handler; |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 51 | import android.os.IBinder; |
| 52 | import android.os.IPowerManager; |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 53 | import android.os.PowerManager; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 54 | import android.os.Process; |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 55 | import android.os.RecoverySystem; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 56 | import android.os.RemoteCallback; |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 57 | import android.os.RemoteException; |
| 58 | import android.os.ServiceManager; |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 59 | import android.os.SystemClock; |
Andy Stadler | 0fe45de | 2011-01-20 16:35:09 -0800 | [diff] [blame] | 60 | import android.os.SystemProperties; |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 61 | import android.os.UserHandle; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 62 | import android.os.UserManager; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 63 | import android.provider.Settings; |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 64 | import android.util.PrintWriterPrinter; |
| 65 | import android.util.Printer; |
Andy Stadler | 1f35d48 | 2010-11-19 15:39:41 -0800 | [diff] [blame] | 66 | import android.util.Slog; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 67 | import android.util.SparseArray; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 68 | import android.util.Xml; |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 69 | import android.view.IWindowManager; |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 70 | import android.view.WindowManagerPolicy; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 71 | |
| 72 | import java.io.File; |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 73 | import java.io.FileDescriptor; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 74 | import java.io.FileInputStream; |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 75 | import java.io.FileNotFoundException; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 76 | import java.io.FileOutputStream; |
| 77 | import java.io.IOException; |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 78 | import java.io.PrintWriter; |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 79 | import java.text.DateFormat; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 80 | import java.util.ArrayList; |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 81 | import java.util.Date; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 82 | import java.util.HashMap; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 83 | import java.util.List; |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 84 | import java.util.Set; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Implementation of the device policy APIs. |
| 88 | */ |
| 89 | public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 90 | private static final String DEVICE_POLICIES_XML = "device_policies.xml"; |
| 91 | |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 92 | private static final String TAG = "DevicePolicyManagerService"; |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 93 | |
Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 94 | private static final int REQUEST_EXPIRE_PASSWORD = 5571; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 95 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 96 | private static final long MS_PER_DAY = 86400 * 1000; |
| 97 | |
| 98 | private static final long EXPIRATION_GRACE_PERIOD_MS = 5 * MS_PER_DAY; // 5 days, in ms |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 99 | |
| 100 | protected static final String ACTION_EXPIRED_PASSWORD_NOTIFICATION |
| 101 | = "com.android.server.ACTION_EXPIRED_PASSWORD_NOTIFICATION"; |
| 102 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 103 | private static final boolean DBG = false; |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 104 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 105 | final Context mContext; |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 106 | final PowerManager.WakeLock mWakeLock; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 107 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 108 | IPowerManager mIPowerManager; |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 109 | IWindowManager mIWindowManager; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 110 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 111 | public static class DevicePolicyData { |
| 112 | int mActivePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
| 113 | int mActivePasswordLength = 0; |
| 114 | int mActivePasswordUpperCase = 0; |
| 115 | int mActivePasswordLowerCase = 0; |
| 116 | int mActivePasswordLetters = 0; |
| 117 | int mActivePasswordNumeric = 0; |
| 118 | int mActivePasswordSymbols = 0; |
| 119 | int mActivePasswordNonLetter = 0; |
| 120 | int mFailedPasswordAttempts = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 121 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 122 | int mUserHandle;; |
| 123 | int mPasswordOwner = -1; |
| 124 | long mLastMaximumTimeToLock = -1; |
| 125 | |
| 126 | final HashMap<ComponentName, ActiveAdmin> mAdminMap |
| 127 | = new HashMap<ComponentName, ActiveAdmin>(); |
| 128 | final ArrayList<ActiveAdmin> mAdminList |
| 129 | = new ArrayList<ActiveAdmin>(); |
| 130 | |
| 131 | public DevicePolicyData(int userHandle) { |
| 132 | mUserHandle = userHandle; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | final SparseArray<DevicePolicyData> mUserData = new SparseArray<DevicePolicyData>(); |
| 137 | |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 138 | Handler mHandler = new Handler(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 139 | |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 140 | BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 141 | @Override |
| 142 | public void onReceive(Context context, Intent intent) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 143 | final String action = intent.getAction(); |
| 144 | final int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, |
| 145 | getSendingUserId()); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 146 | if (Intent.ACTION_BOOT_COMPLETED.equals(action) |
| 147 | || ACTION_EXPIRED_PASSWORD_NOTIFICATION.equals(action)) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 148 | Slog.v(TAG, "Sending password expiration notifications for action " + action |
| 149 | + " for user " + userHandle); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 150 | mHandler.post(new Runnable() { |
| 151 | public void run() { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 152 | handlePasswordExpirationNotification(getUserData(userHandle)); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 153 | } |
| 154 | }); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 155 | } else if (Intent.ACTION_USER_REMOVED.equals(action)) { |
| 156 | removeUserData(userHandle); |
| 157 | } else if (Intent.ACTION_USER_STARTED.equals(action) |
| 158 | || Intent.ACTION_PACKAGE_CHANGED.equals(action) |
| 159 | || Intent.ACTION_PACKAGE_REMOVED.equals(action) |
| 160 | || Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) { |
| 161 | |
| 162 | if (Intent.ACTION_USER_STARTED.equals(action)) { |
| 163 | // Reset the policy data |
| 164 | synchronized (DevicePolicyManagerService.this) { |
| 165 | mUserData.remove(userHandle); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | handlePackagesChanged(userHandle); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | }; |
| 173 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 174 | static class ActiveAdmin { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 175 | final DeviceAdminInfo info; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 176 | |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 177 | int passwordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 178 | |
| 179 | static final int DEF_MINIMUM_PASSWORD_LENGTH = 0; |
| 180 | int minimumPasswordLength = DEF_MINIMUM_PASSWORD_LENGTH; |
| 181 | |
| 182 | static final int DEF_PASSWORD_HISTORY_LENGTH = 0; |
| 183 | int passwordHistoryLength = DEF_PASSWORD_HISTORY_LENGTH; |
| 184 | |
| 185 | static final int DEF_MINIMUM_PASSWORD_UPPER_CASE = 0; |
| 186 | int minimumPasswordUpperCase = DEF_MINIMUM_PASSWORD_UPPER_CASE; |
| 187 | |
| 188 | static final int DEF_MINIMUM_PASSWORD_LOWER_CASE = 0; |
| 189 | int minimumPasswordLowerCase = DEF_MINIMUM_PASSWORD_LOWER_CASE; |
| 190 | |
| 191 | static final int DEF_MINIMUM_PASSWORD_LETTERS = 1; |
Dianne Hackborn | 2a10840 | 2011-05-26 11:45:00 -0700 | [diff] [blame] | 192 | int minimumPasswordLetters = DEF_MINIMUM_PASSWORD_LETTERS; |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 193 | |
| 194 | static final int DEF_MINIMUM_PASSWORD_NUMERIC = 1; |
| 195 | int minimumPasswordNumeric = DEF_MINIMUM_PASSWORD_NUMERIC; |
| 196 | |
| 197 | static final int DEF_MINIMUM_PASSWORD_SYMBOLS = 1; |
| 198 | int minimumPasswordSymbols = DEF_MINIMUM_PASSWORD_SYMBOLS; |
| 199 | |
| 200 | static final int DEF_MINIMUM_PASSWORD_NON_LETTER = 0; |
| 201 | int minimumPasswordNonLetter = DEF_MINIMUM_PASSWORD_NON_LETTER; |
| 202 | |
| 203 | static final long DEF_MAXIMUM_TIME_TO_UNLOCK = 0; |
| 204 | long maximumTimeToUnlock = DEF_MAXIMUM_TIME_TO_UNLOCK; |
| 205 | |
| 206 | static final int DEF_MAXIMUM_FAILED_PASSWORDS_FOR_WIPE = 0; |
| 207 | int maximumFailedPasswordsForWipe = DEF_MAXIMUM_FAILED_PASSWORDS_FOR_WIPE; |
| 208 | |
| 209 | static final long DEF_PASSWORD_EXPIRATION_TIMEOUT = 0; |
| 210 | long passwordExpirationTimeout = DEF_PASSWORD_EXPIRATION_TIMEOUT; |
| 211 | |
| 212 | static final long DEF_PASSWORD_EXPIRATION_DATE = 0; |
| 213 | long passwordExpirationDate = DEF_PASSWORD_EXPIRATION_DATE; |
| 214 | |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 215 | static final int DEF_KEYGUARD_FEATURES_DISABLED = 0; // none |
| 216 | int disabledKeyguardFeatures = DEF_KEYGUARD_FEATURES_DISABLED; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 217 | |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 218 | boolean encryptionRequested = false; |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 219 | boolean disableCamera = false; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 220 | |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 221 | // TODO: review implementation decisions with frameworks team |
| 222 | boolean specifiesGlobalProxy = false; |
| 223 | String globalProxySpec = null; |
| 224 | String globalProxyExclusionList = null; |
| 225 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 226 | ActiveAdmin(DeviceAdminInfo _info) { |
| 227 | info = _info; |
| 228 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 229 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 230 | int getUid() { return info.getActivityInfo().applicationInfo.uid; } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 231 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 232 | public UserHandle getUserHandle() { |
| 233 | return new UserHandle(UserHandle.getUserId(info.getActivityInfo().applicationInfo.uid)); |
| 234 | } |
| 235 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 236 | void writeToXml(XmlSerializer out) |
| 237 | throws IllegalArgumentException, IllegalStateException, IOException { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 238 | out.startTag(null, "policies"); |
| 239 | info.writePoliciesToXml(out); |
| 240 | out.endTag(null, "policies"); |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 241 | if (passwordQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { |
| 242 | out.startTag(null, "password-quality"); |
| 243 | out.attribute(null, "value", Integer.toString(passwordQuality)); |
| 244 | out.endTag(null, "password-quality"); |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 245 | if (minimumPasswordLength != DEF_MINIMUM_PASSWORD_LENGTH) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 246 | out.startTag(null, "min-password-length"); |
| 247 | out.attribute(null, "value", Integer.toString(minimumPasswordLength)); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 248 | out.endTag(null, "min-password-length"); |
| 249 | } |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 250 | if(passwordHistoryLength != DEF_PASSWORD_HISTORY_LENGTH) { |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 251 | out.startTag(null, "password-history-length"); |
| 252 | out.attribute(null, "value", Integer.toString(passwordHistoryLength)); |
| 253 | out.endTag(null, "password-history-length"); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 254 | } |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 255 | if (minimumPasswordUpperCase != DEF_MINIMUM_PASSWORD_UPPER_CASE) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 256 | out.startTag(null, "min-password-uppercase"); |
| 257 | out.attribute(null, "value", Integer.toString(minimumPasswordUpperCase)); |
| 258 | out.endTag(null, "min-password-uppercase"); |
| 259 | } |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 260 | if (minimumPasswordLowerCase != DEF_MINIMUM_PASSWORD_LOWER_CASE) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 261 | out.startTag(null, "min-password-lowercase"); |
| 262 | out.attribute(null, "value", Integer.toString(minimumPasswordLowerCase)); |
| 263 | out.endTag(null, "min-password-lowercase"); |
| 264 | } |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 265 | if (minimumPasswordLetters != DEF_MINIMUM_PASSWORD_LETTERS) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 266 | out.startTag(null, "min-password-letters"); |
| 267 | out.attribute(null, "value", Integer.toString(minimumPasswordLetters)); |
| 268 | out.endTag(null, "min-password-letters"); |
| 269 | } |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 270 | if (minimumPasswordNumeric != DEF_MINIMUM_PASSWORD_NUMERIC) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 271 | out.startTag(null, "min-password-numeric"); |
| 272 | out.attribute(null, "value", Integer.toString(minimumPasswordNumeric)); |
| 273 | out.endTag(null, "min-password-numeric"); |
| 274 | } |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 275 | if (minimumPasswordSymbols != DEF_MINIMUM_PASSWORD_SYMBOLS) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 276 | out.startTag(null, "min-password-symbols"); |
| 277 | out.attribute(null, "value", Integer.toString(minimumPasswordSymbols)); |
| 278 | out.endTag(null, "min-password-symbols"); |
| 279 | } |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 280 | if (minimumPasswordNonLetter > DEF_MINIMUM_PASSWORD_NON_LETTER) { |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 281 | out.startTag(null, "min-password-nonletter"); |
| 282 | out.attribute(null, "value", Integer.toString(minimumPasswordNonLetter)); |
| 283 | out.endTag(null, "min-password-nonletter"); |
| 284 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 285 | } |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 286 | if (maximumTimeToUnlock != DEF_MAXIMUM_TIME_TO_UNLOCK) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 287 | out.startTag(null, "max-time-to-unlock"); |
| 288 | out.attribute(null, "value", Long.toString(maximumTimeToUnlock)); |
| 289 | out.endTag(null, "max-time-to-unlock"); |
| 290 | } |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 291 | if (maximumFailedPasswordsForWipe != DEF_MAXIMUM_FAILED_PASSWORDS_FOR_WIPE) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 292 | out.startTag(null, "max-failed-password-wipe"); |
| 293 | out.attribute(null, "value", Integer.toString(maximumFailedPasswordsForWipe)); |
| 294 | out.endTag(null, "max-failed-password-wipe"); |
| 295 | } |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 296 | if (specifiesGlobalProxy) { |
| 297 | out.startTag(null, "specifies-global-proxy"); |
| 298 | out.attribute(null, "value", Boolean.toString(specifiesGlobalProxy)); |
| 299 | out.endTag(null, "specifies_global_proxy"); |
| 300 | if (globalProxySpec != null) { |
| 301 | out.startTag(null, "global-proxy-spec"); |
| 302 | out.attribute(null, "value", globalProxySpec); |
| 303 | out.endTag(null, "global-proxy-spec"); |
| 304 | } |
| 305 | if (globalProxyExclusionList != null) { |
| 306 | out.startTag(null, "global-proxy-exclusion-list"); |
| 307 | out.attribute(null, "value", globalProxyExclusionList); |
| 308 | out.endTag(null, "global-proxy-exclusion-list"); |
| 309 | } |
| 310 | } |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 311 | if (passwordExpirationTimeout != DEF_PASSWORD_EXPIRATION_TIMEOUT) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 312 | out.startTag(null, "password-expiration-timeout"); |
| 313 | out.attribute(null, "value", Long.toString(passwordExpirationTimeout)); |
| 314 | out.endTag(null, "password-expiration-timeout"); |
| 315 | } |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 316 | if (passwordExpirationDate != DEF_PASSWORD_EXPIRATION_DATE) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 317 | out.startTag(null, "password-expiration-date"); |
| 318 | out.attribute(null, "value", Long.toString(passwordExpirationDate)); |
| 319 | out.endTag(null, "password-expiration-date"); |
| 320 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 321 | if (encryptionRequested) { |
| 322 | out.startTag(null, "encryption-requested"); |
| 323 | out.attribute(null, "value", Boolean.toString(encryptionRequested)); |
| 324 | out.endTag(null, "encryption-requested"); |
| 325 | } |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 326 | if (disableCamera) { |
| 327 | out.startTag(null, "disable-camera"); |
| 328 | out.attribute(null, "value", Boolean.toString(disableCamera)); |
| 329 | out.endTag(null, "disable-camera"); |
| 330 | } |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 331 | if (disabledKeyguardFeatures != DEF_KEYGUARD_FEATURES_DISABLED) { |
| 332 | out.startTag(null, "disable-keyguard-features"); |
| 333 | out.attribute(null, "value", Integer.toString(disabledKeyguardFeatures)); |
| 334 | out.endTag(null, "disable-keyguard-features"); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 335 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 336 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 337 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 338 | void readFromXml(XmlPullParser parser) |
| 339 | throws XmlPullParserException, IOException { |
| 340 | int outerDepth = parser.getDepth(); |
| 341 | int type; |
| 342 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 343 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 344 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 345 | continue; |
| 346 | } |
| 347 | String tag = parser.getName(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 348 | if ("policies".equals(tag)) { |
| 349 | info.readPoliciesFromXml(parser); |
| 350 | } else if ("password-quality".equals(tag)) { |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 351 | passwordQuality = Integer.parseInt( |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 352 | parser.getAttributeValue(null, "value")); |
| 353 | } else if ("min-password-length".equals(tag)) { |
| 354 | minimumPasswordLength = Integer.parseInt( |
| 355 | parser.getAttributeValue(null, "value")); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 356 | } else if ("password-history-length".equals(tag)) { |
| 357 | passwordHistoryLength = Integer.parseInt( |
| 358 | parser.getAttributeValue(null, "value")); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 359 | } else if ("min-password-uppercase".equals(tag)) { |
| 360 | minimumPasswordUpperCase = Integer.parseInt( |
| 361 | parser.getAttributeValue(null, "value")); |
| 362 | } else if ("min-password-lowercase".equals(tag)) { |
| 363 | minimumPasswordLowerCase = Integer.parseInt( |
| 364 | parser.getAttributeValue(null, "value")); |
| 365 | } else if ("min-password-letters".equals(tag)) { |
| 366 | minimumPasswordLetters = Integer.parseInt( |
| 367 | parser.getAttributeValue(null, "value")); |
| 368 | } else if ("min-password-numeric".equals(tag)) { |
| 369 | minimumPasswordNumeric = Integer.parseInt( |
| 370 | parser.getAttributeValue(null, "value")); |
| 371 | } else if ("min-password-symbols".equals(tag)) { |
| 372 | minimumPasswordSymbols = Integer.parseInt( |
| 373 | parser.getAttributeValue(null, "value")); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 374 | } else if ("min-password-nonletter".equals(tag)) { |
| 375 | minimumPasswordNonLetter = Integer.parseInt( |
| 376 | parser.getAttributeValue(null, "value")); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 377 | } else if ("max-time-to-unlock".equals(tag)) { |
| 378 | maximumTimeToUnlock = Long.parseLong( |
| 379 | parser.getAttributeValue(null, "value")); |
| 380 | } else if ("max-failed-password-wipe".equals(tag)) { |
| 381 | maximumFailedPasswordsForWipe = Integer.parseInt( |
| 382 | parser.getAttributeValue(null, "value")); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 383 | } else if ("specifies-global-proxy".equals(tag)) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 384 | specifiesGlobalProxy = Boolean.parseBoolean( |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 385 | parser.getAttributeValue(null, "value")); |
| 386 | } else if ("global-proxy-spec".equals(tag)) { |
| 387 | globalProxySpec = |
| 388 | parser.getAttributeValue(null, "value"); |
| 389 | } else if ("global-proxy-exclusion-list".equals(tag)) { |
| 390 | globalProxyExclusionList = |
| 391 | parser.getAttributeValue(null, "value"); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 392 | } else if ("password-expiration-timeout".equals(tag)) { |
| 393 | passwordExpirationTimeout = Long.parseLong( |
| 394 | parser.getAttributeValue(null, "value")); |
| 395 | } else if ("password-expiration-date".equals(tag)) { |
| 396 | passwordExpirationDate = Long.parseLong( |
| 397 | parser.getAttributeValue(null, "value")); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 398 | } else if ("encryption-requested".equals(tag)) { |
| 399 | encryptionRequested = Boolean.parseBoolean( |
| 400 | parser.getAttributeValue(null, "value")); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 401 | } else if ("disable-camera".equals(tag)) { |
| 402 | disableCamera = Boolean.parseBoolean( |
| 403 | parser.getAttributeValue(null, "value")); |
Amith Yamasani | 7077b3c | 2012-10-04 10:28:50 -0700 | [diff] [blame] | 404 | } else if ("disable-keyguard-features".equals(tag)) { |
| 405 | disabledKeyguardFeatures = Integer.parseInt( |
| 406 | parser.getAttributeValue(null, "value")); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 407 | } else { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 408 | Slog.w(TAG, "Unknown admin tag: " + tag); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 409 | } |
| 410 | XmlUtils.skipCurrentTag(parser); |
| 411 | } |
| 412 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 413 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 414 | void dump(String prefix, PrintWriter pw) { |
| 415 | pw.print(prefix); pw.print("uid="); pw.println(getUid()); |
| 416 | pw.print(prefix); pw.println("policies:"); |
| 417 | ArrayList<DeviceAdminInfo.PolicyInfo> pols = info.getUsedPolicies(); |
| 418 | if (pols != null) { |
| 419 | for (int i=0; i<pols.size(); i++) { |
| 420 | pw.print(prefix); pw.print(" "); pw.println(pols.get(i).tag); |
| 421 | } |
| 422 | } |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 423 | pw.print(prefix); pw.print("passwordQuality=0x"); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 424 | pw.println(Integer.toHexString(passwordQuality)); |
| 425 | pw.print(prefix); pw.print("minimumPasswordLength="); |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 426 | pw.println(minimumPasswordLength); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 427 | pw.print(prefix); pw.print("passwordHistoryLength="); |
| 428 | pw.println(passwordHistoryLength); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 429 | pw.print(prefix); pw.print("minimumPasswordUpperCase="); |
| 430 | pw.println(minimumPasswordUpperCase); |
| 431 | pw.print(prefix); pw.print("minimumPasswordLowerCase="); |
| 432 | pw.println(minimumPasswordLowerCase); |
| 433 | pw.print(prefix); pw.print("minimumPasswordLetters="); |
| 434 | pw.println(minimumPasswordLetters); |
| 435 | pw.print(prefix); pw.print("minimumPasswordNumeric="); |
| 436 | pw.println(minimumPasswordNumeric); |
| 437 | pw.print(prefix); pw.print("minimumPasswordSymbols="); |
| 438 | pw.println(minimumPasswordSymbols); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 439 | pw.print(prefix); pw.print("minimumPasswordNonLetter="); |
| 440 | pw.println(minimumPasswordNonLetter); |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 441 | pw.print(prefix); pw.print("maximumTimeToUnlock="); |
| 442 | pw.println(maximumTimeToUnlock); |
| 443 | pw.print(prefix); pw.print("maximumFailedPasswordsForWipe="); |
| 444 | pw.println(maximumFailedPasswordsForWipe); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 445 | pw.print(prefix); pw.print("specifiesGlobalProxy="); |
| 446 | pw.println(specifiesGlobalProxy); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 447 | pw.print(prefix); pw.print("passwordExpirationTimeout="); |
| 448 | pw.println(passwordExpirationTimeout); |
| 449 | pw.print(prefix); pw.print("passwordExpirationDate="); |
| 450 | pw.println(passwordExpirationDate); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 451 | if (globalProxySpec != null) { |
| 452 | pw.print(prefix); pw.print("globalProxySpec="); |
| 453 | pw.println(globalProxySpec); |
| 454 | } |
| 455 | if (globalProxyExclusionList != null) { |
| 456 | pw.print(prefix); pw.print("globalProxyEclusionList="); |
| 457 | pw.println(globalProxyExclusionList); |
| 458 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 459 | pw.print(prefix); pw.print("encryptionRequested="); |
| 460 | pw.println(encryptionRequested); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 461 | pw.print(prefix); pw.print("disableCamera="); |
| 462 | pw.println(disableCamera); |
Amith Yamasani | 7077b3c | 2012-10-04 10:28:50 -0700 | [diff] [blame] | 463 | pw.print(prefix); pw.print("disabledKeyguardFeatures="); |
| 464 | pw.println(disabledKeyguardFeatures); |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 465 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 466 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 467 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 468 | private void handlePackagesChanged(int userHandle) { |
| 469 | boolean removed = false; |
| 470 | Slog.d(TAG, "Handling package changes for user " + userHandle); |
| 471 | DevicePolicyData policy = getUserData(userHandle); |
| 472 | IPackageManager pm = AppGlobals.getPackageManager(); |
| 473 | for (int i = policy.mAdminList.size() - 1; i >= 0; i--) { |
| 474 | ActiveAdmin aa = policy.mAdminList.get(i); |
| 475 | try { |
| 476 | if (pm.getPackageInfo(aa.info.getPackageName(), 0, userHandle) == null |
| 477 | || pm.getReceiverInfo(aa.info.getComponent(), 0, userHandle) == null) { |
| 478 | removed = true; |
| 479 | policy.mAdminList.remove(i); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 480 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 481 | } catch (RemoteException re) { |
| 482 | // Shouldn't happen |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 483 | } |
| 484 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 485 | if (removed) { |
| 486 | validatePasswordOwnerLocked(policy); |
| 487 | syncDeviceCapabilitiesLocked(policy); |
| 488 | saveSettingsLocked(policy.mUserHandle); |
| 489 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 490 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 491 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 492 | /** |
| 493 | * Instantiates the service. |
| 494 | */ |
| 495 | public DevicePolicyManagerService(Context context) { |
| 496 | mContext = context; |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 497 | mWakeLock = ((PowerManager)context.getSystemService(Context.POWER_SERVICE)) |
| 498 | .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DPM"); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 499 | IntentFilter filter = new IntentFilter(); |
| 500 | filter.addAction(Intent.ACTION_BOOT_COMPLETED); |
| 501 | filter.addAction(ACTION_EXPIRED_PASSWORD_NOTIFICATION); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 502 | filter.addAction(Intent.ACTION_USER_REMOVED); |
| 503 | filter.addAction(Intent.ACTION_USER_STARTED); |
| 504 | context.registerReceiverAsUser(mReceiver, UserHandle.ALL, filter, null, mHandler); |
| 505 | filter = new IntentFilter(); |
| 506 | filter.addAction(Intent.ACTION_PACKAGE_CHANGED); |
| 507 | filter.addAction(Intent.ACTION_PACKAGE_REMOVED); |
| 508 | filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); |
| 509 | filter.addDataScheme("package"); |
| 510 | context.registerReceiverAsUser(mReceiver, UserHandle.ALL, filter, null, mHandler); |
| 511 | } |
| 512 | |
| 513 | /** |
| 514 | * Creates and loads the policy data from xml. |
| 515 | * @param userHandle the user for whom to load the policy data |
| 516 | * @return |
| 517 | */ |
| 518 | DevicePolicyData getUserData(int userHandle) { |
| 519 | synchronized (this) { |
| 520 | DevicePolicyData policy = mUserData.get(userHandle); |
| 521 | if (policy == null) { |
| 522 | policy = new DevicePolicyData(userHandle); |
| 523 | mUserData.append(userHandle, policy); |
| 524 | loadSettingsLocked(policy, userHandle); |
| 525 | } |
| 526 | return policy; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | void removeUserData(int userHandle) { |
| 531 | synchronized (this) { |
| 532 | if (userHandle == UserHandle.USER_OWNER) { |
| 533 | Slog.w(TAG, "Tried to remove device policy file for user 0! Ignoring."); |
| 534 | return; |
| 535 | } |
| 536 | DevicePolicyData policy = mUserData.get(userHandle); |
| 537 | if (policy != null) { |
| 538 | mUserData.remove(userHandle); |
| 539 | } |
| 540 | File policyFile = new File(Environment.getUserSystemDirectory(userHandle), |
| 541 | DEVICE_POLICIES_XML); |
| 542 | policyFile.delete(); |
| 543 | Slog.i(TAG, "Removed device policy file " + policyFile.getAbsolutePath()); |
| 544 | } |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 545 | } |
| 546 | |
Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 547 | /** |
| 548 | * Set an alarm for an upcoming event - expiration warning, expiration, or post-expiration |
| 549 | * reminders. Clears alarm if no expirations are configured. |
| 550 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 551 | protected void setExpirationAlarmCheckLocked(Context context, DevicePolicyData policy) { |
| 552 | final long expiration = getPasswordExpirationLocked(null, policy.mUserHandle); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 553 | final long now = System.currentTimeMillis(); |
| 554 | final long timeToExpire = expiration - now; |
| 555 | final long alarmTime; |
Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 556 | if (expiration == 0) { |
| 557 | // No expirations are currently configured: Cancel alarm. |
| 558 | alarmTime = 0; |
| 559 | } else if (timeToExpire <= 0) { |
| 560 | // The password has already expired: Repeat every 24 hours. |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 561 | alarmTime = now + MS_PER_DAY; |
Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 562 | } else { |
| 563 | // Selecting the next alarm time: Roll forward to the next 24 hour multiple before |
| 564 | // the expiration time. |
| 565 | long alarmInterval = timeToExpire % MS_PER_DAY; |
| 566 | if (alarmInterval == 0) { |
| 567 | alarmInterval = MS_PER_DAY; |
| 568 | } |
| 569 | alarmTime = now + alarmInterval; |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 570 | } |
| 571 | |
Andy Stadler | 1f35d48 | 2010-11-19 15:39:41 -0800 | [diff] [blame] | 572 | long token = Binder.clearCallingIdentity(); |
| 573 | try { |
| 574 | AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 575 | PendingIntent pi = PendingIntent.getBroadcastAsUser(context, REQUEST_EXPIRE_PASSWORD, |
Andy Stadler | 1f35d48 | 2010-11-19 15:39:41 -0800 | [diff] [blame] | 576 | new Intent(ACTION_EXPIRED_PASSWORD_NOTIFICATION), |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 577 | PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT, |
| 578 | new UserHandle(policy.mUserHandle)); |
Andy Stadler | 1f35d48 | 2010-11-19 15:39:41 -0800 | [diff] [blame] | 579 | am.cancel(pi); |
Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 580 | if (alarmTime != 0) { |
| 581 | am.set(AlarmManager.RTC, alarmTime, pi); |
| 582 | } |
Andy Stadler | 1f35d48 | 2010-11-19 15:39:41 -0800 | [diff] [blame] | 583 | } finally { |
| 584 | Binder.restoreCallingIdentity(token); |
| 585 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 586 | } |
| 587 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 588 | private IPowerManager getIPowerManager() { |
| 589 | if (mIPowerManager == null) { |
| 590 | IBinder b = ServiceManager.getService(Context.POWER_SERVICE); |
| 591 | mIPowerManager = IPowerManager.Stub.asInterface(b); |
| 592 | } |
| 593 | return mIPowerManager; |
| 594 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 595 | |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 596 | private IWindowManager getWindowManager() { |
| 597 | if (mIWindowManager == null) { |
| 598 | IBinder b = ServiceManager.getService(Context.WINDOW_SERVICE); |
| 599 | mIWindowManager = IWindowManager.Stub.asInterface(b); |
| 600 | } |
| 601 | return mIWindowManager; |
| 602 | } |
| 603 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 604 | ActiveAdmin getActiveAdminUncheckedLocked(ComponentName who, int userHandle) { |
| 605 | ActiveAdmin admin = getUserData(userHandle).mAdminMap.get(who); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 606 | if (admin != null |
| 607 | && who.getPackageName().equals(admin.info.getActivityInfo().packageName) |
| 608 | && who.getClassName().equals(admin.info.getActivityInfo().name)) { |
| 609 | return admin; |
| 610 | } |
| 611 | return null; |
| 612 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 613 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 614 | ActiveAdmin getActiveAdminForCallerLocked(ComponentName who, int reqPolicy) |
| 615 | throws SecurityException { |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 616 | final int callingUid = Binder.getCallingUid(); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 617 | final int userHandle = UserHandle.getUserId(callingUid); |
| 618 | final DevicePolicyData policy = getUserData(userHandle); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 619 | if (who != null) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 620 | ActiveAdmin admin = policy.mAdminMap.get(who); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 621 | if (admin == null) { |
| 622 | throw new SecurityException("No active admin " + who); |
| 623 | } |
| 624 | if (admin.getUid() != callingUid) { |
| 625 | throw new SecurityException("Admin " + who + " is not owned by uid " |
| 626 | + Binder.getCallingUid()); |
| 627 | } |
| 628 | if (!admin.info.usesPolicy(reqPolicy)) { |
| 629 | throw new SecurityException("Admin " + admin.info.getComponent() |
| 630 | + " did not specify uses-policy for: " |
| 631 | + admin.info.getTagForPolicy(reqPolicy)); |
| 632 | } |
| 633 | return admin; |
| 634 | } else { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 635 | final int N = policy.mAdminList.size(); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 636 | for (int i=0; i<N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 637 | ActiveAdmin admin = policy.mAdminList.get(i); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 638 | if (admin.getUid() == callingUid && admin.info.usesPolicy(reqPolicy)) { |
| 639 | return admin; |
| 640 | } |
| 641 | } |
| 642 | throw new SecurityException("No active admin owned by uid " |
| 643 | + Binder.getCallingUid() + " for policy #" + reqPolicy); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 644 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 645 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 646 | |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 647 | void sendAdminCommandLocked(ActiveAdmin admin, String action) { |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 648 | sendAdminCommandLocked(admin, action, null); |
| 649 | } |
| 650 | |
| 651 | void sendAdminCommandLocked(ActiveAdmin admin, String action, BroadcastReceiver result) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 652 | Intent intent = new Intent(action); |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 653 | intent.setComponent(admin.info.getComponent()); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 654 | if (action.equals(DeviceAdminReceiver.ACTION_PASSWORD_EXPIRING)) { |
| 655 | intent.putExtra("expiration", admin.passwordExpirationDate); |
| 656 | } |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 657 | if (result != null) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 658 | mContext.sendOrderedBroadcastAsUser(intent, admin.getUserHandle(), |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 659 | null, result, mHandler, Activity.RESULT_OK, null, null); |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 660 | } else { |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 661 | mContext.sendBroadcastAsUser(intent, UserHandle.OWNER); |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 662 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 663 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 664 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 665 | void sendAdminCommandLocked(String action, int reqPolicy, int userHandle) { |
| 666 | final DevicePolicyData policy = getUserData(userHandle); |
| 667 | final int count = policy.mAdminList.size(); |
| 668 | if (count > 0) { |
| 669 | for (int i = 0; i < count; i++) { |
| 670 | ActiveAdmin admin = policy.mAdminList.get(i); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 671 | if (admin.info.usesPolicy(reqPolicy)) { |
| 672 | sendAdminCommandLocked(admin, action); |
| 673 | } |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 674 | } |
Dianne Hackborn | 4141d03 | 2010-01-21 16:29:00 -0800 | [diff] [blame] | 675 | } |
| 676 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 677 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 678 | void removeActiveAdminLocked(final ComponentName adminReceiver, int userHandle) { |
| 679 | final ActiveAdmin admin = getActiveAdminUncheckedLocked(adminReceiver, userHandle); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 680 | if (admin != null) { |
| 681 | sendAdminCommandLocked(admin, |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 682 | DeviceAdminReceiver.ACTION_DEVICE_ADMIN_DISABLED, |
| 683 | new BroadcastReceiver() { |
| 684 | @Override |
| 685 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 2fe8fb2 | 2012-06-15 17:05:25 -0700 | [diff] [blame] | 686 | synchronized (DevicePolicyManagerService.this) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 687 | int userHandle = admin.getUserHandle().getIdentifier(); |
| 688 | DevicePolicyData policy = getUserData(userHandle); |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 689 | boolean doProxyCleanup = admin.info.usesPolicy( |
| 690 | DeviceAdminInfo.USES_POLICY_SETS_GLOBAL_PROXY); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 691 | policy.mAdminList.remove(admin); |
| 692 | policy.mAdminMap.remove(adminReceiver); |
| 693 | validatePasswordOwnerLocked(policy); |
| 694 | syncDeviceCapabilitiesLocked(policy); |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 695 | if (doProxyCleanup) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 696 | resetGlobalProxyLocked(getUserData(userHandle)); |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 697 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 698 | saveSettingsLocked(userHandle); |
| 699 | updateMaximumTimeToLockLocked(policy); |
Dianne Hackborn | d998acb | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 700 | } |
| 701 | } |
| 702 | }); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 703 | } |
| 704 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 705 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 706 | public DeviceAdminInfo findAdmin(ComponentName adminName, int userHandle) { |
| 707 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 708 | Intent resolveIntent = new Intent(); |
| 709 | resolveIntent.setComponent(adminName); |
| 710 | List<ResolveInfo> infos = mContext.getPackageManager().queryBroadcastReceivers( |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 711 | resolveIntent, PackageManager.GET_META_DATA, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 712 | if (infos == null || infos.size() <= 0) { |
| 713 | throw new IllegalArgumentException("Unknown admin: " + adminName); |
| 714 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 715 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 716 | try { |
| 717 | return new DeviceAdminInfo(mContext, infos.get(0)); |
| 718 | } catch (XmlPullParserException e) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 719 | Slog.w(TAG, "Bad device admin requested for user=" + userHandle + ": " + adminName, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 720 | return null; |
| 721 | } catch (IOException e) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 722 | Slog.w(TAG, "Bad device admin requested for user=" + userHandle + ": " + adminName, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 723 | return null; |
| 724 | } |
| 725 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 726 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 727 | private static JournaledFile makeJournaledFile(int userHandle) { |
| 728 | final String base = userHandle == 0 |
| 729 | ? "/data/system/" + DEVICE_POLICIES_XML |
| 730 | : new File(Environment.getUserSystemDirectory(userHandle), DEVICE_POLICIES_XML) |
| 731 | .getAbsolutePath(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 732 | return new JournaledFile(new File(base), new File(base + ".tmp")); |
| 733 | } |
| 734 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 735 | private void saveSettingsLocked(int userHandle) { |
| 736 | DevicePolicyData policy = getUserData(userHandle); |
| 737 | JournaledFile journal = makeJournaledFile(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 738 | FileOutputStream stream = null; |
| 739 | try { |
| 740 | stream = new FileOutputStream(journal.chooseForWrite(), false); |
| 741 | XmlSerializer out = new FastXmlSerializer(); |
| 742 | out.setOutput(stream, "utf-8"); |
| 743 | out.startDocument(null, true); |
| 744 | |
| 745 | out.startTag(null, "policies"); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 746 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 747 | final int N = policy.mAdminList.size(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 748 | for (int i=0; i<N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 749 | ActiveAdmin ap = policy.mAdminList.get(i); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 750 | if (ap != null) { |
| 751 | out.startTag(null, "admin"); |
| 752 | out.attribute(null, "name", ap.info.getComponent().flattenToString()); |
| 753 | ap.writeToXml(out); |
| 754 | out.endTag(null, "admin"); |
| 755 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 756 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 757 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 758 | if (policy.mPasswordOwner >= 0) { |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 759 | out.startTag(null, "password-owner"); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 760 | out.attribute(null, "value", Integer.toString(policy.mPasswordOwner)); |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 761 | out.endTag(null, "password-owner"); |
| 762 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 763 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 764 | if (policy.mFailedPasswordAttempts != 0) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 765 | out.startTag(null, "failed-password-attempts"); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 766 | out.attribute(null, "value", Integer.toString(policy.mFailedPasswordAttempts)); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 767 | out.endTag(null, "failed-password-attempts"); |
| 768 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 769 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 770 | if (policy.mActivePasswordQuality != 0 || policy.mActivePasswordLength != 0 |
| 771 | || policy.mActivePasswordUpperCase != 0 || policy.mActivePasswordLowerCase != 0 |
| 772 | || policy.mActivePasswordLetters != 0 || policy.mActivePasswordNumeric != 0 |
| 773 | || policy.mActivePasswordSymbols != 0 || policy.mActivePasswordNonLetter != 0) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 774 | out.startTag(null, "active-password"); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 775 | out.attribute(null, "quality", Integer.toString(policy.mActivePasswordQuality)); |
| 776 | out.attribute(null, "length", Integer.toString(policy.mActivePasswordLength)); |
| 777 | out.attribute(null, "uppercase", Integer.toString(policy.mActivePasswordUpperCase)); |
| 778 | out.attribute(null, "lowercase", Integer.toString(policy.mActivePasswordLowerCase)); |
| 779 | out.attribute(null, "letters", Integer.toString(policy.mActivePasswordLetters)); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 780 | out.attribute(null, "numeric", Integer |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 781 | .toString(policy.mActivePasswordNumeric)); |
| 782 | out.attribute(null, "symbols", Integer.toString(policy.mActivePasswordSymbols)); |
| 783 | out.attribute(null, "nonletter", Integer.toString(policy.mActivePasswordNonLetter)); |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 784 | out.endTag(null, "active-password"); |
| 785 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 786 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 787 | out.endTag(null, "policies"); |
| 788 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 789 | out.endDocument(); |
| 790 | stream.close(); |
| 791 | journal.commit(); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 792 | sendChangedNotification(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 793 | } catch (IOException e) { |
| 794 | try { |
| 795 | if (stream != null) { |
| 796 | stream.close(); |
| 797 | } |
| 798 | } catch (IOException ex) { |
| 799 | // Ignore |
| 800 | } |
| 801 | journal.rollback(); |
| 802 | } |
| 803 | } |
| 804 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 805 | private void sendChangedNotification(int userHandle) { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 806 | Intent intent = new Intent(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 807 | intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
Amith Yamasani | b7a6859 | 2012-09-10 10:24:36 -0700 | [diff] [blame] | 808 | long ident = Binder.clearCallingIdentity(); |
| 809 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 810 | mContext.sendBroadcastAsUser(intent, new UserHandle(userHandle)); |
Amith Yamasani | b7a6859 | 2012-09-10 10:24:36 -0700 | [diff] [blame] | 811 | } finally { |
| 812 | Binder.restoreCallingIdentity(ident); |
| 813 | } |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 816 | private void loadSettingsLocked(DevicePolicyData policy, int userHandle) { |
| 817 | JournaledFile journal = makeJournaledFile(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 818 | FileInputStream stream = null; |
| 819 | File file = journal.chooseForRead(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 820 | try { |
| 821 | stream = new FileInputStream(file); |
| 822 | XmlPullParser parser = Xml.newPullParser(); |
| 823 | parser.setInput(stream, null); |
| 824 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 825 | int type; |
| 826 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 827 | && type != XmlPullParser.START_TAG) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 828 | } |
| 829 | String tag = parser.getName(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 830 | if (!"policies".equals(tag)) { |
| 831 | throw new XmlPullParserException( |
| 832 | "Settings do not start with policies tag: found " + tag); |
| 833 | } |
| 834 | type = parser.next(); |
| 835 | int outerDepth = parser.getDepth(); |
| 836 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 837 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 838 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 839 | continue; |
| 840 | } |
| 841 | tag = parser.getName(); |
| 842 | if ("admin".equals(tag)) { |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 843 | String name = parser.getAttributeValue(null, "name"); |
| 844 | try { |
| 845 | DeviceAdminInfo dai = findAdmin( |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 846 | ComponentName.unflattenFromString(name), userHandle); |
| 847 | if (DBG && (UserHandle.getUserId(dai.getActivityInfo().applicationInfo.uid) |
| 848 | != userHandle)) { |
| 849 | Slog.w(TAG, "findAdmin returned an incorrect uid " |
| 850 | + dai.getActivityInfo().applicationInfo.uid + " for user " |
| 851 | + userHandle); |
| 852 | } |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 853 | if (dai != null) { |
| 854 | ActiveAdmin ap = new ActiveAdmin(dai); |
| 855 | ap.readFromXml(parser); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 856 | policy.mAdminMap.put(ap.info.getComponent(), ap); |
| 857 | policy.mAdminList.add(ap); |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 858 | } |
| 859 | } catch (RuntimeException e) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 860 | Slog.w(TAG, "Failed loading admin " + name, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 861 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 862 | } else if ("failed-password-attempts".equals(tag)) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 863 | policy.mFailedPasswordAttempts = Integer.parseInt( |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 864 | parser.getAttributeValue(null, "value")); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 865 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 866 | } else if ("password-owner".equals(tag)) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 867 | policy.mPasswordOwner = Integer.parseInt( |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 868 | parser.getAttributeValue(null, "value")); |
| 869 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 870 | } else if ("active-password".equals(tag)) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 871 | policy.mActivePasswordQuality = Integer.parseInt( |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 872 | parser.getAttributeValue(null, "quality")); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 873 | policy.mActivePasswordLength = Integer.parseInt( |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 874 | parser.getAttributeValue(null, "length")); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 875 | policy.mActivePasswordUpperCase = Integer.parseInt( |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 876 | parser.getAttributeValue(null, "uppercase")); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 877 | policy.mActivePasswordLowerCase = Integer.parseInt( |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 878 | parser.getAttributeValue(null, "lowercase")); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 879 | policy.mActivePasswordLetters = Integer.parseInt( |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 880 | parser.getAttributeValue(null, "letters")); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 881 | policy.mActivePasswordNumeric = Integer.parseInt( |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 882 | parser.getAttributeValue(null, "numeric")); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 883 | policy.mActivePasswordSymbols = Integer.parseInt( |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 884 | parser.getAttributeValue(null, "symbols")); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 885 | policy.mActivePasswordNonLetter = Integer.parseInt( |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 886 | parser.getAttributeValue(null, "nonletter")); |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 887 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 888 | } else { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 889 | Slog.w(TAG, "Unknown tag: " + tag); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 890 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 891 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 892 | } |
| 893 | } catch (NullPointerException e) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 894 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 895 | } catch (NumberFormatException e) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 896 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 897 | } catch (XmlPullParserException e) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 898 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 899 | } catch (FileNotFoundException e) { |
| 900 | // Don't be noisy, this is normal if we haven't defined any policies. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 901 | } catch (IOException e) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 902 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 903 | } catch (IndexOutOfBoundsException e) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 904 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 905 | } |
| 906 | try { |
| 907 | if (stream != null) { |
| 908 | stream.close(); |
| 909 | } |
| 910 | } catch (IOException e) { |
| 911 | // Ignore |
| 912 | } |
| 913 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 914 | // Validate that what we stored for the password quality matches |
| 915 | // sufficiently what is currently set. Note that this is only |
| 916 | // a sanity check in case the two get out of sync; this should |
| 917 | // never normally happen. |
| 918 | LockPatternUtils utils = new LockPatternUtils(mContext); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 919 | if (utils.getActivePasswordQuality() < policy.mActivePasswordQuality) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 920 | Slog.w(TAG, "Active password quality 0x" |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 921 | + Integer.toHexString(policy.mActivePasswordQuality) |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 922 | + " does not match actual quality 0x" |
| 923 | + Integer.toHexString(utils.getActivePasswordQuality())); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 924 | policy.mActivePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
| 925 | policy.mActivePasswordLength = 0; |
| 926 | policy.mActivePasswordUpperCase = 0; |
| 927 | policy.mActivePasswordLowerCase = 0; |
| 928 | policy.mActivePasswordLetters = 0; |
| 929 | policy.mActivePasswordNumeric = 0; |
| 930 | policy.mActivePasswordSymbols = 0; |
| 931 | policy.mActivePasswordNonLetter = 0; |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 932 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 933 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 934 | validatePasswordOwnerLocked(policy); |
| 935 | syncDeviceCapabilitiesLocked(policy); |
| 936 | updateMaximumTimeToLockLocked(policy); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 937 | } |
| 938 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 939 | static void validateQualityConstant(int quality) { |
| 940 | switch (quality) { |
| 941 | case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED: |
Danielle Millett | de7a2f3 | 2011-12-21 17:02:32 -0500 | [diff] [blame] | 942 | case DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK: |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 943 | case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: |
| 944 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: |
| 945 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: |
| 946 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 947 | case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX: |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 948 | return; |
| 949 | } |
| 950 | throw new IllegalArgumentException("Invalid quality constant: 0x" |
| 951 | + Integer.toHexString(quality)); |
| 952 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 953 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 954 | void validatePasswordOwnerLocked(DevicePolicyData policy) { |
| 955 | if (policy.mPasswordOwner >= 0) { |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 956 | boolean haveOwner = false; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 957 | for (int i = policy.mAdminList.size() - 1; i >= 0; i--) { |
| 958 | if (policy.mAdminList.get(i).getUid() == policy.mPasswordOwner) { |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 959 | haveOwner = true; |
| 960 | break; |
| 961 | } |
| 962 | } |
| 963 | if (!haveOwner) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 964 | Slog.w(TAG, "Previous password owner " + policy.mPasswordOwner |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 965 | + " no longer active; disabling"); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 966 | policy.mPasswordOwner = -1; |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 967 | } |
| 968 | } |
| 969 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 970 | |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 971 | /** |
| 972 | * Pushes down policy information to the system for any policies related to general device |
| 973 | * capabilities that need to be enforced by lower level services (e.g. Camera services). |
| 974 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 975 | void syncDeviceCapabilitiesLocked(DevicePolicyData policy) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 976 | // Ensure the status of the camera is synced down to the system. Interested native services |
| 977 | // should monitor this value and act accordingly. |
| 978 | boolean systemState = SystemProperties.getBoolean(SYSTEM_PROP_DISABLE_CAMERA, false); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 979 | boolean cameraDisabled = getCameraDisabled(null, policy.mUserHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 980 | if (cameraDisabled != systemState) { |
| 981 | long token = Binder.clearCallingIdentity(); |
| 982 | try { |
| 983 | String value = cameraDisabled ? "1" : "0"; |
| 984 | Slog.v(TAG, "Change in camera state [" |
| 985 | + SYSTEM_PROP_DISABLE_CAMERA + "] = " + value); |
| 986 | SystemProperties.set(SYSTEM_PROP_DISABLE_CAMERA, value); |
| 987 | } finally { |
| 988 | Binder.restoreCallingIdentity(token); |
| 989 | } |
| 990 | } |
| 991 | } |
| 992 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 993 | public void systemReady() { |
| 994 | synchronized (this) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 995 | loadSettingsLocked(getUserData(UserHandle.USER_OWNER), UserHandle.USER_OWNER); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 996 | } |
| 997 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 998 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 999 | private void handlePasswordExpirationNotification(DevicePolicyData policy) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1000 | synchronized (this) { |
| 1001 | final long now = System.currentTimeMillis(); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1002 | final int N = policy.mAdminList.size(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1003 | if (N <= 0) { |
| 1004 | return; |
| 1005 | } |
| 1006 | for (int i=0; i < N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1007 | ActiveAdmin admin = policy.mAdminList.get(i); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1008 | if (admin.info.usesPolicy(DeviceAdminInfo.USES_POLICY_EXPIRE_PASSWORD) |
| 1009 | && admin.passwordExpirationTimeout > 0L |
| 1010 | && admin.passwordExpirationDate > 0L |
Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 1011 | && now >= admin.passwordExpirationDate - EXPIRATION_GRACE_PERIOD_MS) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1012 | sendAdminCommandLocked(admin, DeviceAdminReceiver.ACTION_PASSWORD_EXPIRING); |
| 1013 | } |
| 1014 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1015 | setExpirationAlarmCheckLocked(mContext, policy); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1016 | } |
| 1017 | } |
| 1018 | |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1019 | /** |
| 1020 | * @param adminReceiver The admin to add |
| 1021 | * @param refreshing true = update an active admin, no error |
| 1022 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1023 | public void setActiveAdmin(ComponentName adminReceiver, boolean refreshing, int userHandle) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1024 | mContext.enforceCallingOrSelfPermission( |
| 1025 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1026 | enforceCrossUserPermission(userHandle); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1027 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1028 | DevicePolicyData policy = getUserData(userHandle); |
| 1029 | DeviceAdminInfo info = findAdmin(adminReceiver, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1030 | if (info == null) { |
| 1031 | throw new IllegalArgumentException("Bad admin: " + adminReceiver); |
| 1032 | } |
| 1033 | synchronized (this) { |
| 1034 | long ident = Binder.clearCallingIdentity(); |
| 1035 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1036 | if (!refreshing && getActiveAdminUncheckedLocked(adminReceiver, userHandle) != null) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1037 | throw new IllegalArgumentException("Admin is already added"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1038 | } |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1039 | ActiveAdmin newAdmin = new ActiveAdmin(info); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1040 | policy.mAdminMap.put(adminReceiver, newAdmin); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1041 | int replaceIndex = -1; |
| 1042 | if (refreshing) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1043 | final int N = policy.mAdminList.size(); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1044 | for (int i=0; i < N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1045 | ActiveAdmin oldAdmin = policy.mAdminList.get(i); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1046 | if (oldAdmin.info.getComponent().equals(adminReceiver)) { |
| 1047 | replaceIndex = i; |
| 1048 | break; |
| 1049 | } |
| 1050 | } |
| 1051 | } |
| 1052 | if (replaceIndex == -1) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1053 | policy.mAdminList.add(newAdmin); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1054 | } else { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1055 | policy.mAdminList.set(replaceIndex, newAdmin); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1056 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1057 | saveSettingsLocked(userHandle); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1058 | sendAdminCommandLocked(newAdmin, DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1059 | } finally { |
| 1060 | Binder.restoreCallingIdentity(ident); |
| 1061 | } |
| 1062 | } |
| 1063 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1064 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1065 | public boolean isAdminActive(ComponentName adminReceiver, int userHandle) { |
| 1066 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1067 | synchronized (this) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1068 | return getActiveAdminUncheckedLocked(adminReceiver, userHandle) != null; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1069 | } |
| 1070 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1071 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1072 | public boolean hasGrantedPolicy(ComponentName adminReceiver, int policyId, int userHandle) { |
| 1073 | enforceCrossUserPermission(userHandle); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1074 | synchronized (this) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1075 | ActiveAdmin administrator = getActiveAdminUncheckedLocked(adminReceiver, userHandle); |
Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1076 | if (administrator == null) { |
| 1077 | throw new SecurityException("No active admin " + adminReceiver); |
| 1078 | } |
| 1079 | return administrator.info.usesPolicy(policyId); |
| 1080 | } |
| 1081 | } |
| 1082 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1083 | public List<ComponentName> getActiveAdmins(int userHandle) { |
| 1084 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1085 | synchronized (this) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1086 | DevicePolicyData policy = getUserData(userHandle); |
| 1087 | final int N = policy.mAdminList.size(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1088 | if (N <= 0) { |
| 1089 | return null; |
| 1090 | } |
| 1091 | ArrayList<ComponentName> res = new ArrayList<ComponentName>(N); |
| 1092 | for (int i=0; i<N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1093 | res.add(policy.mAdminList.get(i).info.getComponent()); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1094 | } |
| 1095 | return res; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1096 | } |
| 1097 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1098 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1099 | public boolean packageHasActiveAdmins(String packageName, int userHandle) { |
| 1100 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1101 | synchronized (this) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1102 | DevicePolicyData policy = getUserData(userHandle); |
| 1103 | final int N = policy.mAdminList.size(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1104 | for (int i=0; i<N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1105 | if (policy.mAdminList.get(i).info.getPackageName().equals(packageName)) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1106 | return true; |
| 1107 | } |
| 1108 | } |
| 1109 | return false; |
| 1110 | } |
| 1111 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1112 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1113 | public void removeActiveAdmin(ComponentName adminReceiver, int userHandle) { |
| 1114 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1115 | synchronized (this) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1116 | ActiveAdmin admin = getActiveAdminUncheckedLocked(adminReceiver, userHandle); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1117 | if (admin == null) { |
| 1118 | return; |
| 1119 | } |
| 1120 | if (admin.getUid() != Binder.getCallingUid()) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1121 | mContext.enforceCallingOrSelfPermission( |
| 1122 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
| 1123 | } |
| 1124 | long ident = Binder.clearCallingIdentity(); |
| 1125 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1126 | removeActiveAdminLocked(adminReceiver, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1127 | } finally { |
| 1128 | Binder.restoreCallingIdentity(ident); |
| 1129 | } |
| 1130 | } |
| 1131 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1132 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1133 | public void setPasswordQuality(ComponentName who, int quality, int userHandle) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1134 | validateQualityConstant(quality); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1135 | enforceCrossUserPermission(userHandle); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1136 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1137 | synchronized (this) { |
| 1138 | if (who == null) { |
| 1139 | throw new NullPointerException("ComponentName is null"); |
| 1140 | } |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1141 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1142 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1143 | if (ap.passwordQuality != quality) { |
| 1144 | ap.passwordQuality = quality; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1145 | saveSettingsLocked(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1146 | } |
| 1147 | } |
| 1148 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1149 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1150 | public int getPasswordQuality(ComponentName who, int userHandle) { |
| 1151 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1152 | synchronized (this) { |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1153 | int mode = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1154 | DevicePolicyData policy = getUserData(userHandle); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1155 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1156 | if (who != null) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1157 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1158 | return admin != null ? admin.passwordQuality : mode; |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1159 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1160 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1161 | final int N = policy.mAdminList.size(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1162 | for (int i=0; i<N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1163 | ActiveAdmin admin = policy.mAdminList.get(i); |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1164 | if (mode < admin.passwordQuality) { |
| 1165 | mode = admin.passwordQuality; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | return mode; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1169 | } |
| 1170 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1171 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1172 | public void setPasswordMinimumLength(ComponentName who, int length, int userHandle) { |
| 1173 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1174 | synchronized (this) { |
| 1175 | if (who == null) { |
| 1176 | throw new NullPointerException("ComponentName is null"); |
| 1177 | } |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1178 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1179 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1180 | if (ap.minimumPasswordLength != length) { |
| 1181 | ap.minimumPasswordLength = length; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1182 | saveSettingsLocked(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1183 | } |
| 1184 | } |
| 1185 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1186 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1187 | public int getPasswordMinimumLength(ComponentName who, int userHandle) { |
| 1188 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1189 | synchronized (this) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1190 | DevicePolicyData policy = getUserData(userHandle); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1191 | int length = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1192 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1193 | if (who != null) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1194 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1195 | return admin != null ? admin.minimumPasswordLength : length; |
| 1196 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1197 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1198 | final int N = policy.mAdminList.size(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1199 | for (int i=0; i<N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1200 | ActiveAdmin admin = policy.mAdminList.get(i); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1201 | if (length < admin.minimumPasswordLength) { |
| 1202 | length = admin.minimumPasswordLength; |
| 1203 | } |
| 1204 | } |
| 1205 | return length; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1206 | } |
| 1207 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1208 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1209 | public void setPasswordHistoryLength(ComponentName who, int length, int userHandle) { |
| 1210 | enforceCrossUserPermission(userHandle); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1211 | synchronized (this) { |
| 1212 | if (who == null) { |
| 1213 | throw new NullPointerException("ComponentName is null"); |
| 1214 | } |
| 1215 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1216 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 1217 | if (ap.passwordHistoryLength != length) { |
| 1218 | ap.passwordHistoryLength = length; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1219 | saveSettingsLocked(userHandle); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1220 | } |
| 1221 | } |
| 1222 | } |
| 1223 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1224 | public int getPasswordHistoryLength(ComponentName who, int userHandle) { |
| 1225 | enforceCrossUserPermission(userHandle); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1226 | synchronized (this) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1227 | DevicePolicyData policy = getUserData(userHandle); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1228 | int length = 0; |
| 1229 | |
| 1230 | if (who != null) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1231 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1232 | return admin != null ? admin.passwordHistoryLength : length; |
| 1233 | } |
| 1234 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1235 | final int N = policy.mAdminList.size(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1236 | for (int i = 0; i < N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1237 | ActiveAdmin admin = policy.mAdminList.get(i); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1238 | if (length < admin.passwordHistoryLength) { |
| 1239 | length = admin.passwordHistoryLength; |
| 1240 | } |
| 1241 | } |
| 1242 | return length; |
| 1243 | } |
| 1244 | } |
| 1245 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1246 | public void setPasswordExpirationTimeout(ComponentName who, long timeout, int userHandle) { |
| 1247 | enforceCrossUserPermission(userHandle); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1248 | synchronized (this) { |
| 1249 | if (who == null) { |
| 1250 | throw new NullPointerException("ComponentName is null"); |
| 1251 | } |
Andy Stadler | 1f35d48 | 2010-11-19 15:39:41 -0800 | [diff] [blame] | 1252 | if (timeout < 0) { |
| 1253 | throw new IllegalArgumentException("Timeout must be >= 0 ms"); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1254 | } |
| 1255 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1256 | DeviceAdminInfo.USES_POLICY_EXPIRE_PASSWORD); |
| 1257 | // Calling this API automatically bumps the expiration date |
| 1258 | final long expiration = timeout > 0L ? (timeout + System.currentTimeMillis()) : 0L; |
| 1259 | ap.passwordExpirationDate = expiration; |
| 1260 | ap.passwordExpirationTimeout = timeout; |
| 1261 | if (timeout > 0L) { |
| 1262 | Slog.w(TAG, "setPasswordExpiration(): password will expire on " |
| 1263 | + DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT) |
| 1264 | .format(new Date(expiration))); |
| 1265 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1266 | saveSettingsLocked(userHandle); |
| 1267 | // in case this is the first one |
| 1268 | setExpirationAlarmCheckLocked(mContext, getUserData(userHandle)); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1269 | } |
| 1270 | } |
| 1271 | |
Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 1272 | /** |
| 1273 | * Return a single admin's expiration cycle time, or the min of all cycle times. |
| 1274 | * Returns 0 if not configured. |
| 1275 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1276 | public long getPasswordExpirationTimeout(ComponentName who, int userHandle) { |
| 1277 | enforceCrossUserPermission(userHandle); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1278 | synchronized (this) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1279 | if (who != null) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1280 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 1281 | return admin != null ? admin.passwordExpirationTimeout : 0L; |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1282 | } |
| 1283 | |
Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 1284 | long timeout = 0L; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1285 | DevicePolicyData policy = getUserData(userHandle); |
| 1286 | final int N = policy.mAdminList.size(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1287 | for (int i = 0; i < N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1288 | ActiveAdmin admin = policy.mAdminList.get(i); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1289 | if (timeout == 0L || (admin.passwordExpirationTimeout != 0L |
| 1290 | && timeout > admin.passwordExpirationTimeout)) { |
| 1291 | timeout = admin.passwordExpirationTimeout; |
| 1292 | } |
| 1293 | } |
| 1294 | return timeout; |
| 1295 | } |
| 1296 | } |
| 1297 | |
Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 1298 | /** |
| 1299 | * Return a single admin's expiration date/time, or the min (soonest) for all admins. |
| 1300 | * Returns 0 if not configured. |
| 1301 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1302 | private long getPasswordExpirationLocked(ComponentName who, int userHandle) { |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1303 | if (who != null) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1304 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 1305 | return admin != null ? admin.passwordExpirationDate : 0L; |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1306 | } |
| 1307 | |
Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 1308 | long timeout = 0L; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1309 | DevicePolicyData policy = getUserData(userHandle); |
| 1310 | final int N = policy.mAdminList.size(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1311 | for (int i = 0; i < N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1312 | ActiveAdmin admin = policy.mAdminList.get(i); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1313 | if (timeout == 0L || (admin.passwordExpirationDate != 0 |
| 1314 | && timeout > admin.passwordExpirationDate)) { |
| 1315 | timeout = admin.passwordExpirationDate; |
| 1316 | } |
| 1317 | } |
| 1318 | return timeout; |
| 1319 | } |
| 1320 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1321 | public long getPasswordExpiration(ComponentName who, int userHandle) { |
| 1322 | enforceCrossUserPermission(userHandle); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1323 | synchronized (this) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1324 | return getPasswordExpirationLocked(who, userHandle); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1325 | } |
| 1326 | } |
| 1327 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1328 | public void setPasswordMinimumUpperCase(ComponentName who, int length, int userHandle) { |
| 1329 | enforceCrossUserPermission(userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1330 | synchronized (this) { |
| 1331 | if (who == null) { |
| 1332 | throw new NullPointerException("ComponentName is null"); |
| 1333 | } |
| 1334 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1335 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 1336 | if (ap.minimumPasswordUpperCase != length) { |
| 1337 | ap.minimumPasswordUpperCase = length; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1338 | saveSettingsLocked(userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1339 | } |
| 1340 | } |
| 1341 | } |
| 1342 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1343 | public int getPasswordMinimumUpperCase(ComponentName who, int userHandle) { |
| 1344 | enforceCrossUserPermission(userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1345 | synchronized (this) { |
| 1346 | int length = 0; |
| 1347 | |
| 1348 | if (who != null) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1349 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1350 | return admin != null ? admin.minimumPasswordUpperCase : length; |
| 1351 | } |
| 1352 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1353 | DevicePolicyData policy = getUserData(userHandle); |
| 1354 | final int N = policy.mAdminList.size(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1355 | for (int i=0; i<N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1356 | ActiveAdmin admin = policy.mAdminList.get(i); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1357 | if (length < admin.minimumPasswordUpperCase) { |
| 1358 | length = admin.minimumPasswordUpperCase; |
| 1359 | } |
| 1360 | } |
| 1361 | return length; |
| 1362 | } |
| 1363 | } |
| 1364 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1365 | public void setPasswordMinimumLowerCase(ComponentName who, int length, int userHandle) { |
| 1366 | enforceCrossUserPermission(userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1367 | synchronized (this) { |
| 1368 | if (who == null) { |
| 1369 | throw new NullPointerException("ComponentName is null"); |
| 1370 | } |
| 1371 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1372 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 1373 | if (ap.minimumPasswordLowerCase != length) { |
| 1374 | ap.minimumPasswordLowerCase = length; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1375 | saveSettingsLocked(userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1376 | } |
| 1377 | } |
| 1378 | } |
| 1379 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1380 | public int getPasswordMinimumLowerCase(ComponentName who, int userHandle) { |
| 1381 | enforceCrossUserPermission(userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1382 | synchronized (this) { |
| 1383 | int length = 0; |
| 1384 | |
| 1385 | if (who != null) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1386 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1387 | return admin != null ? admin.minimumPasswordLowerCase : length; |
| 1388 | } |
| 1389 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1390 | DevicePolicyData policy = getUserData(userHandle); |
| 1391 | final int N = policy.mAdminList.size(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1392 | for (int i=0; i<N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1393 | ActiveAdmin admin = policy.mAdminList.get(i); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1394 | if (length < admin.minimumPasswordLowerCase) { |
| 1395 | length = admin.minimumPasswordLowerCase; |
| 1396 | } |
| 1397 | } |
| 1398 | return length; |
| 1399 | } |
| 1400 | } |
| 1401 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1402 | public void setPasswordMinimumLetters(ComponentName who, int length, int userHandle) { |
| 1403 | enforceCrossUserPermission(userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1404 | synchronized (this) { |
| 1405 | if (who == null) { |
| 1406 | throw new NullPointerException("ComponentName is null"); |
| 1407 | } |
| 1408 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1409 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 1410 | if (ap.minimumPasswordLetters != length) { |
| 1411 | ap.minimumPasswordLetters = length; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1412 | saveSettingsLocked(userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1413 | } |
| 1414 | } |
| 1415 | } |
| 1416 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1417 | public int getPasswordMinimumLetters(ComponentName who, int userHandle) { |
| 1418 | enforceCrossUserPermission(userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1419 | synchronized (this) { |
| 1420 | int length = 0; |
| 1421 | |
| 1422 | if (who != null) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1423 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1424 | return admin != null ? admin.minimumPasswordLetters : length; |
| 1425 | } |
| 1426 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1427 | DevicePolicyData policy = getUserData(userHandle); |
| 1428 | final int N = policy.mAdminList.size(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1429 | for (int i=0; i<N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1430 | ActiveAdmin admin = policy.mAdminList.get(i); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1431 | if (length < admin.minimumPasswordLetters) { |
| 1432 | length = admin.minimumPasswordLetters; |
| 1433 | } |
| 1434 | } |
| 1435 | return length; |
| 1436 | } |
| 1437 | } |
| 1438 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1439 | public void setPasswordMinimumNumeric(ComponentName who, int length, int userHandle) { |
| 1440 | enforceCrossUserPermission(userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1441 | synchronized (this) { |
| 1442 | if (who == null) { |
| 1443 | throw new NullPointerException("ComponentName is null"); |
| 1444 | } |
| 1445 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1446 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 1447 | if (ap.minimumPasswordNumeric != length) { |
| 1448 | ap.minimumPasswordNumeric = length; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1449 | saveSettingsLocked(userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1450 | } |
| 1451 | } |
| 1452 | } |
| 1453 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1454 | public int getPasswordMinimumNumeric(ComponentName who, int userHandle) { |
| 1455 | enforceCrossUserPermission(userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1456 | synchronized (this) { |
| 1457 | int length = 0; |
| 1458 | |
| 1459 | if (who != null) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1460 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1461 | return admin != null ? admin.minimumPasswordNumeric : length; |
| 1462 | } |
| 1463 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1464 | DevicePolicyData policy = getUserData(userHandle); |
| 1465 | final int N = policy.mAdminList.size(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1466 | for (int i = 0; i < N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1467 | ActiveAdmin admin = policy.mAdminList.get(i); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1468 | if (length < admin.minimumPasswordNumeric) { |
| 1469 | length = admin.minimumPasswordNumeric; |
| 1470 | } |
| 1471 | } |
| 1472 | return length; |
| 1473 | } |
| 1474 | } |
| 1475 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1476 | public void setPasswordMinimumSymbols(ComponentName who, int length, int userHandle) { |
| 1477 | enforceCrossUserPermission(userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1478 | synchronized (this) { |
| 1479 | if (who == null) { |
| 1480 | throw new NullPointerException("ComponentName is null"); |
| 1481 | } |
| 1482 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1483 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 1484 | if (ap.minimumPasswordSymbols != length) { |
| 1485 | ap.minimumPasswordSymbols = length; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1486 | saveSettingsLocked(userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1487 | } |
| 1488 | } |
| 1489 | } |
| 1490 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1491 | public int getPasswordMinimumSymbols(ComponentName who, int userHandle) { |
| 1492 | enforceCrossUserPermission(userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1493 | synchronized (this) { |
| 1494 | int length = 0; |
| 1495 | |
| 1496 | if (who != null) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1497 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1498 | return admin != null ? admin.minimumPasswordSymbols : length; |
| 1499 | } |
| 1500 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1501 | DevicePolicyData policy = getUserData(userHandle); |
| 1502 | final int N = policy.mAdminList.size(); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1503 | for (int i=0; i<N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1504 | ActiveAdmin admin = policy.mAdminList.get(i); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1505 | if (length < admin.minimumPasswordSymbols) { |
| 1506 | length = admin.minimumPasswordSymbols; |
| 1507 | } |
| 1508 | } |
| 1509 | return length; |
| 1510 | } |
| 1511 | } |
| 1512 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1513 | public void setPasswordMinimumNonLetter(ComponentName who, int length, int userHandle) { |
| 1514 | enforceCrossUserPermission(userHandle); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1515 | synchronized (this) { |
| 1516 | if (who == null) { |
| 1517 | throw new NullPointerException("ComponentName is null"); |
| 1518 | } |
| 1519 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1520 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 1521 | if (ap.minimumPasswordNonLetter != length) { |
| 1522 | ap.minimumPasswordNonLetter = length; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1523 | saveSettingsLocked(userHandle); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1524 | } |
| 1525 | } |
| 1526 | } |
| 1527 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1528 | public int getPasswordMinimumNonLetter(ComponentName who, int userHandle) { |
| 1529 | enforceCrossUserPermission(userHandle); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1530 | synchronized (this) { |
| 1531 | int length = 0; |
| 1532 | |
| 1533 | if (who != null) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1534 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1535 | return admin != null ? admin.minimumPasswordNonLetter : length; |
| 1536 | } |
| 1537 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1538 | DevicePolicyData policy = getUserData(userHandle); |
| 1539 | final int N = policy.mAdminList.size(); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1540 | for (int i=0; i<N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1541 | ActiveAdmin admin = policy.mAdminList.get(i); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1542 | if (length < admin.minimumPasswordNonLetter) { |
| 1543 | length = admin.minimumPasswordNonLetter; |
| 1544 | } |
| 1545 | } |
| 1546 | return length; |
| 1547 | } |
| 1548 | } |
| 1549 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1550 | public boolean isActivePasswordSufficient(int userHandle) { |
| 1551 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1552 | synchronized (this) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1553 | DevicePolicyData policy = getUserData(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1554 | // This API can only be called by an active device admin, |
| 1555 | // so try to retrieve it to check that the caller is one. |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1556 | getActiveAdminForCallerLocked(null, |
| 1557 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1558 | if (policy.mActivePasswordQuality < getPasswordQuality(null, userHandle) |
| 1559 | || policy.mActivePasswordLength < getPasswordMinimumLength(null, userHandle)) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1560 | return false; |
| 1561 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1562 | if (policy.mActivePasswordQuality != DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) { |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1563 | return true; |
| 1564 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1565 | return policy.mActivePasswordUpperCase >= getPasswordMinimumUpperCase(null, userHandle) |
| 1566 | && policy.mActivePasswordLowerCase >= getPasswordMinimumLowerCase(null, userHandle) |
| 1567 | && policy.mActivePasswordLetters >= getPasswordMinimumLetters(null, userHandle) |
| 1568 | && policy.mActivePasswordNumeric >= getPasswordMinimumNumeric(null, userHandle) |
| 1569 | && policy.mActivePasswordSymbols >= getPasswordMinimumSymbols(null, userHandle) |
| 1570 | && policy.mActivePasswordNonLetter >= getPasswordMinimumNonLetter(null, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1571 | } |
| 1572 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1573 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1574 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
| 1575 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1576 | synchronized (this) { |
| 1577 | // This API can only be called by an active device admin, |
| 1578 | // so try to retrieve it to check that the caller is one. |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1579 | getActiveAdminForCallerLocked(null, |
| 1580 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1581 | return getUserData(userHandle).mFailedPasswordAttempts; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1582 | } |
| 1583 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1584 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1585 | public void setMaximumFailedPasswordsForWipe(ComponentName who, int num, int userHandle) { |
| 1586 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1587 | synchronized (this) { |
| 1588 | // This API can only be called by an active device admin, |
| 1589 | // so try to retrieve it to check that the caller is one. |
| 1590 | getActiveAdminForCallerLocked(who, |
| 1591 | DeviceAdminInfo.USES_POLICY_WIPE_DATA); |
| 1592 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1593 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN); |
| 1594 | if (ap.maximumFailedPasswordsForWipe != num) { |
| 1595 | ap.maximumFailedPasswordsForWipe = num; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1596 | saveSettingsLocked(userHandle); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1597 | } |
| 1598 | } |
| 1599 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1600 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1601 | public int getMaximumFailedPasswordsForWipe(ComponentName who, int userHandle) { |
| 1602 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1603 | synchronized (this) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1604 | DevicePolicyData policy = getUserData(userHandle); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1605 | int count = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1606 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1607 | if (who != null) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1608 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1609 | return admin != null ? admin.maximumFailedPasswordsForWipe : count; |
| 1610 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1611 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1612 | final int N = policy.mAdminList.size(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1613 | for (int i=0; i<N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1614 | ActiveAdmin admin = policy.mAdminList.get(i); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1615 | if (count == 0) { |
| 1616 | count = admin.maximumFailedPasswordsForWipe; |
| 1617 | } else if (admin.maximumFailedPasswordsForWipe != 0 |
| 1618 | && count > admin.maximumFailedPasswordsForWipe) { |
| 1619 | count = admin.maximumFailedPasswordsForWipe; |
| 1620 | } |
| 1621 | } |
| 1622 | return count; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1623 | } |
| 1624 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1625 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1626 | public boolean resetPassword(String password, int flags, int userHandle) { |
| 1627 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1628 | int quality; |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1629 | synchronized (this) { |
| 1630 | // This API can only be called by an active device admin, |
| 1631 | // so try to retrieve it to check that the caller is one. |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1632 | getActiveAdminForCallerLocked(null, |
| 1633 | DeviceAdminInfo.USES_POLICY_RESET_PASSWORD); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1634 | quality = getPasswordQuality(null, userHandle); |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1635 | if (quality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1636 | int realQuality = LockPatternUtils.computePasswordQuality(password); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1637 | if (realQuality < quality |
| 1638 | && quality != DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1639 | Slog.w(TAG, "resetPassword: password quality 0x" |
| 1640 | + Integer.toHexString(quality) |
| 1641 | + " does not meet required quality 0x" |
| 1642 | + Integer.toHexString(quality)); |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1643 | return false; |
| 1644 | } |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1645 | quality = Math.max(realQuality, quality); |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1646 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1647 | int length = getPasswordMinimumLength(null, userHandle); |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1648 | if (password.length() < length) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1649 | Slog.w(TAG, "resetPassword: password length " + password.length() |
| 1650 | + " does not meet required length " + length); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1651 | return false; |
| 1652 | } |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1653 | if (quality == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) { |
| 1654 | int letters = 0; |
| 1655 | int uppercase = 0; |
| 1656 | int lowercase = 0; |
| 1657 | int numbers = 0; |
| 1658 | int symbols = 0; |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1659 | int nonletter = 0; |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1660 | for (int i = 0; i < password.length(); i++) { |
| 1661 | char c = password.charAt(i); |
| 1662 | if (c >= 'A' && c <= 'Z') { |
| 1663 | letters++; |
| 1664 | uppercase++; |
| 1665 | } else if (c >= 'a' && c <= 'z') { |
| 1666 | letters++; |
| 1667 | lowercase++; |
| 1668 | } else if (c >= '0' && c <= '9') { |
| 1669 | numbers++; |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1670 | nonletter++; |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1671 | } else { |
| 1672 | symbols++; |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1673 | nonletter++; |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1674 | } |
| 1675 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1676 | int neededLetters = getPasswordMinimumLetters(null, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1677 | if(letters < neededLetters) { |
| 1678 | Slog.w(TAG, "resetPassword: number of letters " + letters |
| 1679 | + " does not meet required number of letters " + neededLetters); |
| 1680 | return false; |
| 1681 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1682 | int neededNumbers = getPasswordMinimumNumeric(null, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1683 | if (numbers < neededNumbers) { |
| 1684 | Slog |
| 1685 | .w(TAG, "resetPassword: number of numerical digits " + numbers |
| 1686 | + " does not meet required number of numerical digits " |
| 1687 | + neededNumbers); |
| 1688 | return false; |
| 1689 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1690 | int neededLowerCase = getPasswordMinimumLowerCase(null, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1691 | if (lowercase < neededLowerCase) { |
| 1692 | Slog.w(TAG, "resetPassword: number of lowercase letters " + lowercase |
| 1693 | + " does not meet required number of lowercase letters " |
| 1694 | + neededLowerCase); |
| 1695 | return false; |
| 1696 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1697 | int neededUpperCase = getPasswordMinimumUpperCase(null, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1698 | if (uppercase < neededUpperCase) { |
| 1699 | Slog.w(TAG, "resetPassword: number of uppercase letters " + uppercase |
| 1700 | + " does not meet required number of uppercase letters " |
| 1701 | + neededUpperCase); |
| 1702 | return false; |
| 1703 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1704 | int neededSymbols = getPasswordMinimumSymbols(null, userHandle); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1705 | if (symbols < neededSymbols) { |
| 1706 | Slog.w(TAG, "resetPassword: number of special symbols " + symbols |
| 1707 | + " does not meet required number of special symbols " + neededSymbols); |
| 1708 | return false; |
| 1709 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1710 | int neededNonLetter = getPasswordMinimumNonLetter(null, userHandle); |
Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1711 | if (nonletter < neededNonLetter) { |
| 1712 | Slog.w(TAG, "resetPassword: number of non-letter characters " + nonletter |
| 1713 | + " does not meet required number of non-letter characters " |
| 1714 | + neededNonLetter); |
| 1715 | return false; |
| 1716 | } |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1717 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1718 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1719 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1720 | int callingUid = Binder.getCallingUid(); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1721 | DevicePolicyData policy = getUserData(userHandle); |
| 1722 | if (policy.mPasswordOwner >= 0 && policy.mPasswordOwner != callingUid) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1723 | Slog.w(TAG, "resetPassword: already set by another uid and not entered by user"); |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1724 | return false; |
| 1725 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1726 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1727 | // Don't do this with the lock held, because it is going to call |
| 1728 | // back in to the service. |
| 1729 | long ident = Binder.clearCallingIdentity(); |
| 1730 | try { |
| 1731 | LockPatternUtils utils = new LockPatternUtils(mContext); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1732 | utils.saveLockPassword(password, quality, false, userHandle); |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1733 | synchronized (this) { |
| 1734 | int newOwner = (flags&DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY) |
| 1735 | != 0 ? callingUid : -1; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1736 | if (policy.mPasswordOwner != newOwner) { |
| 1737 | policy.mPasswordOwner = newOwner; |
| 1738 | saveSettingsLocked(userHandle); |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1739 | } |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1740 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1741 | } finally { |
| 1742 | Binder.restoreCallingIdentity(ident); |
| 1743 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1744 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1745 | return true; |
| 1746 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1747 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1748 | public void setMaximumTimeToLock(ComponentName who, long timeMs, int userHandle) { |
| 1749 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1750 | synchronized (this) { |
| 1751 | if (who == null) { |
| 1752 | throw new NullPointerException("ComponentName is null"); |
| 1753 | } |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1754 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 1755 | DeviceAdminInfo.USES_POLICY_FORCE_LOCK); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1756 | if (ap.maximumTimeToUnlock != timeMs) { |
| 1757 | ap.maximumTimeToUnlock = timeMs; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1758 | saveSettingsLocked(userHandle); |
| 1759 | updateMaximumTimeToLockLocked(getUserData(userHandle)); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1760 | } |
| 1761 | } |
| 1762 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1763 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1764 | void updateMaximumTimeToLockLocked(DevicePolicyData policy) { |
| 1765 | long timeMs = getMaximumTimeToLock(null, policy.mUserHandle); |
| 1766 | if (policy.mLastMaximumTimeToLock == timeMs) { |
Dianne Hackborn | 2fe8fb2 | 2012-06-15 17:05:25 -0700 | [diff] [blame] | 1767 | return; |
| 1768 | } |
| 1769 | |
| 1770 | long ident = Binder.clearCallingIdentity(); |
| 1771 | try { |
| 1772 | if (timeMs <= 0) { |
| 1773 | timeMs = Integer.MAX_VALUE; |
| 1774 | } else { |
| 1775 | // Make sure KEEP_SCREEN_ON is disabled, since that |
| 1776 | // would allow bypassing of the maximum time to lock. |
Christopher Tate | 62df6eb5 | 2012-09-07 15:00:54 -0700 | [diff] [blame] | 1777 | Settings.Global.putInt(mContext.getContentResolver(), |
| 1778 | Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0); |
Dianne Hackborn | 2fe8fb2 | 2012-06-15 17:05:25 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1781 | policy.mLastMaximumTimeToLock = timeMs; |
Dianne Hackborn | 2fe8fb2 | 2012-06-15 17:05:25 -0700 | [diff] [blame] | 1782 | |
| 1783 | try { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 1784 | getIPowerManager().setMaximumScreenOffTimeoutFromDeviceAdmin((int)timeMs); |
Dianne Hackborn | 2fe8fb2 | 2012-06-15 17:05:25 -0700 | [diff] [blame] | 1785 | } catch (RemoteException e) { |
| 1786 | Slog.w(TAG, "Failure talking with power manager", e); |
| 1787 | } |
| 1788 | } finally { |
| 1789 | Binder.restoreCallingIdentity(ident); |
| 1790 | } |
| 1791 | } |
| 1792 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1793 | public long getMaximumTimeToLock(ComponentName who, int userHandle) { |
| 1794 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1795 | synchronized (this) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1796 | long time = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1797 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1798 | if (who != null) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1799 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1800 | return admin != null ? admin.maximumTimeToUnlock : time; |
| 1801 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1802 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1803 | DevicePolicyData policy = getUserData(userHandle); |
| 1804 | final int N = policy.mAdminList.size(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1805 | for (int i=0; i<N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1806 | ActiveAdmin admin = policy.mAdminList.get(i); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1807 | if (time == 0) { |
| 1808 | time = admin.maximumTimeToUnlock; |
| 1809 | } else if (admin.maximumTimeToUnlock != 0 |
| 1810 | && time > admin.maximumTimeToUnlock) { |
| 1811 | time = admin.maximumTimeToUnlock; |
| 1812 | } |
| 1813 | } |
| 1814 | return time; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1815 | } |
| 1816 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1817 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1818 | public void lockNow() { |
| 1819 | synchronized (this) { |
| 1820 | // This API can only be called by an active device admin, |
| 1821 | // so try to retrieve it to check that the caller is one. |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1822 | getActiveAdminForCallerLocked(null, |
| 1823 | DeviceAdminInfo.USES_POLICY_FORCE_LOCK); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1824 | lockNowUnchecked(); |
| 1825 | } |
| 1826 | } |
| 1827 | |
| 1828 | private void lockNowUnchecked() { |
| 1829 | long ident = Binder.clearCallingIdentity(); |
| 1830 | try { |
| 1831 | // Power off the display |
| 1832 | getIPowerManager().goToSleep(SystemClock.uptimeMillis(), |
| 1833 | PowerManager.GO_TO_SLEEP_REASON_DEVICE_ADMIN); |
| 1834 | // Ensure the device is locked |
| 1835 | getWindowManager().lockNow(); |
| 1836 | } catch (RemoteException e) { |
| 1837 | } finally { |
| 1838 | Binder.restoreCallingIdentity(ident); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1839 | } |
| 1840 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1841 | |
Ben Komalo | ed48c8b | 2011-10-17 17:30:21 -0700 | [diff] [blame] | 1842 | private boolean isExtStorageEncrypted() { |
| 1843 | String state = SystemProperties.get("vold.decrypt"); |
| 1844 | return !"".equals(state); |
| 1845 | } |
| 1846 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1847 | void wipeDataLocked(int flags) { |
Ben Komalo | ed48c8b | 2011-10-17 17:30:21 -0700 | [diff] [blame] | 1848 | // If the SD card is encrypted and non-removable, we have to force a wipe. |
| 1849 | boolean forceExtWipe = !Environment.isExternalStorageRemovable() && isExtStorageEncrypted(); |
| 1850 | boolean wipeExtRequested = (flags&DevicePolicyManager.WIPE_EXTERNAL_STORAGE) != 0; |
| 1851 | |
| 1852 | // Note: we can only do the wipe via ExternalStorageFormatter if the volume is not emulated. |
| 1853 | if ((forceExtWipe || wipeExtRequested) && !Environment.isExternalStorageEmulated()) { |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 1854 | Intent intent = new Intent(ExternalStorageFormatter.FORMAT_AND_FACTORY_RESET); |
Masanori Ogino | f535cb04 | 2012-02-15 19:25:50 +0900 | [diff] [blame] | 1855 | intent.putExtra(ExternalStorageFormatter.EXTRA_ALWAYS_RESET, true); |
Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 1856 | intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME); |
| 1857 | mWakeLock.acquire(10000); |
| 1858 | mContext.startService(intent); |
| 1859 | } else { |
| 1860 | try { |
| 1861 | RecoverySystem.rebootWipeUserData(mContext); |
| 1862 | } catch (IOException e) { |
| 1863 | Slog.w(TAG, "Failed requesting data wipe", e); |
| 1864 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1865 | } |
| 1866 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1867 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1868 | public void wipeData(int flags, final int userHandle) { |
| 1869 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1870 | synchronized (this) { |
| 1871 | // This API can only be called by an active device admin, |
| 1872 | // so try to retrieve it to check that the caller is one. |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1873 | getActiveAdminForCallerLocked(null, |
| 1874 | DeviceAdminInfo.USES_POLICY_WIPE_DATA); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1875 | long ident = Binder.clearCallingIdentity(); |
| 1876 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1877 | if (userHandle == UserHandle.USER_OWNER) { |
| 1878 | wipeDataLocked(flags); |
| 1879 | } else { |
| 1880 | lockNowUnchecked(); |
| 1881 | mHandler.post(new Runnable() { |
| 1882 | public void run() { |
| 1883 | try { |
| 1884 | ActivityManagerNative.getDefault().switchUser(0); |
| 1885 | ((UserManager) mContext.getSystemService(Context.USER_SERVICE)) |
| 1886 | .removeUser(userHandle); |
| 1887 | } catch (RemoteException re) { |
| 1888 | // Shouldn't happen |
| 1889 | } |
| 1890 | } |
| 1891 | }); |
| 1892 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1893 | } finally { |
| 1894 | Binder.restoreCallingIdentity(ident); |
| 1895 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1896 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1897 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1898 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1899 | public void getRemoveWarning(ComponentName comp, final RemoteCallback result, int userHandle) { |
| 1900 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1901 | mContext.enforceCallingOrSelfPermission( |
| 1902 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1903 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1904 | synchronized (this) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1905 | ActiveAdmin admin = getActiveAdminUncheckedLocked(comp, userHandle); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1906 | if (admin == null) { |
| 1907 | try { |
| 1908 | result.sendResult(null); |
| 1909 | } catch (RemoteException e) { |
| 1910 | } |
| 1911 | return; |
| 1912 | } |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1913 | Intent intent = new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_DISABLE_REQUESTED); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1914 | intent.setComponent(admin.info.getComponent()); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1915 | mContext.sendOrderedBroadcastAsUser(intent, new UserHandle(userHandle), |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 1916 | null, new BroadcastReceiver() { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1917 | @Override |
| 1918 | public void onReceive(Context context, Intent intent) { |
| 1919 | try { |
| 1920 | result.sendResult(getResultExtras(false)); |
| 1921 | } catch (RemoteException e) { |
| 1922 | } |
| 1923 | } |
| 1924 | }, null, Activity.RESULT_OK, null, null); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1925 | } |
| 1926 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1927 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1928 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1929 | int lowercase, int numbers, int symbols, int nonletter, int userHandle) { |
| 1930 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1931 | mContext.enforceCallingOrSelfPermission( |
| 1932 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1933 | DevicePolicyData p = getUserData(userHandle); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1934 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1935 | validateQualityConstant(quality); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1936 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1937 | synchronized (this) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1938 | if (p.mActivePasswordQuality != quality || p.mActivePasswordLength != length |
| 1939 | || p.mFailedPasswordAttempts != 0 || p.mActivePasswordLetters != letters |
| 1940 | || p.mActivePasswordUpperCase != uppercase |
| 1941 | || p.mActivePasswordLowerCase != lowercase || p.mActivePasswordNumeric != numbers |
| 1942 | || p.mActivePasswordSymbols != symbols || p.mActivePasswordNonLetter != nonletter) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1943 | long ident = Binder.clearCallingIdentity(); |
| 1944 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1945 | p.mActivePasswordQuality = quality; |
| 1946 | p.mActivePasswordLength = length; |
| 1947 | p.mActivePasswordLetters = letters; |
| 1948 | p.mActivePasswordLowerCase = lowercase; |
| 1949 | p.mActivePasswordUpperCase = uppercase; |
| 1950 | p.mActivePasswordNumeric = numbers; |
| 1951 | p.mActivePasswordSymbols = symbols; |
| 1952 | p.mActivePasswordNonLetter = nonletter; |
| 1953 | p.mFailedPasswordAttempts = 0; |
| 1954 | saveSettingsLocked(userHandle); |
| 1955 | updatePasswordExpirationsLocked(userHandle); |
| 1956 | setExpirationAlarmCheckLocked(mContext, p); |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1957 | sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_CHANGED, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1958 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1959 | } finally { |
| 1960 | Binder.restoreCallingIdentity(ident); |
| 1961 | } |
| 1962 | } |
| 1963 | } |
| 1964 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1965 | |
Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 1966 | /** |
| 1967 | * Called any time the device password is updated. Resets all password expiration clocks. |
| 1968 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1969 | private void updatePasswordExpirationsLocked(int userHandle) { |
| 1970 | DevicePolicyData policy = getUserData(userHandle); |
| 1971 | final int N = policy.mAdminList.size(); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1972 | if (N > 0) { |
| 1973 | for (int i=0; i<N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1974 | ActiveAdmin admin = policy.mAdminList.get(i); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1975 | if (admin.info.usesPolicy(DeviceAdminInfo.USES_POLICY_EXPIRE_PASSWORD)) { |
Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 1976 | long timeout = admin.passwordExpirationTimeout; |
| 1977 | long expiration = timeout > 0L ? (timeout + System.currentTimeMillis()) : 0L; |
| 1978 | admin.passwordExpirationDate = expiration; |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1979 | } |
| 1980 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1981 | saveSettingsLocked(userHandle); |
Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1982 | } |
| 1983 | } |
| 1984 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1985 | public void reportFailedPasswordAttempt(int userHandle) { |
| 1986 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1987 | mContext.enforceCallingOrSelfPermission( |
| 1988 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1989 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1990 | synchronized (this) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1991 | DevicePolicyData policy = getUserData(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1992 | long ident = Binder.clearCallingIdentity(); |
| 1993 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1994 | policy.mFailedPasswordAttempts++; |
| 1995 | saveSettingsLocked(userHandle); |
| 1996 | int max = getMaximumFailedPasswordsForWipe(null, userHandle); |
| 1997 | if (max > 0 && policy.mFailedPasswordAttempts >= max) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1998 | wipeDataLocked(0); |
| 1999 | } |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2000 | sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_FAILED, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2001 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2002 | } finally { |
| 2003 | Binder.restoreCallingIdentity(ident); |
| 2004 | } |
| 2005 | } |
| 2006 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2007 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2008 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
| 2009 | enforceCrossUserPermission(userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2010 | mContext.enforceCallingOrSelfPermission( |
| 2011 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2012 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2013 | synchronized (this) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2014 | DevicePolicyData policy = getUserData(userHandle); |
| 2015 | if (policy.mFailedPasswordAttempts != 0 || policy.mPasswordOwner >= 0) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2016 | long ident = Binder.clearCallingIdentity(); |
| 2017 | try { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2018 | policy.mFailedPasswordAttempts = 0; |
| 2019 | policy.mPasswordOwner = -1; |
| 2020 | saveSettingsLocked(userHandle); |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2021 | sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_SUCCEEDED, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2022 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN, userHandle); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2023 | } finally { |
| 2024 | Binder.restoreCallingIdentity(ident); |
| 2025 | } |
| 2026 | } |
| 2027 | } |
| 2028 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2029 | |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2030 | public ComponentName setGlobalProxy(ComponentName who, String proxySpec, |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2031 | String exclusionList, int userHandle) { |
| 2032 | enforceCrossUserPermission(userHandle); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2033 | synchronized(this) { |
| 2034 | if (who == null) { |
| 2035 | throw new NullPointerException("ComponentName is null"); |
| 2036 | } |
| 2037 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2038 | // Only check if owner has set global proxy. We don't allow other users to set it. |
| 2039 | DevicePolicyData policy = getUserData(UserHandle.USER_OWNER); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2040 | ActiveAdmin admin = getActiveAdminForCallerLocked(who, |
| 2041 | DeviceAdminInfo.USES_POLICY_SETS_GLOBAL_PROXY); |
| 2042 | |
| 2043 | // Scan through active admins and find if anyone has already |
| 2044 | // set the global proxy. |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2045 | Set<ComponentName> compSet = policy.mAdminMap.keySet(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2046 | for (ComponentName component : compSet) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2047 | ActiveAdmin ap = policy.mAdminMap.get(component); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2048 | if ((ap.specifiesGlobalProxy) && (!component.equals(who))) { |
| 2049 | // Another admin already sets the global proxy |
| 2050 | // Return it to the caller. |
| 2051 | return component; |
| 2052 | } |
| 2053 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2054 | |
| 2055 | // If the user is not the owner, don't set the global proxy. Fail silently. |
| 2056 | if (UserHandle.getCallingUserId() != UserHandle.USER_OWNER) { |
| 2057 | Slog.w(TAG, "Only the owner is allowed to set the global proxy. User " |
| 2058 | + userHandle + " is not permitted."); |
| 2059 | return null; |
| 2060 | } |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2061 | if (proxySpec == null) { |
| 2062 | admin.specifiesGlobalProxy = false; |
| 2063 | admin.globalProxySpec = null; |
| 2064 | admin.globalProxyExclusionList = null; |
| 2065 | } else { |
| 2066 | |
| 2067 | admin.specifiesGlobalProxy = true; |
| 2068 | admin.globalProxySpec = proxySpec; |
| 2069 | admin.globalProxyExclusionList = exclusionList; |
| 2070 | } |
| 2071 | |
| 2072 | // Reset the global proxy accordingly |
| 2073 | // Do this using system permissions, as apps cannot write to secure settings |
| 2074 | long origId = Binder.clearCallingIdentity(); |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2075 | resetGlobalProxyLocked(policy); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2076 | Binder.restoreCallingIdentity(origId); |
| 2077 | return null; |
| 2078 | } |
| 2079 | } |
| 2080 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2081 | public ComponentName getGlobalProxyAdmin(int userHandle) { |
| 2082 | enforceCrossUserPermission(userHandle); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2083 | synchronized(this) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2084 | DevicePolicyData policy = getUserData(UserHandle.USER_OWNER); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2085 | // Scan through active admins and find if anyone has already |
| 2086 | // set the global proxy. |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2087 | final int N = policy.mAdminList.size(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2088 | for (int i = 0; i < N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2089 | ActiveAdmin ap = policy.mAdminList.get(i); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2090 | if (ap.specifiesGlobalProxy) { |
| 2091 | // Device admin sets the global proxy |
| 2092 | // Return it to the caller. |
| 2093 | return ap.info.getComponent(); |
| 2094 | } |
| 2095 | } |
| 2096 | } |
| 2097 | // No device admin sets the global proxy. |
| 2098 | return null; |
| 2099 | } |
| 2100 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2101 | private void resetGlobalProxyLocked(DevicePolicyData policy) { |
| 2102 | final int N = policy.mAdminList.size(); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2103 | for (int i = 0; i < N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2104 | ActiveAdmin ap = policy.mAdminList.get(i); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2105 | if (ap.specifiesGlobalProxy) { |
Dianne Hackborn | 2fe8fb2 | 2012-06-15 17:05:25 -0700 | [diff] [blame] | 2106 | saveGlobalProxyLocked(ap.globalProxySpec, ap.globalProxyExclusionList); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2107 | return; |
| 2108 | } |
| 2109 | } |
| 2110 | // No device admins defining global proxies - reset global proxy settings to none |
Dianne Hackborn | 2fe8fb2 | 2012-06-15 17:05:25 -0700 | [diff] [blame] | 2111 | saveGlobalProxyLocked(null, null); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
Dianne Hackborn | 2fe8fb2 | 2012-06-15 17:05:25 -0700 | [diff] [blame] | 2114 | private void saveGlobalProxyLocked(String proxySpec, String exclusionList) { |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2115 | if (exclusionList == null) { |
| 2116 | exclusionList = ""; |
| 2117 | } |
| 2118 | if (proxySpec == null) { |
| 2119 | proxySpec = ""; |
| 2120 | } |
| 2121 | // Remove white spaces |
| 2122 | proxySpec = proxySpec.trim(); |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 2123 | String data[] = proxySpec.split(":"); |
| 2124 | int proxyPort = 8080; |
| 2125 | if (data.length > 1) { |
| 2126 | try { |
| 2127 | proxyPort = Integer.parseInt(data[1]); |
| 2128 | } catch (NumberFormatException e) {} |
| 2129 | } |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2130 | exclusionList = exclusionList.trim(); |
| 2131 | ContentResolver res = mContext.getContentResolver(); |
Jeff Sharkey | 625239a | 2012-09-26 22:03:49 -0700 | [diff] [blame] | 2132 | Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_HOST, data[0]); |
| 2133 | Settings.Global.putInt(res, Settings.Global.GLOBAL_HTTP_PROXY_PORT, proxyPort); |
| 2134 | Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST, |
Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 2135 | exclusionList); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2136 | } |
| 2137 | |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2138 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2139 | * Set the storage encryption request for a single admin. Returns the new total request |
| 2140 | * status (for all admins). |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2141 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2142 | public int setStorageEncryption(ComponentName who, boolean encrypt, int userHandle) { |
| 2143 | enforceCrossUserPermission(userHandle); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2144 | synchronized (this) { |
| 2145 | // Check for permissions |
| 2146 | if (who == null) { |
| 2147 | throw new NullPointerException("ComponentName is null"); |
| 2148 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2149 | // Only owner can set storage encryption |
| 2150 | if (userHandle != UserHandle.USER_OWNER |
| 2151 | || UserHandle.getCallingUserId() != UserHandle.USER_OWNER) { |
| 2152 | Slog.w(TAG, "Only owner is allowed to set storage encryption. User " |
| 2153 | + UserHandle.getCallingUserId() + " is not permitted."); |
| 2154 | return 0; |
| 2155 | } |
| 2156 | |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2157 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 2158 | DeviceAdminInfo.USES_ENCRYPTED_STORAGE); |
| 2159 | |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2160 | // Quick exit: If the filesystem does not support encryption, we can exit early. |
| 2161 | if (!isEncryptionSupported()) { |
| 2162 | return DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED; |
| 2163 | } |
| 2164 | |
| 2165 | // (1) Record the value for the admin so it's sticky |
| 2166 | if (ap.encryptionRequested != encrypt) { |
| 2167 | ap.encryptionRequested = encrypt; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2168 | saveSettingsLocked(userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2169 | } |
| 2170 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2171 | DevicePolicyData policy = getUserData(UserHandle.USER_OWNER); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2172 | // (2) Compute "max" for all admins |
| 2173 | boolean newRequested = false; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2174 | final int N = policy.mAdminList.size(); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2175 | for (int i = 0; i < N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2176 | newRequested |= policy.mAdminList.get(i).encryptionRequested; |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | // Notify OS of new request |
| 2180 | setEncryptionRequested(newRequested); |
| 2181 | |
| 2182 | // Return the new global request status |
| 2183 | return newRequested |
| 2184 | ? DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE |
| 2185 | : DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2186 | } |
| 2187 | } |
| 2188 | |
| 2189 | /** |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2190 | * Get the current storage encryption request status for a given admin, or aggregate of all |
| 2191 | * active admins. |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2192 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2193 | public boolean getStorageEncryption(ComponentName who, int userHandle) { |
| 2194 | enforceCrossUserPermission(userHandle); |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2195 | synchronized (this) { |
| 2196 | // Check for permissions if a particular caller is specified |
| 2197 | if (who != null) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2198 | // When checking for a single caller, status is based on caller's request |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2199 | ActiveAdmin ap = getActiveAdminUncheckedLocked(who, userHandle); |
Andy Stadler | c994d69 | 2011-06-01 15:30:54 -0700 | [diff] [blame] | 2200 | return ap != null ? ap.encryptionRequested : false; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2201 | } |
| 2202 | |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2203 | // If no particular caller is specified, return the aggregate set of requests. |
| 2204 | // This is short circuited by returning true on the first hit. |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2205 | DevicePolicyData policy = getUserData(userHandle); |
| 2206 | final int N = policy.mAdminList.size(); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2207 | for (int i = 0; i < N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2208 | if (policy.mAdminList.get(i).encryptionRequested) { |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2209 | return true; |
| 2210 | } |
| 2211 | } |
| 2212 | return false; |
Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2213 | } |
| 2214 | } |
| 2215 | |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2216 | /** |
| 2217 | * Get the current encryption status of the device. |
| 2218 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2219 | public int getStorageEncryptionStatus(int userHandle) { |
| 2220 | enforceCrossUserPermission(userHandle); |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2221 | return getEncryptionStatus(); |
| 2222 | } |
| 2223 | |
| 2224 | /** |
| 2225 | * Hook to low-levels: This should report if the filesystem supports encrypted storage. |
| 2226 | */ |
| 2227 | private boolean isEncryptionSupported() { |
| 2228 | // Note, this can be implemented as |
| 2229 | // return getEncryptionStatus() != DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED; |
| 2230 | // But is provided as a separate internal method if there's a faster way to do a |
| 2231 | // simple check for supported-or-not. |
| 2232 | return getEncryptionStatus() != DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED; |
| 2233 | } |
| 2234 | |
| 2235 | /** |
| 2236 | * Hook to low-levels: Reporting the current status of encryption. |
| 2237 | * @return A value such as {@link DevicePolicyManager#ENCRYPTION_STATUS_UNSUPPORTED} or |
| 2238 | * {@link DevicePolicyManager#ENCRYPTION_STATUS_INACTIVE} or |
| 2239 | * {@link DevicePolicyManager#ENCRYPTION_STATUS_ACTIVE}. |
| 2240 | */ |
| 2241 | private int getEncryptionStatus() { |
Andy Stadler | 0fe45de | 2011-01-20 16:35:09 -0800 | [diff] [blame] | 2242 | String status = SystemProperties.get("ro.crypto.state", "unsupported"); |
| 2243 | if ("encrypted".equalsIgnoreCase(status)) { |
| 2244 | return DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE; |
| 2245 | } else if ("unencrypted".equalsIgnoreCase(status)) { |
| 2246 | return DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE; |
| 2247 | } else { |
| 2248 | return DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED; |
| 2249 | } |
Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2250 | } |
| 2251 | |
| 2252 | /** |
| 2253 | * Hook to low-levels: If needed, record the new admin setting for encryption. |
| 2254 | */ |
| 2255 | private void setEncryptionRequested(boolean encrypt) { |
| 2256 | } |
| 2257 | |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2258 | /** |
| 2259 | * The system property used to share the state of the camera. The native camera service |
| 2260 | * is expected to read this property and act accordingly. |
| 2261 | */ |
| 2262 | public static final String SYSTEM_PROP_DISABLE_CAMERA = "sys.secpolicy.camera.disabled"; |
| 2263 | |
| 2264 | /** |
| 2265 | * Disables all device cameras according to the specified admin. |
| 2266 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2267 | public void setCameraDisabled(ComponentName who, boolean disabled, int userHandle) { |
| 2268 | enforceCrossUserPermission(userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2269 | synchronized (this) { |
| 2270 | if (who == null) { |
| 2271 | throw new NullPointerException("ComponentName is null"); |
| 2272 | } |
| 2273 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 2274 | DeviceAdminInfo.USES_POLICY_DISABLE_CAMERA); |
| 2275 | if (ap.disableCamera != disabled) { |
| 2276 | ap.disableCamera = disabled; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2277 | saveSettingsLocked(userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2278 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2279 | syncDeviceCapabilitiesLocked(getUserData(userHandle)); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2280 | } |
| 2281 | } |
| 2282 | |
| 2283 | /** |
| 2284 | * Gets whether or not all device cameras are disabled for a given admin, or disabled for any |
| 2285 | * active admins. |
| 2286 | */ |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2287 | public boolean getCameraDisabled(ComponentName who, int userHandle) { |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2288 | synchronized (this) { |
| 2289 | if (who != null) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2290 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2291 | return (admin != null) ? admin.disableCamera : false; |
| 2292 | } |
| 2293 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2294 | DevicePolicyData policy = getUserData(userHandle); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2295 | // Determine whether or not the device camera is disabled for any active admins. |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2296 | final int N = policy.mAdminList.size(); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2297 | for (int i = 0; i < N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2298 | ActiveAdmin admin = policy.mAdminList.get(i); |
Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2299 | if (admin.disableCamera) { |
| 2300 | return true; |
| 2301 | } |
| 2302 | } |
| 2303 | return false; |
| 2304 | } |
| 2305 | } |
| 2306 | |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2307 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2308 | * Selectively disable keyguard features. |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2309 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2310 | public void setKeyguardDisabledFeatures(ComponentName who, int which, int userHandle) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2311 | enforceCrossUserPermission(userHandle); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2312 | synchronized (this) { |
| 2313 | if (who == null) { |
| 2314 | throw new NullPointerException("ComponentName is null"); |
| 2315 | } |
| 2316 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2317 | DeviceAdminInfo.USES_POLICY_DISABLE_KEYGUARD_FEATURES); |
| 2318 | if (ap.disabledKeyguardFeatures != which) { |
| 2319 | ap.disabledKeyguardFeatures = which; |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2320 | saveSettingsLocked(userHandle); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2321 | } |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2322 | syncDeviceCapabilitiesLocked(getUserData(userHandle)); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2323 | } |
| 2324 | } |
| 2325 | |
| 2326 | /** |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2327 | * Gets the disabled state for features in keyguard for the given admin, |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2328 | * or the aggregate of all active admins if who is null. |
| 2329 | */ |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2330 | public int getKeyguardDisabledFeatures(ComponentName who, int userHandle) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2331 | enforceCrossUserPermission(userHandle); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2332 | synchronized (this) { |
| 2333 | if (who != null) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2334 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2335 | return (admin != null) ? admin.disabledKeyguardFeatures : 0; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2336 | } |
| 2337 | |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2338 | // Determine which keyguard features are disabled for any active admins. |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2339 | DevicePolicyData policy = getUserData(userHandle); |
| 2340 | final int N = policy.mAdminList.size(); |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2341 | int which = 0; |
| 2342 | for (int i = 0; i < N; i++) { |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2343 | ActiveAdmin admin = policy.mAdminList.get(i); |
Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2344 | which |= admin.disabledKeyguardFeatures; |
Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2345 | } |
| 2346 | return which; |
| 2347 | } |
| 2348 | } |
| 2349 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2350 | private void enforceCrossUserPermission(int userHandle) { |
| 2351 | if (userHandle < 0) { |
| 2352 | throw new IllegalArgumentException("Invalid userId " + userHandle); |
| 2353 | } |
| 2354 | final int callingUid = Binder.getCallingUid(); |
| 2355 | if (userHandle == UserHandle.getUserId(callingUid)) return; |
| 2356 | if (callingUid != Process.SYSTEM_UID && callingUid != 0) { |
| 2357 | mContext.enforceCallingOrSelfPermission( |
| 2358 | android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, "Must be system or have" |
| 2359 | + " INTERACT_ACROSS_USERS_FULL permission"); |
| 2360 | } |
| 2361 | } |
| 2362 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2363 | @Override |
| 2364 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 2365 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 2366 | != PackageManager.PERMISSION_GRANTED) { |
| 2367 | |
| 2368 | pw.println("Permission Denial: can't dump DevicePolicyManagerService from from pid=" |
| 2369 | + Binder.getCallingPid() |
| 2370 | + ", uid=" + Binder.getCallingUid()); |
| 2371 | return; |
| 2372 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2373 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2374 | final Printer p = new PrintWriterPrinter(pw); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2375 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2376 | synchronized (this) { |
| 2377 | p.println("Current Device Policy Manager state:"); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2378 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2379 | int userCount = mUserData.size(); |
| 2380 | for (int u = 0; u < userCount; u++) { |
| 2381 | DevicePolicyData policy = getUserData(mUserData.keyAt(u)); |
| 2382 | p.println(" Enabled Device Admins (User " + policy.mUserHandle + "):"); |
| 2383 | final int N = policy.mAdminList.size(); |
| 2384 | for (int i=0; i<N; i++) { |
| 2385 | ActiveAdmin ap = policy.mAdminList.get(i); |
| 2386 | if (ap != null) { |
| 2387 | pw.print(" "); pw.print(ap.info.getComponent().flattenToShortString()); |
| 2388 | pw.println(":"); |
| 2389 | ap.dump(" ", pw); |
| 2390 | } |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2391 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2392 | |
Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2393 | pw.println(" "); |
| 2394 | pw.print(" mPasswordOwner="); pw.println(policy.mPasswordOwner); |
| 2395 | } |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2396 | } |
| 2397 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2398 | } |