Don't query settings for the notification history state every time we update the footer.

Bug: 217450249
Test: manual
Change-Id: Ic8f22359574d7e7dee224bdfcdd772b18984f3b6
This commit is contained in:
Jeff DeCew
2022-02-02 19:16:20 +00:00
parent 0a63040d26
commit 08a567fd35
3 changed files with 41 additions and 18 deletions

View File

@@ -43,7 +43,6 @@ import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.AttributeSet;
import android.util.IndentingPrintWriter;
@@ -696,8 +695,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
&& mQsExpansionFraction != 1
&& !mScreenOffAnimationController.shouldHideNotificationsFooter()
&& !mIsRemoteInputActive;
boolean showHistory = Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, UserHandle.USER_CURRENT) == 1;
boolean showHistory = mController.isHistoryEnabled();
updateFooterView(showFooterView, showDismissView, showHistory);
}
@@ -5243,11 +5241,10 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
R.layout.status_bar_no_notifications, this, false);
view.setText(R.string.empty_shade_text);
view.setOnClickListener(v -> {
final boolean showHistory = Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, UserHandle.USER_CURRENT) == 1;
Intent intent = showHistory ? new Intent(
Settings.ACTION_NOTIFICATION_HISTORY) : new Intent(
Settings.ACTION_NOTIFICATION_SETTINGS);
final boolean showHistory = mController.isHistoryEnabled();
Intent intent = showHistory
? new Intent(Settings.ACTION_NOTIFICATION_HISTORY)
: new Intent(Settings.ACTION_NOTIFICATION_SETTINGS);
mStatusBar.startActivity(intent, true, true, Intent.FLAG_ACTIVITY_SINGLE_TOP);
});
setEmptyShadeView(view);

View File

@@ -36,6 +36,7 @@ import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.PointF;
import android.os.Trace;
import android.os.UserHandle;
import android.provider.Settings;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
@@ -181,7 +182,6 @@ public class NotificationStackScrollLayoutController {
private final NotificationLockscreenUserManager mLockscreenUserManager;
// TODO: StatusBar should be encapsulated behind a Controller
private final StatusBar mStatusBar;
private final NotificationGroupManagerLegacy mLegacyGroupManager;
private final SectionHeaderController mSilentHeaderController;
private final LockscreenShadeTransitionController mLockscreenShadeTransitionController;
private final InteractionJankMonitor mJankMonitor;
@@ -192,6 +192,7 @@ public class NotificationStackScrollLayoutController {
private boolean mFadeNotificationsOnDismiss;
private NotificationSwipeHelper mSwipeHelper;
private boolean mShowEmptyShadeView;
@Nullable private Boolean mHistoryEnabled;
private int mBarState;
private HeadsUpAppearanceController mHeadsUpAppearanceController;
@@ -341,6 +342,8 @@ public class NotificationStackScrollLayoutController {
@Override
public void onUserChanged(int userId) {
mView.updateSensitiveness(false, mLockscreenUserManager.isAnyProfilePublicMode());
mHistoryEnabled = null;
updateFooter();
}
};
@@ -700,8 +703,6 @@ public class NotificationStackScrollLayoutController {
}
});
mNotifPipelineFlags = notifPipelineFlags;
mLegacyGroupManager = mNotifPipelineFlags.isNewPipelineEnabled()
? null : legacyGroupManager;
mSilentHeaderController = silentHeaderController;
mNotifPipeline = notifPipeline;
mNotifCollection = notifCollection;
@@ -803,6 +804,7 @@ public class NotificationStackScrollLayoutController {
(key, newValue) -> {
switch (key) {
case Settings.Secure.NOTIFICATION_HISTORY_ENABLED:
mHistoryEnabled = null; // invalidate
updateFooter();
break;
case HIGH_PRIORITY:
@@ -1010,6 +1012,20 @@ public class NotificationStackScrollLayoutController {
return mNotifStats.getNumActiveNotifs();
}
public boolean isHistoryEnabled() {
Boolean historyEnabled = mHistoryEnabled;
if (historyEnabled == null) {
if (mView == null || mView.getContext() == null) {
Log.wtf(TAG, "isHistoryEnabled failed to initialize its value");
return false;
}
mHistoryEnabled = historyEnabled =
Settings.Secure.getIntForUser(mView.getContext().getContentResolver(),
Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0, UserHandle.USER_CURRENT) == 1;
}
return historyEnabled;
}
public int getIntrinsicContentHeight() {
return mView.getIntrinsicContentHeight();
}

View File

@@ -16,7 +16,6 @@
package com.android.systemui.statusbar.notification.stack;
import static android.provider.Settings.Secure.NOTIFICATION_HISTORY_ENABLED;
import static android.view.View.GONE;
import static com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout.ROWS_ALL;
@@ -41,8 +40,6 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.os.UserHandle;
import android.provider.Settings;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.util.MathUtils;
@@ -112,10 +109,6 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase {
public void setUp() throws Exception {
allowTestableLooperAsMainThread();
Settings.Secure.putIntForUser(mContext.getContentResolver(), NOTIFICATION_HISTORY_ENABLED,
1, UserHandle.USER_CURRENT);
// Interact with real instance of AmbientState.
mAmbientState = new AmbientState(mContext, mNotificationSectionsManager, mBypassController);
@@ -150,6 +143,7 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase {
mStackScroller.setShelfController(notificationShelfController);
mStackScroller.setStatusBar(mBar);
mStackScroller.setEmptyShadeView(mEmptyShadeView);
when(mStackScrollLayoutController.isHistoryEnabled()).thenReturn(true);
when(mStackScrollLayoutController.getNoticationRoundessManager())
.thenReturn(mNotificationRoundnessManager);
mStackScroller.setController(mStackScrollLayoutController);
@@ -403,6 +397,22 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase {
verify(mStackScroller).updateFooterView(true, true, true);
}
@Test
public void testUpdateFooter_withoutHistory() {
setBarStateForTest(StatusBarState.SHADE);
mStackScroller.setCurrentUserSetup(true);
when(mStackScrollLayoutController.isHistoryEnabled()).thenReturn(false);
when(mStackScrollLayoutController.getVisibleNotificationCount()).thenReturn(1);
when(mStackScrollLayoutController.hasActiveClearableNotifications(eq(ROWS_ALL)))
.thenReturn(true);
FooterView view = mock(FooterView.class);
mStackScroller.setFooterView(view);
mStackScroller.updateFooter();
verify(mStackScroller).updateFooterView(true, true, false);
}
@Test
public void testUpdateFooter_oneClearableNotification_beforeUserSetup() {
setBarStateForTest(StatusBarState.SHADE);