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

Commit da8d32ef authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "work_mode_api1"

* changes:
  Add access control to trySetWorkModeEnabled and make it public
  Merge setQuietModeEnabled and trySetQuietModeDisabled into one API
parents 247791f9 e3d1f65a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -32264,6 +32264,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 −2
Original line number Diff line number Diff line
@@ -79,9 +79,7 @@ interface IUserManager {
    void setDefaultGuestRestrictions(in Bundle restrictions);
    Bundle getDefaultGuestRestrictions();
    boolean markGuestForDeletion(int userHandle);
    void setQuietModeEnabled(int userHandle, boolean enableQuietMode, in IntentSender target);
    boolean isQuietModeEnabled(int userHandle);
    boolean trySetQuietModeDisabled(int userHandle, in IntentSender target);
    void setSeedAccountData(int userHandle, in String accountName,
            in String accountType, in PersistableBundle accountOptions, boolean persist);
    String getSeedAccountName();
@@ -99,4 +97,5 @@ interface IUserManager {
    boolean isUserRunning(int userId);
    boolean isUserNameSet(int userHandle);
    boolean hasRestrictedProfiles();
    boolean trySetQuietModeEnabled(String callingPackage, boolean enableQuietMode, int userHandle, in IntentSender target);
}
+36 −26
Original line number Diff line number Diff line
@@ -2130,15 +2130,46 @@ public class UserManager {
    }

    /**
     * Set quiet mode of a managed profile.
     * 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}.
     *
     * @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);
    }

    /**
     * Similar to {@link #trySetQuietModeEnabled(boolean, UserHandle)}, except you can specify
     * a target to start when user is unlocked.
     *
     * @param userHandle The user handle of the profile.
     * @param enableQuietMode Whether quiet mode should be enabled or disabled.
     * @see {@link #trySetQuietModeEnabled(boolean, UserHandle)}
     * @hide
     */
    public void setQuietModeEnabled(@UserIdInt int userHandle, boolean enableQuietMode) {
    public boolean trySetQuietModeEnabled(
            boolean enableQuietMode, @NonNull UserHandle userHandle, IntentSender target) {
        try {
            mService.setQuietModeEnabled(userHandle, enableQuietMode, null);
            return mService.trySetQuietModeEnabled(
                    mContext.getPackageName(), enableQuietMode, userHandle.getIdentifier(), target);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
@@ -2159,27 +2190,6 @@ public class UserManager {
        }
    }

    /**
     * Tries disabling quiet mode for a given user. If the user is still locked, we unlock the user
     * first by showing the confirm credentials screen and disable quiet mode upon successful
     * unlocking. If the user is already unlocked, we call through to {@link #setQuietModeEnabled}
     * directly.
     *
     * @param userHandle The user that is going to disable quiet mode.
     * @param target The target to launch when the user is unlocked.
     * @return {@code true} if quiet mode is disabled without showing confirm credentials screen,
     *         {@code false} otherwise.
     * @hide
     */
    public boolean trySetQuietModeDisabled(
            @UserIdInt int userHandle, @Nullable IntentSender target) {
        try {
            return mService.trySetQuietModeDisabled(userHandle, target);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * If the target user is a managed profile of the calling user or the caller
     * is itself a managed profile, then this returns a badged copy of the given
+1 −1
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ public class UnlaunchableAppActivity extends Activity
    @Override
    public void onClick(DialogInterface dialog, int which) {
        if (mReason == UNLAUNCHABLE_REASON_QUIET_MODE && which == DialogInterface.BUTTON_POSITIVE) {
            UserManager.get(this).trySetQuietModeDisabled(mUserId, mTarget);
            UserManager.get(this).trySetQuietModeEnabled(false, UserHandle.of(mUserId), mTarget);
        }
    }

Loading