Introduce quiet mode state to managed profile users
Quiet mode means the user will be free from visual and audio interruptions
from apps inside the managed profile, including notifications, widgets and
others. This CL adds the underlying state bit to users and exposes various
APIs to control and query the quiet mode state.
Bug: 22541941
Change-Id: If5f8e5a897843050e83b6ec26cb39561098f12b9
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index b65d825..bc7620ce 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -2991,6 +2991,28 @@
"android.intent.action.MANAGED_PROFILE_REMOVED";
/**
+ * Broadcast sent to the primary user when an associated managed profile's availability has
+ * changed. This includes when the user toggles the profile's quiet mode, or when the profile
+ * owner suspends the profile. Carries an extra {@link #EXTRA_USER} that specifies the
+ * UserHandle of the profile. When quiet mode is changed, this broadcast will carry a boolean
+ * extra {@link #EXTRA_QUIET_MODE} indicating the new state of quiet mode. This is only sent to
+ * registered receivers, not manifest receivers.
+ */
+ public static final String ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED =
+ "android.intent.action.MANAGED_PROFILE_AVAILABILITY_CHANGED";
+
+ /**
+ * Broadcast sent to the managed profile when its availability has changed. This includes when
+ * the user toggles the profile's quiet mode, or when the profile owner suspends the profile.
+ * When quiet mode is changed, this broadcast will carry a boolean extra
+ * {@link #EXTRA_QUIET_MODE} indicating the new state of quiet mode. This is only sent to
+ * registered receivers, not manifest receivers. See also
+ * {@link #ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED}
+ */
+ public static final String ACTION_AVAILABILITY_CHANGED =
+ "android.intent.action.AVAILABILITY_CHANGED";
+
+ /**
* Sent when the user taps on the clock widget in the system's "quick settings" area.
*/
public static final String ACTION_QUICK_CLOCK =
@@ -4028,6 +4050,10 @@
/** {@hide} */
public static final String EXTRA_INDEX = "android.intent.extra.INDEX";
+ /**
+ * Optional boolean extra indicating whether quiet mode has been switched on or off.
+ */
+ public static final String EXTRA_QUIET_MODE = "android.intent.extra.QUIET_MODE";
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Intent flags (see mFlags variable).
diff --git a/core/java/android/content/pm/UserInfo.java b/core/java/android/content/pm/UserInfo.java
index d7c2215..6e09595 100644
--- a/core/java/android/content/pm/UserInfo.java
+++ b/core/java/android/content/pm/UserInfo.java
@@ -76,6 +76,7 @@
*/
public static final int FLAG_DISABLED = 0x00000040;
+ public static final int FLAG_QUIET_MODE = 0x00000080;
public static final int NO_PROFILE_GROUP_ID = UserHandle.USER_NULL;
@@ -130,6 +131,9 @@
return (flags & FLAG_DISABLED) != FLAG_DISABLED;
}
+ public boolean isQuietModeEnabled() {
+ return (flags & FLAG_QUIET_MODE) == FLAG_QUIET_MODE;
+ }
/**
* Returns true if the user is a split system user.
* <p>If {@link UserManager#isSplitSystemUser split system user mode} is not enabled,
diff --git a/core/java/android/os/IUserManager.aidl b/core/java/android/os/IUserManager.aidl
index c71d6cc..4af89c9 100644
--- a/core/java/android/os/IUserManager.aidl
+++ b/core/java/android/os/IUserManager.aidl
@@ -63,4 +63,6 @@
void setDefaultGuestRestrictions(in Bundle restrictions);
Bundle getDefaultGuestRestrictions();
boolean markGuestForDeletion(int userHandle);
+ void setQuietModeEnabled(int userHandle, boolean enableQuietMode);
+ boolean isQuietModeEnabled(int userHandle);
}
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index c2fc5e4..4781a6c 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -1246,6 +1246,36 @@
}
/**
+ * Set quiet mode of a managed profile.
+ *
+ * @param userHandle The user handle of the profile.
+ * @param enableQuietMode Whether quiet mode should be enabled or disabled.
+ * @hide
+ */
+ public void setQuietModeEnabled(int userHandle, boolean enableQuietMode) {
+ try {
+ mService.setQuietModeEnabled(userHandle, enableQuietMode);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Could not change the profile's quiet mode", e);
+ }
+ }
+
+ /**
+ * Returns whether the given profile is in quiet mode or not.
+ *
+ * @param userHandle The user handle of the profile to be queried.
+ * @return true if the profile is in quiet mode, false otherwise.
+ */
+ public boolean isQuietModeEnabled(UserHandle userHandle) {
+ try {
+ return mService.isQuietModeEnabled(userHandle.getIdentifier());
+ } catch (RemoteException e) {
+ Log.w(TAG, "Could not query the profile's quiet mode", e);
+ }
+ return false;
+ }
+
+ /**
* 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
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index ee493019..8f3822f 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -322,6 +322,9 @@
<protected-broadcast android:name="android.internal.policy.action.BURN_IN_PROTECTION" />
<protected-broadcast android:name="android.app.action.SYSTEM_UPDATE_POLICY_CHANGED" />
<protected-broadcast android:name="android.app.action.DEVICE_OWNER_CHANGED" />
+
+ <protected-broadcast android:name="android.intent.action.MANAGED_PROFILE_AVAILABILITY_CHANGED" />
+ <protected-broadcast android:name="android.intent.action.AVAILABILITY_CHANGED" />
<!-- ====================================================================== -->
<!-- RUNTIME PERMISSIONS -->
<!-- ====================================================================== -->