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

Commit d2d4a645 authored by Jim Miller's avatar Jim Miller Committed by Android (Google) Code Review
Browse files

Merge "Keep local reference to KeyguardStatusViewManager so it doesn't get GC'd" into jb-mr1-dev

parents e7376e2c 6212cc0d
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) {