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

Commit 6bf87b6a authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge "ServiceSingleton: Improve robustness and logging" into main

parents 1ebbbedc 96ff53af
Loading
Loading
Loading
Loading
+16 −8
Original line number Diff line number Diff line
@@ -155,8 +155,8 @@ public:
                return;
            }
            if (!mService || mService->getDelegate() != service) {
                ALOGW("%s: %s unmatched service death pointers, ignoring",
                        __func__, getServiceName());
                ALOGW("%s: %s unmatched service death pointers, previous %p, ignoring",
                        __func__, getServiceName(), mService.get());
                return;
            }
            mValid = false;
@@ -1002,6 +1002,10 @@ public:
        sp<AudioSystem::AudioPolicyServiceClient> client;
        {
            std::lock_guard l(mMutex);
            if (aps == mService) {
                ALOGW_IF("%s: %s same service, ignoring", __func__, getServiceName());
                return;
            }
            ALOGW_IF(mValid, "%s: %s service already valid, continuing with initialization",
                    __func__, getServiceName());
            if (mClient == nullptr) {
@@ -1025,12 +1029,13 @@ public:
        {
            std::lock_guard l(mMutex);
            if (!mValid) {
                ALOGW("%s: %s service already invalidated, ignoring", __func__, getServiceName());
                ALOGW("%s: %s service already invalidated, previous %p, ignoring",
                        __func__, getServiceName(), mService.get());
                return;
            }
            if (mService != service) {
                ALOGW("%s: %s unmatched service death pointers, ignoring",
                        __func__, getServiceName());
                ALOGW("%s: %s unmatched service death pointers, previous %p, ignoring",
                        __func__, getServiceName(), mService.get());
                return;
            }
            mValid = false;
@@ -1108,9 +1113,12 @@ public:
                return OK;
            }
        }
        mService = aps;
        if (aps) {
            ul.unlock();
        if (aps) onNewService(aps);
            onNewService(aps);
        } else {
            mService = nullptr;
        }
        return OK;
    }

+11 −0
Original line number Diff line number Diff line
@@ -331,6 +331,9 @@ private:
                        traits->onNewService(service);
                        ul.lock();
                        setDeathNotifier_l<Service>(service);
                    } else {
                        ALOGW("%s: ignoring duplicated service: %p",
                                __func__, originalService.get());
                    }
                    ul.unlock();
                    mCv.notify_all();
@@ -358,6 +361,14 @@ private:
                        // we do not need to generation count.
                        {
                            std::lock_guard l(mMutex);
                            const auto currentService =
                                    std::get<BaseInterfaceType<Service>>(mService);
                            if (currentService != service) {
                                ALOGW("%s: ignoring death as current service "
                                        "%p != registered death service %p", __func__,
                                        currentService.get(), service.get());
                                return;
                            }
                            invalidateService_l<Service>();
                        }
                        traits->onServiceDied(service);