Do not allow L2CAP specifier with ROLE_SERVER and remote address set

This is an invalid combination that never seems useful. Note that this
still allows ROLE_ANY in combination with a remote address. This still
doesn't seem particularly useful, but there is no good reason to
disallow it.

Test: TH
Change-Id: Ib0b7284cb99ee92f14113f8184af978eeb2318e7
This commit is contained in:
Patrick Rohr 2025-01-07 21:09:50 -08:00
commit 5e61925e51

View file

@ -240,7 +240,10 @@ public final class L2capNetworkSpecifier extends NetworkSpecifier implements Par
/** Create the L2capNetworkSpecifier object. */
@NonNull
public L2capNetworkSpecifier build() {
// TODO: throw an exception for combinations that cannot be supported.
if (mRole == ROLE_SERVER && mRemoteAddress != null) {
throw new IllegalArgumentException(
"Specifying a remote address is not valid for server role.");
}
return new L2capNetworkSpecifier(mRole, mHeaderCompression, mRemoteAddress, mPsm);
}
}