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

Commit de850bbc authored by Jason Monk's avatar Jason Monk
Browse files

Fix leaks in sysui

Add support for testing for PluginManager and TunerService leaks
and add tests for the known leaks and fix them. Also port PluginManager
and TunerService to Dependency to make them easier to handle in
tests.

Test: runtest systemui
Change-Id: I5642539ee24dd72f802905106decd0c87b41b4eb
Fixes: 34846972
parent 33559507
Loading
Loading
Loading
Loading
+1 −8
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ public class PluginManager extends BroadcastReceiver {
    private boolean mListening;
    private boolean mHasOneShot;

    private PluginManager(Context context) {
    public PluginManager(Context context) {
        this(context, new PluginInstanceManagerFactory(),
                Build.IS_DEBUGGABLE, Thread.getDefaultUncaughtExceptionHandler());
    }
@@ -252,13 +252,6 @@ public class PluginManager extends BroadcastReceiver {
        return new PluginContextWrapper(mContext.createApplicationContext(info, 0), classLoader);
    }

    public static PluginManager getInstance(Context context) {
        if (sInstance == null) {
            sInstance = new PluginManager(context.getApplicationContext());
        }
        return sInstance;
    }

    private class AllPluginClassLoader extends ClassLoader {
        public AllPluginClassLoader(ClassLoader classLoader) {
            super(classLoader);
+2 −0
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ public interface NavGesture extends Plugin {
        public boolean onInterceptTouchEvent(MotionEvent event);

        public void setBarState(boolean vertical, boolean isRtl);

        public default void destroy() { }
    }

}
+2 −2
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ public class BatteryMeterView extends ImageView implements
        mDrawable.setBatteryController(mBatteryController);
        mBatteryController.addCallback(this);
        mDrawable.startListening();
        TunerService.get(getContext()).addTunable(this, StatusBarIconController.ICON_BLACKLIST);
        Dependency.get(TunerService.class).addTunable(this, StatusBarIconController.ICON_BLACKLIST);
    }

    @Override
@@ -84,7 +84,7 @@ public class BatteryMeterView extends ImageView implements
        super.onDetachedFromWindow();
        mBatteryController.removeCallback(this);
        mDrawable.stopListening();
        TunerService.get(getContext()).removeTunable(this);
        Dependency.get(TunerService.class).removeTunable(this);
    }

    @Override
+21 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@

package com.android.systemui;

import android.content.Context;
import android.content.res.Configuration;
import android.os.Handler;
import android.os.HandlerThread;
@@ -23,6 +24,7 @@ import android.util.ArrayMap;

import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.assist.AssistManager;
import com.android.systemui.plugins.PluginManager;
import com.android.systemui.statusbar.phone.ManagedProfileController;
import com.android.systemui.statusbar.phone.ManagedProfileControllerImpl;
import com.android.systemui.statusbar.policy.AccessibilityController;
@@ -56,9 +58,11 @@ import com.android.systemui.statusbar.policy.UserInfoControllerImpl;
import com.android.systemui.statusbar.policy.UserSwitcherController;
import com.android.systemui.statusbar.policy.ZenModeController;
import com.android.systemui.statusbar.policy.ZenModeControllerImpl;
import com.android.systemui.tuner.TunerService;

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

/**
 * Class to handle ugly dependencies throughout sysui until we determine the
@@ -167,12 +171,18 @@ public class Dependency extends SystemUI {
        mProviders.put(DeviceProvisionedController.class.getName(), () ->
                new DeviceProvisionedControllerImpl(mContext));

        mProviders.put(PluginManager.class.getName(), () ->
                new PluginManager(mContext));

        mProviders.put(AssistManager.class.getName(), () ->
                new AssistManager(getDependency(DeviceProvisionedController.class), mContext));

        mProviders.put(SecurityController.class.getName(), () ->
                new SecurityControllerImpl(mContext));

        mProviders.put(TunerService.class.getName(), () ->
                new TunerService(mContext));

        // Put all dependencies above here so the factory can override them if it wants.
        SystemUIFactory.getInstance().injectDependencies(mProviders, mContext);
    }
@@ -220,6 +230,17 @@ public class Dependency extends SystemUI {
        T createDependency();
    }

    /**
     * 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();
        d.mContext = context.getApplicationContext();
        d.mComponents = new HashMap<>();
        d.start();
    }

    public static <T> T get(Class<T> cls) {
        return sDependency.getDependency(cls.getName());
    }
+2 −2
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ public class PluginInflateContainer extends AutoReinflateContainer
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (mAction != null) {
            PluginManager.getInstance(getContext()).addPluginListener(mAction, this, mVersion);
            Dependency.get(PluginManager.class).addPluginListener(mAction, this, mVersion);
        }
    }

@@ -84,7 +84,7 @@ public class PluginInflateContainer extends AutoReinflateContainer
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if (mAction != null) {
            PluginManager.getInstance(getContext()).removePluginListener(this);
            Dependency.get(PluginManager.class).removePluginListener(this);
        }
    }

Loading