Fix text extraction from notifications
ClosedPublic

Authored by di72nn on Jun 28 2019, 12:51 PM.

Details

Summary

Fixes an error of extracting SpannableString as String (which resulted in notification text being null).
Fixes group conversation text extraction on API <28.
Also includes some minor refactoring.

Diff Detail

Repository
R225 KDE Connect - Android application
Branch
fix_notifications
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 13370
Build 13388: arc lint + arc unit
di72nn created this revision.Jun 28 2019, 12:51 PM
Restricted Application added a project: KDE Connect. · View Herald TranscriptJun 28 2019, 12:51 PM
Restricted Application added a subscriber: kdeconnect. · View Herald Transcript
di72nn requested review of this revision.Jun 28 2019, 12:51 PM

I'm not familiar with arcanist, so I'll just add some extra info in a message.

There was a warning message in logs (when a message received in Conversations, for example):

org.kde.kdeconnect_tp W/Bundle: Key text expected String but value was a android.text.SpannableString.  The default value <null> was returned.
org.kde.kdeconnect_tp W/Bundle: Attempt to cast generated internal exception:
    java.lang.ClassCastException: android.text.SpannableString cannot be cast to java.lang.String
        at android.os.BaseBundle.getString(BaseBundle.java:1121)
        at org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationsPlugin.extractConversation(NotificationsPlugin.java:380)
        at org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationsPlugin.sendNotification(NotificationsPlugin.java:254)
        at org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationsPlugin.onNotificationPosted(NotificationsPlugin.java:179)
        at org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationReceiver.onNotificationPosted(NotificationReceiver.java:63)
        at android.service.notification.NotificationListenerService.onNotificationPosted(NotificationListenerService.java:317)
        at android.service.notification.NotificationListenerService$MyHandler.handleMessage(NotificationListenerService.java:1830)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Also Notification.EXTRA_IS_GROUP_CONVERSATION was replaced with a NotificationCompat equivalent which does make a difference on Android <9 (tested on Android 8.1 with Conversations).

Other Build.VERSION.SDK_INT-related changes are not so important, but can improve something on pre-KITKAT devices.

Oh, and thanks for all the great work you guys put into this app!

nicolasfella accepted this revision.Jul 5 2019, 9:11 AM

Thank you!

This revision is now accepted and ready to land.Jul 5 2019, 9:11 AM
nicolasfella closed this revision.Jul 5 2019, 9:11 AM