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(); |
| 450 | } catch (IOException e) { |
| 451 | try { |
| 452 | if (stream != null) { |
| 453 | stream.close(); |
| 454 | } |
| 455 | } catch (IOException ex) { |
| 456 | // Ignore |
| 457 | } |
| 458 | journal.rollback(); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | private void loadSettingsLocked() { |
| 463 | JournaledFile journal = makeJournaledFile(); |
| 464 | FileInputStream stream = null; |
| 465 | File file = journal.chooseForRead(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 466 | try { |
| 467 | stream = new FileInputStream(file); |
| 468 | XmlPullParser parser = Xml.newPullParser(); |
| 469 | parser.setInput(stream, null); |
| 470 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 471 | int type; |
| 472 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 473 | && type != XmlPullParser.START_TAG) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 474 | } |
| 475 | String tag = parser.getName(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 476 | if (!"policies".equals(tag)) { |
| 477 | throw new XmlPullParserException( |
| 478 | "Settings do not start with policies tag: found " + tag); |
| 479 | } |
| 480 | type = parser.next(); |
| 481 | int outerDepth = parser.getDepth(); |
| 482 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 483 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 484 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 485 | continue; |
| 486 | } |
| 487 | tag = parser.getName(); |
| 488 | if ("admin".equals(tag)) { |
Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 489 | String name = parser.getAttributeValue(null, "name"); |
| 490 | try { |
| 491 | DeviceAdminInfo dai = findAdmin( |
| 492 | ComponentName.unflattenFromString(name)); |
| 493 | if (dai != null) { |
| 494 | ActiveAdmin ap = new ActiveAdmin(dai); |
| 495 | ap.readFromXml(parser); |
| 496 | mAdminMap.put(ap.info.getComponent(), ap); |
| 497 | mAdminList.add(ap); |
| 498 | } |
| 499 | } catch (RuntimeException e) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 500 | Slog.w(TAG, "Failed loading admin " + name, e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 501 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 502 | } else if ("failed-password-attempts".equals(tag)) { |
| 503 | mFailedPasswordAttempts = Integer.parseInt( |
| 504 | parser.getAttributeValue(null, "value")); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 505 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 506 | } else if ("password-owner".equals(tag)) { |
| 507 | mPasswordOwner = Integer.parseInt( |
| 508 | parser.getAttributeValue(null, "value")); |
| 509 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 510 | } else if ("active-password".equals(tag)) { |
| 511 | mActivePasswordQuality = Integer.parseInt( |
| 512 | parser.getAttributeValue(null, "quality")); |
| 513 | mActivePasswordLength = Integer.parseInt( |
| 514 | parser.getAttributeValue(null, "length")); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame^] | 515 | mActivePasswordUpperCase = Integer.parseInt( |
| 516 | parser.getAttributeValue(null, "uppercase")); |
| 517 | mActivePasswordLowerCase = Integer.parseInt( |
| 518 | parser.getAttributeValue(null, "lowercase")); |
| 519 | mActivePasswordLetters = Integer.parseInt( |
| 520 | parser.getAttributeValue(null, "letters")); |
| 521 | mActivePasswordNumeric = Integer.parseInt( |
| 522 | parser.getAttributeValue(null, "numeric")); |
| 523 | mActivePasswordSymbols = Integer.parseInt( |
| 524 | parser.getAttributeValue(null, "symbols")); |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 525 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 526 | } else { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 527 | Slog.w(TAG, "Unknown tag: " + tag); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 528 | XmlUtils.skipCurrentTag(parser); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 529 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 530 | } |
| 531 | } catch (NullPointerException e) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 532 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 533 | } catch (NumberFormatException e) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 534 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 535 | } catch (XmlPullParserException e) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 536 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 537 | } catch (IOException e) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 538 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 539 | } catch (IndexOutOfBoundsException e) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 540 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 541 | } |
| 542 | try { |
| 543 | if (stream != null) { |
| 544 | stream.close(); |
| 545 | } |
| 546 | } catch (IOException e) { |
| 547 | // Ignore |
| 548 | } |
| 549 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 550 | // Validate that what we stored for the password quality matches |
| 551 | // sufficiently what is currently set. Note that this is only |
| 552 | // a sanity check in case the two get out of sync; this should |
| 553 | // never normally happen. |
| 554 | LockPatternUtils utils = new LockPatternUtils(mContext); |
| 555 | if (utils.getActivePasswordQuality() < mActivePasswordQuality) { |
| 556 | Slog.w(TAG, "Active password quality 0x" |
| 557 | + Integer.toHexString(mActivePasswordQuality) |
| 558 | + " does not match actual quality 0x" |
| 559 | + Integer.toHexString(utils.getActivePasswordQuality())); |
| 560 | mActivePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
| 561 | mActivePasswordLength = 0; |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame^] | 562 | mActivePasswordUpperCase = 0; |
| 563 | mActivePasswordLowerCase = 0; |
| 564 | mActivePasswordLetters = 0; |
| 565 | mActivePasswordNumeric = 0; |
| 566 | mActivePasswordSymbols = 0; |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 567 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 568 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 569 | validatePasswordOwnerLocked(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 570 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 571 | long timeMs = getMaximumTimeToLock(null); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 572 | if (timeMs <= 0) { |
| 573 | timeMs = Integer.MAX_VALUE; |
| 574 | } |
| 575 | try { |
| 576 | getIPowerManager().setMaximumScreenOffTimeount((int)timeMs); |
| 577 | } catch (RemoteException e) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 578 | Slog.w(TAG, "Failure talking with power manager", e); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 579 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 580 | } |
| 581 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 582 | static void validateQualityConstant(int quality) { |
| 583 | switch (quality) { |
| 584 | case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED: |
| 585 | case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: |
| 586 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: |
| 587 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: |
| 588 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame^] | 589 | case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX: |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 590 | return; |
| 591 | } |
| 592 | throw new IllegalArgumentException("Invalid quality constant: 0x" |
| 593 | + Integer.toHexString(quality)); |
| 594 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 595 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 596 | void validatePasswordOwnerLocked() { |
| 597 | if (mPasswordOwner >= 0) { |
| 598 | boolean haveOwner = false; |
| 599 | for (int i=mAdminList.size()-1; i>=0; i--) { |
| 600 | if (mAdminList.get(i).getUid() == mPasswordOwner) { |
| 601 | haveOwner = true; |
| 602 | break; |
| 603 | } |
| 604 | } |
| 605 | if (!haveOwner) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 606 | Slog.w(TAG, "Previous password owner " + mPasswordOwner |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 607 | + " no longer active; disabling"); |
| 608 | mPasswordOwner = -1; |
| 609 | } |
| 610 | } |
| 611 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 612 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 613 | public void systemReady() { |
| 614 | synchronized (this) { |
| 615 | loadSettingsLocked(); |
| 616 | } |
| 617 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 618 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 619 | public void setActiveAdmin(ComponentName adminReceiver) { |
| 620 | mContext.enforceCallingOrSelfPermission( |
| 621 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 622 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 623 | DeviceAdminInfo info = findAdmin(adminReceiver); |
| 624 | if (info == null) { |
| 625 | throw new IllegalArgumentException("Bad admin: " + adminReceiver); |
| 626 | } |
| 627 | synchronized (this) { |
| 628 | long ident = Binder.clearCallingIdentity(); |
| 629 | try { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 630 | if (getActiveAdminUncheckedLocked(adminReceiver) != null) { |
| 631 | throw new IllegalArgumentException("Admin is already added"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 632 | } |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 633 | ActiveAdmin admin = new ActiveAdmin(info); |
| 634 | mAdminMap.put(adminReceiver, admin); |
| 635 | mAdminList.add(admin); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 636 | saveSettingsLocked(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 637 | sendAdminCommandLocked(admin, |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 638 | DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 639 | } finally { |
| 640 | Binder.restoreCallingIdentity(ident); |
| 641 | } |
| 642 | } |
| 643 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 644 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 645 | public boolean isAdminActive(ComponentName adminReceiver) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 646 | synchronized (this) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 647 | return getActiveAdminUncheckedLocked(adminReceiver) != null; |
| 648 | } |
| 649 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 650 | |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 651 | public List<ComponentName> getActiveAdmins() { |
| 652 | synchronized (this) { |
| 653 | final int N = mAdminList.size(); |
| 654 | if (N <= 0) { |
| 655 | return null; |
| 656 | } |
| 657 | ArrayList<ComponentName> res = new ArrayList<ComponentName>(N); |
| 658 | for (int i=0; i<N; i++) { |
| 659 | res.add(mAdminList.get(i).info.getComponent()); |
| 660 | } |
| 661 | return res; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 662 | } |
| 663 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 664 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 665 | public boolean packageHasActiveAdmins(String packageName) { |
| 666 | synchronized (this) { |
| 667 | final int N = mAdminList.size(); |
| 668 | for (int i=0; i<N; i++) { |
| 669 | if (mAdminList.get(i).info.getPackageName().equals(packageName)) { |
| 670 | return true; |
| 671 | } |
| 672 | } |
| 673 | return false; |
| 674 | } |
| 675 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 676 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 677 | public void removeActiveAdmin(ComponentName adminReceiver) { |
| 678 | synchronized (this) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 679 | ActiveAdmin admin = getActiveAdminUncheckedLocked(adminReceiver); |
| 680 | if (admin == null) { |
| 681 | return; |
| 682 | } |
| 683 | if (admin.getUid() != Binder.getCallingUid()) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 684 | mContext.enforceCallingOrSelfPermission( |
| 685 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
| 686 | } |
| 687 | long ident = Binder.clearCallingIdentity(); |
| 688 | try { |
| 689 | removeActiveAdminLocked(adminReceiver); |
| 690 | } finally { |
| 691 | Binder.restoreCallingIdentity(ident); |
| 692 | } |
| 693 | } |
| 694 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 695 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 696 | public void setPasswordQuality(ComponentName who, int quality) { |
| 697 | validateQualityConstant(quality); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 698 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 699 | synchronized (this) { |
| 700 | if (who == null) { |
| 701 | throw new NullPointerException("ComponentName is null"); |
| 702 | } |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 703 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 704 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 705 | if (ap.passwordQuality != quality) { |
| 706 | ap.passwordQuality = quality; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 707 | saveSettingsLocked(); |
| 708 | } |
| 709 | } |
| 710 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 711 | |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 712 | public int getPasswordQuality(ComponentName who) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 713 | synchronized (this) { |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 714 | int mode = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 715 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 716 | if (who != null) { |
| 717 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 718 | return admin != null ? admin.passwordQuality : mode; |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 719 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 720 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 721 | final int N = mAdminList.size(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 722 | for (int i=0; i<N; i++) { |
| 723 | ActiveAdmin admin = mAdminList.get(i); |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 724 | if (mode < admin.passwordQuality) { |
| 725 | mode = admin.passwordQuality; |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | return mode; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 729 | } |
| 730 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 731 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 732 | public void setPasswordMinimumLength(ComponentName who, int length) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 733 | synchronized (this) { |
| 734 | if (who == null) { |
| 735 | throw new NullPointerException("ComponentName is null"); |
| 736 | } |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 737 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 738 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 739 | if (ap.minimumPasswordLength != length) { |
| 740 | ap.minimumPasswordLength = length; |
| 741 | saveSettingsLocked(); |
| 742 | } |
| 743 | } |
| 744 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 745 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 746 | public int getPasswordMinimumLength(ComponentName who) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 747 | synchronized (this) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 748 | int length = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 749 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 750 | if (who != null) { |
| 751 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 752 | return admin != null ? admin.minimumPasswordLength : length; |
| 753 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 754 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 755 | final int N = mAdminList.size(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 756 | for (int i=0; i<N; i++) { |
| 757 | ActiveAdmin admin = mAdminList.get(i); |
| 758 | if (length < admin.minimumPasswordLength) { |
| 759 | length = admin.minimumPasswordLength; |
| 760 | } |
| 761 | } |
| 762 | return length; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 763 | } |
| 764 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 765 | |
| 766 | public void setPasswordHistoryLength(ComponentName who, int length) { |
| 767 | synchronized (this) { |
| 768 | if (who == null) { |
| 769 | throw new NullPointerException("ComponentName is null"); |
| 770 | } |
| 771 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 772 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 773 | if (ap.passwordHistoryLength != length) { |
| 774 | ap.passwordHistoryLength = length; |
| 775 | saveSettingsLocked(); |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | public int getPasswordHistoryLength(ComponentName who) { |
| 781 | synchronized (this) { |
| 782 | int length = 0; |
| 783 | |
| 784 | if (who != null) { |
| 785 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 786 | return admin != null ? admin.passwordHistoryLength : length; |
| 787 | } |
| 788 | |
| 789 | final int N = mAdminList.size(); |
| 790 | for (int i = 0; i < N; i++) { |
| 791 | ActiveAdmin admin = mAdminList.get(i); |
| 792 | if (length < admin.passwordHistoryLength) { |
| 793 | length = admin.passwordHistoryLength; |
| 794 | } |
| 795 | } |
| 796 | return length; |
| 797 | } |
| 798 | } |
| 799 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame^] | 800 | public void setPasswordMinimumUpperCase(ComponentName who, int length) { |
| 801 | synchronized (this) { |
| 802 | if (who == null) { |
| 803 | throw new NullPointerException("ComponentName is null"); |
| 804 | } |
| 805 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 806 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 807 | if (ap.minimumPasswordUpperCase != length) { |
| 808 | ap.minimumPasswordUpperCase = length; |
| 809 | saveSettingsLocked(); |
| 810 | } |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | public int getPasswordMinimumUpperCase(ComponentName who) { |
| 815 | synchronized (this) { |
| 816 | int length = 0; |
| 817 | |
| 818 | if (who != null) { |
| 819 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 820 | return admin != null ? admin.minimumPasswordUpperCase : length; |
| 821 | } |
| 822 | |
| 823 | final int N = mAdminList.size(); |
| 824 | for (int i=0; i<N; i++) { |
| 825 | ActiveAdmin admin = mAdminList.get(i); |
| 826 | if (length < admin.minimumPasswordUpperCase) { |
| 827 | length = admin.minimumPasswordUpperCase; |
| 828 | } |
| 829 | } |
| 830 | return length; |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | public void setPasswordMinimumLowerCase(ComponentName who, int length) { |
| 835 | synchronized (this) { |
| 836 | if (who == null) { |
| 837 | throw new NullPointerException("ComponentName is null"); |
| 838 | } |
| 839 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 840 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 841 | if (ap.minimumPasswordLowerCase != length) { |
| 842 | ap.minimumPasswordLowerCase = length; |
| 843 | saveSettingsLocked(); |
| 844 | } |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | public int getPasswordMinimumLowerCase(ComponentName who) { |
| 849 | synchronized (this) { |
| 850 | int length = 0; |
| 851 | |
| 852 | if (who != null) { |
| 853 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 854 | return admin != null ? admin.minimumPasswordLowerCase : length; |
| 855 | } |
| 856 | |
| 857 | final int N = mAdminList.size(); |
| 858 | for (int i=0; i<N; i++) { |
| 859 | ActiveAdmin admin = mAdminList.get(i); |
| 860 | if (length < admin.minimumPasswordLowerCase) { |
| 861 | length = admin.minimumPasswordLowerCase; |
| 862 | } |
| 863 | } |
| 864 | return length; |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | public void setPasswordMinimumLetters(ComponentName who, int length) { |
| 869 | synchronized (this) { |
| 870 | if (who == null) { |
| 871 | throw new NullPointerException("ComponentName is null"); |
| 872 | } |
| 873 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 874 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 875 | if (ap.minimumPasswordLetters != length) { |
| 876 | ap.minimumPasswordLetters = length; |
| 877 | saveSettingsLocked(); |
| 878 | } |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | public int getPasswordMinimumLetters(ComponentName who) { |
| 883 | synchronized (this) { |
| 884 | int length = 0; |
| 885 | |
| 886 | if (who != null) { |
| 887 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 888 | return admin != null ? admin.minimumPasswordLetters : length; |
| 889 | } |
| 890 | |
| 891 | final int N = mAdminList.size(); |
| 892 | for (int i=0; i<N; i++) { |
| 893 | ActiveAdmin admin = mAdminList.get(i); |
| 894 | if (length < admin.minimumPasswordLetters) { |
| 895 | length = admin.minimumPasswordLetters; |
| 896 | } |
| 897 | } |
| 898 | return length; |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | public void setPasswordMinimumNumeric(ComponentName who, int length) { |
| 903 | synchronized (this) { |
| 904 | if (who == null) { |
| 905 | throw new NullPointerException("ComponentName is null"); |
| 906 | } |
| 907 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 908 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 909 | if (ap.minimumPasswordNumeric != length) { |
| 910 | ap.minimumPasswordNumeric = length; |
| 911 | saveSettingsLocked(); |
| 912 | } |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | public int getPasswordMinimumNumeric(ComponentName who) { |
| 917 | synchronized (this) { |
| 918 | int length = 0; |
| 919 | |
| 920 | if (who != null) { |
| 921 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 922 | return admin != null ? admin.minimumPasswordNumeric : length; |
| 923 | } |
| 924 | |
| 925 | final int N = mAdminList.size(); |
| 926 | for (int i = 0; i < N; i++) { |
| 927 | ActiveAdmin admin = mAdminList.get(i); |
| 928 | if (length < admin.minimumPasswordNumeric) { |
| 929 | length = admin.minimumPasswordNumeric; |
| 930 | } |
| 931 | } |
| 932 | return length; |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | public void setPasswordMinimumSymbols(ComponentName who, int length) { |
| 937 | synchronized (this) { |
| 938 | if (who == null) { |
| 939 | throw new NullPointerException("ComponentName is null"); |
| 940 | } |
| 941 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 942 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 943 | if (ap.minimumPasswordSymbols != length) { |
| 944 | ap.minimumPasswordSymbols = length; |
| 945 | saveSettingsLocked(); |
| 946 | } |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | public int getPasswordMinimumSymbols(ComponentName who) { |
| 951 | synchronized (this) { |
| 952 | int length = 0; |
| 953 | |
| 954 | if (who != null) { |
| 955 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 956 | return admin != null ? admin.minimumPasswordSymbols : length; |
| 957 | } |
| 958 | |
| 959 | final int N = mAdminList.size(); |
| 960 | for (int i=0; i<N; i++) { |
| 961 | ActiveAdmin admin = mAdminList.get(i); |
| 962 | if (length < admin.minimumPasswordSymbols) { |
| 963 | length = admin.minimumPasswordSymbols; |
| 964 | } |
| 965 | } |
| 966 | return length; |
| 967 | } |
| 968 | } |
| 969 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 970 | public boolean isActivePasswordSufficient() { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 971 | synchronized (this) { |
| 972 | // This API can only be called by an active device admin, |
| 973 | // so try to retrieve it to check that the caller is one. |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 974 | getActiveAdminForCallerLocked(null, |
| 975 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame^] | 976 | if (mActivePasswordQuality < getPasswordQuality(null) |
| 977 | || mActivePasswordLength < getPasswordMinimumLength(null)) { |
| 978 | return false; |
| 979 | } |
| 980 | if(mActivePasswordQuality != DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) { |
| 981 | return true; |
| 982 | } |
| 983 | return mActivePasswordUpperCase >= getPasswordMinimumUpperCase(null) |
| 984 | && mActivePasswordLowerCase >= getPasswordMinimumLowerCase(null) |
| 985 | && mActivePasswordLetters >= getPasswordMinimumLetters(null) |
| 986 | && mActivePasswordNumeric >= getPasswordMinimumNumeric(null) |
| 987 | && mActivePasswordSymbols >= getPasswordMinimumSymbols(null); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 988 | } |
| 989 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 990 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 991 | public int getCurrentFailedPasswordAttempts() { |
| 992 | synchronized (this) { |
| 993 | // This API can only be called by an active device admin, |
| 994 | // so try to retrieve it to check that the caller is one. |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 995 | getActiveAdminForCallerLocked(null, |
| 996 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 997 | return mFailedPasswordAttempts; |
| 998 | } |
| 999 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1000 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1001 | public void setMaximumFailedPasswordsForWipe(ComponentName who, int num) { |
| 1002 | synchronized (this) { |
| 1003 | // This API can only be called by an active device admin, |
| 1004 | // so try to retrieve it to check that the caller is one. |
| 1005 | getActiveAdminForCallerLocked(who, |
| 1006 | DeviceAdminInfo.USES_POLICY_WIPE_DATA); |
| 1007 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1008 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN); |
| 1009 | if (ap.maximumFailedPasswordsForWipe != num) { |
| 1010 | ap.maximumFailedPasswordsForWipe = num; |
| 1011 | saveSettingsLocked(); |
| 1012 | } |
| 1013 | } |
| 1014 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1015 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1016 | public int getMaximumFailedPasswordsForWipe(ComponentName who) { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1017 | synchronized (this) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1018 | int count = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1019 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1020 | if (who != null) { |
| 1021 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 1022 | return admin != null ? admin.maximumFailedPasswordsForWipe : count; |
| 1023 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1024 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1025 | final int N = mAdminList.size(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1026 | for (int i=0; i<N; i++) { |
| 1027 | ActiveAdmin admin = mAdminList.get(i); |
| 1028 | if (count == 0) { |
| 1029 | count = admin.maximumFailedPasswordsForWipe; |
| 1030 | } else if (admin.maximumFailedPasswordsForWipe != 0 |
| 1031 | && count > admin.maximumFailedPasswordsForWipe) { |
| 1032 | count = admin.maximumFailedPasswordsForWipe; |
| 1033 | } |
| 1034 | } |
| 1035 | return count; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1036 | } |
| 1037 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1038 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1039 | public boolean resetPassword(String password, int flags) { |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1040 | int quality; |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1041 | synchronized (this) { |
| 1042 | // This API can only be called by an active device admin, |
| 1043 | // so try to retrieve it to check that the caller is one. |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1044 | getActiveAdminForCallerLocked(null, |
| 1045 | DeviceAdminInfo.USES_POLICY_RESET_PASSWORD); |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1046 | quality = getPasswordQuality(null); |
| 1047 | if (quality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1048 | int realQuality = LockPatternUtils.computePasswordQuality(password); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame^] | 1049 | if (realQuality < quality |
| 1050 | && quality != DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1051 | Slog.w(TAG, "resetPassword: password quality 0x" |
| 1052 | + Integer.toHexString(quality) |
| 1053 | + " does not meet required quality 0x" |
| 1054 | + Integer.toHexString(quality)); |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1055 | return false; |
| 1056 | } |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame^] | 1057 | quality = Math.max(realQuality, quality); |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1058 | } |
| 1059 | int length = getPasswordMinimumLength(null); |
| 1060 | if (password.length() < length) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1061 | Slog.w(TAG, "resetPassword: password length " + password.length() |
| 1062 | + " does not meet required length " + length); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1063 | return false; |
| 1064 | } |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame^] | 1065 | if (quality == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) { |
| 1066 | int letters = 0; |
| 1067 | int uppercase = 0; |
| 1068 | int lowercase = 0; |
| 1069 | int numbers = 0; |
| 1070 | int symbols = 0; |
| 1071 | for (int i = 0; i < password.length(); i++) { |
| 1072 | char c = password.charAt(i); |
| 1073 | if (c >= 'A' && c <= 'Z') { |
| 1074 | letters++; |
| 1075 | uppercase++; |
| 1076 | } else if (c >= 'a' && c <= 'z') { |
| 1077 | letters++; |
| 1078 | lowercase++; |
| 1079 | } else if (c >= '0' && c <= '9') { |
| 1080 | numbers++; |
| 1081 | } else { |
| 1082 | symbols++; |
| 1083 | } |
| 1084 | } |
| 1085 | int neededLetters = getPasswordMinimumLetters(null); |
| 1086 | if(letters < neededLetters) { |
| 1087 | Slog.w(TAG, "resetPassword: number of letters " + letters |
| 1088 | + " does not meet required number of letters " + neededLetters); |
| 1089 | return false; |
| 1090 | } |
| 1091 | int neededNumbers = getPasswordMinimumNumeric(null); |
| 1092 | if (numbers < neededNumbers) { |
| 1093 | Slog |
| 1094 | .w(TAG, "resetPassword: number of numerical digits " + numbers |
| 1095 | + " does not meet required number of numerical digits " |
| 1096 | + neededNumbers); |
| 1097 | return false; |
| 1098 | } |
| 1099 | int neededLowerCase = getPasswordMinimumLowerCase(null); |
| 1100 | if (lowercase < neededLowerCase) { |
| 1101 | Slog.w(TAG, "resetPassword: number of lowercase letters " + lowercase |
| 1102 | + " does not meet required number of lowercase letters " |
| 1103 | + neededLowerCase); |
| 1104 | return false; |
| 1105 | } |
| 1106 | int neededUpperCase = getPasswordMinimumUpperCase(null); |
| 1107 | if (uppercase < neededUpperCase) { |
| 1108 | Slog.w(TAG, "resetPassword: number of uppercase letters " + uppercase |
| 1109 | + " does not meet required number of uppercase letters " |
| 1110 | + neededUpperCase); |
| 1111 | return false; |
| 1112 | } |
| 1113 | int neededSymbols = getPasswordMinimumSymbols(null); |
| 1114 | if (symbols < neededSymbols) { |
| 1115 | Slog.w(TAG, "resetPassword: number of special symbols " + symbols |
| 1116 | + " does not meet required number of special symbols " + neededSymbols); |
| 1117 | return false; |
| 1118 | } |
| 1119 | } |
| 1120 | |
| 1121 | LockPatternUtils utils = new LockPatternUtils(mContext); |
| 1122 | if(utils.checkPasswordHistory(password)) { |
| 1123 | Slog.w(TAG, "resetPassword: password is the same as one of the last " |
| 1124 | + getPasswordHistoryLength(null) + " passwords"); |
| 1125 | return false; |
| 1126 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1127 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1128 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1129 | int callingUid = Binder.getCallingUid(); |
| 1130 | if (mPasswordOwner >= 0 && mPasswordOwner != callingUid) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1131 | 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] | 1132 | return false; |
| 1133 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1134 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1135 | // Don't do this with the lock held, because it is going to call |
| 1136 | // back in to the service. |
| 1137 | long ident = Binder.clearCallingIdentity(); |
| 1138 | try { |
| 1139 | LockPatternUtils utils = new LockPatternUtils(mContext); |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1140 | utils.saveLockPassword(password, quality); |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1141 | synchronized (this) { |
| 1142 | int newOwner = (flags&DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY) |
| 1143 | != 0 ? callingUid : -1; |
| 1144 | if (mPasswordOwner != newOwner) { |
| 1145 | mPasswordOwner = newOwner; |
| 1146 | saveSettingsLocked(); |
| 1147 | } |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1148 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1149 | } finally { |
| 1150 | Binder.restoreCallingIdentity(ident); |
| 1151 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1152 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1153 | return true; |
| 1154 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1155 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1156 | public void setMaximumTimeToLock(ComponentName who, long timeMs) { |
| 1157 | synchronized (this) { |
| 1158 | if (who == null) { |
| 1159 | throw new NullPointerException("ComponentName is null"); |
| 1160 | } |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1161 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 1162 | DeviceAdminInfo.USES_POLICY_FORCE_LOCK); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1163 | if (ap.maximumTimeToUnlock != timeMs) { |
| 1164 | ap.maximumTimeToUnlock = timeMs; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1165 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1166 | long ident = Binder.clearCallingIdentity(); |
| 1167 | try { |
| 1168 | saveSettingsLocked(); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1169 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1170 | timeMs = getMaximumTimeToLock(null); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1171 | if (timeMs <= 0) { |
| 1172 | timeMs = Integer.MAX_VALUE; |
| 1173 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1174 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1175 | try { |
| 1176 | getIPowerManager().setMaximumScreenOffTimeount((int)timeMs); |
| 1177 | } catch (RemoteException e) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1178 | Slog.w(TAG, "Failure talking with power manager", e); |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1179 | } |
| 1180 | } finally { |
| 1181 | Binder.restoreCallingIdentity(ident); |
| 1182 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1183 | } |
| 1184 | } |
| 1185 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1186 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1187 | public long getMaximumTimeToLock(ComponentName who) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1188 | synchronized (this) { |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1189 | long time = 0; |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1190 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1191 | if (who != null) { |
| 1192 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 1193 | return admin != null ? admin.maximumTimeToUnlock : time; |
| 1194 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1195 | |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1196 | final int N = mAdminList.size(); |
Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1197 | for (int i=0; i<N; i++) { |
| 1198 | ActiveAdmin admin = mAdminList.get(i); |
| 1199 | if (time == 0) { |
| 1200 | time = admin.maximumTimeToUnlock; |
| 1201 | } else if (admin.maximumTimeToUnlock != 0 |
| 1202 | && time > admin.maximumTimeToUnlock) { |
| 1203 | time = admin.maximumTimeToUnlock; |
| 1204 | } |
| 1205 | } |
| 1206 | return time; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1207 | } |
| 1208 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1209 | |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1210 | public void lockNow() { |
| 1211 | synchronized (this) { |
| 1212 | // This API can only be called by an active device admin, |
| 1213 | // so try to retrieve it to check that the caller is one. |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1214 | getActiveAdminForCallerLocked(null, |
| 1215 | DeviceAdminInfo.USES_POLICY_FORCE_LOCK); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1216 | long ident = Binder.clearCallingIdentity(); |
| 1217 | try { |
| 1218 | mIPowerManager.goToSleepWithReason(SystemClock.uptimeMillis(), |
| 1219 | WindowManagerPolicy.OFF_BECAUSE_OF_ADMIN); |
| 1220 | } catch (RemoteException e) { |
| 1221 | } finally { |
| 1222 | Binder.restoreCallingIdentity(ident); |
| 1223 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1224 | } |
| 1225 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1226 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1227 | void wipeDataLocked(int flags) { |
| 1228 | try { |
| 1229 | RecoverySystem.rebootWipeUserData(mContext); |
| 1230 | } catch (IOException e) { |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1231 | Slog.w(TAG, "Failed requesting data wipe", e); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1232 | } |
| 1233 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1234 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1235 | public void wipeData(int flags) { |
| 1236 | synchronized (this) { |
| 1237 | // This API can only be called by an active device admin, |
| 1238 | // so try to retrieve it to check that the caller is one. |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1239 | getActiveAdminForCallerLocked(null, |
| 1240 | DeviceAdminInfo.USES_POLICY_WIPE_DATA); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1241 | long ident = Binder.clearCallingIdentity(); |
| 1242 | try { |
| 1243 | wipeDataLocked(flags); |
| 1244 | } finally { |
| 1245 | Binder.restoreCallingIdentity(ident); |
| 1246 | } |
Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1247 | } |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1248 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1249 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1250 | public void getRemoveWarning(ComponentName comp, final RemoteCallback result) { |
| 1251 | mContext.enforceCallingOrSelfPermission( |
| 1252 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1253 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1254 | synchronized (this) { |
| 1255 | ActiveAdmin admin = getActiveAdminUncheckedLocked(comp); |
| 1256 | if (admin == null) { |
| 1257 | try { |
| 1258 | result.sendResult(null); |
| 1259 | } catch (RemoteException e) { |
| 1260 | } |
| 1261 | return; |
| 1262 | } |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1263 | Intent intent = new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_DISABLE_REQUESTED); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1264 | intent.setComponent(admin.info.getComponent()); |
| 1265 | mContext.sendOrderedBroadcast(intent, null, new BroadcastReceiver() { |
| 1266 | @Override |
| 1267 | public void onReceive(Context context, Intent intent) { |
| 1268 | try { |
| 1269 | result.sendResult(getResultExtras(false)); |
| 1270 | } catch (RemoteException e) { |
| 1271 | } |
| 1272 | } |
| 1273 | }, null, Activity.RESULT_OK, null, null); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1274 | } |
| 1275 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1276 | |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame^] | 1277 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
| 1278 | int lowercase, int numbers, int symbols) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1279 | mContext.enforceCallingOrSelfPermission( |
| 1280 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1281 | |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1282 | validateQualityConstant(quality); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1283 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1284 | synchronized (this) { |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1285 | if (mActivePasswordQuality != quality || mActivePasswordLength != length |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame^] | 1286 | || mFailedPasswordAttempts != 0 || mActivePasswordLetters != letters |
| 1287 | || mActivePasswordUpperCase != uppercase |
| 1288 | || mActivePasswordLowerCase != lowercase || mActivePasswordNumeric != numbers |
| 1289 | || mActivePasswordSymbols != symbols) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1290 | long ident = Binder.clearCallingIdentity(); |
| 1291 | try { |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1292 | mActivePasswordQuality = quality; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1293 | mActivePasswordLength = length; |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame^] | 1294 | mActivePasswordLetters = letters; |
| 1295 | mActivePasswordLowerCase = lowercase; |
| 1296 | mActivePasswordUpperCase = uppercase; |
| 1297 | mActivePasswordNumeric = numbers; |
| 1298 | mActivePasswordSymbols = symbols; |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1299 | mFailedPasswordAttempts = 0; |
| 1300 | saveSettingsLocked(); |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1301 | sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_CHANGED, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1302 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1303 | } finally { |
| 1304 | Binder.restoreCallingIdentity(ident); |
| 1305 | } |
| 1306 | } |
| 1307 | } |
| 1308 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1309 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1310 | public void reportFailedPasswordAttempt() { |
| 1311 | mContext.enforceCallingOrSelfPermission( |
| 1312 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1313 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1314 | synchronized (this) { |
| 1315 | long ident = Binder.clearCallingIdentity(); |
| 1316 | try { |
| 1317 | mFailedPasswordAttempts++; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1318 | saveSettingsLocked(); |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1319 | int max = getMaximumFailedPasswordsForWipe(null); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1320 | if (max > 0 && mFailedPasswordAttempts >= max) { |
| 1321 | wipeDataLocked(0); |
| 1322 | } |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1323 | sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_FAILED, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1324 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1325 | } finally { |
| 1326 | Binder.restoreCallingIdentity(ident); |
| 1327 | } |
| 1328 | } |
| 1329 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1330 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1331 | public void reportSuccessfulPasswordAttempt() { |
| 1332 | mContext.enforceCallingOrSelfPermission( |
| 1333 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1334 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1335 | synchronized (this) { |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1336 | if (mFailedPasswordAttempts != 0 || mPasswordOwner >= 0) { |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1337 | long ident = Binder.clearCallingIdentity(); |
| 1338 | try { |
| 1339 | mFailedPasswordAttempts = 0; |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1340 | mPasswordOwner = -1; |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1341 | saveSettingsLocked(); |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 1342 | sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_SUCCEEDED, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1343 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1344 | } finally { |
| 1345 | Binder.restoreCallingIdentity(ident); |
| 1346 | } |
| 1347 | } |
| 1348 | } |
| 1349 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1350 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1351 | @Override |
| 1352 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1353 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 1354 | != PackageManager.PERMISSION_GRANTED) { |
| 1355 | |
| 1356 | pw.println("Permission Denial: can't dump DevicePolicyManagerService from from pid=" |
| 1357 | + Binder.getCallingPid() |
| 1358 | + ", uid=" + Binder.getCallingUid()); |
| 1359 | return; |
| 1360 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1361 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1362 | final Printer p = new PrintWriterPrinter(pw); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1363 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1364 | synchronized (this) { |
| 1365 | p.println("Current Device Policy Manager state:"); |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1366 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1367 | p.println(" Enabled Device Admins:"); |
| 1368 | final int N = mAdminList.size(); |
| 1369 | for (int i=0; i<N; i++) { |
| 1370 | ActiveAdmin ap = mAdminList.get(i); |
| 1371 | if (ap != null) { |
| 1372 | pw.print(" "); pw.print(ap.info.getComponent().flattenToShortString()); |
| 1373 | pw.println(":"); |
| 1374 | ap.dump(" ", pw); |
| 1375 | } |
| 1376 | } |
Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1377 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1378 | pw.println(" "); |
Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1379 | pw.print(" mActivePasswordQuality=0x"); |
| 1380 | pw.println(Integer.toHexString(mActivePasswordQuality)); |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1381 | pw.print(" mActivePasswordLength="); pw.println(mActivePasswordLength); |
Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame^] | 1382 | pw.print(" mActivePasswordUpperCase="); pw.println(mActivePasswordUpperCase); |
| 1383 | pw.print(" mActivePasswordLowerCase="); pw.println(mActivePasswordLowerCase); |
| 1384 | pw.print(" mActivePasswordLetters="); pw.println(mActivePasswordLetters); |
| 1385 | pw.print(" mActivePasswordNumeric="); pw.println(mActivePasswordNumeric); |
| 1386 | pw.print(" mActivePasswordSymbols="); pw.println(mActivePasswordSymbols); |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1387 | pw.print(" mFailedPasswordAttempts="); pw.println(mFailedPasswordAttempts); |
| 1388 | pw.print(" mPasswordOwner="); pw.println(mPasswordOwner); |
| 1389 | } |
| 1390 | } |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1391 | } |