Merge "New Pipeline: Add HeadsUpManagerLogger"

This commit is contained in:
Jeff DeCew
2021-11-08 18:27:41 +00:00
committed by Android (Google) Code Review
13 changed files with 241 additions and 49 deletions

View File

@@ -64,6 +64,7 @@ import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.policy.DeviceProvisionedControllerImpl;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.statusbar.policy.HeadsUpManagerLogger;
import com.android.systemui.statusbar.policy.IndividualSensorPrivacyController;
import com.android.systemui.statusbar.policy.IndividualSensorPrivacyControllerImpl;
import com.android.systemui.statusbar.policy.SensorPrivacyController;
@@ -169,12 +170,19 @@ public abstract class SystemUIDefaultModule {
@Provides
static HeadsUpManagerPhone provideHeadsUpManagerPhone(
Context context,
HeadsUpManagerLogger headsUpManagerLogger,
StatusBarStateController statusBarStateController,
KeyguardBypassController bypassController,
GroupMembershipManager groupManager,
ConfigurationController configurationController) {
return new HeadsUpManagerPhone(context, statusBarStateController, bypassController,
groupManager, configurationController);
return new HeadsUpManagerPhone(
context,
headsUpManagerLogger,
statusBarStateController,
bypassController,
groupManager,
configurationController
);
}
@Binds

View File

@@ -52,6 +52,14 @@ public class LogModule {
return factory.create("NotifLog", 1000);
}
/** Provides a logging buffer for all logs related to the data layer of notifications. */
@Provides
@SysUISingleton
@NotificationHeadsUpLog
public static LogBuffer provideNotificationHeadsUpLogBuffer(LogBufferFactory factory) {
return factory.create("NotifHeadsUpLog", 1000);
}
/** Provides a logging buffer for all logs related to managing notification sections. */
@Provides
@SysUISingleton

View File

@@ -0,0 +1,33 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.systemui.log.dagger;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import com.android.systemui.log.LogBuffer;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import javax.inject.Qualifier;
/** A {@link LogBuffer} for heads up notification-related messages. */
@Qualifier
@Documented
@Retention(RUNTIME)
public @interface NotificationHeadsUpLog {
}

View File

@@ -23,12 +23,12 @@ import android.os.Looper;
import android.os.SystemClock;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag;
import com.android.systemui.statusbar.policy.HeadsUpManagerLogger;
import java.util.stream.Stream;
@@ -41,6 +41,11 @@ public abstract class AlertingNotificationManager implements NotificationLifetim
private static final String TAG = "AlertNotifManager";
protected final Clock mClock = new Clock();
protected final ArrayMap<String, AlertEntry> mAlertEntries = new ArrayMap<>();
protected final HeadsUpManagerLogger mLogger;
public AlertingNotificationManager(HeadsUpManagerLogger logger) {
mLogger = logger;
}
/**
* This is the list of entries that have already been removed from the
@@ -61,9 +66,7 @@ public abstract class AlertingNotificationManager implements NotificationLifetim
* @param entry entry to show
*/
public void showNotification(@NonNull NotificationEntry entry) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "showNotification");
}
mLogger.logShowNotification(entry.getKey());
addAlertEntry(entry);
updateNotification(entry.getKey(), true /* alert */);
entry.setInterruption();
@@ -77,9 +80,7 @@ public abstract class AlertingNotificationManager implements NotificationLifetim
* @return true if notification is removed, false otherwise
*/
public boolean removeNotification(@NonNull String key, boolean releaseImmediately) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "removeNotification");
}
mLogger.logRemoveNotification(key, releaseImmediately);
AlertEntry alertEntry = mAlertEntries.get(key);
if (alertEntry == null) {
return true;
@@ -100,11 +101,8 @@ public abstract class AlertingNotificationManager implements NotificationLifetim
* removal time
*/
public void updateNotification(@NonNull String key, boolean alert) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "updateNotification");
}
AlertEntry alertEntry = mAlertEntries.get(key);
mLogger.logUpdateNotification(key, alert, alertEntry != null);
if (alertEntry == null) {
// the entry was released before this update (i.e by a listener) This can happen
// with the groupmanager
@@ -121,9 +119,7 @@ public abstract class AlertingNotificationManager implements NotificationLifetim
* Clears all managed notifications.
*/
public void releaseAllImmediately() {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "releaseAllImmediately");
}
mLogger.logReleaseAllImmediately();
// A copy is necessary here as we are changing the underlying map. This would cause
// undefined behavior if we iterated over the key set directly.
ArraySet<String> keysToRemove = new ArraySet<>(mAlertEntries.keySet());
@@ -300,9 +296,7 @@ public abstract class AlertingNotificationManager implements NotificationLifetim
* @param updatePostTime whether or not to refresh the post time
*/
public void updateEntry(boolean updatePostTime) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "updateEntry");
}
mLogger.logUpdateEntry(updatePostTime);
long currentTime = mClock.currentTimeMillis();
mEarliestRemovaltime = currentTime + mMinimumDisplayTime;

View File

@@ -38,6 +38,7 @@ import com.android.systemui.statusbar.notification.collection.render.GroupMember
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.statusbar.policy.HeadsUpManagerLogger;
import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener;
import java.io.FileDescriptor;
@@ -101,11 +102,12 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,
// Constructor:
public HeadsUpManagerPhone(@NonNull final Context context,
HeadsUpManagerLogger logger,
StatusBarStateController statusBarStateController,
KeyguardBypassController bypassController,
GroupMembershipManager groupMembershipManager,
ConfigurationController configurationController) {
super(context);
super(context, logger);
Resources resources = mContext.getResources();
mExtensionTime = resources.getInteger(R.integer.ambient_notification_extension_time);
mAutoHeadsUpNotificationDecay = resources.getInteger(

View File

@@ -26,7 +26,6 @@ import android.content.res.Resources;
import android.database.ContentObserver;
import android.provider.Settings;
import android.util.ArrayMap;
import android.util.Log;
import android.view.accessibility.AccessibilityManager;
import com.android.internal.logging.MetricsLogger;
@@ -81,7 +80,8 @@ public abstract class HeadsUpManager extends AlertingNotificationManager {
}
}
public HeadsUpManager(@NonNull final Context context) {
public HeadsUpManager(@NonNull final Context context, HeadsUpManagerLogger logger) {
super(logger);
mContext = context;
mAccessibilityMgr = Dependency.get(AccessibilityManagerWrapper.class);
mUiEventLogger = Dependency.get(UiEventLogger.class);
@@ -102,9 +102,7 @@ public abstract class HeadsUpManager extends AlertingNotificationManager {
context.getContentResolver(), SETTING_HEADS_UP_SNOOZE_LENGTH_MS, -1);
if (packageSnoozeLengthMs > -1 && packageSnoozeLengthMs != mSnoozeLengthMs) {
mSnoozeLengthMs = packageSnoozeLengthMs;
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "mSnoozeLengthMs = " + mSnoozeLengthMs);
}
mLogger.logSnoozeLengthChange(packageSnoozeLengthMs);
}
}
};
@@ -145,9 +143,7 @@ public abstract class HeadsUpManager extends AlertingNotificationManager {
protected void setEntryPinned(
@NonNull HeadsUpManager.HeadsUpEntry headsUpEntry, boolean isPinned) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "setEntryPinned: " + isPinned);
}
mLogger.logSetEntryPinned(headsUpEntry.mEntry.getKey(), isPinned);
NotificationEntry entry = headsUpEntry.mEntry;
if (entry.isRowPinned() != isPinned) {
entry.setRowPinned(isPinned);
@@ -198,10 +194,7 @@ public abstract class HeadsUpManager extends AlertingNotificationManager {
if (hasPinnedNotification == mHasPinnedNotification) {
return;
}
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "Pinned mode changed: " + mHasPinnedNotification + " -> " +
hasPinnedNotification);
}
mLogger.logUpdatePinnedMode(hasPinnedNotification);
mHasPinnedNotification = hasPinnedNotification;
if (mHasPinnedNotification) {
MetricsLogger.count(mContext, "note_peek", 1);
@@ -219,12 +212,11 @@ public abstract class HeadsUpManager extends AlertingNotificationManager {
Long snoozedUntil = mSnoozedPackages.get(key);
if (snoozedUntil != null) {
if (snoozedUntil > mClock.currentTimeMillis()) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, key + " snoozed");
}
mLogger.logIsSnoozedReturned(key);
return true;
}
mSnoozedPackages.remove(packageName);
mLogger.logPackageUnsnoozed(key);
mSnoozedPackages.remove(key);
}
return false;
}
@@ -236,8 +228,9 @@ public abstract class HeadsUpManager extends AlertingNotificationManager {
for (String key : mAlertEntries.keySet()) {
AlertEntry entry = getHeadsUpEntry(key);
String packageName = entry.mEntry.getSbn().getPackageName();
mSnoozedPackages.put(snoozeKey(packageName, mUser),
mClock.currentTimeMillis() + mSnoozeLengthMs);
String snoozeKey = snoozeKey(packageName, mUser);
mLogger.logPackageSnoozed(snoozeKey);
mSnoozedPackages.put(snoozeKey, mClock.currentTimeMillis() + mSnoozeLengthMs);
}
}

View File

@@ -0,0 +1,120 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.systemui.statusbar.policy
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogLevel.INFO
import com.android.systemui.log.LogLevel.VERBOSE
import com.android.systemui.log.dagger.NotificationHeadsUpLog
import javax.inject.Inject
/** Logger for [HeadsUpManager]. */
class HeadsUpManagerLogger @Inject constructor(
@NotificationHeadsUpLog private val buffer: LogBuffer
) {
fun logPackageSnoozed(snoozeKey: String) {
buffer.log(TAG, INFO, {
str1 = snoozeKey
}, {
"package snoozed $str1"
})
}
fun logPackageUnsnoozed(snoozeKey: String) {
buffer.log(TAG, INFO, {
str1 = snoozeKey
}, {
"package unsnoozed $str1"
})
}
fun logIsSnoozedReturned(snoozeKey: String) {
buffer.log(TAG, INFO, {
str1 = snoozeKey
}, {
"package snoozed when queried $str1"
})
}
fun logReleaseAllImmediately() {
buffer.log(TAG, INFO, { }, {
"release all immediately"
})
}
fun logShowNotification(key: String) {
buffer.log(TAG, INFO, {
str1 = key
}, {
"show notification $str1"
})
}
fun logRemoveNotification(key: String, releaseImmediately: Boolean) {
buffer.log(TAG, INFO, {
str1 = key
bool1 = releaseImmediately
}, {
"remove notification $str1 releaseImmediately: $bool1"
})
}
fun logUpdateNotification(key: String, alert: Boolean, hasEntry: Boolean) {
buffer.log(TAG, INFO, {
str1 = key
bool1 = alert
bool2 = hasEntry
}, {
"update notification $str1 alert: $bool1 hasEntry: $bool2"
})
}
fun logUpdateEntry(updatePostTime: Boolean) {
buffer.log(TAG, INFO, {
bool1 = updatePostTime
}, {
"update entry updatePostTime: $bool1"
})
}
fun logSnoozeLengthChange(packageSnoozeLengthMs: Int) {
buffer.log(TAG, INFO, {
int1 = packageSnoozeLengthMs
}, {
"snooze length changed: ${int1}ms"
})
}
fun logSetEntryPinned(key: String, isPinned: Boolean) {
buffer.log(TAG, VERBOSE, {
str1 = key
bool1 = isPinned
}, {
"set entry pinned $str1 pinned: $bool1"
})
}
fun logUpdatePinnedMode(hasPinnedNotification: Boolean) {
buffer.log(TAG, INFO, {
bool1 = hasPinnedNotification
}, {
"has pinned notification changed to $bool1"
})
}
}
private const val TAG = "HeadsUpManager"

View File

@@ -65,6 +65,7 @@ import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.policy.DeviceProvisionedControllerImpl;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.statusbar.policy.HeadsUpManagerLogger;
import com.android.systemui.statusbar.policy.IndividualSensorPrivacyController;
import com.android.systemui.statusbar.policy.IndividualSensorPrivacyControllerImpl;
import com.android.systemui.statusbar.policy.SensorPrivacyController;
@@ -162,12 +163,19 @@ public abstract class TvSystemUIModule {
@Provides
static HeadsUpManagerPhone provideHeadsUpManagerPhone(
Context context,
HeadsUpManagerLogger headsUpManagerLogger,
StatusBarStateController statusBarStateController,
KeyguardBypassController bypassController,
NotificationGroupManagerLegacy groupManager,
ConfigurationController configurationController) {
return new HeadsUpManagerPhone(context, statusBarStateController, bypassController,
groupManager, configurationController);
return new HeadsUpManagerPhone(
context,
headsUpManagerLogger,
statusBarStateController,
bypassController,
groupManager,
configurationController
);
}
@Binds

View File

@@ -23,6 +23,7 @@ import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -42,6 +43,7 @@ import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.policy.HeadsUpManagerLogger;
import org.junit.Before;
import org.junit.Rule;
@@ -81,6 +83,7 @@ public class AlertingNotificationManagerTest extends SysuiTestCase {
private AlertEntry mLastCreatedEntry;
private TestableAlertingNotificationManager() {
super(mock(HeadsUpManagerLogger.class));
mMinimumDisplayTime = TEST_MINIMUM_DISPLAY_TIME;
mAutoDismissNotificationDecay = TEST_AUTO_DISMISS_TIME;
mHandler = mTestHandler;

View File

@@ -68,6 +68,7 @@ import com.android.systemui.statusbar.notification.row.NotificationRowContentBin
import com.android.systemui.statusbar.phone.ConfigurationControllerImpl;
import com.android.systemui.statusbar.phone.HeadsUpManagerPhone;
import com.android.systemui.statusbar.phone.KeyguardBypassController;
import com.android.systemui.statusbar.policy.HeadsUpManagerLogger;
import com.android.systemui.statusbar.policy.InflatedSmartReplyState;
import com.android.systemui.statusbar.policy.InflatedSmartReplyViewHolder;
import com.android.systemui.statusbar.policy.SmartReplyStateInflater;
@@ -129,9 +130,14 @@ public class NotificationTestHelper {
Optional.of((mock(Bubbles.class))),
mock(DumpManager.class));
mGroupExpansionManager = mGroupMembershipManager;
mHeadsUpManager = new HeadsUpManagerPhone(mContext, mStatusBarStateController,
mock(KeyguardBypassController.class), mock(NotificationGroupManagerLegacy.class),
mock(ConfigurationControllerImpl.class));
mHeadsUpManager = new HeadsUpManagerPhone(
mContext,
mock(HeadsUpManagerLogger.class),
mStatusBarStateController,
mock(KeyguardBypassController.class),
mock(NotificationGroupManagerLegacy.class),
mock(ConfigurationControllerImpl.class)
);
mGroupMembershipManager.setHeadsUpManager(mHeadsUpManager);
mIconManager = new IconManager(
mock(CommonNotifCollection.class),

View File

@@ -39,6 +39,7 @@ import com.android.systemui.statusbar.notification.collection.legacy.Notificatio
import com.android.systemui.statusbar.notification.collection.legacy.VisualStabilityManager;
import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.HeadsUpManagerLogger;
import org.junit.Before;
import org.junit.Ignore;
@@ -57,6 +58,7 @@ public class HeadsUpManagerPhoneTest extends AlertingNotificationManagerTest {
private HeadsUpManagerPhone mHeadsUpManager;
@Mock private HeadsUpManagerLogger mHeadsUpManagerLogger;
@Mock private NotificationGroupManagerLegacy mGroupManager;
@Mock private View mNotificationShadeWindowView;
@Mock private VisualStabilityManager mVSManager;
@@ -69,14 +71,21 @@ public class HeadsUpManagerPhoneTest extends AlertingNotificationManagerTest {
private final class TestableHeadsUpManagerPhone extends HeadsUpManagerPhone {
TestableHeadsUpManagerPhone(
Context context,
HeadsUpManagerLogger headsUpManagerLogger,
NotificationGroupManagerLegacy groupManager,
VisualStabilityManager vsManager,
StatusBarStateController statusBarStateController,
KeyguardBypassController keyguardBypassController,
ConfigurationController configurationController
) {
super(context, statusBarStateController, keyguardBypassController,
groupManager, configurationController);
super(
context,
headsUpManagerLogger,
statusBarStateController,
keyguardBypassController,
groupManager,
configurationController
);
setup(vsManager);
mMinimumDisplayTime = TEST_MINIMUM_DISPLAY_TIME;
mAutoDismissNotificationDecay = TEST_AUTO_DISMISS_TIME;
@@ -96,8 +105,15 @@ public class HeadsUpManagerPhoneTest extends AlertingNotificationManagerTest {
when(mVSManager.isReorderingAllowed()).thenReturn(true);
mDependency.injectMockDependency(NotificationShadeWindowController.class);
mDependency.injectMockDependency(ConfigurationController.class);
mHeadsUpManager = new TestableHeadsUpManagerPhone(mContext, mGroupManager, mVSManager,
mStatusBarStateController, mBypassController, mConfigurationController);
mHeadsUpManager = new TestableHeadsUpManagerPhone(
mContext,
mHeadsUpManagerLogger,
mGroupManager,
mVSManager,
mStatusBarStateController,
mBypassController,
mConfigurationController
);
super.setUp();
mHeadsUpManager.mHandler = mTestHandler;
}

View File

@@ -48,6 +48,7 @@ import com.android.systemui.statusbar.notification.row.NotifBindPipeline.BindCal
import com.android.systemui.statusbar.notification.row.RowContentBindParams;
import com.android.systemui.statusbar.notification.row.RowContentBindStage;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.statusbar.policy.HeadsUpManagerLogger;
import com.android.wm.shell.bubbles.Bubbles;
import org.junit.Before;
@@ -86,7 +87,7 @@ public class NotificationGroupAlertTransferHelperTest extends SysuiTestCase {
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mHeadsUpManager = new HeadsUpManager(mContext) {};
mHeadsUpManager = new HeadsUpManager(mContext, mock(HeadsUpManagerLogger.class)) {};
when(mNotificationEntryManager.getPendingNotificationsIterator())
.thenReturn(mPendingEntries.values());

View File

@@ -60,7 +60,7 @@ public class HeadsUpManagerTest extends AlertingNotificationManagerTest {
private final class TestableHeadsUpManager extends HeadsUpManager {
TestableHeadsUpManager(Context context) {
super(context);
super(context, mock(HeadsUpManagerLogger.class));
mMinimumDisplayTime = TEST_MINIMUM_DISPLAY_TIME;
mAutoDismissNotificationDecay = TEST_AUTO_DISMISS_TIME;
}