Fix text extraction from notifications

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



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

R225 KDE Connect - Android application
No Linters Available
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(
        at org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationsPlugin.extractConversation(
        at org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationsPlugin.sendNotification(
        at org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationsPlugin.onNotificationPosted(
        at org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationReceiver.onNotificationPosted(
        at android.service.notification.NotificationListenerService.onNotificationPosted(
        at android.service.notification.NotificationListenerService$MyHandler.handleMessage(
        at android.os.Handler.dispatchMessage(
        at android.os.Looper.loop(
        at java.lang.reflect.Method.invoke(Native Method)

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