@@ -69,8 +69,6 @@ public class KeyguardWidgetFrame extends FrameLayout {
6969 private float mBackgroundAlphaMultiplier = 1.0f ;
7070 private Drawable mBackgroundDrawable ;
7171 private Rect mBackgroundRect = new Rect ();
72- private int mLastMeasuredWidth = -1 ;
73- private int mLastMeasuredHeight = 1 ;
7472
7573 // These variables are all needed in order to size things properly before we're actually
7674 // measured.
@@ -79,6 +77,7 @@ public class KeyguardWidgetFrame extends FrameLayout {
7977 private boolean mWidgetLockedSmall = false ;
8078 private int mMaxChallengeTop = -1 ;
8179 private int mFrameStrokeAdjustment ;
80+ private boolean mPerformAppWidgetSizeUpdateOnBootComplete ;
8281
8382 // This will hold the width value before we've actually been measured
8483 private int mFrameHeight ;
@@ -123,9 +122,29 @@ public KeyguardWidgetFrame(Context context, AttributeSet attrs, int defStyle) {
123122
124123 @ Override
125124 protected void onDetachedFromWindow () {
125+ super .onDetachedFromWindow ();
126126 cancelLongPress ();
127+ KeyguardUpdateMonitor .getInstance (mContext ).removeCallback (mUpdateMonitorCallbacks );
128+
127129 }
128130
131+ @ Override
132+ protected void onAttachedToWindow () {
133+ super .onAttachedToWindow ();
134+ KeyguardUpdateMonitor .getInstance (mContext ).registerCallback (mUpdateMonitorCallbacks );
135+ }
136+
137+ private KeyguardUpdateMonitorCallback mUpdateMonitorCallbacks =
138+ new KeyguardUpdateMonitorCallback () {
139+ @ Override
140+ public void onBootCompleted () {
141+ if (mPerformAppWidgetSizeUpdateOnBootComplete ) {
142+ performAppWidgetSizeCallbacksIfNecessary ();
143+ mPerformAppWidgetSizeUpdateOnBootComplete = false ;
144+ }
145+ }
146+ };
147+
129148 void setIsHoveringOverDeleteDropTarget (boolean isHovering ) {
130149 if (ENABLE_HOVER_OVER_DELETE_DROP_TARGET_OVERLAY ) {
131150 if (mIsHoveringOverDeleteDropTarget != isHovering ) {
@@ -453,12 +472,14 @@ private void performAppWidgetSizeCallbacksIfNecessary() {
453472 View content = getContent ();
454473 if (!(content instanceof AppWidgetHostView )) return ;
455474
456- boolean sizeDirty = content .getMeasuredWidth () != mLastMeasuredWidth ||
457- content .getMeasuredHeight () != mLastMeasuredHeight ;
458- if (sizeDirty ) {
459-
475+ if (!KeyguardUpdateMonitor .getInstance (mContext ).hasBootCompleted ()) {
476+ mPerformAppWidgetSizeUpdateOnBootComplete = true ;
477+ return ;
460478 }
461479
480+ // TODO: there's no reason to force the AppWidgetHostView to catch duplicate size calls.
481+ // We can do that even more cheaply here. It's not an issue right now since we're in the
482+ // system process and hence no binder calls.
462483 AppWidgetHostView awhv = (AppWidgetHostView ) content ;
463484 float density = getResources ().getDisplayMetrics ().density ;
464485
0 commit comments