Skip to content

Commit efb3ffb

Browse files
author
Adam Cohen
committed
Ensuring bindAppWidget isn't called until boot completed (issue 7469267)
Change-Id: I997f5a191116db7c840bf4a947385958b57cd657
1 parent ad9f594 commit efb3ffb

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public class KeyguardHostView extends KeyguardViewBase {
7676
private boolean mEnableFallback; // TODO: This should get the value from KeyguardPatternView
7777
private SecurityMode mCurrentSecuritySelection = SecurityMode.Invalid;
7878

79+
private boolean mBootCompleted = false;
80+
private boolean mCheckAppWidgetConsistencyOnBootCompleted = false;
81+
7982
protected Runnable mLaunchRunnable;
8083

8184
protected int mFailedAttempts;
@@ -142,6 +145,19 @@ public KeyguardHostView(Context context, AttributeSet attrs) {
142145
}
143146
}
144147

148+
private KeyguardUpdateMonitorCallback mUpdateMonitorCallbacks =
149+
new KeyguardUpdateMonitorCallback() {
150+
@Override
151+
public void onBootCompleted() {
152+
mBootCompleted = true;
153+
if (mCheckAppWidgetConsistencyOnBootCompleted) {
154+
checkAppWidgetConsistency();
155+
mSwitchPageRunnable.run();
156+
mCheckAppWidgetConsistencyOnBootCompleted = false;
157+
}
158+
}
159+
};
160+
145161
@Override
146162
public boolean onTouchEvent(MotionEvent ev) {
147163
boolean result = super.onTouchEvent(ev);
@@ -265,12 +281,14 @@ void setLockPatternUtils(LockPatternUtils utils) {
265281
protected void onAttachedToWindow() {
266282
super.onAttachedToWindow();
267283
mAppWidgetHost.startListening();
284+
KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallbacks);
268285
}
269286

270287
@Override
271288
protected void onDetachedFromWindow() {
272289
super.onDetachedFromWindow();
273290
mAppWidgetHost.stopListening();
291+
KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateMonitorCallbacks);
274292
}
275293

276294
private AppWidgetHost getAppWidgetHost() {
@@ -1087,8 +1105,13 @@ private int allocateIdForDefaultAppWidget() {
10871105
}
10881106
return appWidgetId;
10891107
}
1090-
10911108
public void checkAppWidgetConsistency() {
1109+
// Since this method may bind a widget (which we can't do until boot completed) we
1110+
// may have to defer it until after boot complete.
1111+
if (!mBootCompleted) {
1112+
mCheckAppWidgetConsistencyOnBootCompleted = true;
1113+
return;
1114+
}
10921115
final int childCount = mAppWidgetContainer.getChildCount();
10931116
boolean widgetPageExists = false;
10941117
for (int i = 0; i < childCount; i++) {

policy/src/com/android/internal/policy/impl/keyguard/KeyguardUpdateMonitor.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public class KeyguardUpdateMonitor {
8181
private static final int MSG_USER_SWITCHED = 310;
8282
private static final int MSG_USER_REMOVED = 311;
8383
private static final int MSG_KEYGUARD_VISIBILITY_CHANGED = 312;
84+
protected static final int MSG_BOOT_COMPLETED = 313;
85+
8486

8587
private static KeyguardUpdateMonitor sInstance;
8688

@@ -152,6 +154,9 @@ public void handleMessage(Message msg) {
152154
case MSG_KEYGUARD_VISIBILITY_CHANGED:
153155
handleKeyguardVisibilityChanged(msg.arg1);
154156
break;
157+
case MSG_BOOT_COMPLETED:
158+
handleBootCompleted();
159+
break;
155160

156161
}
157162
}
@@ -198,6 +203,8 @@ public void onReceive(Context context, Intent intent) {
198203
} else if (Intent.ACTION_USER_REMOVED.equals(action)) {
199204
mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_REMOVED,
200205
intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0), 0));
206+
} else if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
207+
mHandler.sendMessage(mHandler.obtainMessage(MSG_BOOT_COMPLETED));
201208
}
202209
}
203210
};
@@ -340,6 +347,7 @@ private KeyguardUpdateMonitor(Context context) {
340347
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
341348
filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
342349
filter.addAction(Intent.ACTION_USER_REMOVED);
350+
filter.addAction(Intent.ACTION_BOOT_COMPLETED);
343351
context.registerReceiver(mBroadcastReceiver, filter);
344352

345353
try {
@@ -419,6 +427,18 @@ protected void handleUserSwitched(int userId, IRemoteCallback reply) {
419427
}
420428
}
421429

430+
/**
431+
* Handle {@link #MSG_BOOT_COMPLETED}
432+
*/
433+
protected void handleBootCompleted() {
434+
for (int i = 0; i < mCallbacks.size(); i++) {
435+
KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
436+
if (cb != null) {
437+
cb.onBootCompleted();
438+
}
439+
}
440+
}
441+
422442
/**
423443
* Handle {@link #MSG_USER_SWITCHED}
424444
*/

policy/src/com/android/internal/policy/impl/keyguard/KeyguardUpdateMonitorCallback.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,12 @@ void onSimStateChanged(IccCardConstants.State simState) { }
9999
* Called when a user is removed.
100100
*/
101101
void onUserRemoved(int userId) { }
102+
103+
/**
104+
* Called when boot completed.
105+
*
106+
* Note, this callback will only be received if boot complete occurs after registering with
107+
* KeyguardUpdateMonitor.
108+
*/
109+
void onBootCompleted() { }
102110
}

0 commit comments

Comments
 (0)