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

Commit 1cb959d1 authored by Xin Li's avatar Xin Li
Browse files

Merge RQ2A.210305.007

Bug: 180401296
Merged-In: I2f7cee6cdae4b16c5adeb7af751a591a939948e2
Change-Id: I6c6bab18dc342c4456e8fd2db35173568fab1407
parents e9b81a40 e00110e1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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];
+64 −21
Original line number Diff line number Diff line
@@ -30,16 +30,12 @@ namespace internal {

using AidlServiceManager = android::os::IServiceManager;

class ClientCounterCallback : public ::android::os::BnClientCallback {
class ClientCounterCallbackImpl : public ::android::os::BnClientCallback {
public:
    ClientCounterCallback() : mNumConnectedServices(0), mForcePersist(false) {}
    ClientCounterCallbackImpl() : mNumConnectedServices(0), mForcePersist(false) {}

    bool registerService(const sp<IBinder>& service, const std::string& name,
                         bool allowIsolated, int dumpFlags);

    /**
     * Set a flag to prevent services from automatically shutting down
     */
    void forcePersist(bool persist);

    void setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback);
@@ -97,7 +93,29 @@ private:
    std::function<bool(bool)> mActiveServicesCallback;
};

bool ClientCounterCallback::registerService(const sp<IBinder>& service, const std::string& name,
class ClientCounterCallback {
public:
    ClientCounterCallback();

    bool registerService(const sp<IBinder>& service, const std::string& name,
                                            bool allowIsolated, int dumpFlags);

    /**
     * Set a flag to prevent services from automatically shutting down
     */
    void forcePersist(bool persist);

    void setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback);

    bool tryUnregister();

    void reRegister();

private:
    sp<ClientCounterCallbackImpl> mImpl;
};

bool ClientCounterCallbackImpl::registerService(const sp<IBinder>& service, const std::string& name,
                                            bool allowIsolated, int dumpFlags) {
    auto manager = interface_cast<AidlServiceManager>(asBinder(defaultServiceManager()));

@@ -127,7 +145,7 @@ bool ClientCounterCallback::registerService(const sp<IBinder>& service, const st
    return true;
}

std::map<std::string, ClientCounterCallback::Service>::iterator ClientCounterCallback::assertRegisteredService(const sp<IBinder>& service) {
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;
@@ -139,7 +157,7 @@ std::map<std::string, ClientCounterCallback::Service>::iterator ClientCounterCal
    __builtin_unreachable();
}

void ClientCounterCallback::forcePersist(bool persist) {
void ClientCounterCallbackImpl::forcePersist(bool persist) {
    mForcePersist = persist;
    if (!mForcePersist) {
        // Attempt a shutdown in case the number of clients hit 0 while the flag was on
@@ -147,7 +165,7 @@ void ClientCounterCallback::forcePersist(bool persist) {
    }
}

bool ClientCounterCallback::tryUnregister() {
bool ClientCounterCallbackImpl::tryUnregister() {
    auto manager = interface_cast<AidlServiceManager>(asBinder(defaultServiceManager()));

    for (auto& [name, entry] : mRegisteredServices) {
@@ -163,7 +181,7 @@ bool ClientCounterCallback::tryUnregister() {
    return true;
}

void ClientCounterCallback::reRegister() {
void ClientCounterCallbackImpl::reRegister() {
    for (auto& [name, entry] : mRegisteredServices) {
        // re-register entry if not already registered
        if (entry.registered) {
@@ -180,7 +198,7 @@ void ClientCounterCallback::reRegister() {
    }
}

void ClientCounterCallback::maybeTryShutdown() {
void ClientCounterCallbackImpl::maybeTryShutdown() {
    if (mForcePersist) {
        ALOGI("Shutdown prevented by forcePersist override flag.");
        return;
@@ -207,7 +225,7 @@ void ClientCounterCallback::maybeTryShutdown() {
 * onClients is oneway, so no need to worry about multi-threading. Note that this means multiple
 * invocations could occur on different threads however.
 */
Status ClientCounterCallback::onClients(const sp<IBinder>& service, bool clients) {
Status ClientCounterCallbackImpl::onClients(const sp<IBinder>& service, bool clients) {
    auto & [name, registered] = *assertRegisteredService(service);
    if (registered.clients == clients) {
        LOG_ALWAYS_FATAL("Process already thought %s had clients: %d but servicemanager has "
@@ -229,11 +247,10 @@ Status ClientCounterCallback::onClients(const sp<IBinder>& service, bool clients
          mNumConnectedServices, mRegisteredServices.size(), name.c_str(), clients);

    maybeTryShutdown();

    return Status::ok();
}

void ClientCounterCallback::tryShutdown() {
 void ClientCounterCallbackImpl::tryShutdown() {
     ALOGI("Trying to shut down the service. No clients in use for any service in process.");

    if (tryUnregister()) {
@@ -244,11 +261,37 @@ void ClientCounterCallback::tryShutdown() {
    reRegister();
}

void ClientCounterCallback::setActiveServicesCallback(const std::function<bool(bool)>&
void ClientCounterCallbackImpl::setActiveServicesCallback(const std::function<bool(bool)>&
                                                          activeServicesCallback) {
    mActiveServicesCallback = activeServicesCallback;
}

ClientCounterCallback::ClientCounterCallback() {
      mImpl = sp<ClientCounterCallbackImpl>::make();
}

bool ClientCounterCallback::registerService(const sp<IBinder>& service, const std::string& name,
                                            bool allowIsolated, int dumpFlags) {
    return mImpl->registerService(service, name, allowIsolated, dumpFlags);
}

void ClientCounterCallback::forcePersist(bool persist) {
    mImpl->forcePersist(persist);
}

void ClientCounterCallback::setActiveServicesCallback(const std::function<bool(bool)>&
                                                      activeServicesCallback) {
    mImpl->setActiveServicesCallback(activeServicesCallback);
}

bool ClientCounterCallback::tryUnregister() {
    return mImpl->tryUnregister();
}

void ClientCounterCallback::reRegister() {
    mImpl->reRegister();
}

}  // namespace internal

LazyServiceRegistrar::LazyServiceRegistrar() {
+8 −2
Original line number Diff line number Diff line
@@ -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;
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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();
+5 −5
Original line number Diff line number Diff line
@@ -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