| 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 | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 19 | import com.android.internal.content.PackageMonitor; |
| 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; |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 30 | import android.app.admin.DeviceAdminInfo; |
| 31 | import android.app.admin.DeviceAdminReceiver; |
| 32 | import android.app.admin.DevicePolicyManager; |
| 33 | import android.app.admin.IDevicePolicyManager; |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 34 | import android.content.BroadcastReceiver; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 35 | import android.content.ComponentName; |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 36 | import android.content.ContentResolver; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 37 | import android.content.Context; |
| 38 | import android.content.Intent; |
| 39 | import android.content.pm.PackageManager; |
| 40 | import android.content.pm.ResolveInfo; |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 41 | import android.content.pm.PackageManager.NameNotFoundException; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 42 | import android.os.Binder; |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 43 | import android.os.IBinder; |
| 44 | import android.os.IPowerManager; |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 45 | import android.os.RecoverySystem; |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 46 | import android.os.RemoteCallback; |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 47 | import android.os.RemoteException; |
| 48 | import android.os.ServiceManager; |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 49 | import android.os.SystemClock; |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 50 | import android.net.Proxy; |
| 51 | import android.provider.Settings; |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 52 | import android.util.Slog; |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 53 | import android.util.PrintWriterPrinter; |
| 54 | import android.util.Printer; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 55 | import android.util.Xml; |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 56 | import android.view.WindowManagerPolicy; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 57 | |
| 58 | import java.io.File; |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 59 | import java.io.FileDescriptor; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 60 | import java.io.FileInputStream; |
| Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 61 | import java.io.FileNotFoundException; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 62 | import java.io.FileOutputStream; |
| 63 | import java.io.IOException; |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 64 | import java.io.PrintWriter; |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 65 | import java.net.InetSocketAddress; |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 66 | import java.util.ArrayList; |
| 67 | import java.util.HashMap; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 68 | import java.util.List; |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 69 | import java.util.Set; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Implementation of the device policy APIs. |
| 73 | */ |
| 74 | public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 75 | static final String TAG = "DevicePolicyManagerService"; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 76 | |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 77 | final Context mContext; |
| 78 | final MyPackageMonitor mMonitor; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 79 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 80 | IPowerManager mIPowerManager; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 81 | |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 82 | int mActivePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 83 | int mActivePasswordLength = 0; |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 84 | int mActivePasswordUpperCase = 0; |
| 85 | int mActivePasswordLowerCase = 0; |
| 86 | int mActivePasswordLetters = 0; |
| 87 | int mActivePasswordNumeric = 0; |
| 88 | int mActivePasswordSymbols = 0; |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 89 | int mActivePasswordNonLetter = 0; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 90 | int mFailedPasswordAttempts = 0; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 91 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 92 | int mPasswordOwner = -1; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 93 | |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 94 | final HashMap<ComponentName, ActiveAdmin> mAdminMap |
| 95 | = new HashMap<ComponentName, ActiveAdmin>(); |
| 96 | final ArrayList<ActiveAdmin> mAdminList |
| 97 | = new ArrayList<ActiveAdmin>(); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 98 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 99 | static class ActiveAdmin { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 100 | final DeviceAdminInfo info; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 101 | |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 102 | int passwordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 103 | int minimumPasswordLength = 0; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 104 | int passwordHistoryLength = 0; |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 105 | int minimumPasswordUpperCase = 0; |
| 106 | int minimumPasswordLowerCase = 0; |
| 107 | int minimumPasswordLetters = 1; |
| 108 | int minimumPasswordNumeric = 1; |
| 109 | int minimumPasswordSymbols = 1; |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 110 | int minimumPasswordNonLetter = 0; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 111 | long maximumTimeToUnlock = 0; |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 112 | int maximumFailedPasswordsForWipe = 0; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 113 | |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 114 | // TODO: review implementation decisions with frameworks team |
| 115 | boolean specifiesGlobalProxy = false; |
| 116 | String globalProxySpec = null; |
| 117 | String globalProxyExclusionList = null; |
| 118 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 119 | ActiveAdmin(DeviceAdminInfo _info) { |
| 120 | info = _info; |
| 121 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 122 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 123 | int getUid() { return info.getActivityInfo().applicationInfo.uid; } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 124 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 125 | void writeToXml(XmlSerializer out) |
| 126 | throws IllegalArgumentException, IllegalStateException, IOException { |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 127 | out.startTag(null, "policies"); |
| 128 | info.writePoliciesToXml(out); |
| 129 | out.endTag(null, "policies"); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 130 | if (passwordQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { |
| 131 | out.startTag(null, "password-quality"); |
| 132 | out.attribute(null, "value", Integer.toString(passwordQuality)); |
| 133 | out.endTag(null, "password-quality"); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 134 | if (minimumPasswordLength > 0) { |
| 135 | out.startTag(null, "min-password-length"); |
| 136 | out.attribute(null, "value", Integer.toString(minimumPasswordLength)); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 137 | out.endTag(null, "min-password-length"); |
| 138 | } |
| 139 | if(passwordHistoryLength > 0) { |
| 140 | out.startTag(null, "password-history-length"); |
| 141 | out.attribute(null, "value", Integer.toString(passwordHistoryLength)); |
| 142 | out.endTag(null, "password-history-length"); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 143 | } |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 144 | if (minimumPasswordUpperCase > 0) { |
| 145 | out.startTag(null, "min-password-uppercase"); |
| 146 | out.attribute(null, "value", Integer.toString(minimumPasswordUpperCase)); |
| 147 | out.endTag(null, "min-password-uppercase"); |
| 148 | } |
| 149 | if (minimumPasswordLowerCase > 0) { |
| 150 | out.startTag(null, "min-password-lowercase"); |
| 151 | out.attribute(null, "value", Integer.toString(minimumPasswordLowerCase)); |
| 152 | out.endTag(null, "min-password-lowercase"); |
| 153 | } |
| 154 | if (minimumPasswordLetters > 0) { |
| 155 | out.startTag(null, "min-password-letters"); |
| 156 | out.attribute(null, "value", Integer.toString(minimumPasswordLetters)); |
| 157 | out.endTag(null, "min-password-letters"); |
| 158 | } |
| 159 | if (minimumPasswordNumeric > 0) { |
| 160 | out.startTag(null, "min-password-numeric"); |
| 161 | out.attribute(null, "value", Integer.toString(minimumPasswordNumeric)); |
| 162 | out.endTag(null, "min-password-numeric"); |
| 163 | } |
| 164 | if (minimumPasswordSymbols > 0) { |
| 165 | out.startTag(null, "min-password-symbols"); |
| 166 | out.attribute(null, "value", Integer.toString(minimumPasswordSymbols)); |
| 167 | out.endTag(null, "min-password-symbols"); |
| 168 | } |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 169 | if (minimumPasswordNonLetter > 0) { |
| 170 | out.startTag(null, "min-password-nonletter"); |
| 171 | out.attribute(null, "value", Integer.toString(minimumPasswordNonLetter)); |
| 172 | out.endTag(null, "min-password-nonletter"); |
| 173 | } |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 174 | } |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 175 | if (maximumTimeToUnlock != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 176 | out.startTag(null, "max-time-to-unlock"); |
| 177 | out.attribute(null, "value", Long.toString(maximumTimeToUnlock)); |
| 178 | out.endTag(null, "max-time-to-unlock"); |
| 179 | } |
| 180 | if (maximumFailedPasswordsForWipe != 0) { |
| 181 | out.startTag(null, "max-failed-password-wipe"); |
| 182 | out.attribute(null, "value", Integer.toString(maximumFailedPasswordsForWipe)); |
| 183 | out.endTag(null, "max-failed-password-wipe"); |
| 184 | } |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 185 | if (specifiesGlobalProxy) { |
| 186 | out.startTag(null, "specifies-global-proxy"); |
| 187 | out.attribute(null, "value", Boolean.toString(specifiesGlobalProxy)); |
| 188 | out.endTag(null, "specifies_global_proxy"); |
| 189 | if (globalProxySpec != null) { |
| 190 | out.startTag(null, "global-proxy-spec"); |
| 191 | out.attribute(null, "value", globalProxySpec); |
| 192 | out.endTag(null, "global-proxy-spec"); |
| 193 | } |
| 194 | if (globalProxyExclusionList != null) { |
| 195 | out.startTag(null, "global-proxy-exclusion-list"); |
| 196 | out.attribute(null, "value", globalProxyExclusionList); |
| 197 | out.endTag(null, "global-proxy-exclusion-list"); |
| 198 | } |
| 199 | } |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 200 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 201 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 202 | void readFromXml(XmlPullParser parser) |
| 203 | throws XmlPullParserException, IOException { |
| 204 | int outerDepth = parser.getDepth(); |
| 205 | int type; |
| 206 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 207 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 208 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 209 | continue; |
| 210 | } |
| 211 | String tag = parser.getName(); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 212 | if ("policies".equals(tag)) { |
| 213 | info.readPoliciesFromXml(parser); |
| 214 | } else if ("password-quality".equals(tag)) { |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 215 | passwordQuality = Integer.parseInt( |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 216 | parser.getAttributeValue(null, "value")); |
| 217 | } else if ("min-password-length".equals(tag)) { |
| 218 | minimumPasswordLength = Integer.parseInt( |
| 219 | parser.getAttributeValue(null, "value")); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 220 | } else if ("password-history-length".equals(tag)) { |
| 221 | passwordHistoryLength = Integer.parseInt( |
| 222 | parser.getAttributeValue(null, "value")); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 223 | } else if ("min-password-uppercase".equals(tag)) { |
| 224 | minimumPasswordUpperCase = Integer.parseInt( |
| 225 | parser.getAttributeValue(null, "value")); |
| 226 | } else if ("min-password-lowercase".equals(tag)) { |
| 227 | minimumPasswordLowerCase = Integer.parseInt( |
| 228 | parser.getAttributeValue(null, "value")); |
| 229 | } else if ("min-password-letters".equals(tag)) { |
| 230 | minimumPasswordLetters = Integer.parseInt( |
| 231 | parser.getAttributeValue(null, "value")); |
| 232 | } else if ("min-password-numeric".equals(tag)) { |
| 233 | minimumPasswordNumeric = Integer.parseInt( |
| 234 | parser.getAttributeValue(null, "value")); |
| 235 | } else if ("min-password-symbols".equals(tag)) { |
| 236 | minimumPasswordSymbols = Integer.parseInt( |
| 237 | parser.getAttributeValue(null, "value")); |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 238 | } else if ("min-password-nonletter".equals(tag)) { |
| 239 | minimumPasswordNonLetter = Integer.parseInt( |
| 240 | parser.getAttributeValue(null, "value")); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 241 | } else if ("max-time-to-unlock".equals(tag)) { |
| 242 | maximumTimeToUnlock = Long.parseLong( |
| 243 | parser.getAttributeValue(null, "value")); |
| 244 | } else if ("max-failed-password-wipe".equals(tag)) { |
| 245 | maximumFailedPasswordsForWipe = Integer.parseInt( |
| 246 | parser.getAttributeValue(null, "value")); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 247 | } else if ("specifies-global-proxy".equals(tag)) { |
| 248 | specifiesGlobalProxy = Boolean.getBoolean( |
| 249 | parser.getAttributeValue(null, "value")); |
| 250 | } else if ("global-proxy-spec".equals(tag)) { |
| 251 | globalProxySpec = |
| 252 | parser.getAttributeValue(null, "value"); |
| 253 | } else if ("global-proxy-exclusion-list".equals(tag)) { |
| 254 | globalProxyExclusionList = |
| 255 | parser.getAttributeValue(null, "value"); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 256 | } else { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 257 | Slog.w(TAG, "Unknown admin tag: " + tag); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 258 | } |
| 259 | XmlUtils.skipCurrentTag(parser); |
| 260 | } |
| 261 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 262 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 263 | void dump(String prefix, PrintWriter pw) { |
| 264 | pw.print(prefix); pw.print("uid="); pw.println(getUid()); |
| 265 | pw.print(prefix); pw.println("policies:"); |
| 266 | ArrayList<DeviceAdminInfo.PolicyInfo> pols = info.getUsedPolicies(); |
| 267 | if (pols != null) { |
| 268 | for (int i=0; i<pols.size(); i++) { |
| 269 | pw.print(prefix); pw.print(" "); pw.println(pols.get(i).tag); |
| 270 | } |
| 271 | } |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 272 | pw.print(prefix); pw.print("passwordQuality=0x"); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 273 | pw.println(Integer.toHexString(passwordQuality)); |
| 274 | pw.print(prefix); pw.print("minimumPasswordLength="); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 275 | pw.println(minimumPasswordLength); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 276 | pw.print(prefix); pw.print("passwordHistoryLength="); |
| 277 | pw.println(passwordHistoryLength); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 278 | pw.print(prefix); pw.print("minimumPasswordUpperCase="); |
| 279 | pw.println(minimumPasswordUpperCase); |
| 280 | pw.print(prefix); pw.print("minimumPasswordLowerCase="); |
| 281 | pw.println(minimumPasswordLowerCase); |
| 282 | pw.print(prefix); pw.print("minimumPasswordLetters="); |
| 283 | pw.println(minimumPasswordLetters); |
| 284 | pw.print(prefix); pw.print("minimumPasswordNumeric="); |
| 285 | pw.println(minimumPasswordNumeric); |
| 286 | pw.print(prefix); pw.print("minimumPasswordSymbols="); |
| 287 | pw.println(minimumPasswordSymbols); |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 288 | pw.print(prefix); pw.print("minimumPasswordNonLetter="); |
| 289 | pw.println(minimumPasswordNonLetter); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 290 | pw.print(prefix); pw.print("maximumTimeToUnlock="); |
| 291 | pw.println(maximumTimeToUnlock); |
| 292 | pw.print(prefix); pw.print("maximumFailedPasswordsForWipe="); |
| 293 | pw.println(maximumFailedPasswordsForWipe); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 294 | pw.print(prefix); pw.print("specifiesGlobalProxy="); |
| 295 | pw.println(specifiesGlobalProxy); |
| 296 | if (globalProxySpec != null) { |
| 297 | pw.print(prefix); pw.print("globalProxySpec="); |
| 298 | pw.println(globalProxySpec); |
| 299 | } |
| 300 | if (globalProxyExclusionList != null) { |
| 301 | pw.print(prefix); pw.print("globalProxyEclusionList="); |
| 302 | pw.println(globalProxyExclusionList); |
| 303 | } |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 304 | } |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 305 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 306 | |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 307 | class MyPackageMonitor extends PackageMonitor { |
| 308 | public void onSomePackagesChanged() { |
| 309 | synchronized (DevicePolicyManagerService.this) { |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 310 | boolean removed = false; |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 311 | for (int i=mAdminList.size()-1; i>=0; i--) { |
| 312 | ActiveAdmin aa = mAdminList.get(i); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 313 | int change = isPackageDisappearing(aa.info.getPackageName()); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 314 | if (change == PACKAGE_PERMANENT_CHANGE |
| 315 | || change == PACKAGE_TEMPORARY_CHANGE) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 316 | Slog.w(TAG, "Admin unexpectedly uninstalled: " |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 317 | + aa.info.getComponent()); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 318 | removed = true; |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 319 | mAdminList.remove(i); |
| 320 | } else if (isPackageModified(aa.info.getPackageName())) { |
| 321 | try { |
| 322 | mContext.getPackageManager().getReceiverInfo( |
| 323 | aa.info.getComponent(), 0); |
| 324 | } catch (NameNotFoundException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 325 | Slog.w(TAG, "Admin package change removed component: " |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 326 | + aa.info.getComponent()); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 327 | removed = true; |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 328 | mAdminList.remove(i); |
| 329 | } |
| 330 | } |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 331 | } |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 332 | if (removed) { |
| 333 | validatePasswordOwnerLocked(); |
| 334 | } |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 335 | } |
| 336 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 337 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 338 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 339 | /** |
| 340 | * Instantiates the service. |
| 341 | */ |
| 342 | public DevicePolicyManagerService(Context context) { |
| 343 | mContext = context; |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 344 | mMonitor = new MyPackageMonitor(); |
| 345 | mMonitor.register(context, true); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 346 | } |
| 347 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 348 | private IPowerManager getIPowerManager() { |
| 349 | if (mIPowerManager == null) { |
| 350 | IBinder b = ServiceManager.getService(Context.POWER_SERVICE); |
| 351 | mIPowerManager = IPowerManager.Stub.asInterface(b); |
| 352 | } |
| 353 | return mIPowerManager; |
| 354 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 355 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 356 | ActiveAdmin getActiveAdminUncheckedLocked(ComponentName who) { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 357 | ActiveAdmin admin = mAdminMap.get(who); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 358 | if (admin != null |
| 359 | && who.getPackageName().equals(admin.info.getActivityInfo().packageName) |
| 360 | && who.getClassName().equals(admin.info.getActivityInfo().name)) { |
| 361 | return admin; |
| 362 | } |
| 363 | return null; |
| 364 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 365 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 366 | ActiveAdmin getActiveAdminForCallerLocked(ComponentName who, int reqPolicy) |
| 367 | throws SecurityException { |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 368 | final int callingUid = Binder.getCallingUid(); |
| 369 | if (who != null) { |
| 370 | ActiveAdmin admin = mAdminMap.get(who); |
| 371 | if (admin == null) { |
| 372 | throw new SecurityException("No active admin " + who); |
| 373 | } |
| 374 | if (admin.getUid() != callingUid) { |
| 375 | throw new SecurityException("Admin " + who + " is not owned by uid " |
| 376 | + Binder.getCallingUid()); |
| 377 | } |
| 378 | if (!admin.info.usesPolicy(reqPolicy)) { |
| 379 | throw new SecurityException("Admin " + admin.info.getComponent() |
| 380 | + " did not specify uses-policy for: " |
| 381 | + admin.info.getTagForPolicy(reqPolicy)); |
| 382 | } |
| 383 | return admin; |
| 384 | } else { |
| 385 | final int N = mAdminList.size(); |
| 386 | for (int i=0; i<N; i++) { |
| 387 | ActiveAdmin admin = mAdminList.get(i); |
| 388 | if (admin.getUid() == callingUid && admin.info.usesPolicy(reqPolicy)) { |
| 389 | return admin; |
| 390 | } |
| 391 | } |
| 392 | throw new SecurityException("No active admin owned by uid " |
| 393 | + Binder.getCallingUid() + " for policy #" + reqPolicy); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 394 | } |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 395 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 396 | |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 397 | void sendAdminCommandLocked(ActiveAdmin admin, String action) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 398 | Intent intent = new Intent(action); |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 399 | intent.setComponent(admin.info.getComponent()); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 400 | mContext.sendBroadcast(intent); |
| 401 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 402 | |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 403 | void sendAdminCommandLocked(String action, int reqPolicy) { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 404 | final int N = mAdminList.size(); |
| 405 | if (N > 0) { |
| 406 | for (int i=0; i<N; i++) { |
| 407 | ActiveAdmin admin = mAdminList.get(i); |
| 408 | if (admin.info.usesPolicy(reqPolicy)) { |
| 409 | sendAdminCommandLocked(admin, action); |
| 410 | } |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 411 | } |
| Dianne Hackborn | 4141d03 | 2010-01-21 16:29:00 -0800 | [diff] [blame] | 412 | } |
| 413 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 414 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 415 | void removeActiveAdminLocked(ComponentName adminReceiver) { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 416 | ActiveAdmin admin = getActiveAdminUncheckedLocked(adminReceiver); |
| 417 | if (admin != null) { |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 418 | boolean doProxyCleanup = |
| 419 | admin.info.usesPolicy(DeviceAdminInfo.USES_POLICY_SETS_GLOBAL_PROXY); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 420 | sendAdminCommandLocked(admin, |
| Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 421 | DeviceAdminReceiver.ACTION_DEVICE_ADMIN_DISABLED); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 422 | // XXX need to wait for it to complete. |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 423 | mAdminList.remove(admin); |
| 424 | mAdminMap.remove(adminReceiver); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 425 | validatePasswordOwnerLocked(); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 426 | if (doProxyCleanup) { |
| 427 | resetGlobalProxy(); |
| 428 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 429 | } |
| 430 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 431 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 432 | public DeviceAdminInfo findAdmin(ComponentName adminName) { |
| 433 | Intent resolveIntent = new Intent(); |
| 434 | resolveIntent.setComponent(adminName); |
| 435 | List<ResolveInfo> infos = mContext.getPackageManager().queryBroadcastReceivers( |
| 436 | resolveIntent, PackageManager.GET_META_DATA); |
| 437 | if (infos == null || infos.size() <= 0) { |
| 438 | throw new IllegalArgumentException("Unknown admin: " + adminName); |
| 439 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 440 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 441 | try { |
| 442 | return new DeviceAdminInfo(mContext, infos.get(0)); |
| 443 | } catch (XmlPullParserException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 444 | Slog.w(TAG, "Bad device admin requested: " + adminName, e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 445 | return null; |
| 446 | } catch (IOException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 447 | Slog.w(TAG, "Bad device admin requested: " + adminName, e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 448 | return null; |
| 449 | } |
| 450 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 451 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 452 | private static JournaledFile makeJournaledFile() { |
| 453 | final String base = "/data/system/device_policies.xml"; |
| 454 | return new JournaledFile(new File(base), new File(base + ".tmp")); |
| 455 | } |
| 456 | |
| 457 | private void saveSettingsLocked() { |
| 458 | JournaledFile journal = makeJournaledFile(); |
| 459 | FileOutputStream stream = null; |
| 460 | try { |
| 461 | stream = new FileOutputStream(journal.chooseForWrite(), false); |
| 462 | XmlSerializer out = new FastXmlSerializer(); |
| 463 | out.setOutput(stream, "utf-8"); |
| 464 | out.startDocument(null, true); |
| 465 | |
| 466 | out.startTag(null, "policies"); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 467 | |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 468 | final int N = mAdminList.size(); |
| 469 | for (int i=0; i<N; i++) { |
| 470 | ActiveAdmin ap = mAdminList.get(i); |
| 471 | if (ap != null) { |
| 472 | out.startTag(null, "admin"); |
| 473 | out.attribute(null, "name", ap.info.getComponent().flattenToString()); |
| 474 | ap.writeToXml(out); |
| 475 | out.endTag(null, "admin"); |
| 476 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 477 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 478 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 479 | if (mPasswordOwner >= 0) { |
| 480 | out.startTag(null, "password-owner"); |
| 481 | out.attribute(null, "value", Integer.toString(mPasswordOwner)); |
| 482 | out.endTag(null, "password-owner"); |
| 483 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 484 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 485 | if (mFailedPasswordAttempts != 0) { |
| 486 | out.startTag(null, "failed-password-attempts"); |
| 487 | out.attribute(null, "value", Integer.toString(mFailedPasswordAttempts)); |
| 488 | out.endTag(null, "failed-password-attempts"); |
| 489 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 490 | |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 491 | if (mActivePasswordQuality != 0 || mActivePasswordLength != 0 |
| 492 | || mActivePasswordUpperCase != 0 || mActivePasswordLowerCase != 0 |
| 493 | || mActivePasswordLetters != 0 || mActivePasswordNumeric != 0 |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 494 | || mActivePasswordSymbols != 0 || mActivePasswordNonLetter != 0) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 495 | out.startTag(null, "active-password"); |
| 496 | out.attribute(null, "quality", Integer.toString(mActivePasswordQuality)); |
| 497 | out.attribute(null, "length", Integer.toString(mActivePasswordLength)); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 498 | out.attribute(null, "uppercase", Integer.toString(mActivePasswordUpperCase)); |
| 499 | out.attribute(null, "lowercase", Integer.toString(mActivePasswordLowerCase)); |
| 500 | out.attribute(null, "letters", Integer.toString(mActivePasswordLetters)); |
| 501 | out.attribute(null, "numeric", Integer |
| 502 | .toString(mActivePasswordNumeric)); |
| 503 | out.attribute(null, "symbols", Integer.toString(mActivePasswordSymbols)); |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 504 | out.attribute(null, "nonletter", Integer.toString(mActivePasswordNonLetter)); |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 505 | out.endTag(null, "active-password"); |
| 506 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 507 | |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 508 | out.endTag(null, "policies"); |
| 509 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 510 | out.endDocument(); |
| 511 | stream.close(); |
| 512 | journal.commit(); |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 513 | sendChangedNotification(); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 514 | } catch (IOException e) { |
| 515 | try { |
| 516 | if (stream != null) { |
| 517 | stream.close(); |
| 518 | } |
| 519 | } catch (IOException ex) { |
| 520 | // Ignore |
| 521 | } |
| 522 | journal.rollback(); |
| 523 | } |
| 524 | } |
| 525 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 526 | private void sendChangedNotification() { |
| 527 | Intent intent = new Intent(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 528 | intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 529 | mContext.sendBroadcast(intent); |
| 530 | } |
| 531 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 532 | private void loadSettingsLocked() { |
| 533 | JournaledFile journal = makeJournaledFile(); |
| 534 | FileInputStream stream = null; |
| 535 | File file = journal.chooseForRead(); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 536 | try { |
| 537 | stream = new FileInputStream(file); |
| 538 | XmlPullParser parser = Xml.newPullParser(); |
| 539 | parser.setInput(stream, null); |
| 540 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 541 | int type; |
| 542 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 543 | && type != XmlPullParser.START_TAG) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 544 | } |
| 545 | String tag = parser.getName(); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 546 | if (!"policies".equals(tag)) { |
| 547 | throw new XmlPullParserException( |
| 548 | "Settings do not start with policies tag: found " + tag); |
| 549 | } |
| 550 | type = parser.next(); |
| 551 | int outerDepth = parser.getDepth(); |
| 552 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 553 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 554 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 555 | continue; |
| 556 | } |
| 557 | tag = parser.getName(); |
| 558 | if ("admin".equals(tag)) { |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 559 | String name = parser.getAttributeValue(null, "name"); |
| 560 | try { |
| 561 | DeviceAdminInfo dai = findAdmin( |
| 562 | ComponentName.unflattenFromString(name)); |
| 563 | if (dai != null) { |
| 564 | ActiveAdmin ap = new ActiveAdmin(dai); |
| 565 | ap.readFromXml(parser); |
| 566 | mAdminMap.put(ap.info.getComponent(), ap); |
| 567 | mAdminList.add(ap); |
| 568 | } |
| 569 | } catch (RuntimeException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 570 | Slog.w(TAG, "Failed loading admin " + name, e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 571 | } |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 572 | } else if ("failed-password-attempts".equals(tag)) { |
| 573 | mFailedPasswordAttempts = Integer.parseInt( |
| 574 | parser.getAttributeValue(null, "value")); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 575 | XmlUtils.skipCurrentTag(parser); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 576 | } else if ("password-owner".equals(tag)) { |
| 577 | mPasswordOwner = Integer.parseInt( |
| 578 | parser.getAttributeValue(null, "value")); |
| 579 | XmlUtils.skipCurrentTag(parser); |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 580 | } else if ("active-password".equals(tag)) { |
| 581 | mActivePasswordQuality = Integer.parseInt( |
| 582 | parser.getAttributeValue(null, "quality")); |
| 583 | mActivePasswordLength = Integer.parseInt( |
| 584 | parser.getAttributeValue(null, "length")); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 585 | mActivePasswordUpperCase = Integer.parseInt( |
| 586 | parser.getAttributeValue(null, "uppercase")); |
| 587 | mActivePasswordLowerCase = Integer.parseInt( |
| 588 | parser.getAttributeValue(null, "lowercase")); |
| 589 | mActivePasswordLetters = Integer.parseInt( |
| 590 | parser.getAttributeValue(null, "letters")); |
| 591 | mActivePasswordNumeric = Integer.parseInt( |
| 592 | parser.getAttributeValue(null, "numeric")); |
| 593 | mActivePasswordSymbols = Integer.parseInt( |
| 594 | parser.getAttributeValue(null, "symbols")); |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 595 | mActivePasswordNonLetter = Integer.parseInt( |
| 596 | parser.getAttributeValue(null, "nonletter")); |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 597 | XmlUtils.skipCurrentTag(parser); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 598 | } else { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 599 | Slog.w(TAG, "Unknown tag: " + tag); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 600 | XmlUtils.skipCurrentTag(parser); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 601 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 602 | } |
| 603 | } catch (NullPointerException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 604 | Slog.w(TAG, "failed parsing " + file + " " + e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 605 | } catch (NumberFormatException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 606 | Slog.w(TAG, "failed parsing " + file + " " + e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 607 | } catch (XmlPullParserException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 608 | Slog.w(TAG, "failed parsing " + file + " " + e); |
| Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 609 | } catch (FileNotFoundException e) { |
| 610 | // 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] | 611 | } catch (IOException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 612 | Slog.w(TAG, "failed parsing " + file + " " + e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 613 | } catch (IndexOutOfBoundsException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 614 | Slog.w(TAG, "failed parsing " + file + " " + e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 615 | } |
| 616 | try { |
| 617 | if (stream != null) { |
| 618 | stream.close(); |
| 619 | } |
| 620 | } catch (IOException e) { |
| 621 | // Ignore |
| 622 | } |
| 623 | |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 624 | // Validate that what we stored for the password quality matches |
| 625 | // sufficiently what is currently set. Note that this is only |
| 626 | // a sanity check in case the two get out of sync; this should |
| 627 | // never normally happen. |
| 628 | LockPatternUtils utils = new LockPatternUtils(mContext); |
| 629 | if (utils.getActivePasswordQuality() < mActivePasswordQuality) { |
| 630 | Slog.w(TAG, "Active password quality 0x" |
| 631 | + Integer.toHexString(mActivePasswordQuality) |
| 632 | + " does not match actual quality 0x" |
| 633 | + Integer.toHexString(utils.getActivePasswordQuality())); |
| 634 | mActivePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
| 635 | mActivePasswordLength = 0; |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 636 | mActivePasswordUpperCase = 0; |
| 637 | mActivePasswordLowerCase = 0; |
| 638 | mActivePasswordLetters = 0; |
| 639 | mActivePasswordNumeric = 0; |
| 640 | mActivePasswordSymbols = 0; |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 641 | mActivePasswordNonLetter = 0; |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 642 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 643 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 644 | validatePasswordOwnerLocked(); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 645 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 646 | long timeMs = getMaximumTimeToLock(null); |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 647 | if (timeMs <= 0) { |
| 648 | timeMs = Integer.MAX_VALUE; |
| 649 | } |
| 650 | try { |
| 651 | getIPowerManager().setMaximumScreenOffTimeount((int)timeMs); |
| 652 | } catch (RemoteException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 653 | Slog.w(TAG, "Failure talking with power manager", e); |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 654 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 655 | } |
| 656 | |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 657 | static void validateQualityConstant(int quality) { |
| 658 | switch (quality) { |
| 659 | case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED: |
| 660 | case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: |
| 661 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: |
| 662 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: |
| 663 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 664 | case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX: |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 665 | return; |
| 666 | } |
| 667 | throw new IllegalArgumentException("Invalid quality constant: 0x" |
| 668 | + Integer.toHexString(quality)); |
| 669 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 670 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 671 | void validatePasswordOwnerLocked() { |
| 672 | if (mPasswordOwner >= 0) { |
| 673 | boolean haveOwner = false; |
| 674 | for (int i=mAdminList.size()-1; i>=0; i--) { |
| 675 | if (mAdminList.get(i).getUid() == mPasswordOwner) { |
| 676 | haveOwner = true; |
| 677 | break; |
| 678 | } |
| 679 | } |
| 680 | if (!haveOwner) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 681 | Slog.w(TAG, "Previous password owner " + mPasswordOwner |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 682 | + " no longer active; disabling"); |
| 683 | mPasswordOwner = -1; |
| 684 | } |
| 685 | } |
| 686 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 687 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 688 | public void systemReady() { |
| 689 | synchronized (this) { |
| 690 | loadSettingsLocked(); |
| 691 | } |
| 692 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 693 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 694 | public void setActiveAdmin(ComponentName adminReceiver) { |
| 695 | mContext.enforceCallingOrSelfPermission( |
| 696 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 697 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 698 | DeviceAdminInfo info = findAdmin(adminReceiver); |
| 699 | if (info == null) { |
| 700 | throw new IllegalArgumentException("Bad admin: " + adminReceiver); |
| 701 | } |
| 702 | synchronized (this) { |
| 703 | long ident = Binder.clearCallingIdentity(); |
| 704 | try { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 705 | if (getActiveAdminUncheckedLocked(adminReceiver) != null) { |
| 706 | throw new IllegalArgumentException("Admin is already added"); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 707 | } |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 708 | ActiveAdmin admin = new ActiveAdmin(info); |
| 709 | mAdminMap.put(adminReceiver, admin); |
| 710 | mAdminList.add(admin); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 711 | saveSettingsLocked(); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 712 | sendAdminCommandLocked(admin, |
| Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 713 | DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 714 | } finally { |
| 715 | Binder.restoreCallingIdentity(ident); |
| 716 | } |
| 717 | } |
| 718 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 719 | |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 720 | public boolean isAdminActive(ComponentName adminReceiver) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 721 | synchronized (this) { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 722 | return getActiveAdminUncheckedLocked(adminReceiver) != null; |
| 723 | } |
| 724 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 725 | |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 726 | public List<ComponentName> getActiveAdmins() { |
| 727 | synchronized (this) { |
| 728 | final int N = mAdminList.size(); |
| 729 | if (N <= 0) { |
| 730 | return null; |
| 731 | } |
| 732 | ArrayList<ComponentName> res = new ArrayList<ComponentName>(N); |
| 733 | for (int i=0; i<N; i++) { |
| 734 | res.add(mAdminList.get(i).info.getComponent()); |
| 735 | } |
| 736 | return res; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 737 | } |
| 738 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 739 | |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 740 | public boolean packageHasActiveAdmins(String packageName) { |
| 741 | synchronized (this) { |
| 742 | final int N = mAdminList.size(); |
| 743 | for (int i=0; i<N; i++) { |
| 744 | if (mAdminList.get(i).info.getPackageName().equals(packageName)) { |
| 745 | return true; |
| 746 | } |
| 747 | } |
| 748 | return false; |
| 749 | } |
| 750 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 751 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 752 | public void removeActiveAdmin(ComponentName adminReceiver) { |
| 753 | synchronized (this) { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 754 | ActiveAdmin admin = getActiveAdminUncheckedLocked(adminReceiver); |
| 755 | if (admin == null) { |
| 756 | return; |
| 757 | } |
| 758 | if (admin.getUid() != Binder.getCallingUid()) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 759 | mContext.enforceCallingOrSelfPermission( |
| 760 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
| 761 | } |
| 762 | long ident = Binder.clearCallingIdentity(); |
| 763 | try { |
| 764 | removeActiveAdminLocked(adminReceiver); |
| 765 | } finally { |
| 766 | Binder.restoreCallingIdentity(ident); |
| 767 | } |
| 768 | } |
| 769 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 770 | |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 771 | public void setPasswordQuality(ComponentName who, int quality) { |
| 772 | validateQualityConstant(quality); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 773 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 774 | synchronized (this) { |
| 775 | if (who == null) { |
| 776 | throw new NullPointerException("ComponentName is null"); |
| 777 | } |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 778 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 779 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 780 | if (ap.passwordQuality != quality) { |
| 781 | ap.passwordQuality = quality; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 782 | saveSettingsLocked(); |
| 783 | } |
| 784 | } |
| 785 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 786 | |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 787 | public int getPasswordQuality(ComponentName who) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 788 | synchronized (this) { |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 789 | int mode = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 790 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 791 | if (who != null) { |
| 792 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 793 | return admin != null ? admin.passwordQuality : mode; |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 794 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 795 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 796 | final int N = mAdminList.size(); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 797 | for (int i=0; i<N; i++) { |
| 798 | ActiveAdmin admin = mAdminList.get(i); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 799 | if (mode < admin.passwordQuality) { |
| 800 | mode = admin.passwordQuality; |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | return mode; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 804 | } |
| 805 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 806 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 807 | public void setPasswordMinimumLength(ComponentName who, int length) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 808 | synchronized (this) { |
| 809 | if (who == null) { |
| 810 | throw new NullPointerException("ComponentName is null"); |
| 811 | } |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 812 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 813 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 814 | if (ap.minimumPasswordLength != length) { |
| 815 | ap.minimumPasswordLength = length; |
| 816 | saveSettingsLocked(); |
| 817 | } |
| 818 | } |
| 819 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 820 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 821 | public int getPasswordMinimumLength(ComponentName who) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 822 | synchronized (this) { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 823 | int length = 0; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 824 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 825 | if (who != null) { |
| 826 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 827 | return admin != null ? admin.minimumPasswordLength : length; |
| 828 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 829 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 830 | final int N = mAdminList.size(); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 831 | for (int i=0; i<N; i++) { |
| 832 | ActiveAdmin admin = mAdminList.get(i); |
| 833 | if (length < admin.minimumPasswordLength) { |
| 834 | length = admin.minimumPasswordLength; |
| 835 | } |
| 836 | } |
| 837 | return length; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 838 | } |
| 839 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 840 | |
| 841 | public void setPasswordHistoryLength(ComponentName who, int length) { |
| 842 | synchronized (this) { |
| 843 | if (who == null) { |
| 844 | throw new NullPointerException("ComponentName is null"); |
| 845 | } |
| 846 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 847 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 848 | if (ap.passwordHistoryLength != length) { |
| 849 | ap.passwordHistoryLength = length; |
| 850 | saveSettingsLocked(); |
| 851 | } |
| 852 | } |
| 853 | } |
| 854 | |
| 855 | public int getPasswordHistoryLength(ComponentName who) { |
| 856 | synchronized (this) { |
| 857 | int length = 0; |
| 858 | |
| 859 | if (who != null) { |
| 860 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 861 | return admin != null ? admin.passwordHistoryLength : length; |
| 862 | } |
| 863 | |
| 864 | final int N = mAdminList.size(); |
| 865 | for (int i = 0; i < N; i++) { |
| 866 | ActiveAdmin admin = mAdminList.get(i); |
| 867 | if (length < admin.passwordHistoryLength) { |
| 868 | length = admin.passwordHistoryLength; |
| 869 | } |
| 870 | } |
| 871 | return length; |
| 872 | } |
| 873 | } |
| 874 | |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 875 | public void setPasswordMinimumUpperCase(ComponentName who, int length) { |
| 876 | synchronized (this) { |
| 877 | if (who == null) { |
| 878 | throw new NullPointerException("ComponentName is null"); |
| 879 | } |
| 880 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 881 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 882 | if (ap.minimumPasswordUpperCase != length) { |
| 883 | ap.minimumPasswordUpperCase = length; |
| 884 | saveSettingsLocked(); |
| 885 | } |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | public int getPasswordMinimumUpperCase(ComponentName who) { |
| 890 | synchronized (this) { |
| 891 | int length = 0; |
| 892 | |
| 893 | if (who != null) { |
| 894 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 895 | return admin != null ? admin.minimumPasswordUpperCase : length; |
| 896 | } |
| 897 | |
| 898 | final int N = mAdminList.size(); |
| 899 | for (int i=0; i<N; i++) { |
| 900 | ActiveAdmin admin = mAdminList.get(i); |
| 901 | if (length < admin.minimumPasswordUpperCase) { |
| 902 | length = admin.minimumPasswordUpperCase; |
| 903 | } |
| 904 | } |
| 905 | return length; |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | public void setPasswordMinimumLowerCase(ComponentName who, int length) { |
| 910 | synchronized (this) { |
| 911 | if (who == null) { |
| 912 | throw new NullPointerException("ComponentName is null"); |
| 913 | } |
| 914 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 915 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 916 | if (ap.minimumPasswordLowerCase != length) { |
| 917 | ap.minimumPasswordLowerCase = length; |
| 918 | saveSettingsLocked(); |
| 919 | } |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | public int getPasswordMinimumLowerCase(ComponentName who) { |
| 924 | synchronized (this) { |
| 925 | int length = 0; |
| 926 | |
| 927 | if (who != null) { |
| 928 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 929 | return admin != null ? admin.minimumPasswordLowerCase : length; |
| 930 | } |
| 931 | |
| 932 | final int N = mAdminList.size(); |
| 933 | for (int i=0; i<N; i++) { |
| 934 | ActiveAdmin admin = mAdminList.get(i); |
| 935 | if (length < admin.minimumPasswordLowerCase) { |
| 936 | length = admin.minimumPasswordLowerCase; |
| 937 | } |
| 938 | } |
| 939 | return length; |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | public void setPasswordMinimumLetters(ComponentName who, int length) { |
| 944 | synchronized (this) { |
| 945 | if (who == null) { |
| 946 | throw new NullPointerException("ComponentName is null"); |
| 947 | } |
| 948 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 949 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 950 | if (ap.minimumPasswordLetters != length) { |
| 951 | ap.minimumPasswordLetters = length; |
| 952 | saveSettingsLocked(); |
| 953 | } |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | public int getPasswordMinimumLetters(ComponentName who) { |
| 958 | synchronized (this) { |
| 959 | int length = 0; |
| 960 | |
| 961 | if (who != null) { |
| 962 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 963 | return admin != null ? admin.minimumPasswordLetters : length; |
| 964 | } |
| 965 | |
| 966 | final int N = mAdminList.size(); |
| 967 | for (int i=0; i<N; i++) { |
| 968 | ActiveAdmin admin = mAdminList.get(i); |
| 969 | if (length < admin.minimumPasswordLetters) { |
| 970 | length = admin.minimumPasswordLetters; |
| 971 | } |
| 972 | } |
| 973 | return length; |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | public void setPasswordMinimumNumeric(ComponentName who, int length) { |
| 978 | synchronized (this) { |
| 979 | if (who == null) { |
| 980 | throw new NullPointerException("ComponentName is null"); |
| 981 | } |
| 982 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 983 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 984 | if (ap.minimumPasswordNumeric != length) { |
| 985 | ap.minimumPasswordNumeric = length; |
| 986 | saveSettingsLocked(); |
| 987 | } |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | public int getPasswordMinimumNumeric(ComponentName who) { |
| 992 | synchronized (this) { |
| 993 | int length = 0; |
| 994 | |
| 995 | if (who != null) { |
| 996 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 997 | return admin != null ? admin.minimumPasswordNumeric : length; |
| 998 | } |
| 999 | |
| 1000 | final int N = mAdminList.size(); |
| 1001 | for (int i = 0; i < N; i++) { |
| 1002 | ActiveAdmin admin = mAdminList.get(i); |
| 1003 | if (length < admin.minimumPasswordNumeric) { |
| 1004 | length = admin.minimumPasswordNumeric; |
| 1005 | } |
| 1006 | } |
| 1007 | return length; |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | public void setPasswordMinimumSymbols(ComponentName who, int length) { |
| 1012 | synchronized (this) { |
| 1013 | if (who == null) { |
| 1014 | throw new NullPointerException("ComponentName is null"); |
| 1015 | } |
| 1016 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1017 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 1018 | if (ap.minimumPasswordSymbols != length) { |
| 1019 | ap.minimumPasswordSymbols = length; |
| 1020 | saveSettingsLocked(); |
| 1021 | } |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | public int getPasswordMinimumSymbols(ComponentName who) { |
| 1026 | synchronized (this) { |
| 1027 | int length = 0; |
| 1028 | |
| 1029 | if (who != null) { |
| 1030 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 1031 | return admin != null ? admin.minimumPasswordSymbols : length; |
| 1032 | } |
| 1033 | |
| 1034 | final int N = mAdminList.size(); |
| 1035 | for (int i=0; i<N; i++) { |
| 1036 | ActiveAdmin admin = mAdminList.get(i); |
| 1037 | if (length < admin.minimumPasswordSymbols) { |
| 1038 | length = admin.minimumPasswordSymbols; |
| 1039 | } |
| 1040 | } |
| 1041 | return length; |
| 1042 | } |
| 1043 | } |
| 1044 | |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1045 | public void setPasswordMinimumNonLetter(ComponentName who, int length) { |
| 1046 | synchronized (this) { |
| 1047 | if (who == null) { |
| 1048 | throw new NullPointerException("ComponentName is null"); |
| 1049 | } |
| 1050 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1051 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 1052 | if (ap.minimumPasswordNonLetter != length) { |
| 1053 | ap.minimumPasswordNonLetter = length; |
| 1054 | saveSettingsLocked(); |
| 1055 | } |
| 1056 | } |
| 1057 | } |
| 1058 | |
| 1059 | public int getPasswordMinimumNonLetter(ComponentName who) { |
| 1060 | synchronized (this) { |
| 1061 | int length = 0; |
| 1062 | |
| 1063 | if (who != null) { |
| 1064 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 1065 | return admin != null ? admin.minimumPasswordNonLetter : length; |
| 1066 | } |
| 1067 | |
| 1068 | final int N = mAdminList.size(); |
| 1069 | for (int i=0; i<N; i++) { |
| 1070 | ActiveAdmin admin = mAdminList.get(i); |
| 1071 | if (length < admin.minimumPasswordNonLetter) { |
| 1072 | length = admin.minimumPasswordNonLetter; |
| 1073 | } |
| 1074 | } |
| 1075 | return length; |
| 1076 | } |
| 1077 | } |
| 1078 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1079 | public boolean isActivePasswordSufficient() { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1080 | synchronized (this) { |
| 1081 | // This API can only be called by an active device admin, |
| 1082 | // so try to retrieve it to check that the caller is one. |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1083 | getActiveAdminForCallerLocked(null, |
| 1084 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1085 | if (mActivePasswordQuality < getPasswordQuality(null) |
| 1086 | || mActivePasswordLength < getPasswordMinimumLength(null)) { |
| 1087 | return false; |
| 1088 | } |
| 1089 | if(mActivePasswordQuality != DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) { |
| 1090 | return true; |
| 1091 | } |
| 1092 | return mActivePasswordUpperCase >= getPasswordMinimumUpperCase(null) |
| 1093 | && mActivePasswordLowerCase >= getPasswordMinimumLowerCase(null) |
| 1094 | && mActivePasswordLetters >= getPasswordMinimumLetters(null) |
| 1095 | && mActivePasswordNumeric >= getPasswordMinimumNumeric(null) |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1096 | && mActivePasswordSymbols >= getPasswordMinimumSymbols(null) |
| 1097 | && mActivePasswordNonLetter >= getPasswordMinimumNonLetter(null); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1098 | } |
| 1099 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1100 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1101 | public int getCurrentFailedPasswordAttempts() { |
| 1102 | synchronized (this) { |
| 1103 | // This API can only be called by an active device admin, |
| 1104 | // so try to retrieve it to check that the caller is one. |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1105 | getActiveAdminForCallerLocked(null, |
| 1106 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1107 | return mFailedPasswordAttempts; |
| 1108 | } |
| 1109 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1110 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1111 | public void setMaximumFailedPasswordsForWipe(ComponentName who, int num) { |
| 1112 | synchronized (this) { |
| 1113 | // This API can only be called by an active device admin, |
| 1114 | // so try to retrieve it to check that the caller is one. |
| 1115 | getActiveAdminForCallerLocked(who, |
| 1116 | DeviceAdminInfo.USES_POLICY_WIPE_DATA); |
| 1117 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1118 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN); |
| 1119 | if (ap.maximumFailedPasswordsForWipe != num) { |
| 1120 | ap.maximumFailedPasswordsForWipe = num; |
| 1121 | saveSettingsLocked(); |
| 1122 | } |
| 1123 | } |
| 1124 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1125 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1126 | public int getMaximumFailedPasswordsForWipe(ComponentName who) { |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1127 | synchronized (this) { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1128 | int count = 0; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1129 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1130 | if (who != null) { |
| 1131 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 1132 | return admin != null ? admin.maximumFailedPasswordsForWipe : count; |
| 1133 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1134 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1135 | final int N = mAdminList.size(); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1136 | for (int i=0; i<N; i++) { |
| 1137 | ActiveAdmin admin = mAdminList.get(i); |
| 1138 | if (count == 0) { |
| 1139 | count = admin.maximumFailedPasswordsForWipe; |
| 1140 | } else if (admin.maximumFailedPasswordsForWipe != 0 |
| 1141 | && count > admin.maximumFailedPasswordsForWipe) { |
| 1142 | count = admin.maximumFailedPasswordsForWipe; |
| 1143 | } |
| 1144 | } |
| 1145 | return count; |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1146 | } |
| 1147 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1148 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1149 | public boolean resetPassword(String password, int flags) { |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1150 | int quality; |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1151 | synchronized (this) { |
| 1152 | // This API can only be called by an active device admin, |
| 1153 | // so try to retrieve it to check that the caller is one. |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1154 | getActiveAdminForCallerLocked(null, |
| 1155 | DeviceAdminInfo.USES_POLICY_RESET_PASSWORD); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1156 | quality = getPasswordQuality(null); |
| 1157 | if (quality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1158 | int realQuality = LockPatternUtils.computePasswordQuality(password); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1159 | if (realQuality < quality |
| 1160 | && quality != DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1161 | Slog.w(TAG, "resetPassword: password quality 0x" |
| 1162 | + Integer.toHexString(quality) |
| 1163 | + " does not meet required quality 0x" |
| 1164 | + Integer.toHexString(quality)); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1165 | return false; |
| 1166 | } |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1167 | quality = Math.max(realQuality, quality); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1168 | } |
| 1169 | int length = getPasswordMinimumLength(null); |
| 1170 | if (password.length() < length) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1171 | Slog.w(TAG, "resetPassword: password length " + password.length() |
| 1172 | + " does not meet required length " + length); |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1173 | return false; |
| 1174 | } |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1175 | if (quality == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) { |
| 1176 | int letters = 0; |
| 1177 | int uppercase = 0; |
| 1178 | int lowercase = 0; |
| 1179 | int numbers = 0; |
| 1180 | int symbols = 0; |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1181 | int nonletter = 0; |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1182 | for (int i = 0; i < password.length(); i++) { |
| 1183 | char c = password.charAt(i); |
| 1184 | if (c >= 'A' && c <= 'Z') { |
| 1185 | letters++; |
| 1186 | uppercase++; |
| 1187 | } else if (c >= 'a' && c <= 'z') { |
| 1188 | letters++; |
| 1189 | lowercase++; |
| 1190 | } else if (c >= '0' && c <= '9') { |
| 1191 | numbers++; |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1192 | nonletter++; |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1193 | } else { |
| 1194 | symbols++; |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1195 | nonletter++; |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1196 | } |
| 1197 | } |
| 1198 | int neededLetters = getPasswordMinimumLetters(null); |
| 1199 | if(letters < neededLetters) { |
| 1200 | Slog.w(TAG, "resetPassword: number of letters " + letters |
| 1201 | + " does not meet required number of letters " + neededLetters); |
| 1202 | return false; |
| 1203 | } |
| 1204 | int neededNumbers = getPasswordMinimumNumeric(null); |
| 1205 | if (numbers < neededNumbers) { |
| 1206 | Slog |
| 1207 | .w(TAG, "resetPassword: number of numerical digits " + numbers |
| 1208 | + " does not meet required number of numerical digits " |
| 1209 | + neededNumbers); |
| 1210 | return false; |
| 1211 | } |
| 1212 | int neededLowerCase = getPasswordMinimumLowerCase(null); |
| 1213 | if (lowercase < neededLowerCase) { |
| 1214 | Slog.w(TAG, "resetPassword: number of lowercase letters " + lowercase |
| 1215 | + " does not meet required number of lowercase letters " |
| 1216 | + neededLowerCase); |
| 1217 | return false; |
| 1218 | } |
| 1219 | int neededUpperCase = getPasswordMinimumUpperCase(null); |
| 1220 | if (uppercase < neededUpperCase) { |
| 1221 | Slog.w(TAG, "resetPassword: number of uppercase letters " + uppercase |
| 1222 | + " does not meet required number of uppercase letters " |
| 1223 | + neededUpperCase); |
| 1224 | return false; |
| 1225 | } |
| 1226 | int neededSymbols = getPasswordMinimumSymbols(null); |
| 1227 | if (symbols < neededSymbols) { |
| 1228 | Slog.w(TAG, "resetPassword: number of special symbols " + symbols |
| 1229 | + " does not meet required number of special symbols " + neededSymbols); |
| 1230 | return false; |
| 1231 | } |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1232 | int neededNonLetter = getPasswordMinimumNonLetter(null); |
| 1233 | if (nonletter < neededNonLetter) { |
| 1234 | Slog.w(TAG, "resetPassword: number of non-letter characters " + nonletter |
| 1235 | + " does not meet required number of non-letter characters " |
| 1236 | + neededNonLetter); |
| 1237 | return false; |
| 1238 | } |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | LockPatternUtils utils = new LockPatternUtils(mContext); |
| 1242 | if(utils.checkPasswordHistory(password)) { |
| 1243 | Slog.w(TAG, "resetPassword: password is the same as one of the last " |
| 1244 | + getPasswordHistoryLength(null) + " passwords"); |
| 1245 | return false; |
| 1246 | } |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1247 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1248 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1249 | int callingUid = Binder.getCallingUid(); |
| 1250 | if (mPasswordOwner >= 0 && mPasswordOwner != callingUid) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1251 | 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] | 1252 | return false; |
| 1253 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1254 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1255 | // Don't do this with the lock held, because it is going to call |
| 1256 | // back in to the service. |
| 1257 | long ident = Binder.clearCallingIdentity(); |
| 1258 | try { |
| 1259 | LockPatternUtils utils = new LockPatternUtils(mContext); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1260 | utils.saveLockPassword(password, quality); |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1261 | synchronized (this) { |
| 1262 | int newOwner = (flags&DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY) |
| 1263 | != 0 ? callingUid : -1; |
| 1264 | if (mPasswordOwner != newOwner) { |
| 1265 | mPasswordOwner = newOwner; |
| 1266 | saveSettingsLocked(); |
| 1267 | } |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1268 | } |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1269 | } finally { |
| 1270 | Binder.restoreCallingIdentity(ident); |
| 1271 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1272 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1273 | return true; |
| 1274 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1275 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1276 | public void setMaximumTimeToLock(ComponentName who, long timeMs) { |
| 1277 | synchronized (this) { |
| 1278 | if (who == null) { |
| 1279 | throw new NullPointerException("ComponentName is null"); |
| 1280 | } |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1281 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 1282 | DeviceAdminInfo.USES_POLICY_FORCE_LOCK); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1283 | if (ap.maximumTimeToUnlock != timeMs) { |
| 1284 | ap.maximumTimeToUnlock = timeMs; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1285 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1286 | long ident = Binder.clearCallingIdentity(); |
| 1287 | try { |
| 1288 | saveSettingsLocked(); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1289 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1290 | timeMs = getMaximumTimeToLock(null); |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1291 | if (timeMs <= 0) { |
| 1292 | timeMs = Integer.MAX_VALUE; |
| 1293 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1294 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1295 | try { |
| 1296 | getIPowerManager().setMaximumScreenOffTimeount((int)timeMs); |
| 1297 | } catch (RemoteException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1298 | Slog.w(TAG, "Failure talking with power manager", e); |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1299 | } |
| 1300 | } finally { |
| 1301 | Binder.restoreCallingIdentity(ident); |
| 1302 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1303 | } |
| 1304 | } |
| 1305 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1306 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1307 | public long getMaximumTimeToLock(ComponentName who) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1308 | synchronized (this) { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1309 | long time = 0; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1310 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1311 | if (who != null) { |
| 1312 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 1313 | return admin != null ? admin.maximumTimeToUnlock : time; |
| 1314 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1315 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1316 | final int N = mAdminList.size(); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1317 | for (int i=0; i<N; i++) { |
| 1318 | ActiveAdmin admin = mAdminList.get(i); |
| 1319 | if (time == 0) { |
| 1320 | time = admin.maximumTimeToUnlock; |
| 1321 | } else if (admin.maximumTimeToUnlock != 0 |
| 1322 | && time > admin.maximumTimeToUnlock) { |
| 1323 | time = admin.maximumTimeToUnlock; |
| 1324 | } |
| 1325 | } |
| 1326 | return time; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1327 | } |
| 1328 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1329 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1330 | public void lockNow() { |
| 1331 | synchronized (this) { |
| 1332 | // This API can only be called by an active device admin, |
| 1333 | // so try to retrieve it to check that the caller is one. |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1334 | getActiveAdminForCallerLocked(null, |
| 1335 | DeviceAdminInfo.USES_POLICY_FORCE_LOCK); |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1336 | long ident = Binder.clearCallingIdentity(); |
| 1337 | try { |
| 1338 | mIPowerManager.goToSleepWithReason(SystemClock.uptimeMillis(), |
| 1339 | WindowManagerPolicy.OFF_BECAUSE_OF_ADMIN); |
| 1340 | } catch (RemoteException e) { |
| 1341 | } finally { |
| 1342 | Binder.restoreCallingIdentity(ident); |
| 1343 | } |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1344 | } |
| 1345 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1346 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1347 | void wipeDataLocked(int flags) { |
| 1348 | try { |
| 1349 | RecoverySystem.rebootWipeUserData(mContext); |
| 1350 | } catch (IOException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1351 | Slog.w(TAG, "Failed requesting data wipe", e); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1352 | } |
| 1353 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1354 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1355 | public void wipeData(int flags) { |
| 1356 | synchronized (this) { |
| 1357 | // This API can only be called by an active device admin, |
| 1358 | // so try to retrieve it to check that the caller is one. |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1359 | getActiveAdminForCallerLocked(null, |
| 1360 | DeviceAdminInfo.USES_POLICY_WIPE_DATA); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1361 | long ident = Binder.clearCallingIdentity(); |
| 1362 | try { |
| 1363 | wipeDataLocked(flags); |
| 1364 | } finally { |
| 1365 | Binder.restoreCallingIdentity(ident); |
| 1366 | } |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1367 | } |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1368 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1369 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1370 | public void getRemoveWarning(ComponentName comp, final RemoteCallback result) { |
| 1371 | mContext.enforceCallingOrSelfPermission( |
| 1372 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1373 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1374 | synchronized (this) { |
| 1375 | ActiveAdmin admin = getActiveAdminUncheckedLocked(comp); |
| 1376 | if (admin == null) { |
| 1377 | try { |
| 1378 | result.sendResult(null); |
| 1379 | } catch (RemoteException e) { |
| 1380 | } |
| 1381 | return; |
| 1382 | } |
| Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1383 | Intent intent = new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_DISABLE_REQUESTED); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1384 | intent.setComponent(admin.info.getComponent()); |
| 1385 | mContext.sendOrderedBroadcast(intent, null, new BroadcastReceiver() { |
| 1386 | @Override |
| 1387 | public void onReceive(Context context, Intent intent) { |
| 1388 | try { |
| 1389 | result.sendResult(getResultExtras(false)); |
| 1390 | } catch (RemoteException e) { |
| 1391 | } |
| 1392 | } |
| 1393 | }, null, Activity.RESULT_OK, null, null); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1394 | } |
| 1395 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1396 | |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1397 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1398 | int lowercase, int numbers, int symbols, int nonletter) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1399 | mContext.enforceCallingOrSelfPermission( |
| 1400 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1401 | |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1402 | validateQualityConstant(quality); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1403 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1404 | synchronized (this) { |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1405 | if (mActivePasswordQuality != quality || mActivePasswordLength != length |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1406 | || mFailedPasswordAttempts != 0 || mActivePasswordLetters != letters |
| 1407 | || mActivePasswordUpperCase != uppercase |
| 1408 | || mActivePasswordLowerCase != lowercase || mActivePasswordNumeric != numbers |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1409 | || mActivePasswordSymbols != symbols || mActivePasswordNonLetter != nonletter) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1410 | long ident = Binder.clearCallingIdentity(); |
| 1411 | try { |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1412 | mActivePasswordQuality = quality; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1413 | mActivePasswordLength = length; |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1414 | mActivePasswordLetters = letters; |
| 1415 | mActivePasswordLowerCase = lowercase; |
| 1416 | mActivePasswordUpperCase = uppercase; |
| 1417 | mActivePasswordNumeric = numbers; |
| 1418 | mActivePasswordSymbols = symbols; |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1419 | mActivePasswordNonLetter = nonletter; |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1420 | mFailedPasswordAttempts = 0; |
| 1421 | saveSettingsLocked(); |
| Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1422 | sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_CHANGED, |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1423 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1424 | } finally { |
| 1425 | Binder.restoreCallingIdentity(ident); |
| 1426 | } |
| 1427 | } |
| 1428 | } |
| 1429 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1430 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1431 | public void reportFailedPasswordAttempt() { |
| 1432 | mContext.enforceCallingOrSelfPermission( |
| 1433 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1434 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1435 | synchronized (this) { |
| 1436 | long ident = Binder.clearCallingIdentity(); |
| 1437 | try { |
| 1438 | mFailedPasswordAttempts++; |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1439 | saveSettingsLocked(); |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1440 | int max = getMaximumFailedPasswordsForWipe(null); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1441 | if (max > 0 && mFailedPasswordAttempts >= max) { |
| 1442 | wipeDataLocked(0); |
| 1443 | } |
| Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1444 | sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_FAILED, |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1445 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1446 | } finally { |
| 1447 | Binder.restoreCallingIdentity(ident); |
| 1448 | } |
| 1449 | } |
| 1450 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1451 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1452 | public void reportSuccessfulPasswordAttempt() { |
| 1453 | mContext.enforceCallingOrSelfPermission( |
| 1454 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1455 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1456 | synchronized (this) { |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1457 | if (mFailedPasswordAttempts != 0 || mPasswordOwner >= 0) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1458 | long ident = Binder.clearCallingIdentity(); |
| 1459 | try { |
| 1460 | mFailedPasswordAttempts = 0; |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1461 | mPasswordOwner = -1; |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1462 | saveSettingsLocked(); |
| Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1463 | sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_SUCCEEDED, |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1464 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1465 | } finally { |
| 1466 | Binder.restoreCallingIdentity(ident); |
| 1467 | } |
| 1468 | } |
| 1469 | } |
| 1470 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1471 | |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 1472 | public ComponentName setGlobalProxy(ComponentName who, String proxySpec, |
| 1473 | String exclusionList) { |
| 1474 | synchronized(this) { |
| 1475 | if (who == null) { |
| 1476 | throw new NullPointerException("ComponentName is null"); |
| 1477 | } |
| 1478 | |
| 1479 | ActiveAdmin admin = getActiveAdminForCallerLocked(who, |
| 1480 | DeviceAdminInfo.USES_POLICY_SETS_GLOBAL_PROXY); |
| 1481 | |
| 1482 | // Scan through active admins and find if anyone has already |
| 1483 | // set the global proxy. |
| 1484 | final int N = mAdminList.size(); |
| 1485 | Set<ComponentName> compSet = mAdminMap.keySet(); |
| 1486 | for (ComponentName component : compSet) { |
| 1487 | ActiveAdmin ap = mAdminMap.get(component); |
| 1488 | if ((ap.specifiesGlobalProxy) && (!component.equals(who))) { |
| 1489 | // Another admin already sets the global proxy |
| 1490 | // Return it to the caller. |
| 1491 | return component; |
| 1492 | } |
| 1493 | } |
| 1494 | if (proxySpec == null) { |
| 1495 | admin.specifiesGlobalProxy = false; |
| 1496 | admin.globalProxySpec = null; |
| 1497 | admin.globalProxyExclusionList = null; |
| 1498 | } else { |
| 1499 | |
| 1500 | admin.specifiesGlobalProxy = true; |
| 1501 | admin.globalProxySpec = proxySpec; |
| 1502 | admin.globalProxyExclusionList = exclusionList; |
| 1503 | } |
| 1504 | |
| 1505 | // Reset the global proxy accordingly |
| 1506 | // Do this using system permissions, as apps cannot write to secure settings |
| 1507 | long origId = Binder.clearCallingIdentity(); |
| 1508 | resetGlobalProxy(); |
| 1509 | Binder.restoreCallingIdentity(origId); |
| 1510 | return null; |
| 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | public ComponentName getGlobalProxyAdmin() { |
| 1515 | synchronized(this) { |
| 1516 | // Scan through active admins and find if anyone has already |
| 1517 | // set the global proxy. |
| 1518 | final int N = mAdminList.size(); |
| 1519 | for (int i = 0; i < N; i++) { |
| 1520 | ActiveAdmin ap = mAdminList.get(i); |
| 1521 | if (ap.specifiesGlobalProxy) { |
| 1522 | // Device admin sets the global proxy |
| 1523 | // Return it to the caller. |
| 1524 | return ap.info.getComponent(); |
| 1525 | } |
| 1526 | } |
| 1527 | } |
| 1528 | // No device admin sets the global proxy. |
| 1529 | return null; |
| 1530 | } |
| 1531 | |
| 1532 | private void resetGlobalProxy() { |
| 1533 | final int N = mAdminList.size(); |
| 1534 | for (int i = 0; i < N; i++) { |
| 1535 | ActiveAdmin ap = mAdminList.get(i); |
| 1536 | if (ap.specifiesGlobalProxy) { |
| 1537 | saveGlobalProxy(ap.globalProxySpec, ap.globalProxyExclusionList); |
| 1538 | return; |
| 1539 | } |
| 1540 | } |
| 1541 | // No device admins defining global proxies - reset global proxy settings to none |
| 1542 | saveGlobalProxy(null, null); |
| 1543 | } |
| 1544 | |
| 1545 | private void saveGlobalProxy(String proxySpec, String exclusionList) { |
| 1546 | if (exclusionList == null) { |
| 1547 | exclusionList = ""; |
| 1548 | } |
| 1549 | if (proxySpec == null) { |
| 1550 | proxySpec = ""; |
| 1551 | } |
| 1552 | // Remove white spaces |
| 1553 | proxySpec = proxySpec.trim(); |
| 1554 | exclusionList = exclusionList.trim(); |
| 1555 | ContentResolver res = mContext.getContentResolver(); |
| 1556 | Settings.Secure.putString(res, Settings.Secure.HTTP_PROXY, proxySpec); |
| 1557 | Settings.Secure.putString(res, Settings.Secure.HTTP_PROXY_EXCLUSION_LIST, exclusionList); |
| 1558 | } |
| 1559 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1560 | @Override |
| 1561 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1562 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 1563 | != PackageManager.PERMISSION_GRANTED) { |
| 1564 | |
| 1565 | pw.println("Permission Denial: can't dump DevicePolicyManagerService from from pid=" |
| 1566 | + Binder.getCallingPid() |
| 1567 | + ", uid=" + Binder.getCallingUid()); |
| 1568 | return; |
| 1569 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1570 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1571 | final Printer p = new PrintWriterPrinter(pw); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1572 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1573 | synchronized (this) { |
| 1574 | p.println("Current Device Policy Manager state:"); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1575 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1576 | p.println(" Enabled Device Admins:"); |
| 1577 | final int N = mAdminList.size(); |
| 1578 | for (int i=0; i<N; i++) { |
| 1579 | ActiveAdmin ap = mAdminList.get(i); |
| 1580 | if (ap != null) { |
| 1581 | pw.print(" "); pw.print(ap.info.getComponent().flattenToShortString()); |
| 1582 | pw.println(":"); |
| 1583 | ap.dump(" ", pw); |
| 1584 | } |
| 1585 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1586 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1587 | pw.println(" "); |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1588 | pw.print(" mActivePasswordQuality=0x"); |
| 1589 | pw.println(Integer.toHexString(mActivePasswordQuality)); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1590 | pw.print(" mActivePasswordLength="); pw.println(mActivePasswordLength); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1591 | pw.print(" mActivePasswordUpperCase="); pw.println(mActivePasswordUpperCase); |
| 1592 | pw.print(" mActivePasswordLowerCase="); pw.println(mActivePasswordLowerCase); |
| 1593 | pw.print(" mActivePasswordLetters="); pw.println(mActivePasswordLetters); |
| 1594 | pw.print(" mActivePasswordNumeric="); pw.println(mActivePasswordNumeric); |
| 1595 | pw.print(" mActivePasswordSymbols="); pw.println(mActivePasswordSymbols); |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1596 | pw.print(" mActivePasswordNonLetter="); pw.println(mActivePasswordNonLetter); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1597 | pw.print(" mFailedPasswordAttempts="); pw.println(mFailedPasswordAttempts); |
| 1598 | pw.print(" mPasswordOwner="); pw.println(mPasswordOwner); |
| 1599 | } |
| 1600 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1601 | } |