summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKalesh Singh <kaleshsingh@google.com>2021-04-05 22:27:17 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-04-05 22:27:17 +0000
commit9c9ce1ee567e00191146ff8a9a3d32483a31c7d8 (patch)
tree9169b800b380636b50a89b776d6389c840674d55
parent9e8ee9bd4fa48255553e757b3903baf9af8f056f (diff)
parent3b9ac062d22c241fa3b09533488a2fba91c3a283 (diff)
downloadnative-9c9ce1ee567e00191146ff8a9a3d32483a31c7d8.tar.gz
Merge "Add force downgrade to vendor stability test"
-rw-r--r--libs/binder/include/binder/Stability.h6
-rw-r--r--libs/binder/tests/binderStabilityTest.cpp31
2 files changed, 32 insertions, 5 deletions
diff --git a/libs/binder/include/binder/Stability.h b/libs/binder/include/binder/Stability.h
index 1831ffcf75..f4bfac890a 100644
--- a/libs/binder/include/binder/Stability.h
+++ b/libs/binder/include/binder/Stability.h
@@ -57,6 +57,9 @@ public:
// can be called to use that same interface within the local partition.
static void forceDowngradeToLocalStability(const sp<IBinder>& binder);
+ // WARNING: Below APIs are only ever expected to be called by auto-generated code.
+ // Instead of calling them, you should set the stability of a .aidl interface
+
// WARNING: The only client of
// - forceDowngradeToSystemStability() and;
// - korceDowngradeToVendorStability()
@@ -82,9 +85,6 @@ public:
// can be called to use that same interface within the system partition.
static void forceDowngradeToSystemStability(const sp<IBinder>& binder);
- // WARNING: Below APIs are only ever expected to be called by auto-generated code.
- // Instead of calling them, you should set the stability of a .aidl interface
-
// WARNING: This is only ever expected to be called by auto-generated code. You likely want to
// change or modify the stability class of the interface you are using.
// This must be called as soon as the binder in question is constructed. No thread safety
diff --git a/libs/binder/tests/binderStabilityTest.cpp b/libs/binder/tests/binderStabilityTest.cpp
index dbd3f4ef1f..cb309bdd81 100644
--- a/libs/binder/tests/binderStabilityTest.cpp
+++ b/libs/binder/tests/binderStabilityTest.cpp
@@ -132,7 +132,7 @@ TEST(BinderStability, OnlyVintfStabilityBinderNeedsVintfDeclaration) {
EXPECT_TRUE(Stability::requiresVintfDeclaration(BadStableBinder::vintf()));
}
-TEST(BinderStability, ForceDowngradeStability) {
+TEST(BinderStability, ForceDowngradeToLocalStability) {
sp<IBinder> someBinder = BadStableBinder::vintf();
EXPECT_TRUE(Stability::requiresVintfDeclaration(someBinder));
@@ -143,7 +143,7 @@ TEST(BinderStability, ForceDowngradeStability) {
EXPECT_FALSE(Stability::requiresVintfDeclaration(someBinder));
}
-TEST(BinderStability, NdkForceDowngradeStability) {
+TEST(BinderStability, NdkForceDowngradeToLocalStability) {
sp<IBinder> someBinder = BadStableBinder::vintf();
EXPECT_TRUE(Stability::requiresVintfDeclaration(someBinder));
@@ -154,6 +154,33 @@ TEST(BinderStability, NdkForceDowngradeStability) {
EXPECT_FALSE(Stability::requiresVintfDeclaration(someBinder));
}
+TEST(BinderStability, ForceDowngradeToVendorStability) {
+ sp<IBinder> serverBinder = android::defaultServiceManager()->getService(kSystemStabilityServer);
+ auto server = interface_cast<IBinderStabilityTest>(serverBinder);
+
+ ASSERT_NE(nullptr, server.get());
+ ASSERT_NE(nullptr, IInterface::asBinder(server)->remoteBinder());
+
+ {
+ sp<BadStableBinder> binder = BadStableBinder::vintf();
+
+ EXPECT_TRUE(Stability::requiresVintfDeclaration(binder));
+ EXPECT_TRUE(server->sendAndCallBinder(binder).isOk());
+ EXPECT_TRUE(binder->gotUserTransaction);
+ }
+ {
+ sp<BadStableBinder> binder = BadStableBinder::vintf();
+
+ // This method should never be called directly. This is done only for the test.
+ Stability::forceDowngradeToVendorStability(binder);
+
+ // Binder downgraded to vendor stability, cannot be called from system context
+ EXPECT_FALSE(Stability::requiresVintfDeclaration(binder));
+ EXPECT_EQ(BAD_TYPE, server->sendAndCallBinder(binder).exceptionCode());
+ EXPECT_FALSE(binder->gotUserTransaction);
+ }
+}
+
TEST(BinderStability, VintfStabilityServerMustBeDeclaredInManifest) {
sp<IBinder> vintfServer = BadStableBinder::vintf();