DeviceAdminReceiver.java revision 87bba1ee14279bb14a28d42e27c4ef66d9967bf8
1d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn/* 2d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * Copyright (C) 2010 The Android Open Source Project 3d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * 4d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * Licensed under the Apache License, Version 2.0 (the "License"); 5d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * you may not use this file except in compliance with the License. 6d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * You may obtain a copy of the License at 7d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * 8d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * http://www.apache.org/licenses/LICENSE-2.0 9d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * 10d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * Unless required by applicable law or agreed to in writing, software 11d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * distributed under the License is distributed on an "AS IS" BASIS, 12d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * See the License for the specific language governing permissions and 14d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * limitations under the License. 15d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn */ 16d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn 1787bba1ee14279bb14a28d42e27c4ef66d9967bf8Dianne Hackbornpackage android.app.admin; 18d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn 19d68478467e3f837511196c80891d7245d0e163dfDianne Hackbornimport android.annotation.SdkConstant; 20d68478467e3f837511196c80891d7245d0e163dfDianne Hackbornimport android.annotation.SdkConstant.SdkConstantType; 2187bba1ee14279bb14a28d42e27c4ef66d9967bf8Dianne Hackbornimport android.app.Service; 22d68478467e3f837511196c80891d7245d0e163dfDianne Hackbornimport android.content.BroadcastReceiver; 23d68478467e3f837511196c80891d7245d0e163dfDianne Hackbornimport android.content.ComponentName; 24d68478467e3f837511196c80891d7245d0e163dfDianne Hackbornimport android.content.Context; 25d68478467e3f837511196c80891d7245d0e163dfDianne Hackbornimport android.content.Intent; 268ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackbornimport android.os.Bundle; 27d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn 28d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn/** 29d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * Base class for implementing a device administration component. This 30d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * class provides a convenience for interpreting the raw intent actions 31d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * that are sent by the system. 32d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * 33ef6b22fc04a8d5ab26e13efac8069c097e0da7c9Dianne Hackborn * <p>The callback methods, like the base 34ef6b22fc04a8d5ab26e13efac8069c097e0da7c9Dianne Hackborn * {@link BroadcastReceiver#onReceive(Context, Intent) BroadcastReceiver.onReceive()} 35ef6b22fc04a8d5ab26e13efac8069c097e0da7c9Dianne Hackborn * method, happen on the main thread of the process. Thus long running 36ef6b22fc04a8d5ab26e13efac8069c097e0da7c9Dianne Hackborn * operations must be done on another thread. Note that because a receiver 37ef6b22fc04a8d5ab26e13efac8069c097e0da7c9Dianne Hackborn * is done once returning from its receive function, such long-running operations 38ef6b22fc04a8d5ab26e13efac8069c097e0da7c9Dianne Hackborn * should probably be done in a {@link Service}. 39ef6b22fc04a8d5ab26e13efac8069c097e0da7c9Dianne Hackborn * 40d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * <p>When publishing your DeviceAdmin subclass as a receiver, it must 41d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * handle {@link #ACTION_DEVICE_ADMIN_ENABLED} and require the 42d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * {@link android.Manifest.permission#BIND_DEVICE_ADMIN} permission. A typical 43d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * manifest entry would look like:</p> 44d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * 45ab8a8ed2eb068b696f6b5519c55a03546a5927efDianne Hackborn * {@sample development/samples/ApiDemos/AndroidManifest.xml device_admin_declaration} 46d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * 47d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * <p>The meta-data referenced here provides addition information specific 48d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * to the device administrator, as parsed by the {@link DeviceAdminInfo} class. 49d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * A typical file would be:</p> 50d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * 5188209d15dd5fcb883403525a6455857566e3aee7Andrew Stadler * {@sample development/samples/ApiDemos/res/xml/device_admin_sample.xml meta_data} 52d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn */ 53ef6b22fc04a8d5ab26e13efac8069c097e0da7c9Dianne Hackbornpublic class DeviceAdminReceiver extends BroadcastReceiver { 54d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn private static String TAG = "DevicePolicy"; 55d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn private static boolean DEBUG = false; 56d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn private static boolean localLOGV = DEBUG || android.util.Config.LOGV; 57d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn 58d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn /** 59d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * This is the primary action that a device administrator must implement to be 60d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * allowed to manage a device. This will be set to the receiver 61d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * when the user enables it for administration. You will generally 62ef6b22fc04a8d5ab26e13efac8069c097e0da7c9Dianne Hackborn * handle this in {@link DeviceAdminReceiver#onEnabled(Context, Intent)}. To be 63d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * supported, the receiver must also require the 64d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * {@link android.Manifest.permission#BIND_DEVICE_ADMIN} permission so 65d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * that other applications can not abuse it. 66d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn */ 67d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 68d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn public static final String ACTION_DEVICE_ADMIN_ENABLED 69d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn = "android.app.action.DEVICE_ADMIN_ENABLED"; 70d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn 71d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn /** 728ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * Action sent to a device administrator when the user has requested to 738ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * disable it, but before this has actually been done. This gives you 748ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * a chance to supply a message to the user about the impact of 758ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * disabling your admin, by setting the extra field 768ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * {@link #EXTRA_DISABLE_WARNING} in the result Intent. If not set, 778ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * no warning will be displayed. If set, the given text will be shown 788ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * to the user before they disable your admin. 798ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn */ 808ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 818ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn public static final String ACTION_DEVICE_ADMIN_DISABLE_REQUESTED 828ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn = "android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED"; 838ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn 848ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn /** 858ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * A CharSequence that can be shown to the user informing them of the 868ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * impact of disabling your admin. 878ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * 888ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * @see #ACTION_DEVICE_ADMIN_DISABLE_REQUESTED 898ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn */ 908ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn public static final String EXTRA_DISABLE_WARNING = "android.app.extra.DISABLE_WARNING"; 918ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn 928ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn /** 93d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * Action sent to a device administrator when the user has disabled 94d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * it. Upon return, the application no longer has access to the 95d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * protected device policy manager APIs. You will generally 96ef6b22fc04a8d5ab26e13efac8069c097e0da7c9Dianne Hackborn * handle this in {@link DeviceAdminReceiver#onDisabled(Context, Intent)}. Note 97d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * that this action will be 98d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * sent the receiver regardless of whether it is explicitly listed in 99d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * its intent filter. 100d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn */ 101d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 102d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn public static final String ACTION_DEVICE_ADMIN_DISABLED 103d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn = "android.app.action.DEVICE_ADMIN_DISABLED"; 104d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn 105d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn /** 106d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * Action sent to a device administrator when the user has changed the 107d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * password of their device. You can at this point check the characteristics 108254cb446faa7cb13699d8150eb4cc4f44cb61a2dDianne Hackborn * of the new password with {@link DevicePolicyManager#isActivePasswordSufficient() 109254cb446faa7cb13699d8150eb4cc4f44cb61a2dDianne Hackborn * DevicePolicyManager.isActivePasswordSufficient()}. 110254cb446faa7cb13699d8150eb4cc4f44cb61a2dDianne Hackborn * You will generally 111ef6b22fc04a8d5ab26e13efac8069c097e0da7c9Dianne Hackborn * handle this in {@link DeviceAdminReceiver#onPasswordChanged}. 1128aa2e8939c61d788cbc192098465e79f584e173aDianne Hackborn * 1138aa2e8939c61d788cbc192098465e79f584e173aDianne Hackborn * <p>The calling device admin must have requested 1148aa2e8939c61d788cbc192098465e79f584e173aDianne Hackborn * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to receive 1158aa2e8939c61d788cbc192098465e79f584e173aDianne Hackborn * this broadcast. 116d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn */ 117d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 118d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn public static final String ACTION_PASSWORD_CHANGED 119d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn = "android.app.action.ACTION_PASSWORD_CHANGED"; 120d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn 121d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn /** 122d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * Action sent to a device administrator when the user has failed at 123d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * attempted to enter the password. You can at this point check the 124d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * number of failed password attempts there have been with 125254cb446faa7cb13699d8150eb4cc4f44cb61a2dDianne Hackborn * {@link DevicePolicyManager#getCurrentFailedPasswordAttempts 126d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * DevicePolicyManager.getCurrentFailedPasswordAttempts()}. You will generally 127ef6b22fc04a8d5ab26e13efac8069c097e0da7c9Dianne Hackborn * handle this in {@link DeviceAdminReceiver#onPasswordFailed}. 1288aa2e8939c61d788cbc192098465e79f584e173aDianne Hackborn * 1298aa2e8939c61d788cbc192098465e79f584e173aDianne Hackborn * <p>The calling device admin must have requested 1308aa2e8939c61d788cbc192098465e79f584e173aDianne Hackborn * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to receive 1318aa2e8939c61d788cbc192098465e79f584e173aDianne Hackborn * this broadcast. 132d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn */ 133d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 134d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn public static final String ACTION_PASSWORD_FAILED 135d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn = "android.app.action.ACTION_PASSWORD_FAILED"; 136d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn 137d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn /** 138d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * Action sent to a device administrator when the user has successfully 139d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * entered their password, after failing one or more times. 1408aa2e8939c61d788cbc192098465e79f584e173aDianne Hackborn * 1418aa2e8939c61d788cbc192098465e79f584e173aDianne Hackborn * <p>The calling device admin must have requested 1428aa2e8939c61d788cbc192098465e79f584e173aDianne Hackborn * {@link DeviceAdminInfo#USES_POLICY_WATCH_LOGIN} to receive 1438aa2e8939c61d788cbc192098465e79f584e173aDianne Hackborn * this broadcast. 144d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn */ 145d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 146d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn public static final String ACTION_PASSWORD_SUCCEEDED 147d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn = "android.app.action.ACTION_PASSWORD_SUCCEEDED"; 148d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn 149d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn /** 150d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * Name under which an DevicePolicy component publishes information 151d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * about itself. This meta-data must reference an XML resource containing 152d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * a device-admin tag. XXX TO DO: describe syntax. 153d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn */ 154d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn public static final String DEVICE_ADMIN_META_DATA = "android.app.device_admin"; 155d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn 156d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn private DevicePolicyManager mManager; 157d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn private ComponentName mWho; 158d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn 159d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn /** 160d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * Retrieve the DevicePolicyManager interface for this administrator to work 161d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * with the system. 162d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn */ 163d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn public DevicePolicyManager getManager(Context context) { 164d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn if (mManager != null) { 165d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn return mManager; 166d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn } 167d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn mManager = (DevicePolicyManager)context.getSystemService( 168d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn Context.DEVICE_POLICY_SERVICE); 169d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn return mManager; 170d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn } 171d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn 172d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn /** 173d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * Retrieve the ComponentName describing who this device administrator is, for 174d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * use in {@link DevicePolicyManager} APIs that require the administrator to 175d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * identify itself. 176d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn */ 177d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn public ComponentName getWho(Context context) { 178d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn if (mWho != null) { 179d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn return mWho; 180d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn } 181d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn mWho = new ComponentName(context, getClass()); 182d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn return mWho; 183d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn } 184d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn 185d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn /** 186d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * Called after the administrator is first enabled, as a result of 187d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * receiving {@link #ACTION_DEVICE_ADMIN_ENABLED}. At this point you 188d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * can use {@link DevicePolicyManager} to set your desired policies. 189d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * @param context The running context as per {@link #onReceive}. 190d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * @param intent The received intent as per {@link #onReceive}. 191d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn */ 192d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn public void onEnabled(Context context, Intent intent) { 193d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn } 194d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn 195d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn /** 1968ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * Called when the user has asked to disable the administrator, as a result of 1978ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * receiving {@link #ACTION_DEVICE_ADMIN_DISABLE_REQUESTED}, giving you 1988ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * a chance to present a warning message to them. The message is returned 1998ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * as the result; if null is returned (the default implementation), no 2008ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * message will be displayed. 2018ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * @param context The running context as per {@link #onReceive}. 2028ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * @param intent The received intent as per {@link #onReceive}. 2038ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * @return Return the warning message to display to the user before 2048ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn * being disabled; if null is returned, no message is displayed. 2058ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn */ 2068ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn public CharSequence onDisableRequested(Context context, Intent intent) { 2078ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn return null; 2088ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn } 2098ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn 2108ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn /** 211d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * Called prior to the administrator being disabled, as a result of 212d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * receiving {@link #ACTION_DEVICE_ADMIN_DISABLED}. Upon return, you 213d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * can no longer use the protected parts of the {@link DevicePolicyManager} 214d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * API. 215d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * @param context The running context as per {@link #onReceive}. 216d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * @param intent The received intent as per {@link #onReceive}. 217d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn */ 218d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn public void onDisabled(Context context, Intent intent) { 219d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn } 220d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn 221d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn /** 222d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * Called after the user has changed their password, as a result of 223d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * receiving {@link #ACTION_PASSWORD_CHANGED}. At this point you 224d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * can use {@link DevicePolicyManager#getCurrentFailedPasswordAttempts() 225d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * DevicePolicyManager.getCurrentFailedPasswordAttempts()} 226d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * to retrieve the active password characteristics. 227d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * @param context The running context as per {@link #onReceive}. 228d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * @param intent The received intent as per {@link #onReceive}. 229d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn */ 230d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn public void onPasswordChanged(Context context, Intent intent) { 231d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn } 232d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn 233d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn /** 234d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * Called after the user has failed at entering their current password, as a result of 235d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * receiving {@link #ACTION_PASSWORD_FAILED}. At this point you 236d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * can use {@link DevicePolicyManager} to retrieve the number of failed 237d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * password attempts. 238d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * @param context The running context as per {@link #onReceive}. 239d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * @param intent The received intent as per {@link #onReceive}. 240d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn */ 241d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn public void onPasswordFailed(Context context, Intent intent) { 242d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn } 243d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn 244d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn /** 245d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * Called after the user has succeeded at entering their current password, 246d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * as a result of receiving {@link #ACTION_PASSWORD_SUCCEEDED}. This will 247d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * only be received the first time they succeed after having previously 248d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * failed. 249d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * @param context The running context as per {@link #onReceive}. 250d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * @param intent The received intent as per {@link #onReceive}. 251d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn */ 252d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn public void onPasswordSucceeded(Context context, Intent intent) { 253d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn } 254d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn 255d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn /** 256d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * Intercept standard device administrator broadcasts. Implementations 257d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * should not override this method; it is better to implement the 258d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn * convenience callbacks for each action. 259d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn */ 260d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn @Override 261d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn public void onReceive(Context context, Intent intent) { 262d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn String action = intent.getAction(); 263d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn if (ACTION_PASSWORD_CHANGED.equals(action)) { 264d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn onPasswordChanged(context, intent); 265d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn } else if (ACTION_PASSWORD_FAILED.equals(action)) { 266d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn onPasswordFailed(context, intent); 267d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn } else if (ACTION_PASSWORD_SUCCEEDED.equals(action)) { 268d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn onPasswordSucceeded(context, intent); 269d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn } else if (ACTION_DEVICE_ADMIN_ENABLED.equals(action)) { 270d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn onEnabled(context, intent); 2718ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn } else if (ACTION_DEVICE_ADMIN_DISABLE_REQUESTED.equals(action)) { 2728ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn CharSequence res = onDisableRequested(context, intent); 2738ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn if (res != null) { 2748ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn Bundle extras = getResultExtras(true); 2758ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn extras.putCharSequence(EXTRA_DISABLE_WARNING, res); 2768ea138cbf12b140d43fd81f4f12fe1a9234f1f25Dianne Hackborn } 277d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn } else if (ACTION_DEVICE_ADMIN_DISABLED.equals(action)) { 278d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn onDisabled(context, intent); 279d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn } 280d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn } 281d68478467e3f837511196c80891d7245d0e163dfDianne Hackborn} 282