diff options
5 files changed, 74 insertions, 60 deletions
diff --git a/api/current.txt b/api/current.txt index 7b7e876..bdeae78 100644 --- a/api/current.txt +++ b/api/current.txt @@ -5370,7 +5370,8 @@ package android.app.admin { method public java.lang.CharSequence onDisableRequested(android.content.Context, android.content.Intent); method public void onDisabled(android.content.Context, android.content.Intent); method public void onEnabled(android.content.Context, android.content.Intent); - method public void onLockTaskModeChanged(android.content.Context, android.content.Intent, boolean, java.lang.String); + method public void onLockTaskModeEntering(android.content.Context, android.content.Intent, java.lang.String); + method public void onLockTaskModeExiting(android.content.Context, android.content.Intent); method public void onPasswordChanged(android.content.Context, android.content.Intent); method public void onPasswordExpiring(android.content.Context, android.content.Intent); method public void onPasswordFailed(android.content.Context, android.content.Intent); @@ -5380,7 +5381,8 @@ package android.app.admin { field public static final java.lang.String ACTION_DEVICE_ADMIN_DISABLED = "android.app.action.DEVICE_ADMIN_DISABLED"; field public static final java.lang.String ACTION_DEVICE_ADMIN_DISABLE_REQUESTED = "android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED"; field public static final java.lang.String ACTION_DEVICE_ADMIN_ENABLED = "android.app.action.DEVICE_ADMIN_ENABLED"; - field public static final java.lang.String ACTION_LOCK_TASK_CHANGED = "android.app.action.ACTION_LOCK_TASK_CHANGED"; + field public static final java.lang.String ACTION_LOCK_TASK_ENTERING = "android.app.action.ACTION_LOCK_TASK_ENTERING"; + field public static final java.lang.String ACTION_LOCK_TASK_EXITING = "android.app.action.ACTION_LOCK_TASK_EXITING"; field public static final java.lang.String ACTION_PASSWORD_CHANGED = "android.app.action.ACTION_PASSWORD_CHANGED"; field public static final java.lang.String ACTION_PASSWORD_EXPIRING = "android.app.action.ACTION_PASSWORD_EXPIRING"; field public static final java.lang.String ACTION_PASSWORD_FAILED = "android.app.action.ACTION_PASSWORD_FAILED"; @@ -5388,7 +5390,6 @@ package android.app.admin { field public static final java.lang.String ACTION_PROFILE_PROVISIONING_COMPLETE = "android.app.action.ACTION_PROFILE_PROVISIONING_COMPLETE"; field public static final java.lang.String DEVICE_ADMIN_META_DATA = "android.app.device_admin"; field public static final java.lang.String EXTRA_DISABLE_WARNING = "android.app.extra.DISABLE_WARNING"; - field public static final java.lang.String EXTRA_LOCK_TASK_ENTERING = "android.app.extra.LOCK_TASK_ENTERING"; field public static final java.lang.String EXTRA_LOCK_TASK_PACKAGE = "android.app.extra.LOCK_TASK_PACKAGE"; } @@ -5457,7 +5458,7 @@ package android.app.admin { method public void setCrossProfileCallerIdDisabled(android.content.ComponentName, boolean); method public void setGlobalSetting(android.content.ComponentName, java.lang.String, java.lang.String); method public void setKeyguardDisabledFeatures(android.content.ComponentName, int); - method public void setLockTaskPackages(java.lang.String[]) throws java.lang.SecurityException; + method public void setLockTaskPackages(android.content.ComponentName, java.lang.String[]) throws java.lang.SecurityException; method public void setMasterVolumeMuted(android.content.ComponentName, boolean); method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int); method public void setMaximumTimeToLock(android.content.ComponentName, long); diff --git a/core/java/android/app/admin/DeviceAdminReceiver.java b/core/java/android/app/admin/DeviceAdminReceiver.java index 1f168c3..15def09 100644 --- a/core/java/android/app/admin/DeviceAdminReceiver.java +++ b/core/java/android/app/admin/DeviceAdminReceiver.java @@ -167,28 +167,30 @@ public class DeviceAdminReceiver extends BroadcastReceiver { /** * Action sent to a device administrator to notify that the device is entering - * or exiting lock task mode from an authorized package. The extra - * {@link #EXTRA_LOCK_TASK_ENTERING} will describe whether entering or exiting - * the mode. If entering, the extra {@link #EXTRA_LOCK_TASK_PACKAGE} will describe - * the authorized package using lock task mode. + * lock task mode from an authorized package. The extra {@link #EXTRA_LOCK_TASK_PACKAGE} + * will describe the authorized package using lock task mode. * - * @see DevicePolicyManager#isLockTaskPermitted + * @see DevicePolicyManager#isLockTaskPermitted(String) * * <p>The calling device admin must be the device owner or profile * owner to receive this broadcast. */ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) - public static final String ACTION_LOCK_TASK_CHANGED - = "android.app.action.ACTION_LOCK_TASK_CHANGED"; + public static final String ACTION_LOCK_TASK_ENTERING + = "android.app.action.ACTION_LOCK_TASK_ENTERING"; /** - * A boolean describing whether the device is currently entering or exiting - * lock task mode. + * Action sent to a device administrator to notify that the device is exiting + * lock task mode from an authorized package. * - * @see #ACTION_LOCK_TASK_CHANGED + * @see DevicePolicyManager#isLockTaskPermitted(String) + * + * <p>The calling device admin must be the device owner or profile + * owner to receive this broadcast. */ - public static final String EXTRA_LOCK_TASK_ENTERING = - "android.app.extra.LOCK_TASK_ENTERING"; + @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) + public static final String ACTION_LOCK_TASK_EXITING + = "android.app.action.ACTION_LOCK_TASK_EXITING"; /** * A boolean describing whether the device is currently entering or exiting @@ -380,16 +382,24 @@ public class DeviceAdminReceiver extends BroadcastReceiver { } /** - * Called when a device is entering or exiting lock task mode by a package - * authorized by {@link DevicePolicyManager#isLockTaskPermitted(String)} + * Called when a device is entering lock task mode by a package authorized + * by {@link DevicePolicyManager#isLockTaskPermitted(String)} * * @param context The running context as per {@link #onReceive}. * @param intent The received intent as per {@link #onReceive}. - * @param isEnteringLockTask Whether the device is entering or exiting lock task mode. * @param pkg If entering, the authorized package using lock task mode, otherwise null. */ - public void onLockTaskModeChanged(Context context, Intent intent, boolean isEnteringLockTask, - String pkg) { + public void onLockTaskModeEntering(Context context, Intent intent, String pkg) { + } + + /** + * Called when a device is exiting lock task mode by a package authorized + * by {@link DevicePolicyManager#isLockTaskPermitted(String)} + * + * @param context The running context as per {@link #onReceive}. + * @param intent The received intent as per {@link #onReceive}. + */ + public void onLockTaskModeExiting(Context context, Intent intent) { } /** @@ -421,10 +431,11 @@ public class DeviceAdminReceiver extends BroadcastReceiver { onPasswordExpiring(context, intent); } else if (ACTION_PROFILE_PROVISIONING_COMPLETE.equals(action)) { onProfileProvisioningComplete(context, intent); - } else if (ACTION_LOCK_TASK_CHANGED.equals(action)) { - boolean isEntering = intent.getBooleanExtra(EXTRA_LOCK_TASK_ENTERING, false); + } else if (ACTION_LOCK_TASK_ENTERING.equals(action)) { String pkg = intent.getStringExtra(EXTRA_LOCK_TASK_PACKAGE); - onLockTaskModeChanged(context, intent, isEntering, pkg); + onLockTaskModeEntering(context, intent, pkg); + } else if (ACTION_LOCK_TASK_EXITING.equals(action)) { + onLockTaskModeExiting(context, intent); } } } diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index 5350d70..f3f0c4d 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -2943,15 +2943,17 @@ public class DevicePolicyManager { * * This function can only be called by the device owner. * @param packages The list of packages allowed to enter lock task mode + * @param admin Which {@link DeviceAdminReceiver} this request is associated with. * * @see Activity#startLockTask() * @see DeviceAdminReceiver#onLockTaskModeChanged(Context, Intent, boolean, String) * @see UserManager#DISALLOW_CREATE_WINDOWS */ - public void setLockTaskPackages(String[] packages) throws SecurityException { + public void setLockTaskPackages(ComponentName admin, String[] packages) + throws SecurityException { if (mService != null) { try { - mService.setLockTaskPackages(packages); + mService.setLockTaskPackages(admin, packages); } catch (RemoteException e) { Log.w(TAG, "Failed talking with device policy service", e); } @@ -2960,12 +2962,14 @@ public class DevicePolicyManager { /** * This function returns the list of packages allowed to start the lock task mode. + * + * @param admin Which {@link DeviceAdminReceiver} this request is associated with. * @hide */ - public String[] getLockTaskPackages() { + public String[] getLockTaskPackages(ComponentName admin) { if (mService != null) { try { - return mService.getLockTaskPackages(); + return mService.getLockTaskPackages(admin); } catch (RemoteException e) { Log.w(TAG, "Failed talking with device policy service", e); } diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl index 8954c0d..324b963 100644 --- a/core/java/android/app/admin/IDevicePolicyManager.aidl +++ b/core/java/android/app/admin/IDevicePolicyManager.aidl @@ -153,8 +153,8 @@ interface IDevicePolicyManager { String[] getAccountTypesWithManagementDisabled(); String[] getAccountTypesWithManagementDisabledAsUser(int userId); - void setLockTaskPackages(in String[] packages); - String[] getLockTaskPackages(); + void setLockTaskPackages(in ComponentName who, in String[] packages); + String[] getLockTaskPackages(in ComponentName who); boolean isLockTaskPermitted(in String pkg); void setGlobalSetting(in ComponentName who, in String setting, in String value); diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index d46ae42..958cb6d 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -4442,44 +4442,39 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { * This function can only be called by the device owner. * @param components The list of components allowed to enter lock task mode. */ - public void setLockTaskPackages(String[] packages) throws SecurityException { - // Get the package names of the caller. - int uid = Binder.getCallingUid(); - String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid); - + public void setLockTaskPackages(ComponentName who, String[] packages) throws SecurityException { synchronized (this) { - // Check whether any of the package name is the device owner. - for (int i=0; i<packageNames.length; i++) { - String packageName = packageNames[i]; - int userHandle = UserHandle.getUserId(uid); - if (isDeviceOwner(packageName)) { - - // If a package name is the device owner, - // we update the component list. - DevicePolicyData policy = getUserData(userHandle); - policy.mLockTaskPackages.clear(); - if (packages != null) { - for (int j = 0; j < packages.length; j++) { - String pkg = packages[j]; - policy.mLockTaskPackages.add(pkg); - } - } + if (who == null) { + throw new NullPointerException("ComponentName is null"); + } + getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER); - // Store the settings persistently. - saveSettingsLocked(userHandle); - return; + int userHandle = Binder.getCallingUserHandle().getIdentifier(); + DevicePolicyData policy = getUserData(userHandle); + policy.mLockTaskPackages.clear(); + if (packages != null) { + for (int j = 0; j < packages.length; j++) { + String pkg = packages[j]; + policy.mLockTaskPackages.add(pkg); } } + + // Store the settings persistently. + saveSettingsLocked(userHandle); } - throw new SecurityException(); } /** * This function returns the list of components allowed to start the task lock mode. */ - public String[] getLockTaskPackages() { + public String[] getLockTaskPackages(ComponentName who) { synchronized (this) { - int userHandle = UserHandle.USER_OWNER; + if (who == null) { + throw new NullPointerException("ComponentName is null"); + } + getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER); + + int userHandle = Binder.getCallingUserHandle().getIdentifier(); DevicePolicyData policy = getUserData(userHandle); return policy.mLockTaskPackages.toArray(new String[0]); } @@ -4517,15 +4512,18 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { synchronized (this) { final DevicePolicyData policy = getUserData(userHandle); Bundle adminExtras = new Bundle(); - adminExtras.putBoolean(DeviceAdminReceiver.EXTRA_LOCK_TASK_ENTERING, isEnabled); adminExtras.putString(DeviceAdminReceiver.EXTRA_LOCK_TASK_PACKAGE, pkg); for (ActiveAdmin admin : policy.mAdminList) { boolean ownsDevice = isDeviceOwner(admin.info.getPackageName()); boolean ownsProfile = (getProfileOwner(userHandle) != null && getProfileOwner(userHandle).equals(admin.info.getPackageName())); if (ownsDevice || ownsProfile) { - sendAdminCommandLocked(admin, DeviceAdminReceiver.ACTION_LOCK_TASK_CHANGED, - adminExtras, null); + if (isEnabled) { + sendAdminCommandLocked(admin, DeviceAdminReceiver.ACTION_LOCK_TASK_ENTERING, + adminExtras, null); + } else { + sendAdminCommandLocked(admin, DeviceAdminReceiver.ACTION_LOCK_TASK_EXITING); + } } } } |