Loading cmds/installd/QuotaUtils.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ std::recursive_mutex mMountsLock; /* Map of all quota mounts from target to source */ std::unordered_map<std::string, std::string> mQuotaReverseMounts; std::string& FindQuotaDeviceForUuid(const std::string& uuid) { std::string FindQuotaDeviceForUuid(const std::string& uuid) { std::lock_guard<std::recursive_mutex> lock(mMountsLock); auto path = create_data_path(uuid.empty() ? nullptr : uuid.c_str()); return mQuotaReverseMounts[path]; Loading libs/binder/LazyServiceRegistrar.cpp +53 −22 Original line number Diff line number Diff line Loading @@ -48,6 +48,22 @@ protected: Status onClients(const sp<IBinder>& service, bool clients) override; private: struct Service { sp<IBinder> service; bool allowIsolated; int dumpFlags; // whether, based on onClients calls, we know we have a client for this // service or not bool clients = false; bool registered = true; }; /** * Looks up a service guaranteed to be registered (service from onClients). */ std::map<std::string, Service>::iterator assertRegisteredService(const sp<IBinder>& service); /** * Unregisters all services that we can. If we can't unregister all, re-register other * services. Loading @@ -62,24 +78,13 @@ private: */ void maybeTryShutdown(); /* * Counter of the number of services that currently have at least one client. */ // count of services with clients size_t mNumConnectedServices; // previous value passed to the active services callback std::optional<bool> mPreviousHasClients; struct Service { sp<IBinder> service; bool allowIsolated; int dumpFlags; bool registered = true; }; /** * Map of registered names and services */ // map of registered names and services std::map<std::string, Service> mRegisteredServices; bool mForcePersist; Loading Loading @@ -130,12 +135,28 @@ bool ClientCounterCallbackImpl::registerService(const sp<IBinder>& service, cons } // Only add this when a service is added for the first time, as it is not removed mRegisteredServices[name] = {service, allowIsolated, dumpFlags}; mRegisteredServices[name] = { .service = service, .allowIsolated = allowIsolated, .dumpFlags = dumpFlags }; } return true; } std::map<std::string, ClientCounterCallbackImpl::Service>::iterator ClientCounterCallbackImpl::assertRegisteredService(const sp<IBinder>& service) { LOG_ALWAYS_FATAL_IF(service == nullptr, "Got onClients callback for null service"); for (auto it = mRegisteredServices.begin(); it != mRegisteredServices.end(); ++it) { auto const& [name, registered] = *it; (void) name; if (registered.service != service) continue; return it; } LOG_ALWAYS_FATAL("Got callback on service which we did not register: %s", String8(service->getInterfaceDescriptor()).c_str()); __builtin_unreachable(); } void ClientCounterCallbackImpl::forcePersist(bool persist) { mForcePersist = persist; if (!mForcePersist) { Loading Loading @@ -205,15 +226,25 @@ void ClientCounterCallbackImpl::maybeTryShutdown() { * invocations could occur on different threads however. */ Status ClientCounterCallbackImpl::onClients(const sp<IBinder>& service, bool clients) { if (clients) { mNumConnectedServices++; } else { mNumConnectedServices--; auto & [name, registered] = *assertRegisteredService(service); if (registered.clients == clients) { LOG_ALWAYS_FATAL("Process already thought %s had clients: %d but servicemanager has " "notified has clients: %d", name.c_str(), registered.clients, clients); } registered.clients = clients; // update cache count of clients { size_t numWithClients = 0; for (const auto& [name, registered] : mRegisteredServices) { (void) name; if (registered.clients) numWithClients++; } mNumConnectedServices = numWithClients; } ALOGI("Process has %zu (of %zu available) client(s) in use after notification %s has clients: %d", mNumConnectedServices, mRegisteredServices.size(), String8(service->getInterfaceDescriptor()).string(), clients); mNumConnectedServices, mRegisteredServices.size(), name.c_str(), clients); maybeTryShutdown(); return Status::ok(); Loading @@ -236,7 +267,7 @@ void ClientCounterCallbackImpl::setActiveServicesCallback(const std::function<bo } ClientCounterCallback::ClientCounterCallback() { mImpl = new ClientCounterCallbackImpl(); mImpl = sp<ClientCounterCallbackImpl>::make(); } bool ClientCounterCallback::registerService(const sp<IBinder>& service, const std::string& name, Loading libs/binder/Parcel.cpp +8 −2 Original line number Diff line number Diff line Loading @@ -1651,8 +1651,11 @@ const char* Parcel::readString8Inplace(size_t* outLen) const *outLen = size; const char* str = (const char*)readInplace(size+1); if (str != nullptr) { if (str[size] == '\0') { return str; } android_errorWriteLog(0x534e4554, "172655291"); } } *outLen = 0; return nullptr; Loading Loading @@ -1689,8 +1692,11 @@ const char16_t* Parcel::readString16Inplace(size_t* outLen) const *outLen = size; const char16_t* str = (const char16_t*)readInplace((size+1)*sizeof(char16_t)); if (str != nullptr) { if (str[size] == u'\0') { return str; } android_errorWriteLog(0x534e4554, "172655291"); } } *outLen = 0; return nullptr; Loading libs/binder/ndk/ibinder.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -181,7 +181,7 @@ status_t ABBinder::onTransact(transaction_code_t code, const Parcel& data, Parce binder_status_t status = getClass()->onTransact(this, code, &in, &out); return PruneStatusT(status); } else if (code == SHELL_COMMAND_TRANSACTION && getClass()->handleShellCommand != nullptr) { } else if (code == SHELL_COMMAND_TRANSACTION) { int in = data.readFileDescriptor(); int out = data.readFileDescriptor(); int err = data.readFileDescriptor(); Loading libs/binder/ndk/ibinder_internal.h +5 −5 Original line number Diff line number Diff line Loading @@ -116,13 +116,13 @@ struct AIBinder_Class { const char* getInterfaceDescriptorUtf8() const { return mInterfaceDescriptor.c_str(); } // required to be non-null, implemented for every class const AIBinder_Class_onCreate onCreate = nullptr; const AIBinder_Class_onDestroy onDestroy = nullptr; const AIBinder_Class_onTransact onTransact = nullptr; const AIBinder_Class_onCreate onCreate; const AIBinder_Class_onDestroy onDestroy; const AIBinder_Class_onTransact onTransact; // optional methods for a class AIBinder_onDump onDump = nullptr; AIBinder_handleShellCommand handleShellCommand = nullptr; AIBinder_onDump onDump; AIBinder_handleShellCommand handleShellCommand; private: // Copy of the raw char string for when we don't have to return UTF-16 Loading Loading
cmds/installd/QuotaUtils.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ std::recursive_mutex mMountsLock; /* Map of all quota mounts from target to source */ std::unordered_map<std::string, std::string> mQuotaReverseMounts; std::string& FindQuotaDeviceForUuid(const std::string& uuid) { std::string FindQuotaDeviceForUuid(const std::string& uuid) { std::lock_guard<std::recursive_mutex> lock(mMountsLock); auto path = create_data_path(uuid.empty() ? nullptr : uuid.c_str()); return mQuotaReverseMounts[path]; Loading
libs/binder/LazyServiceRegistrar.cpp +53 −22 Original line number Diff line number Diff line Loading @@ -48,6 +48,22 @@ protected: Status onClients(const sp<IBinder>& service, bool clients) override; private: struct Service { sp<IBinder> service; bool allowIsolated; int dumpFlags; // whether, based on onClients calls, we know we have a client for this // service or not bool clients = false; bool registered = true; }; /** * Looks up a service guaranteed to be registered (service from onClients). */ std::map<std::string, Service>::iterator assertRegisteredService(const sp<IBinder>& service); /** * Unregisters all services that we can. If we can't unregister all, re-register other * services. Loading @@ -62,24 +78,13 @@ private: */ void maybeTryShutdown(); /* * Counter of the number of services that currently have at least one client. */ // count of services with clients size_t mNumConnectedServices; // previous value passed to the active services callback std::optional<bool> mPreviousHasClients; struct Service { sp<IBinder> service; bool allowIsolated; int dumpFlags; bool registered = true; }; /** * Map of registered names and services */ // map of registered names and services std::map<std::string, Service> mRegisteredServices; bool mForcePersist; Loading Loading @@ -130,12 +135,28 @@ bool ClientCounterCallbackImpl::registerService(const sp<IBinder>& service, cons } // Only add this when a service is added for the first time, as it is not removed mRegisteredServices[name] = {service, allowIsolated, dumpFlags}; mRegisteredServices[name] = { .service = service, .allowIsolated = allowIsolated, .dumpFlags = dumpFlags }; } return true; } std::map<std::string, ClientCounterCallbackImpl::Service>::iterator ClientCounterCallbackImpl::assertRegisteredService(const sp<IBinder>& service) { LOG_ALWAYS_FATAL_IF(service == nullptr, "Got onClients callback for null service"); for (auto it = mRegisteredServices.begin(); it != mRegisteredServices.end(); ++it) { auto const& [name, registered] = *it; (void) name; if (registered.service != service) continue; return it; } LOG_ALWAYS_FATAL("Got callback on service which we did not register: %s", String8(service->getInterfaceDescriptor()).c_str()); __builtin_unreachable(); } void ClientCounterCallbackImpl::forcePersist(bool persist) { mForcePersist = persist; if (!mForcePersist) { Loading Loading @@ -205,15 +226,25 @@ void ClientCounterCallbackImpl::maybeTryShutdown() { * invocations could occur on different threads however. */ Status ClientCounterCallbackImpl::onClients(const sp<IBinder>& service, bool clients) { if (clients) { mNumConnectedServices++; } else { mNumConnectedServices--; auto & [name, registered] = *assertRegisteredService(service); if (registered.clients == clients) { LOG_ALWAYS_FATAL("Process already thought %s had clients: %d but servicemanager has " "notified has clients: %d", name.c_str(), registered.clients, clients); } registered.clients = clients; // update cache count of clients { size_t numWithClients = 0; for (const auto& [name, registered] : mRegisteredServices) { (void) name; if (registered.clients) numWithClients++; } mNumConnectedServices = numWithClients; } ALOGI("Process has %zu (of %zu available) client(s) in use after notification %s has clients: %d", mNumConnectedServices, mRegisteredServices.size(), String8(service->getInterfaceDescriptor()).string(), clients); mNumConnectedServices, mRegisteredServices.size(), name.c_str(), clients); maybeTryShutdown(); return Status::ok(); Loading @@ -236,7 +267,7 @@ void ClientCounterCallbackImpl::setActiveServicesCallback(const std::function<bo } ClientCounterCallback::ClientCounterCallback() { mImpl = new ClientCounterCallbackImpl(); mImpl = sp<ClientCounterCallbackImpl>::make(); } bool ClientCounterCallback::registerService(const sp<IBinder>& service, const std::string& name, Loading
libs/binder/Parcel.cpp +8 −2 Original line number Diff line number Diff line Loading @@ -1651,8 +1651,11 @@ const char* Parcel::readString8Inplace(size_t* outLen) const *outLen = size; const char* str = (const char*)readInplace(size+1); if (str != nullptr) { if (str[size] == '\0') { return str; } android_errorWriteLog(0x534e4554, "172655291"); } } *outLen = 0; return nullptr; Loading Loading @@ -1689,8 +1692,11 @@ const char16_t* Parcel::readString16Inplace(size_t* outLen) const *outLen = size; const char16_t* str = (const char16_t*)readInplace((size+1)*sizeof(char16_t)); if (str != nullptr) { if (str[size] == u'\0') { return str; } android_errorWriteLog(0x534e4554, "172655291"); } } *outLen = 0; return nullptr; Loading
libs/binder/ndk/ibinder.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -181,7 +181,7 @@ status_t ABBinder::onTransact(transaction_code_t code, const Parcel& data, Parce binder_status_t status = getClass()->onTransact(this, code, &in, &out); return PruneStatusT(status); } else if (code == SHELL_COMMAND_TRANSACTION && getClass()->handleShellCommand != nullptr) { } else if (code == SHELL_COMMAND_TRANSACTION) { int in = data.readFileDescriptor(); int out = data.readFileDescriptor(); int err = data.readFileDescriptor(); Loading
libs/binder/ndk/ibinder_internal.h +5 −5 Original line number Diff line number Diff line Loading @@ -116,13 +116,13 @@ struct AIBinder_Class { const char* getInterfaceDescriptorUtf8() const { return mInterfaceDescriptor.c_str(); } // required to be non-null, implemented for every class const AIBinder_Class_onCreate onCreate = nullptr; const AIBinder_Class_onDestroy onDestroy = nullptr; const AIBinder_Class_onTransact onTransact = nullptr; const AIBinder_Class_onCreate onCreate; const AIBinder_Class_onDestroy onDestroy; const AIBinder_Class_onTransact onTransact; // optional methods for a class AIBinder_onDump onDump = nullptr; AIBinder_handleShellCommand handleShellCommand = nullptr; AIBinder_onDump onDump; AIBinder_handleShellCommand handleShellCommand; private: // Copy of the raw char string for when we don't have to return UTF-16 Loading