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

Commit e3d1f65a authored by Tony Mak's avatar Tony Mak
Browse files

Add access control to trySetWorkModeEnabled and make it public

Test: Quick Settings -> Toggle work mode
Test: Settings -> Work profile settings -> Toggle work mode
Test: Turn off work mode -> Settings -> Turn on work mode in the suggestion
Test: Turn on work mode through tapping on work app

Test: cts-tradefed run cts-dev --module DevicePolicyManager --test com.android.cts.devicepolicy.QuietModeHostsideTest

BUG: 70212757

Change-Id: I335c3ab2306a3eb794cd35a3a7b0d184dc31f85e
parent b7e6fd49
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -32086,6 +32086,7 @@ package android.os {
    method public deprecated void setUserRestrictions(android.os.Bundle);
    method public deprecated void setUserRestrictions(android.os.Bundle, android.os.UserHandle);
    method public static boolean supportsMultipleUsers();
    method public boolean trySetQuietModeEnabled(boolean, android.os.UserHandle);
    field public static final java.lang.String ALLOW_PARENT_PROFILE_APP_LINKING = "allow_parent_profile_app_linking";
    field public static final java.lang.String DISALLOW_ADD_MANAGED_PROFILE = "no_add_managed_profile";
    field public static final java.lang.String DISALLOW_ADD_USER = "no_add_user";
+1 −0
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ package android {
    field public static final deprecated java.lang.String MODIFY_NETWORK_ACCOUNTING = "android.permission.MODIFY_NETWORK_ACCOUNTING";
    field public static final java.lang.String MODIFY_PARENTAL_CONTROLS = "android.permission.MODIFY_PARENTAL_CONTROLS";
    field public static final java.lang.String MODIFY_PHONE_STATE = "android.permission.MODIFY_PHONE_STATE";
    field public static final java.lang.String MODIFY_QUIET_MODE = "android.permission.MODIFY_QUIET_MODE";
    field public static final java.lang.String MOUNT_FORMAT_FILESYSTEMS = "android.permission.MOUNT_FORMAT_FILESYSTEMS";
    field public static final java.lang.String MOUNT_UNMOUNT_FILESYSTEMS = "android.permission.MOUNT_UNMOUNT_FILESYSTEMS";
    field public static final java.lang.String MOVE_PACKAGE = "android.permission.MOVE_PACKAGE";
+1 −1
Original line number Diff line number Diff line
@@ -97,5 +97,5 @@ interface IUserManager {
    boolean isUserRunning(int userId);
    boolean isUserNameSet(int userHandle);
    boolean hasRestrictedProfiles();
    boolean trySetQuietModeEnabled(boolean enableQuietMode, int userHandle, in IntentSender target);
    boolean trySetQuietModeEnabled(String callingPackage, boolean enableQuietMode, int userHandle, in IntentSender target);
}
+26 −14
Original line number Diff line number Diff line
@@ -2111,34 +2111,46 @@ public class UserManager {
    }

    /**
     * @see {@link #trySetQuietModeEnabled(boolean, UserHandle, IntentSender)}
     * Enables or disables quiet mode for a managed profile. If quiet mode is enabled, apps in a
     * managed profile don't run, generate notifications, or consume data or battery.
     * <p>
     * If a user's credential is needed to turn off quiet mode, a confirm credential screen will be
     * shown to the user.
     * <p>
     * The change may not happen instantly, however apps can listen for
     * {@link Intent#ACTION_MANAGED_PROFILE_AVAILABLE} and
     * {@link Intent#ACTION_MANAGED_PROFILE_UNAVAILABLE} broadcasts in order to be notified of
     * the change of the quiet mode. Apps can also check the current state of quiet mode by
     * calling {@link #isQuietModeEnabled(UserHandle)}.
     * <p>
     * The caller must either be the foreground default launcher or have one of these permissions:
     * {@code MANAGE_USERS} or {@code MODIFY_QUIET_MODE}.
     *
     * @hide
     * @param enableQuietMode whether quiet mode should be enabled or disabled
     * @param userHandle user handle of the profile
     * @return {@code false} if user's credential is needed in order to turn off quiet mode,
     *         {@code true} otherwise
     * @throws SecurityException if the caller is invalid
     * @throws IllegalArgumentException if {@code userHandle} is not a managed profile
     *
     * @see #isQuietModeEnabled(UserHandle)
     */
    public boolean trySetQuietModeEnabled(boolean enableQuietMode, @NonNull UserHandle userHandle) {
        return trySetQuietModeEnabled(enableQuietMode, userHandle, null);
    }

    /**
     * Set quiet mode of a managed profile. If quiet mode is on, work apps don't run, generate
     * notifications, or consume data or the battery. You also can’t access work apps or widgets.
     * <p>
     * If user credential is needed, confirm credential screen would be shown to user.
     * Similar to {@link #trySetQuietModeEnabled(boolean, UserHandle)}, except you can specify
     * a target to start when user is unlocked.
     *
     * @param enableQuietMode Whether work mode should be enabled or disabled.
     * @param userHandle The user handle of the profile.
     * @param target The target to start once work mode is enabled.
     * @return {@code false} confirm credential screen is shown in order turn off quiet mode,
     *         {@code true} otherwise.
     * @throws IllegalArgumentException if enableWorkMode is {@code false} while target is not null.
     * @throws IllegalArgumentException if userHandle is not a managed profile.
     * @see {@link #trySetQuietModeEnabled(boolean, UserHandle)}
     * @hide
     */
    public boolean trySetQuietModeEnabled(
            boolean enableQuietMode, @NonNull UserHandle userHandle, IntentSender target) {
        try {
            return mService.trySetQuietModeEnabled(
                    enableQuietMode, userHandle.getIdentifier(), target);
                    mContext.getPackageName(), enableQuietMode, userHandle.getIdentifier(), target);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
+5 −0
Original line number Diff line number Diff line
@@ -3627,6 +3627,11 @@
    <permission android:name="android.permission.READ_RUNTIME_PROFILES"
                android:protectionLevel="signature|privileged" />

    <!-- @SystemApi Allows an application to turn on / off quiet mode.
         @hide <p>Not for use by third-party applications. -->
    <permission android:name="android.permission.MODIFY_QUIET_MODE"
                android:protectionLevel="signature|privileged" />

    <application android:process="system"
                 android:persistent="true"
                 android:hasCode="false"
Loading