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