Skip to content

Commit e3918bd

Browse files
author
Android Build Coastguard Worker
committed
Snap for 12735943 from c0919ab to 25Q1-release
Change-Id: Ifafa9fe1658860e05750d806024f3f5a4339d598
2 parents e2729d5 + c0919ab commit e3918bd

43 files changed

Lines changed: 876 additions & 93 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmds/dumpsys/tests/dumpsys_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class ServiceManagerMock : public IServiceManager {
6767
MOCK_METHOD2(unregisterForNotifications, status_t(const String16&,
6868
const sp<LocalRegistrationCallback>&));
6969
MOCK_METHOD0(getServiceDebugInfo, std::vector<ServiceDebugInfo>());
70+
MOCK_METHOD1(enableAddServiceCache, void(bool));
71+
7072
protected:
7173
MOCK_METHOD0(onAsBinder, IBinder*());
7274
};

include/android/display_luts.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ typedef enum ADisplayLuts_Dimension ADisplayLuts_Dimension;
4343
enum ADisplayLuts_SamplingKey : int32_t {
4444
ADISPLAYLUTS_SAMPLINGKEY_RGB = 0,
4545
ADISPLAYLUTS_SAMPLINGKEY_MAX_RGB = 1,
46+
ADISPLAYLUTS_SAMPLINGKEY_CIE_Y = 2,
4647
};
4748
typedef enum ADisplayLuts_SamplingKey ADisplayLuts_SamplingKey;
4849

@@ -74,7 +75,8 @@ typedef struct ADisplayLuts ADisplayLuts;
7475
* @return a new \a ADisplayLutsEntry instance.
7576
*/
7677
ADisplayLutsEntry* _Nonnull ADisplayLutsEntry_createEntry(float* _Nonnull buffer,
77-
int32_t length, int32_t dimension, int32_t key) __INTRODUCED_IN(36);
78+
int32_t length, ADisplayLuts_Dimension dimension, ADisplayLuts_SamplingKey key)
79+
__INTRODUCED_IN(36);
7880

7981
/**
8082
* Destroy the \a ADisplayLutsEntry instance.

include/private/display_luts_private.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#pragma once
1818

19+
#include <android/display_luts.h>
1920
#include <stdint.h>
2021
#include <vector>
2122
#include <utils/RefBase.h>
@@ -29,9 +30,9 @@ struct ADisplayLutsEntry_buffer {
2930
};
3031

3132
struct ADisplayLutsEntry_properties {
32-
int32_t dimension;
33+
ADisplayLuts_Dimension dimension;
3334
int32_t size;
34-
int32_t samplingKey;
35+
ADisplayLuts_SamplingKey samplingKey;
3536
};
3637

3738
struct ADisplayLutsEntry: public RefBase {

libs/binder/Android.bp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,34 @@ libbinder_client_cache_config {
477477
},
478478
}
479479

480+
soong_config_module_type {
481+
name: "libbinder_addservice_cache_config",
482+
module_type: "cc_defaults",
483+
config_namespace: "libbinder",
484+
bool_variables: ["release_libbinder_addservice_cache"],
485+
properties: [
486+
"cflags",
487+
],
488+
}
489+
490+
libbinder_addservice_cache_config {
491+
name: "libbinder_addservice_cache_flag",
492+
soong_config_variables: {
493+
release_libbinder_addservice_cache: {
494+
cflags: ["-DLIBBINDER_ADDSERVICE_CACHE"],
495+
conditions_default: {
496+
cflags: ["-DNO_LIBBINDER_ADDSERVICE_CACHE"],
497+
},
498+
},
499+
},
500+
}
501+
480502
cc_defaults {
481503
name: "libbinder_kernel_defaults",
482-
defaults: ["libbinder_client_cache_flag"],
504+
defaults: [
505+
"libbinder_client_cache_flag",
506+
"libbinder_addservice_cache_flag",
507+
],
483508
srcs: [
484509
"BufferedTextOutput.cpp",
485510
"BackendUnifiedServiceManager.cpp",

libs/binder/BackendUnifiedServiceManager.cpp

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ constexpr bool kUseCache = true;
3030
constexpr bool kUseCache = false;
3131
#endif
3232

33+
#ifdef LIBBINDER_ADDSERVICE_CACHE
34+
constexpr bool kUseCacheInAddService = true;
35+
#else
36+
constexpr bool kUseCacheInAddService = false;
37+
#endif
38+
3339
using AidlServiceManager = android::os::IServiceManager;
3440
using android::os::IAccessor;
3541
using binder::Status;
@@ -125,31 +131,36 @@ Status BackendUnifiedServiceManager::updateCache(const std::string& serviceName,
125131
if (!kUseCache) {
126132
return Status::ok();
127133
}
134+
135+
if (service.getTag() == os::Service::Tag::binder) {
136+
return updateCache(serviceName, service.get<os::Service::Tag::binder>());
137+
}
138+
return Status::ok();
139+
}
140+
141+
Status BackendUnifiedServiceManager::updateCache(const std::string& serviceName,
142+
const sp<IBinder>& binder) {
128143
std::string traceStr;
129144
if (atrace_is_tag_enabled(ATRACE_TAG_AIDL)) {
130145
traceStr = "BinderCacheWithInvalidation::updateCache : " + serviceName;
131146
}
132147
binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL, traceStr.c_str());
133-
134-
if (service.getTag() == os::Service::Tag::binder) {
135-
sp<IBinder> binder = service.get<os::Service::Tag::binder>();
136-
if (!binder) {
137-
binder::ScopedTrace
138-
aidlTrace(ATRACE_TAG_AIDL,
139-
"BinderCacheWithInvalidation::updateCache failed: binder_null");
140-
} else if (!binder->isBinderAlive()) {
141-
binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL,
142-
"BinderCacheWithInvalidation::updateCache failed: "
143-
"isBinderAlive_false");
144-
} else if (mCacheForGetService->isClientSideCachingEnabled(serviceName)) {
145-
binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL,
146-
"BinderCacheWithInvalidation::updateCache successful");
147-
return mCacheForGetService->setItem(serviceName, binder);
148-
} else {
149-
binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL,
150-
"BinderCacheWithInvalidation::updateCache failed: "
151-
"caching_not_enabled");
152-
}
148+
if (!binder) {
149+
binder::ScopedTrace
150+
aidlTrace(ATRACE_TAG_AIDL,
151+
"BinderCacheWithInvalidation::updateCache failed: binder_null");
152+
} else if (!binder->isBinderAlive()) {
153+
binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL,
154+
"BinderCacheWithInvalidation::updateCache failed: "
155+
"isBinderAlive_false");
156+
} else if (mCacheForGetService->isClientSideCachingEnabled(serviceName)) {
157+
binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL,
158+
"BinderCacheWithInvalidation::updateCache successful");
159+
return mCacheForGetService->setItem(serviceName, binder);
160+
} else {
161+
binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL,
162+
"BinderCacheWithInvalidation::updateCache failed: "
163+
"caching_not_enabled");
153164
}
154165
return Status::ok();
155166
}
@@ -277,7 +288,12 @@ Status BackendUnifiedServiceManager::toBinderService(const ::std::string& name,
277288
Status BackendUnifiedServiceManager::addService(const ::std::string& name,
278289
const sp<IBinder>& service, bool allowIsolated,
279290
int32_t dumpPriority) {
280-
return mTheRealServiceManager->addService(name, service, allowIsolated, dumpPriority);
291+
Status status = mTheRealServiceManager->addService(name, service, allowIsolated, dumpPriority);
292+
// mEnableAddServiceCache is true by default.
293+
if (kUseCacheInAddService && mEnableAddServiceCache && status.isOk()) {
294+
return updateCache(name, service);
295+
}
296+
return status;
281297
}
282298
Status BackendUnifiedServiceManager::listServices(int32_t dumpPriority,
283299
::std::vector<::std::string>* _aidl_return) {

libs/binder/BackendUnifiedServiceManager.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ class BinderCacheWithInvalidation
105105
binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL,
106106
"BinderCacheWithInvalidation::setItem Successfully Cached");
107107
std::lock_guard<std::mutex> lock(mCacheMutex);
108-
Entry entry = {.service = item, .deathRecipient = deathRecipient};
109-
mCache[key] = entry;
108+
mCache[key] = {.service = item, .deathRecipient = deathRecipient};
110109
return binder::Status::ok();
111110
}
112111

@@ -147,17 +146,20 @@ class BackendUnifiedServiceManager : public android::os::BnServiceManager {
147146
const sp<IBinder>& service) override;
148147
binder::Status getServiceDebugInfo(::std::vector<os::ServiceDebugInfo>* _aidl_return) override;
149148

149+
void enableAddServiceCache(bool value) { mEnableAddServiceCache = value; }
150150
// for legacy ABI
151151
const String16& getInterfaceDescriptor() const override {
152152
return mTheRealServiceManager->getInterfaceDescriptor();
153153
}
154154

155155
private:
156+
bool mEnableAddServiceCache = true;
156157
std::shared_ptr<BinderCacheWithInvalidation> mCacheForGetService;
157158
sp<os::IServiceManager> mTheRealServiceManager;
158159
binder::Status toBinderService(const ::std::string& name, const os::Service& in,
159160
os::Service* _out);
160161
binder::Status updateCache(const std::string& serviceName, const os::Service& service);
162+
binder::Status updateCache(const std::string& serviceName, const sp<IBinder>& binder);
161163
bool returnIfCached(const std::string& serviceName, os::Service* _out);
162164
};
163165

libs/binder/IServiceManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ class CppBackendShim : public IServiceManager {
127127
}
128128
IBinder* onAsBinder() override { return IInterface::asBinder(mUnifiedServiceManager).get(); }
129129

130+
void enableAddServiceCache(bool value) { mUnifiedServiceManager->enableAddServiceCache(value); }
131+
130132
protected:
131133
sp<BackendUnifiedServiceManager> mUnifiedServiceManager;
132134
// AidlRegistrationCallback -> services that its been registered for

libs/binder/include/binder/IServiceManager.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ class LIBBINDER_EXPORTED IServiceManager : public IInterface {
150150
int pid;
151151
};
152152
virtual std::vector<ServiceDebugInfo> getServiceDebugInfo() = 0;
153+
154+
/**
155+
* Directly enable or disable caching binder during addService calls.
156+
* Only used for testing.
157+
*/
158+
virtual void enableAddServiceCache(bool value) = 0;
153159
};
154160

155161
LIBBINDER_EXPORTED sp<IServiceManager> defaultServiceManager();

libs/binder/tests/Android.bp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ cc_test {
7070
static_libs: [
7171
"libfakeservicemanager",
7272
],
73-
defaults: ["libbinder_client_cache_flag"],
73+
defaults: [
74+
"libbinder_client_cache_flag",
75+
"libbinder_addservice_cache_flag",
76+
],
7477
test_suites: ["general-tests"],
7578
require_root: true,
7679
}

libs/binder/tests/binderCacheUnitTest.cpp

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ constexpr bool kUseLibbinderCache = true;
3434
constexpr bool kUseLibbinderCache = false;
3535
#endif
3636

37+
#ifdef LIBBINDER_ADDSERVICE_CACHE
38+
constexpr bool kUseCacheInAddService = true;
39+
#else
40+
constexpr bool kUseCacheInAddService = false;
41+
#endif
42+
3743
// A service name which is in the static list of cachable services
3844
const String16 kCachedServiceName = String16("isub");
3945

@@ -74,14 +80,58 @@ class MockAidlServiceManager : public os::IServiceManagerDefault {
7480
innerSm.addService(String16(name.c_str()), service, allowIsolated, dumpPriority));
7581
}
7682

83+
void clearServices() { innerSm.clear(); }
84+
7785
FakeServiceManager innerSm;
7886
};
7987

88+
class LibbinderCacheAddServiceTest : public ::testing::Test {
89+
protected:
90+
void SetUp() override {
91+
fakeServiceManager = sp<MockAidlServiceManager>::make();
92+
mServiceManager = getServiceManagerShimFromAidlServiceManagerForTests(fakeServiceManager);
93+
mServiceManager->enableAddServiceCache(true);
94+
}
95+
96+
void TearDown() override {}
97+
98+
public:
99+
void cacheAddServiceAndConfirmCacheHit(const sp<IBinder>& binder1) {
100+
// Add a service. This also caches it.
101+
EXPECT_EQ(OK, mServiceManager->addService(kCachedServiceName, binder1));
102+
// remove services from fakeservicemanager
103+
fakeServiceManager->clearServices();
104+
105+
sp<IBinder> result = mServiceManager->checkService(kCachedServiceName);
106+
if (kUseCacheInAddService && kUseLibbinderCache) {
107+
// If cache is enabled, we should get the binder.
108+
EXPECT_EQ(binder1, result);
109+
} else {
110+
// If cache is disabled, then we should get the null binder
111+
EXPECT_EQ(nullptr, result);
112+
}
113+
}
114+
sp<MockAidlServiceManager> fakeServiceManager;
115+
sp<android::IServiceManager> mServiceManager;
116+
};
117+
118+
TEST_F(LibbinderCacheAddServiceTest, AddLocalServiceAndConfirmCacheHit) {
119+
sp<IBinder> binder1 = sp<BBinder>::make();
120+
cacheAddServiceAndConfirmCacheHit(binder1);
121+
}
122+
123+
TEST_F(LibbinderCacheAddServiceTest, AddRemoteServiceAndConfirmCacheHit) {
124+
sp<IBinder> binder1 = defaultServiceManager()->checkService(kServerName);
125+
ASSERT_NE(binder1, nullptr);
126+
cacheAddServiceAndConfirmCacheHit(binder1);
127+
}
128+
80129
class LibbinderCacheTest : public ::testing::Test {
81130
protected:
82131
void SetUp() override {
83-
sp<MockAidlServiceManager> sm = sp<MockAidlServiceManager>::make();
84-
mServiceManager = getServiceManagerShimFromAidlServiceManagerForTests(sm);
132+
fakeServiceManager = sp<MockAidlServiceManager>::make();
133+
mServiceManager = getServiceManagerShimFromAidlServiceManagerForTests(fakeServiceManager);
134+
mServiceManager->enableAddServiceCache(false);
85135
}
86136

87137
void TearDown() override {}
@@ -108,6 +158,7 @@ class LibbinderCacheTest : public ::testing::Test {
108158
}
109159
}
110160

161+
sp<MockAidlServiceManager> fakeServiceManager;
111162
sp<android::IServiceManager> mServiceManager;
112163
};
113164

0 commit comments

Comments
 (0)