mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
This should prevent crashes on Androids < 13 due to broken POST_NOTIFICATIONS permission check
This commit is contained in:
parent
77f61c1cfa
commit
fb3feb0bc3
4 changed files with 22 additions and 13 deletions
|
|
@ -20,6 +20,8 @@
|
|||
package org.linphone.compatibility
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
|
||||
|
|
@ -34,5 +36,11 @@ class Api33Compatibility {
|
|||
Manifest.permission.CAMERA
|
||||
)
|
||||
}
|
||||
|
||||
fun isPostNotificationsPermissionGranted(context: Context): Boolean {
|
||||
return context.checkSelfPermission(
|
||||
Manifest.permission.POST_NOTIFICATIONS
|
||||
) == PackageManager.PERMISSION_GRANTED
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,6 +111,13 @@ class Compatibility {
|
|||
return false
|
||||
}
|
||||
|
||||
fun isPostNotificationsPermissionGranted(context: Context): Boolean {
|
||||
if (Version.sdkAboveOrEqual(Version.API33_ANDROID_13_TIRAMISU)) {
|
||||
return Api33Compatibility.isPostNotificationsPermissionGranted(context)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun enterPipMode(activity: Activity): Boolean {
|
||||
if (Version.sdkStrictlyBelow(Version.API31_ANDROID_12)) {
|
||||
return Api28Compatibility.enterPipMode(activity)
|
||||
|
|
|
|||
|
|
@ -19,19 +19,18 @@
|
|||
*/
|
||||
package org.linphone.core
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.PendingIntent
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.IBinder
|
||||
import androidx.annotation.AnyThread
|
||||
import androidx.annotation.MainThread
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.R
|
||||
import org.linphone.compatibility.Compatibility
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.core.tools.service.FileTransferService
|
||||
import org.linphone.ui.main.MainActivity
|
||||
|
|
@ -171,14 +170,11 @@ class CoreFileTransferService : FileTransferService() {
|
|||
postNotification()
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@AnyThread
|
||||
private fun postNotification() {
|
||||
val notificationsManager = NotificationManagerCompat.from(this)
|
||||
if (ActivityCompat.checkSelfPermission(
|
||||
this,
|
||||
Manifest.permission.POST_NOTIFICATIONS
|
||||
) == PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
if (Compatibility.isPostNotificationsPermissionGranted(this)) {
|
||||
if (mServiceNotification != null) {
|
||||
Log.i("$TAG Sending notification to manager")
|
||||
notificationsManager.notify(SERVICE_NOTIF_ID, mServiceNotification)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
package org.linphone.notifications
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Notification
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
|
|
@ -1022,13 +1023,10 @@ class NotificationsManager
|
|||
notify(notifiable.notificationId, notification, CHAT_TAG)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@WorkerThread
|
||||
private fun notify(id: Int, notification: Notification, tag: String? = null) {
|
||||
if (ActivityCompat.checkSelfPermission(
|
||||
context,
|
||||
Manifest.permission.POST_NOTIFICATIONS
|
||||
) == PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
if (Compatibility.isPostNotificationsPermissionGranted(context)) {
|
||||
Log.i(
|
||||
"$TAG Notifying using ID [$id] and ${if (tag == null) "without tag" else "with tag [$tag]"}"
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue