Skip to content

Commit 42164ef

Browse files
Adam CohenAndroid (Google) Code Review
authored andcommitted
Merge "Ensuring bindAppWidget isn't called until boot completed (issue 7469267)" into jb-mr1-lockscreen-dev
2 parents 835579e + efb3ffb commit 42164ef

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
@@ -75,6 +75,9 @@ public class KeyguardHostView extends KeyguardViewBase {
7575
private SecurityMode mCurrentSecuritySelection = SecurityMode.Invalid;
7676
private int mAppWidgetToShow;
7777

78+
private boolean mBootCompleted = false;
79+
private boolean mCheckAppWidgetConsistencyOnBootCompleted = false;
80+
7881
protected Runnable mLaunchRunnable;
7982

8083
protected int mFailedAttempts;
@@ -140,6 +143,19 @@ public KeyguardHostView(Context context, AttributeSet attrs) {
140143
}
141144
}
142145

146+
private KeyguardUpdateMonitorCallback mUpdateMonitorCallbacks =
147+
new KeyguardUpdateMonitorCallback() {
148+
@Override
149+
public void onBootCompleted() {
150+
mBootCompleted = true;
151+
if (mCheckAppWidgetConsistencyOnBootCompleted) {
152+
checkAppWidgetConsistency();
153+
mSwitchPageRunnable.run();
154+
mCheckAppWidgetConsistencyOnBootCompleted = false;
155+
}
156+
}
157+
};
158+
143159
@Override
144160
public boolean onTouchEvent(MotionEvent ev) {
145161
boolean result = super.onTouchEvent(ev);
@@ -263,12 +279,14 @@ void setLockPatternUtils(LockPatternUtils utils) {
263279
protected void onAttachedToWindow() {
264280
super.onAttachedToWindow();
265281
mAppWidgetHost.startListening();
282+
KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallbacks);
266283
}
267284

268285
@Override
269286
protected void onDetachedFromWindow() {
270287
super.onDetachedFromWindow();
271288
mAppWidgetHost.stopListening();
289+
KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateMonitorCallbacks);
272290
}
273291

274292
private AppWidgetHost getAppWidgetHost() {
@@ -1086,8 +1104,13 @@ private int allocateIdForDefaultAppWidget() {
10861104
}
10871105
return appWidgetId;
10881106
}
1089-
10901107
public void checkAppWidgetConsistency() {
1108+
// Since this method may bind a widget (which we can't do until boot completed) we
1109+
// may have to defer it until after boot complete.
1110+
if (!mBootCompleted) {
1111+
mCheckAppWidgetConsistencyOnBootCompleted = true;
1112+
return;
1113+
}
10911114
final int childCount = mAppWidgetContainer.getChildCount();
10921115
boolean widgetPageExists = false;
10931116
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)