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

Commit 037d9fcd authored by Dave Mankoff's avatar Dave Mankoff
Browse files

Initialize Dependency with the Application when Dagger starts.

Dependency is no longer a subclass of SystemUI. It gets initialized
directly as part of the application, just like the rest of Dagger.
It was an awkward implementation of SystemUI anyways.

Bug: 137324767
Change-Id: Icf49e9262e8c0710210a8bc0231c4d16396ffdf3
Test: atest SystemUITests
parent 285bf9df
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -276,7 +276,6 @@

    <!-- SystemUI Services: The classes of the stuff to start. -->
    <string-array name="config_systemUIServiceComponents" translatable="false">
        <item>com.android.systemui.Dependency$DependencyCreator</item>
        <item>com.android.systemui.util.NotificationChannels</item>
        <item>com.android.systemui.statusbar.CommandQueue$CommandQueueStart</item>
        <item>com.android.systemui.keyguard.KeyguardViewMediator</item>
@@ -307,7 +306,6 @@

    <!-- SystemUI Services (per user): The classes of the stuff to start for each user. This is a subset of the config_systemUIServiceComponents -->
    <string-array name="config_systemUIServiceComponentsPerUser" translatable="false">
        <item>com.android.systemui.Dependency$DependencyCreator</item>
        <item>com.android.systemui.util.NotificationChannels</item>
    </string-array>

+26 −37
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@ package com.android.systemui;

import android.annotation.Nullable;
import android.app.INotificationManager;
import android.content.Context;
import android.content.res.Configuration;
import android.hardware.SensorPrivacyManager;
import android.hardware.display.NightDisplayListener;
@@ -114,7 +113,6 @@ import com.android.systemui.util.leak.LeakReporter;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.function.Consumer;

import javax.inject.Inject;
@@ -138,9 +136,7 @@ import dagger.Subcomponent;
 * they have no clients they should not have any registered resources like bound
 * services, registered receivers, etc.
 */
public class Dependency extends SystemUI {
    private static final String TAG = "Dependency";

public class Dependency {
    /**
     * Key for getting a background Looper for background work.
     */
@@ -305,8 +301,20 @@ public class Dependency extends SystemUI {
    public Dependency() {
    }

    @Override
    public void start() {

    /**
     * Initialize Depenency.
     */
    public static void initDependencies(SystemUIRootComponent rootComponent) {
        if (sDependency != null) {
            return;
        }
        sDependency = new Dependency();
        rootComponent.createDependency().createSystemUI(sDependency);
        sDependency.start();
    }

    protected void start() {
        // TODO: Think about ways to push these creation rules out of Dependency to cut down
        // on imports.
        mProviders.put(TIME_TICK_HANDLER, mTimeTickHandler::get);
@@ -486,10 +494,14 @@ public class Dependency extends SystemUI {
        sDependency = this;
    }

    @Override
    public synchronized void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        super.dump(fd, pw, args);
    static void staticDump(FileDescriptor fd, PrintWriter pw, String[] args) {
        sDependency.dump(fd, pw, args);
    }

    /**
     * {@see SystemUI.dump}
     */
    public synchronized void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        // Make sure that the DumpController gets added to mDependencies, as they are only added
        // with Dependency#get.
        getDependency(DumpController.class);
@@ -509,9 +521,11 @@ public class Dependency extends SystemUI {
                .forEach(o -> ((Dumpable) o).dump(fd, pw, args));
    }

    @Override
    protected static void staticOnConfigurationChanged(Configuration newConfig) {
        sDependency.onConfigurationChanged(newConfig);
    }

    protected synchronized void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        mDependencies.values().stream().filter(obj -> obj instanceof ConfigurationChangedReceiver)
                .forEach(o -> ((ConfigurationChangedReceiver) o).onConfigurationChanged(newConfig));
    }
@@ -564,20 +578,6 @@ public class Dependency extends SystemUI {
        }
    }

    /**
     * Used in separate processes (like tuner settings) to init the dependencies.
     */
    public static void initDependencies(Context context) {
        if (sDependency != null) return;
        Dependency d = new Dependency();
        SystemUIFactory.getInstance().getRootComponent()
                .createDependency()
                .createSystemUI(d);
        d.mContext = context;
        d.mComponents = new HashMap<>();
        d.start();
    }

    /**
     * Used in separate process teardown to ensure the context isn't leaked.
     *
@@ -629,15 +629,4 @@ public class Dependency extends SystemUI {
    public interface DependencyInjector {
        void createSystemUI(Dependency dependency);
    }

    public static class DependencyCreator implements Injector {
        @Override
        public SystemUI apply(Context context) {
            Dependency dependency = new Dependency();
            SystemUIFactory.getInstance().getRootComponent()
                    .createDependency()
                    .createSystemUI(dependency);
            return dependency;
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ public final class ForegroundServicesDialog extends AlertActivity implements
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Dependency.initDependencies(getApplicationContext());
        Dependency.initDependencies(SystemUIFactory.getInstance().getRootComponent());

        mMetricsLogger = Dependency.get(MetricsLogger.class);

+15 −3
Original line number Diff line number Diff line
@@ -62,19 +62,28 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
    private final Map<Class<?>, Object> mComponents = new HashMap<>();
    private ContextAvailableCallback mContextAvailableCallback;

    public SystemUIApplication() {
        super();
        Log.v(TAG, "SystemUIApplication constructed.");
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.v(TAG, "SystemUIApplication created.");
        // This line is used to setup Dagger's dependency injection and should be kept at the
        // top of this method.
        TimingsTraceLog log = new TimingsTraceLog("SystemUIBootTiming",
                Trace.TRACE_TAG_APP);
        log.traceBegin("DependencyInjection");
        mContextAvailableCallback.onContextAvailable(this);
        log.traceEnd();

        // Set the application theme that is inherited by all services. Note that setting the
        // application theme in the manifest does only work for activities. Keep this in sync with
        // the theme set there.
        setTheme(R.style.Theme_SystemUI);


        if (Process.myUserHandle().equals(UserHandle.SYSTEM)) {
            IntentFilter bootCompletedFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
            bootCompletedFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
@@ -138,7 +147,7 @@ public class SystemUIApplication extends Application implements SysUiServiceProv

    /**
     * Ensures that all the Secondary user SystemUI services are running. If they are already
     * running, this is a no-op. This is needed to conditinally start all the services, as we only
     * running, this is a no-op. This is needed to conditionally start all the services, as we only
     * need to have it in the main process.
     * <p>This method must only be called from the main thread.</p>
     */
@@ -159,7 +168,9 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
            // see ActivityManagerService.finishBooting()
            if ("1".equals(SystemProperties.get("sys.boot_completed"))) {
                mBootCompleted = true;
                if (DEBUG) Log.v(TAG, "BOOT_COMPLETED was already sent");
                if (DEBUG) {
                    Log.v(TAG, "BOOT_COMPLETED was already sent");
                }
            }
        }

@@ -273,6 +284,7 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        if (mServicesStarted) {
            Dependency.staticOnConfigurationChanged(newConfig);
            int len = mServices.length;
            for (int i = 0; i < len; i++) {
                if (mServices[i] != null) {
+5 −1
Original line number Diff line number Diff line
@@ -115,6 +115,10 @@ public class SystemUIFactory {
                .dependencyProvider(new com.android.systemui.DependencyProvider())
                .contextHolder(new ContextHolder(context))
                .build();

        // Every other part of our codebase currently relies on Dependency, so we
        // really need to ensure the Dependency gets initialized early on.
        Dependency.initDependencies(mRootComponent);
    }

    public SystemUIRootComponent getRootComponent() {
Loading