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

Commit 4b7a914b authored by arangelov's avatar arangelov Committed by Antoan Angelov
Browse files

Add logic to support custom error messages from DPM APIs

Bug: 215105442
Test: atest ProvisioningExceptionTest
Change-Id: I3da36554c103cb41202ff19ee84711915a53a9c4
parent 910e11ac
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1283,6 +1283,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;
    }