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

Commit 97e42e27 authored by Felipe Leme's avatar Felipe Leme
Browse files

Disabled some password-related APIs on automotive.

The APIs are deprecated (in favor of setRequiredPasswordComplexity())
and some automotive OEMs might not even provide the option to
set passwords (just PINs and patterns).

Fixes: 204252236

Test: atest CtsDevicePolicyTestCases:android.devicepolicy.cts.DeprecatedPasswordAPIsTest # on automotive and phone

Change-Id: I6272bdd0e893f6fd8f1d126d384d1b332e61bac2
parent e9ca4099
Loading
Loading
Loading
Loading
+24 −7
Original line number Diff line number Diff line
@@ -3437,6 +3437,9 @@ public class DevicePolicyManager {
     * set on the primary {@link DevicePolicyManager} must be cleared first by calling
     * {@link #setRequiredPasswordComplexity} with {@link #PASSWORD_COMPLEXITY_NONE) first.
     *
     * <p><string>Note:</strong> this method is ignored on
     * {PackageManager#FEATURE_AUTOMOTIVE automotive builds}.
     *
     * @deprecated Prefer using {@link #setRequiredPasswordComplexity(int)}, to require a password
     * that satisfies a complexity level defined by the platform, rather than specifying custom
     * password requirement.
@@ -3527,12 +3530,14 @@ public class DevicePolicyManager {
     * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
     * not, a security exception will be thrown.
     * <p>
     *
     * Apps targeting {@link android.os.Build.VERSION_CODES#R} and below can call this method on the
     * {@link DevicePolicyManager} instance returned by
     * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
     * profile.
     *
     * <p><string>Note:</strong> this method is ignored on
     * {PackageManager#FEATURE_AUTOMOTIVE automotive builds}.
     *
     * @deprecated see {@link #setPasswordQuality(ComponentName, int)} for details.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
@@ -3610,12 +3615,14 @@ public class DevicePolicyManager {
     * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
     * not, a security exception will be thrown.
     * <p>
     *
     * Apps targeting {@link android.os.Build.VERSION_CODES#R} and below can call this method on the
     * {@link DevicePolicyManager} instance returned by
     * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
     * profile.
     *
     * <p><string>Note:</strong> this method is ignored on
     * {PackageManager#FEATURE_AUTOMOTIVE automotive builds}.
     *
     * @deprecated see {@link #setPasswordQuality(ComponentName, int)} for details.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
@@ -3700,12 +3707,14 @@ public class DevicePolicyManager {
     * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
     * not, a security exception will be thrown.
     * <p>
     *
     * Apps targeting {@link android.os.Build.VERSION_CODES#R} and below can call this method on the
     * {@link DevicePolicyManager} instance returned by
     * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
     * profile.
     *
     * <p><string>Note:</strong> this method is ignored on
     * {PackageManager#FEATURE_AUTOMOTIVE automotive builds}.
     *
     * @deprecated see {@link #setPasswordQuality(ComponentName, int)} for details.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
@@ -3790,12 +3799,14 @@ public class DevicePolicyManager {
     * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
     * not, a security exception will be thrown.
     * <p>
     *
     * Apps targeting {@link android.os.Build.VERSION_CODES#R} and below can call this method on the
     * {@link DevicePolicyManager} instance returned by
     * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
     * profile.
     *
     * <p><string>Note:</strong> this method is ignored on
     * {PackageManager#FEATURE_AUTOMOTIVE automotive builds}.
     *
     * @deprecated see {@link #setPasswordQuality(ComponentName, int)} for details.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
@@ -3879,12 +3890,14 @@ public class DevicePolicyManager {
     * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
     * not, a security exception will be thrown.
     * <p>
     *
     * Apps targeting {@link android.os.Build.VERSION_CODES#R} and below can call this method on the
     * {@link DevicePolicyManager} instance returned by
     * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
     * profile.
     *
     * <p><string>Note:</strong> this method is ignored on
     * {PackageManager#FEATURE_AUTOMOTIVE automotive builds}.
     *
     * @deprecated see {@link #setPasswordQuality(ComponentName, int)} for details.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
@@ -3968,12 +3981,14 @@ public class DevicePolicyManager {
     * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
     * not, a security exception will be thrown.
     * <p>
     *
     * Apps targeting {@link android.os.Build.VERSION_CODES#R} and below can call this method on the
     * {@link DevicePolicyManager} instance returned by
     * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
     * profile.
     *
     * <p><string>Note:</strong> this method is ignored on
     * {PackageManager#FEATURE_AUTOMOTIVE automotive builds}.
     *
     * @deprecated see {@link #setPasswordQuality(ComponentName, int)} for details.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
@@ -4056,12 +4071,14 @@ public class DevicePolicyManager {
     * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call this method; if it has
     * not, a security exception will be thrown.
     * <p>
     *
     * Apps targeting {@link android.os.Build.VERSION_CODES#R} and below can call this method on the
     * {@link DevicePolicyManager} instance returned by
     * {@link #getParentProfileInstance(ComponentName)} in order to set restrictions on the parent
     * profile.
     *
     * <p><string>Note:</strong> this method is ignored on
     * {PackageManager#FEATURE_AUTOMOTIVE automotive builds}.
     *
     * @deprecated see {@link #setPasswordQuality(ComponentName, int)} for details.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
+18 −7
Original line number Diff line number Diff line
@@ -3836,9 +3836,17 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        }
    }
    private boolean notSupportedOnAutomotive(String method) {
        if (mIsAutomotive) {
            Slogf.i(LOG_TAG, "%s is not supported on automotive builds", method);
            return true;
        }
        return false;
    }
    @Override
    public void setPasswordQuality(ComponentName who, int quality, boolean parent) {
        if (!mHasFeature) {
        if (!mHasFeature || notSupportedOnAutomotive("setPasswordQuality")) {
            return;
        }
        Objects.requireNonNull(who, "ComponentName is null");
@@ -4073,7 +4081,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    @Override
    public void setPasswordMinimumLength(ComponentName who, int length, boolean parent) {
        if (!mHasFeature) {
        if (!mHasFeature || notSupportedOnAutomotive("setPasswordMinimumLength")) {
            return;
        }
        Objects.requireNonNull(who, "ComponentName is null");
@@ -4355,7 +4363,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    @Override
    public void setPasswordMinimumUpperCase(ComponentName who, int length, boolean parent) {
        if (!mHasFeature) {
        if (!mHasFeature || notSupportedOnAutomotive("setPasswordMinimumUpperCase")) {
            return;
        }
        Objects.requireNonNull(who, "ComponentName is null");
@@ -4388,6 +4396,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    @Override
    public void setPasswordMinimumLowerCase(ComponentName who, int length, boolean parent) {
        if (notSupportedOnAutomotive("setPasswordMinimumLowerCase")) {
            return;
        }
        Objects.requireNonNull(who, "ComponentName is null");
        final int userId = mInjector.userHandleGetCallingUserId();
        synchronized (getLockObject()) {
@@ -4418,7 +4429,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    @Override
    public void setPasswordMinimumLetters(ComponentName who, int length, boolean parent) {
        if (!mHasFeature) {
        if (!mHasFeature || notSupportedOnAutomotive("setPasswordMinimumLetters")) {
            return;
        }
        Objects.requireNonNull(who, "ComponentName is null");
@@ -4450,7 +4461,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    @Override
    public void setPasswordMinimumNumeric(ComponentName who, int length, boolean parent) {
        if (!mHasFeature) {
        if (!mHasFeature || notSupportedOnAutomotive("setPasswordMinimumNumeric")) {
            return;
        }
        Objects.requireNonNull(who, "ComponentName is null");
@@ -4482,7 +4493,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    @Override
    public void setPasswordMinimumSymbols(ComponentName who, int length, boolean parent) {
        if (!mHasFeature) {
        if (!mHasFeature || notSupportedOnAutomotive("setPasswordMinimumSymbols")) {
            return;
        }
        Objects.requireNonNull(who, "ComponentName is null");
@@ -4514,7 +4525,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    @Override
    public void setPasswordMinimumNonLetter(ComponentName who, int length, boolean parent) {
        if (!mHasFeature) {
        if (!mHasFeature || notSupportedOnAutomotive("setPasswordMinimumNonLetter")) {
            return;
        }
        Objects.requireNonNull(who, "ComponentName is null");