0cd995e4ef
We already reached the limit of 32 flags for an int. To be able to have more, changing from int to long. This is needed, as new flags have to be added. Flag: NONE Test: Manually running SysUI and Launcher Test: Unit tests in CL Bug: 335625543 Change-Id: Iec1d40218264c7c64c50fd09764aa07c0caa7787
72 lines
2.3 KiB
Kotlin
72 lines
2.3 KiB
Kotlin
package com.android.launcher3.util
|
|
|
|
import java.util.StringJoiner
|
|
import java.util.function.IntFunction
|
|
import java.util.function.LongFunction
|
|
|
|
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)
|
|
}
|
|
}
|
|
/** Appends the [flagName] to [str] when the [flag] is set in [flags]. */
|
|
@JvmStatic
|
|
fun appendFlag(str: StringJoiner, flags: Long, flag: Long, flagName: String) {
|
|
if (flags and flag != 0L) {
|
|
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()
|
|
}
|
|
|
|
/**
|
|
* 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: Long,
|
|
previous: Long,
|
|
flagSerializer: LongFunction<String>
|
|
): String {
|
|
val result = StringJoiner(" ")
|
|
result.add("[" + flagSerializer.apply(current) + "]")
|
|
val changed = current xor previous
|
|
val added = current and changed
|
|
if (added != 0L) {
|
|
result.add("+[" + flagSerializer.apply(added) + "]")
|
|
}
|
|
val removed = previous and changed
|
|
if (removed != 0L) {
|
|
result.add("-[" + flagSerializer.apply(removed) + "]")
|
|
}
|
|
return result.toString()
|
|
}
|
|
}
|