Loading iconloaderlib/src/com/android/launcher3/icons/BitmapInfo.java +3 −17 Original line number Diff line number Diff line Loading @@ -43,11 +43,9 @@ public class BitmapInfo { public static final int FLAG_THEMED = 1 << 0; public static final int FLAG_NO_BADGE = 1 << 1; public static final int FLAG_SKIP_USER_BADGE = 1 << 2; @IntDef(flag = true, value = { FLAG_THEMED, FLAG_NO_BADGE, FLAG_SKIP_USER_BADGE, }) public @interface DrawableCreationFlags {} Loading Loading @@ -157,32 +155,20 @@ public class BitmapInfo { drawable.mDisabledAlpha = GraphicsUtils.getFloat(context, R.attr.disabledIconAlpha, 1f); drawable.mCreationFlags = creationFlags; if ((creationFlags & FLAG_NO_BADGE) == 0) { Drawable badge = getBadgeDrawable(context, (creationFlags & FLAG_THEMED) != 0, (creationFlags & FLAG_SKIP_USER_BADGE) != 0); Drawable badge = getBadgeDrawable(context, (creationFlags & FLAG_THEMED) != 0); if (badge != null) { drawable.setBadge(badge); } } } public Drawable getBadgeDrawable(Context context, boolean isThemed) { return getBadgeDrawable(context, isThemed, false); } /** * Returns a drawable representing the badge for this info */ @Nullable private Drawable getBadgeDrawable(Context context, boolean isThemed, boolean skipUserBadge) { public Drawable getBadgeDrawable(Context context, boolean isThemed) { if (badgeInfo != null) { int creationFlag = isThemed ? FLAG_THEMED : 0; if (skipUserBadge) { creationFlag |= FLAG_SKIP_USER_BADGE; } return badgeInfo.newIcon(context, creationFlag); } if (skipUserBadge) { return null; return badgeInfo.newIcon(context, isThemed ? FLAG_THEMED : 0); } else if ((flags & FLAG_INSTANT) != 0) { return context.getDrawable(isThemed ? R.drawable.ic_instant_app_badge_themed Loading tracinglib/src/com/android/app/tracing/FlowTracing.kt 0 → 100644 +33 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.app.tracing import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.onEach /** Utilities to trace Flows */ object FlowTracing { /** Logs each flow element to a trace. */ inline fun <T> Flow<T>.traceEach( flowName: String, logcat: Boolean = false, crossinline valueToString: (T) -> String = { it.toString() } ): Flow<T> { val stateLogger = TraceStateLogger(flowName, logcat = logcat) return onEach { stateLogger.log(valueToString(it)) } } } tracinglib/src/com/android/app/tracing/TraceStateLogger.kt +6 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.app.tracing import android.os.Trace import android.util.Log /** * Utility class used to log state changes easily in a track with a custom name. Loading @@ -37,7 +38,8 @@ import android.os.Trace class TraceStateLogger( private val trackName: String, private val logOnlyIfDifferent: Boolean = true, private val instantEvent: Boolean = true private val instantEvent: Boolean = true, private val logcat: Boolean = false, ) { private var previousValue: String? = null Loading @@ -50,6 +52,9 @@ class TraceStateLogger( if (logOnlyIfDifferent && previousValue == newValue) return Trace.asyncTraceForTrackEnd(Trace.TRACE_TAG_APP, trackName, 0) Trace.asyncTraceForTrackBegin(Trace.TRACE_TAG_APP, trackName, newValue, 0) if (logcat) { Log.d(trackName, "newValue: $newValue") } previousValue = newValue } } Loading
iconloaderlib/src/com/android/launcher3/icons/BitmapInfo.java +3 −17 Original line number Diff line number Diff line Loading @@ -43,11 +43,9 @@ public class BitmapInfo { public static final int FLAG_THEMED = 1 << 0; public static final int FLAG_NO_BADGE = 1 << 1; public static final int FLAG_SKIP_USER_BADGE = 1 << 2; @IntDef(flag = true, value = { FLAG_THEMED, FLAG_NO_BADGE, FLAG_SKIP_USER_BADGE, }) public @interface DrawableCreationFlags {} Loading Loading @@ -157,32 +155,20 @@ public class BitmapInfo { drawable.mDisabledAlpha = GraphicsUtils.getFloat(context, R.attr.disabledIconAlpha, 1f); drawable.mCreationFlags = creationFlags; if ((creationFlags & FLAG_NO_BADGE) == 0) { Drawable badge = getBadgeDrawable(context, (creationFlags & FLAG_THEMED) != 0, (creationFlags & FLAG_SKIP_USER_BADGE) != 0); Drawable badge = getBadgeDrawable(context, (creationFlags & FLAG_THEMED) != 0); if (badge != null) { drawable.setBadge(badge); } } } public Drawable getBadgeDrawable(Context context, boolean isThemed) { return getBadgeDrawable(context, isThemed, false); } /** * Returns a drawable representing the badge for this info */ @Nullable private Drawable getBadgeDrawable(Context context, boolean isThemed, boolean skipUserBadge) { public Drawable getBadgeDrawable(Context context, boolean isThemed) { if (badgeInfo != null) { int creationFlag = isThemed ? FLAG_THEMED : 0; if (skipUserBadge) { creationFlag |= FLAG_SKIP_USER_BADGE; } return badgeInfo.newIcon(context, creationFlag); } if (skipUserBadge) { return null; return badgeInfo.newIcon(context, isThemed ? FLAG_THEMED : 0); } else if ((flags & FLAG_INSTANT) != 0) { return context.getDrawable(isThemed ? R.drawable.ic_instant_app_badge_themed Loading
tracinglib/src/com/android/app/tracing/FlowTracing.kt 0 → 100644 +33 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.app.tracing import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.onEach /** Utilities to trace Flows */ object FlowTracing { /** Logs each flow element to a trace. */ inline fun <T> Flow<T>.traceEach( flowName: String, logcat: Boolean = false, crossinline valueToString: (T) -> String = { it.toString() } ): Flow<T> { val stateLogger = TraceStateLogger(flowName, logcat = logcat) return onEach { stateLogger.log(valueToString(it)) } } }
tracinglib/src/com/android/app/tracing/TraceStateLogger.kt +6 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.app.tracing import android.os.Trace import android.util.Log /** * Utility class used to log state changes easily in a track with a custom name. Loading @@ -37,7 +38,8 @@ import android.os.Trace class TraceStateLogger( private val trackName: String, private val logOnlyIfDifferent: Boolean = true, private val instantEvent: Boolean = true private val instantEvent: Boolean = true, private val logcat: Boolean = false, ) { private var previousValue: String? = null Loading @@ -50,6 +52,9 @@ class TraceStateLogger( if (logOnlyIfDifferent && previousValue == newValue) return Trace.asyncTraceForTrackEnd(Trace.TRACE_TAG_APP, trackName, 0) Trace.asyncTraceForTrackBegin(Trace.TRACE_TAG_APP, trackName, newValue, 0) if (logcat) { Log.d(trackName, "newValue: $newValue") } previousValue = newValue } }