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

Commit 746e1341 authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Add API to limit maximum time the profile can be turned off.

If this policy is set:
* Whenever work profile gets turned off or system boots, timer is
  started, so theat unless the profile is unlocked in time, apps
  will be suspended.
* when the user is unlocked, alarm is discharged.

Currently there is no upfront warning notification, will be addressed
in a follow-up.

Bug: 143517719
Test: manual, using TestDPC
Change-Id: Ib0f936b6d1414f65ae8c86367b7059c14862827d
parent 03e931d3
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -6827,6 +6827,7 @@ package android.app.admin {
    method public int getLockTaskFeatures(@NonNull android.content.ComponentName);
    method public int getLockTaskFeatures(@NonNull android.content.ComponentName);
    method @NonNull public String[] getLockTaskPackages(@NonNull android.content.ComponentName);
    method @NonNull public String[] getLockTaskPackages(@NonNull android.content.ComponentName);
    method @Nullable public CharSequence getLongSupportMessage(@NonNull android.content.ComponentName);
    method @Nullable public CharSequence getLongSupportMessage(@NonNull android.content.ComponentName);
    method public long getManagedProfileMaximumTimeOff(@NonNull android.content.ComponentName);
    method public int getMaximumFailedPasswordsForWipe(@Nullable android.content.ComponentName);
    method public int getMaximumFailedPasswordsForWipe(@Nullable android.content.ComponentName);
    method public long getMaximumTimeToLock(@Nullable android.content.ComponentName);
    method public long getMaximumTimeToLock(@Nullable android.content.ComponentName);
    method @NonNull public java.util.List<java.lang.String> getMeteredDataDisabledPackages(@NonNull android.content.ComponentName);
    method @NonNull public java.util.List<java.lang.String> getMeteredDataDisabledPackages(@NonNull android.content.ComponentName);
@@ -6956,6 +6957,7 @@ package android.app.admin {
    method public void setLockdownAdminConfiguredNetworks(@NonNull android.content.ComponentName, boolean);
    method public void setLockdownAdminConfiguredNetworks(@NonNull android.content.ComponentName, boolean);
    method public void setLogoutEnabled(@NonNull android.content.ComponentName, boolean);
    method public void setLogoutEnabled(@NonNull android.content.ComponentName, boolean);
    method public void setLongSupportMessage(@NonNull android.content.ComponentName, @Nullable CharSequence);
    method public void setLongSupportMessage(@NonNull android.content.ComponentName, @Nullable CharSequence);
    method public void setManagedProfileMaximumTimeOff(@NonNull android.content.ComponentName, long);
    method public void setMasterVolumeMuted(@NonNull android.content.ComponentName, boolean);
    method public void setMasterVolumeMuted(@NonNull android.content.ComponentName, boolean);
    method public void setMaximumFailedPasswordsForWipe(@NonNull android.content.ComponentName, int);
    method public void setMaximumFailedPasswordsForWipe(@NonNull android.content.ComponentName, int);
    method public void setMaximumTimeToLock(@NonNull android.content.ComponentName, long);
    method public void setMaximumTimeToLock(@NonNull android.content.ComponentName, long);
@@ -7142,6 +7144,7 @@ package android.app.admin {
    field public static final int PERMISSION_POLICY_PROMPT = 0; // 0x0
    field public static final int PERMISSION_POLICY_PROMPT = 0; // 0x0
    field public static final int PERSONAL_APPS_NOT_SUSPENDED = 0; // 0x0
    field public static final int PERSONAL_APPS_NOT_SUSPENDED = 0; // 0x0
    field public static final int PERSONAL_APPS_SUSPENDED_EXPLICITLY = 1; // 0x1
    field public static final int PERSONAL_APPS_SUSPENDED_EXPLICITLY = 1; // 0x1
    field public static final int PERSONAL_APPS_SUSPENDED_PROFILE_TIMEOUT = 2; // 0x2
    field public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera";
    field public static final String POLICY_DISABLE_CAMERA = "policy_disable_camera";
    field public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture";
    field public static final String POLICY_DISABLE_SCREEN_CAPTURE = "policy_disable_screen_capture";
    field public static final int PRIVATE_DNS_MODE_OFF = 1; // 0x1
    field public static final int PRIVATE_DNS_MODE_OFF = 1; // 0x1
+59 −1
Original line number Original line Diff line number Diff line
@@ -2402,12 +2402,20 @@ public class DevicePolicyManager {
     */
     */
    public static final int PERSONAL_APPS_SUSPENDED_EXPLICITLY = 1 << 0;
    public static final int PERSONAL_APPS_SUSPENDED_EXPLICITLY = 1 << 0;
    /**
     * Flag for {@link #getPersonalAppsSuspendedReasons} return value. Set when personal apps are
     * suspended by framework because managed profile was off for longer than allowed by policy.
     * @see #setManagedProfileMaximumTimeOff
     */
    public static final int PERSONAL_APPS_SUSPENDED_PROFILE_TIMEOUT = 1 << 1;
    /**
    /**
     * @hide
     * @hide
     */
     */
    @IntDef(flag = true, prefix = { "PERSONAL_APPS_" }, value = {
    @IntDef(flag = true, prefix = { "PERSONAL_APPS_" }, value = {
            PERSONAL_APPS_NOT_SUSPENDED,
            PERSONAL_APPS_NOT_SUSPENDED,
            PERSONAL_APPS_SUSPENDED_EXPLICITLY
            PERSONAL_APPS_SUSPENDED_EXPLICITLY,
            PERSONAL_APPS_SUSPENDED_PROFILE_TIMEOUT
    })
    })
    @Retention(RetentionPolicy.SOURCE)
    @Retention(RetentionPolicy.SOURCE)
    public @interface PersonalAppSuspensionReason {}
    public @interface PersonalAppSuspensionReason {}
@@ -11742,6 +11750,8 @@ public class DevicePolicyManager {
     *
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with
     * @param suspended Whether personal apps should be suspended.
     * @param suspended Whether personal apps should be suspended.
     * @throws IllegalStateException if the profile owner doesn't have an activity that handles
     *        {@link #ACTION_CHECK_POLICY_COMPLIANCE}
     */
     */
    public void setPersonalAppsSuspended(@NonNull ComponentName admin, boolean suspended) {
    public void setPersonalAppsSuspended(@NonNull ComponentName admin, boolean suspended) {
        throwIfParentInstance("setPersonalAppsSuspended");
        throwIfParentInstance("setPersonalAppsSuspended");
@@ -11753,4 +11763,52 @@ public class DevicePolicyManager {
            }
            }
        }
        }
    }
    }
    /**
     * Called by a profile owner of an organization-owned managed profile to set maximum time
     * the profile is allowed to be turned off. If the profile is turned off for longer, personal
     * apps are suspended on the device.
     *
     * <p>When personal apps are suspended, an ongoing notification about that is shown to the user.
     * When the user taps the notification, system invokes {@link #ACTION_CHECK_POLICY_COMPLIANCE}
     * in the profile owner package. Profile owner implementation that uses personal apps suspension
     * must handle this intent.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with
     * @param timeoutMs Maximum time the profile is allowed to be off in milliseconds or 0 if
     *        not limited.
     * @throws IllegalStateException if the profile owner doesn't have an activity that handles
     *        {@link #ACTION_CHECK_POLICY_COMPLIANCE}
     * @see #setPersonalAppsSuspended
     */
    public void setManagedProfileMaximumTimeOff(@NonNull ComponentName admin, long timeoutMs) {
        throwIfParentInstance("setManagedProfileMaximumTimeOff");
        if (mService != null) {
            try {
                mService.setManagedProfileMaximumTimeOff(admin, timeoutMs);
            } catch (RemoteException re) {
                throw re.rethrowFromSystemServer();
            }
        }
    }
     /**
     * Called by a profile owner of an organization-owned managed profile to get maximum time
     * the profile is allowed to be turned off.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with
     * @return Maximum time the profile is allowed to be off in milliseconds or 0 if not limited.
     * @see #setPersonalAppsSuspended
     */
    public long getManagedProfileMaximumTimeOff(@NonNull ComponentName admin) {
        throwIfParentInstance("getManagedProfileMaximumTimeOff");
        if (mService != null) {
            try {
                return mService.getManagedProfileMaximumTimeOff(admin);
            } catch (RemoteException re) {
                throw re.rethrowFromSystemServer();
            }
        }
        return 0;
    }
}
}
+3 −0
Original line number Original line Diff line number Diff line
@@ -473,4 +473,7 @@ interface IDevicePolicyManager {


    int getPersonalAppsSuspendedReasons(in ComponentName admin);
    int getPersonalAppsSuspendedReasons(in ComponentName admin);
    void setPersonalAppsSuspended(in ComponentName admin, boolean suspended);
    void setPersonalAppsSuspended(in ComponentName admin, boolean suspended);

    long getManagedProfileMaximumTimeOff(in ComponentName admin);
    void setManagedProfileMaximumTimeOff(in ComponentName admin, long timeoutMs);
}
}
+7 −0
Original line number Original line Diff line number Diff line
@@ -75,4 +75,11 @@ abstract class BaseIDevicePolicyManager extends IDevicePolicyManager.Stub {


    public void setPersonalAppsSuspended(ComponentName admin, boolean suspended) {
    public void setPersonalAppsSuspended(ComponentName admin, boolean suspended) {
    }
    }

    public void setManagedProfileMaximumTimeOff(ComponentName admin, long timeoutMs) {
    }

    public long getManagedProfileMaximumTimeOff(ComponentName admin) {
        return 0;
    }
}
}
+226 −76

File changed.

Preview size limit exceeded, changes collapsed.