@@ -102,6 +102,40 @@ class KeyguardClipboardService : Service(), DIAware {
102102 ) = Intent (context, KeyguardClipboardService ::class .java).apply {
103103 putExtra(KEY_ARGUMENTS , args)
104104 }
105+
106+ //
107+ // Notification channel
108+ //
109+
110+ fun createNotificationChannel (
111+ context : Context ,
112+ clipboardService : ClipboardService ,
113+ ): String {
114+ val channelImportance = if (clipboardService.hasCopyNotification()) {
115+ NotificationManager .IMPORTANCE_DEFAULT
116+ } else {
117+ NotificationManager .IMPORTANCE_HIGH
118+ }
119+ val channel = kotlin.run {
120+ val id = context.getString(R .string.notification_clipboard_channel_id)
121+ val name = context.getString(R .string.notification_clipboard_channel_name)
122+ NotificationChannel (id, name, channelImportance)
123+ }
124+ channel.enableVibration(false )
125+ val audioUri = getAudioUri(context)
126+ val audioAttributes = AudioAttributes .Builder ()
127+ .setContentType(AudioAttributes .CONTENT_TYPE_SONIFICATION )
128+ .setUsage(AudioAttributes .USAGE_NOTIFICATION )
129+ .build()
130+ channel.setSound(audioUri, audioAttributes)
131+ val nm = context.getSystemService<NotificationManager >()!!
132+ nm.createNotificationChannel(channel)
133+ return channel.id
134+ }
135+
136+ private fun getAudioUri (context : Context ) =
137+ " ${ContentResolver .SCHEME_ANDROID_RESOURCE } ://${context.packageName} /${R .raw.silence} "
138+ .toUri()
105139 }
106140
107141 sealed interface Args : Parcelable {
@@ -394,7 +428,7 @@ class KeyguardClipboardService : Service(), DIAware {
394428 else -> R .drawable.ic_number_9_plus
395429 }
396430
397- val contentTitle = if (autoCopy) {
431+ val contentTitle = if (autoCopy) {
398432 when (type) {
399433 CopyValueEvent .Type .TOTP -> org.jetbrains.compose.resources.getString(Res .string.copied_otp_code)
400434 CopyValueEvent .Type .VALUE -> org.jetbrains.compose.resources.getString(Res .string.copied_value)
@@ -452,7 +486,7 @@ class KeyguardClipboardService : Service(), DIAware {
452486 }
453487
454488 val channelId = createNotificationChannel()
455- val audioUri = getAudioUri()
489+ val audioUri = getAudioUri(this )
456490 return NotificationCompat .Builder (this , channelId)
457491 .setForegroundServiceBehavior(NotificationCompat .FOREGROUND_SERVICE_IMMEDIATE )
458492 .setContentTitle(contentTitle)
@@ -468,30 +502,8 @@ class KeyguardClipboardService : Service(), DIAware {
468502 .build()
469503 }
470504
471- private fun createNotificationChannel (): String {
472- val channelImportance = if (clipboardService.hasCopyNotification()) {
473- NotificationManager .IMPORTANCE_DEFAULT
474- } else {
475- NotificationManager .IMPORTANCE_HIGH
476- }
477- val channel = kotlin.run {
478- val id = getString(R .string.notification_clipboard_channel_id)
479- val name = getString(R .string.notification_clipboard_channel_name)
480- NotificationChannel (id, name, channelImportance)
481- }
482- channel.enableVibration(false )
483- val audioUri = getAudioUri()
484- val audioAttributes = AudioAttributes .Builder ()
485- .setContentType(AudioAttributes .CONTENT_TYPE_SONIFICATION )
486- .setUsage(AudioAttributes .USAGE_NOTIFICATION )
487- .build()
488- channel.setSound(audioUri, audioAttributes)
489- val nm = getSystemService<NotificationManager >()!!
490- nm.createNotificationChannel(channel)
491- return channel.id
492- }
493-
494- private fun getAudioUri () =
495- " ${ContentResolver .SCHEME_ANDROID_RESOURCE } ://${applicationContext.packageName} /${R .raw.silence} "
496- .toUri()
505+ private fun createNotificationChannel (): String = createNotificationChannel(
506+ context = this ,
507+ clipboardService = clipboardService,
508+ )
497509}
0 commit comments