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

Commit 313d4c5d authored by Evan Chen's avatar Evan Chen Committed by Mohammed Althaf T
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:872038799ed19500a09391cd2225d5b8fd2752a6
Merged-In: I41dc3804c35328a5968716f502c4320a58b75158
Change-Id: I41dc3804c35328a5968716f502c4320a58b75158
parent 3f23d6a3
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -261,6 +261,7 @@ public final class AssociationRequest implements Parcelable {
            @Nullable CharSequence displayName,
            boolean selfManaged,
            boolean forceConfirmation) {
        validateDisplayName(displayName);
        mSingleDevice = singleDevice;
        mDeviceFilters = requireNonNull(deviceFilters);
        mDeviceProfile = deviceProfile;
@@ -342,6 +343,7 @@ public final class AssociationRequest implements Parcelable {

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

@@ -421,10 +423,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;
        }
@@ -672,4 +671,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");
        }
    }
}