Cache and reuses LauncherAppWidgetHostView when launcher resumes

Currently by design when launcher enters the background, it stops
listening to updates in widgets. This eventually causes the dilemma
for launcher when it resumes, before the update can be returned from
the system process via IPC, launcher could do one of the following
to fill the gap:
1. show a deferred widget view -- a placeholder that renders the shape
   of the widget -- to let the user know widget is being reloaded.
2. show whichever widget view that was previously displayed to the
   user that may now contain stale content.

There is a descrepancy here since in some edge cases we are showing the
former while in most other cases we are showing the later. This CL added
a short-term fix to address the descrepancy and favors the later where
possible.

Bug: 218067434
Test: manual
Change-Id: I6cd2cd704186267227e2ec47f2581843fd526fa0
This commit is contained in:
Pinyao Ting committed 2022-06-15 13:23:31 -07:00
1 parent 9074e97780
commit e5dbb75acd
3 files changed
+73 -13

No files matched your search

@@ -43,6 +43,7 @@ import com.android.launcher3.CheckLongPressHelper;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
@@ -85,7 +86,7 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView
private Runnable mAutoAdvanceRunnable;
private long mDeferUpdatesUntilMillis = 0;
private RemoteViews mDeferredRemoteViews;
RemoteViews mLastRemoteViews;
private boolean mHasDeferredColorChange = false;
private @Nullable SparseIntArray mDeferredColorChange = null;
@@ -150,11 +151,18 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView
TRACE_METHOD_NAME + getAppWidgetInfo().provider, getAppWidgetId());
mTrackingWidgetUpdate = false;
}
if (isDeferringUpdates()) {
mDeferredRemoteViews = remoteViews;
return;
if (FeatureFlags.ENABLE_CACHED_WIDGET.get()) {
mLastRemoteViews = remoteViews;
if (isDeferringUpdates()) {
return;
}
} else {
if (isDeferringUpdates()) {
mLastRemoteViews = remoteViews;
return;
}
mLastRemoteViews = null;
}
mDeferredRemoteViews = null;
super.updateAppWidget(remoteViews);
@@ -218,8 +226,7 @@ public class LauncherAppWidgetHostView extends BaseLauncherAppWidgetHostView
SparseIntArray deferredColors;
boolean hasDeferredColors;
mDeferUpdatesUntilMillis = 0;
remoteViews = mDeferredRemoteViews;
mDeferredRemoteViews = null;
remoteViews = mLastRemoteViews;
deferredColors = mDeferredColorChange;
hasDeferredColors = mHasDeferredColorChange;
mDeferredColorChange = null;