Skip to content

Fix notification channel names not being set when creating notification channels

Summary

This PR fixes the app crashing at startup when setting up notification channels.

Notification channels require a non-empty name. Failing to specify one results in a crash. I've changed the current code to set the names instead of descriptions.

The crash I'm getting most probably relates to this line in the Android source code.

java.lang.RuntimeException: Unable to create service org.kde.kdeconnect.BackgroundService: java.lang.IllegalArgumentException
	at android.app.ActivityThread.handleCreateService(ActivityThread.java:4567)
	at android.app.ActivityThread.access$1700(ActivityThread.java:256)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2110)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:201)
	at android.os.Looper.loop(Looper.java:288)
	at android.app.ActivityThread.main(ActivityThread.java:7870)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.lang.IllegalArgumentException
	at android.os.Parcel.createExceptionOrNull(Parcel.java:2430)
	at android.os.Parcel.createException(Parcel.java:2410)
	at android.os.Parcel.readException(Parcel.java:2393)
	at android.os.Parcel.readException(Parcel.java:2335)
	at android.app.INotificationManager$Stub$Proxy.createNotificationChannels(INotificationManager.java:4020)
	at android.app.NotificationManager.createNotificationChannels(NotificationManager.java:928)
	at androidx.core.app.NotificationManagerCompat.createNotificationChannelsCompat(NotificationManagerCompat.java:376)
	at org.kde.kdeconnect.Helpers.NotificationHelper.initializeChannels(NotificationHelper.java:82)
	at org.kde.kdeconnect.BackgroundService.onCreate(BackgroundService.java:270)
	at android.app.ActivityThread.handleCreateService(ActivityThread.java:4554)
	at android.app.ActivityThread.access$1700(ActivityThread.java:256) 
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2110) 
	at android.os.Handler.dispatchMessage(Handler.java:106) 
	at android.os.Looper.loopOnce(Looper.java:201) 
	at android.os.Looper.loop(Looper.java:288) 
	at android.app.ActivityThread.main(ActivityThread.java:7870) 
	at java.lang.reflect.Method.invoke(Native Method) 
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 
Caused by: android.os.RemoteException: Remote stack trace:
	at com.android.internal.util.Preconditions.checkArgument(Preconditions.java:44)
	at com.android.server.notification.PreferencesHelper.createNotificationChannel(PreferencesHelper.java:845)
	at com.android.server.notification.NotificationManagerService$11.createNotificationChannelsImpl(NotificationManagerService.java:3700)
	at com.android.server.notification.NotificationManagerService$11.createNotificationChannels(NotificationManagerService.java:3721)
	at android.app.INotificationManager$Stub.onTransact(INotificationManager.java:1588)

Test Plan

Before:

Launch the app. It crashes immediately.

After:

Launch the app. It does not crash. Notification channels can be viewed in the app's system settings.

Merge request reports

Loading