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

Commit de27b16b authored by Evan Chen's avatar Evan Chen Committed by Android Build Coastguard Worker
Browse files

Validate displayName for AssociationRequest

validate the length of displayName in the constructor, setDisplayName
and the builder

Test: cts
Flag: EXEMPT BUGFIX
Bug: 443742829
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:110f3e5843d87e4a994eb07160064ca3552355dd
Merged-In: I41dc3804c35328a5968716f502c4320a58b75158
Change-Id: I41dc3804c35328a5968716f502c4320a58b75158
parent 0f3e2487
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -311,6 +311,7 @@ public final class AssociationRequest implements Parcelable {
            boolean forceConfirmation,
            boolean skipRoleGrant,
            @Nullable Icon deviceIcon) {
        validateDisplayName(displayName);
        mSingleDevice = singleDevice;
        mDeviceFilters = requireNonNull(deviceFilters);
        mDeviceProfile = deviceProfile;
@@ -418,6 +419,7 @@ public final class AssociationRequest implements Parcelable {

    /** @hide */
    public void setDisplayName(CharSequence displayName) {
        validateDisplayName(displayName);
        mDisplayName = displayName;
    }

@@ -503,11 +505,7 @@ public final class AssociationRequest implements Parcelable {
        public Builder setDisplayName(@NonNull CharSequence displayName) {
            checkNotUsed();
            mDisplayName = requireNonNull(displayName);
            if (displayName.length() > DISPLAY_NAME_LENGTH_LIMIT) {
                throw new IllegalArgumentException("Length of the display name must be at most "
                        + DISPLAY_NAME_LENGTH_LIMIT + " characters");
            }

            validateDisplayName(displayName);
            return this;
        }

@@ -815,4 +813,11 @@ public final class AssociationRequest implements Parcelable {
            return new AssociationRequest(in);
        }
    };

    private static void validateDisplayName(@Nullable CharSequence displayName) {
        if (displayName != null && displayName.length() > DISPLAY_NAME_LENGTH_LIMIT) {
            throw new IllegalArgumentException("Length of the display name must be at most "
                    + DISPLAY_NAME_LENGTH_LIMIT + " characters");
        }
    }
}