diff options
author | 2025-03-27 12:06:51 -0400 | |
---|---|---|
committer | 2025-03-31 20:53:49 -0700 | |
commit | 95276b472825ec246173f0ec77ca041feb9cc349 (patch) | |
tree | c24a137817d75887e5e19780bbac5fc6c763e2f6 /packages/SystemUI/src | |
parent | a3d56716869ed36b5d1ee012556c3648c96ee7b5 (diff) |
Fix for missing widgets
This works around around a Jetpack Compose bug where if we add a child
to the element inside an AndroidView composable before the element has
been laid out, it will fail to render. We therefore delay processing the
RemoteViews for the widget until after the parent has been laid out.
Test: manually on device by verifying widgets properly show up
Flag: EXEMPT bugfix
Bug: 387938328
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:9c4b228662a1881efdd42e8f2fac3f50899c311f)
Merged-In: I3b094086dd133981c37fa9709547334091fcb580
Change-Id: I3b094086dd133981c37fa9709547334091fcb580
Diffstat (limited to 'packages/SystemUI/src')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostView.kt | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostView.kt b/packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostView.kt index d5497345dda5..08ecc3431511 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostView.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostView.kt @@ -28,6 +28,7 @@ import android.view.View import android.view.ViewOutlineProvider import android.widget.RemoteViews import android.widget.RemoteViews.RemoteResponse +import androidx.core.view.doOnLayout import com.android.systemui.animation.LaunchableView import com.android.systemui.animation.LaunchableViewDelegate @@ -37,10 +38,7 @@ class CommunalAppWidgetHostView( private val interactionHandler: RemoteViews.InteractionHandler, ) : AppWidgetHostView(context, interactionHandler), LaunchableView { private val launchableViewDelegate = - LaunchableViewDelegate( - this, - superSetVisibility = { super.setVisibility(it) }, - ) + LaunchableViewDelegate(this, superSetVisibility = { super.setVisibility(it) }) // Mutable corner radius. var enforcedCornerRadius: Float @@ -48,6 +46,9 @@ class CommunalAppWidgetHostView( // Mutable `Rect`. The size will be mutated when the widget is reapplied. var enforcedRectangle: Rect + private var pendingUpdate: Boolean = false + private var pendingRemoteViews: RemoteViews? = null + init { enforcedCornerRadius = RoundedCornerEnforcement.computeEnforcedRadius(context) enforcedRectangle = Rect() @@ -75,6 +76,23 @@ class CommunalAppWidgetHostView( } } + override fun updateAppWidget(remoteViews: RemoteViews?) { + // Workaround for Jetpack Compose bug which fails to render the widget if we add the + // RemoteViews before this parent view has been laid out. Therefore we wait for layout + // before calling the super.updateAppWidget() to actually render the widget. + // See b/387938328 + pendingRemoteViews = remoteViews + + if (!pendingUpdate) { + pendingUpdate = true + doOnLayout { + super.updateAppWidget(pendingRemoteViews) + pendingRemoteViews = null + pendingUpdate = false + } + } + } + private fun enforceRoundedCorners() { if (enforcedCornerRadius <= 0) { resetRoundedCorners() @@ -116,7 +134,7 @@ class CommunalAppWidgetHostView( launcherApps.getMainActivityLaunchIntent( activityInfo.componentName, null, - activityInfo.user + activityInfo.user, ) if (intent != null) { interactionHandler.onInteraction(view, intent, RemoteResponse.fromPendingIntent(intent)) |