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

Commit c6dff3db authored by Dan Sandler's avatar Dan Sandler Committed by Daniel Sandler
Browse files

Clean up DozeService plugin listeners.

Also adds some additional debugging:
`adb shell dumpsys activity service SystemUI` will now dump
the plugin map. This will help us discover leaks that happen
to interact with plugins, or leaks in the plugins themselves.

(Note that plugins only work on debuggable builds.)

Bug: 72138063
Test: adb shell dumpsys activity service SystemUI
Change-Id: I328aeb9a0940404760e9121ef26a0518371b8319
parent 581576ef
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;

import com.android.internal.os.BinderInternal;
import com.android.systemui.plugins.PluginManager;
import com.android.systemui.plugins.PluginManagerImpl;

public class SystemUIService extends Service {

@@ -70,6 +72,10 @@ public class SystemUIService extends Service {
                pw.println("dumping service: " + ui.getClass().getName());
                ui.dump(fd, pw, args);
            }
            if (Build.IS_DEBUGGABLE) {
                pw.println("dumping plugins:");
                ((PluginManagerImpl) Dependency.get(PluginManager.class)).dump(fd, pw, args);
            }
        } else {
            String svc = args[0];
            for (SystemUI ui: services) {
+6 −0
Original line number Diff line number Diff line
@@ -58,6 +58,12 @@ public class DozeService extends DreamService
        mDozeMachine = new DozeFactory().assembleMachine(this);
    }

    @Override
    public void onDestroy() {
        Dependency.get(PluginManager.class).removePluginListener(this);
        super.onDestroy();
    }

    @Override
    public void onPluginConnected(DozeServicePlugin plugin, Context pluginContext) {
        mDozePlugin = plugin;
+6 −0
Original line number Diff line number Diff line
@@ -168,6 +168,12 @@ public class PluginInstanceManager<T extends Plugin> {
        return false;
    }

    @Override
    public String toString() {
        return String.format("%s@%s (action=%s)",
                getClass().getSimpleName(), hashCode(), mAction);
    }

    private class MainHandler extends Handler {
        private static final int PLUGIN_CONNECTED = 1;
        private static final int PLUGIN_DISCONNECTED = 2;
+10 −0
Original line number Diff line number Diff line
@@ -50,6 +50,8 @@ import com.android.systemui.plugins.annotations.ProvidesInterface;

import dalvik.system.PathClassLoader;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.Map;

@@ -303,6 +305,14 @@ public class PluginManagerImpl extends BroadcastReceiver implements PluginManage
        }
    }

    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.println(String.format("  plugin map (%d):", mPluginMap.size()));
        for (PluginListener listener: mPluginMap.keySet()) {
            pw.println(String.format("    %s -> %s",
                    listener, mPluginMap.get(listener)));
        }
    }

    @VisibleForTesting
    public static class PluginInstanceManagerFactory {
        public <T extends Plugin> PluginInstanceManager createPluginInstanceManager(Context context,