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

Commit 2e1db134 authored by Evan Chen's avatar Evan Chen Committed by Nishith Khanna
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:c27094d481e10d30585f5bbba95fd5188e1847f0
Merged-In: I41dc3804c35328a5968716f502c4320a58b75158
Change-Id: I41dc3804c35328a5968716f502c4320a58b75158
parent 3d38374b
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -271,6 +271,7 @@ public final class AssociationRequest implements Parcelable {
            boolean selfManaged,
            boolean forceConfirmation,
            @Nullable Icon deviceIcon) {
        validateDisplayName(displayName);
        mSingleDevice = singleDevice;
        mDeviceFilters = requireNonNull(deviceFilters);
        mDeviceProfile = deviceProfile;
@@ -365,6 +366,7 @@ public final class AssociationRequest implements Parcelable {

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

@@ -445,11 +447,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;
        }

@@ -728,4 +726,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");
        }
    }
}