Browse Source

Fix lint warnings.

test/jme/compound-poc
Benoit Marty 1 year ago committed by Benoit Marty
parent
commit
415830be1a
  1. 30
      libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/intent/PendingIntentCompat.kt
  2. 33
      libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationUtils.kt

30
libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/intent/PendingIntentCompat.kt

@ -1,30 +0,0 @@ @@ -1,30 +0,0 @@
/*
* Copyright (c) 2021 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.libraries.androidutils.intent
import android.app.PendingIntent
import android.os.Build
object PendingIntentCompat {
const val FLAG_IMMUTABLE = PendingIntent.FLAG_IMMUTABLE
val FLAG_MUTABLE = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_MUTABLE
} else {
0
}
}

33
libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationUtils.kt

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
package io.element.android.libraries.push.impl.notifications
import android.Manifest
import android.annotation.SuppressLint
import android.app.Activity
import android.app.Notification
@ -26,18 +27,19 @@ import android.app.NotificationManager @@ -26,18 +27,19 @@ import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.Canvas
import android.os.Build
import androidx.annotation.ChecksSdkIntAtLeast
import androidx.annotation.DrawableRes
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.RemoteInput
import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
import androidx.core.content.res.ResourcesCompat
import io.element.android.libraries.androidutils.intent.PendingIntentCompat
import io.element.android.libraries.androidutils.system.startNotificationChannelSettingsIntent
import io.element.android.libraries.androidutils.uri.createIgnoredUri
import io.element.android.libraries.core.meta.BuildMeta
@ -295,7 +297,7 @@ class NotificationUtils @Inject constructor( @@ -295,7 +297,7 @@ class NotificationUtils @Inject constructor(
context,
clock.epochMillis().toInt(),
markRoomReadIntent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntentCompat.FLAG_IMMUTABLE
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
NotificationCompat.Action.Builder(
@ -341,7 +343,7 @@ class NotificationUtils @Inject constructor( @@ -341,7 +343,7 @@ class NotificationUtils @Inject constructor(
context.applicationContext,
clock.epochMillis().toInt(),
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntentCompat.FLAG_IMMUTABLE
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
setDeleteIntent(pendingIntent)
}
@ -377,7 +379,7 @@ class NotificationUtils @Inject constructor( @@ -377,7 +379,7 @@ class NotificationUtils @Inject constructor(
context,
clock.epochMillis().toInt(),
rejectIntent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntentCompat.FLAG_IMMUTABLE
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
addAction(
@ -396,7 +398,7 @@ class NotificationUtils @Inject constructor( @@ -396,7 +398,7 @@ class NotificationUtils @Inject constructor(
context,
clock.epochMillis().toInt(),
joinIntent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntentCompat.FLAG_IMMUTABLE
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
addAction(
R.drawable.vector_notification_accept_invitation,
@ -489,7 +491,7 @@ class NotificationUtils @Inject constructor( @@ -489,7 +491,7 @@ class NotificationUtils @Inject constructor(
context,
clock.epochMillis().toInt(),
roomIntent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntentCompat.FLAG_IMMUTABLE
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
}
@ -505,7 +507,7 @@ class NotificationUtils @Inject constructor( @@ -505,7 +507,7 @@ class NotificationUtils @Inject constructor(
context,
clock.epochMillis().toInt(),
threadIntentTap,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntentCompat.FLAG_IMMUTABLE
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
}
@ -516,7 +518,7 @@ class NotificationUtils @Inject constructor( @@ -516,7 +518,7 @@ class NotificationUtils @Inject constructor(
context,
clock.epochMillis().toInt(),
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntentCompat.FLAG_IMMUTABLE
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
}
@ -549,7 +551,11 @@ class NotificationUtils @Inject constructor( @@ -549,7 +551,11 @@ class NotificationUtils @Inject constructor(
clock.epochMillis().toInt(),
intent,
// PendingIntents attached to actions with remote inputs must be mutable
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntentCompat.FLAG_MUTABLE
PendingIntent.FLAG_UPDATE_CURRENT or if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_MUTABLE
} else {
0
}
)
} else {
/*
@ -627,7 +633,7 @@ class NotificationUtils @Inject constructor( @@ -627,7 +633,7 @@ class NotificationUtils @Inject constructor(
context.applicationContext,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntentCompat.FLAG_IMMUTABLE
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
}
@ -652,15 +658,18 @@ class NotificationUtils @Inject constructor( @@ -652,15 +658,18 @@ class NotificationUtils @Inject constructor(
@SuppressLint("LaunchActivityFromNotification")
fun displayDiagnosticNotification() {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
Timber.w("Not allowed to notify.")
return
}
val testActionIntent = Intent(context, TestNotificationReceiver::class.java)
testActionIntent.action = actionIds.diagnostic
val testPendingIntent = PendingIntent.getBroadcast(
context,
0,
testActionIntent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntentCompat.FLAG_IMMUTABLE
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
notificationManager.notify(
"DIAGNOSTIC",
888,

Loading…
Cancel
Save