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

Commit 9c9ce1ee authored by Kalesh Singh's avatar Kalesh Singh Committed by Gerrit Code Review
Browse files

Merge "Add force downgrade to vendor stability test"

parents 9e8ee9bd 3b9ac062
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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
+29 −2
Original line number Diff line number Diff line
@@ -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();