Loading packages/SystemUI/customization/src/com/android/systemui/shared/clocks/ClockRegistry.kt +91 −31 Original line number Diff line number Diff line Loading @@ -32,6 +32,12 @@ import com.android.systemui.plugins.ClockSettings import com.android.systemui.plugins.PluginLifecycleManager import com.android.systemui.plugins.PluginListener import com.android.systemui.plugins.PluginManager import com.android.systemui.plugins.log.LogBuffer import com.android.systemui.plugins.log.LogLevel import com.android.systemui.plugins.log.LogMessage import com.android.systemui.plugins.log.LogMessageImpl import com.android.systemui.plugins.log.MessageInitializer import com.android.systemui.plugins.log.MessagePrinter import com.android.systemui.util.Assert import java.io.PrintWriter import java.util.concurrent.ConcurrentHashMap Loading @@ -40,7 +46,6 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch private const val DEBUG = true private val KEY_TIMESTAMP = "appliedTimestamp" private fun <TKey, TVal> ConcurrentHashMap<TKey, TVal>.concurrentGetOrPut( Loading @@ -55,6 +60,32 @@ private fun <TKey, TVal> ConcurrentHashMap<TKey, TVal>.concurrentGetOrPut( return result ?: value } private val TMP_MESSAGE: LogMessage by lazy { LogMessageImpl.Factory.create() } private inline fun LogBuffer?.tryLog( tag: String, level: LogLevel, messageInitializer: MessageInitializer, noinline messagePrinter: MessagePrinter, ex: Throwable? = null, ) { if (this != null) { // Wrap messagePrinter to convert it from crossinline to noinline this.log(tag, level, messageInitializer, messagePrinter, ex) } else { messageInitializer(TMP_MESSAGE) val msg = messagePrinter(TMP_MESSAGE) when (level) { LogLevel.VERBOSE -> Log.v(tag, msg, ex) LogLevel.DEBUG -> Log.d(tag, msg, ex) LogLevel.INFO -> Log.i(tag, msg, ex) LogLevel.WARNING -> Log.w(tag, msg, ex) LogLevel.ERROR -> Log.e(tag, msg, ex) LogLevel.WTF -> Log.wtf(tag, msg, ex) } } } /** ClockRegistry aggregates providers and plugins */ open class ClockRegistry( val context: Context, Loading @@ -66,8 +97,9 @@ open class ClockRegistry( val handleAllUsers: Boolean, defaultClockProvider: ClockProvider, val fallbackClockId: ClockId = DEFAULT_CLOCK_ID, val logBuffer: LogBuffer? = null, val keepAllLoaded: Boolean, val subTag: String, subTag: String, ) { private val TAG = "${ClockRegistry::class.simpleName} ($subTag)" interface ClockChangeListener { Loading Loading @@ -113,9 +145,11 @@ open class ClockRegistry( } if (manager != info.manager) { Log.e( logBuffer.tryLog( TAG, "Clock Id conflict on load: $id is registered to another provider" LogLevel.ERROR, { str1 = id }, { "Clock Id conflict on load: $str1 is double registered" } ) continue } Loading @@ -138,9 +172,11 @@ open class ClockRegistry( val id = clock.clockId val info = availableClocks[id] if (info?.manager != manager) { Log.e( logBuffer.tryLog( TAG, "Clock Id conflict on unload: $id is registered to another provider" LogLevel.ERROR, { str1 = id }, { "Clock Id conflict on unload: $str1 is double registered" } ) continue } Loading Loading @@ -211,7 +247,7 @@ open class ClockRegistry( ClockSettings.deserialize(json) } catch (ex: Exception) { Log.e(TAG, "Failed to parse clock settings", ex) logBuffer.tryLog(TAG, LogLevel.ERROR, {}, { "Failed to parse clock settings" }, ex) null } settings = result Loading Loading @@ -240,7 +276,7 @@ open class ClockRegistry( ) } } catch (ex: Exception) { Log.e(TAG, "Failed to set clock settings", ex) logBuffer.tryLog(TAG, LogLevel.ERROR, {}, { "Failed to set clock settings" }, ex) } settings = value } Loading Loading @@ -400,46 +436,55 @@ open class ClockRegistry( } private fun onConnected(clockId: ClockId) { if (DEBUG) { Log.i(TAG, "Connected $clockId") } logBuffer.tryLog(TAG, LogLevel.DEBUG, { str1 = clockId }, { "Connected $str1" }) if (currentClockId == clockId) { if (DEBUG) { Log.i(TAG, "Current clock ($clockId) was connected") } logBuffer.tryLog( TAG, LogLevel.INFO, { str1 = clockId }, { "Current clock ($str1) was connected" } ) } } private fun onLoaded(clockId: ClockId) { if (DEBUG) { Log.i(TAG, "Loaded $clockId") } logBuffer.tryLog(TAG, LogLevel.DEBUG, { str1 = clockId }, { "Loaded $str1" }) if (currentClockId == clockId) { Log.i(TAG, "Current clock ($clockId) was loaded") logBuffer.tryLog( TAG, LogLevel.INFO, { str1 = clockId }, { "Current clock ($str1) was loaded" } ) triggerOnCurrentClockChanged() } } private fun onUnloaded(clockId: ClockId) { if (DEBUG) { Log.i(TAG, "Unloaded $clockId") } logBuffer.tryLog(TAG, LogLevel.DEBUG, { str1 = clockId }, { "Unloaded $str1" }) if (currentClockId == clockId) { Log.w(TAG, "Current clock ($clockId) was unloaded") logBuffer.tryLog( TAG, LogLevel.WARNING, { str1 = clockId }, { "Current clock ($str1) was unloaded" } ) triggerOnCurrentClockChanged() } } private fun onDisconnected(clockId: ClockId) { if (DEBUG) { Log.i(TAG, "Disconnected $clockId") } logBuffer.tryLog(TAG, LogLevel.DEBUG, { str1 = clockId }, { "Disconnected $str1" }) if (currentClockId == clockId) { Log.w(TAG, "Current clock ($clockId) was disconnected") logBuffer.tryLog( TAG, LogLevel.WARNING, { str1 = clockId }, { "Current clock ($str1) was disconnected" } ) } } Loading @@ -466,12 +511,27 @@ open class ClockRegistry( if (isEnabled && clockId.isNotEmpty()) { val clock = createClock(clockId) if (clock != null) { if (DEBUG) { Log.i(TAG, "Rendering clock $clockId") } logBuffer.tryLog( TAG, LogLevel.INFO, { str1 = clockId }, { "Rendering clock $str1" } ) return clock } else if (availableClocks.containsKey(clockId)) { logBuffer.tryLog( TAG, LogLevel.WARNING, { str1 = clockId }, { "Clock $str1 not loaded; using default" } ) } else { Log.e(TAG, "Clock $clockId not found; using default") logBuffer.tryLog( TAG, LogLevel.ERROR, { str1 = clockId }, { "Clock $str1 not found; using default" } ) } } Loading packages/SystemUI/src/com/android/keyguard/dagger/ClockRegistryModule.java +5 −1 Original line number Diff line number Diff line Loading @@ -27,7 +27,9 @@ import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.flags.FeatureFlags; import com.android.systemui.flags.Flags; import com.android.systemui.log.dagger.KeyguardClockLog; import com.android.systemui.plugins.PluginManager; import com.android.systemui.plugins.log.LogBuffer; import com.android.systemui.shared.clocks.ClockRegistry; import com.android.systemui.shared.clocks.DefaultClockProvider; Loading @@ -51,7 +53,8 @@ public abstract class ClockRegistryModule { @Background CoroutineDispatcher bgDispatcher, FeatureFlags featureFlags, @Main Resources resources, LayoutInflater layoutInflater) { LayoutInflater layoutInflater, @KeyguardClockLog LogBuffer logBuffer) { ClockRegistry registry = new ClockRegistry( context, pluginManager, Loading @@ -62,6 +65,7 @@ public abstract class ClockRegistryModule { /* handleAllUsers= */ true, new DefaultClockProvider(context, layoutInflater, resources), context.getString(R.string.lockscreen_clock_id_fallback), logBuffer, /* keepAllLoaded = */ false, /* subTag = */ "System"); registry.registerListeners(); Loading Loading
packages/SystemUI/customization/src/com/android/systemui/shared/clocks/ClockRegistry.kt +91 −31 Original line number Diff line number Diff line Loading @@ -32,6 +32,12 @@ import com.android.systemui.plugins.ClockSettings import com.android.systemui.plugins.PluginLifecycleManager import com.android.systemui.plugins.PluginListener import com.android.systemui.plugins.PluginManager import com.android.systemui.plugins.log.LogBuffer import com.android.systemui.plugins.log.LogLevel import com.android.systemui.plugins.log.LogMessage import com.android.systemui.plugins.log.LogMessageImpl import com.android.systemui.plugins.log.MessageInitializer import com.android.systemui.plugins.log.MessagePrinter import com.android.systemui.util.Assert import java.io.PrintWriter import java.util.concurrent.ConcurrentHashMap Loading @@ -40,7 +46,6 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch private const val DEBUG = true private val KEY_TIMESTAMP = "appliedTimestamp" private fun <TKey, TVal> ConcurrentHashMap<TKey, TVal>.concurrentGetOrPut( Loading @@ -55,6 +60,32 @@ private fun <TKey, TVal> ConcurrentHashMap<TKey, TVal>.concurrentGetOrPut( return result ?: value } private val TMP_MESSAGE: LogMessage by lazy { LogMessageImpl.Factory.create() } private inline fun LogBuffer?.tryLog( tag: String, level: LogLevel, messageInitializer: MessageInitializer, noinline messagePrinter: MessagePrinter, ex: Throwable? = null, ) { if (this != null) { // Wrap messagePrinter to convert it from crossinline to noinline this.log(tag, level, messageInitializer, messagePrinter, ex) } else { messageInitializer(TMP_MESSAGE) val msg = messagePrinter(TMP_MESSAGE) when (level) { LogLevel.VERBOSE -> Log.v(tag, msg, ex) LogLevel.DEBUG -> Log.d(tag, msg, ex) LogLevel.INFO -> Log.i(tag, msg, ex) LogLevel.WARNING -> Log.w(tag, msg, ex) LogLevel.ERROR -> Log.e(tag, msg, ex) LogLevel.WTF -> Log.wtf(tag, msg, ex) } } } /** ClockRegistry aggregates providers and plugins */ open class ClockRegistry( val context: Context, Loading @@ -66,8 +97,9 @@ open class ClockRegistry( val handleAllUsers: Boolean, defaultClockProvider: ClockProvider, val fallbackClockId: ClockId = DEFAULT_CLOCK_ID, val logBuffer: LogBuffer? = null, val keepAllLoaded: Boolean, val subTag: String, subTag: String, ) { private val TAG = "${ClockRegistry::class.simpleName} ($subTag)" interface ClockChangeListener { Loading Loading @@ -113,9 +145,11 @@ open class ClockRegistry( } if (manager != info.manager) { Log.e( logBuffer.tryLog( TAG, "Clock Id conflict on load: $id is registered to another provider" LogLevel.ERROR, { str1 = id }, { "Clock Id conflict on load: $str1 is double registered" } ) continue } Loading @@ -138,9 +172,11 @@ open class ClockRegistry( val id = clock.clockId val info = availableClocks[id] if (info?.manager != manager) { Log.e( logBuffer.tryLog( TAG, "Clock Id conflict on unload: $id is registered to another provider" LogLevel.ERROR, { str1 = id }, { "Clock Id conflict on unload: $str1 is double registered" } ) continue } Loading Loading @@ -211,7 +247,7 @@ open class ClockRegistry( ClockSettings.deserialize(json) } catch (ex: Exception) { Log.e(TAG, "Failed to parse clock settings", ex) logBuffer.tryLog(TAG, LogLevel.ERROR, {}, { "Failed to parse clock settings" }, ex) null } settings = result Loading Loading @@ -240,7 +276,7 @@ open class ClockRegistry( ) } } catch (ex: Exception) { Log.e(TAG, "Failed to set clock settings", ex) logBuffer.tryLog(TAG, LogLevel.ERROR, {}, { "Failed to set clock settings" }, ex) } settings = value } Loading Loading @@ -400,46 +436,55 @@ open class ClockRegistry( } private fun onConnected(clockId: ClockId) { if (DEBUG) { Log.i(TAG, "Connected $clockId") } logBuffer.tryLog(TAG, LogLevel.DEBUG, { str1 = clockId }, { "Connected $str1" }) if (currentClockId == clockId) { if (DEBUG) { Log.i(TAG, "Current clock ($clockId) was connected") } logBuffer.tryLog( TAG, LogLevel.INFO, { str1 = clockId }, { "Current clock ($str1) was connected" } ) } } private fun onLoaded(clockId: ClockId) { if (DEBUG) { Log.i(TAG, "Loaded $clockId") } logBuffer.tryLog(TAG, LogLevel.DEBUG, { str1 = clockId }, { "Loaded $str1" }) if (currentClockId == clockId) { Log.i(TAG, "Current clock ($clockId) was loaded") logBuffer.tryLog( TAG, LogLevel.INFO, { str1 = clockId }, { "Current clock ($str1) was loaded" } ) triggerOnCurrentClockChanged() } } private fun onUnloaded(clockId: ClockId) { if (DEBUG) { Log.i(TAG, "Unloaded $clockId") } logBuffer.tryLog(TAG, LogLevel.DEBUG, { str1 = clockId }, { "Unloaded $str1" }) if (currentClockId == clockId) { Log.w(TAG, "Current clock ($clockId) was unloaded") logBuffer.tryLog( TAG, LogLevel.WARNING, { str1 = clockId }, { "Current clock ($str1) was unloaded" } ) triggerOnCurrentClockChanged() } } private fun onDisconnected(clockId: ClockId) { if (DEBUG) { Log.i(TAG, "Disconnected $clockId") } logBuffer.tryLog(TAG, LogLevel.DEBUG, { str1 = clockId }, { "Disconnected $str1" }) if (currentClockId == clockId) { Log.w(TAG, "Current clock ($clockId) was disconnected") logBuffer.tryLog( TAG, LogLevel.WARNING, { str1 = clockId }, { "Current clock ($str1) was disconnected" } ) } } Loading @@ -466,12 +511,27 @@ open class ClockRegistry( if (isEnabled && clockId.isNotEmpty()) { val clock = createClock(clockId) if (clock != null) { if (DEBUG) { Log.i(TAG, "Rendering clock $clockId") } logBuffer.tryLog( TAG, LogLevel.INFO, { str1 = clockId }, { "Rendering clock $str1" } ) return clock } else if (availableClocks.containsKey(clockId)) { logBuffer.tryLog( TAG, LogLevel.WARNING, { str1 = clockId }, { "Clock $str1 not loaded; using default" } ) } else { Log.e(TAG, "Clock $clockId not found; using default") logBuffer.tryLog( TAG, LogLevel.ERROR, { str1 = clockId }, { "Clock $str1 not found; using default" } ) } } Loading
packages/SystemUI/src/com/android/keyguard/dagger/ClockRegistryModule.java +5 −1 Original line number Diff line number Diff line Loading @@ -27,7 +27,9 @@ import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.flags.FeatureFlags; import com.android.systemui.flags.Flags; import com.android.systemui.log.dagger.KeyguardClockLog; import com.android.systemui.plugins.PluginManager; import com.android.systemui.plugins.log.LogBuffer; import com.android.systemui.shared.clocks.ClockRegistry; import com.android.systemui.shared.clocks.DefaultClockProvider; Loading @@ -51,7 +53,8 @@ public abstract class ClockRegistryModule { @Background CoroutineDispatcher bgDispatcher, FeatureFlags featureFlags, @Main Resources resources, LayoutInflater layoutInflater) { LayoutInflater layoutInflater, @KeyguardClockLog LogBuffer logBuffer) { ClockRegistry registry = new ClockRegistry( context, pluginManager, Loading @@ -62,6 +65,7 @@ public abstract class ClockRegistryModule { /* handleAllUsers= */ true, new DefaultClockProvider(context, layoutInflater, resources), context.getString(R.string.lockscreen_clock_id_fallback), logBuffer, /* keepAllLoaded = */ false, /* subTag = */ "System"); registry.registerListeners(); Loading