summaryrefslogtreecommitdiff
path: root/core/java/android/os/UserManager.java
diff options
context:
space:
mode:
authorTony Mak <tonymak@google.com>2017-12-05 19:40:28 +0000
committerTony Mak <tonymak@google.com>2017-12-15 16:27:48 +0000
commitb7e6fd49a5500c6182484335b03343bfdbd6b70b (patch)
tree289d7bcd136f8066dc4b53c3809083ba6c70a4eb /core/java/android/os/UserManager.java
parent5c9d80199e48322ab9939bc78d3ffeb224817a4c (diff)
Merge setQuietModeEnabled and trySetQuietModeDisabled into one API
This is the first step to introduce a public API to toggle work mode. All the callers actually have the similar bit of logic like this: if (workModeOn) { trySetQuietModeDisabled(..) } else { setQuietModeEnabled(...) } So, let's merge them into one API. 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 TODO: Allow foreground default Launcher to call the API TODO: Allow privileged apps to call the API TODO: Remove @hide TODO: Write a CTS to toggle the work mode once it is public API BUG: 70212757 Change-Id: Ibcdd43458c236eca929c5f934fea61be2e2be863
Diffstat (limited to 'core/java/android/os/UserManager.java')
-rw-r--r--core/java/android/os/UserManager.java48
1 files changed, 23 insertions, 25 deletions
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index fb60bbb483b1..2412009e9d98 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -2111,15 +2111,34 @@ public class UserManager {
}
/**
- * Set quiet mode of a managed profile.
+ * @see {@link #trySetQuietModeEnabled(boolean, UserHandle, IntentSender)}
*
+ * @hide
+ */
+ 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.
+ *
+ * @param enableQuietMode Whether work mode should be enabled or disabled.
* @param userHandle The user handle of the profile.
- * @param enableQuietMode Whether quiet mode should be enabled or disabled.
+ * @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.
* @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(
+ enableQuietMode, userHandle.getIdentifier(), target);
} catch (RemoteException re) {
throw re.rethrowFromSystemServer();
}
@@ -2141,27 +2160,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
* icon to be able to distinguish it from the original icon. For badging an