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

Commit 07242285 authored by Dave Mankoff's avatar Dave Mankoff Committed by Android (Google) Code Review
Browse files

Merge "Provide the ability to inject into SystemUI objects."

parents 8839020e aa8b7ae4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import dagger.Component;
                DependencyProvider.class,
                DependencyBinder.class,
                ServiceBinder.class,
                SystemUIBinder.class,
                SystemUIFactory.ContextHolder.class,
                SystemUIModule.class,
                CarSystemUIModule.class
+3 −0
Original line number Diff line number Diff line
@@ -24,4 +24,7 @@ import android.app.Service;
public interface ContextComponentHelper {
    /** Turns a classname into an instance of the class or returns null. */
    Service resolveService(String className);

    /** Turns a classname into an instance of the class or returns null. */
    SystemUI resolveSystemUI(String className);
}
+14 −1
Original line number Diff line number Diff line
@@ -22,17 +22,22 @@ import java.util.Map;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;

/**
 * Used during Service and Activity instantiation to make them injectable.
 */
@Singleton
public class ContextComponentResolver implements ContextComponentHelper {
    private final Map<Class<?>, Provider<Service>> mServiceCreators;
    private final Map<Class<?>, Provider<SystemUI>> mSystemUICreators;

    @Inject
    ContextComponentResolver(
            Map<Class<?>, Provider<Service>> serviceCreators) {
            Map<Class<?>, Provider<Service>> serviceCreators,
            Map<Class<?>, Provider<SystemUI>> systemUICreators) {
        mServiceCreators = serviceCreators;
        mSystemUICreators = systemUICreators;
    }

    /**
@@ -43,6 +48,14 @@ public class ContextComponentResolver implements ContextComponentHelper {
        return resolve(className, mServiceCreators);
    }

    /**
     * Looks up the SystemUI class name to see if Dagger has an instance of it.
     */
    @Override
    public SystemUI resolveSystemUI(String className) {
        return resolve(className, mSystemUICreators);
    }

    private <T> T resolve(String className, Map<Class<?>, Provider<T>> creators) {
        for (Map.Entry<Class<?>, Provider<T>> p : creators.entrySet()) {
            if (p.getKey().getName().equals(className)) {
+0 −4
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.os.Bundle;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.Map;
import java.util.function.Function;

public abstract class SystemUI implements SysUiServiceProvider {
    public Context mContext;
@@ -62,7 +61,4 @@ public abstract class SystemUI implements SysUiServiceProvider {

        n.addExtras(extras);
    }

    public interface Injector extends Function<Context, SystemUI> {
    }
}
+9 −7
Original line number Diff line number Diff line
@@ -54,6 +54,8 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
    public static final String TAG = "SystemUIService";
    private static final boolean DEBUG = false;

    private ContextComponentHelper mComponentHelper;

    /**
     * Hold a reference on the stuff we start.
     */
@@ -78,6 +80,8 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
                Trace.TRACE_TAG_APP);
        log.traceBegin("DependencyInjection");
        mContextAvailableCallback.onContextAvailable(this);
        mComponentHelper = SystemUIFactory
                .getInstance().getRootComponent().getContextComponentHelper();
        log.traceEnd();

        // Set the application theme that is inherited by all services. Note that setting the
@@ -186,14 +190,12 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
            if (DEBUG) Log.d(TAG, "loading: " + clsName);
            log.traceBegin("StartServices" + clsName);
            long ti = System.currentTimeMillis();
            Class cls;
            try {
                cls = Class.forName(clsName);
                Object o = cls.newInstance();
                if (o instanceof SystemUI.Injector) {
                    o = ((SystemUI.Injector) o).apply(this);
                SystemUI obj = mComponentHelper.resolveSystemUI(clsName);
                if (obj == null) {
                    obj = (SystemUI) Class.forName(clsName).newInstance();
                }
                mServices[i] = (SystemUI) o;
                mServices[i] = obj;
            } catch (ClassNotFoundException ex) {
                throw new RuntimeException(ex);
            } catch (IllegalAccessException ex) {
@@ -211,7 +213,7 @@ public class SystemUIApplication extends Application implements SysUiServiceProv
            // Warn if initialization of component takes too long
            ti = System.currentTimeMillis() - ti;
            if (ti > 1000) {
                Log.w(TAG, "Initialization of " + cls.getName() + " took " + ti + " ms");
                Log.w(TAG, "Initialization of " + clsName + " took " + ti + " ms");
            }
            if (mBootCompleted) {
                mServices[i].onBootCompleted();
Loading