Fix bug where notification text colors stop updating

ColorExtractor adds onColorsChangedListener as WeakReference
so we should not pass it in as anonymous lambda; otherwise it gets
garbage collected eventually and notif text colors stop updating.

This change adds persistent onColorsChangedListener to NSSLC.

Fixes: 173107499
Bug: 172289783
Test: visual - white text on dark background and vice versa
Change-Id: I42ee25fdf2ff9b40b78bae38416004249603444d
This commit is contained in:
Lyn Han
2020-11-12 10:41:53 -06:00
parent 8265afebfa
commit 3838cbfc3f

View File

@@ -48,6 +48,7 @@ import android.view.WindowInsets;
import android.widget.FrameLayout;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.colorextraction.ColorExtractor;
import com.android.internal.jank.InteractionJankMonitor;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.UiEvent;
@@ -177,6 +178,8 @@ public class NotificationStackScrollLayoutController {
private final NotificationListContainerImpl mNotificationListContainer =
new NotificationListContainerImpl();
private ColorExtractor.OnColorsChangedListener mOnColorsChangedListener;
@VisibleForTesting
final View.OnAttachStateChangeListener mOnAttachStateChangeListener =
new View.OnAttachStateChangeListener() {
@@ -703,10 +706,11 @@ public class NotificationStackScrollLayoutController {
Settings.Secure.NOTIFICATION_DISMISS_RTL,
Settings.Secure.NOTIFICATION_HISTORY_ENABLED);
mColorExtractor.addOnColorsChangedListener((colorExtractor, which) -> {
mOnColorsChangedListener = (colorExtractor, which) -> {
final boolean useDarkText = mColorExtractor.getNeutralColors().supportsDarkText();
mView.updateDecorViews(useDarkText);
});
};
mColorExtractor.addOnColorsChangedListener(mOnColorsChangedListener);
mKeyguardMediaController.setVisibilityChangedListener(visible -> {
mView.setKeyguardMediaControllorVisible(visible);