forked from Blendman974/faceclaw
Clear notification popups when they're dismissed on the phone, and avoid showing some notifications that are spurious
This commit is contained in:
1 parent
42c2d5cd55
commit
bf92a5a2ce
17 files changed
+422
-70
No files matched your search
+25
-7
@@ -267,13 +267,21 @@ class FaceclawMediaNotificationListenerService : NotificationListenerService() {
|
||||
}
|
||||
|
||||
private fun emitNotificationPosted(key: String?) {
|
||||
emitNotificationEvent(key) { listener, eventKey -> listener.onNotificationPosted(eventKey) }
|
||||
}
|
||||
|
||||
private fun emitNotificationRemoved(key: String?) {
|
||||
emitNotificationEvent(key) { listener, eventKey -> listener.onNotificationRemoved(eventKey) }
|
||||
}
|
||||
|
||||
private fun emitNotificationEvent(key: String?, deliver: (FaceclawNotificationListener, String) -> Unit) {
|
||||
if (key == null || key.isEmpty() || notificationListeners.isEmpty()) {
|
||||
return
|
||||
}
|
||||
for (listener in notificationListeners) {
|
||||
mainHandler.post {
|
||||
try {
|
||||
listener.onNotificationPosted(key)
|
||||
deliver(listener, key)
|
||||
} catch (t: Throwable) {
|
||||
Log.w(TAG, "notification listener failed", t)
|
||||
}
|
||||
@@ -319,16 +327,17 @@ class FaceclawMediaNotificationListenerService : NotificationListenerService() {
|
||||
return !alreadyActive || !isPersistentNotification(statusBarNotification)
|
||||
}
|
||||
|
||||
private fun forgetActiveNotificationWakeKey(statusBarNotification: StatusBarNotification?) {
|
||||
/** Stop tracking a notification; returns whether it was tracked (i.e. listed on the glasses). */
|
||||
private fun forgetActiveNotificationWakeKey(statusBarNotification: StatusBarNotification?): Boolean {
|
||||
if (statusBarNotification == null) {
|
||||
return
|
||||
return false
|
||||
}
|
||||
val key: String? = statusBarNotification.key
|
||||
if (key == null || key.isEmpty()) {
|
||||
return
|
||||
return false
|
||||
}
|
||||
synchronized(activeNotificationWakeKeys) {
|
||||
activeNotificationWakeKeys.remove(key)
|
||||
return activeNotificationWakeKeys.remove(key)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -531,6 +540,7 @@ class FaceclawMediaNotificationListenerService : NotificationListenerService() {
|
||||
out.put("appName", getNotificationAppName(service, statusBarNotification))
|
||||
out.put("postTime", statusBarNotification.postTime)
|
||||
out.put("when", notification.`when`)
|
||||
out.put("foregroundService", (notification.flags and Notification.FLAG_FOREGROUND_SERVICE) != 0)
|
||||
putString(out, "category", notification.category)
|
||||
if (extras != null) {
|
||||
putCharSequence(out, "title", firstNonEmpty(
|
||||
@@ -654,7 +664,10 @@ class FaceclawMediaNotificationListenerService : NotificationListenerService() {
|
||||
override fun onNotificationPosted(statusBarNotification: StatusBarNotification?) {
|
||||
super.onNotificationPosted(statusBarNotification)
|
||||
if (!shouldShowNotificationInList(this, statusBarNotification)) {
|
||||
forgetActiveNotificationWakeKey(statusBarNotification)
|
||||
// An update that takes a listed notification off the list removes it as far as the glasses go.
|
||||
if (forgetActiveNotificationWakeKey(statusBarNotification)) {
|
||||
emitNotificationRemoved(statusBarNotification!!.key)
|
||||
}
|
||||
return
|
||||
}
|
||||
if (shouldEmitNotificationPosted(statusBarNotification!!)) {
|
||||
@@ -663,7 +676,12 @@ class FaceclawMediaNotificationListenerService : NotificationListenerService() {
|
||||
}
|
||||
|
||||
override fun onNotificationRemoved(statusBarNotification: StatusBarNotification?) {
|
||||
forgetActiveNotificationWakeKey(statusBarNotification)
|
||||
// Includes notifications their source cancels on its own, e.g. a
|
||||
// short-lived foreground-service notification that was standing in
|
||||
// for one posted moments later under another key.
|
||||
if (forgetActiveNotificationWakeKey(statusBarNotification)) {
|
||||
emitNotificationRemoved(statusBarNotification!!.key)
|
||||
}
|
||||
super.onNotificationRemoved(statusBarNotification)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user