1 package com.android.launcher3.util 2 3 import java.util.StringJoiner 4 import java.util.function.IntFunction 5 6 object FlagDebugUtils { 7 8 /** Appends the [flagName] to [str] when the [flag] is set in [flags]. */ 9 @JvmStatic appendFlagnull10 fun appendFlag(str: StringJoiner, flags: Int, flag: Int, flagName: String) { 11 if (flags and flag != 0) { 12 str.add(flagName) 13 } 14 } 15 16 /** 17 * Produces a human-readable representation of the [current] flags, followed by a diff from from 18 * [previous]. 19 * 20 * The resulting string is intented for logging and debugging. 21 */ 22 @JvmStatic formatFlagChangenull23 fun formatFlagChange(current: Int, previous: Int, flagSerializer: IntFunction<String>): String { 24 val result = StringJoiner(" ") 25 result.add("[" + flagSerializer.apply(current) + "]") 26 val changed = current xor previous 27 val added = current and changed 28 if (added != 0) { 29 result.add("+[" + flagSerializer.apply(added) + "]") 30 } 31 val removed = previous and changed 32 if (removed != 0) { 33 result.add("-[" + flagSerializer.apply(removed) + "]") 34 } 35 return result.toString() 36 } 37 } 38