Loading packages/SystemUI/src/com/android/systemui/flags/RefactorFlagUtils.kt +35 −2 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.flags package com.android.systemui.flags import android.os.Build import android.util.Log import android.util.Log /** /** Loading @@ -32,6 +33,11 @@ import android.util.Log * RefactorFlagUtils.assertInLegacyMode(isEnabled, FLAG_NAME) * RefactorFlagUtils.assertInLegacyMode(isEnabled, FLAG_NAME) * } * } * ``` * ``` * * Legacy mode crashes can be disabled with the command: * ``` * adb shell setprop log.tag.RefactorFlagAssert silent * ``` */ */ @Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE") object RefactorFlagUtils { object RefactorFlagUtils { Loading @@ -51,8 +57,7 @@ object RefactorFlagUtils { inline fun isUnexpectedlyInLegacyMode(isEnabled: Boolean, flagName: Any): Boolean { inline fun isUnexpectedlyInLegacyMode(isEnabled: Boolean, flagName: Any): Boolean { val inLegacyMode = !isEnabled val inLegacyMode = !isEnabled if (inLegacyMode) { if (inLegacyMode) { val message = "New code path expects $flagName to be enabled." assertOnEngBuild("New code path expects $flagName to be enabled.") Log.wtf("RefactorFlag", message, IllegalStateException(message)) } } return inLegacyMode return inLegacyMode } } Loading @@ -71,4 +76,32 @@ object RefactorFlagUtils { */ */ inline fun assertInLegacyMode(isEnabled: Boolean, flagName: Any) = inline fun assertInLegacyMode(isEnabled: Boolean, flagName: Any) = check(!isEnabled) { "Legacy code path not supported when $flagName is enabled." } check(!isEnabled) { "Legacy code path not supported when $flagName is enabled." } /** * This will [Log.wtf] with the given message, assuming [ASSERT_TAG] is loggable at that level. * This means an engineer can prevent this from crashing by running the command: * ``` * adb shell setprop log.tag.RefactorFlagAssert silent * ``` */ fun assertOnEngBuild(message: String) { if (Log.isLoggable(ASSERT_TAG, Log.ASSERT)) { val exception = if (Build.isDebuggable()) IllegalStateException(message) else null Log.wtf(ASSERT_TAG, message, exception) } else if (Log.isLoggable(STANDARD_TAG, Log.WARN)) { Log.w(STANDARD_TAG, message) } } /** * Tag used to determine if an incorrect flag guard should crash System UI running an eng build. * This is enabled by default. To disable, run: * ``` * adb shell setprop log.tag.RefactorFlagAssert silent * ``` */ private const val ASSERT_TAG = "RefactorFlagAssert" /** Tag used for non-crashing logs or when the [ASSERT_TAG] has been silenced. */ private const val STANDARD_TAG = "RefactorFlag" } } Loading
packages/SystemUI/src/com/android/systemui/flags/RefactorFlagUtils.kt +35 −2 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.flags package com.android.systemui.flags import android.os.Build import android.util.Log import android.util.Log /** /** Loading @@ -32,6 +33,11 @@ import android.util.Log * RefactorFlagUtils.assertInLegacyMode(isEnabled, FLAG_NAME) * RefactorFlagUtils.assertInLegacyMode(isEnabled, FLAG_NAME) * } * } * ``` * ``` * * Legacy mode crashes can be disabled with the command: * ``` * adb shell setprop log.tag.RefactorFlagAssert silent * ``` */ */ @Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE") object RefactorFlagUtils { object RefactorFlagUtils { Loading @@ -51,8 +57,7 @@ object RefactorFlagUtils { inline fun isUnexpectedlyInLegacyMode(isEnabled: Boolean, flagName: Any): Boolean { inline fun isUnexpectedlyInLegacyMode(isEnabled: Boolean, flagName: Any): Boolean { val inLegacyMode = !isEnabled val inLegacyMode = !isEnabled if (inLegacyMode) { if (inLegacyMode) { val message = "New code path expects $flagName to be enabled." assertOnEngBuild("New code path expects $flagName to be enabled.") Log.wtf("RefactorFlag", message, IllegalStateException(message)) } } return inLegacyMode return inLegacyMode } } Loading @@ -71,4 +76,32 @@ object RefactorFlagUtils { */ */ inline fun assertInLegacyMode(isEnabled: Boolean, flagName: Any) = inline fun assertInLegacyMode(isEnabled: Boolean, flagName: Any) = check(!isEnabled) { "Legacy code path not supported when $flagName is enabled." } check(!isEnabled) { "Legacy code path not supported when $flagName is enabled." } /** * This will [Log.wtf] with the given message, assuming [ASSERT_TAG] is loggable at that level. * This means an engineer can prevent this from crashing by running the command: * ``` * adb shell setprop log.tag.RefactorFlagAssert silent * ``` */ fun assertOnEngBuild(message: String) { if (Log.isLoggable(ASSERT_TAG, Log.ASSERT)) { val exception = if (Build.isDebuggable()) IllegalStateException(message) else null Log.wtf(ASSERT_TAG, message, exception) } else if (Log.isLoggable(STANDARD_TAG, Log.WARN)) { Log.w(STANDARD_TAG, message) } } /** * Tag used to determine if an incorrect flag guard should crash System UI running an eng build. * This is enabled by default. To disable, run: * ``` * adb shell setprop log.tag.RefactorFlagAssert silent * ``` */ private const val ASSERT_TAG = "RefactorFlagAssert" /** Tag used for non-crashing logs or when the [ASSERT_TAG] has been silenced. */ private const val STANDARD_TAG = "RefactorFlag" } }