| 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; |
| Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame^] | 58 | import java.io.FileNotFoundException; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 59 | import java.io.FileOutputStream; |
| 60 | import java.io.IOException; |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 61 | import java.io.PrintWriter; |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 62 | import java.util.ArrayList; |
| 63 | import java.util.HashMap; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 64 | import java.util.List; |
| 65 | |
| 66 | /** |
| 67 | * Implementation of the device policy APIs. |
| 68 | */ |
| 69 | public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 70 | static final String TAG = "DevicePolicyManagerService"; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 71 | |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 72 | final Context mContext; |
| 73 | final MyPackageMonitor mMonitor; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 74 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 75 | IPowerManager mIPowerManager; |
| 76 | |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 77 | int mActivePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 78 | int mActivePasswordLength = 0; |
| 79 | int mFailedPasswordAttempts = 0; |
| 80 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 81 | int mPasswordOwner = -1; |
| 82 | |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 83 | final HashMap<ComponentName, ActiveAdmin> mAdminMap |
| 84 | = new HashMap<ComponentName, ActiveAdmin>(); |
| 85 | final ArrayList<ActiveAdmin> mAdminList |
| 86 | = new ArrayList<ActiveAdmin>(); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 87 | |
| 88 | static class ActiveAdmin { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 89 | final DeviceAdminInfo info; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 90 | |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 91 | int passwordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 92 | int minimumPasswordLength = 0; |
| 93 | long maximumTimeToUnlock = 0; |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 94 | int maximumFailedPasswordsForWipe = 0; |
| 95 | |
| 96 | ActiveAdmin(DeviceAdminInfo _info) { |
| 97 | info = _info; |
| 98 | } |
| 99 | |
| 100 | int getUid() { return info.getActivityInfo().applicationInfo.uid; } |
| 101 | |
| 102 | void writeToXml(XmlSerializer out) |
| 103 | throws IllegalArgumentException, IllegalStateException, IOException { |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 104 | out.startTag(null, "policies"); |
| 105 | info.writePoliciesToXml(out); |
| 106 | out.endTag(null, "policies"); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 107 | if (passwordQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { |
| 108 | out.startTag(null, "password-quality"); |
| 109 | out.attribute(null, "value", Integer.toString(passwordQuality)); |
| 110 | out.endTag(null, "password-quality"); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 111 | if (minimumPasswordLength > 0) { |
| 112 | out.startTag(null, "min-password-length"); |
| 113 | out.attribute(null, "value", Integer.toString(minimumPasswordLength)); |
| 114 | out.endTag(null, "mn-password-length"); |
| 115 | } |
| 116 | } |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 117 | if (maximumTimeToUnlock != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 118 | out.startTag(null, "max-time-to-unlock"); |
| 119 | out.attribute(null, "value", Long.toString(maximumTimeToUnlock)); |
| 120 | out.endTag(null, "max-time-to-unlock"); |
| 121 | } |
| 122 | if (maximumFailedPasswordsForWipe != 0) { |
| 123 | out.startTag(null, "max-failed-password-wipe"); |
| 124 | out.attribute(null, "value", Integer.toString(maximumFailedPasswordsForWipe)); |
| 125 | out.endTag(null, "max-failed-password-wipe"); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | void readFromXml(XmlPullParser parser) |
| 130 | throws XmlPullParserException, IOException { |
| 131 | int outerDepth = parser.getDepth(); |
| 132 | int type; |
| 133 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 134 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 135 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 136 | continue; |
| 137 | } |
| 138 | String tag = parser.getName(); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 139 | if ("policies".equals(tag)) { |
| 140 | info.readPoliciesFromXml(parser); |
| 141 | } else if ("password-quality".equals(tag)) { |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 142 | passwordQuality = Integer.parseInt( |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 143 | parser.getAttributeValue(null, "value")); |
| 144 | } else if ("min-password-length".equals(tag)) { |
| 145 | minimumPasswordLength = Integer.parseInt( |
| 146 | parser.getAttributeValue(null, "value")); |
| 147 | } else if ("max-time-to-unlock".equals(tag)) { |
| 148 | maximumTimeToUnlock = Long.parseLong( |
| 149 | parser.getAttributeValue(null, "value")); |
| 150 | } else if ("max-failed-password-wipe".equals(tag)) { |
| 151 | maximumFailedPasswordsForWipe = Integer.parseInt( |
| 152 | parser.getAttributeValue(null, "value")); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 153 | } else { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 154 | Slog.w(TAG, "Unknown admin tag: " + tag); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 155 | } |
| 156 | XmlUtils.skipCurrentTag(parser); |
| 157 | } |
| 158 | } |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 159 | |
| 160 | void dump(String prefix, PrintWriter pw) { |
| 161 | pw.print(prefix); pw.print("uid="); pw.println(getUid()); |
| 162 | pw.print(prefix); pw.println("policies:"); |
| 163 | ArrayList<DeviceAdminInfo.PolicyInfo> pols = info.getUsedPolicies(); |
| 164 | if (pols != null) { |
| 165 | for (int i=0; i<pols.size(); i++) { |
| 166 | pw.print(prefix); pw.print(" "); pw.println(pols.get(i).tag); |
| 167 | } |
| 168 | } |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 169 | pw.print(prefix); pw.print("passwordQuality=0x"); |
| 170 | pw.print(Integer.toHexString(passwordQuality)); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 171 | pw.print(" minimumPasswordLength="); |
| 172 | pw.println(minimumPasswordLength); |
| 173 | pw.print(prefix); pw.print("maximumTimeToUnlock="); |
| 174 | pw.println(maximumTimeToUnlock); |
| 175 | pw.print(prefix); pw.print("maximumFailedPasswordsForWipe="); |
| 176 | pw.println(maximumFailedPasswordsForWipe); |
| 177 | } |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | class MyPackageMonitor extends PackageMonitor { |
| 181 | public void onSomePackagesChanged() { |
| 182 | synchronized (DevicePolicyManagerService.this) { |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 183 | boolean removed = false; |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 184 | for (int i=mAdminList.size()-1; i>=0; i--) { |
| 185 | ActiveAdmin aa = mAdminList.get(i); |
| 186 | int change = isPackageDisappearing(aa.info.getPackageName()); |
| 187 | if (change == PACKAGE_PERMANENT_CHANGE |
| 188 | || change == PACKAGE_TEMPORARY_CHANGE) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 189 | Slog.w(TAG, "Admin unexpectedly uninstalled: " |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 190 | + aa.info.getComponent()); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 191 | removed = true; |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 192 | mAdminList.remove(i); |
| 193 | } else if (isPackageModified(aa.info.getPackageName())) { |
| 194 | try { |
| 195 | mContext.getPackageManager().getReceiverInfo( |
| 196 | aa.info.getComponent(), 0); |
| 197 | } catch (NameNotFoundException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 198 | Slog.w(TAG, "Admin package change removed component: " |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 199 | + aa.info.getComponent()); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 200 | removed = true; |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 201 | mAdminList.remove(i); |
| 202 | } |
| 203 | } |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 204 | } |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 205 | if (removed) { |
| 206 | validatePasswordOwnerLocked(); |
| 207 | } |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 208 | } |
| 209 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Instantiates the service. |
| 214 | */ |
| 215 | public DevicePolicyManagerService(Context context) { |
| 216 | mContext = context; |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 217 | mMonitor = new MyPackageMonitor(); |
| 218 | mMonitor.register(context, true); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 219 | } |
| 220 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 221 | private IPowerManager getIPowerManager() { |
| 222 | if (mIPowerManager == null) { |
| 223 | IBinder b = ServiceManager.getService(Context.POWER_SERVICE); |
| 224 | mIPowerManager = IPowerManager.Stub.asInterface(b); |
| 225 | } |
| 226 | return mIPowerManager; |
| 227 | } |
| 228 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 229 | ActiveAdmin getActiveAdminUncheckedLocked(ComponentName who) { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 230 | ActiveAdmin admin = mAdminMap.get(who); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 231 | if (admin != null |
| 232 | && who.getPackageName().equals(admin.info.getActivityInfo().packageName) |
| 233 | && who.getClassName().equals(admin.info.getActivityInfo().name)) { |
| 234 | return admin; |
| 235 | } |
| 236 | return null; |
| 237 | } |
| 238 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 239 | ActiveAdmin getActiveAdminForCallerLocked(ComponentName who, int reqPolicy) |
| 240 | throws SecurityException { |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 241 | final int callingUid = Binder.getCallingUid(); |
| 242 | if (who != null) { |
| 243 | ActiveAdmin admin = mAdminMap.get(who); |
| 244 | if (admin == null) { |
| 245 | throw new SecurityException("No active admin " + who); |
| 246 | } |
| 247 | if (admin.getUid() != callingUid) { |
| 248 | throw new SecurityException("Admin " + who + " is not owned by uid " |
| 249 | + Binder.getCallingUid()); |
| 250 | } |
| 251 | if (!admin.info.usesPolicy(reqPolicy)) { |
| 252 | throw new SecurityException("Admin " + admin.info.getComponent() |
| 253 | + " did not specify uses-policy for: " |
| 254 | + admin.info.getTagForPolicy(reqPolicy)); |
| 255 | } |
| 256 | return admin; |
| 257 | } else { |
| 258 | final int N = mAdminList.size(); |
| 259 | for (int i=0; i<N; i++) { |
| 260 | ActiveAdmin admin = mAdminList.get(i); |
| 261 | if (admin.getUid() == callingUid && admin.info.usesPolicy(reqPolicy)) { |
| 262 | return admin; |
| 263 | } |
| 264 | } |
| 265 | throw new SecurityException("No active admin owned by uid " |
| 266 | + Binder.getCallingUid() + " for policy #" + reqPolicy); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 267 | } |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 268 | } |
| 269 | |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 270 | void sendAdminCommandLocked(ActiveAdmin admin, String action) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 271 | Intent intent = new Intent(action); |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 272 | intent.setComponent(admin.info.getComponent()); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 273 | mContext.sendBroadcast(intent); |
| 274 | } |
| 275 | |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 276 | void sendAdminCommandLocked(String action, int reqPolicy) { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 277 | final int N = mAdminList.size(); |
| 278 | if (N > 0) { |
| 279 | for (int i=0; i<N; i++) { |
| 280 | ActiveAdmin admin = mAdminList.get(i); |
| 281 | if (admin.info.usesPolicy(reqPolicy)) { |
| 282 | sendAdminCommandLocked(admin, action); |
| 283 | } |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 284 | } |
| Dianne Hackborn | 4141d03 | 2010-01-21 16:29:00 -0800 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 288 | void removeActiveAdminLocked(ComponentName adminReceiver) { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 289 | ActiveAdmin admin = getActiveAdminUncheckedLocked(adminReceiver); |
| 290 | if (admin != null) { |
| 291 | sendAdminCommandLocked(admin, |
| Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 292 | DeviceAdminReceiver.ACTION_DEVICE_ADMIN_DISABLED); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 293 | // XXX need to wait for it to complete. |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 294 | mAdminList.remove(admin); |
| 295 | mAdminMap.remove(adminReceiver); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 296 | validatePasswordOwnerLocked(); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | |
| 300 | public DeviceAdminInfo findAdmin(ComponentName adminName) { |
| 301 | Intent resolveIntent = new Intent(); |
| 302 | resolveIntent.setComponent(adminName); |
| 303 | List<ResolveInfo> infos = mContext.getPackageManager().queryBroadcastReceivers( |
| 304 | resolveIntent, PackageManager.GET_META_DATA); |
| 305 | if (infos == null || infos.size() <= 0) { |
| 306 | throw new IllegalArgumentException("Unknown admin: " + adminName); |
| 307 | } |
| 308 | |
| 309 | try { |
| 310 | return new DeviceAdminInfo(mContext, infos.get(0)); |
| 311 | } catch (XmlPullParserException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 312 | Slog.w(TAG, "Bad device admin requested: " + adminName, e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 313 | return null; |
| 314 | } catch (IOException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 315 | Slog.w(TAG, "Bad device admin requested: " + adminName, e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 316 | return null; |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | private static JournaledFile makeJournaledFile() { |
| 321 | final String base = "/data/system/device_policies.xml"; |
| 322 | return new JournaledFile(new File(base), new File(base + ".tmp")); |
| 323 | } |
| 324 | |
| 325 | private void saveSettingsLocked() { |
| 326 | JournaledFile journal = makeJournaledFile(); |
| 327 | FileOutputStream stream = null; |
| 328 | try { |
| 329 | stream = new FileOutputStream(journal.chooseForWrite(), false); |
| 330 | XmlSerializer out = new FastXmlSerializer(); |
| 331 | out.setOutput(stream, "utf-8"); |
| 332 | out.startDocument(null, true); |
| 333 | |
| 334 | out.startTag(null, "policies"); |
| 335 | |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 336 | final int N = mAdminList.size(); |
| 337 | for (int i=0; i<N; i++) { |
| 338 | ActiveAdmin ap = mAdminList.get(i); |
| 339 | if (ap != null) { |
| 340 | out.startTag(null, "admin"); |
| 341 | out.attribute(null, "name", ap.info.getComponent().flattenToString()); |
| 342 | ap.writeToXml(out); |
| 343 | out.endTag(null, "admin"); |
| 344 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 345 | } |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 346 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 347 | if (mPasswordOwner >= 0) { |
| 348 | out.startTag(null, "password-owner"); |
| 349 | out.attribute(null, "value", Integer.toString(mPasswordOwner)); |
| 350 | out.endTag(null, "password-owner"); |
| 351 | } |
| 352 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 353 | if (mFailedPasswordAttempts != 0) { |
| 354 | out.startTag(null, "failed-password-attempts"); |
| 355 | out.attribute(null, "value", Integer.toString(mFailedPasswordAttempts)); |
| 356 | out.endTag(null, "failed-password-attempts"); |
| 357 | } |
| 358 | |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 359 | if (mActivePasswordQuality != 0 || mActivePasswordLength != 0) { |
| 360 | out.startTag(null, "active-password"); |
| 361 | out.attribute(null, "quality", Integer.toString(mActivePasswordQuality)); |
| 362 | out.attribute(null, "length", Integer.toString(mActivePasswordLength)); |
| 363 | out.endTag(null, "active-password"); |
| 364 | } |
| 365 | |
| 366 | out.endTag(null, "policies"); |
| 367 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 368 | out.endDocument(); |
| 369 | stream.close(); |
| 370 | journal.commit(); |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 371 | sendChangedNotification(); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 372 | } catch (IOException e) { |
| 373 | try { |
| 374 | if (stream != null) { |
| 375 | stream.close(); |
| 376 | } |
| 377 | } catch (IOException ex) { |
| 378 | // Ignore |
| 379 | } |
| 380 | journal.rollback(); |
| 381 | } |
| 382 | } |
| 383 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 384 | private void sendChangedNotification() { |
| 385 | Intent intent = new Intent(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 386 | intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 387 | mContext.sendBroadcast(intent); |
| 388 | } |
| 389 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 390 | private void loadSettingsLocked() { |
| 391 | JournaledFile journal = makeJournaledFile(); |
| 392 | FileInputStream stream = null; |
| 393 | File file = journal.chooseForRead(); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 394 | try { |
| 395 | stream = new FileInputStream(file); |
| 396 | XmlPullParser parser = Xml.newPullParser(); |
| 397 | parser.setInput(stream, null); |
| 398 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 399 | int type; |
| 400 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 401 | && type != XmlPullParser.START_TAG) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 402 | } |
| 403 | String tag = parser.getName(); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 404 | if (!"policies".equals(tag)) { |
| 405 | throw new XmlPullParserException( |
| 406 | "Settings do not start with policies tag: found " + tag); |
| 407 | } |
| 408 | type = parser.next(); |
| 409 | int outerDepth = parser.getDepth(); |
| 410 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 411 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 412 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 413 | continue; |
| 414 | } |
| 415 | tag = parser.getName(); |
| 416 | if ("admin".equals(tag)) { |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 417 | String name = parser.getAttributeValue(null, "name"); |
| 418 | try { |
| 419 | DeviceAdminInfo dai = findAdmin( |
| 420 | ComponentName.unflattenFromString(name)); |
| 421 | if (dai != null) { |
| 422 | ActiveAdmin ap = new ActiveAdmin(dai); |
| 423 | ap.readFromXml(parser); |
| 424 | mAdminMap.put(ap.info.getComponent(), ap); |
| 425 | mAdminList.add(ap); |
| 426 | } |
| 427 | } catch (RuntimeException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 428 | Slog.w(TAG, "Failed loading admin " + name, e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 429 | } |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 430 | } else if ("failed-password-attempts".equals(tag)) { |
| 431 | mFailedPasswordAttempts = Integer.parseInt( |
| 432 | parser.getAttributeValue(null, "value")); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 433 | XmlUtils.skipCurrentTag(parser); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 434 | } else if ("password-owner".equals(tag)) { |
| 435 | mPasswordOwner = Integer.parseInt( |
| 436 | parser.getAttributeValue(null, "value")); |
| 437 | XmlUtils.skipCurrentTag(parser); |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 438 | } else if ("active-password".equals(tag)) { |
| 439 | mActivePasswordQuality = Integer.parseInt( |
| 440 | parser.getAttributeValue(null, "quality")); |
| 441 | mActivePasswordLength = Integer.parseInt( |
| 442 | parser.getAttributeValue(null, "length")); |
| 443 | XmlUtils.skipCurrentTag(parser); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 444 | } else { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 445 | Slog.w(TAG, "Unknown tag: " + tag); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 446 | XmlUtils.skipCurrentTag(parser); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 447 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 448 | } |
| 449 | } catch (NullPointerException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 450 | Slog.w(TAG, "failed parsing " + file + " " + e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 451 | } catch (NumberFormatException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 452 | Slog.w(TAG, "failed parsing " + file + " " + e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 453 | } catch (XmlPullParserException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 454 | Slog.w(TAG, "failed parsing " + file + " " + e); |
| Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame^] | 455 | } catch (FileNotFoundException e) { |
| 456 | // Don't be noisy, this is normal if we haven't defined any policies. |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 457 | } catch (IOException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 458 | Slog.w(TAG, "failed parsing " + file + " " + e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 459 | } catch (IndexOutOfBoundsException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 460 | Slog.w(TAG, "failed parsing " + file + " " + e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 461 | } |
| 462 | try { |
| 463 | if (stream != null) { |
| 464 | stream.close(); |
| 465 | } |
| 466 | } catch (IOException e) { |
| 467 | // Ignore |
| 468 | } |
| 469 | |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 470 | // Validate that what we stored for the password quality matches |
| 471 | // sufficiently what is currently set. Note that this is only |
| 472 | // a sanity check in case the two get out of sync; this should |
| 473 | // never normally happen. |
| 474 | LockPatternUtils utils = new LockPatternUtils(mContext); |
| 475 | if (utils.getActivePasswordQuality() < mActivePasswordQuality) { |
| 476 | Slog.w(TAG, "Active password quality 0x" |
| 477 | + Integer.toHexString(mActivePasswordQuality) |
| 478 | + " does not match actual quality 0x" |
| 479 | + Integer.toHexString(utils.getActivePasswordQuality())); |
| 480 | mActivePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
| 481 | mActivePasswordLength = 0; |
| 482 | } |
| 483 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 484 | validatePasswordOwnerLocked(); |
| 485 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 486 | long timeMs = getMaximumTimeToLock(null); |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 487 | if (timeMs <= 0) { |
| 488 | timeMs = Integer.MAX_VALUE; |
| 489 | } |
| 490 | try { |
| 491 | getIPowerManager().setMaximumScreenOffTimeount((int)timeMs); |
| 492 | } catch (RemoteException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 493 | Slog.w(TAG, "Failure talking with power manager", e); |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 494 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 495 | } |
| 496 | |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 497 | static void validateQualityConstant(int quality) { |
| 498 | switch (quality) { |
| 499 | case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED: |
| 500 | case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: |
| 501 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: |
| 502 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: |
| 503 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: |
| 504 | return; |
| 505 | } |
| 506 | throw new IllegalArgumentException("Invalid quality constant: 0x" |
| 507 | + Integer.toHexString(quality)); |
| 508 | } |
| 509 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 510 | void validatePasswordOwnerLocked() { |
| 511 | if (mPasswordOwner >= 0) { |
| 512 | boolean haveOwner = false; |
| 513 | for (int i=mAdminList.size()-1; i>=0; i--) { |
| 514 | if (mAdminList.get(i).getUid() == mPasswordOwner) { |
| 515 | haveOwner = true; |
| 516 | break; |
| 517 | } |
| 518 | } |
| 519 | if (!haveOwner) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 520 | Slog.w(TAG, "Previous password owner " + mPasswordOwner |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 521 | + " no longer active; disabling"); |
| 522 | mPasswordOwner = -1; |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 527 | public void systemReady() { |
| 528 | synchronized (this) { |
| 529 | loadSettingsLocked(); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | public void setActiveAdmin(ComponentName adminReceiver) { |
| 534 | mContext.enforceCallingOrSelfPermission( |
| 535 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
| 536 | |
| 537 | DeviceAdminInfo info = findAdmin(adminReceiver); |
| 538 | if (info == null) { |
| 539 | throw new IllegalArgumentException("Bad admin: " + adminReceiver); |
| 540 | } |
| 541 | synchronized (this) { |
| 542 | long ident = Binder.clearCallingIdentity(); |
| 543 | try { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 544 | if (getActiveAdminUncheckedLocked(adminReceiver) != null) { |
| 545 | throw new IllegalArgumentException("Admin is already added"); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 546 | } |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 547 | ActiveAdmin admin = new ActiveAdmin(info); |
| 548 | mAdminMap.put(adminReceiver, admin); |
| 549 | mAdminList.add(admin); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 550 | saveSettingsLocked(); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 551 | sendAdminCommandLocked(admin, |
| Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 552 | DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 553 | } finally { |
| 554 | Binder.restoreCallingIdentity(ident); |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 559 | public boolean isAdminActive(ComponentName adminReceiver) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 560 | synchronized (this) { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 561 | return getActiveAdminUncheckedLocked(adminReceiver) != null; |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | public List<ComponentName> getActiveAdmins() { |
| 566 | synchronized (this) { |
| 567 | final int N = mAdminList.size(); |
| 568 | if (N <= 0) { |
| 569 | return null; |
| 570 | } |
| 571 | ArrayList<ComponentName> res = new ArrayList<ComponentName>(N); |
| 572 | for (int i=0; i<N; i++) { |
| 573 | res.add(mAdminList.get(i).info.getComponent()); |
| 574 | } |
| 575 | return res; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 576 | } |
| 577 | } |
| 578 | |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 579 | public boolean packageHasActiveAdmins(String packageName) { |
| 580 | synchronized (this) { |
| 581 | final int N = mAdminList.size(); |
| 582 | for (int i=0; i<N; i++) { |
| 583 | if (mAdminList.get(i).info.getPackageName().equals(packageName)) { |
| 584 | return true; |
| 585 | } |
| 586 | } |
| 587 | return false; |
| 588 | } |
| 589 | } |
| 590 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 591 | public void removeActiveAdmin(ComponentName adminReceiver) { |
| 592 | synchronized (this) { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 593 | ActiveAdmin admin = getActiveAdminUncheckedLocked(adminReceiver); |
| 594 | if (admin == null) { |
| 595 | return; |
| 596 | } |
| 597 | if (admin.getUid() != Binder.getCallingUid()) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 598 | mContext.enforceCallingOrSelfPermission( |
| 599 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
| 600 | } |
| 601 | long ident = Binder.clearCallingIdentity(); |
| 602 | try { |
| 603 | removeActiveAdminLocked(adminReceiver); |
| 604 | } finally { |
| 605 | Binder.restoreCallingIdentity(ident); |
| 606 | } |
| 607 | } |
| 608 | } |
| 609 | |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 610 | public void setPasswordQuality(ComponentName who, int quality) { |
| 611 | validateQualityConstant(quality); |
| 612 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 613 | synchronized (this) { |
| 614 | if (who == null) { |
| 615 | throw new NullPointerException("ComponentName is null"); |
| 616 | } |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 617 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 618 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 619 | if (ap.passwordQuality != quality) { |
| 620 | ap.passwordQuality = quality; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 621 | saveSettingsLocked(); |
| 622 | } |
| 623 | } |
| 624 | } |
| 625 | |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 626 | public int getPasswordQuality(ComponentName who) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 627 | synchronized (this) { |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 628 | int mode = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 629 | |
| 630 | if (who != null) { |
| 631 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 632 | return admin != null ? admin.passwordQuality : mode; |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | final int N = mAdminList.size(); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 636 | for (int i=0; i<N; i++) { |
| 637 | ActiveAdmin admin = mAdminList.get(i); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 638 | if (mode < admin.passwordQuality) { |
| 639 | mode = admin.passwordQuality; |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 640 | } |
| 641 | } |
| 642 | return mode; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 646 | public void setPasswordMinimumLength(ComponentName who, int length) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 647 | synchronized (this) { |
| 648 | if (who == null) { |
| 649 | throw new NullPointerException("ComponentName is null"); |
| 650 | } |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 651 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 652 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 653 | if (ap.minimumPasswordLength != length) { |
| 654 | ap.minimumPasswordLength = length; |
| 655 | saveSettingsLocked(); |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 660 | public int getPasswordMinimumLength(ComponentName who) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 661 | synchronized (this) { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 662 | int length = 0; |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 663 | |
| 664 | if (who != null) { |
| 665 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 666 | return admin != null ? admin.minimumPasswordLength : length; |
| 667 | } |
| 668 | |
| 669 | final int N = mAdminList.size(); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 670 | for (int i=0; i<N; i++) { |
| 671 | ActiveAdmin admin = mAdminList.get(i); |
| 672 | if (length < admin.minimumPasswordLength) { |
| 673 | length = admin.minimumPasswordLength; |
| 674 | } |
| 675 | } |
| 676 | return length; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 680 | public boolean isActivePasswordSufficient() { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 681 | synchronized (this) { |
| 682 | // This API can only be called by an active device admin, |
| 683 | // so try to retrieve it to check that the caller is one. |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 684 | getActiveAdminForCallerLocked(null, |
| 685 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 686 | return mActivePasswordQuality >= getPasswordQuality(null) |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 687 | && mActivePasswordLength >= getPasswordMinimumLength(null); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | |
| 691 | public int getCurrentFailedPasswordAttempts() { |
| 692 | synchronized (this) { |
| 693 | // This API can only be called by an active device admin, |
| 694 | // so try to retrieve it to check that the caller is one. |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 695 | getActiveAdminForCallerLocked(null, |
| 696 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 697 | return mFailedPasswordAttempts; |
| 698 | } |
| 699 | } |
| 700 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 701 | public void setMaximumFailedPasswordsForWipe(ComponentName who, int num) { |
| 702 | synchronized (this) { |
| 703 | // This API can only be called by an active device admin, |
| 704 | // so try to retrieve it to check that the caller is one. |
| 705 | getActiveAdminForCallerLocked(who, |
| 706 | DeviceAdminInfo.USES_POLICY_WIPE_DATA); |
| 707 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 708 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN); |
| 709 | if (ap.maximumFailedPasswordsForWipe != num) { |
| 710 | ap.maximumFailedPasswordsForWipe = num; |
| 711 | saveSettingsLocked(); |
| 712 | } |
| 713 | } |
| 714 | } |
| 715 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 716 | public int getMaximumFailedPasswordsForWipe(ComponentName who) { |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 717 | synchronized (this) { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 718 | int count = 0; |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 719 | |
| 720 | if (who != null) { |
| 721 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 722 | return admin != null ? admin.maximumFailedPasswordsForWipe : count; |
| 723 | } |
| 724 | |
| 725 | final int N = mAdminList.size(); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 726 | for (int i=0; i<N; i++) { |
| 727 | ActiveAdmin admin = mAdminList.get(i); |
| 728 | if (count == 0) { |
| 729 | count = admin.maximumFailedPasswordsForWipe; |
| 730 | } else if (admin.maximumFailedPasswordsForWipe != 0 |
| 731 | && count > admin.maximumFailedPasswordsForWipe) { |
| 732 | count = admin.maximumFailedPasswordsForWipe; |
| 733 | } |
| 734 | } |
| 735 | return count; |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 736 | } |
| 737 | } |
| 738 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 739 | public boolean resetPassword(String password, int flags) { |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 740 | int quality; |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 741 | synchronized (this) { |
| 742 | // This API can only be called by an active device admin, |
| 743 | // so try to retrieve it to check that the caller is one. |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 744 | getActiveAdminForCallerLocked(null, |
| 745 | DeviceAdminInfo.USES_POLICY_RESET_PASSWORD); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 746 | quality = getPasswordQuality(null); |
| 747 | if (quality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 748 | int realQuality = LockPatternUtils.computePasswordQuality(password); |
| 749 | if (realQuality < quality) { |
| 750 | Slog.w(TAG, "resetPassword: password quality 0x" |
| 751 | + Integer.toHexString(quality) |
| 752 | + " does not meet required quality 0x" |
| 753 | + Integer.toHexString(quality)); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 754 | return false; |
| 755 | } |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 756 | quality = realQuality; |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 757 | } |
| 758 | int length = getPasswordMinimumLength(null); |
| 759 | if (password.length() < length) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 760 | Slog.w(TAG, "resetPassword: password length " + password.length() |
| 761 | + " does not meet required length " + length); |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 762 | return false; |
| 763 | } |
| 764 | } |
| 765 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 766 | int callingUid = Binder.getCallingUid(); |
| 767 | if (mPasswordOwner >= 0 && mPasswordOwner != callingUid) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 768 | 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] | 769 | return false; |
| 770 | } |
| 771 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 772 | // Don't do this with the lock held, because it is going to call |
| 773 | // back in to the service. |
| 774 | long ident = Binder.clearCallingIdentity(); |
| 775 | try { |
| 776 | LockPatternUtils utils = new LockPatternUtils(mContext); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 777 | utils.saveLockPassword(password, quality); |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 778 | synchronized (this) { |
| 779 | int newOwner = (flags&DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY) |
| 780 | != 0 ? callingUid : -1; |
| 781 | if (mPasswordOwner != newOwner) { |
| 782 | mPasswordOwner = newOwner; |
| 783 | saveSettingsLocked(); |
| 784 | } |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 785 | } |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 786 | } finally { |
| 787 | Binder.restoreCallingIdentity(ident); |
| 788 | } |
| 789 | |
| 790 | return true; |
| 791 | } |
| 792 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 793 | public void setMaximumTimeToLock(ComponentName who, long timeMs) { |
| 794 | synchronized (this) { |
| 795 | if (who == null) { |
| 796 | throw new NullPointerException("ComponentName is null"); |
| 797 | } |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 798 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 799 | DeviceAdminInfo.USES_POLICY_FORCE_LOCK); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 800 | if (ap.maximumTimeToUnlock != timeMs) { |
| 801 | ap.maximumTimeToUnlock = timeMs; |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 802 | |
| 803 | long ident = Binder.clearCallingIdentity(); |
| 804 | try { |
| 805 | saveSettingsLocked(); |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 806 | |
| 807 | timeMs = getMaximumTimeToLock(null); |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 808 | if (timeMs <= 0) { |
| 809 | timeMs = Integer.MAX_VALUE; |
| 810 | } |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 811 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 812 | try { |
| 813 | getIPowerManager().setMaximumScreenOffTimeount((int)timeMs); |
| 814 | } catch (RemoteException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 815 | Slog.w(TAG, "Failure talking with power manager", e); |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 816 | } |
| 817 | } finally { |
| 818 | Binder.restoreCallingIdentity(ident); |
| 819 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 820 | } |
| 821 | } |
| 822 | } |
| 823 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 824 | public long getMaximumTimeToLock(ComponentName who) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 825 | synchronized (this) { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 826 | long time = 0; |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 827 | |
| 828 | if (who != null) { |
| 829 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who); |
| 830 | return admin != null ? admin.maximumTimeToUnlock : time; |
| 831 | } |
| 832 | |
| 833 | final int N = mAdminList.size(); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 834 | for (int i=0; i<N; i++) { |
| 835 | ActiveAdmin admin = mAdminList.get(i); |
| 836 | if (time == 0) { |
| 837 | time = admin.maximumTimeToUnlock; |
| 838 | } else if (admin.maximumTimeToUnlock != 0 |
| 839 | && time > admin.maximumTimeToUnlock) { |
| 840 | time = admin.maximumTimeToUnlock; |
| 841 | } |
| 842 | } |
| 843 | return time; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 844 | } |
| 845 | } |
| 846 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 847 | public void lockNow() { |
| 848 | synchronized (this) { |
| 849 | // This API can only be called by an active device admin, |
| 850 | // so try to retrieve it to check that the caller is one. |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 851 | getActiveAdminForCallerLocked(null, |
| 852 | DeviceAdminInfo.USES_POLICY_FORCE_LOCK); |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 853 | long ident = Binder.clearCallingIdentity(); |
| 854 | try { |
| 855 | mIPowerManager.goToSleepWithReason(SystemClock.uptimeMillis(), |
| 856 | WindowManagerPolicy.OFF_BECAUSE_OF_ADMIN); |
| 857 | } catch (RemoteException e) { |
| 858 | } finally { |
| 859 | Binder.restoreCallingIdentity(ident); |
| 860 | } |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 861 | } |
| 862 | } |
| 863 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 864 | void wipeDataLocked(int flags) { |
| 865 | try { |
| 866 | RecoverySystem.rebootWipeUserData(mContext); |
| 867 | } catch (IOException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 868 | Slog.w(TAG, "Failed requesting data wipe", e); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 869 | } |
| 870 | } |
| 871 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 872 | public void wipeData(int flags) { |
| 873 | synchronized (this) { |
| 874 | // This API can only be called by an active device admin, |
| 875 | // so try to retrieve it to check that the caller is one. |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 876 | getActiveAdminForCallerLocked(null, |
| 877 | DeviceAdminInfo.USES_POLICY_WIPE_DATA); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 878 | long ident = Binder.clearCallingIdentity(); |
| 879 | try { |
| 880 | wipeDataLocked(flags); |
| 881 | } finally { |
| 882 | Binder.restoreCallingIdentity(ident); |
| 883 | } |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 884 | } |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | public void getRemoveWarning(ComponentName comp, final RemoteCallback result) { |
| 888 | mContext.enforceCallingOrSelfPermission( |
| 889 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
| 890 | |
| 891 | synchronized (this) { |
| 892 | ActiveAdmin admin = getActiveAdminUncheckedLocked(comp); |
| 893 | if (admin == null) { |
| 894 | try { |
| 895 | result.sendResult(null); |
| 896 | } catch (RemoteException e) { |
| 897 | } |
| 898 | return; |
| 899 | } |
| Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 900 | Intent intent = new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_DISABLE_REQUESTED); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 901 | intent.setComponent(admin.info.getComponent()); |
| 902 | mContext.sendOrderedBroadcast(intent, null, new BroadcastReceiver() { |
| 903 | @Override |
| 904 | public void onReceive(Context context, Intent intent) { |
| 905 | try { |
| 906 | result.sendResult(getResultExtras(false)); |
| 907 | } catch (RemoteException e) { |
| 908 | } |
| 909 | } |
| 910 | }, null, Activity.RESULT_OK, null, null); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 911 | } |
| 912 | } |
| 913 | |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 914 | public void setActivePasswordState(int quality, int length) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 915 | mContext.enforceCallingOrSelfPermission( |
| 916 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
| 917 | |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 918 | validateQualityConstant(quality); |
| 919 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 920 | synchronized (this) { |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 921 | if (mActivePasswordQuality != quality || mActivePasswordLength != length |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 922 | || mFailedPasswordAttempts != 0) { |
| 923 | long ident = Binder.clearCallingIdentity(); |
| 924 | try { |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 925 | mActivePasswordQuality = quality; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 926 | mActivePasswordLength = length; |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 927 | mFailedPasswordAttempts = 0; |
| 928 | saveSettingsLocked(); |
| Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 929 | sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_CHANGED, |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 930 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 931 | } finally { |
| 932 | Binder.restoreCallingIdentity(ident); |
| 933 | } |
| 934 | } |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | public void reportFailedPasswordAttempt() { |
| 939 | mContext.enforceCallingOrSelfPermission( |
| 940 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
| 941 | |
| 942 | synchronized (this) { |
| 943 | long ident = Binder.clearCallingIdentity(); |
| 944 | try { |
| 945 | mFailedPasswordAttempts++; |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 946 | saveSettingsLocked(); |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 947 | int max = getMaximumFailedPasswordsForWipe(null); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 948 | if (max > 0 && mFailedPasswordAttempts >= max) { |
| 949 | wipeDataLocked(0); |
| 950 | } |
| Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 951 | sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_FAILED, |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 952 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 953 | } finally { |
| 954 | Binder.restoreCallingIdentity(ident); |
| 955 | } |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | public void reportSuccessfulPasswordAttempt() { |
| 960 | mContext.enforceCallingOrSelfPermission( |
| 961 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
| 962 | |
| 963 | synchronized (this) { |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 964 | if (mFailedPasswordAttempts != 0 || mPasswordOwner >= 0) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 965 | long ident = Binder.clearCallingIdentity(); |
| 966 | try { |
| 967 | mFailedPasswordAttempts = 0; |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 968 | mPasswordOwner = -1; |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 969 | saveSettingsLocked(); |
| Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 970 | sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_SUCCEEDED, |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 971 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 972 | } finally { |
| 973 | Binder.restoreCallingIdentity(ident); |
| 974 | } |
| 975 | } |
| 976 | } |
| 977 | } |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 978 | |
| 979 | @Override |
| 980 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 981 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 982 | != PackageManager.PERMISSION_GRANTED) { |
| 983 | |
| 984 | pw.println("Permission Denial: can't dump DevicePolicyManagerService from from pid=" |
| 985 | + Binder.getCallingPid() |
| 986 | + ", uid=" + Binder.getCallingUid()); |
| 987 | return; |
| 988 | } |
| 989 | |
| 990 | final Printer p = new PrintWriterPrinter(pw); |
| 991 | |
| 992 | synchronized (this) { |
| 993 | p.println("Current Device Policy Manager state:"); |
| 994 | |
| 995 | p.println(" Enabled Device Admins:"); |
| 996 | final int N = mAdminList.size(); |
| 997 | for (int i=0; i<N; i++) { |
| 998 | ActiveAdmin ap = mAdminList.get(i); |
| 999 | if (ap != null) { |
| 1000 | pw.print(" "); pw.print(ap.info.getComponent().flattenToShortString()); |
| 1001 | pw.println(":"); |
| 1002 | ap.dump(" ", pw); |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | pw.println(" "); |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1007 | pw.print(" mActivePasswordQuality=0x"); |
| 1008 | pw.println(Integer.toHexString(mActivePasswordQuality)); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1009 | pw.print(" mActivePasswordLength="); pw.println(mActivePasswordLength); |
| 1010 | pw.print(" mFailedPasswordAttempts="); pw.println(mFailedPasswordAttempts); |
| 1011 | pw.print(" mPasswordOwner="); pw.println(mPasswordOwner); |
| 1012 | } |
| 1013 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1014 | } |