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:
parent
7faa0b486c
commit
5e61925e51
2 changed files with 6 additions and 4 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import android.net.L2capNetworkSpecifier
|
|||
import android.net.L2capNetworkSpecifier.HEADER_COMPRESSION_6LOWPAN
|
||||
import android.net.L2capNetworkSpecifier.HEADER_COMPRESSION_NONE
|
||||
import android.net.L2capNetworkSpecifier.ROLE_CLIENT
|
||||
import android.net.L2capNetworkSpecifier.ROLE_SERVER
|
||||
import android.net.MacAddress
|
||||
import android.os.Build
|
||||
import com.android.testutils.ConnectivityModuleTest
|
||||
|
|
@ -51,12 +50,12 @@ class L2capNetworkSpecifierTest {
|
|||
fun testGetters() {
|
||||
val remoteMac = MacAddress.fromString("11:22:33:44:55:66")
|
||||
val specifier = L2capNetworkSpecifier.Builder()
|
||||
.setRole(ROLE_SERVER)
|
||||
.setRole(ROLE_CLIENT)
|
||||
.setHeaderCompression(HEADER_COMPRESSION_NONE)
|
||||
.setPsm(123)
|
||||
.setRemoteAddress(remoteMac)
|
||||
.build()
|
||||
assertEquals(ROLE_SERVER, specifier.getRole())
|
||||
assertEquals(ROLE_CLIENT, specifier.getRole())
|
||||
assertEquals(HEADER_COMPRESSION_NONE, specifier.getHeaderCompression())
|
||||
assertEquals(123, specifier.getPsm())
|
||||
assertEquals(remoteMac, specifier.getRemoteAddress())
|
||||
|
|
|
|||
Loading…
Reference in a new issue