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