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

Commit 436808f3 authored by Steven Moreland's avatar Steven Moreland Committed by Automerger Merge Worker
Browse files

Merge "servicemanager: log for service collision" am: af93203d am:...

Merge "servicemanager: log for service collision" am: af93203d am: 84e419d5 am: ea8c8388 am: 241d57e3 am: 667ddcd4

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2230788



Change-Id: I5370189011c670e87e38fd4559cad25cfeaeda2b
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents e6e1e8a8 667ddcd4
Loading
Loading
Loading
Loading
+35 −10
Original line number Diff line number Diff line
@@ -326,16 +326,41 @@ Status ServiceManager::addService(const std::string& name, const sp<IBinder>& bi
        return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE, "linkToDeath failure");
    }

    auto it = mNameToService.find(name);
    if (it != mNameToService.end()) {
        const Service& existing = it->second;

        // We could do better than this because if the other service dies, it
        // may not have an entry here. However, this case is unlikely. We are
        // only trying to detect when two different services are accidentally installed.

        if (existing.ctx.uid != ctx.uid) {
            LOG(WARNING) << "Service '" << name << "' originally registered from UID "
                         << existing.ctx.uid << " but it is now being registered from UID "
                         << ctx.uid << ". Multiple instances installed?";
        }

        if (existing.ctx.sid != ctx.sid) {
            LOG(WARNING) << "Service '" << name << "' originally registered from SID "
                         << existing.ctx.sid << " but it is now being registered from SID "
                         << ctx.sid << ". Multiple instances installed?";
        }

        LOG(INFO) << "Service '" << name << "' originally registered from PID "
                  << existing.ctx.debugPid << " but it is being registered again from PID "
                  << ctx.debugPid
                  << ". Bad state? Late death notification? Multiple instances installed?";
    }

    // Overwrite the old service if it exists
    mNameToService[name] = Service{
            .binder = binder,
            .allowIsolated = allowIsolated,
            .dumpPriority = dumpPriority,
        .debugPid = ctx.debugPid,
            .ctx = ctx,
    };

    auto it = mNameToRegistrationCallback.find(name);
    if (it != mNameToRegistrationCallback.end()) {
    if (auto it = mNameToRegistrationCallback.find(name); it != mNameToRegistrationCallback.end()) {
        for (const sp<IServiceCallback>& cb : it->second) {
            mNameToService[name].guaranteeClient = true;
            // permission checked in registerForNotifications
@@ -571,7 +596,7 @@ Status ServiceManager::registerClientCallback(const std::string& name, const sp<
        return Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT);
    }

    if (serviceIt->second.debugPid != IPCThreadState::self()->getCallingPid()) {
    if (serviceIt->second.ctx.debugPid != IPCThreadState::self()->getCallingPid()) {
        LOG(WARNING) << "Only a server can register for client callbacks (for " << name << ")";
        return Status::fromExceptionCode(Status::EX_UNSUPPORTED_OPERATION);
    }
@@ -707,7 +732,7 @@ Status ServiceManager::tryUnregisterService(const std::string& name, const sp<IB
        return Status::fromExceptionCode(Status::EX_ILLEGAL_STATE);
    }

    if (serviceIt->second.debugPid != IPCThreadState::self()->getCallingPid()) {
    if (serviceIt->second.ctx.debugPid != IPCThreadState::self()->getCallingPid()) {
        LOG(WARNING) << "Only a server can unregister itself (for " << name << ")";
        return Status::fromExceptionCode(Status::EX_UNSUPPORTED_OPERATION);
    }
@@ -754,7 +779,7 @@ Status ServiceManager::getServiceDebugInfo(std::vector<ServiceDebugInfo>* outRet
    for (auto const& [name, service] : mNameToService) {
        ServiceDebugInfo info;
        info.name = name;
        info.debugPid = service.debugPid;
        info.debugPid = service.ctx.debugPid;

        outReturn->push_back(std::move(info));
    }
+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ private:
        int32_t dumpPriority;
        bool hasClients = false; // notifications sent on true -> false.
        bool guaranteeClient = false; // forces the client check to true
        pid_t debugPid = 0; // the process in which this service runs
        Access::CallingContext ctx;   // process that originally registers this

        // the number of clients of the service, including servicemanager itself
        ssize_t getNodeStrongRefCount();