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

Commit e72cdc5c 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:c27094d481e10d30585f5bbba95fd5188e1847f0
Merged-In: I41dc3804c35328a5968716f502c4320a58b75158
Change-Id: I41dc3804c35328a5968716f502c4320a58b75158
parent dc0e5049
Loading
Loading
Loading
Loading
+10 −5
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,11 +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 +670,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");
        }
    }
}