aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/dev/msfjarvis/aps/util/services/ClipboardService.kt
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-05-28 01:48:39 +0530
committerGitHub <noreply@github.com>2022-05-27 20:18:39 +0000
commit184391599b3b2946a485fc31e3b6896d2ab6f303 (patch)
tree50663ba3b5c3fb43383b864b90e38e364d15cdfa /app/src/main/java/dev/msfjarvis/aps/util/services/ClipboardService.kt
parentfb7c81124cce8f89aeaa282ecdfdcdc65c460acd (diff)
downloadHardenedPass-184391599b3b2946a485fc31e3b6896d2ab6f303.tar.gz
HardenedPass-184391599b3b2946a485fc31e3b6896d2ab6f303.zip
Fix ClipboardService crash (#1928)
* Fix clipboard service crash on API 31 * all: use ints directly for SDK version checks I much prefer it this way
Diffstat (limited to 'app/src/main/java/dev/msfjarvis/aps/util/services/ClipboardService.kt')
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/util/services/ClipboardService.kt19
1 files changed, 14 insertions, 5 deletions
diff --git a/app/src/main/java/dev/msfjarvis/aps/util/services/ClipboardService.kt b/app/src/main/java/dev/msfjarvis/aps/util/services/ClipboardService.kt
index 580cd4b5..34c3a989 100644
--- a/app/src/main/java/dev/msfjarvis/aps/util/services/ClipboardService.kt
+++ b/app/src/main/java/dev/msfjarvis/aps/util/services/ClipboardService.kt
@@ -112,8 +112,17 @@ class ClipboardService : Service() {
val clearTimeMs = clearTime * 1000L
val clearIntent = Intent(this, ClipboardService::class.java).apply { action = ACTION_CLEAR }
val pendingIntent =
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- PendingIntent.getForegroundService(this, 0, clearIntent, PendingIntent.FLAG_UPDATE_CURRENT)
+ if (Build.VERSION.SDK_INT >= 26) {
+ PendingIntent.getForegroundService(
+ this,
+ 0,
+ clearIntent,
+ if (Build.VERSION.SDK_INT >= 31) {
+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
+ } else {
+ PendingIntent.FLAG_UPDATE_CURRENT
+ }
+ )
} else {
PendingIntent.getService(
this,
@@ -127,7 +136,7 @@ class ClipboardService : Service() {
)
}
val notification =
- if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
+ if (Build.VERSION.SDK_INT <= 23) {
createNotificationApi23(pendingIntent)
} else {
createNotificationApi24(pendingIntent, clearTimeMs)
@@ -148,7 +157,7 @@ class ClipboardService : Service() {
.build()
}
- @RequiresApi(Build.VERSION_CODES.N)
+ @RequiresApi(24)
private fun createNotificationApi24(
pendingIntent: PendingIntent,
clearTimeMs: Long
@@ -167,7 +176,7 @@ class ClipboardService : Service() {
}
private fun createNotificationChannel() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ if (Build.VERSION.SDK_INT >= 26) {
val serviceChannel =
NotificationChannel(
CHANNEL_ID,