| 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 | |
| Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 19 | import static android.Manifest.permission.MANAGE_CA_CERTIFICATES; |
| 20 | |
| Maggie Benthall | 0469f41 | 2013-09-05 15:30:26 -0400 | [diff] [blame] | 21 | import com.android.internal.R; |
| Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 22 | import com.android.internal.os.storage.ExternalStorageFormatter; |
| Dianne Hackborn | 2269d157 | 2010-02-24 19:54:22 -0800 | [diff] [blame] | 23 | import com.android.internal.util.FastXmlSerializer; |
| Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 24 | import com.android.internal.util.JournaledFile; |
| Dianne Hackborn | 2269d157 | 2010-02-24 19:54:22 -0800 | [diff] [blame] | 25 | import com.android.internal.util.XmlUtils; |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 26 | import com.android.internal.widget.LockPatternUtils; |
| Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 27 | import com.android.org.conscrypt.TrustedCertificateStore; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 28 | |
| 29 | import org.xmlpull.v1.XmlPullParser; |
| 30 | import org.xmlpull.v1.XmlPullParserException; |
| 31 | import org.xmlpull.v1.XmlSerializer; |
| 32 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 33 | import android.app.Activity; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 34 | import android.app.ActivityManagerNative; |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 35 | import android.app.AlarmManager; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 36 | import android.app.AppGlobals; |
| Maggie Benthall | 0469f41 | 2013-09-05 15:30:26 -0400 | [diff] [blame] | 37 | import android.app.INotificationManager; |
| 38 | import android.app.Notification; |
| 39 | import android.app.NotificationManager; |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 40 | import android.app.PendingIntent; |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 41 | import android.app.admin.DeviceAdminInfo; |
| 42 | import android.app.admin.DeviceAdminReceiver; |
| 43 | import android.app.admin.DevicePolicyManager; |
| 44 | import android.app.admin.IDevicePolicyManager; |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 45 | import android.content.BroadcastReceiver; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 46 | import android.content.ComponentName; |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 47 | import android.content.ContentResolver; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 48 | import android.content.Context; |
| 49 | import android.content.Intent; |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 50 | import android.content.IntentFilter; |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 51 | import android.content.pm.ApplicationInfo; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 52 | import android.content.pm.IPackageManager; |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 53 | import android.content.pm.PackageInfo; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 54 | import android.content.pm.PackageManager; |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 55 | import android.content.pm.Signature; |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 56 | import android.content.pm.PackageManager.NameNotFoundException; |
| Andy Stadler | 1f35d48 | 2010-11-19 15:39:41 -0800 | [diff] [blame] | 57 | import android.content.pm.ResolveInfo; |
| Maggie Benthall | 0469f41 | 2013-09-05 15:30:26 -0400 | [diff] [blame] | 58 | import android.content.pm.UserInfo; |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 59 | import android.net.Uri; |
| Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 60 | import android.os.AsyncTask; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 61 | import android.os.Binder; |
| Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 62 | import android.os.Bundle; |
| Ben Komalo | ed48c8b | 2011-10-17 17:30:21 -0700 | [diff] [blame] | 63 | import android.os.Environment; |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 64 | import android.os.Handler; |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 65 | import android.os.IBinder; |
| 66 | import android.os.IPowerManager; |
| Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 67 | import android.os.PowerManager; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 68 | import android.os.Process; |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 69 | import android.os.RecoverySystem; |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 70 | import android.os.RemoteCallback; |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 71 | import android.os.RemoteException; |
| 72 | import android.os.ServiceManager; |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 73 | import android.os.SystemClock; |
| Andy Stadler | 0fe45de | 2011-01-20 16:35:09 -0800 | [diff] [blame] | 74 | import android.os.SystemProperties; |
| Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 75 | import android.os.UserHandle; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 76 | import android.os.UserManager; |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 77 | import android.provider.Settings; |
| Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 78 | import android.security.Credentials; |
| 79 | import android.security.IKeyChainService; |
| 80 | import android.security.KeyChain; |
| 81 | import android.security.KeyChain.KeyChainConnection; |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 82 | import android.util.AtomicFile; |
| Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 83 | import android.util.Log; |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 84 | import android.util.PrintWriterPrinter; |
| 85 | import android.util.Printer; |
| Andy Stadler | 1f35d48 | 2010-11-19 15:39:41 -0800 | [diff] [blame] | 86 | import android.util.Slog; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 87 | import android.util.SparseArray; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 88 | import android.util.Xml; |
| Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 89 | import android.view.IWindowManager; |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 90 | import android.view.WindowManagerPolicy; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 91 | |
| Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 92 | import java.io.ByteArrayInputStream; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 93 | import java.io.File; |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 94 | import java.io.FileDescriptor; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 95 | import java.io.FileInputStream; |
| Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 96 | import java.io.FileNotFoundException; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 97 | import java.io.FileOutputStream; |
| 98 | import java.io.IOException; |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 99 | import java.io.PrintWriter; |
| Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 100 | import java.security.KeyStore.TrustedCertificateEntry; |
| 101 | import java.security.cert.CertificateException; |
| 102 | import java.security.cert.CertificateFactory; |
| 103 | import java.security.cert.X509Certificate; |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 104 | import java.text.DateFormat; |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 105 | import java.util.ArrayList; |
| Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 106 | import java.util.Arrays; |
| 107 | import java.util.Collection; |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 108 | import java.util.Collections; |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 109 | import java.util.Date; |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 110 | import java.util.HashMap; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 111 | import java.util.List; |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 112 | import java.util.Set; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 113 | |
| 114 | /** |
| 115 | * Implementation of the device policy APIs. |
| 116 | */ |
| 117 | public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 118 | |
| Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 119 | private static final String TAG = "DevicePolicyManagerService"; |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 120 | |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 121 | private static final String DEVICE_POLICIES_XML = "device_policies.xml"; |
| 122 | |
| Jim Miller | 6b85768 | 2011-02-16 16:27:41 -0800 | [diff] [blame] | 123 | private static final int REQUEST_EXPIRE_PASSWORD = 5571; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 124 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 125 | private static final long MS_PER_DAY = 86400 * 1000; |
| 126 | |
| 127 | private static final long EXPIRATION_GRACE_PERIOD_MS = 5 * MS_PER_DAY; // 5 days, in ms |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 128 | |
| 129 | protected static final String ACTION_EXPIRED_PASSWORD_NOTIFICATION |
| 130 | = "com.android.server.ACTION_EXPIRED_PASSWORD_NOTIFICATION"; |
| 131 | |
| Maggie Benthall | 0469f41 | 2013-09-05 15:30:26 -0400 | [diff] [blame] | 132 | private static final int MONITORING_CERT_NOTIFICATION_ID = R.string.ssl_ca_cert_warning; |
| 133 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 134 | private static final boolean DBG = false; |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 135 | |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 136 | final Context mContext; |
| Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 137 | final PowerManager.WakeLock mWakeLock; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 138 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 139 | IPowerManager mIPowerManager; |
| Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 140 | IWindowManager mIWindowManager; |
| Maggie Benthall | 0469f41 | 2013-09-05 15:30:26 -0400 | [diff] [blame] | 141 | NotificationManager mNotificationManager; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 142 | |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 143 | private DeviceOwner mDeviceOwner; |
| 144 | |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 145 | /** |
| 146 | * Whether or not device admin feature is supported. If it isn't return defaults for all |
| 147 | * public methods. |
| 148 | */ |
| 149 | private boolean mHasFeature; |
| 150 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 151 | public static class DevicePolicyData { |
| 152 | int mActivePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
| 153 | int mActivePasswordLength = 0; |
| 154 | int mActivePasswordUpperCase = 0; |
| 155 | int mActivePasswordLowerCase = 0; |
| 156 | int mActivePasswordLetters = 0; |
| 157 | int mActivePasswordNumeric = 0; |
| 158 | int mActivePasswordSymbols = 0; |
| 159 | int mActivePasswordNonLetter = 0; |
| 160 | int mFailedPasswordAttempts = 0; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 161 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 162 | int mUserHandle;; |
| 163 | int mPasswordOwner = -1; |
| 164 | long mLastMaximumTimeToLock = -1; |
| 165 | |
| 166 | final HashMap<ComponentName, ActiveAdmin> mAdminMap |
| 167 | = new HashMap<ComponentName, ActiveAdmin>(); |
| 168 | final ArrayList<ActiveAdmin> mAdminList |
| 169 | = new ArrayList<ActiveAdmin>(); |
| 170 | |
| 171 | public DevicePolicyData(int userHandle) { |
| 172 | mUserHandle = userHandle; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | final SparseArray<DevicePolicyData> mUserData = new SparseArray<DevicePolicyData>(); |
| 177 | |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 178 | Handler mHandler = new Handler(); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 179 | |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 180 | BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 181 | @Override |
| 182 | public void onReceive(Context context, Intent intent) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 183 | final String action = intent.getAction(); |
| 184 | final int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, |
| 185 | getSendingUserId()); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 186 | if (Intent.ACTION_BOOT_COMPLETED.equals(action) |
| 187 | || ACTION_EXPIRED_PASSWORD_NOTIFICATION.equals(action)) { |
| Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 188 | if (DBG) Slog.v(TAG, "Sending password expiration notifications for action " |
| 189 | + action + " for user " + userHandle); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 190 | mHandler.post(new Runnable() { |
| 191 | public void run() { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 192 | handlePasswordExpirationNotification(getUserData(userHandle)); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 193 | } |
| 194 | }); |
| Maggie Benthall | 0469f41 | 2013-09-05 15:30:26 -0400 | [diff] [blame] | 195 | } |
| 196 | if (Intent.ACTION_BOOT_COMPLETED.equals(action) |
| 197 | || KeyChain.ACTION_STORAGE_CHANGED.equals(action)) { |
| 198 | manageMonitoringCertificateNotification(intent); |
| 199 | } |
| 200 | if (Intent.ACTION_USER_REMOVED.equals(action)) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 201 | removeUserData(userHandle); |
| 202 | } else if (Intent.ACTION_USER_STARTED.equals(action) |
| 203 | || Intent.ACTION_PACKAGE_CHANGED.equals(action) |
| 204 | || Intent.ACTION_PACKAGE_REMOVED.equals(action) |
| 205 | || Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) { |
| 206 | |
| 207 | if (Intent.ACTION_USER_STARTED.equals(action)) { |
| 208 | // Reset the policy data |
| 209 | synchronized (DevicePolicyManagerService.this) { |
| 210 | mUserData.remove(userHandle); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | handlePackagesChanged(userHandle); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | }; |
| 218 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 219 | static class ActiveAdmin { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 220 | final DeviceAdminInfo info; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 221 | |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 222 | int passwordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 223 | |
| 224 | static final int DEF_MINIMUM_PASSWORD_LENGTH = 0; |
| 225 | int minimumPasswordLength = DEF_MINIMUM_PASSWORD_LENGTH; |
| 226 | |
| 227 | static final int DEF_PASSWORD_HISTORY_LENGTH = 0; |
| 228 | int passwordHistoryLength = DEF_PASSWORD_HISTORY_LENGTH; |
| 229 | |
| 230 | static final int DEF_MINIMUM_PASSWORD_UPPER_CASE = 0; |
| 231 | int minimumPasswordUpperCase = DEF_MINIMUM_PASSWORD_UPPER_CASE; |
| 232 | |
| 233 | static final int DEF_MINIMUM_PASSWORD_LOWER_CASE = 0; |
| 234 | int minimumPasswordLowerCase = DEF_MINIMUM_PASSWORD_LOWER_CASE; |
| 235 | |
| 236 | static final int DEF_MINIMUM_PASSWORD_LETTERS = 1; |
| Dianne Hackborn | 2a10840 | 2011-05-26 11:45:00 -0700 | [diff] [blame] | 237 | int minimumPasswordLetters = DEF_MINIMUM_PASSWORD_LETTERS; |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 238 | |
| 239 | static final int DEF_MINIMUM_PASSWORD_NUMERIC = 1; |
| 240 | int minimumPasswordNumeric = DEF_MINIMUM_PASSWORD_NUMERIC; |
| 241 | |
| 242 | static final int DEF_MINIMUM_PASSWORD_SYMBOLS = 1; |
| 243 | int minimumPasswordSymbols = DEF_MINIMUM_PASSWORD_SYMBOLS; |
| 244 | |
| 245 | static final int DEF_MINIMUM_PASSWORD_NON_LETTER = 0; |
| 246 | int minimumPasswordNonLetter = DEF_MINIMUM_PASSWORD_NON_LETTER; |
| 247 | |
| 248 | static final long DEF_MAXIMUM_TIME_TO_UNLOCK = 0; |
| 249 | long maximumTimeToUnlock = DEF_MAXIMUM_TIME_TO_UNLOCK; |
| 250 | |
| 251 | static final int DEF_MAXIMUM_FAILED_PASSWORDS_FOR_WIPE = 0; |
| 252 | int maximumFailedPasswordsForWipe = DEF_MAXIMUM_FAILED_PASSWORDS_FOR_WIPE; |
| 253 | |
| 254 | static final long DEF_PASSWORD_EXPIRATION_TIMEOUT = 0; |
| 255 | long passwordExpirationTimeout = DEF_PASSWORD_EXPIRATION_TIMEOUT; |
| 256 | |
| 257 | static final long DEF_PASSWORD_EXPIRATION_DATE = 0; |
| 258 | long passwordExpirationDate = DEF_PASSWORD_EXPIRATION_DATE; |
| 259 | |
| Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 260 | static final int DEF_KEYGUARD_FEATURES_DISABLED = 0; // none |
| 261 | int disabledKeyguardFeatures = DEF_KEYGUARD_FEATURES_DISABLED; |
| Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 262 | |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 263 | boolean encryptionRequested = false; |
| Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 264 | boolean disableCamera = false; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 265 | |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 266 | // TODO: review implementation decisions with frameworks team |
| 267 | boolean specifiesGlobalProxy = false; |
| 268 | String globalProxySpec = null; |
| 269 | String globalProxyExclusionList = null; |
| 270 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 271 | ActiveAdmin(DeviceAdminInfo _info) { |
| 272 | info = _info; |
| 273 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 274 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 275 | int getUid() { return info.getActivityInfo().applicationInfo.uid; } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 276 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 277 | public UserHandle getUserHandle() { |
| 278 | return new UserHandle(UserHandle.getUserId(info.getActivityInfo().applicationInfo.uid)); |
| 279 | } |
| 280 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 281 | void writeToXml(XmlSerializer out) |
| 282 | throws IllegalArgumentException, IllegalStateException, IOException { |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 283 | out.startTag(null, "policies"); |
| 284 | info.writePoliciesToXml(out); |
| 285 | out.endTag(null, "policies"); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 286 | if (passwordQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { |
| 287 | out.startTag(null, "password-quality"); |
| 288 | out.attribute(null, "value", Integer.toString(passwordQuality)); |
| 289 | out.endTag(null, "password-quality"); |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 290 | if (minimumPasswordLength != DEF_MINIMUM_PASSWORD_LENGTH) { |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 291 | out.startTag(null, "min-password-length"); |
| 292 | out.attribute(null, "value", Integer.toString(minimumPasswordLength)); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 293 | out.endTag(null, "min-password-length"); |
| 294 | } |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 295 | if(passwordHistoryLength != DEF_PASSWORD_HISTORY_LENGTH) { |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 296 | out.startTag(null, "password-history-length"); |
| 297 | out.attribute(null, "value", Integer.toString(passwordHistoryLength)); |
| 298 | out.endTag(null, "password-history-length"); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 299 | } |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 300 | if (minimumPasswordUpperCase != DEF_MINIMUM_PASSWORD_UPPER_CASE) { |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 301 | out.startTag(null, "min-password-uppercase"); |
| 302 | out.attribute(null, "value", Integer.toString(minimumPasswordUpperCase)); |
| 303 | out.endTag(null, "min-password-uppercase"); |
| 304 | } |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 305 | if (minimumPasswordLowerCase != DEF_MINIMUM_PASSWORD_LOWER_CASE) { |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 306 | out.startTag(null, "min-password-lowercase"); |
| 307 | out.attribute(null, "value", Integer.toString(minimumPasswordLowerCase)); |
| 308 | out.endTag(null, "min-password-lowercase"); |
| 309 | } |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 310 | if (minimumPasswordLetters != DEF_MINIMUM_PASSWORD_LETTERS) { |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 311 | out.startTag(null, "min-password-letters"); |
| 312 | out.attribute(null, "value", Integer.toString(minimumPasswordLetters)); |
| 313 | out.endTag(null, "min-password-letters"); |
| 314 | } |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 315 | if (minimumPasswordNumeric != DEF_MINIMUM_PASSWORD_NUMERIC) { |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 316 | out.startTag(null, "min-password-numeric"); |
| 317 | out.attribute(null, "value", Integer.toString(minimumPasswordNumeric)); |
| 318 | out.endTag(null, "min-password-numeric"); |
| 319 | } |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 320 | if (minimumPasswordSymbols != DEF_MINIMUM_PASSWORD_SYMBOLS) { |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 321 | out.startTag(null, "min-password-symbols"); |
| 322 | out.attribute(null, "value", Integer.toString(minimumPasswordSymbols)); |
| 323 | out.endTag(null, "min-password-symbols"); |
| 324 | } |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 325 | if (minimumPasswordNonLetter > DEF_MINIMUM_PASSWORD_NON_LETTER) { |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 326 | out.startTag(null, "min-password-nonletter"); |
| 327 | out.attribute(null, "value", Integer.toString(minimumPasswordNonLetter)); |
| 328 | out.endTag(null, "min-password-nonletter"); |
| 329 | } |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 330 | } |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 331 | if (maximumTimeToUnlock != DEF_MAXIMUM_TIME_TO_UNLOCK) { |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 332 | out.startTag(null, "max-time-to-unlock"); |
| 333 | out.attribute(null, "value", Long.toString(maximumTimeToUnlock)); |
| 334 | out.endTag(null, "max-time-to-unlock"); |
| 335 | } |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 336 | if (maximumFailedPasswordsForWipe != DEF_MAXIMUM_FAILED_PASSWORDS_FOR_WIPE) { |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 337 | out.startTag(null, "max-failed-password-wipe"); |
| 338 | out.attribute(null, "value", Integer.toString(maximumFailedPasswordsForWipe)); |
| 339 | out.endTag(null, "max-failed-password-wipe"); |
| 340 | } |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 341 | if (specifiesGlobalProxy) { |
| 342 | out.startTag(null, "specifies-global-proxy"); |
| 343 | out.attribute(null, "value", Boolean.toString(specifiesGlobalProxy)); |
| 344 | out.endTag(null, "specifies_global_proxy"); |
| 345 | if (globalProxySpec != null) { |
| 346 | out.startTag(null, "global-proxy-spec"); |
| 347 | out.attribute(null, "value", globalProxySpec); |
| 348 | out.endTag(null, "global-proxy-spec"); |
| 349 | } |
| 350 | if (globalProxyExclusionList != null) { |
| 351 | out.startTag(null, "global-proxy-exclusion-list"); |
| 352 | out.attribute(null, "value", globalProxyExclusionList); |
| 353 | out.endTag(null, "global-proxy-exclusion-list"); |
| 354 | } |
| 355 | } |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 356 | if (passwordExpirationTimeout != DEF_PASSWORD_EXPIRATION_TIMEOUT) { |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 357 | out.startTag(null, "password-expiration-timeout"); |
| 358 | out.attribute(null, "value", Long.toString(passwordExpirationTimeout)); |
| 359 | out.endTag(null, "password-expiration-timeout"); |
| 360 | } |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 361 | if (passwordExpirationDate != DEF_PASSWORD_EXPIRATION_DATE) { |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 362 | out.startTag(null, "password-expiration-date"); |
| 363 | out.attribute(null, "value", Long.toString(passwordExpirationDate)); |
| 364 | out.endTag(null, "password-expiration-date"); |
| 365 | } |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 366 | if (encryptionRequested) { |
| 367 | out.startTag(null, "encryption-requested"); |
| 368 | out.attribute(null, "value", Boolean.toString(encryptionRequested)); |
| 369 | out.endTag(null, "encryption-requested"); |
| 370 | } |
| Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 371 | if (disableCamera) { |
| 372 | out.startTag(null, "disable-camera"); |
| 373 | out.attribute(null, "value", Boolean.toString(disableCamera)); |
| 374 | out.endTag(null, "disable-camera"); |
| 375 | } |
| Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 376 | if (disabledKeyguardFeatures != DEF_KEYGUARD_FEATURES_DISABLED) { |
| 377 | out.startTag(null, "disable-keyguard-features"); |
| 378 | out.attribute(null, "value", Integer.toString(disabledKeyguardFeatures)); |
| 379 | out.endTag(null, "disable-keyguard-features"); |
| Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 380 | } |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 381 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 382 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 383 | void readFromXml(XmlPullParser parser) |
| 384 | throws XmlPullParserException, IOException { |
| 385 | int outerDepth = parser.getDepth(); |
| 386 | int type; |
| 387 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 388 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 389 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 390 | continue; |
| 391 | } |
| 392 | String tag = parser.getName(); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 393 | if ("policies".equals(tag)) { |
| 394 | info.readPoliciesFromXml(parser); |
| 395 | } else if ("password-quality".equals(tag)) { |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 396 | passwordQuality = Integer.parseInt( |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 397 | parser.getAttributeValue(null, "value")); |
| 398 | } else if ("min-password-length".equals(tag)) { |
| 399 | minimumPasswordLength = Integer.parseInt( |
| 400 | parser.getAttributeValue(null, "value")); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 401 | } else if ("password-history-length".equals(tag)) { |
| 402 | passwordHistoryLength = Integer.parseInt( |
| 403 | parser.getAttributeValue(null, "value")); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 404 | } else if ("min-password-uppercase".equals(tag)) { |
| 405 | minimumPasswordUpperCase = Integer.parseInt( |
| 406 | parser.getAttributeValue(null, "value")); |
| 407 | } else if ("min-password-lowercase".equals(tag)) { |
| 408 | minimumPasswordLowerCase = Integer.parseInt( |
| 409 | parser.getAttributeValue(null, "value")); |
| 410 | } else if ("min-password-letters".equals(tag)) { |
| 411 | minimumPasswordLetters = Integer.parseInt( |
| 412 | parser.getAttributeValue(null, "value")); |
| 413 | } else if ("min-password-numeric".equals(tag)) { |
| 414 | minimumPasswordNumeric = Integer.parseInt( |
| 415 | parser.getAttributeValue(null, "value")); |
| 416 | } else if ("min-password-symbols".equals(tag)) { |
| 417 | minimumPasswordSymbols = Integer.parseInt( |
| 418 | parser.getAttributeValue(null, "value")); |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 419 | } else if ("min-password-nonletter".equals(tag)) { |
| 420 | minimumPasswordNonLetter = Integer.parseInt( |
| 421 | parser.getAttributeValue(null, "value")); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 422 | } else if ("max-time-to-unlock".equals(tag)) { |
| 423 | maximumTimeToUnlock = Long.parseLong( |
| 424 | parser.getAttributeValue(null, "value")); |
| 425 | } else if ("max-failed-password-wipe".equals(tag)) { |
| 426 | maximumFailedPasswordsForWipe = Integer.parseInt( |
| 427 | parser.getAttributeValue(null, "value")); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 428 | } else if ("specifies-global-proxy".equals(tag)) { |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 429 | specifiesGlobalProxy = Boolean.parseBoolean( |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 430 | parser.getAttributeValue(null, "value")); |
| 431 | } else if ("global-proxy-spec".equals(tag)) { |
| 432 | globalProxySpec = |
| 433 | parser.getAttributeValue(null, "value"); |
| 434 | } else if ("global-proxy-exclusion-list".equals(tag)) { |
| 435 | globalProxyExclusionList = |
| 436 | parser.getAttributeValue(null, "value"); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 437 | } else if ("password-expiration-timeout".equals(tag)) { |
| 438 | passwordExpirationTimeout = Long.parseLong( |
| 439 | parser.getAttributeValue(null, "value")); |
| 440 | } else if ("password-expiration-date".equals(tag)) { |
| 441 | passwordExpirationDate = Long.parseLong( |
| 442 | parser.getAttributeValue(null, "value")); |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 443 | } else if ("encryption-requested".equals(tag)) { |
| 444 | encryptionRequested = Boolean.parseBoolean( |
| 445 | parser.getAttributeValue(null, "value")); |
| Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 446 | } else if ("disable-camera".equals(tag)) { |
| 447 | disableCamera = Boolean.parseBoolean( |
| 448 | parser.getAttributeValue(null, "value")); |
| Amith Yamasani | 7077b3c | 2012-10-04 10:28:50 -0700 | [diff] [blame] | 449 | } else if ("disable-keyguard-features".equals(tag)) { |
| 450 | disabledKeyguardFeatures = Integer.parseInt( |
| 451 | parser.getAttributeValue(null, "value")); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 452 | } else { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 453 | Slog.w(TAG, "Unknown admin tag: " + tag); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 454 | } |
| 455 | XmlUtils.skipCurrentTag(parser); |
| 456 | } |
| 457 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 458 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 459 | void dump(String prefix, PrintWriter pw) { |
| 460 | pw.print(prefix); pw.print("uid="); pw.println(getUid()); |
| 461 | pw.print(prefix); pw.println("policies:"); |
| 462 | ArrayList<DeviceAdminInfo.PolicyInfo> pols = info.getUsedPolicies(); |
| 463 | if (pols != null) { |
| 464 | for (int i=0; i<pols.size(); i++) { |
| 465 | pw.print(prefix); pw.print(" "); pw.println(pols.get(i).tag); |
| 466 | } |
| 467 | } |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 468 | pw.print(prefix); pw.print("passwordQuality=0x"); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 469 | pw.println(Integer.toHexString(passwordQuality)); |
| 470 | pw.print(prefix); pw.print("minimumPasswordLength="); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 471 | pw.println(minimumPasswordLength); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 472 | pw.print(prefix); pw.print("passwordHistoryLength="); |
| 473 | pw.println(passwordHistoryLength); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 474 | pw.print(prefix); pw.print("minimumPasswordUpperCase="); |
| 475 | pw.println(minimumPasswordUpperCase); |
| 476 | pw.print(prefix); pw.print("minimumPasswordLowerCase="); |
| 477 | pw.println(minimumPasswordLowerCase); |
| 478 | pw.print(prefix); pw.print("minimumPasswordLetters="); |
| 479 | pw.println(minimumPasswordLetters); |
| 480 | pw.print(prefix); pw.print("minimumPasswordNumeric="); |
| 481 | pw.println(minimumPasswordNumeric); |
| 482 | pw.print(prefix); pw.print("minimumPasswordSymbols="); |
| 483 | pw.println(minimumPasswordSymbols); |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 484 | pw.print(prefix); pw.print("minimumPasswordNonLetter="); |
| 485 | pw.println(minimumPasswordNonLetter); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 486 | pw.print(prefix); pw.print("maximumTimeToUnlock="); |
| 487 | pw.println(maximumTimeToUnlock); |
| 488 | pw.print(prefix); pw.print("maximumFailedPasswordsForWipe="); |
| 489 | pw.println(maximumFailedPasswordsForWipe); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 490 | pw.print(prefix); pw.print("specifiesGlobalProxy="); |
| 491 | pw.println(specifiesGlobalProxy); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 492 | pw.print(prefix); pw.print("passwordExpirationTimeout="); |
| 493 | pw.println(passwordExpirationTimeout); |
| 494 | pw.print(prefix); pw.print("passwordExpirationDate="); |
| 495 | pw.println(passwordExpirationDate); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 496 | if (globalProxySpec != null) { |
| 497 | pw.print(prefix); pw.print("globalProxySpec="); |
| 498 | pw.println(globalProxySpec); |
| 499 | } |
| 500 | if (globalProxyExclusionList != null) { |
| 501 | pw.print(prefix); pw.print("globalProxyEclusionList="); |
| 502 | pw.println(globalProxyExclusionList); |
| 503 | } |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 504 | pw.print(prefix); pw.print("encryptionRequested="); |
| 505 | pw.println(encryptionRequested); |
| Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 506 | pw.print(prefix); pw.print("disableCamera="); |
| 507 | pw.println(disableCamera); |
| Amith Yamasani | 7077b3c | 2012-10-04 10:28:50 -0700 | [diff] [blame] | 508 | pw.print(prefix); pw.print("disabledKeyguardFeatures="); |
| 509 | pw.println(disabledKeyguardFeatures); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 510 | } |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 511 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 512 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 513 | private void handlePackagesChanged(int userHandle) { |
| 514 | boolean removed = false; |
| Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 515 | if (DBG) Slog.d(TAG, "Handling package changes for user " + userHandle); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 516 | DevicePolicyData policy = getUserData(userHandle); |
| 517 | IPackageManager pm = AppGlobals.getPackageManager(); |
| 518 | for (int i = policy.mAdminList.size() - 1; i >= 0; i--) { |
| 519 | ActiveAdmin aa = policy.mAdminList.get(i); |
| 520 | try { |
| 521 | if (pm.getPackageInfo(aa.info.getPackageName(), 0, userHandle) == null |
| 522 | || pm.getReceiverInfo(aa.info.getComponent(), 0, userHandle) == null) { |
| 523 | removed = true; |
| 524 | policy.mAdminList.remove(i); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 525 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 526 | } catch (RemoteException re) { |
| 527 | // Shouldn't happen |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 528 | } |
| 529 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 530 | if (removed) { |
| 531 | validatePasswordOwnerLocked(policy); |
| 532 | syncDeviceCapabilitiesLocked(policy); |
| 533 | saveSettingsLocked(policy.mUserHandle); |
| 534 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 535 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 536 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 537 | /** |
| 538 | * Instantiates the service. |
| 539 | */ |
| 540 | public DevicePolicyManagerService(Context context) { |
| 541 | mContext = context; |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 542 | mHasFeature = context.getPackageManager().hasSystemFeature( |
| 543 | PackageManager.FEATURE_DEVICE_ADMIN); |
| Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 544 | mWakeLock = ((PowerManager)context.getSystemService(Context.POWER_SERVICE)) |
| 545 | .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DPM"); |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 546 | if (!mHasFeature) { |
| 547 | // Skip the rest of the initialization |
| 548 | return; |
| 549 | } |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 550 | IntentFilter filter = new IntentFilter(); |
| 551 | filter.addAction(Intent.ACTION_BOOT_COMPLETED); |
| 552 | filter.addAction(ACTION_EXPIRED_PASSWORD_NOTIFICATION); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 553 | filter.addAction(Intent.ACTION_USER_REMOVED); |
| 554 | filter.addAction(Intent.ACTION_USER_STARTED); |
| Maggie Benthall | 0469f41 | 2013-09-05 15:30:26 -0400 | [diff] [blame] | 555 | filter.addAction(KeyChain.ACTION_STORAGE_CHANGED); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 556 | context.registerReceiverAsUser(mReceiver, UserHandle.ALL, filter, null, mHandler); |
| 557 | filter = new IntentFilter(); |
| 558 | filter.addAction(Intent.ACTION_PACKAGE_CHANGED); |
| 559 | filter.addAction(Intent.ACTION_PACKAGE_REMOVED); |
| 560 | filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 561 | filter.addAction(Intent.ACTION_PACKAGE_ADDED); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 562 | filter.addDataScheme("package"); |
| 563 | context.registerReceiverAsUser(mReceiver, UserHandle.ALL, filter, null, mHandler); |
| 564 | } |
| 565 | |
| 566 | /** |
| 567 | * Creates and loads the policy data from xml. |
| 568 | * @param userHandle the user for whom to load the policy data |
| 569 | * @return |
| 570 | */ |
| 571 | DevicePolicyData getUserData(int userHandle) { |
| 572 | synchronized (this) { |
| 573 | DevicePolicyData policy = mUserData.get(userHandle); |
| 574 | if (policy == null) { |
| 575 | policy = new DevicePolicyData(userHandle); |
| 576 | mUserData.append(userHandle, policy); |
| 577 | loadSettingsLocked(policy, userHandle); |
| 578 | } |
| 579 | return policy; |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | void removeUserData(int userHandle) { |
| 584 | synchronized (this) { |
| 585 | if (userHandle == UserHandle.USER_OWNER) { |
| 586 | Slog.w(TAG, "Tried to remove device policy file for user 0! Ignoring."); |
| 587 | return; |
| 588 | } |
| 589 | DevicePolicyData policy = mUserData.get(userHandle); |
| 590 | if (policy != null) { |
| 591 | mUserData.remove(userHandle); |
| 592 | } |
| 593 | File policyFile = new File(Environment.getUserSystemDirectory(userHandle), |
| 594 | DEVICE_POLICIES_XML); |
| 595 | policyFile.delete(); |
| 596 | Slog.i(TAG, "Removed device policy file " + policyFile.getAbsolutePath()); |
| 597 | } |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 598 | } |
| 599 | |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 600 | void loadDeviceOwner() { |
| 601 | synchronized (this) { |
| 602 | if (DeviceOwner.isRegistered()) { |
| 603 | mDeviceOwner = new DeviceOwner(); |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | |
| Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 608 | /** |
| 609 | * Set an alarm for an upcoming event - expiration warning, expiration, or post-expiration |
| 610 | * reminders. Clears alarm if no expirations are configured. |
| 611 | */ |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 612 | protected void setExpirationAlarmCheckLocked(Context context, DevicePolicyData policy) { |
| 613 | final long expiration = getPasswordExpirationLocked(null, policy.mUserHandle); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 614 | final long now = System.currentTimeMillis(); |
| 615 | final long timeToExpire = expiration - now; |
| 616 | final long alarmTime; |
| Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 617 | if (expiration == 0) { |
| 618 | // No expirations are currently configured: Cancel alarm. |
| 619 | alarmTime = 0; |
| 620 | } else if (timeToExpire <= 0) { |
| 621 | // The password has already expired: Repeat every 24 hours. |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 622 | alarmTime = now + MS_PER_DAY; |
| Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 623 | } else { |
| 624 | // Selecting the next alarm time: Roll forward to the next 24 hour multiple before |
| 625 | // the expiration time. |
| 626 | long alarmInterval = timeToExpire % MS_PER_DAY; |
| 627 | if (alarmInterval == 0) { |
| 628 | alarmInterval = MS_PER_DAY; |
| 629 | } |
| 630 | alarmTime = now + alarmInterval; |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 631 | } |
| 632 | |
| Andy Stadler | 1f35d48 | 2010-11-19 15:39:41 -0800 | [diff] [blame] | 633 | long token = Binder.clearCallingIdentity(); |
| 634 | try { |
| 635 | AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 636 | PendingIntent pi = PendingIntent.getBroadcastAsUser(context, REQUEST_EXPIRE_PASSWORD, |
| Andy Stadler | 1f35d48 | 2010-11-19 15:39:41 -0800 | [diff] [blame] | 637 | new Intent(ACTION_EXPIRED_PASSWORD_NOTIFICATION), |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 638 | PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT, |
| 639 | new UserHandle(policy.mUserHandle)); |
| Andy Stadler | 1f35d48 | 2010-11-19 15:39:41 -0800 | [diff] [blame] | 640 | am.cancel(pi); |
| Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 641 | if (alarmTime != 0) { |
| 642 | am.set(AlarmManager.RTC, alarmTime, pi); |
| 643 | } |
| Andy Stadler | 1f35d48 | 2010-11-19 15:39:41 -0800 | [diff] [blame] | 644 | } finally { |
| 645 | Binder.restoreCallingIdentity(token); |
| 646 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 647 | } |
| 648 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 649 | private IPowerManager getIPowerManager() { |
| 650 | if (mIPowerManager == null) { |
| 651 | IBinder b = ServiceManager.getService(Context.POWER_SERVICE); |
| 652 | mIPowerManager = IPowerManager.Stub.asInterface(b); |
| 653 | } |
| 654 | return mIPowerManager; |
| 655 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 656 | |
| Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 657 | private IWindowManager getWindowManager() { |
| 658 | if (mIWindowManager == null) { |
| 659 | IBinder b = ServiceManager.getService(Context.WINDOW_SERVICE); |
| 660 | mIWindowManager = IWindowManager.Stub.asInterface(b); |
| 661 | } |
| 662 | return mIWindowManager; |
| 663 | } |
| 664 | |
| Maggie Benthall | 0469f41 | 2013-09-05 15:30:26 -0400 | [diff] [blame] | 665 | private NotificationManager getNotificationManager() { |
| 666 | if (mNotificationManager == null) { |
| 667 | mNotificationManager = |
| 668 | (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); |
| 669 | } |
| 670 | return mNotificationManager; |
| 671 | } |
| 672 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 673 | ActiveAdmin getActiveAdminUncheckedLocked(ComponentName who, int userHandle) { |
| 674 | ActiveAdmin admin = getUserData(userHandle).mAdminMap.get(who); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 675 | if (admin != null |
| 676 | && who.getPackageName().equals(admin.info.getActivityInfo().packageName) |
| 677 | && who.getClassName().equals(admin.info.getActivityInfo().name)) { |
| 678 | return admin; |
| 679 | } |
| 680 | return null; |
| 681 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 682 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 683 | ActiveAdmin getActiveAdminForCallerLocked(ComponentName who, int reqPolicy) |
| 684 | throws SecurityException { |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 685 | final int callingUid = Binder.getCallingUid(); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 686 | final int userHandle = UserHandle.getUserId(callingUid); |
| 687 | final DevicePolicyData policy = getUserData(userHandle); |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 688 | if (who != null) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 689 | ActiveAdmin admin = policy.mAdminMap.get(who); |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 690 | if (admin == null) { |
| 691 | throw new SecurityException("No active admin " + who); |
| 692 | } |
| 693 | if (admin.getUid() != callingUid) { |
| 694 | throw new SecurityException("Admin " + who + " is not owned by uid " |
| 695 | + Binder.getCallingUid()); |
| 696 | } |
| 697 | if (!admin.info.usesPolicy(reqPolicy)) { |
| 698 | throw new SecurityException("Admin " + admin.info.getComponent() |
| 699 | + " did not specify uses-policy for: " |
| 700 | + admin.info.getTagForPolicy(reqPolicy)); |
| 701 | } |
| 702 | return admin; |
| 703 | } else { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 704 | final int N = policy.mAdminList.size(); |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 705 | for (int i=0; i<N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 706 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 707 | if (admin.getUid() == callingUid && admin.info.usesPolicy(reqPolicy)) { |
| 708 | return admin; |
| 709 | } |
| 710 | } |
| 711 | throw new SecurityException("No active admin owned by uid " |
| 712 | + Binder.getCallingUid() + " for policy #" + reqPolicy); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 713 | } |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 714 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 715 | |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 716 | void sendAdminCommandLocked(ActiveAdmin admin, String action) { |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 717 | sendAdminCommandLocked(admin, action, null); |
| 718 | } |
| 719 | |
| 720 | void sendAdminCommandLocked(ActiveAdmin admin, String action, BroadcastReceiver result) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 721 | Intent intent = new Intent(action); |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 722 | intent.setComponent(admin.info.getComponent()); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 723 | if (action.equals(DeviceAdminReceiver.ACTION_PASSWORD_EXPIRING)) { |
| 724 | intent.putExtra("expiration", admin.passwordExpirationDate); |
| 725 | } |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 726 | if (result != null) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 727 | mContext.sendOrderedBroadcastAsUser(intent, admin.getUserHandle(), |
| Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 728 | null, result, mHandler, Activity.RESULT_OK, null, null); |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 729 | } else { |
| Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 730 | mContext.sendBroadcastAsUser(intent, UserHandle.OWNER); |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 731 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 732 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 733 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 734 | void sendAdminCommandLocked(String action, int reqPolicy, int userHandle) { |
| 735 | final DevicePolicyData policy = getUserData(userHandle); |
| 736 | final int count = policy.mAdminList.size(); |
| 737 | if (count > 0) { |
| 738 | for (int i = 0; i < count; i++) { |
| 739 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 740 | if (admin.info.usesPolicy(reqPolicy)) { |
| 741 | sendAdminCommandLocked(admin, action); |
| 742 | } |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 743 | } |
| Dianne Hackborn | 4141d03 | 2010-01-21 16:29:00 -0800 | [diff] [blame] | 744 | } |
| 745 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 746 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 747 | void removeActiveAdminLocked(final ComponentName adminReceiver, int userHandle) { |
| 748 | final ActiveAdmin admin = getActiveAdminUncheckedLocked(adminReceiver, userHandle); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 749 | if (admin != null) { |
| 750 | sendAdminCommandLocked(admin, |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 751 | DeviceAdminReceiver.ACTION_DEVICE_ADMIN_DISABLED, |
| 752 | new BroadcastReceiver() { |
| 753 | @Override |
| 754 | public void onReceive(Context context, Intent intent) { |
| Dianne Hackborn | 2fe8fb2 | 2012-06-15 17:05:25 -0700 | [diff] [blame] | 755 | synchronized (DevicePolicyManagerService.this) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 756 | int userHandle = admin.getUserHandle().getIdentifier(); |
| 757 | DevicePolicyData policy = getUserData(userHandle); |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 758 | boolean doProxyCleanup = admin.info.usesPolicy( |
| 759 | DeviceAdminInfo.USES_POLICY_SETS_GLOBAL_PROXY); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 760 | policy.mAdminList.remove(admin); |
| 761 | policy.mAdminMap.remove(adminReceiver); |
| 762 | validatePasswordOwnerLocked(policy); |
| 763 | syncDeviceCapabilitiesLocked(policy); |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 764 | if (doProxyCleanup) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 765 | resetGlobalProxyLocked(getUserData(userHandle)); |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 766 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 767 | saveSettingsLocked(userHandle); |
| 768 | updateMaximumTimeToLockLocked(policy); |
| Dianne Hackborn | d998acb3 | 2011-05-25 10:48:28 -0700 | [diff] [blame] | 769 | } |
| 770 | } |
| 771 | }); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 772 | } |
| 773 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 774 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 775 | public DeviceAdminInfo findAdmin(ComponentName adminName, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 776 | if (!mHasFeature) { |
| 777 | return null; |
| 778 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 779 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 780 | Intent resolveIntent = new Intent(); |
| 781 | resolveIntent.setComponent(adminName); |
| 782 | List<ResolveInfo> infos = mContext.getPackageManager().queryBroadcastReceivers( |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 783 | resolveIntent, |
| 784 | PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, |
| 785 | userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 786 | if (infos == null || infos.size() <= 0) { |
| 787 | throw new IllegalArgumentException("Unknown admin: " + adminName); |
| 788 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 789 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 790 | try { |
| 791 | return new DeviceAdminInfo(mContext, infos.get(0)); |
| 792 | } catch (XmlPullParserException e) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 793 | Slog.w(TAG, "Bad device admin requested for user=" + userHandle + ": " + adminName, e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 794 | return null; |
| 795 | } catch (IOException e) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 796 | Slog.w(TAG, "Bad device admin requested for user=" + userHandle + ": " + adminName, e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 797 | return null; |
| 798 | } |
| 799 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 800 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 801 | private static JournaledFile makeJournaledFile(int userHandle) { |
| 802 | final String base = userHandle == 0 |
| 803 | ? "/data/system/" + DEVICE_POLICIES_XML |
| 804 | : new File(Environment.getUserSystemDirectory(userHandle), DEVICE_POLICIES_XML) |
| 805 | .getAbsolutePath(); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 806 | return new JournaledFile(new File(base), new File(base + ".tmp")); |
| 807 | } |
| 808 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 809 | private void saveSettingsLocked(int userHandle) { |
| 810 | DevicePolicyData policy = getUserData(userHandle); |
| 811 | JournaledFile journal = makeJournaledFile(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 812 | FileOutputStream stream = null; |
| 813 | try { |
| 814 | stream = new FileOutputStream(journal.chooseForWrite(), false); |
| 815 | XmlSerializer out = new FastXmlSerializer(); |
| 816 | out.setOutput(stream, "utf-8"); |
| 817 | out.startDocument(null, true); |
| 818 | |
| 819 | out.startTag(null, "policies"); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 820 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 821 | final int N = policy.mAdminList.size(); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 822 | for (int i=0; i<N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 823 | ActiveAdmin ap = policy.mAdminList.get(i); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 824 | if (ap != null) { |
| 825 | out.startTag(null, "admin"); |
| 826 | out.attribute(null, "name", ap.info.getComponent().flattenToString()); |
| 827 | ap.writeToXml(out); |
| 828 | out.endTag(null, "admin"); |
| 829 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 830 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 831 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 832 | if (policy.mPasswordOwner >= 0) { |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 833 | out.startTag(null, "password-owner"); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 834 | out.attribute(null, "value", Integer.toString(policy.mPasswordOwner)); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 835 | out.endTag(null, "password-owner"); |
| 836 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 837 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 838 | if (policy.mFailedPasswordAttempts != 0) { |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 839 | out.startTag(null, "failed-password-attempts"); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 840 | out.attribute(null, "value", Integer.toString(policy.mFailedPasswordAttempts)); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 841 | out.endTag(null, "failed-password-attempts"); |
| 842 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 843 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 844 | if (policy.mActivePasswordQuality != 0 || policy.mActivePasswordLength != 0 |
| 845 | || policy.mActivePasswordUpperCase != 0 || policy.mActivePasswordLowerCase != 0 |
| 846 | || policy.mActivePasswordLetters != 0 || policy.mActivePasswordNumeric != 0 |
| 847 | || policy.mActivePasswordSymbols != 0 || policy.mActivePasswordNonLetter != 0) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 848 | out.startTag(null, "active-password"); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 849 | out.attribute(null, "quality", Integer.toString(policy.mActivePasswordQuality)); |
| 850 | out.attribute(null, "length", Integer.toString(policy.mActivePasswordLength)); |
| 851 | out.attribute(null, "uppercase", Integer.toString(policy.mActivePasswordUpperCase)); |
| 852 | out.attribute(null, "lowercase", Integer.toString(policy.mActivePasswordLowerCase)); |
| 853 | out.attribute(null, "letters", Integer.toString(policy.mActivePasswordLetters)); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 854 | out.attribute(null, "numeric", Integer |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 855 | .toString(policy.mActivePasswordNumeric)); |
| 856 | out.attribute(null, "symbols", Integer.toString(policy.mActivePasswordSymbols)); |
| 857 | out.attribute(null, "nonletter", Integer.toString(policy.mActivePasswordNonLetter)); |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 858 | out.endTag(null, "active-password"); |
| 859 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 860 | |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 861 | out.endTag(null, "policies"); |
| 862 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 863 | out.endDocument(); |
| 864 | stream.close(); |
| 865 | journal.commit(); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 866 | sendChangedNotification(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 867 | } catch (IOException e) { |
| 868 | try { |
| 869 | if (stream != null) { |
| 870 | stream.close(); |
| 871 | } |
| 872 | } catch (IOException ex) { |
| 873 | // Ignore |
| 874 | } |
| 875 | journal.rollback(); |
| 876 | } |
| 877 | } |
| 878 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 879 | private void sendChangedNotification(int userHandle) { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 880 | Intent intent = new Intent(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 881 | intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| Amith Yamasani | b7a6859 | 2012-09-10 10:24:36 -0700 | [diff] [blame] | 882 | long ident = Binder.clearCallingIdentity(); |
| 883 | try { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 884 | mContext.sendBroadcastAsUser(intent, new UserHandle(userHandle)); |
| Amith Yamasani | b7a6859 | 2012-09-10 10:24:36 -0700 | [diff] [blame] | 885 | } finally { |
| 886 | Binder.restoreCallingIdentity(ident); |
| 887 | } |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 888 | } |
| 889 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 890 | private void loadSettingsLocked(DevicePolicyData policy, int userHandle) { |
| 891 | JournaledFile journal = makeJournaledFile(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 892 | FileInputStream stream = null; |
| 893 | File file = journal.chooseForRead(); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 894 | try { |
| 895 | stream = new FileInputStream(file); |
| 896 | XmlPullParser parser = Xml.newPullParser(); |
| 897 | parser.setInput(stream, null); |
| 898 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 899 | int type; |
| 900 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 901 | && type != XmlPullParser.START_TAG) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 902 | } |
| 903 | String tag = parser.getName(); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 904 | if (!"policies".equals(tag)) { |
| 905 | throw new XmlPullParserException( |
| 906 | "Settings do not start with policies tag: found " + tag); |
| 907 | } |
| 908 | type = parser.next(); |
| 909 | int outerDepth = parser.getDepth(); |
| 910 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 911 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 912 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 913 | continue; |
| 914 | } |
| 915 | tag = parser.getName(); |
| 916 | if ("admin".equals(tag)) { |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 917 | String name = parser.getAttributeValue(null, "name"); |
| 918 | try { |
| 919 | DeviceAdminInfo dai = findAdmin( |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 920 | ComponentName.unflattenFromString(name), userHandle); |
| 921 | if (DBG && (UserHandle.getUserId(dai.getActivityInfo().applicationInfo.uid) |
| 922 | != userHandle)) { |
| 923 | Slog.w(TAG, "findAdmin returned an incorrect uid " |
| 924 | + dai.getActivityInfo().applicationInfo.uid + " for user " |
| 925 | + userHandle); |
| 926 | } |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 927 | if (dai != null) { |
| 928 | ActiveAdmin ap = new ActiveAdmin(dai); |
| 929 | ap.readFromXml(parser); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 930 | policy.mAdminMap.put(ap.info.getComponent(), ap); |
| 931 | policy.mAdminList.add(ap); |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 932 | } |
| 933 | } catch (RuntimeException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 934 | Slog.w(TAG, "Failed loading admin " + name, e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 935 | } |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 936 | } else if ("failed-password-attempts".equals(tag)) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 937 | policy.mFailedPasswordAttempts = Integer.parseInt( |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 938 | parser.getAttributeValue(null, "value")); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 939 | XmlUtils.skipCurrentTag(parser); |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 940 | } else if ("password-owner".equals(tag)) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 941 | policy.mPasswordOwner = Integer.parseInt( |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 942 | parser.getAttributeValue(null, "value")); |
| 943 | XmlUtils.skipCurrentTag(parser); |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 944 | } else if ("active-password".equals(tag)) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 945 | policy.mActivePasswordQuality = Integer.parseInt( |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 946 | parser.getAttributeValue(null, "quality")); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 947 | policy.mActivePasswordLength = Integer.parseInt( |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 948 | parser.getAttributeValue(null, "length")); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 949 | policy.mActivePasswordUpperCase = Integer.parseInt( |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 950 | parser.getAttributeValue(null, "uppercase")); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 951 | policy.mActivePasswordLowerCase = Integer.parseInt( |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 952 | parser.getAttributeValue(null, "lowercase")); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 953 | policy.mActivePasswordLetters = Integer.parseInt( |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 954 | parser.getAttributeValue(null, "letters")); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 955 | policy.mActivePasswordNumeric = Integer.parseInt( |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 956 | parser.getAttributeValue(null, "numeric")); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 957 | policy.mActivePasswordSymbols = Integer.parseInt( |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 958 | parser.getAttributeValue(null, "symbols")); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 959 | policy.mActivePasswordNonLetter = Integer.parseInt( |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 960 | parser.getAttributeValue(null, "nonletter")); |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 961 | XmlUtils.skipCurrentTag(parser); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 962 | } else { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 963 | Slog.w(TAG, "Unknown tag: " + tag); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 964 | XmlUtils.skipCurrentTag(parser); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 965 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 966 | } |
| 967 | } catch (NullPointerException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 968 | Slog.w(TAG, "failed parsing " + file + " " + e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 969 | } catch (NumberFormatException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 970 | Slog.w(TAG, "failed parsing " + file + " " + e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 971 | } catch (XmlPullParserException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 972 | Slog.w(TAG, "failed parsing " + file + " " + e); |
| Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 973 | } catch (FileNotFoundException e) { |
| 974 | // 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] | 975 | } catch (IOException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 976 | Slog.w(TAG, "failed parsing " + file + " " + e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 977 | } catch (IndexOutOfBoundsException e) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 978 | Slog.w(TAG, "failed parsing " + file + " " + e); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 979 | } |
| 980 | try { |
| 981 | if (stream != null) { |
| 982 | stream.close(); |
| 983 | } |
| 984 | } catch (IOException e) { |
| 985 | // Ignore |
| 986 | } |
| 987 | |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 988 | // Validate that what we stored for the password quality matches |
| 989 | // sufficiently what is currently set. Note that this is only |
| 990 | // a sanity check in case the two get out of sync; this should |
| 991 | // never normally happen. |
| 992 | LockPatternUtils utils = new LockPatternUtils(mContext); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 993 | if (utils.getActivePasswordQuality() < policy.mActivePasswordQuality) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 994 | Slog.w(TAG, "Active password quality 0x" |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 995 | + Integer.toHexString(policy.mActivePasswordQuality) |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 996 | + " does not match actual quality 0x" |
| 997 | + Integer.toHexString(utils.getActivePasswordQuality())); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 998 | policy.mActivePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
| 999 | policy.mActivePasswordLength = 0; |
| 1000 | policy.mActivePasswordUpperCase = 0; |
| 1001 | policy.mActivePasswordLowerCase = 0; |
| 1002 | policy.mActivePasswordLetters = 0; |
| 1003 | policy.mActivePasswordNumeric = 0; |
| 1004 | policy.mActivePasswordSymbols = 0; |
| 1005 | policy.mActivePasswordNonLetter = 0; |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1006 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1007 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1008 | validatePasswordOwnerLocked(policy); |
| 1009 | syncDeviceCapabilitiesLocked(policy); |
| 1010 | updateMaximumTimeToLockLocked(policy); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1011 | } |
| 1012 | |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1013 | static void validateQualityConstant(int quality) { |
| 1014 | switch (quality) { |
| 1015 | case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED: |
| Danielle Millett | de7a2f3 | 2011-12-21 17:02:32 -0500 | [diff] [blame] | 1016 | case DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK: |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1017 | case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING: |
| 1018 | case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC: |
| 1019 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC: |
| 1020 | case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC: |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1021 | case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX: |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1022 | return; |
| 1023 | } |
| 1024 | throw new IllegalArgumentException("Invalid quality constant: 0x" |
| 1025 | + Integer.toHexString(quality)); |
| 1026 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1027 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1028 | void validatePasswordOwnerLocked(DevicePolicyData policy) { |
| 1029 | if (policy.mPasswordOwner >= 0) { |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1030 | boolean haveOwner = false; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1031 | for (int i = policy.mAdminList.size() - 1; i >= 0; i--) { |
| 1032 | if (policy.mAdminList.get(i).getUid() == policy.mPasswordOwner) { |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1033 | haveOwner = true; |
| 1034 | break; |
| 1035 | } |
| 1036 | } |
| 1037 | if (!haveOwner) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1038 | Slog.w(TAG, "Previous password owner " + policy.mPasswordOwner |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1039 | + " no longer active; disabling"); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1040 | policy.mPasswordOwner = -1; |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1041 | } |
| 1042 | } |
| 1043 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1044 | |
| Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 1045 | /** |
| 1046 | * Pushes down policy information to the system for any policies related to general device |
| 1047 | * capabilities that need to be enforced by lower level services (e.g. Camera services). |
| 1048 | */ |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1049 | void syncDeviceCapabilitiesLocked(DevicePolicyData policy) { |
| Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 1050 | // Ensure the status of the camera is synced down to the system. Interested native services |
| 1051 | // should monitor this value and act accordingly. |
| 1052 | boolean systemState = SystemProperties.getBoolean(SYSTEM_PROP_DISABLE_CAMERA, false); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1053 | boolean cameraDisabled = getCameraDisabled(null, policy.mUserHandle); |
| Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 1054 | if (cameraDisabled != systemState) { |
| 1055 | long token = Binder.clearCallingIdentity(); |
| 1056 | try { |
| 1057 | String value = cameraDisabled ? "1" : "0"; |
| Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 1058 | if (DBG) Slog.v(TAG, "Change in camera state [" |
| Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 1059 | + SYSTEM_PROP_DISABLE_CAMERA + "] = " + value); |
| 1060 | SystemProperties.set(SYSTEM_PROP_DISABLE_CAMERA, value); |
| 1061 | } finally { |
| 1062 | Binder.restoreCallingIdentity(token); |
| 1063 | } |
| 1064 | } |
| 1065 | } |
| 1066 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1067 | public void systemReady() { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1068 | if (!mHasFeature) { |
| 1069 | return; |
| 1070 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1071 | synchronized (this) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1072 | loadSettingsLocked(getUserData(UserHandle.USER_OWNER), UserHandle.USER_OWNER); |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1073 | loadDeviceOwner(); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1074 | } |
| 1075 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1076 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1077 | private void handlePasswordExpirationNotification(DevicePolicyData policy) { |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1078 | synchronized (this) { |
| 1079 | final long now = System.currentTimeMillis(); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1080 | final int N = policy.mAdminList.size(); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1081 | if (N <= 0) { |
| 1082 | return; |
| 1083 | } |
| 1084 | for (int i=0; i < N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1085 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1086 | if (admin.info.usesPolicy(DeviceAdminInfo.USES_POLICY_EXPIRE_PASSWORD) |
| 1087 | && admin.passwordExpirationTimeout > 0L |
| 1088 | && admin.passwordExpirationDate > 0L |
| Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 1089 | && now >= admin.passwordExpirationDate - EXPIRATION_GRACE_PERIOD_MS) { |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1090 | sendAdminCommandLocked(admin, DeviceAdminReceiver.ACTION_PASSWORD_EXPIRING); |
| 1091 | } |
| 1092 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1093 | setExpirationAlarmCheckLocked(mContext, policy); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1094 | } |
| 1095 | } |
| 1096 | |
| Maggie Benthall | 0469f41 | 2013-09-05 15:30:26 -0400 | [diff] [blame] | 1097 | private void manageMonitoringCertificateNotification(Intent intent) { |
| 1098 | final NotificationManager notificationManager = getNotificationManager(); |
| 1099 | |
| 1100 | final boolean hasCert = DevicePolicyManager.hasAnyCaCertsInstalled(); |
| 1101 | if (! hasCert) { |
| 1102 | if (intent.getAction().equals(KeyChain.ACTION_STORAGE_CHANGED)) { |
| 1103 | UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE); |
| 1104 | for (UserInfo user : um.getUsers()) { |
| 1105 | notificationManager.cancelAsUser( |
| 1106 | null, MONITORING_CERT_NOTIFICATION_ID, user.getUserHandle()); |
| 1107 | } |
| 1108 | } |
| 1109 | return; |
| 1110 | } |
| 1111 | final boolean isManaged = getDeviceOwner() != null; |
| 1112 | int smallIconId; |
| 1113 | String contentText; |
| 1114 | if (isManaged) { |
| 1115 | contentText = mContext.getString(R.string.ssl_ca_cert_noti_managed, |
| 1116 | getDeviceOwnerName()); |
| 1117 | smallIconId = R.drawable.stat_sys_certificate_info; |
| 1118 | } else { |
| 1119 | contentText = mContext.getString(R.string.ssl_ca_cert_noti_by_unknown); |
| 1120 | smallIconId = android.R.drawable.stat_sys_warning; |
| 1121 | } |
| 1122 | |
| 1123 | Intent dialogIntent = new Intent(Settings.ACTION_MONITORING_CERT_INFO); |
| 1124 | dialogIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
| 1125 | dialogIntent.setPackage("com.android.settings"); |
| 1126 | // Notification will be sent individually to all users. The activity should start as |
| 1127 | // whichever user is current when it starts. |
| 1128 | PendingIntent notifyIntent = PendingIntent.getActivityAsUser(mContext, 0, dialogIntent, |
| 1129 | PendingIntent.FLAG_UPDATE_CURRENT, null, UserHandle.CURRENT); |
| 1130 | |
| 1131 | Notification noti = new Notification.Builder(mContext) |
| 1132 | .setSmallIcon(smallIconId) |
| 1133 | .setContentTitle(mContext.getString(R.string.ssl_ca_cert_warning)) |
| 1134 | .setContentText(contentText) |
| 1135 | .setContentIntent(notifyIntent) |
| 1136 | .setPriority(Notification.PRIORITY_HIGH) |
| 1137 | .setShowWhen(false) |
| 1138 | .build(); |
| 1139 | |
| 1140 | // If this is a boot intent, this will fire for each user. But if this is a storage changed |
| 1141 | // intent, it will fire once, so we need to notify all users. |
| 1142 | if (intent.getAction().equals(KeyChain.ACTION_STORAGE_CHANGED)) { |
| 1143 | UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE); |
| 1144 | for (UserInfo user : um.getUsers()) { |
| 1145 | notificationManager.notifyAsUser( |
| 1146 | null, MONITORING_CERT_NOTIFICATION_ID, noti, user.getUserHandle()); |
| 1147 | } |
| 1148 | } else { |
| 1149 | notificationManager.notifyAsUser( |
| 1150 | null, MONITORING_CERT_NOTIFICATION_ID, noti, UserHandle.CURRENT); |
| 1151 | } |
| 1152 | } |
| 1153 | |
| Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1154 | /** |
| 1155 | * @param adminReceiver The admin to add |
| 1156 | * @param refreshing true = update an active admin, no error |
| 1157 | */ |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1158 | public void setActiveAdmin(ComponentName adminReceiver, boolean refreshing, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1159 | if (!mHasFeature) { |
| 1160 | return; |
| 1161 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1162 | mContext.enforceCallingOrSelfPermission( |
| Amith Yamasani | a418cf2 | 2013-07-19 12:39:17 -0700 | [diff] [blame] | 1163 | android.Manifest.permission.MANAGE_DEVICE_ADMINS, null); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1164 | enforceCrossUserPermission(userHandle); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1165 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1166 | DevicePolicyData policy = getUserData(userHandle); |
| 1167 | DeviceAdminInfo info = findAdmin(adminReceiver, userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1168 | if (info == null) { |
| 1169 | throw new IllegalArgumentException("Bad admin: " + adminReceiver); |
| 1170 | } |
| 1171 | synchronized (this) { |
| 1172 | long ident = Binder.clearCallingIdentity(); |
| 1173 | try { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1174 | if (!refreshing && getActiveAdminUncheckedLocked(adminReceiver, userHandle) != null) { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1175 | throw new IllegalArgumentException("Admin is already added"); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1176 | } |
| Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1177 | ActiveAdmin newAdmin = new ActiveAdmin(info); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1178 | policy.mAdminMap.put(adminReceiver, newAdmin); |
| Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1179 | int replaceIndex = -1; |
| 1180 | if (refreshing) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1181 | final int N = policy.mAdminList.size(); |
| Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1182 | for (int i=0; i < N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1183 | ActiveAdmin oldAdmin = policy.mAdminList.get(i); |
| Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1184 | if (oldAdmin.info.getComponent().equals(adminReceiver)) { |
| 1185 | replaceIndex = i; |
| 1186 | break; |
| 1187 | } |
| 1188 | } |
| 1189 | } |
| 1190 | if (replaceIndex == -1) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1191 | policy.mAdminList.add(newAdmin); |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1192 | enableIfNecessary(info.getPackageName(), userHandle); |
| Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1193 | } else { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1194 | policy.mAdminList.set(replaceIndex, newAdmin); |
| Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1195 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1196 | saveSettingsLocked(userHandle); |
| Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1197 | sendAdminCommandLocked(newAdmin, DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1198 | } finally { |
| 1199 | Binder.restoreCallingIdentity(ident); |
| 1200 | } |
| 1201 | } |
| 1202 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1203 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1204 | public boolean isAdminActive(ComponentName adminReceiver, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1205 | if (!mHasFeature) { |
| 1206 | return false; |
| 1207 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1208 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1209 | synchronized (this) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1210 | return getActiveAdminUncheckedLocked(adminReceiver, userHandle) != null; |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1211 | } |
| 1212 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1213 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1214 | public boolean hasGrantedPolicy(ComponentName adminReceiver, int policyId, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1215 | if (!mHasFeature) { |
| 1216 | return false; |
| 1217 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1218 | enforceCrossUserPermission(userHandle); |
| Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1219 | synchronized (this) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1220 | ActiveAdmin administrator = getActiveAdminUncheckedLocked(adminReceiver, userHandle); |
| Andy Stadler | c25f70a | 2010-12-08 15:56:45 -0800 | [diff] [blame] | 1221 | if (administrator == null) { |
| 1222 | throw new SecurityException("No active admin " + adminReceiver); |
| 1223 | } |
| 1224 | return administrator.info.usesPolicy(policyId); |
| 1225 | } |
| 1226 | } |
| 1227 | |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1228 | @SuppressWarnings("unchecked") |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1229 | public List<ComponentName> getActiveAdmins(int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1230 | if (!mHasFeature) { |
| 1231 | return Collections.EMPTY_LIST; |
| 1232 | } |
| 1233 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1234 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1235 | synchronized (this) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1236 | DevicePolicyData policy = getUserData(userHandle); |
| 1237 | final int N = policy.mAdminList.size(); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1238 | if (N <= 0) { |
| 1239 | return null; |
| 1240 | } |
| 1241 | ArrayList<ComponentName> res = new ArrayList<ComponentName>(N); |
| 1242 | for (int i=0; i<N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1243 | res.add(policy.mAdminList.get(i).info.getComponent()); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1244 | } |
| 1245 | return res; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1246 | } |
| 1247 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1248 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1249 | public boolean packageHasActiveAdmins(String packageName, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1250 | if (!mHasFeature) { |
| 1251 | return false; |
| 1252 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1253 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1254 | synchronized (this) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1255 | DevicePolicyData policy = getUserData(userHandle); |
| 1256 | final int N = policy.mAdminList.size(); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1257 | for (int i=0; i<N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1258 | if (policy.mAdminList.get(i).info.getPackageName().equals(packageName)) { |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1259 | return true; |
| 1260 | } |
| 1261 | } |
| 1262 | return false; |
| 1263 | } |
| 1264 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1265 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1266 | public void removeActiveAdmin(ComponentName adminReceiver, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1267 | if (!mHasFeature) { |
| 1268 | return; |
| 1269 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1270 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1271 | synchronized (this) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1272 | ActiveAdmin admin = getActiveAdminUncheckedLocked(adminReceiver, userHandle); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1273 | if (admin == null) { |
| 1274 | return; |
| 1275 | } |
| 1276 | if (admin.getUid() != Binder.getCallingUid()) { |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 1277 | // If trying to remove device owner, refuse when the caller is not the owner. |
| 1278 | if (mDeviceOwner != null |
| 1279 | && adminReceiver.getPackageName().equals(mDeviceOwner.getPackageName())) { |
| 1280 | return; |
| 1281 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1282 | mContext.enforceCallingOrSelfPermission( |
| Amith Yamasani | a418cf2 | 2013-07-19 12:39:17 -0700 | [diff] [blame] | 1283 | android.Manifest.permission.MANAGE_DEVICE_ADMINS, null); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1284 | } |
| 1285 | long ident = Binder.clearCallingIdentity(); |
| 1286 | try { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1287 | removeActiveAdminLocked(adminReceiver, userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1288 | } finally { |
| 1289 | Binder.restoreCallingIdentity(ident); |
| 1290 | } |
| 1291 | } |
| 1292 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1293 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1294 | public void setPasswordQuality(ComponentName who, int quality, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1295 | if (!mHasFeature) { |
| 1296 | return; |
| 1297 | } |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1298 | validateQualityConstant(quality); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1299 | enforceCrossUserPermission(userHandle); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1300 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1301 | synchronized (this) { |
| 1302 | if (who == null) { |
| 1303 | throw new NullPointerException("ComponentName is null"); |
| 1304 | } |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1305 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1306 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1307 | if (ap.passwordQuality != quality) { |
| 1308 | ap.passwordQuality = quality; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1309 | saveSettingsLocked(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1310 | } |
| 1311 | } |
| 1312 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1313 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1314 | public int getPasswordQuality(ComponentName who, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1315 | if (!mHasFeature) { |
| 1316 | return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
| 1317 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1318 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1319 | synchronized (this) { |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1320 | int mode = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1321 | DevicePolicyData policy = getUserData(userHandle); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1322 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1323 | if (who != null) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1324 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1325 | return admin != null ? admin.passwordQuality : mode; |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1326 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1327 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1328 | final int N = policy.mAdminList.size(); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1329 | for (int i=0; i<N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1330 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1331 | if (mode < admin.passwordQuality) { |
| 1332 | mode = admin.passwordQuality; |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1333 | } |
| 1334 | } |
| 1335 | return mode; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1336 | } |
| 1337 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1338 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1339 | public void setPasswordMinimumLength(ComponentName who, int length, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1340 | if (!mHasFeature) { |
| 1341 | return; |
| 1342 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1343 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1344 | synchronized (this) { |
| 1345 | if (who == null) { |
| 1346 | throw new NullPointerException("ComponentName is null"); |
| 1347 | } |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1348 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1349 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1350 | if (ap.minimumPasswordLength != length) { |
| 1351 | ap.minimumPasswordLength = length; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1352 | saveSettingsLocked(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1353 | } |
| 1354 | } |
| 1355 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1356 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1357 | public int getPasswordMinimumLength(ComponentName who, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1358 | if (!mHasFeature) { |
| 1359 | return 0; |
| 1360 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1361 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1362 | synchronized (this) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1363 | DevicePolicyData policy = getUserData(userHandle); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1364 | int length = 0; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1365 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1366 | if (who != null) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1367 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1368 | return admin != null ? admin.minimumPasswordLength : length; |
| 1369 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1370 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1371 | final int N = policy.mAdminList.size(); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1372 | for (int i=0; i<N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1373 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1374 | if (length < admin.minimumPasswordLength) { |
| 1375 | length = admin.minimumPasswordLength; |
| 1376 | } |
| 1377 | } |
| 1378 | return length; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1379 | } |
| 1380 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1381 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1382 | public void setPasswordHistoryLength(ComponentName who, int length, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1383 | if (!mHasFeature) { |
| 1384 | return; |
| 1385 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1386 | enforceCrossUserPermission(userHandle); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1387 | synchronized (this) { |
| 1388 | if (who == null) { |
| 1389 | throw new NullPointerException("ComponentName is null"); |
| 1390 | } |
| 1391 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1392 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 1393 | if (ap.passwordHistoryLength != length) { |
| 1394 | ap.passwordHistoryLength = length; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1395 | saveSettingsLocked(userHandle); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1396 | } |
| 1397 | } |
| 1398 | } |
| 1399 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1400 | public int getPasswordHistoryLength(ComponentName who, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1401 | if (!mHasFeature) { |
| 1402 | return 0; |
| 1403 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1404 | enforceCrossUserPermission(userHandle); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1405 | synchronized (this) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1406 | DevicePolicyData policy = getUserData(userHandle); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1407 | int length = 0; |
| 1408 | |
| 1409 | if (who != null) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1410 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1411 | return admin != null ? admin.passwordHistoryLength : length; |
| 1412 | } |
| 1413 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1414 | final int N = policy.mAdminList.size(); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1415 | for (int i = 0; i < N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1416 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1417 | if (length < admin.passwordHistoryLength) { |
| 1418 | length = admin.passwordHistoryLength; |
| 1419 | } |
| 1420 | } |
| 1421 | return length; |
| 1422 | } |
| 1423 | } |
| 1424 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1425 | public void setPasswordExpirationTimeout(ComponentName who, long timeout, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1426 | if (!mHasFeature) { |
| 1427 | return; |
| 1428 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1429 | enforceCrossUserPermission(userHandle); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1430 | synchronized (this) { |
| 1431 | if (who == null) { |
| 1432 | throw new NullPointerException("ComponentName is null"); |
| 1433 | } |
| Andy Stadler | 1f35d48 | 2010-11-19 15:39:41 -0800 | [diff] [blame] | 1434 | if (timeout < 0) { |
| 1435 | throw new IllegalArgumentException("Timeout must be >= 0 ms"); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1436 | } |
| 1437 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1438 | DeviceAdminInfo.USES_POLICY_EXPIRE_PASSWORD); |
| 1439 | // Calling this API automatically bumps the expiration date |
| 1440 | final long expiration = timeout > 0L ? (timeout + System.currentTimeMillis()) : 0L; |
| 1441 | ap.passwordExpirationDate = expiration; |
| 1442 | ap.passwordExpirationTimeout = timeout; |
| 1443 | if (timeout > 0L) { |
| 1444 | Slog.w(TAG, "setPasswordExpiration(): password will expire on " |
| 1445 | + DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT) |
| 1446 | .format(new Date(expiration))); |
| 1447 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1448 | saveSettingsLocked(userHandle); |
| 1449 | // in case this is the first one |
| 1450 | setExpirationAlarmCheckLocked(mContext, getUserData(userHandle)); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1451 | } |
| 1452 | } |
| 1453 | |
| Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 1454 | /** |
| 1455 | * Return a single admin's expiration cycle time, or the min of all cycle times. |
| 1456 | * Returns 0 if not configured. |
| 1457 | */ |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1458 | public long getPasswordExpirationTimeout(ComponentName who, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1459 | if (!mHasFeature) { |
| 1460 | return 0L; |
| 1461 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1462 | enforceCrossUserPermission(userHandle); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1463 | synchronized (this) { |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1464 | if (who != null) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1465 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
| Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 1466 | return admin != null ? admin.passwordExpirationTimeout : 0L; |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1467 | } |
| 1468 | |
| Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 1469 | long timeout = 0L; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1470 | DevicePolicyData policy = getUserData(userHandle); |
| 1471 | final int N = policy.mAdminList.size(); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1472 | for (int i = 0; i < N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1473 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1474 | if (timeout == 0L || (admin.passwordExpirationTimeout != 0L |
| 1475 | && timeout > admin.passwordExpirationTimeout)) { |
| 1476 | timeout = admin.passwordExpirationTimeout; |
| 1477 | } |
| 1478 | } |
| 1479 | return timeout; |
| 1480 | } |
| 1481 | } |
| 1482 | |
| Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 1483 | /** |
| 1484 | * Return a single admin's expiration date/time, or the min (soonest) for all admins. |
| 1485 | * Returns 0 if not configured. |
| 1486 | */ |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1487 | private long getPasswordExpirationLocked(ComponentName who, int userHandle) { |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1488 | if (who != null) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1489 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
| Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 1490 | return admin != null ? admin.passwordExpirationDate : 0L; |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1491 | } |
| 1492 | |
| Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 1493 | long timeout = 0L; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1494 | DevicePolicyData policy = getUserData(userHandle); |
| 1495 | final int N = policy.mAdminList.size(); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1496 | for (int i = 0; i < N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1497 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1498 | if (timeout == 0L || (admin.passwordExpirationDate != 0 |
| 1499 | && timeout > admin.passwordExpirationDate)) { |
| 1500 | timeout = admin.passwordExpirationDate; |
| 1501 | } |
| 1502 | } |
| 1503 | return timeout; |
| 1504 | } |
| 1505 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1506 | public long getPasswordExpiration(ComponentName who, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1507 | if (!mHasFeature) { |
| 1508 | return 0L; |
| 1509 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1510 | enforceCrossUserPermission(userHandle); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1511 | synchronized (this) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1512 | return getPasswordExpirationLocked(who, userHandle); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 1513 | } |
| 1514 | } |
| 1515 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1516 | public void setPasswordMinimumUpperCase(ComponentName who, int length, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1517 | if (!mHasFeature) { |
| 1518 | return; |
| 1519 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1520 | enforceCrossUserPermission(userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1521 | synchronized (this) { |
| 1522 | if (who == null) { |
| 1523 | throw new NullPointerException("ComponentName is null"); |
| 1524 | } |
| 1525 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1526 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 1527 | if (ap.minimumPasswordUpperCase != length) { |
| 1528 | ap.minimumPasswordUpperCase = length; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1529 | saveSettingsLocked(userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1530 | } |
| 1531 | } |
| 1532 | } |
| 1533 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1534 | public int getPasswordMinimumUpperCase(ComponentName who, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1535 | if (!mHasFeature) { |
| 1536 | return 0; |
| 1537 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1538 | enforceCrossUserPermission(userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1539 | synchronized (this) { |
| 1540 | int length = 0; |
| 1541 | |
| 1542 | if (who != null) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1543 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1544 | return admin != null ? admin.minimumPasswordUpperCase : length; |
| 1545 | } |
| 1546 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1547 | DevicePolicyData policy = getUserData(userHandle); |
| 1548 | final int N = policy.mAdminList.size(); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1549 | for (int i=0; i<N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1550 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1551 | if (length < admin.minimumPasswordUpperCase) { |
| 1552 | length = admin.minimumPasswordUpperCase; |
| 1553 | } |
| 1554 | } |
| 1555 | return length; |
| 1556 | } |
| 1557 | } |
| 1558 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1559 | public void setPasswordMinimumLowerCase(ComponentName who, int length, int userHandle) { |
| 1560 | enforceCrossUserPermission(userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1561 | synchronized (this) { |
| 1562 | if (who == null) { |
| 1563 | throw new NullPointerException("ComponentName is null"); |
| 1564 | } |
| 1565 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1566 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 1567 | if (ap.minimumPasswordLowerCase != length) { |
| 1568 | ap.minimumPasswordLowerCase = length; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1569 | saveSettingsLocked(userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1570 | } |
| 1571 | } |
| 1572 | } |
| 1573 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1574 | public int getPasswordMinimumLowerCase(ComponentName who, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1575 | if (!mHasFeature) { |
| 1576 | return 0; |
| 1577 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1578 | enforceCrossUserPermission(userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1579 | synchronized (this) { |
| 1580 | int length = 0; |
| 1581 | |
| 1582 | if (who != null) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1583 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1584 | return admin != null ? admin.minimumPasswordLowerCase : length; |
| 1585 | } |
| 1586 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1587 | DevicePolicyData policy = getUserData(userHandle); |
| 1588 | final int N = policy.mAdminList.size(); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1589 | for (int i=0; i<N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1590 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1591 | if (length < admin.minimumPasswordLowerCase) { |
| 1592 | length = admin.minimumPasswordLowerCase; |
| 1593 | } |
| 1594 | } |
| 1595 | return length; |
| 1596 | } |
| 1597 | } |
| 1598 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1599 | public void setPasswordMinimumLetters(ComponentName who, int length, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1600 | if (!mHasFeature) { |
| 1601 | return; |
| 1602 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1603 | enforceCrossUserPermission(userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1604 | synchronized (this) { |
| 1605 | if (who == null) { |
| 1606 | throw new NullPointerException("ComponentName is null"); |
| 1607 | } |
| 1608 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1609 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 1610 | if (ap.minimumPasswordLetters != length) { |
| 1611 | ap.minimumPasswordLetters = length; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1612 | saveSettingsLocked(userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1613 | } |
| 1614 | } |
| 1615 | } |
| 1616 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1617 | public int getPasswordMinimumLetters(ComponentName who, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1618 | if (!mHasFeature) { |
| 1619 | return 0; |
| 1620 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1621 | enforceCrossUserPermission(userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1622 | synchronized (this) { |
| 1623 | int length = 0; |
| 1624 | |
| 1625 | if (who != null) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1626 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1627 | return admin != null ? admin.minimumPasswordLetters : length; |
| 1628 | } |
| 1629 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1630 | DevicePolicyData policy = getUserData(userHandle); |
| 1631 | final int N = policy.mAdminList.size(); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1632 | for (int i=0; i<N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1633 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1634 | if (length < admin.minimumPasswordLetters) { |
| 1635 | length = admin.minimumPasswordLetters; |
| 1636 | } |
| 1637 | } |
| 1638 | return length; |
| 1639 | } |
| 1640 | } |
| 1641 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1642 | public void setPasswordMinimumNumeric(ComponentName who, int length, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1643 | if (!mHasFeature) { |
| 1644 | return; |
| 1645 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1646 | enforceCrossUserPermission(userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1647 | synchronized (this) { |
| 1648 | if (who == null) { |
| 1649 | throw new NullPointerException("ComponentName is null"); |
| 1650 | } |
| 1651 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1652 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 1653 | if (ap.minimumPasswordNumeric != length) { |
| 1654 | ap.minimumPasswordNumeric = length; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1655 | saveSettingsLocked(userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1656 | } |
| 1657 | } |
| 1658 | } |
| 1659 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1660 | public int getPasswordMinimumNumeric(ComponentName who, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1661 | if (!mHasFeature) { |
| 1662 | return 0; |
| 1663 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1664 | enforceCrossUserPermission(userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1665 | synchronized (this) { |
| 1666 | int length = 0; |
| 1667 | |
| 1668 | if (who != null) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1669 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1670 | return admin != null ? admin.minimumPasswordNumeric : length; |
| 1671 | } |
| 1672 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1673 | DevicePolicyData policy = getUserData(userHandle); |
| 1674 | final int N = policy.mAdminList.size(); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1675 | for (int i = 0; i < N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1676 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1677 | if (length < admin.minimumPasswordNumeric) { |
| 1678 | length = admin.minimumPasswordNumeric; |
| 1679 | } |
| 1680 | } |
| 1681 | return length; |
| 1682 | } |
| 1683 | } |
| 1684 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1685 | public void setPasswordMinimumSymbols(ComponentName who, int length, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1686 | if (!mHasFeature) { |
| 1687 | return; |
| 1688 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1689 | enforceCrossUserPermission(userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1690 | synchronized (this) { |
| 1691 | if (who == null) { |
| 1692 | throw new NullPointerException("ComponentName is null"); |
| 1693 | } |
| 1694 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1695 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 1696 | if (ap.minimumPasswordSymbols != length) { |
| 1697 | ap.minimumPasswordSymbols = length; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1698 | saveSettingsLocked(userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1699 | } |
| 1700 | } |
| 1701 | } |
| 1702 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1703 | public int getPasswordMinimumSymbols(ComponentName who, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1704 | if (!mHasFeature) { |
| 1705 | return 0; |
| 1706 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1707 | enforceCrossUserPermission(userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1708 | synchronized (this) { |
| 1709 | int length = 0; |
| 1710 | |
| 1711 | if (who != null) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1712 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1713 | return admin != null ? admin.minimumPasswordSymbols : length; |
| 1714 | } |
| 1715 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1716 | DevicePolicyData policy = getUserData(userHandle); |
| 1717 | final int N = policy.mAdminList.size(); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1718 | for (int i=0; i<N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1719 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1720 | if (length < admin.minimumPasswordSymbols) { |
| 1721 | length = admin.minimumPasswordSymbols; |
| 1722 | } |
| 1723 | } |
| 1724 | return length; |
| 1725 | } |
| 1726 | } |
| 1727 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1728 | public void setPasswordMinimumNonLetter(ComponentName who, int length, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1729 | if (!mHasFeature) { |
| 1730 | return; |
| 1731 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1732 | enforceCrossUserPermission(userHandle); |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1733 | synchronized (this) { |
| 1734 | if (who == null) { |
| 1735 | throw new NullPointerException("ComponentName is null"); |
| 1736 | } |
| 1737 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1738 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| 1739 | if (ap.minimumPasswordNonLetter != length) { |
| 1740 | ap.minimumPasswordNonLetter = length; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1741 | saveSettingsLocked(userHandle); |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1742 | } |
| 1743 | } |
| 1744 | } |
| 1745 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1746 | public int getPasswordMinimumNonLetter(ComponentName who, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1747 | if (!mHasFeature) { |
| 1748 | return 0; |
| 1749 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1750 | enforceCrossUserPermission(userHandle); |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1751 | synchronized (this) { |
| 1752 | int length = 0; |
| 1753 | |
| 1754 | if (who != null) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1755 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1756 | return admin != null ? admin.minimumPasswordNonLetter : length; |
| 1757 | } |
| 1758 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1759 | DevicePolicyData policy = getUserData(userHandle); |
| 1760 | final int N = policy.mAdminList.size(); |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1761 | for (int i=0; i<N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1762 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1763 | if (length < admin.minimumPasswordNonLetter) { |
| 1764 | length = admin.minimumPasswordNonLetter; |
| 1765 | } |
| 1766 | } |
| 1767 | return length; |
| 1768 | } |
| 1769 | } |
| 1770 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1771 | public boolean isActivePasswordSufficient(int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1772 | if (!mHasFeature) { |
| 1773 | return true; |
| 1774 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1775 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1776 | synchronized (this) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1777 | DevicePolicyData policy = getUserData(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1778 | // This API can only be called by an active device admin, |
| 1779 | // so try to retrieve it to check that the caller is one. |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1780 | getActiveAdminForCallerLocked(null, |
| 1781 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1782 | if (policy.mActivePasswordQuality < getPasswordQuality(null, userHandle) |
| 1783 | || policy.mActivePasswordLength < getPasswordMinimumLength(null, userHandle)) { |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1784 | return false; |
| 1785 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1786 | if (policy.mActivePasswordQuality != DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) { |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1787 | return true; |
| 1788 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1789 | return policy.mActivePasswordUpperCase >= getPasswordMinimumUpperCase(null, userHandle) |
| 1790 | && policy.mActivePasswordLowerCase >= getPasswordMinimumLowerCase(null, userHandle) |
| 1791 | && policy.mActivePasswordLetters >= getPasswordMinimumLetters(null, userHandle) |
| 1792 | && policy.mActivePasswordNumeric >= getPasswordMinimumNumeric(null, userHandle) |
| 1793 | && policy.mActivePasswordSymbols >= getPasswordMinimumSymbols(null, userHandle) |
| 1794 | && policy.mActivePasswordNonLetter >= getPasswordMinimumNonLetter(null, userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1795 | } |
| 1796 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1797 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1798 | public int getCurrentFailedPasswordAttempts(int userHandle) { |
| 1799 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1800 | synchronized (this) { |
| 1801 | // This API can only be called by an active device admin, |
| 1802 | // so try to retrieve it to check that the caller is one. |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1803 | getActiveAdminForCallerLocked(null, |
| 1804 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1805 | return getUserData(userHandle).mFailedPasswordAttempts; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1806 | } |
| 1807 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1808 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1809 | public void setMaximumFailedPasswordsForWipe(ComponentName who, int num, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1810 | if (!mHasFeature) { |
| 1811 | return; |
| 1812 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1813 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1814 | synchronized (this) { |
| 1815 | // This API can only be called by an active device admin, |
| 1816 | // so try to retrieve it to check that the caller is one. |
| 1817 | getActiveAdminForCallerLocked(who, |
| 1818 | DeviceAdminInfo.USES_POLICY_WIPE_DATA); |
| 1819 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 1820 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN); |
| 1821 | if (ap.maximumFailedPasswordsForWipe != num) { |
| 1822 | ap.maximumFailedPasswordsForWipe = num; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1823 | saveSettingsLocked(userHandle); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1824 | } |
| 1825 | } |
| 1826 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1827 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1828 | public int getMaximumFailedPasswordsForWipe(ComponentName who, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1829 | if (!mHasFeature) { |
| 1830 | return 0; |
| 1831 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1832 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1833 | synchronized (this) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1834 | DevicePolicyData policy = getUserData(userHandle); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1835 | int count = 0; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1836 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1837 | if (who != null) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1838 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 1839 | return admin != null ? admin.maximumFailedPasswordsForWipe : count; |
| 1840 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1841 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1842 | final int N = policy.mAdminList.size(); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1843 | for (int i=0; i<N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1844 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 1845 | if (count == 0) { |
| 1846 | count = admin.maximumFailedPasswordsForWipe; |
| 1847 | } else if (admin.maximumFailedPasswordsForWipe != 0 |
| 1848 | && count > admin.maximumFailedPasswordsForWipe) { |
| 1849 | count = admin.maximumFailedPasswordsForWipe; |
| 1850 | } |
| 1851 | } |
| 1852 | return count; |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 1853 | } |
| 1854 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1855 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1856 | public boolean resetPassword(String password, int flags, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1857 | if (!mHasFeature) { |
| 1858 | return false; |
| 1859 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1860 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1861 | int quality; |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1862 | synchronized (this) { |
| 1863 | // This API can only be called by an active device admin, |
| 1864 | // so try to retrieve it to check that the caller is one. |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1865 | getActiveAdminForCallerLocked(null, |
| 1866 | DeviceAdminInfo.USES_POLICY_RESET_PASSWORD); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1867 | quality = getPasswordQuality(null, userHandle); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1868 | if (quality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1869 | int realQuality = LockPatternUtils.computePasswordQuality(password); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1870 | if (realQuality < quality |
| 1871 | && quality != DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1872 | Slog.w(TAG, "resetPassword: password quality 0x" |
| joonyoung.cho | ad83c19 | 2013-04-18 13:51:08 +0900 | [diff] [blame] | 1873 | + Integer.toHexString(realQuality) |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1874 | + " does not meet required quality 0x" |
| 1875 | + Integer.toHexString(quality)); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1876 | return false; |
| 1877 | } |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1878 | quality = Math.max(realQuality, quality); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1879 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1880 | int length = getPasswordMinimumLength(null, userHandle); |
| Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 1881 | if (password.length() < length) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1882 | Slog.w(TAG, "resetPassword: password length " + password.length() |
| 1883 | + " does not meet required length " + length); |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1884 | return false; |
| 1885 | } |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1886 | if (quality == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) { |
| 1887 | int letters = 0; |
| 1888 | int uppercase = 0; |
| 1889 | int lowercase = 0; |
| 1890 | int numbers = 0; |
| 1891 | int symbols = 0; |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1892 | int nonletter = 0; |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1893 | for (int i = 0; i < password.length(); i++) { |
| 1894 | char c = password.charAt(i); |
| 1895 | if (c >= 'A' && c <= 'Z') { |
| 1896 | letters++; |
| 1897 | uppercase++; |
| 1898 | } else if (c >= 'a' && c <= 'z') { |
| 1899 | letters++; |
| 1900 | lowercase++; |
| 1901 | } else if (c >= '0' && c <= '9') { |
| 1902 | numbers++; |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1903 | nonletter++; |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1904 | } else { |
| 1905 | symbols++; |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1906 | nonletter++; |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1907 | } |
| 1908 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1909 | int neededLetters = getPasswordMinimumLetters(null, userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1910 | if(letters < neededLetters) { |
| 1911 | Slog.w(TAG, "resetPassword: number of letters " + letters |
| 1912 | + " does not meet required number of letters " + neededLetters); |
| 1913 | return false; |
| 1914 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1915 | int neededNumbers = getPasswordMinimumNumeric(null, userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1916 | if (numbers < neededNumbers) { |
| Dianne Hackborn | 40e9f29 | 2012-11-27 19:12:23 -0800 | [diff] [blame] | 1917 | Slog.w(TAG, "resetPassword: number of numerical digits " + numbers |
| 1918 | + " does not meet required number of numerical digits " |
| 1919 | + neededNumbers); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1920 | return false; |
| 1921 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1922 | int neededLowerCase = getPasswordMinimumLowerCase(null, userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1923 | if (lowercase < neededLowerCase) { |
| 1924 | Slog.w(TAG, "resetPassword: number of lowercase letters " + lowercase |
| 1925 | + " does not meet required number of lowercase letters " |
| 1926 | + neededLowerCase); |
| 1927 | return false; |
| 1928 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1929 | int neededUpperCase = getPasswordMinimumUpperCase(null, userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1930 | if (uppercase < neededUpperCase) { |
| 1931 | Slog.w(TAG, "resetPassword: number of uppercase letters " + uppercase |
| 1932 | + " does not meet required number of uppercase letters " |
| 1933 | + neededUpperCase); |
| 1934 | return false; |
| 1935 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1936 | int neededSymbols = getPasswordMinimumSymbols(null, userHandle); |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1937 | if (symbols < neededSymbols) { |
| 1938 | Slog.w(TAG, "resetPassword: number of special symbols " + symbols |
| 1939 | + " does not meet required number of special symbols " + neededSymbols); |
| 1940 | return false; |
| 1941 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1942 | int neededNonLetter = getPasswordMinimumNonLetter(null, userHandle); |
| Konstantin Lopyrev | c857740 | 2010-06-04 17:15:02 -0700 | [diff] [blame] | 1943 | if (nonletter < neededNonLetter) { |
| 1944 | Slog.w(TAG, "resetPassword: number of non-letter characters " + nonletter |
| 1945 | + " does not meet required number of non-letter characters " |
| 1946 | + neededNonLetter); |
| 1947 | return false; |
| 1948 | } |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 1949 | } |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1950 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1951 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1952 | int callingUid = Binder.getCallingUid(); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1953 | DevicePolicyData policy = getUserData(userHandle); |
| 1954 | if (policy.mPasswordOwner >= 0 && policy.mPasswordOwner != callingUid) { |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1955 | 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] | 1956 | return false; |
| 1957 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1958 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1959 | // Don't do this with the lock held, because it is going to call |
| 1960 | // back in to the service. |
| 1961 | long ident = Binder.clearCallingIdentity(); |
| 1962 | try { |
| 1963 | LockPatternUtils utils = new LockPatternUtils(mContext); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1964 | utils.saveLockPassword(password, quality, false, userHandle); |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1965 | synchronized (this) { |
| 1966 | int newOwner = (flags&DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY) |
| 1967 | != 0 ? callingUid : -1; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1968 | if (policy.mPasswordOwner != newOwner) { |
| 1969 | policy.mPasswordOwner = newOwner; |
| 1970 | saveSettingsLocked(userHandle); |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 1971 | } |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 1972 | } |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1973 | } finally { |
| 1974 | Binder.restoreCallingIdentity(ident); |
| 1975 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1976 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 1977 | return true; |
| 1978 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1979 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1980 | public void setMaximumTimeToLock(ComponentName who, long timeMs, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 1981 | if (!mHasFeature) { |
| 1982 | return; |
| 1983 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1984 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1985 | synchronized (this) { |
| 1986 | if (who == null) { |
| 1987 | throw new NullPointerException("ComponentName is null"); |
| 1988 | } |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 1989 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 1990 | DeviceAdminInfo.USES_POLICY_FORCE_LOCK); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1991 | if (ap.maximumTimeToUnlock != timeMs) { |
| 1992 | ap.maximumTimeToUnlock = timeMs; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1993 | saveSettingsLocked(userHandle); |
| 1994 | updateMaximumTimeToLockLocked(getUserData(userHandle)); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1995 | } |
| 1996 | } |
| 1997 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 1998 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 1999 | void updateMaximumTimeToLockLocked(DevicePolicyData policy) { |
| 2000 | long timeMs = getMaximumTimeToLock(null, policy.mUserHandle); |
| 2001 | if (policy.mLastMaximumTimeToLock == timeMs) { |
| Dianne Hackborn | 2fe8fb2 | 2012-06-15 17:05:25 -0700 | [diff] [blame] | 2002 | return; |
| 2003 | } |
| 2004 | |
| 2005 | long ident = Binder.clearCallingIdentity(); |
| 2006 | try { |
| 2007 | if (timeMs <= 0) { |
| 2008 | timeMs = Integer.MAX_VALUE; |
| 2009 | } else { |
| 2010 | // Make sure KEEP_SCREEN_ON is disabled, since that |
| 2011 | // would allow bypassing of the maximum time to lock. |
| Christopher Tate | 62df6eb5 | 2012-09-07 15:00:54 -0700 | [diff] [blame] | 2012 | Settings.Global.putInt(mContext.getContentResolver(), |
| 2013 | Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0); |
| Dianne Hackborn | 2fe8fb2 | 2012-06-15 17:05:25 -0700 | [diff] [blame] | 2014 | } |
| 2015 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2016 | policy.mLastMaximumTimeToLock = timeMs; |
| Dianne Hackborn | 2fe8fb2 | 2012-06-15 17:05:25 -0700 | [diff] [blame] | 2017 | |
| 2018 | try { |
| Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 2019 | getIPowerManager().setMaximumScreenOffTimeoutFromDeviceAdmin((int)timeMs); |
| Dianne Hackborn | 2fe8fb2 | 2012-06-15 17:05:25 -0700 | [diff] [blame] | 2020 | } catch (RemoteException e) { |
| 2021 | Slog.w(TAG, "Failure talking with power manager", e); |
| 2022 | } |
| 2023 | } finally { |
| 2024 | Binder.restoreCallingIdentity(ident); |
| 2025 | } |
| 2026 | } |
| 2027 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2028 | public long getMaximumTimeToLock(ComponentName who, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2029 | if (!mHasFeature) { |
| 2030 | return 0; |
| 2031 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2032 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2033 | synchronized (this) { |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 2034 | long time = 0; |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2035 | |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2036 | if (who != null) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2037 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
| Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 2038 | return admin != null ? admin.maximumTimeToUnlock : time; |
| 2039 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2040 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2041 | DevicePolicyData policy = getUserData(userHandle); |
| 2042 | final int N = policy.mAdminList.size(); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 2043 | for (int i=0; i<N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2044 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Dianne Hackborn | d47c6ed | 2010-01-27 16:21:20 -0800 | [diff] [blame] | 2045 | if (time == 0) { |
| 2046 | time = admin.maximumTimeToUnlock; |
| 2047 | } else if (admin.maximumTimeToUnlock != 0 |
| 2048 | && time > admin.maximumTimeToUnlock) { |
| 2049 | time = admin.maximumTimeToUnlock; |
| 2050 | } |
| 2051 | } |
| 2052 | return time; |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2053 | } |
| 2054 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2055 | |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2056 | public void lockNow() { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2057 | if (!mHasFeature) { |
| 2058 | return; |
| 2059 | } |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2060 | synchronized (this) { |
| 2061 | // This API can only be called by an active device admin, |
| 2062 | // so try to retrieve it to check that the caller is one. |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2063 | getActiveAdminForCallerLocked(null, |
| 2064 | DeviceAdminInfo.USES_POLICY_FORCE_LOCK); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2065 | lockNowUnchecked(); |
| 2066 | } |
| 2067 | } |
| 2068 | |
| 2069 | private void lockNowUnchecked() { |
| 2070 | long ident = Binder.clearCallingIdentity(); |
| 2071 | try { |
| 2072 | // Power off the display |
| 2073 | getIPowerManager().goToSleep(SystemClock.uptimeMillis(), |
| 2074 | PowerManager.GO_TO_SLEEP_REASON_DEVICE_ADMIN); |
| 2075 | // Ensure the device is locked |
| Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 2076 | getWindowManager().lockNow(null); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2077 | } catch (RemoteException e) { |
| 2078 | } finally { |
| 2079 | Binder.restoreCallingIdentity(ident); |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2080 | } |
| 2081 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2082 | |
| Ben Komalo | ed48c8b | 2011-10-17 17:30:21 -0700 | [diff] [blame] | 2083 | private boolean isExtStorageEncrypted() { |
| 2084 | String state = SystemProperties.get("vold.decrypt"); |
| 2085 | return !"".equals(state); |
| 2086 | } |
| 2087 | |
| Maggie Benthall | da51e68 | 2013-08-08 22:35:44 -0400 | [diff] [blame] | 2088 | public boolean installCaCert(byte[] certBuffer) throws RemoteException { |
| 2089 | mContext.enforceCallingOrSelfPermission(MANAGE_CA_CERTIFICATES, null); |
| 2090 | KeyChainConnection keyChainConnection = null; |
| 2091 | byte[] pemCert; |
| 2092 | try { |
| 2093 | X509Certificate cert = parseCert(certBuffer); |
| 2094 | pemCert = Credentials.convertToPem(cert); |
| 2095 | } catch (CertificateException ce) { |
| 2096 | Log.e(TAG, "Problem converting cert", ce); |
| 2097 | return false; |
| 2098 | } catch (IOException ioe) { |
| 2099 | Log.e(TAG, "Problem reading cert", ioe); |
| 2100 | return false; |
| 2101 | } |
| 2102 | try { |
| 2103 | keyChainConnection = KeyChain.bind(mContext); |
| 2104 | try { |
| 2105 | keyChainConnection.getService().installCaCertificate(pemCert); |
| 2106 | return true; |
| 2107 | } finally { |
| 2108 | if (keyChainConnection != null) { |
| 2109 | keyChainConnection.close(); |
| 2110 | keyChainConnection = null; |
| 2111 | } |
| 2112 | } |
| 2113 | } catch (InterruptedException e1) { |
| 2114 | Log.w(TAG, "installCaCertsToKeyChain(): ", e1); |
| 2115 | Thread.currentThread().interrupt(); |
| 2116 | } |
| 2117 | return false; |
| 2118 | } |
| 2119 | |
| 2120 | private static X509Certificate parseCert(byte[] certBuffer) |
| 2121 | throws CertificateException, IOException { |
| 2122 | CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); |
| 2123 | return (X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream( |
| 2124 | certBuffer)); |
| 2125 | } |
| 2126 | |
| 2127 | public void uninstallCaCert(final byte[] certBuffer) { |
| 2128 | mContext.enforceCallingOrSelfPermission(MANAGE_CA_CERTIFICATES, null); |
| 2129 | TrustedCertificateStore certStore = new TrustedCertificateStore(); |
| 2130 | String alias = null; |
| 2131 | try { |
| 2132 | X509Certificate cert = parseCert(certBuffer); |
| 2133 | alias = certStore.getCertificateAlias(cert); |
| 2134 | } catch (CertificateException ce) { |
| 2135 | Log.e(TAG, "Problem creating X509Certificate", ce); |
| 2136 | return; |
| 2137 | } catch (IOException ioe) { |
| 2138 | Log.e(TAG, "Problem reading certificate", ioe); |
| 2139 | return; |
| 2140 | } |
| 2141 | try { |
| 2142 | KeyChainConnection keyChainConnection = KeyChain.bind(mContext); |
| 2143 | IKeyChainService service = keyChainConnection.getService(); |
| 2144 | try { |
| 2145 | service.deleteCaCertificate(alias); |
| 2146 | } catch (RemoteException e) { |
| 2147 | Log.e(TAG, "from CaCertUninstaller: ", e); |
| 2148 | } finally { |
| 2149 | keyChainConnection.close(); |
| 2150 | keyChainConnection = null; |
| 2151 | } |
| 2152 | } catch (InterruptedException ie) { |
| 2153 | Log.w(TAG, "CaCertUninstaller: ", ie); |
| 2154 | Thread.currentThread().interrupt(); |
| 2155 | } |
| 2156 | } |
| 2157 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2158 | void wipeDataLocked(int flags) { |
| Ben Komalo | ed48c8b | 2011-10-17 17:30:21 -0700 | [diff] [blame] | 2159 | // If the SD card is encrypted and non-removable, we have to force a wipe. |
| 2160 | boolean forceExtWipe = !Environment.isExternalStorageRemovable() && isExtStorageEncrypted(); |
| 2161 | boolean wipeExtRequested = (flags&DevicePolicyManager.WIPE_EXTERNAL_STORAGE) != 0; |
| 2162 | |
| 2163 | // Note: we can only do the wipe via ExternalStorageFormatter if the volume is not emulated. |
| 2164 | if ((forceExtWipe || wipeExtRequested) && !Environment.isExternalStorageEmulated()) { |
| Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2165 | Intent intent = new Intent(ExternalStorageFormatter.FORMAT_AND_FACTORY_RESET); |
| Masanori Ogino | f535cb04 | 2012-02-15 19:25:50 +0900 | [diff] [blame] | 2166 | intent.putExtra(ExternalStorageFormatter.EXTRA_ALWAYS_RESET, true); |
| Dianne Hackborn | 4249917 | 2010-10-15 18:45:07 -0700 | [diff] [blame] | 2167 | intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME); |
| 2168 | mWakeLock.acquire(10000); |
| 2169 | mContext.startService(intent); |
| 2170 | } else { |
| 2171 | try { |
| 2172 | RecoverySystem.rebootWipeUserData(mContext); |
| 2173 | } catch (IOException e) { |
| 2174 | Slog.w(TAG, "Failed requesting data wipe", e); |
| 2175 | } |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2176 | } |
| 2177 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2178 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2179 | public void wipeData(int flags, final int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2180 | if (!mHasFeature) { |
| 2181 | return; |
| 2182 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2183 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2184 | synchronized (this) { |
| 2185 | // This API can only be called by an active device admin, |
| 2186 | // so try to retrieve it to check that the caller is one. |
| Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 2187 | getActiveAdminForCallerLocked(null, |
| 2188 | DeviceAdminInfo.USES_POLICY_WIPE_DATA); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2189 | long ident = Binder.clearCallingIdentity(); |
| 2190 | try { |
| Amith Yamasani | 32f0742 | 2012-11-16 15:09:13 -0800 | [diff] [blame] | 2191 | wipeDeviceOrUserLocked(flags, userHandle); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2192 | } finally { |
| 2193 | Binder.restoreCallingIdentity(ident); |
| 2194 | } |
| Dianne Hackborn | df83afa | 2010-01-20 13:37:26 -0800 | [diff] [blame] | 2195 | } |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2196 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2197 | |
| Amith Yamasani | 32f0742 | 2012-11-16 15:09:13 -0800 | [diff] [blame] | 2198 | private void wipeDeviceOrUserLocked(int flags, final int userHandle) { |
| 2199 | if (userHandle == UserHandle.USER_OWNER) { |
| 2200 | wipeDataLocked(flags); |
| 2201 | } else { |
| 2202 | lockNowUnchecked(); |
| 2203 | mHandler.post(new Runnable() { |
| 2204 | public void run() { |
| 2205 | try { |
| Amith Yamasani | e4cf734 | 2012-12-17 11:12:09 -0800 | [diff] [blame] | 2206 | ActivityManagerNative.getDefault().switchUser(UserHandle.USER_OWNER); |
| Amith Yamasani | 32f0742 | 2012-11-16 15:09:13 -0800 | [diff] [blame] | 2207 | ((UserManager) mContext.getSystemService(Context.USER_SERVICE)) |
| 2208 | .removeUser(userHandle); |
| 2209 | } catch (RemoteException re) { |
| 2210 | // Shouldn't happen |
| 2211 | } |
| 2212 | } |
| 2213 | }); |
| 2214 | } |
| 2215 | } |
| 2216 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2217 | public void getRemoveWarning(ComponentName comp, final RemoteCallback result, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2218 | if (!mHasFeature) { |
| 2219 | return; |
| 2220 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2221 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2222 | mContext.enforceCallingOrSelfPermission( |
| 2223 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2224 | |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2225 | synchronized (this) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2226 | ActiveAdmin admin = getActiveAdminUncheckedLocked(comp, userHandle); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2227 | if (admin == null) { |
| 2228 | try { |
| 2229 | result.sendResult(null); |
| 2230 | } catch (RemoteException e) { |
| 2231 | } |
| 2232 | return; |
| 2233 | } |
| Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2234 | Intent intent = new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_DISABLE_REQUESTED); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2235 | intent.setComponent(admin.info.getComponent()); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2236 | mContext.sendOrderedBroadcastAsUser(intent, new UserHandle(userHandle), |
| Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2237 | null, new BroadcastReceiver() { |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2238 | @Override |
| 2239 | public void onReceive(Context context, Intent intent) { |
| 2240 | try { |
| 2241 | result.sendResult(getResultExtras(false)); |
| 2242 | } catch (RemoteException e) { |
| 2243 | } |
| 2244 | } |
| 2245 | }, null, Activity.RESULT_OK, null, null); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2246 | } |
| 2247 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2248 | |
| Konstantin Lopyrev | a15dcfa | 2010-05-24 17:10:56 -0700 | [diff] [blame] | 2249 | public void setActivePasswordState(int quality, int length, int letters, int uppercase, |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2250 | int lowercase, int numbers, int symbols, int nonletter, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2251 | if (!mHasFeature) { |
| 2252 | return; |
| 2253 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2254 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2255 | mContext.enforceCallingOrSelfPermission( |
| 2256 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2257 | DevicePolicyData p = getUserData(userHandle); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2258 | |
| Dianne Hackborn | 85f2c9c | 2010-03-22 11:12:48 -0700 | [diff] [blame] | 2259 | validateQualityConstant(quality); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2260 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2261 | synchronized (this) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2262 | if (p.mActivePasswordQuality != quality || p.mActivePasswordLength != length |
| 2263 | || p.mFailedPasswordAttempts != 0 || p.mActivePasswordLetters != letters |
| 2264 | || p.mActivePasswordUpperCase != uppercase |
| 2265 | || p.mActivePasswordLowerCase != lowercase || p.mActivePasswordNumeric != numbers |
| 2266 | || p.mActivePasswordSymbols != symbols || p.mActivePasswordNonLetter != nonletter) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2267 | long ident = Binder.clearCallingIdentity(); |
| 2268 | try { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2269 | p.mActivePasswordQuality = quality; |
| 2270 | p.mActivePasswordLength = length; |
| 2271 | p.mActivePasswordLetters = letters; |
| 2272 | p.mActivePasswordLowerCase = lowercase; |
| 2273 | p.mActivePasswordUpperCase = uppercase; |
| 2274 | p.mActivePasswordNumeric = numbers; |
| 2275 | p.mActivePasswordSymbols = symbols; |
| 2276 | p.mActivePasswordNonLetter = nonletter; |
| 2277 | p.mFailedPasswordAttempts = 0; |
| 2278 | saveSettingsLocked(userHandle); |
| 2279 | updatePasswordExpirationsLocked(userHandle); |
| 2280 | setExpirationAlarmCheckLocked(mContext, p); |
| Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 2281 | sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_CHANGED, |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2282 | DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD, userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2283 | } finally { |
| 2284 | Binder.restoreCallingIdentity(ident); |
| 2285 | } |
| 2286 | } |
| 2287 | } |
| 2288 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2289 | |
| Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 2290 | /** |
| 2291 | * Called any time the device password is updated. Resets all password expiration clocks. |
| 2292 | */ |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2293 | private void updatePasswordExpirationsLocked(int userHandle) { |
| 2294 | DevicePolicyData policy = getUserData(userHandle); |
| 2295 | final int N = policy.mAdminList.size(); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2296 | if (N > 0) { |
| 2297 | for (int i=0; i<N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2298 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2299 | if (admin.info.usesPolicy(DeviceAdminInfo.USES_POLICY_EXPIRE_PASSWORD)) { |
| Andy Stadler | 043116a | 2010-11-29 17:43:32 -0800 | [diff] [blame] | 2300 | long timeout = admin.passwordExpirationTimeout; |
| 2301 | long expiration = timeout > 0L ? (timeout + System.currentTimeMillis()) : 0L; |
| 2302 | admin.passwordExpirationDate = expiration; |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2303 | } |
| 2304 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2305 | saveSettingsLocked(userHandle); |
| Jim Miller | a4e28d1 | 2010-11-08 16:15:47 -0800 | [diff] [blame] | 2306 | } |
| 2307 | } |
| 2308 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2309 | public void reportFailedPasswordAttempt(int userHandle) { |
| 2310 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2311 | mContext.enforceCallingOrSelfPermission( |
| 2312 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2313 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2314 | synchronized (this) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2315 | DevicePolicyData policy = getUserData(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2316 | long ident = Binder.clearCallingIdentity(); |
| 2317 | try { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2318 | policy.mFailedPasswordAttempts++; |
| 2319 | saveSettingsLocked(userHandle); |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2320 | if (mHasFeature) { |
| 2321 | int max = getMaximumFailedPasswordsForWipe(null, userHandle); |
| 2322 | if (max > 0 && policy.mFailedPasswordAttempts >= max) { |
| 2323 | wipeDeviceOrUserLocked(0, userHandle); |
| 2324 | } |
| 2325 | sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_FAILED, |
| 2326 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN, userHandle); |
| Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 2327 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2328 | } finally { |
| 2329 | Binder.restoreCallingIdentity(ident); |
| 2330 | } |
| 2331 | } |
| 2332 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2333 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2334 | public void reportSuccessfulPasswordAttempt(int userHandle) { |
| 2335 | enforceCrossUserPermission(userHandle); |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2336 | mContext.enforceCallingOrSelfPermission( |
| 2337 | android.Manifest.permission.BIND_DEVICE_ADMIN, null); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2338 | |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2339 | synchronized (this) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2340 | DevicePolicyData policy = getUserData(userHandle); |
| 2341 | if (policy.mFailedPasswordAttempts != 0 || policy.mPasswordOwner >= 0) { |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2342 | long ident = Binder.clearCallingIdentity(); |
| 2343 | try { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2344 | policy.mFailedPasswordAttempts = 0; |
| 2345 | policy.mPasswordOwner = -1; |
| 2346 | saveSettingsLocked(userHandle); |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2347 | if (mHasFeature) { |
| 2348 | sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_SUCCEEDED, |
| 2349 | DeviceAdminInfo.USES_POLICY_WATCH_LOGIN, userHandle); |
| 2350 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2351 | } finally { |
| 2352 | Binder.restoreCallingIdentity(ident); |
| 2353 | } |
| 2354 | } |
| 2355 | } |
| 2356 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2357 | |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2358 | public ComponentName setGlobalProxy(ComponentName who, String proxySpec, |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2359 | String exclusionList, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2360 | if (!mHasFeature) { |
| 2361 | return null; |
| 2362 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2363 | enforceCrossUserPermission(userHandle); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2364 | synchronized(this) { |
| 2365 | if (who == null) { |
| 2366 | throw new NullPointerException("ComponentName is null"); |
| 2367 | } |
| 2368 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2369 | // Only check if owner has set global proxy. We don't allow other users to set it. |
| 2370 | DevicePolicyData policy = getUserData(UserHandle.USER_OWNER); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2371 | ActiveAdmin admin = getActiveAdminForCallerLocked(who, |
| 2372 | DeviceAdminInfo.USES_POLICY_SETS_GLOBAL_PROXY); |
| 2373 | |
| 2374 | // Scan through active admins and find if anyone has already |
| 2375 | // set the global proxy. |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2376 | Set<ComponentName> compSet = policy.mAdminMap.keySet(); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2377 | for (ComponentName component : compSet) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2378 | ActiveAdmin ap = policy.mAdminMap.get(component); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2379 | if ((ap.specifiesGlobalProxy) && (!component.equals(who))) { |
| 2380 | // Another admin already sets the global proxy |
| 2381 | // Return it to the caller. |
| 2382 | return component; |
| 2383 | } |
| 2384 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2385 | |
| 2386 | // If the user is not the owner, don't set the global proxy. Fail silently. |
| 2387 | if (UserHandle.getCallingUserId() != UserHandle.USER_OWNER) { |
| 2388 | Slog.w(TAG, "Only the owner is allowed to set the global proxy. User " |
| 2389 | + userHandle + " is not permitted."); |
| 2390 | return null; |
| 2391 | } |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2392 | if (proxySpec == null) { |
| 2393 | admin.specifiesGlobalProxy = false; |
| 2394 | admin.globalProxySpec = null; |
| 2395 | admin.globalProxyExclusionList = null; |
| 2396 | } else { |
| 2397 | |
| 2398 | admin.specifiesGlobalProxy = true; |
| 2399 | admin.globalProxySpec = proxySpec; |
| 2400 | admin.globalProxyExclusionList = exclusionList; |
| 2401 | } |
| 2402 | |
| 2403 | // Reset the global proxy accordingly |
| 2404 | // Do this using system permissions, as apps cannot write to secure settings |
| 2405 | long origId = Binder.clearCallingIdentity(); |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2406 | resetGlobalProxyLocked(policy); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2407 | Binder.restoreCallingIdentity(origId); |
| 2408 | return null; |
| 2409 | } |
| 2410 | } |
| 2411 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2412 | public ComponentName getGlobalProxyAdmin(int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2413 | if (!mHasFeature) { |
| 2414 | return null; |
| 2415 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2416 | enforceCrossUserPermission(userHandle); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2417 | synchronized(this) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2418 | DevicePolicyData policy = getUserData(UserHandle.USER_OWNER); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2419 | // Scan through active admins and find if anyone has already |
| 2420 | // set the global proxy. |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2421 | final int N = policy.mAdminList.size(); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2422 | for (int i = 0; i < N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2423 | ActiveAdmin ap = policy.mAdminList.get(i); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2424 | if (ap.specifiesGlobalProxy) { |
| 2425 | // Device admin sets the global proxy |
| 2426 | // Return it to the caller. |
| 2427 | return ap.info.getComponent(); |
| 2428 | } |
| 2429 | } |
| 2430 | } |
| 2431 | // No device admin sets the global proxy. |
| 2432 | return null; |
| 2433 | } |
| 2434 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2435 | private void resetGlobalProxyLocked(DevicePolicyData policy) { |
| 2436 | final int N = policy.mAdminList.size(); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2437 | for (int i = 0; i < N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2438 | ActiveAdmin ap = policy.mAdminList.get(i); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2439 | if (ap.specifiesGlobalProxy) { |
| Dianne Hackborn | 2fe8fb2 | 2012-06-15 17:05:25 -0700 | [diff] [blame] | 2440 | saveGlobalProxyLocked(ap.globalProxySpec, ap.globalProxyExclusionList); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2441 | return; |
| 2442 | } |
| 2443 | } |
| 2444 | // No device admins defining global proxies - reset global proxy settings to none |
| Dianne Hackborn | 2fe8fb2 | 2012-06-15 17:05:25 -0700 | [diff] [blame] | 2445 | saveGlobalProxyLocked(null, null); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2446 | } |
| 2447 | |
| Dianne Hackborn | 2fe8fb2 | 2012-06-15 17:05:25 -0700 | [diff] [blame] | 2448 | private void saveGlobalProxyLocked(String proxySpec, String exclusionList) { |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2449 | if (exclusionList == null) { |
| 2450 | exclusionList = ""; |
| 2451 | } |
| 2452 | if (proxySpec == null) { |
| 2453 | proxySpec = ""; |
| 2454 | } |
| 2455 | // Remove white spaces |
| 2456 | proxySpec = proxySpec.trim(); |
| Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 2457 | String data[] = proxySpec.split(":"); |
| 2458 | int proxyPort = 8080; |
| 2459 | if (data.length > 1) { |
| 2460 | try { |
| 2461 | proxyPort = Integer.parseInt(data[1]); |
| 2462 | } catch (NumberFormatException e) {} |
| 2463 | } |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2464 | exclusionList = exclusionList.trim(); |
| 2465 | ContentResolver res = mContext.getContentResolver(); |
| Jeff Sharkey | 625239a | 2012-09-26 22:03:49 -0700 | [diff] [blame] | 2466 | Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_HOST, data[0]); |
| 2467 | Settings.Global.putInt(res, Settings.Global.GLOBAL_HTTP_PROXY_PORT, proxyPort); |
| 2468 | Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST, |
| Robert Greenwalt | 434203a | 2010-10-11 16:00:27 -0700 | [diff] [blame] | 2469 | exclusionList); |
| Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
| Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2472 | /** |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2473 | * Set the storage encryption request for a single admin. Returns the new total request |
| 2474 | * status (for all admins). |
| Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2475 | */ |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2476 | public int setStorageEncryption(ComponentName who, boolean encrypt, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2477 | if (!mHasFeature) { |
| 2478 | return DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED; |
| 2479 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2480 | enforceCrossUserPermission(userHandle); |
| Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2481 | synchronized (this) { |
| 2482 | // Check for permissions |
| 2483 | if (who == null) { |
| 2484 | throw new NullPointerException("ComponentName is null"); |
| 2485 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2486 | // Only owner can set storage encryption |
| 2487 | if (userHandle != UserHandle.USER_OWNER |
| 2488 | || UserHandle.getCallingUserId() != UserHandle.USER_OWNER) { |
| 2489 | Slog.w(TAG, "Only owner is allowed to set storage encryption. User " |
| 2490 | + UserHandle.getCallingUserId() + " is not permitted."); |
| 2491 | return 0; |
| 2492 | } |
| 2493 | |
| Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2494 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 2495 | DeviceAdminInfo.USES_ENCRYPTED_STORAGE); |
| 2496 | |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2497 | // Quick exit: If the filesystem does not support encryption, we can exit early. |
| 2498 | if (!isEncryptionSupported()) { |
| 2499 | return DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED; |
| 2500 | } |
| 2501 | |
| 2502 | // (1) Record the value for the admin so it's sticky |
| 2503 | if (ap.encryptionRequested != encrypt) { |
| 2504 | ap.encryptionRequested = encrypt; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2505 | saveSettingsLocked(userHandle); |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2506 | } |
| 2507 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2508 | DevicePolicyData policy = getUserData(UserHandle.USER_OWNER); |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2509 | // (2) Compute "max" for all admins |
| 2510 | boolean newRequested = false; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2511 | final int N = policy.mAdminList.size(); |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2512 | for (int i = 0; i < N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2513 | newRequested |= policy.mAdminList.get(i).encryptionRequested; |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2514 | } |
| 2515 | |
| 2516 | // Notify OS of new request |
| 2517 | setEncryptionRequested(newRequested); |
| 2518 | |
| 2519 | // Return the new global request status |
| 2520 | return newRequested |
| 2521 | ? DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE |
| 2522 | : DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE; |
| Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2523 | } |
| 2524 | } |
| 2525 | |
| 2526 | /** |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2527 | * Get the current storage encryption request status for a given admin, or aggregate of all |
| 2528 | * active admins. |
| Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2529 | */ |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2530 | public boolean getStorageEncryption(ComponentName who, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2531 | if (!mHasFeature) { |
| 2532 | return false; |
| 2533 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2534 | enforceCrossUserPermission(userHandle); |
| Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2535 | synchronized (this) { |
| 2536 | // Check for permissions if a particular caller is specified |
| 2537 | if (who != null) { |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2538 | // When checking for a single caller, status is based on caller's request |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2539 | ActiveAdmin ap = getActiveAdminUncheckedLocked(who, userHandle); |
| Andy Stadler | c994d69 | 2011-06-01 15:30:54 -0700 | [diff] [blame] | 2540 | return ap != null ? ap.encryptionRequested : false; |
| Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2541 | } |
| 2542 | |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2543 | // If no particular caller is specified, return the aggregate set of requests. |
| 2544 | // This is short circuited by returning true on the first hit. |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2545 | DevicePolicyData policy = getUserData(userHandle); |
| 2546 | final int N = policy.mAdminList.size(); |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2547 | for (int i = 0; i < N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2548 | if (policy.mAdminList.get(i).encryptionRequested) { |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2549 | return true; |
| 2550 | } |
| 2551 | } |
| 2552 | return false; |
| Andy Stadler | 7b0f8f0 | 2011-01-12 14:59:52 -0800 | [diff] [blame] | 2553 | } |
| 2554 | } |
| 2555 | |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2556 | /** |
| 2557 | * Get the current encryption status of the device. |
| 2558 | */ |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2559 | public int getStorageEncryptionStatus(int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2560 | if (!mHasFeature) { |
| 2561 | // Ok to return current status. |
| 2562 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2563 | enforceCrossUserPermission(userHandle); |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2564 | return getEncryptionStatus(); |
| 2565 | } |
| 2566 | |
| 2567 | /** |
| 2568 | * Hook to low-levels: This should report if the filesystem supports encrypted storage. |
| 2569 | */ |
| 2570 | private boolean isEncryptionSupported() { |
| 2571 | // Note, this can be implemented as |
| 2572 | // return getEncryptionStatus() != DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED; |
| 2573 | // But is provided as a separate internal method if there's a faster way to do a |
| 2574 | // simple check for supported-or-not. |
| 2575 | return getEncryptionStatus() != DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED; |
| 2576 | } |
| 2577 | |
| 2578 | /** |
| 2579 | * Hook to low-levels: Reporting the current status of encryption. |
| 2580 | * @return A value such as {@link DevicePolicyManager#ENCRYPTION_STATUS_UNSUPPORTED} or |
| 2581 | * {@link DevicePolicyManager#ENCRYPTION_STATUS_INACTIVE} or |
| 2582 | * {@link DevicePolicyManager#ENCRYPTION_STATUS_ACTIVE}. |
| 2583 | */ |
| 2584 | private int getEncryptionStatus() { |
| Andy Stadler | 0fe45de | 2011-01-20 16:35:09 -0800 | [diff] [blame] | 2585 | String status = SystemProperties.get("ro.crypto.state", "unsupported"); |
| 2586 | if ("encrypted".equalsIgnoreCase(status)) { |
| 2587 | return DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE; |
| 2588 | } else if ("unencrypted".equalsIgnoreCase(status)) { |
| 2589 | return DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE; |
| 2590 | } else { |
| 2591 | return DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED; |
| 2592 | } |
| Andy Stadler | 22dbfda | 2011-01-17 12:47:31 -0800 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | /** |
| 2596 | * Hook to low-levels: If needed, record the new admin setting for encryption. |
| 2597 | */ |
| 2598 | private void setEncryptionRequested(boolean encrypt) { |
| 2599 | } |
| 2600 | |
| Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2601 | /** |
| 2602 | * The system property used to share the state of the camera. The native camera service |
| 2603 | * is expected to read this property and act accordingly. |
| 2604 | */ |
| 2605 | public static final String SYSTEM_PROP_DISABLE_CAMERA = "sys.secpolicy.camera.disabled"; |
| 2606 | |
| 2607 | /** |
| 2608 | * Disables all device cameras according to the specified admin. |
| 2609 | */ |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2610 | public void setCameraDisabled(ComponentName who, boolean disabled, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2611 | if (!mHasFeature) { |
| 2612 | return; |
| 2613 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2614 | enforceCrossUserPermission(userHandle); |
| Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2615 | synchronized (this) { |
| 2616 | if (who == null) { |
| 2617 | throw new NullPointerException("ComponentName is null"); |
| 2618 | } |
| 2619 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| 2620 | DeviceAdminInfo.USES_POLICY_DISABLE_CAMERA); |
| 2621 | if (ap.disableCamera != disabled) { |
| 2622 | ap.disableCamera = disabled; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2623 | saveSettingsLocked(userHandle); |
| Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2624 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2625 | syncDeviceCapabilitiesLocked(getUserData(userHandle)); |
| Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2626 | } |
| 2627 | } |
| 2628 | |
| 2629 | /** |
| 2630 | * Gets whether or not all device cameras are disabled for a given admin, or disabled for any |
| 2631 | * active admins. |
| 2632 | */ |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2633 | public boolean getCameraDisabled(ComponentName who, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2634 | if (!mHasFeature) { |
| 2635 | return false; |
| 2636 | } |
| Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2637 | synchronized (this) { |
| 2638 | if (who != null) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2639 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
| Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2640 | return (admin != null) ? admin.disableCamera : false; |
| 2641 | } |
| 2642 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2643 | DevicePolicyData policy = getUserData(userHandle); |
| Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2644 | // Determine whether or not the device camera is disabled for any active admins. |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2645 | final int N = policy.mAdminList.size(); |
| Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2646 | for (int i = 0; i < N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2647 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Ben Komalo | 2447edd | 2011-05-09 16:05:33 -0700 | [diff] [blame] | 2648 | if (admin.disableCamera) { |
| 2649 | return true; |
| 2650 | } |
| 2651 | } |
| 2652 | return false; |
| 2653 | } |
| 2654 | } |
| 2655 | |
| Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2656 | /** |
| Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2657 | * Selectively disable keyguard features. |
| Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2658 | */ |
| Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2659 | public void setKeyguardDisabledFeatures(ComponentName who, int which, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2660 | if (!mHasFeature) { |
| 2661 | return; |
| 2662 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2663 | enforceCrossUserPermission(userHandle); |
| Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2664 | synchronized (this) { |
| 2665 | if (who == null) { |
| 2666 | throw new NullPointerException("ComponentName is null"); |
| 2667 | } |
| 2668 | ActiveAdmin ap = getActiveAdminForCallerLocked(who, |
| Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2669 | DeviceAdminInfo.USES_POLICY_DISABLE_KEYGUARD_FEATURES); |
| 2670 | if (ap.disabledKeyguardFeatures != which) { |
| 2671 | ap.disabledKeyguardFeatures = which; |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2672 | saveSettingsLocked(userHandle); |
| Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2673 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2674 | syncDeviceCapabilitiesLocked(getUserData(userHandle)); |
| Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2675 | } |
| 2676 | } |
| 2677 | |
| 2678 | /** |
| Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2679 | * Gets the disabled state for features in keyguard for the given admin, |
| Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2680 | * or the aggregate of all active admins if who is null. |
| 2681 | */ |
| Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2682 | public int getKeyguardDisabledFeatures(ComponentName who, int userHandle) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2683 | if (!mHasFeature) { |
| 2684 | return 0; |
| 2685 | } |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2686 | enforceCrossUserPermission(userHandle); |
| Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2687 | synchronized (this) { |
| 2688 | if (who != null) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2689 | ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle); |
| Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2690 | return (admin != null) ? admin.disabledKeyguardFeatures : 0; |
| Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2691 | } |
| 2692 | |
| Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2693 | // Determine which keyguard features are disabled for any active admins. |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2694 | DevicePolicyData policy = getUserData(userHandle); |
| 2695 | final int N = policy.mAdminList.size(); |
| Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2696 | int which = 0; |
| 2697 | for (int i = 0; i < N; i++) { |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2698 | ActiveAdmin admin = policy.mAdminList.get(i); |
| Jim Miller | 48b9b0d | 2012-09-19 23:16:50 -0700 | [diff] [blame] | 2699 | which |= admin.disabledKeyguardFeatures; |
| Jim Miller | b8ec470 | 2012-08-31 17:19:10 -0700 | [diff] [blame] | 2700 | } |
| 2701 | return which; |
| 2702 | } |
| 2703 | } |
| 2704 | |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2705 | @Override |
| Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2706 | public boolean setDeviceOwner(String packageName, String ownerName) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2707 | if (!mHasFeature) { |
| 2708 | return false; |
| 2709 | } |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2710 | if (packageName == null |
| 2711 | || !DeviceOwner.isInstalled(packageName, mContext.getPackageManager())) { |
| 2712 | throw new IllegalArgumentException("Invalid package name " + packageName |
| 2713 | + " for device owner"); |
| 2714 | } |
| 2715 | synchronized (this) { |
| 2716 | if (mDeviceOwner == null && !isDeviceProvisioned()) { |
| Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2717 | mDeviceOwner = new DeviceOwner(packageName, ownerName); |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2718 | mDeviceOwner.writeOwnerFile(); |
| 2719 | return true; |
| 2720 | } else { |
| 2721 | throw new IllegalStateException("Trying to set device owner to " + packageName |
| 2722 | + ", owner=" + mDeviceOwner.getPackageName() |
| 2723 | + ", device_provisioned=" + isDeviceProvisioned()); |
| 2724 | } |
| 2725 | } |
| 2726 | } |
| 2727 | |
| 2728 | @Override |
| 2729 | public boolean isDeviceOwner(String packageName) { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2730 | if (!mHasFeature) { |
| 2731 | return false; |
| 2732 | } |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2733 | synchronized (this) { |
| 2734 | return mDeviceOwner != null |
| 2735 | && mDeviceOwner.getPackageName().equals(packageName); |
| 2736 | } |
| 2737 | } |
| 2738 | |
| 2739 | @Override |
| 2740 | public String getDeviceOwner() { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2741 | if (!mHasFeature) { |
| 2742 | return null; |
| 2743 | } |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2744 | synchronized (this) { |
| 2745 | if (mDeviceOwner != null) { |
| 2746 | return mDeviceOwner.getPackageName(); |
| 2747 | } |
| 2748 | } |
| 2749 | return null; |
| 2750 | } |
| 2751 | |
| Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2752 | @Override |
| 2753 | public String getDeviceOwnerName() { |
| Amith Yamasani | 44a01b7 | 2013-09-16 10:44:57 -0700 | [diff] [blame] | 2754 | if (!mHasFeature) { |
| 2755 | return null; |
| 2756 | } |
| Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2757 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USERS, null); |
| 2758 | synchronized (this) { |
| 2759 | if (mDeviceOwner != null) { |
| 2760 | return mDeviceOwner.getName(); |
| 2761 | } |
| 2762 | } |
| 2763 | return null; |
| 2764 | } |
| 2765 | |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2766 | private boolean isDeviceProvisioned() { |
| 2767 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 2768 | Settings.Global.DEVICE_PROVISIONED, 0) > 0; |
| 2769 | } |
| 2770 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2771 | private void enforceCrossUserPermission(int userHandle) { |
| 2772 | if (userHandle < 0) { |
| 2773 | throw new IllegalArgumentException("Invalid userId " + userHandle); |
| 2774 | } |
| 2775 | final int callingUid = Binder.getCallingUid(); |
| 2776 | if (userHandle == UserHandle.getUserId(callingUid)) return; |
| 2777 | if (callingUid != Process.SYSTEM_UID && callingUid != 0) { |
| 2778 | mContext.enforceCallingOrSelfPermission( |
| 2779 | android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, "Must be system or have" |
| 2780 | + " INTERACT_ACROSS_USERS_FULL permission"); |
| 2781 | } |
| 2782 | } |
| 2783 | |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2784 | private void enableIfNecessary(String packageName, int userId) { |
| 2785 | try { |
| 2786 | IPackageManager ipm = AppGlobals.getPackageManager(); |
| 2787 | ApplicationInfo ai = ipm.getApplicationInfo(packageName, |
| 2788 | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, |
| 2789 | userId); |
| 2790 | if (ai.enabledSetting |
| 2791 | == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) { |
| 2792 | ipm.setApplicationEnabledSetting(packageName, |
| 2793 | PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, |
| Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 2794 | PackageManager.DONT_KILL_APP, userId, "DevicePolicyManager"); |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2795 | } |
| 2796 | } catch (RemoteException e) { |
| 2797 | } |
| 2798 | } |
| 2799 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2800 | @Override |
| 2801 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 2802 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 2803 | != PackageManager.PERMISSION_GRANTED) { |
| 2804 | |
| 2805 | pw.println("Permission Denial: can't dump DevicePolicyManagerService from from pid=" |
| 2806 | + Binder.getCallingPid() |
| 2807 | + ", uid=" + Binder.getCallingUid()); |
| 2808 | return; |
| 2809 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2810 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2811 | final Printer p = new PrintWriterPrinter(pw); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2812 | |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2813 | synchronized (this) { |
| 2814 | p.println("Current Device Policy Manager state:"); |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2815 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2816 | int userCount = mUserData.size(); |
| 2817 | for (int u = 0; u < userCount; u++) { |
| 2818 | DevicePolicyData policy = getUserData(mUserData.keyAt(u)); |
| 2819 | p.println(" Enabled Device Admins (User " + policy.mUserHandle + "):"); |
| 2820 | final int N = policy.mAdminList.size(); |
| 2821 | for (int i=0; i<N; i++) { |
| 2822 | ActiveAdmin ap = policy.mAdminList.get(i); |
| 2823 | if (ap != null) { |
| 2824 | pw.print(" "); pw.print(ap.info.getComponent().flattenToShortString()); |
| 2825 | pw.println(":"); |
| 2826 | ap.dump(" ", pw); |
| 2827 | } |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2828 | } |
| Konstantin Lopyrev | 3255823 | 2010-05-20 16:18:05 -0700 | [diff] [blame] | 2829 | |
| Amith Yamasani | 599dd7c | 2012-09-14 23:20:08 -0700 | [diff] [blame] | 2830 | pw.println(" "); |
| 2831 | pw.print(" mPasswordOwner="); pw.println(policy.mPasswordOwner); |
| 2832 | } |
| Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 2833 | } |
| 2834 | } |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2835 | |
| 2836 | static class DeviceOwner { |
| 2837 | private static final String DEVICE_OWNER_XML = "device_owner.xml"; |
| 2838 | private static final String TAG_DEVICE_OWNER = "device-owner"; |
| Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2839 | private static final String ATTR_NAME = "name"; |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2840 | private static final String ATTR_PACKAGE = "package"; |
| 2841 | private String mPackageName; |
| Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2842 | private String mOwnerName; |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2843 | |
| 2844 | DeviceOwner() { |
| 2845 | readOwnerFile(); |
| 2846 | } |
| 2847 | |
| Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2848 | DeviceOwner(String packageName, String ownerName) { |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2849 | this.mPackageName = packageName; |
| Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2850 | this.mOwnerName = ownerName; |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2851 | } |
| 2852 | |
| 2853 | static boolean isRegistered() { |
| 2854 | return new File(Environment.getSystemSecureDirectory(), |
| 2855 | DEVICE_OWNER_XML).exists(); |
| 2856 | } |
| 2857 | |
| 2858 | String getPackageName() { |
| 2859 | return mPackageName; |
| 2860 | } |
| 2861 | |
| Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2862 | String getName() { |
| 2863 | return mOwnerName; |
| 2864 | } |
| 2865 | |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2866 | static boolean isInstalled(String packageName, PackageManager pm) { |
| 2867 | try { |
| 2868 | PackageInfo pi; |
| 2869 | if ((pi = pm.getPackageInfo(packageName, 0)) != null) { |
| 2870 | if ((pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 2871 | return true; |
| 2872 | } |
| 2873 | } |
| 2874 | } catch (NameNotFoundException nnfe) { |
| 2875 | Slog.w(TAG, "Device Owner package " + packageName + " not installed."); |
| 2876 | } |
| 2877 | return false; |
| 2878 | } |
| 2879 | |
| 2880 | void readOwnerFile() { |
| 2881 | AtomicFile file = new AtomicFile(new File(Environment.getSystemSecureDirectory(), |
| 2882 | DEVICE_OWNER_XML)); |
| 2883 | try { |
| 2884 | FileInputStream input = file.openRead(); |
| 2885 | XmlPullParser parser = Xml.newPullParser(); |
| 2886 | parser.setInput(input, null); |
| 2887 | int type; |
| 2888 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 2889 | && type != XmlPullParser.START_TAG) { |
| 2890 | } |
| 2891 | String tag = parser.getName(); |
| 2892 | if (!TAG_DEVICE_OWNER.equals(tag)) { |
| 2893 | throw new XmlPullParserException( |
| 2894 | "Device Owner file does not start with device-owner tag: found " + tag); |
| 2895 | } |
| 2896 | mPackageName = parser.getAttributeValue(null, ATTR_PACKAGE); |
| Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2897 | mOwnerName = parser.getAttributeValue(null, ATTR_NAME); |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2898 | input.close(); |
| 2899 | } catch (XmlPullParserException xppe) { |
| 2900 | Slog.e(TAG, "Error parsing device-owner file\n" + xppe); |
| 2901 | } catch (IOException ioe) { |
| 2902 | Slog.e(TAG, "IO Exception when reading device-owner file\n" + ioe); |
| 2903 | } |
| 2904 | } |
| 2905 | |
| 2906 | void writeOwnerFile() { |
| 2907 | synchronized (this) { |
| 2908 | writeOwnerFileLocked(); |
| 2909 | } |
| 2910 | } |
| 2911 | |
| 2912 | private void writeOwnerFileLocked() { |
| 2913 | AtomicFile file = new AtomicFile(new File(Environment.getSystemSecureDirectory(), |
| 2914 | DEVICE_OWNER_XML)); |
| 2915 | try { |
| 2916 | FileOutputStream output = file.startWrite(); |
| 2917 | XmlSerializer out = new FastXmlSerializer(); |
| 2918 | out.setOutput(output, "utf-8"); |
| 2919 | out.startDocument(null, true); |
| 2920 | out.startTag(null, TAG_DEVICE_OWNER); |
| 2921 | out.attribute(null, ATTR_PACKAGE, mPackageName); |
| Geoffrey Borggaard | 334c7e3 | 2013-08-08 14:31:36 -0400 | [diff] [blame] | 2922 | if (mOwnerName != null) { |
| 2923 | out.attribute(null, ATTR_NAME, mOwnerName); |
| 2924 | } |
| Amith Yamasani | 71e6c69 | 2013-03-24 17:39:28 -0700 | [diff] [blame] | 2925 | out.endTag(null, TAG_DEVICE_OWNER); |
| 2926 | out.endDocument(); |
| 2927 | out.flush(); |
| 2928 | file.finishWrite(output); |
| 2929 | } catch (IOException ioe) { |
| 2930 | Slog.e(TAG, "IO Exception when writing device-owner file\n" + ioe); |
| 2931 | } |
| 2932 | } |
| 2933 | } |
| Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 2934 | } |