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

Commit d29b21b8 authored by Antoan Angelov's avatar Antoan Angelov Committed by Android (Google) Code Review
Browse files

Merge "Add logic to support custom error messages from DPM APIs"

parents a0846285 4b7a914b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1284,6 +1284,7 @@ package android.app.admin {
  public class ProvisioningException extends android.util.AndroidException {
    ctor public ProvisioningException(@NonNull Exception, int);
    ctor public ProvisioningException(@NonNull Exception, int, @Nullable String);
    method public int getProvisioningError();
    field public static final int ERROR_ADMIN_PACKAGE_INSTALLATION_FAILED = 3; // 0x3
    field public static final int ERROR_PRE_CONDITION_FAILED = 1; // 0x1
+11 −2
Original line number Diff line number Diff line
@@ -14588,12 +14588,21 @@ public class DevicePolicyManager {
            return mService.createAndProvisionManagedProfile(
                    provisioningParams, mContext.getPackageName());
        } catch (ServiceSpecificException e) {
            throw new ProvisioningException(e, e.errorCode);
            throw new ProvisioningException(e, e.errorCode, getErrorMessage(e));
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
    /**
     * The localized error message to show to the end-user. If {@code null}, a generic error
     * message will be shown.
     */
    private String getErrorMessage(ServiceSpecificException e) {
        return null;
    }
    /**
     * Provisions a managed device and sets the {@code deviceAdminComponentName} as the device
     * owner.
@@ -14619,7 +14628,7 @@ public class DevicePolicyManager {
            try {
                mService.provisionFullyManagedDevice(provisioningParams, mContext.getPackageName());
            } catch (ServiceSpecificException e) {
                throw new ProvisioningException(e, e.errorCode);
                throw new ProvisioningException(e, e.errorCode, getErrorMessage(e));
            } catch (RemoteException re) {
                throw re.rethrowFromSystemServer();
            }
+26 −1
Original line number Diff line number Diff line
@@ -15,8 +15,10 @@
 */

package android.app.admin;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.content.pm.PackageManager;
import android.util.AndroidException;
@@ -106,12 +108,35 @@ public class ProvisioningException extends AndroidException {

    private final @ProvisioningError int mProvisioningError;

    /**
     * Constructs a {@link ProvisioningException}.
     *
     * @param cause the cause
     * @param provisioningError the error code
     */
    public ProvisioningException(@NonNull Exception cause,
            @ProvisioningError int provisioningError) {
        super(cause);
        this(cause, provisioningError, /* errorMessage= */ null);
    }

    /**
     * Constructs a {@link ProvisioningException}.
     *
     * @param cause the cause
     * @param provisioningError the error code
     * @param errorMessage a {@code String} error message that give a more specific
     *                     description of the exception; can be {@code null}
     */
    public ProvisioningException(@NonNull Exception cause,
            @ProvisioningError int provisioningError,
            @Nullable String errorMessage) {
        super(errorMessage, cause);
        mProvisioningError = provisioningError;
    }

    /**
     * Returns the provisioning error specified at construction time.
     */
    public @ProvisioningError int getProvisioningError() {
        return mProvisioningError;
    }