mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-19 18:58:19 +00:00
FlagDebugUtils.formatFlagChange() utility to always write the set of updated flags, with a list of actual changes applied. Examples: [allow_gesture|device_dozing] +[device_dozing] [] -[state_started] Additionally, moved the appendFlag utility to the new FlagDebugUtils Test: manually verifed the output in logcat Bug: 261418621 Change-Id: Ie4f2cfcd4b34f0a816db7845e1df4331babed07a
38 lines
1.2 KiB
Kotlin
38 lines
1.2 KiB
Kotlin
package com.android.launcher3.util
|
|
|
|
import java.util.StringJoiner
|
|
import java.util.function.IntFunction
|
|
|
|
object FlagDebugUtils {
|
|
|
|
/** Appends the [flagName] to [str] when the [flag] is set in [flags]. */
|
|
@JvmStatic
|
|
fun appendFlag(str: StringJoiner, flags: Int, flag: Int, flagName: String) {
|
|
if (flags and flag != 0) {
|
|
str.add(flagName)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Produces a human-readable representation of the [current] flags, followed by a diff from from
|
|
* [previous].
|
|
*
|
|
* The resulting string is intented for logging and debugging.
|
|
*/
|
|
@JvmStatic
|
|
fun formatFlagChange(current: Int, previous: Int, flagSerializer: IntFunction<String>): String {
|
|
val result = StringJoiner(" ")
|
|
result.add("[" + flagSerializer.apply(current) + "]")
|
|
val changed = current xor previous
|
|
val added = current and changed
|
|
if (added != 0) {
|
|
result.add("+[" + flagSerializer.apply(added) + "]")
|
|
}
|
|
val removed = previous and changed
|
|
if (removed != 0) {
|
|
result.add("-[" + flagSerializer.apply(removed) + "]")
|
|
}
|
|
return result.toString()
|
|
}
|
|
}
|