Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit efb3ffb0 authored by Adam Cohen's avatar Adam Cohen
Browse files

Ensuring bindAppWidget isn't called until boot completed (issue 7469267)

Change-Id: I997f5a191116db7c840bf4a947385958b57cd657
parent ad9f594e
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -76,6 +76,9 @@ public class KeyguardHostView extends KeyguardViewBase {
    private boolean mEnableFallback; // TODO: This should get the value from KeyguardPatternView
    private SecurityMode mCurrentSecuritySelection = SecurityMode.Invalid;

    private boolean mBootCompleted = false;
    private boolean mCheckAppWidgetConsistencyOnBootCompleted = false;

    protected Runnable mLaunchRunnable;

    protected int mFailedAttempts;
@@ -142,6 +145,19 @@ public class KeyguardHostView extends KeyguardViewBase {
        }
    }

    private KeyguardUpdateMonitorCallback mUpdateMonitorCallbacks =
            new KeyguardUpdateMonitorCallback() {
        @Override
        public void onBootCompleted() {
            mBootCompleted = true;
            if (mCheckAppWidgetConsistencyOnBootCompleted) {
                checkAppWidgetConsistency();
                mSwitchPageRunnable.run();
                mCheckAppWidgetConsistencyOnBootCompleted = false;
            }
        }
    };

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        boolean result = super.onTouchEvent(ev);
@@ -265,12 +281,14 @@ public class KeyguardHostView extends KeyguardViewBase {
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        mAppWidgetHost.startListening();
        KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallbacks);
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        mAppWidgetHost.stopListening();
        KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateMonitorCallbacks);
    }

    private AppWidgetHost getAppWidgetHost() {
@@ -1087,8 +1105,13 @@ public class KeyguardHostView extends KeyguardViewBase {
        }
        return appWidgetId;
    }

    public void checkAppWidgetConsistency() {
        // Since this method may bind a widget (which we can't do until boot completed) we
        // may have to defer it until after boot complete.
        if (!mBootCompleted) {
            mCheckAppWidgetConsistencyOnBootCompleted = true;
            return;
        }
        final int childCount = mAppWidgetContainer.getChildCount();
        boolean widgetPageExists = false;
        for (int i = 0; i < childCount; i++) {
+20 −0
Original line number Diff line number Diff line
@@ -81,6 +81,8 @@ public class KeyguardUpdateMonitor {
    private static final int MSG_USER_SWITCHED = 310;
    private static final int MSG_USER_REMOVED = 311;
    private static final int MSG_KEYGUARD_VISIBILITY_CHANGED = 312;
    protected static final int MSG_BOOT_COMPLETED = 313;


    private static KeyguardUpdateMonitor sInstance;

@@ -152,6 +154,9 @@ public class KeyguardUpdateMonitor {
                case MSG_KEYGUARD_VISIBILITY_CHANGED:
                    handleKeyguardVisibilityChanged(msg.arg1);
                    break;
                case MSG_BOOT_COMPLETED:
                    handleBootCompleted();
                    break;

            }
        }
@@ -198,6 +203,8 @@ public class KeyguardUpdateMonitor {
            } else if (Intent.ACTION_USER_REMOVED.equals(action)) {
                mHandler.sendMessage(mHandler.obtainMessage(MSG_USER_REMOVED,
                       intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0), 0));
            } else if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
                mHandler.sendMessage(mHandler.obtainMessage(MSG_BOOT_COMPLETED));
            }
        }
    };
@@ -340,6 +347,7 @@ public class KeyguardUpdateMonitor {
        filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
        filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
        filter.addAction(Intent.ACTION_USER_REMOVED);
        filter.addAction(Intent.ACTION_BOOT_COMPLETED);
        context.registerReceiver(mBroadcastReceiver, filter);

        try {
@@ -419,6 +427,18 @@ public class KeyguardUpdateMonitor {
        }
    }

    /**
     * Handle {@link #MSG_BOOT_COMPLETED}
     */
    protected void handleBootCompleted() {
        for (int i = 0; i < mCallbacks.size(); i++) {
            KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
            if (cb != null) {
                cb.onBootCompleted();
            }
        }
    }

    /**
     * Handle {@link #MSG_USER_SWITCHED}
     */
+8 −0
Original line number Diff line number Diff line
@@ -99,4 +99,12 @@ class KeyguardUpdateMonitorCallback {
     * Called when a user is removed.
     */
    void onUserRemoved(int userId) { }

    /**
     * Called when boot completed.
     *
     * Note, this callback will only be received if boot complete occurs after registering with
     * KeyguardUpdateMonitor.
     */
    void onBootCompleted() { }
}