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

Commit 2115bbe0 authored by Alex Stetson's avatar Alex Stetson
Browse files

Remove dumpable container from SystemUIApplication

It is not guaranteed that the dump manager is created prior to an
external process attempting to use the application as a dumpable
container. The dump manager should be used through a supplied dagger
instance instead to guarantee that it exists.

Bug: 271391142
Test: manual
Change-Id: I080c049f896c482b2da4efb4b2396afe78aa984d
parent d373da3c
Loading
Loading
Loading
Loading
+3 −42
Original line number Diff line number Diff line
@@ -31,9 +31,6 @@ import android.os.Process;
import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.Dumpable;
import android.util.DumpableContainer;
import android.util.Log;
import android.util.TimingsTraceLog;
import android.view.SurfaceControl;
@@ -57,18 +54,12 @@ import javax.inject.Provider;
 * Application class for SystemUI.
 */
public class SystemUIApplication extends Application implements
        SystemUIAppComponentFactory.ContextInitializer, DumpableContainer {
        SystemUIAppComponentFactory.ContextInitializer {

    public static final String TAG = "SystemUIService";
    private static final boolean DEBUG = false;

    private BootCompleteCacheImpl mBootCompleteCache;
    private DumpManager mDumpManager;

    /**
     * Map of dumpables added externally.
     */
    private final ArrayMap<String, Dumpable> mDumpables = new ArrayMap<>();

    /**
     * Hold a reference on the stuff we start.
@@ -233,7 +224,7 @@ public class SystemUIApplication extends Application implements
            }
        }

        mDumpManager = mSysUIComponent.createDumpManager();
        DumpManager dumpManager = mSysUIComponent.createDumpManager();

        Log.v(TAG, "Starting SystemUI services for user " +
                Process.myUserHandle().getIdentifier() + ".");
@@ -267,7 +258,7 @@ public class SystemUIApplication extends Application implements
                notifyBootCompleted(mServices[i]);
            }

            mDumpManager.registerDumpable(mServices[i].getClass().getName(), mServices[i]);
            dumpManager.registerDumpable(mServices[i].getClass().getName(), mServices[i]);
        }
        mSysUIComponent.getInitController().executePostInitTasks();
        log.traceEnd();
@@ -342,36 +333,6 @@ public class SystemUIApplication extends Application implements
        return startable;
    }

    // TODO(b/217567642): add unit tests? There doesn't seem to be a SystemUiApplicationTest...
    @Override
    public boolean addDumpable(Dumpable dumpable) {
        String name = dumpable.getDumpableName();
        if (mDumpables.containsKey(name)) {
            // This is normal because SystemUIApplication is an application context that is shared
            // among multiple components
            if (DEBUG) {
                Log.d(TAG, "addDumpable(): ignoring " + dumpable + " as there is already a dumpable"
                        + " with that name (" + name + "): " + mDumpables.get(name));
            }
            return false;
        }
        if (DEBUG) Log.d(TAG, "addDumpable(): adding '" + name + "' = " + dumpable);
        mDumpables.put(name, dumpable);

        // TODO(b/217567642): replace com.android.systemui.dump.Dumpable by
        // com.android.util.Dumpable and get rid of the intermediate lambda
        mDumpManager.registerDumpable(dumpable.getDumpableName(), dumpable::dump);
        return true;
    }

    // TODO(b/217567642): implement
    @Override
    public boolean removeDumpable(Dumpable dumpable) {
        Log.w(TAG, "removeDumpable(" + dumpable + "): not implemented");

        return false;
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        if (mServicesStarted) {