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

Commit 6212cc0d authored by Jim Miller's avatar Jim Miller
Browse files

Keep local reference to KeyguardStatusViewManager so it doesn't get GC'd

This fixes a bug where we'd stop updating the status view in keyguard
because KeyguardStatusViewManager had no references.

It also fixes a bug where KeyguardUpdateMonitor wasn't removing objects
because objects were being compared with WeakReferences rather than the
content of the WeakReferences.

Bug:7095359

Change-Id: I2d9df6097b2270655ad3662bcf7a6757e0515363
parent 6d617c2d
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -149,7 +149,6 @@ public class KeyguardSelectorView extends LinearLayout implements KeyguardSecuri
        mGlowPadView = (GlowPadView) findViewById(R.id.glow_pad_view);
        mGlowPadView.setOnTriggerListener(mOnTriggerListener);
        mEmergencyCallButton = (Button) findViewById(R.id.emergency_call_button);
        KeyguardUpdateMonitor.getInstance(getContext()).registerCallback(mInfoCallback);
        updateTargets();
    }

+3 −1
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.util.AttributeSet;
import android.widget.GridLayout;

public class KeyguardStatusView extends GridLayout {
    private KeyguardStatusViewManager mStatusViewManager;

    public KeyguardStatusView(Context context) {
        this(context, null, 0);
    }
@@ -38,7 +40,7 @@ public class KeyguardStatusView extends GridLayout {
        super.onFinishInflate();

        // StatusView manages all of the widgets in this view.
        new KeyguardStatusViewManager(this);
        mStatusViewManager = new KeyguardStatusViewManager(this);
    }

}
+31 −24
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ public class KeyguardUpdateMonitor {

    private boolean mClockVisible;

    private ArrayList<WeakReference<KeyguardUpdateMonitorCallback>>
    private final ArrayList<WeakReference<KeyguardUpdateMonitorCallback>>
            mCallbacks = Lists.newArrayList();
    private ContentObserver mContentObserver;

@@ -586,20 +586,38 @@ public class KeyguardUpdateMonitor {
    /**
     * Remove the given observer's callback.
     *
     * @param observer The observer to remove
     * @param callback The callback to remove
     */
    public void removeCallback(Object observer) {
        mCallbacks.remove(observer);
    public void removeCallback(KeyguardUpdateMonitorCallback callback) {
        if (DEBUG) Log.v(TAG, "*** unregister callback for " + callback);
        for (int i = mCallbacks.size() - 1; i >= 0; i--) {
            if (mCallbacks.get(i).get() == callback) {
                mCallbacks.remove(i);
            }
        }
    }

    /**
     * Register to receive notifications about general keyguard information
     * (see {@link InfoCallback}.
     * @param callback The callback.
     * @param callback The callback to register
     */
    public void registerCallback(KeyguardUpdateMonitorCallback callback) {
        if (!mCallbacks.contains(callback)) {
        if (DEBUG) Log.v(TAG, "*** register callback for " + callback);
        // Prevent adding duplicate callbacks
        for (int i = 0; i < mCallbacks.size(); i++) {
            if (mCallbacks.get(i).get() == callback) {
                if (DEBUG) Log.e(TAG, "Object tried to add another callback",
                        new Exception("Called by"));
                return;
            }
        }
        mCallbacks.add(new WeakReference<KeyguardUpdateMonitorCallback>(callback));
        removeCallback(null); // remove unused references
        sendUpdates(callback);
    }

    private void sendUpdates(KeyguardUpdateMonitorCallback callback) {
        // Notify listener of the current state
        callback.onRefreshBatteryInfo(mBatteryStatus);
        callback.onTimeChanged();
@@ -608,17 +626,6 @@ public class KeyguardUpdateMonitor {
        callback.onRefreshCarrierInfo(mTelephonyPlmn, mTelephonySpn);
        callback.onClockVisibilityChanged();
        callback.onSimStateChanged(mSimState);
        } else {
            if (DEBUG) Log.e(TAG, "Object tried to add another callback",
                    new Exception("Called by"));
        }

        // Clean up any unused references
        for (int i = mCallbacks.size() - 1; i >= 0; i--) {
            if (mCallbacks.get(i).get() == null) {
                mCallbacks.remove(i);
            }
        }
    }

    public void reportClockVisible(boolean visible) {