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

core: Move Lineage notification LED code to NotificationAttentionHelper

14 QRP3 enabled refactor_attention_helper flag.

Change-Id: I1fe99c53f7cfa2b10828f72d092bbcc46321ef78
parent 45b7963f
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (C) 2023 The Android Open Source Project
* Copyright (C) 2015 The CyanogenMod Project
* Copyright (C) 2017 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -73,6 +75,9 @@ import com.android.server.EventLogTags;
import com.android.server.lights.LightsManager;
import com.android.server.lights.LogicalLight;
import com.libremobileos.notification.LedValues;
import com.libremobileos.notification.LineageNotificationLights;
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
......@@ -153,6 +158,7 @@ public final class NotificationAttentionHelper {
private final AudioAttributes mInCallNotificationAudioAttributes;
private final float mInCallNotificationVolume;
private Binder mCallNotificationToken = null;
private LineageNotificationLights mLineageNotificationLights;
// Settings flags
private boolean mNotificationCooldownEnabled;
......@@ -205,6 +211,22 @@ public final class NotificationAttentionHelper {
.build();
mInCallNotificationVolume = resources.getFloat(R.dimen.config_inCallNotificationVolume);
mLineageNotificationLights = new LineageNotificationLights(mContext,
new LineageNotificationLights.LedUpdater() {
public void update() {
updateLightsLocked();
}
});
mZenModeHelper.addCallback(new ZenModeHelper.Callback() {
@Override
void onZenModeChanged() {
Binder.withCleanCallingIdentity(() -> {
mLineageNotificationLights.setZenMode(mZenModeHelper.getZenMode());
});
}
});
if (Flags.politeNotifications()) {
mStrategy = createPolitenessStrategy();
} else {
......@@ -809,9 +831,11 @@ public final class NotificationAttentionHelper {
}
private void clearLightsLocked() {
// light
mLights.clear();
updateLightsLocked();
// clear only if lockscreen is not active
if (!mLineageNotificationLights.isKeyguardLocked()) {
mLights.clear();
updateLightsLocked();
}
}
public void clearEffectsLocked(String key) {
......@@ -849,25 +873,57 @@ public final class NotificationAttentionHelper {
}
}
// Don't flash while we are in a call or screen is on
if (ledNotification == null || isInCall() || mScreenOn) {
NotificationRecord.Light light = ledNotification != null ?
ledNotification.getLight() : null;
if (ledNotification == null || mLineageNotificationLights == null || light == null) {
mNotificationLight.turnOff();
return;
}
int ledColor = light.color;
if (isLedForcedOn(ledNotification) && ledColor == 0) {
// User has requested color 0. However, lineage-sdk interprets
// color 0 as "supply a default" therefore adjust alpha to make
// the color still black but non-zero.
ledColor = 0x01000000;
}
LedValues ledValues = new LedValues(ledColor, light.onMs, light.offMs);
mLineageNotificationLights.calcLights(ledValues, ledNotification.getSbn().getPackageName(),
ledNotification.getSbn().getNotification(), mScreenOn || isInCall(),
ledNotification.getSuppressedVisualEffects());
if (!ledValues.isEnabled()) {
mNotificationLight.turnOff();
} else {
NotificationRecord.Light light = ledNotification.getLight();
if (light != null && mNotificationPulseEnabled) {
// pulse repeatedly
mNotificationLight.setFlashing(light.color, LogicalLight.LIGHT_FLASH_TIMED,
light.onMs, light.offMs);
mNotificationLight.setModes(ledValues.getBrightness());
// we are using 1:0 to indicate LED should stay always on
if (ledValues.getOnMs() == 1 && ledValues.getOffMs() == 0) {
mNotificationLight.setColor(ledValues.getColor());
} else {
mNotificationLight.setFlashing(ledValues.getColor(),
LogicalLight.LIGHT_FLASH_TIMED, ledValues.getOnMs(), ledValues.getOffMs());
}
}
}
private boolean isLedForcedOn(NotificationRecord nr) {
return nr != null && mLineageNotificationLights.isForcedOn(nr.getSbn().getNotification());
}
boolean canShowLightsLocked(final NotificationRecord record, final Signals signals,
boolean aboveThreshold) {
// device lacks light
if (!mHasLight) {
return false;
}
// Forced on
// Used by LineageParts light picker
// eg to allow selecting battery light color when notification led is turned off.
if (isLedForcedOn(record)) {
return true;
}
// user turned lights off globally
if (!mNotificationPulseEnabled) {
return false;
......@@ -880,10 +936,6 @@ public final class NotificationAttentionHelper {
if (!aboveThreshold) {
return false;
}
// suppressed due to DND
if ((record.getSuppressedVisualEffects() & SUPPRESSED_EFFECT_LIGHTS) != 0) {
return false;
}
// Suppressed because it's a silent update
final Notification notification = record.getNotification();
if (record.isUpdate && (notification.flags & FLAG_ONLY_ALERT_ONCE) != 0) {
......@@ -893,10 +945,6 @@ public final class NotificationAttentionHelper {
if (record.getSbn().isGroup() && record.getNotification().suppressAlertingDueToGrouping()) {
return false;
}
// not if in call
if (isInCall()) {
return false;
}
// check current user
if (!isNotificationForCurrentUser(record, signals)) {
return false;
......@@ -1464,7 +1512,10 @@ public final class NotificationAttentionHelper {
mUserPresent = true;
// turn off LED when user passes through lock screen
if (mNotificationLight != null) {
mNotificationLight.turnOff();
// if lights with screen on is disabled.
if (!mLineageNotificationLights.showLightsScreenOn()) {
mNotificationLight.turnOff();
}
}
} else if (action.equals(Intent.ACTION_USER_ADDED)
|| action.equals(Intent.ACTION_USER_REMOVED)
......
/*
* Copyright (C) 2007 The Android Open Source Project
* Copyright (C) 2015 The CyanogenMod Project
* Copyright (C) 2017 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -374,9 +372,6 @@ import com.android.server.wm.ActivityTaskManagerInternal;
import com.android.server.wm.BackgroundActivityStartCallback;
import com.android.server.wm.WindowManagerInternal;
 
import com.libremobileos.notification.LedValues;
import com.libremobileos.notification.LineageNotificationLights;
import libcore.io.IoUtils;
 
import org.json.JSONException;
......@@ -783,8 +778,6 @@ public class NotificationManagerService extends SystemService {
// Broadcast intent receiver for notification permissions review-related intents
private ReviewNotificationPermissionsReceiver mReviewNotificationPermissionsReceiver;
 
private LineageNotificationLights mLineageNotificationLights;
private AppLockManagerServiceInternal mAppLockManagerService = null;
 
static class Archive {
......@@ -1863,11 +1856,8 @@ public class NotificationManagerService extends SystemService {
@GuardedBy("mNotificationLock")
private void clearLightsLocked() {
// light
// clear only if lockscreen is not active
if (!mLineageNotificationLights.isKeyguardLocked()) {
mLights.clear();
updateLightsLocked();
}
mLights.clear();
updateLightsLocked();
}
 
@GuardedBy("mNotificationLock")
......@@ -2089,9 +2079,7 @@ public class NotificationManagerService extends SystemService {
} else if (action.equals(Intent.ACTION_USER_PRESENT)) {
// turn off LED when user passes through lock screen
if (mNotificationLight != null) {
if (!mLineageNotificationLights.showLightsScreenOn()) {
mNotificationLight.turnOff();
}
mNotificationLight.turnOff();
}
}
}
......@@ -2589,7 +2577,6 @@ public class NotificationManagerService extends SystemService {
new Intent(ACTION_INTERRUPTION_FILTER_CHANGED_INTERNAL)
.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT),
UserHandle.ALL, permission.MANAGE_NOTIFICATIONS);
mLineageNotificationLights.setZenMode(mZenModeHelper.getZenMode());
synchronized (mNotificationLock) {
updateInterruptionFilterLocked();
}
......@@ -2894,13 +2881,6 @@ public class NotificationManagerService extends SystemService {
getContext().getSystemService(PowerManager.class),
new PostNotificationTrackerFactory() {});
 
mLineageNotificationLights = new LineageNotificationLights(getContext(),
new LineageNotificationLights.LedUpdater() {
public void update() {
updateNotificationPulse();
}
});
publishBinderService(Context.NOTIFICATION_SERVICE, mService, /* allowIsolated= */ false,
DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PRIORITY_NORMAL);
publishBinderService(Context.NOTIFICATION_SERVICE, mService);
......@@ -9407,12 +9387,6 @@ public class NotificationManagerService extends SystemService {
if (!mHasLight) {
return false;
}
// Forced on
// Used by LineageParts light picker
// eg to allow selecting battery light color when notification led is turned off.
if (isLedForcedOn(record)) {
return true;
}
// user turned lights off globally
if (!mNotificationPulseEnabled) {
return false;
......@@ -9425,6 +9399,10 @@ public class NotificationManagerService extends SystemService {
if (!aboveThreshold) {
return false;
}
// suppressed due to DND
if ((record.getSuppressedVisualEffects() & SUPPRESSED_EFFECT_LIGHTS) != 0) {
return false;
}
// Suppressed because it's a silent update
final Notification notification = record.getNotification();
if (record.isUpdate && (notification.flags & FLAG_ONLY_ALERT_ONCE) != 0) {
......@@ -9434,6 +9412,10 @@ public class NotificationManagerService extends SystemService {
if (record.getSbn().isGroup() && record.getNotification().suppressAlertingDueToGrouping()) {
return false;
}
// not if in call
if (isInCall()) {
return false;
}
// check current user
if (!isNotificationForCurrentUser(record)) {
return false;
......@@ -10854,45 +10836,19 @@ public class NotificationManagerService extends SystemService {
}
}
 
NotificationRecord.Light light = ledNotification != null ?
ledNotification.getLight() : null;
if (ledNotification == null || mLineageNotificationLights == null || light == null) {
mNotificationLight.turnOff();
return;
}
int ledColor = light.color;
if (isLedForcedOn(ledNotification) && ledColor == 0) {
// User has requested color 0. However, lineage-sdk interprets
// color 0 as "supply a default" therefore adjust alpha to make
// the color still black but non-zero.
ledColor = 0x01000000;
}
LedValues ledValues = new LedValues(ledColor, light.onMs, light.offMs);
mLineageNotificationLights.calcLights(ledValues, ledNotification.getSbn().getPackageName(),
ledNotification.getSbn().getNotification(), mScreenOn || isInCall(),
ledNotification.getSuppressedVisualEffects());
if (!ledValues.isEnabled()) {
// Don't flash while we are in a call or screen is on
if (ledNotification == null || isInCall() || mScreenOn) {
mNotificationLight.turnOff();
} else {
mNotificationLight.setModes(ledValues.getBrightness());
// we are using 1:0 to indicate LED should stay always on
if (ledValues.getOnMs() == 1 && ledValues.getOffMs() == 0) {
mNotificationLight.setColor(ledValues.getColor());
} else {
mNotificationLight.setFlashing(ledValues.getColor(),
LogicalLight.LIGHT_FLASH_TIMED, ledValues.getOnMs(), ledValues.getOffMs());
NotificationRecord.Light light = ledNotification.getLight();
if (light != null && mNotificationPulseEnabled) {
// pulse repeatedly
mNotificationLight.setFlashing(light.color, LogicalLight.LIGHT_FLASH_TIMED,
light.onMs, light.offMs);
}
}
}
 
private boolean isLedForcedOn(NotificationRecord nr) {
return nr != null && mLineageNotificationLights.isForcedOn(nr.getSbn().getNotification());
}
@GuardedBy("mNotificationLock")
@NonNull
List<NotificationRecord> findCurrentAndSnoozedGroupNotificationsLocked(String pkg,
......
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