Skip to content
Snippets Groups Projects
Commit 90a77104 authored by LuK1337's avatar LuK1337 Committed by Dhina17
Browse files

core: Move notification timeout code to NotificationAttentionHelper

14 QRP3 enabled refactor_attention_helper flag.

Fixes: https://gitlab.com/LineageOS/issues/android/-/issues/7458
Change-Id: I2bbcd8d16587fe38eebf24eea159d968c5256ede
parent 13e04d1a
No related merge requests found
......@@ -50,6 +50,7 @@ import android.media.IRingtonePlayer;
import android.net.Uri;
import android.os.Binder;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
......@@ -58,9 +59,11 @@ import android.provider.Settings;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Pair;
import android.util.Slog;
import android.util.TimeUtils;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
......@@ -158,6 +161,7 @@ public final class NotificationAttentionHelper {
private final AudioAttributes mInCallNotificationAudioAttributes;
private final float mInCallNotificationVolume;
private Binder mCallNotificationToken = null;
private final ArrayMap<String, Long> mLastSoundTimestamps = new ArrayMap<>();
private LineageNotificationLights mLineageNotificationLights;
// Settings flags
......@@ -430,7 +434,8 @@ public final class NotificationAttentionHelper {
boolean vibrateOnly =
hasValidVibrate && mNotificationCooldownVibrateUnlocked && mUserPresent;
boolean hasAudibleAlert = hasValidSound || hasValidVibrate;
if (hasAudibleAlert && !shouldMuteNotificationLocked(record, signals)) {
if (hasAudibleAlert && !shouldMuteNotificationLocked(record, signals)
&& !isInSoundTimeoutPeriod(record)) {
if (!sentAccessibilityEvent) {
sendAccessibilityEvent(record);
sentAccessibilityEvent = true;
......@@ -521,6 +526,10 @@ public final class NotificationAttentionHelper {
}
}
}
if (buzz || beep) {
mLastSoundTimestamps.put(generateLastSoundTimeoutKey(record),
SystemClock.elapsedRealtime());
}
final int buzzBeepBlinkLoggingCode =
(buzz ? 1 : 0) | (beep ? 2 : 0) | (blink ? 4 : 0) | getPoliteBit(record);
if (buzzBeepBlinkLoggingCode > 0) {
......@@ -541,6 +550,24 @@ public final class NotificationAttentionHelper {
return buzzBeepBlinkLoggingCode;
}
private boolean isInSoundTimeoutPeriod(NotificationRecord record) {
long timeoutMillis = mNMP.getNotificationSoundTimeout(
record.getSbn().getPackageName(), record.getSbn().getUid());
if (timeoutMillis == 0) {
return false;
}
Long value = mLastSoundTimestamps.get(generateLastSoundTimeoutKey(record));
if (value == null) {
return false;
}
return SystemClock.elapsedRealtime() - value < timeoutMillis;
}
private String generateLastSoundTimeoutKey(NotificationRecord record) {
return record.getSbn().getPackageName() + "|" + record.getSbn().getUid();
}
private int getPoliteBit(final NotificationRecord record) {
switch (getPolitenessState(record)) {
case PolitenessStrategy.POLITE_STATE_POLITE:
......@@ -1099,6 +1126,14 @@ public final class NotificationAttentionHelper {
pw.print(prefix);
pw.println(" mNotificationPulseEnabled=" + mNotificationPulseEnabled);
long now = SystemClock.elapsedRealtime();
pw.println("\n Last notification sound timestamps:");
for (Map.Entry<String, Long> entry : mLastSoundTimestamps.entrySet()) {
pw.print(" " + entry.getKey() + " -> ");
TimeUtils.formatDuration(entry.getValue(), now, pw);
pw.println(" ago");
}
int N = mLights.size();
if (N > 0) {
pw.print(prefix);
......
......@@ -25,4 +25,5 @@ import android.annotation.Nullable;
interface NotificationManagerPrivate {
@Nullable
NotificationRecord getNotificationByKey(String key);
long getNotificationSoundTimeout(String pkg, int uid);
}
......@@ -310,7 +310,6 @@ import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.util.StatsEvent;
import android.util.TimeUtils;
import android.util.Xml;
import android.util.proto.ProtoOutputStream;
import android.view.Display;
......@@ -690,7 +689,6 @@ public class NotificationManagerService extends SystemService {
@GuardedBy("mToastQueue")
private final Set<Integer> mToastRateLimitingDisabledUids = new ArraySet<>();
final ArrayMap<String, NotificationRecord> mSummaryByGroupKey = new ArrayMap<>();
final ArrayMap<String, Long> mLastSoundTimestamps = new ArrayMap<>();
 
// True if the toast that's on top of the queue is being shown at the moment.
@GuardedBy("mToastQueue")
......@@ -1792,9 +1790,17 @@ public class NotificationManagerService extends SystemService {
 
};
 
NotificationManagerPrivate mNotificationManagerPrivate = key -> {
synchronized (mNotificationLock) {
return mNotificationsByKey.get(key);
NotificationManagerPrivate mNotificationManagerPrivate = new NotificationManagerPrivate() {
@Override
public NotificationRecord getNotificationByKey(String key) {
synchronized (mNotificationLock) {
return mNotificationsByKey.get(key);
}
}
@Override
public long getNotificationSoundTimeout(String pkg, int uid) {
return mPreferencesHelper.getNotificationSoundTimeout(pkg, uid);
}
};
 
......@@ -7176,14 +7182,6 @@ public class NotificationManagerService extends SystemService {
pw.println("\n Usage Stats:");
mUsageStats.dump(pw, " ", filter);
}
long now = SystemClock.elapsedRealtime();
pw.println("\n Last notification sound timestamps:");
for (Map.Entry<String, Long> entry : mLastSoundTimestamps.entrySet()) {
pw.print(" " + entry.getKey() + " -> ");
TimeUtils.formatDuration(entry.getValue(), now, pw);
pw.println(" ago");
}
}
}
 
......@@ -9257,8 +9255,7 @@ public class NotificationManagerService extends SystemService {
}
hasValidVibrate = vibration != null;
boolean hasAudibleAlert = hasValidSound || hasValidVibrate;
if (hasAudibleAlert && !shouldMuteNotificationLocked(record)
&& !isInSoundTimeoutPeriod(record)) {
if (hasAudibleAlert && !shouldMuteNotificationLocked(record)) {
if (!sentAccessibilityEvent) {
sendAccessibilityEvent(record);
sentAccessibilityEvent = true;
......@@ -9329,10 +9326,6 @@ public class NotificationManagerService extends SystemService {
} else if (wasShowLights) {
updateLightsLocked();
}
if (buzz || beep) {
mLastSoundTimestamps.put(generateLastSoundTimeoutKey(record),
SystemClock.elapsedRealtime());
}
final int buzzBeepBlink = (buzz ? 1 : 0) | (beep ? 2 : 0) | (blink ? 4 : 0);
if (buzzBeepBlink > 0) {
// Ignore summary updates because we don't display most of the information.
......@@ -9363,24 +9356,6 @@ public class NotificationManagerService extends SystemService {
return buzzBeepBlink;
}
 
private boolean isInSoundTimeoutPeriod(NotificationRecord record) {
long timeoutMillis = mPreferencesHelper.getNotificationSoundTimeout(
record.getSbn().getPackageName(), record.getSbn().getUid());
if (timeoutMillis == 0) {
return false;
}
Long value = mLastSoundTimestamps.get(generateLastSoundTimeoutKey(record));
if (value == null) {
return false;
}
return SystemClock.elapsedRealtime() - value < timeoutMillis;
}
private String generateLastSoundTimeoutKey(NotificationRecord record) {
return record.getSbn().getPackageName() + "|" + record.getSbn().getUid();
}
@GuardedBy("mNotificationLock")
boolean canShowLightsLocked(final NotificationRecord record, boolean aboveThreshold) {
// device lacks light
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment