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

Commit 9b623c33 authored by Robert Carr's avatar Robert Carr Committed by Rob Carr
Browse files

SurfaceFlinger: Avoid race in flag manager

Initializing the flag manager from one binder
thread while using it from another doesn't seem
very safe. This is in fact what could happen if
onBootFinished overlaps with dump, the objects constructor
doesn't do anything in particular so we can just default
construct it as a value member instead.

Bug: 219059993
Test: Existing tests pass
Change-Id: I7162812b000d67adb9ed745d31d8bac8b2e8f73e
parent 88b85e1f
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -707,10 +707,9 @@ void SurfaceFlinger::bootFinished() {
    const nsecs_t duration = now - mBootTime;
    ALOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) );

    mFlagManager = std::make_unique<android::FlagManager>();
    mFrameTracer->initialize();
    mFrameTimeline->onBootFinished();
    getRenderEngine().setEnableTracing(mFlagManager->use_skia_tracing());
    getRenderEngine().setEnableTracing(mFlagManager.use_skia_tracing());

    // wait patiently for the window manager death
    const String16 name("window");
@@ -745,7 +744,7 @@ void SurfaceFlinger::bootFinished() {
            tidList.emplace_back(*renderEngineTid);
        }
        mPowerAdvisor.onBootFinished();
        mPowerAdvisor.enablePowerHint(mFlagManager->use_adpf_cpu_hint());
        mPowerAdvisor.enablePowerHint(mFlagManager.use_adpf_cpu_hint());
        if (mPowerAdvisor.usePowerHintSession()) {
            mPowerAdvisor.startPowerHintSession(tidList);
        }
@@ -5436,9 +5435,7 @@ void SurfaceFlinger::dumpAllLocked(const DumpArgs& args, std::string& result) co
    /*
     * Dump flag/property manager state
     */
    if (mFlagManager != nullptr) {
        mFlagManager->dump(result);
    }
    mFlagManager.dump(result);

    result.append(mTimeStats->miniDump());
    result.append("\n");
+2 −1
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@
#include "DisplayHardware/PowerAdvisor.h"
#include "DisplayIdGenerator.h"
#include "Effects/Daltonizer.h"
#include "FlagManager.h"
#include "FrameTracker.h"
#include "LayerVector.h"
#include "Scheduler/RefreshRateConfigs.h"
@@ -1413,7 +1414,7 @@ private:

    const sp<WindowInfosListenerInvoker> mWindowInfosListenerInvoker;

    std::unique_ptr<FlagManager> mFlagManager;
    FlagManager mFlagManager;

    // returns the framerate of the layer with the given sequence ID
    float getLayerFramerate(nsecs_t now, int32_t id) const {