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

Commit af05567b authored by Jon Spivack's avatar Jon Spivack Committed by android-build-merger
Browse files

Revert "Dynamically stop services with multiple interfaces"

am: 37f70cc1

Change-Id: I2abcb3d8142e4e089069afa7bc4647169a7f7149
parents b4931c59 37f70cc1
Loading
Loading
Loading
Loading
+11 −15
Original line number Diff line number Diff line
@@ -423,12 +423,11 @@ ssize_t ServiceManager::Service::getNodeStrongRefCount() {

void ServiceManager::handleClientCallbacks() {
    for (const auto& [name, service] : mNameToService) {
        handleServiceClientCallback(name, true);
        handleServiceClientCallback(name);
    }
}

ssize_t ServiceManager::handleServiceClientCallback(const std::string& serviceName,
                                                    bool isCalledOnInterval) {
ssize_t ServiceManager::handleServiceClientCallback(const std::string& serviceName) {
    auto serviceIt = mNameToService.find(serviceName);
    if (serviceIt == mNameToService.end() || mNameToClientCallback.count(serviceName) < 1) {
        return -1;
@@ -452,8 +451,6 @@ ssize_t ServiceManager::handleServiceClientCallback(const std::string& serviceNa
        service.guaranteeClient = false;
    }

    // only send notifications if this was called via the interval checking workflow
    if (isCalledOnInterval) {
    if (hasClients && !service.hasClients) {
        // client was retrieved in some other way
        sendClientCallbackNotifications(serviceName, true);
@@ -463,7 +460,6 @@ ssize_t ServiceManager::handleServiceClientCallback(const std::string& serviceNa
    if (!hasClients && service.hasClients) {
        sendClientCallbackNotifications(serviceName, false);
    }
    }

    return count;
}
@@ -522,7 +518,7 @@ Status ServiceManager::tryUnregisterService(const std::string& name, const sp<IB
        return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE);
    }

    int clients = handleServiceClientCallback(name, false);
    int clients = handleServiceClientCallback(name);

    // clients < 0: feature not implemented or other error. Assume clients.
    // Otherwise:
@@ -531,7 +527,7 @@ Status ServiceManager::tryUnregisterService(const std::string& name, const sp<IB
    // So, if clients > 2, then at least one other service on the system must hold a refcount.
    if (clients < 0 || clients > 2) {
        // client callbacks are either disabled or there are other clients
        LOG(INFO) << "Tried to unregister " << name << ", but there are clients: " << clients;
        LOG(INFO) << "Tried to unregister " << name << " but there are clients: " << clients;
        return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE);
    }

+1 −1
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ private:
    void removeRegistrationCallback(const wp<IBinder>& who,
                        ServiceCallbackMap::iterator* it,
                        bool* found);
    ssize_t handleServiceClientCallback(const std::string& serviceName, bool isCalledOnInterval);
    ssize_t handleServiceClientCallback(const std::string& serviceName);
     // Also updates mHasClients (of what the last callback was)
    void sendClientCallbackNotifications(const std::string& serviceName, bool hasClients);
    // removes a callback from mNameToClientCallback, deleting the entry if the vector is empty
+12 −17
Original line number Diff line number Diff line
@@ -53,13 +53,14 @@ private:

    struct Service {
        sp<IBinder> service;
        std::string name;
        bool allowIsolated;
        int dumpFlags;
    };
    /**
     * Map of registered names and services
     * Number of services that have been registered.
     */
    std::map<std::string, Service> mRegisteredServices;
    std::vector<Service> mRegisteredServices;
};

bool ClientCounterCallback::registerService(const sp<IBinder>& service, const std::string& name,
@@ -67,24 +68,20 @@ bool ClientCounterCallback::registerService(const sp<IBinder>& service, const st
    auto manager = interface_cast<AidlServiceManager>(
                    ProcessState::self()->getContextObject(nullptr));

    bool reRegister = mRegisteredServices.count(name) > 0;
    std::string regStr = (reRegister) ? "Re-registering" : "Registering";
    ALOGI("%s service %s", regStr.c_str(), name.c_str());
    ALOGI("Registering service %s", name.c_str());

    if (!manager->addService(name.c_str(), service, allowIsolated, dumpFlags).isOk()) {
        ALOGE("Failed to register service %s", name.c_str());
        return false;
    }

    if (!manager->registerClientCallback(name, service, this).isOk()) {
    if (!manager->registerClientCallback(name, service, this).isOk())
    {
      ALOGE("Failed to add client callback for service %s", name.c_str());
      return false;
    }

    if (!reRegister) {
        // Only add this when a service is added for the first time, as it is not removed
        mRegisteredServices[name] = {service, allowIsolated, dumpFlags};
    }
    mRegisteredServices.push_back({service, name, allowIsolated, dumpFlags});

    return true;
}
@@ -122,11 +119,10 @@ void ClientCounterCallback::tryShutdown() {
    for (; unRegisterIt != mRegisteredServices.end(); ++unRegisterIt) {
        auto& entry = (*unRegisterIt);

        bool success = manager->tryUnregisterService(entry.first, entry.second.service).isOk();

        bool success = manager->tryUnregisterService(entry.name, entry.service).isOk();

        if (!success) {
            ALOGI("Failed to unregister service %s", entry.first.c_str());
            ALOGI("Failed to unregister service %s", entry.name.c_str());
            break;
        }
    }
@@ -141,8 +137,7 @@ void ClientCounterCallback::tryShutdown() {
        auto& entry = (*reRegisterIt);

        // re-register entry
        if (!registerService(entry.second.service, entry.first, entry.second.allowIsolated,
                             entry.second.dumpFlags)) {
        if (!registerService(entry.service, entry.name, entry.allowIsolated, entry.dumpFlags)) {
            // Must restart. Otherwise, clients will never be able to get a hold of this service.
            ALOGE("Bad state: could not re-register services");
        }