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

Commit af309450 authored by Valentin Iftime's avatar Valentin Iftime
Browse files

Add start/stopProfile @SystemApi

 Add ActivityManager APIs to start/stop profiles.
 Add PROFILE_ACCESSIBLE and PROFILE_INACCESSIBLE broadcast intents.

Test: atest UserControllerTest
Bug: 159716781

Change-Id: I65b461f47f12a7a1bdce93bef5c2e09925c575ca
parent 281c2f5b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -10753,6 +10753,8 @@ package android.content {
    field public static final String ACTION_POWER_DISCONNECTED = "android.intent.action.ACTION_POWER_DISCONNECTED";
    field public static final String ACTION_POWER_USAGE_SUMMARY = "android.intent.action.POWER_USAGE_SUMMARY";
    field public static final String ACTION_PROCESS_TEXT = "android.intent.action.PROCESS_TEXT";
    field public static final String ACTION_PROFILE_ACCESSIBLE = "android.intent.action.PROFILE_ACCESSIBLE";
    field public static final String ACTION_PROFILE_INACCESSIBLE = "android.intent.action.PROFILE_INACCESSIBLE";
    field public static final String ACTION_PROVIDER_CHANGED = "android.intent.action.PROVIDER_CHANGED";
    field public static final String ACTION_QUICK_CLOCK = "android.intent.action.QUICK_CLOCK";
    field public static final String ACTION_QUICK_VIEW = "android.intent.action.QUICK_VIEW";
+2 −0
Original line number Diff line number Diff line
@@ -366,6 +366,8 @@ package android.app {
    method @RequiresPermission(android.Manifest.permission.PACKAGE_USAGE_STATS) public void removeOnUidImportanceListener(android.app.ActivityManager.OnUidImportanceListener);
    method public void setDeviceLocales(@NonNull android.os.LocaleList);
    method @RequiresPermission(android.Manifest.permission.RESTRICTED_VR_ACCESS) public static void setPersistentVrThread(int);
    method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}) public boolean startProfile(@NonNull android.os.UserHandle);
    method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}) public boolean stopProfile(@NonNull android.os.UserHandle);
    method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public boolean switchUser(@NonNull android.os.UserHandle);
  }
+46 −0
Original line number Diff line number Diff line
@@ -3891,6 +3891,52 @@ public class ActivityManager {
        return switchUser(user.getIdentifier());
    }

    /**
     * Starts a profile.
     * To be used with non-managed profiles, managed profiles should use
     * {@link UserManager#requestQuietModeEnabled}
     *
     * @param userHandle user handle of the profile.
     * @return true if the profile has been successfully started or if the profile is already
     * running, false if profile failed to start.
     * @throws IllegalArgumentException if {@code userHandle} is not a profile.
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS,
            android.Manifest.permission.INTERACT_ACROSS_USERS_FULL})
    public boolean startProfile(@NonNull UserHandle userHandle) {
        try {
            return getService().startProfile(userHandle.getIdentifier());
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Stops a running profile.
     * To be used with non-managed profiles, managed profiles should use
     * {@link UserManager#requestQuietModeEnabled}
     *
     * @param userHandle user handle of the profile.
     * @return true if the profile has been successfully stopped or is already stopped. Otherwise
     * the exceptions listed below are thrown.
     * @throws IllegalArgumentException if {@code userHandle} is not a profile.
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS,
            android.Manifest.permission.INTERACT_ACROSS_USERS_FULL})
    public boolean stopProfile(@NonNull UserHandle userHandle) {
        try {
            return getService().stopProfile(userHandle.getIdentifier());
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
    }

    /**
     * Updates the MCC (Mobile Country Code) and MNC (Mobile Network Code) in the
     * system configuration.
+18 −0
Original line number Diff line number Diff line
@@ -687,4 +687,22 @@ interface IActivityManager {
     * {@link android.content.pm.PackageManager#getHoldLockToken()}.
     */
    void holdLock(in IBinder token, in int durationMs);

    /**
     * Starts a profile.
     * @param userId the user id of the profile.
     * @return true if the profile has been successfully started or if the profile is already
     * running, false if profile failed to start.
     * @throws IllegalArgumentException if the user is not a profile.
     */
    boolean startProfile(int userId);

    /**
     * Stops a profile.
     * @param userId the user id of the profile.
     * @return true if the profile has been successfully stopped or is already stopped. Otherwise
     * the exceptions listed below are thrown.
     * @throws IllegalArgumentException if the user is not a profile.
     */
    boolean stopProfile(int userId);
}
+20 −4
Original line number Diff line number Diff line
@@ -3649,7 +3649,7 @@ public class Intent implements Parcelable, Cloneable {

    /**
     * Broadcast sent by the system when a user is started. Carries an extra
     * EXTRA_USER_HANDLE that has the userHandle of the user.  This is only sent to
     * {@link EXTRA_USER_HANDLE} that has the userHandle of the user.  This is only sent to
     * registered receivers, not manifest receivers.  It is sent to the user
     * that has been started.  This is sent as a foreground
     * broadcast, since it is part of a visible user interaction; be as quick
@@ -3661,7 +3661,7 @@ public class Intent implements Parcelable, Cloneable {

    /**
     * Broadcast sent when a user is in the process of starting.  Carries an extra
     * EXTRA_USER_HANDLE that has the userHandle of the user.  This is only
     * {@link EXTRA_USER_HANDLE} that has the userHandle of the user.  This is only
     * sent to registered receivers, not manifest receivers.  It is sent to all
     * users (including the one that is being started).  You must hold
     * {@link android.Manifest.permission#INTERACT_ACROSS_USERS} to receive
@@ -3678,7 +3678,7 @@ public class Intent implements Parcelable, Cloneable {

    /**
     * Broadcast sent when a user is going to be stopped.  Carries an extra
     * EXTRA_USER_HANDLE that has the userHandle of the user.  This is only
     * {@link EXTRA_USER_HANDLE} that has the userHandle of the user.  This is only
     * sent to registered receivers, not manifest receivers.  It is sent to all
     * users (including the one that is being stopped).  You must hold
     * {@link android.Manifest.permission#INTERACT_ACROSS_USERS} to receive
@@ -3696,7 +3696,7 @@ public class Intent implements Parcelable, Cloneable {

    /**
     * Broadcast sent to the system when a user is stopped. Carries an extra
     * EXTRA_USER_HANDLE that has the userHandle of the user.  This is similar to
     * {@link EXTRA_USER_HANDLE} that has the userHandle of the user.  This is similar to
     * {@link #ACTION_PACKAGE_RESTARTED}, but for an entire user instead of a
     * specific package.  This is only sent to registered receivers, not manifest
     * receivers.  It is sent to all running users <em>except</em> the one that
@@ -3799,6 +3799,22 @@ public class Intent implements Parcelable, Cloneable {
    public static final String ACTION_MANAGED_PROFILE_UNAVAILABLE =
            "android.intent.action.MANAGED_PROFILE_UNAVAILABLE";

    /**
     * Broadcast sent to the parent user when an associated profile has been started and unlocked.
     * Carries an extra {@link #EXTRA_USER} that specifies the {@link UserHandle} of the profile.
     * This is only sent to registered receivers, not manifest receivers.
     */
    public static final String ACTION_PROFILE_ACCESSIBLE =
            "android.intent.action.PROFILE_ACCESSIBLE";

    /**
     * Broadcast sent to the parent user when an associated profile has stopped.
     * Carries an extra {@link #EXTRA_USER} that specifies the {@link UserHandle} of the profile.
     * This is only sent to registered receivers, not manifest receivers.
     */
    public static final String ACTION_PROFILE_INACCESSIBLE =
            "android.intent.action.PROFILE_INACCESSIBLE";

    /**
     * Broadcast sent to the system user when the 'device locked' state changes for any user.
     * Carries an extra {@link #EXTRA_USER_HANDLE} that specifies the ID of the user for which
Loading