Skip to content

Commit a17adea

Browse files
Steven Morelandandroid-build-merge-worker-robot
authored andcommitted
Merge changes from topic "aidl-partition-check" into main am: 4ac78a1 am: 86b835d
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/3440648 Change-Id: Id61670f359cda566ea11f692446e2de43f1794c1 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2 parents c92fd97 + 86b835d commit a17adea

6 files changed

Lines changed: 130 additions & 2 deletions

File tree

cmds/lshal/libprocpartition/include/procpartition/procpartition.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ namespace procpartition {
2727
enum class Partition {
2828
UNKNOWN = 0,
2929
SYSTEM,
30+
SYSTEM_EXT,
31+
PRODUCT,
3032
VENDOR,
3133
ODM
3234
};

cmds/lshal/libprocpartition/procpartition.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ namespace procpartition {
2424
std::ostream& operator<<(std::ostream& os, Partition p) {
2525
switch (p) {
2626
case Partition::SYSTEM: return os << "system";
27+
case Partition::SYSTEM_EXT: return os << "system_ext";
28+
case Partition::PRODUCT: return os << "product";
2729
case Partition::VENDOR: return os << "vendor";
2830
case Partition::ODM: return os << "odm";
2931
case Partition::UNKNOWN: // fallthrough
@@ -57,6 +59,12 @@ Partition parsePartition(const std::string& s) {
5759
if (s == "system") {
5860
return Partition::SYSTEM;
5961
}
62+
if (s == "system_ext") {
63+
return Partition::SYSTEM_EXT;
64+
}
65+
if (s == "product") {
66+
return Partition::PRODUCT;
67+
}
6068
if (s == "vendor") {
6169
return Partition::VENDOR;
6270
}

libs/binder/TEST_MAPPING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
{
3737
"name": "binderStabilityTest"
3838
},
39+
{
40+
"name": "binderStabilityIntegrationTest"
41+
},
3942
{
4043
"name": "binderRpcWireProtocolTest"
4144
},

libs/binder/include/binder/Stability.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <binder/IBinder.h>
2121
#include <string>
2222

23+
class BinderStabilityIntegrationTest_ExpectedStabilityForItsPartition_Test;
24+
2325
namespace android {
2426

2527
class BpBinder;
@@ -127,6 +129,8 @@ class Stability final {
127129
// through Parcel)
128130
friend ::android::ProcessState;
129131

132+
friend ::BinderStabilityIntegrationTest_ExpectedStabilityForItsPartition_Test;
133+
130134
static void tryMarkCompilationUnit(IBinder* binder);
131135

132136
// Currently, we use int16_t for Level so that it can fit in BBinder.
@@ -156,11 +160,11 @@ class Stability final {
156160
uint32_t flags);
157161

158162
// get stability information as encoded on the wire
159-
static int16_t getRepr(IBinder* binder);
163+
LIBBINDER_EXPORTED static int16_t getRepr(IBinder* binder);
160164

161165
// whether a transaction on binder is allowed, if the transaction
162166
// is done from a context with a specific stability level
163-
static bool check(int16_t provided, Level required);
167+
LIBBINDER_EXPORTED static bool check(int16_t provided, Level required);
164168

165169
static bool isDeclaredLevel(int32_t level);
166170
static std::string levelString(int32_t level);

libs/binder/tests/Android.bp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,28 @@ cc_test {
802802
require_root: true,
803803
}
804804

805+
cc_test {
806+
name: "binderStabilityIntegrationTest",
807+
defaults: ["binder_test_defaults"],
808+
srcs: [
809+
"binderStabilityIntegrationTest.cpp",
810+
],
811+
812+
shared_libs: [
813+
"libbinder",
814+
"libutils",
815+
],
816+
static_libs: [
817+
"libprocpartition",
818+
],
819+
820+
test_suites: [
821+
"general-tests",
822+
"vts",
823+
],
824+
require_root: true,
825+
}
826+
805827
cc_test {
806828
name: "binderAllocationLimits",
807829
defaults: ["binder_test_defaults"],
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (C) 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <binder/Binder.h>
18+
#include <binder/IServiceManager.h>
19+
#include <binder/Stability.h>
20+
#include <gtest/gtest.h>
21+
#include <procpartition/procpartition.h>
22+
23+
using namespace android;
24+
using android::internal::Stability; // for testing only!
25+
using android::procpartition::getPartition;
26+
using android::procpartition::Partition;
27+
28+
class BinderStabilityIntegrationTest : public testing::Test,
29+
public ::testing::WithParamInterface<String16> {
30+
public:
31+
virtual ~BinderStabilityIntegrationTest() {}
32+
};
33+
34+
TEST_P(BinderStabilityIntegrationTest, ExpectedStabilityForItsPartition) {
35+
const String16& serviceName = GetParam();
36+
37+
sp<IBinder> binder = defaultServiceManager()->checkService(serviceName);
38+
if (!binder) GTEST_SKIP() << "Could not get service, may have gone away.";
39+
40+
pid_t pid;
41+
status_t res = binder->getDebugPid(&pid);
42+
if (res != OK) {
43+
GTEST_SKIP() << "Could not talk to service to get PID, res: " << statusToString(res);
44+
}
45+
46+
Partition partition = getPartition(pid);
47+
48+
Stability::Level level = Stability::Level::UNDECLARED;
49+
switch (partition) {
50+
case Partition::SYSTEM:
51+
case Partition::SYSTEM_EXT:
52+
level = Stability::Level::SYSTEM;
53+
break;
54+
case Partition::VENDOR:
55+
case Partition::ODM:
56+
level = Stability::Level::VENDOR;
57+
break;
58+
case Partition::UNKNOWN:
59+
GTEST_SKIP() << "Not sure of partition of process.";
60+
return;
61+
default:
62+
ADD_FAILURE() << "Unrecognized partition for service: " << partition;
63+
return;
64+
}
65+
66+
ASSERT_TRUE(Stability::check(Stability::getRepr(binder.get()), level))
67+
<< "Binder hosted on partition " << partition
68+
<< " should have corresponding stability set.";
69+
}
70+
71+
std::string PrintTestParam(
72+
const testing::TestParamInfo<BinderStabilityIntegrationTest::ParamType>& info) {
73+
std::string name = String8(info.param).c_str();
74+
for (size_t i = 0; i < name.size(); i++) {
75+
bool alnum = false;
76+
alnum |= (name[i] >= 'a' && name[i] <= 'z');
77+
alnum |= (name[i] >= 'A' && name[i] <= 'Z');
78+
alnum |= (name[i] >= '0' && name[i] <= '9');
79+
alnum |= (name[i] == '_');
80+
if (!alnum) name[i] = '_';
81+
}
82+
83+
// index for uniqueness
84+
return std::to_string(info.index) + "__" + name;
85+
}
86+
87+
INSTANTIATE_TEST_CASE_P(RegisteredServices, BinderStabilityIntegrationTest,
88+
::testing::ValuesIn(defaultServiceManager()->listServices()),
89+
PrintTestParam);

0 commit comments

Comments
 (0)