mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-12 18:57:36 +01:00
notif: sanitize strings set by external apps
It seems some apps like Telegram add a lot of Unicode Control sequences for unknown reasons. Because these strings are set by external apps, it is safer to sanitize them. For the moment, only Unicode control sequences are stripped. Fixes: #1344
This commit is contained in:
parent
632f6d86a3
commit
d60d10ddb1
@ -351,6 +351,11 @@ public class NotificationListener extends NotificationListenerService {
|
||||
GBApplication.deviceService().onNotification(notificationSpec);
|
||||
}
|
||||
|
||||
// Strip Unicode control sequences: some apps like Telegram add a lot of them for unknown reasons
|
||||
private String sanitizeUnicode(String orig) {
|
||||
return orig.replaceAll("\\p{C}", "");
|
||||
}
|
||||
|
||||
private void dissectNotificationTo(Notification notification, NotificationSpec notificationSpec, boolean preferBigText) {
|
||||
|
||||
Bundle extras = NotificationCompat.getExtras(notification);
|
||||
@ -359,7 +364,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
|
||||
CharSequence title = extras.getCharSequence(Notification.EXTRA_TITLE);
|
||||
if (title != null) {
|
||||
notificationSpec.title = title.toString();
|
||||
notificationSpec.title = sanitizeUnicode(title.toString());
|
||||
}
|
||||
|
||||
CharSequence contentCS = null;
|
||||
@ -369,7 +374,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
contentCS = extras.getCharSequence(NotificationCompat.EXTRA_TEXT);
|
||||
}
|
||||
if (contentCS != null) {
|
||||
notificationSpec.body = contentCS.toString();
|
||||
notificationSpec.body = sanitizeUnicode(contentCS.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user