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

Commit c8d19f18 authored by Alex Johnston's avatar Alex Johnston
Browse files

Split up DPM.createAndProvisionManagedProfile

Instead, have two APIs:
- DPM.createManagedProfile
- DPM.finalizeCreateManagedProfile

Moved account migration out of managed profile creation

Bug: 375382324
Test: atest CreateManagedProfileTest
Flag: android.app.admin.flags.split_create_managed_profile_enabled

Change-Id: Ia9c255d1ad7edb0715809ff3829a462e8e8ac5f7
parent 3c56396e
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -1336,8 +1336,10 @@ package android.app.admin {
  public class DevicePolicyManager {
    method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public int checkProvisioningPrecondition(@NonNull String, @NonNull String);
    method @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_POLICY_AUDIT_LOGGING) public void clearAuditLogEventCallback();
    method @Nullable @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public android.os.UserHandle createAndProvisionManagedProfile(@NonNull android.app.admin.ManagedProfileProvisioningParams) throws android.app.admin.ProvisioningException;
    method @Deprecated @FlaggedApi("android.app.admin.flags.split_create_managed_profile_enabled") @Nullable @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public android.os.UserHandle createAndProvisionManagedProfile(@NonNull android.app.admin.ManagedProfileProvisioningParams) throws android.app.admin.ProvisioningException;
    method @FlaggedApi("android.app.admin.flags.split_create_managed_profile_enabled") @Nullable @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public android.os.UserHandle createManagedProfile(@NonNull android.app.admin.ManagedProfileProvisioningParams) throws android.app.admin.ProvisioningException;
    method @Nullable public android.content.Intent createProvisioningIntentFromNfcIntent(@NonNull android.content.Intent);
    method @FlaggedApi("android.app.admin.flags.split_create_managed_profile_enabled") @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public void finalizeCreateManagedProfile(@NonNull android.app.admin.ManagedProfileProvisioningParams, @NonNull android.os.UserHandle) throws android.app.admin.ProvisioningException;
    method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public void finalizeWorkProfileProvisioning(@NonNull android.os.UserHandle, @Nullable android.accounts.Account);
    method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_DEVICE_POLICY_APP_EXEMPTIONS) public java.util.Set<java.lang.Integer> getApplicationExemptions(@NonNull String) throws android.content.pm.PackageManager.NameNotFoundException;
    method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) public boolean getBluetoothContactSharingDisabled(@NonNull android.os.UserHandle);
+67 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package android.app.admin;
import static android.app.admin.flags.Flags.FLAG_SPLIT_CREATE_MANAGED_PROFILE_ENABLED;
import static android.Manifest.permission.INTERACT_ACROSS_USERS;
import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
import static android.Manifest.permission.LOCK_DEVICE;
@@ -17142,11 +17143,14 @@ public class DevicePolicyManager {
     * @throws SecurityException if the caller does not hold
     * {@link android.Manifest.permission#MANAGE_PROFILE_AND_DEVICE_OWNERS}.
     * @throws ProvisioningException if an error occurred during provisioning.
     * @deprecated Use {@link #createManagedProfile} and {@link #finalizeCreateManagedProfile}
     * @hide
     */
    @Nullable
    @SystemApi
    @Deprecated
    @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS)
    @FlaggedApi(FLAG_SPLIT_CREATE_MANAGED_PROFILE_ENABLED)
    public UserHandle createAndProvisionManagedProfile(
            @NonNull ManagedProfileProvisioningParams provisioningParams)
            throws ProvisioningException {
@@ -17163,6 +17167,69 @@ public class DevicePolicyManager {
        }
    }
    /**
     * Creates a managed profile and sets the
     * {@link ManagedProfileProvisioningParams#getProfileAdminComponentName()} as the profile
     * owner. The method {@link #finalizeCreateManagedProfile} must be called after to finalize the
     * creation of the managed profile.
     *
     * <p>The method {@link #checkProvisioningPrecondition} must return {@link #STATUS_OK}
     * before calling this method. If it doesn't, a ProvisioningException will be thrown.
     *
     * @param provisioningParams Params required to provision a managed profile,
     * see {@link ManagedProfileProvisioningParams}.
     * @return The {@link UserHandle} of the created profile or {@code null} if the service is
     * not available.
     * @throws ProvisioningException if an error occurred during provisioning.
     * @hide
     */
    @Nullable
    @SystemApi
    @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS)
    @FlaggedApi(FLAG_SPLIT_CREATE_MANAGED_PROFILE_ENABLED)
    public UserHandle createManagedProfile(
            @NonNull ManagedProfileProvisioningParams provisioningParams)
            throws ProvisioningException {
        if (mService == null) {
            return null;
        }
        try {
            return mService.createManagedProfile(provisioningParams, mContext.getPackageName());
        } catch (ServiceSpecificException e) {
            throw new ProvisioningException(e, e.errorCode, getErrorMessage(e));
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
    /**
     * Finalizes the creation of a managed profile by informing the necessary components that
     * the managed profile is ready.
     *
     * @param provisioningParams Params required to provision a managed profile,
     * see {@link ManagedProfileProvisioningParams}.
     * @param managedProfileUser The recently created managed profile.
     * @throws ProvisioningException if an error occurred during provisioning.
     * @hide
     */
    @SuppressLint("UserHandle")
    @SystemApi
    @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS)
    @FlaggedApi(FLAG_SPLIT_CREATE_MANAGED_PROFILE_ENABLED)
    public void finalizeCreateManagedProfile(
            @NonNull ManagedProfileProvisioningParams provisioningParams,
            @NonNull UserHandle managedProfileUser)
            throws ProvisioningException {
        if (mService == null) {
            return;
        }
        try {
            mService.finalizeCreateManagedProfile(provisioningParams, managedProfileUser);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
    /**
     * Removes a manged profile from the device only when called from a managed profile's context
     *
+2 −0
Original line number Diff line number Diff line
@@ -569,6 +569,8 @@ interface IDevicePolicyManager {
    void setOrganizationIdForUser(in String callerPackage, in String enterpriseId, int userId);

    UserHandle createAndProvisionManagedProfile(in ManagedProfileProvisioningParams provisioningParams, in String callerPackage);
    UserHandle createManagedProfile(in ManagedProfileProvisioningParams provisioningParams, in String callerPackage);
    void finalizeCreateManagedProfile(in ManagedProfileProvisioningParams provisioningParams, in UserHandle managedProfileUser);
    void provisionFullyManagedDevice(in FullyManagedDeviceProvisioningParams provisioningParams, in String callerPackage);

    void finalizeWorkProfileProvisioning(in UserHandle managedProfileUser, in Account migratedAccount);
+256 −119

File changed.

Preview size limit exceeded, changes collapsed.