Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 95d9ad0f authored by Jason Monk's avatar Jason Monk Committed by Android (Google) Code Review
Browse files

Merge "Fixes to lock task API from API review" into lmp-dev

parents 9a888b9b 48aacba7
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -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);
+31 −20
Original line number Diff line number Diff line
@@ -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);
        }
    }
}
+8 −4
Original line number Diff line number Diff line
@@ -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);
            }
+2 −2
Original line number Diff line number Diff line
@@ -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);
+28 −30
Original line number Diff line number Diff line
@@ -4442,20 +4442,14 @@ 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 (who == null) {
                throw new NullPointerException("ComponentName is null");
            }
            getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);

                    // If a package name is the device owner,
                    // we update the component list.
            int userHandle = Binder.getCallingUserHandle().getIdentifier();
            DevicePolicyData policy = getUserData(userHandle);
            policy.mLockTaskPackages.clear();
            if (packages != null) {
@@ -4467,19 +4461,20 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {

            // Store the settings persistently.
            saveSettingsLocked(userHandle);
                    return;
                }
        }
    }
        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,
                    if (isEnabled) {
                        sendAdminCommandLocked(admin, DeviceAdminReceiver.ACTION_LOCK_TASK_ENTERING,
                                adminExtras, null);
                    } else {
                        sendAdminCommandLocked(admin, DeviceAdminReceiver.ACTION_LOCK_TASK_EXITING);
                    }
                }
            }
        }