From 0884c553986c4ea13ef4e449c900bb1ca13160b6 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Tue, 17 Oct 2023 18:23:31 +0000 Subject: binderRpcTest: conditional experimental protocol Previously this test failed in REL mode and required a change. This was done so that we made sure to freeze it for release. Now that we have TARGET_RELEASE, we need to make this conditional. Bug: 305786304 Test: binderRpcTest on '-next' configuration Change-Id: I726c71399c7e469698abc630a006ce089dc4bca8 --- libs/binder/RpcState.cpp | 3 ++- libs/binder/tests/binderRpcTestCommon.h | 13 ++++++++++++- libs/binder/tests/binderRpcUniversalTests.cpp | 3 ++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/libs/binder/RpcState.cpp b/libs/binder/RpcState.cpp index bac2808b26..f9e833b126 100644 --- a/libs/binder/RpcState.cpp +++ b/libs/binder/RpcState.cpp @@ -409,10 +409,11 @@ bool RpcState::validateProtocolVersion(uint32_t version) { char codename[PROPERTY_VALUE_MAX]; property_get("ro.build.version.codename", codename, ""); if (!strcmp(codename, "REL")) { - ALOGE("Cannot use experimental RPC binder protocol on a release branch."); + ALOGE("Cannot use experimental RPC binder protocol in a release configuration."); return false; } #else + // TODO(b/305983144) // don't restrict on other platforms, though experimental should // only really be used for testing, we don't have a good way to see // what is shipping outside of Android diff --git a/libs/binder/tests/binderRpcTestCommon.h b/libs/binder/tests/binderRpcTestCommon.h index c1364dd9a0..eceff35e3e 100644 --- a/libs/binder/tests/binderRpcTestCommon.h +++ b/libs/binder/tests/binderRpcTestCommon.h @@ -70,12 +70,23 @@ static inline std::vector RpcSecurityValues() { return {RpcSecurity::RAW, RpcSecurity::TLS}; } +static inline bool hasExperimentalRpc() { +#ifdef __ANDROID__ + return base::GetProperty("ro.build.version.codename", "") != "REL"; +#else + // TODO(b/305983144): restrict on other platforms + return true; +#endif +} + static inline std::vector testVersions() { std::vector versions; for (size_t i = 0; i < RPC_WIRE_PROTOCOL_VERSION_NEXT; i++) { versions.push_back(i); } - versions.push_back(RPC_WIRE_PROTOCOL_VERSION_EXPERIMENTAL); + if (hasExperimentalRpc()) { + versions.push_back(RPC_WIRE_PROTOCOL_VERSION_EXPERIMENTAL); + } return versions; } diff --git a/libs/binder/tests/binderRpcUniversalTests.cpp b/libs/binder/tests/binderRpcUniversalTests.cpp index e43508ee79..885bb45d82 100644 --- a/libs/binder/tests/binderRpcUniversalTests.cpp +++ b/libs/binder/tests/binderRpcUniversalTests.cpp @@ -50,7 +50,8 @@ TEST(BinderRpc, CannotUseNextWireVersion) { TEST(BinderRpc, CanUseExperimentalWireVersion) { auto session = RpcSession::make(); - EXPECT_TRUE(session->setProtocolVersion(RPC_WIRE_PROTOCOL_VERSION_EXPERIMENTAL)); + EXPECT_EQ(hasExperimentalRpc(), + session->setProtocolVersion(RPC_WIRE_PROTOCOL_VERSION_EXPERIMENTAL)); } TEST_P(BinderRpc, Ping) { -- cgit v1.2.3-59-g8ed1b