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