Loading packages/SystemUI/customization/src/com/android/systemui/shared/clocks/ClockRegistry.kt +4 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.net.Uri import android.os.UserHandle import android.provider.Settings import androidx.annotation.OpenForTesting import com.android.systemui.log.LogBuffer import com.android.systemui.log.core.LogLevel import com.android.systemui.log.core.LogcatOnlyMessageBuffer import com.android.systemui.log.core.Logger Loading Loading @@ -120,8 +121,9 @@ open class ClockRegistry( override fun onPluginAttached( manager: PluginLifecycleManager<ClockProviderPlugin> ): Boolean { manager.isDebug = !keepAllLoaded manager.setLogFunc({ tag, msg -> (clockBuffers?.infraMessageBuffer as LogBuffer?)?.log(tag, LogLevel.DEBUG, msg) }) if (keepAllLoaded) { // Always load new plugins if requested return true Loading packages/SystemUI/plugin_core/src/com/android/systemui/plugins/PluginLifecycleManager.java +4 −5 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.systemui.plugins; import android.content.ComponentName; import java.util.function.BiConsumer; /** * Provides the ability for consumers to control plugin lifecycle. * Loading @@ -33,11 +35,8 @@ public interface PluginLifecycleManager<T extends Plugin> { /** Returns the currently loaded plugin instance (if plugin is loaded) */ T getPlugin(); /** Returns true if the lifecycle manager should log debug messages */ boolean getIsDebug(); /** Sets whether or not hte lifecycle manager should log debug messages */ void setIsDebug(boolean debug); /** Log tag and messages will be sent to the provided Consumer */ void setLogFunc(BiConsumer<String, String> logConsumer); /** returns true if the plugin is currently loaded */ default boolean isLoaded() { Loading packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginInstance.java +15 −18 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import dalvik.system.PathClassLoader; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.function.BiConsumer; import java.util.function.Supplier; /** Loading @@ -57,7 +58,7 @@ public class PluginInstance<T extends Plugin> implements PluginLifecycleManager private final PluginFactory<T> mPluginFactory; private final String mTag; private boolean mIsDebug = false; private BiConsumer<String, String> mLogConsumer = null; private Context mPluginContext; private T mPlugin; Loading Loading @@ -86,17 +87,13 @@ public class PluginInstance<T extends Plugin> implements PluginLifecycleManager return mTag; } public boolean getIsDebug() { return mIsDebug; public void setLogFunc(BiConsumer logConsumer) { mLogConsumer = logConsumer; } public void setIsDebug(boolean debug) { mIsDebug = debug; } private void logDebug(String message) { if (mIsDebug) { Log.i(mTag, message); private void log(String message) { if (mLogConsumer != null) { mLogConsumer.accept(mTag, message); } } Loading @@ -105,19 +102,19 @@ public class PluginInstance<T extends Plugin> implements PluginLifecycleManager boolean loadPlugin = mListener.onPluginAttached(this); if (!loadPlugin) { if (mPlugin != null) { logDebug("onCreate: auto-unload"); log("onCreate: auto-unload"); unloadPlugin(); } return; } if (mPlugin == null) { logDebug("onCreate auto-load"); log("onCreate auto-load"); loadPlugin(); return; } logDebug("onCreate: load callbacks"); log("onCreate: load callbacks"); mPluginFactory.checkVersion(mPlugin); if (!(mPlugin instanceof PluginFragment)) { // Only call onCreate for plugins that aren't fragments, as fragments Loading @@ -129,7 +126,7 @@ public class PluginInstance<T extends Plugin> implements PluginLifecycleManager /** Alerts listener and plugin that the plugin is being shutdown. */ public synchronized void onDestroy() { logDebug("onDestroy"); log("onDestroy"); unloadPlugin(); mListener.onPluginDetached(this); } Loading @@ -145,7 +142,7 @@ public class PluginInstance<T extends Plugin> implements PluginLifecycleManager */ public synchronized void loadPlugin() { if (mPlugin != null) { logDebug("Load request when already loaded"); log("Load request when already loaded"); return; } Loading @@ -157,7 +154,7 @@ public class PluginInstance<T extends Plugin> implements PluginLifecycleManager return; } logDebug("Loaded plugin; running callbacks"); log("Loaded plugin; running callbacks"); mPluginFactory.checkVersion(mPlugin); if (!(mPlugin instanceof PluginFragment)) { // Only call onCreate for plugins that aren't fragments, as fragments Loading @@ -174,11 +171,11 @@ public class PluginInstance<T extends Plugin> implements PluginLifecycleManager */ public synchronized void unloadPlugin() { if (mPlugin == null) { logDebug("Unload request when already unloaded"); log("Unload request when already unloaded"); return; } logDebug("Unloading plugin, running callbacks"); log("Unloading plugin, running callbacks"); mListener.onPluginUnloaded(mPlugin, this); if (!(mPlugin instanceof PluginFragment)) { // Only call onDestroy for plugins that aren't fragments, as fragments Loading packages/SystemUI/tests/src/com/android/systemui/shared/clocks/ClockRegistryTest.kt +2 −4 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import com.android.systemui.plugins.PluginListener import com.android.systemui.plugins.PluginManager import com.android.systemui.util.mockito.argumentCaptor import com.android.systemui.util.mockito.eq import java.util.function.BiConsumer import junit.framework.Assert.assertEquals import junit.framework.Assert.fail import kotlinx.coroutines.CoroutineDispatcher Loading Loading @@ -100,10 +101,7 @@ class ClockRegistryTest : SysuiTestCase() { override fun toString() = "Manager[$tag]" override fun getPackage(): String = mComponentName.getPackageName() override fun getComponentName(): ComponentName = mComponentName private var isDebug: Boolean = false override fun getIsDebug(): Boolean = isDebug override fun setIsDebug(value: Boolean) { isDebug = value } override fun setLogFunc(func: BiConsumer<String, String>) { } override fun loadPlugin() { if (!mIsLoaded) { Loading packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -112,7 +112,7 @@ public class PluginInstanceTest extends SysuiTestCase { mPluginInstance = mPluginInstanceFactory.create( mContext, mAppInfo, TEST_PLUGIN_COMPONENT_NAME, TestPlugin.class, mPluginListener); mPluginInstance.setIsDebug(true); mPluginInstance.setLogFunc((tag, msg) -> Log.d((String) tag, (String) msg)); mPluginContext = new WeakReference<>(mPluginInstance.getPluginContext()); } Loading Loading
packages/SystemUI/customization/src/com/android/systemui/shared/clocks/ClockRegistry.kt +4 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.net.Uri import android.os.UserHandle import android.provider.Settings import androidx.annotation.OpenForTesting import com.android.systemui.log.LogBuffer import com.android.systemui.log.core.LogLevel import com.android.systemui.log.core.LogcatOnlyMessageBuffer import com.android.systemui.log.core.Logger Loading Loading @@ -120,8 +121,9 @@ open class ClockRegistry( override fun onPluginAttached( manager: PluginLifecycleManager<ClockProviderPlugin> ): Boolean { manager.isDebug = !keepAllLoaded manager.setLogFunc({ tag, msg -> (clockBuffers?.infraMessageBuffer as LogBuffer?)?.log(tag, LogLevel.DEBUG, msg) }) if (keepAllLoaded) { // Always load new plugins if requested return true Loading
packages/SystemUI/plugin_core/src/com/android/systemui/plugins/PluginLifecycleManager.java +4 −5 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.systemui.plugins; import android.content.ComponentName; import java.util.function.BiConsumer; /** * Provides the ability for consumers to control plugin lifecycle. * Loading @@ -33,11 +35,8 @@ public interface PluginLifecycleManager<T extends Plugin> { /** Returns the currently loaded plugin instance (if plugin is loaded) */ T getPlugin(); /** Returns true if the lifecycle manager should log debug messages */ boolean getIsDebug(); /** Sets whether or not hte lifecycle manager should log debug messages */ void setIsDebug(boolean debug); /** Log tag and messages will be sent to the provided Consumer */ void setLogFunc(BiConsumer<String, String> logConsumer); /** returns true if the plugin is currently loaded */ default boolean isLoaded() { Loading
packages/SystemUI/shared/src/com/android/systemui/shared/plugins/PluginInstance.java +15 −18 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import dalvik.system.PathClassLoader; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.function.BiConsumer; import java.util.function.Supplier; /** Loading @@ -57,7 +58,7 @@ public class PluginInstance<T extends Plugin> implements PluginLifecycleManager private final PluginFactory<T> mPluginFactory; private final String mTag; private boolean mIsDebug = false; private BiConsumer<String, String> mLogConsumer = null; private Context mPluginContext; private T mPlugin; Loading Loading @@ -86,17 +87,13 @@ public class PluginInstance<T extends Plugin> implements PluginLifecycleManager return mTag; } public boolean getIsDebug() { return mIsDebug; public void setLogFunc(BiConsumer logConsumer) { mLogConsumer = logConsumer; } public void setIsDebug(boolean debug) { mIsDebug = debug; } private void logDebug(String message) { if (mIsDebug) { Log.i(mTag, message); private void log(String message) { if (mLogConsumer != null) { mLogConsumer.accept(mTag, message); } } Loading @@ -105,19 +102,19 @@ public class PluginInstance<T extends Plugin> implements PluginLifecycleManager boolean loadPlugin = mListener.onPluginAttached(this); if (!loadPlugin) { if (mPlugin != null) { logDebug("onCreate: auto-unload"); log("onCreate: auto-unload"); unloadPlugin(); } return; } if (mPlugin == null) { logDebug("onCreate auto-load"); log("onCreate auto-load"); loadPlugin(); return; } logDebug("onCreate: load callbacks"); log("onCreate: load callbacks"); mPluginFactory.checkVersion(mPlugin); if (!(mPlugin instanceof PluginFragment)) { // Only call onCreate for plugins that aren't fragments, as fragments Loading @@ -129,7 +126,7 @@ public class PluginInstance<T extends Plugin> implements PluginLifecycleManager /** Alerts listener and plugin that the plugin is being shutdown. */ public synchronized void onDestroy() { logDebug("onDestroy"); log("onDestroy"); unloadPlugin(); mListener.onPluginDetached(this); } Loading @@ -145,7 +142,7 @@ public class PluginInstance<T extends Plugin> implements PluginLifecycleManager */ public synchronized void loadPlugin() { if (mPlugin != null) { logDebug("Load request when already loaded"); log("Load request when already loaded"); return; } Loading @@ -157,7 +154,7 @@ public class PluginInstance<T extends Plugin> implements PluginLifecycleManager return; } logDebug("Loaded plugin; running callbacks"); log("Loaded plugin; running callbacks"); mPluginFactory.checkVersion(mPlugin); if (!(mPlugin instanceof PluginFragment)) { // Only call onCreate for plugins that aren't fragments, as fragments Loading @@ -174,11 +171,11 @@ public class PluginInstance<T extends Plugin> implements PluginLifecycleManager */ public synchronized void unloadPlugin() { if (mPlugin == null) { logDebug("Unload request when already unloaded"); log("Unload request when already unloaded"); return; } logDebug("Unloading plugin, running callbacks"); log("Unloading plugin, running callbacks"); mListener.onPluginUnloaded(mPlugin, this); if (!(mPlugin instanceof PluginFragment)) { // Only call onDestroy for plugins that aren't fragments, as fragments Loading
packages/SystemUI/tests/src/com/android/systemui/shared/clocks/ClockRegistryTest.kt +2 −4 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import com.android.systemui.plugins.PluginListener import com.android.systemui.plugins.PluginManager import com.android.systemui.util.mockito.argumentCaptor import com.android.systemui.util.mockito.eq import java.util.function.BiConsumer import junit.framework.Assert.assertEquals import junit.framework.Assert.fail import kotlinx.coroutines.CoroutineDispatcher Loading Loading @@ -100,10 +101,7 @@ class ClockRegistryTest : SysuiTestCase() { override fun toString() = "Manager[$tag]" override fun getPackage(): String = mComponentName.getPackageName() override fun getComponentName(): ComponentName = mComponentName private var isDebug: Boolean = false override fun getIsDebug(): Boolean = isDebug override fun setIsDebug(value: Boolean) { isDebug = value } override fun setLogFunc(func: BiConsumer<String, String>) { } override fun loadPlugin() { if (!mIsLoaded) { Loading
packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -112,7 +112,7 @@ public class PluginInstanceTest extends SysuiTestCase { mPluginInstance = mPluginInstanceFactory.create( mContext, mAppInfo, TEST_PLUGIN_COMPONENT_NAME, TestPlugin.class, mPluginListener); mPluginInstance.setIsDebug(true); mPluginInstance.setLogFunc((tag, msg) -> Log.d((String) tag, (String) msg)); mPluginContext = new WeakReference<>(mPluginInstance.getPluginContext()); } Loading