Skip to content

Commit c7b5864

Browse files
committed
Rename ServiceManagerShim to CppBackendShim
This is a refactor to make it clear that this code path is only used by native clients. Test: atest aidl_integration_test Bug: 333854840 Flag: Exempt Refactor Change-Id: I8555310a989bf16916c06592a219e1cf9acb2212
1 parent 43e3b8b commit c7b5864

1 file changed

Lines changed: 34 additions & 40 deletions

File tree

libs/binder/IServiceManager.cpp

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,9 @@ IServiceManager::IServiceManager() {}
7979
IServiceManager::~IServiceManager() {}
8080

8181
// From the old libbinder IServiceManager interface to IServiceManager.
82-
class ServiceManagerShim : public IServiceManager
83-
{
82+
class CppBackendShim : public IServiceManager {
8483
public:
85-
explicit ServiceManagerShim(const sp<BackendUnifiedServiceManager>& impl);
84+
explicit CppBackendShim(const sp<BackendUnifiedServiceManager>& impl);
8685

8786
sp<IBinder> getService(const String16& name) const override;
8887
sp<IBinder> checkService(const String16& name) const override;
@@ -136,11 +135,11 @@ class ServiceManagerShim : public IServiceManager
136135
sp<RegistrationWaiter>* waiter);
137136

138137
// Directly get the service in a way that, for lazy services, requests the service to be started
139-
// if it is not currently started. This way, calls directly to ServiceManagerShim::getService
138+
// if it is not currently started. This way, calls directly to CppBackendShim::getService
140139
// will still have the 5s delay that is expected by a large amount of Android code.
141140
//
142-
// When implementing ServiceManagerShim, use realGetService instead of
143-
// mUnifiedServiceManager->getService so that it can be overridden in ServiceManagerHostShim.
141+
// When implementing CppBackendShim, use realGetService instead of
142+
// mUnifiedServiceManager->getService so that it can be overridden in CppServiceManagerHostShim.
144143
virtual Status realGetService(const std::string& name, sp<IBinder>* _aidl_return) {
145144
Service service;
146145
Status status = mUnifiedServiceManager->getService2(name, &service);
@@ -155,7 +154,7 @@ class ServiceManagerShim : public IServiceManager
155154
sp<IServiceManager> defaultServiceManager()
156155
{
157156
std::call_once(gSmOnce, []() {
158-
gDefaultServiceManager = sp<ServiceManagerShim>::make(getBackendUnifiedServiceManager());
157+
gDefaultServiceManager = sp<CppBackendShim>::make(getBackendUnifiedServiceManager());
159158
});
160159

161160
return gDefaultServiceManager;
@@ -278,15 +277,14 @@ void* openDeclaredPassthroughHal(const String16& interface, const String16& inst
278277

279278
// ----------------------------------------------------------------------
280279

281-
ServiceManagerShim::ServiceManagerShim(const sp<BackendUnifiedServiceManager>& impl)
280+
CppBackendShim::CppBackendShim(const sp<BackendUnifiedServiceManager>& impl)
282281
: mUnifiedServiceManager(impl) {}
283282

284283
// This implementation could be simplified and made more efficient by delegating
285284
// to waitForService. However, this changes the threading structure in some
286285
// cases and could potentially break prebuilts. Once we have higher logistical
287286
// complexity, this could be attempted.
288-
sp<IBinder> ServiceManagerShim::getService(const String16& name) const
289-
{
287+
sp<IBinder> CppBackendShim::getService(const String16& name) const {
290288
static bool gSystemBootCompleted = false;
291289

292290
sp<IBinder> svc = checkService(name);
@@ -330,25 +328,22 @@ sp<IBinder> ServiceManagerShim::getService(const String16& name) const
330328
return nullptr;
331329
}
332330

333-
sp<IBinder> ServiceManagerShim::checkService(const String16& name) const
334-
{
331+
sp<IBinder> CppBackendShim::checkService(const String16& name) const {
335332
Service ret;
336333
if (!mUnifiedServiceManager->checkService(String8(name).c_str(), &ret).isOk()) {
337334
return nullptr;
338335
}
339336
return ret.get<Service::Tag::binder>();
340337
}
341338

342-
status_t ServiceManagerShim::addService(const String16& name, const sp<IBinder>& service,
343-
bool allowIsolated, int dumpsysPriority)
344-
{
339+
status_t CppBackendShim::addService(const String16& name, const sp<IBinder>& service,
340+
bool allowIsolated, int dumpsysPriority) {
345341
Status status = mUnifiedServiceManager->addService(String8(name).c_str(), service,
346342
allowIsolated, dumpsysPriority);
347343
return status.exceptionCode();
348344
}
349345

350-
Vector<String16> ServiceManagerShim::listServices(int dumpsysPriority)
351-
{
346+
Vector<String16> CppBackendShim::listServices(int dumpsysPriority) {
352347
std::vector<std::string> ret;
353348
if (!mUnifiedServiceManager->listServices(dumpsysPriority, &ret).isOk()) {
354349
return {};
@@ -362,8 +357,7 @@ Vector<String16> ServiceManagerShim::listServices(int dumpsysPriority)
362357
return res;
363358
}
364359

365-
sp<IBinder> ServiceManagerShim::waitForService(const String16& name16)
366-
{
360+
sp<IBinder> CppBackendShim::waitForService(const String16& name16) {
367361
class Waiter : public android::os::BnServiceCallback {
368362
Status onRegistration(const std::string& /*name*/,
369363
const sp<IBinder>& binder) override {
@@ -452,7 +446,7 @@ sp<IBinder> ServiceManagerShim::waitForService(const String16& name16)
452446
}
453447
}
454448

455-
bool ServiceManagerShim::isDeclared(const String16& name) {
449+
bool CppBackendShim::isDeclared(const String16& name) {
456450
bool declared;
457451
if (Status status = mUnifiedServiceManager->isDeclared(String8(name).c_str(), &declared);
458452
!status.isOk()) {
@@ -463,7 +457,7 @@ bool ServiceManagerShim::isDeclared(const String16& name) {
463457
return declared;
464458
}
465459

466-
Vector<String16> ServiceManagerShim::getDeclaredInstances(const String16& interface) {
460+
Vector<String16> CppBackendShim::getDeclaredInstances(const String16& interface) {
467461
std::vector<std::string> out;
468462
if (Status status =
469463
mUnifiedServiceManager->getDeclaredInstances(String8(interface).c_str(), &out);
@@ -481,7 +475,7 @@ Vector<String16> ServiceManagerShim::getDeclaredInstances(const String16& interf
481475
return res;
482476
}
483477

484-
std::optional<String16> ServiceManagerShim::updatableViaApex(const String16& name) {
478+
std::optional<String16> CppBackendShim::updatableViaApex(const String16& name) {
485479
std::optional<std::string> declared;
486480
if (Status status = mUnifiedServiceManager->updatableViaApex(String8(name).c_str(), &declared);
487481
!status.isOk()) {
@@ -492,7 +486,7 @@ std::optional<String16> ServiceManagerShim::updatableViaApex(const String16& nam
492486
return declared ? std::optional<String16>(String16(declared.value().c_str())) : std::nullopt;
493487
}
494488

495-
Vector<String16> ServiceManagerShim::getUpdatableNames(const String16& apexName) {
489+
Vector<String16> CppBackendShim::getUpdatableNames(const String16& apexName) {
496490
std::vector<std::string> out;
497491
if (Status status = mUnifiedServiceManager->getUpdatableNames(String8(apexName).c_str(), &out);
498492
!status.isOk()) {
@@ -509,7 +503,7 @@ Vector<String16> ServiceManagerShim::getUpdatableNames(const String16& apexName)
509503
return res;
510504
}
511505

512-
std::optional<IServiceManager::ConnectionInfo> ServiceManagerShim::getConnectionInfo(
506+
std::optional<IServiceManager::ConnectionInfo> CppBackendShim::getConnectionInfo(
513507
const String16& name) {
514508
std::optional<os::ConnectionInfo> connectionInfo;
515509
if (Status status =
@@ -524,8 +518,8 @@ std::optional<IServiceManager::ConnectionInfo> ServiceManagerShim::getConnection
524518
: std::nullopt;
525519
}
526520

527-
status_t ServiceManagerShim::registerForNotifications(const String16& name,
528-
const sp<AidlRegistrationCallback>& cb) {
521+
status_t CppBackendShim::registerForNotifications(const String16& name,
522+
const sp<AidlRegistrationCallback>& cb) {
529523
if (cb == nullptr) {
530524
ALOGE("%s: null cb passed", __FUNCTION__);
531525
return BAD_VALUE;
@@ -544,9 +538,9 @@ status_t ServiceManagerShim::registerForNotifications(const String16& name,
544538
return OK;
545539
}
546540

547-
void ServiceManagerShim::removeRegistrationCallbackLocked(const sp<AidlRegistrationCallback>& cb,
548-
ServiceCallbackMap::iterator* it,
549-
sp<RegistrationWaiter>* waiter) {
541+
void CppBackendShim::removeRegistrationCallbackLocked(const sp<AidlRegistrationCallback>& cb,
542+
ServiceCallbackMap::iterator* it,
543+
sp<RegistrationWaiter>* waiter) {
550544
std::vector<LocalRegistrationAndWaiter>& localRegistrationAndWaiters = (*it)->second;
551545
for (auto lit = localRegistrationAndWaiters.begin();
552546
lit != localRegistrationAndWaiters.end();) {
@@ -565,8 +559,8 @@ void ServiceManagerShim::removeRegistrationCallbackLocked(const sp<AidlRegistrat
565559
}
566560
}
567561

568-
status_t ServiceManagerShim::unregisterForNotifications(const String16& name,
569-
const sp<AidlRegistrationCallback>& cb) {
562+
status_t CppBackendShim::unregisterForNotifications(const String16& name,
563+
const sp<AidlRegistrationCallback>& cb) {
570564
if (cb == nullptr) {
571565
ALOGE("%s: null cb passed", __FUNCTION__);
572566
return BAD_VALUE;
@@ -595,7 +589,7 @@ status_t ServiceManagerShim::unregisterForNotifications(const String16& name,
595589
return OK;
596590
}
597591

598-
std::vector<IServiceManager::ServiceDebugInfo> ServiceManagerShim::getServiceDebugInfo() {
592+
std::vector<IServiceManager::ServiceDebugInfo> CppBackendShim::getServiceDebugInfo() {
599593
std::vector<os::ServiceDebugInfo> serviceDebugInfos;
600594
std::vector<IServiceManager::ServiceDebugInfo> ret;
601595
if (Status status = mUnifiedServiceManager->getServiceDebugInfo(&serviceDebugInfos);
@@ -613,21 +607,21 @@ std::vector<IServiceManager::ServiceDebugInfo> ServiceManagerShim::getServiceDeb
613607
}
614608

615609
#ifndef __ANDROID__
616-
// ServiceManagerShim for host. Implements the old libbinder android::IServiceManager API.
610+
// CppBackendShim for host. Implements the old libbinder android::IServiceManager API.
617611
// The internal implementation of the AIDL interface android::os::IServiceManager calls into
618612
// on-device service manager.
619-
class ServiceManagerHostShim : public ServiceManagerShim {
613+
class CppServiceManagerHostShim : public CppBackendShim {
620614
public:
621-
ServiceManagerHostShim(const sp<AidlServiceManager>& impl,
622-
const RpcDelegateServiceManagerOptions& options)
623-
: ServiceManagerShim(sp<BackendUnifiedServiceManager>::make(impl)), mOptions(options) {}
624-
// ServiceManagerShim::getService is based on checkService, so no need to override it.
615+
CppServiceManagerHostShim(const sp<AidlServiceManager>& impl,
616+
const RpcDelegateServiceManagerOptions& options)
617+
: CppBackendShim(sp<BackendUnifiedServiceManager>::make(impl)), mOptions(options) {}
618+
// CppBackendShim::getService is based on checkService, so no need to override it.
625619
sp<IBinder> checkService(const String16& name) const override {
626620
return getDeviceService({String8(name).c_str()}, mOptions);
627621
}
628622

629623
protected:
630-
// Override realGetService for ServiceManagerShim::waitForService.
624+
// Override realGetService for CppBackendShim::waitForService.
631625
Status realGetService(const std::string& name, sp<IBinder>* _aidl_return) override {
632626
*_aidl_return = getDeviceService({"-g", name}, mOptions);
633627
return Status::ok();
@@ -648,7 +642,7 @@ sp<IServiceManager> createRpcDelegateServiceManager(
648642
ALOGE("getDeviceService(\"manager\") returns non service manager");
649643
return nullptr;
650644
}
651-
return sp<ServiceManagerHostShim>::make(interface, options);
645+
return sp<CppServiceManagerHostShim>::make(interface, options);
652646
}
653647
#endif
654648

0 commit comments

Comments
 (0)