Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cc819b3a authored by Moez Bhatti's avatar Moez Bhatti
Browse files

Request notification permission on Android 13

parent c4e07c21
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
package com.moez.QKSMS.manager

import android.Manifest
import android.app.NotificationManager
import android.app.role.RoleManager
import android.content.Context
import android.content.pm.PackageManager
@@ -29,6 +30,8 @@ import javax.inject.Inject

class PermissionManagerImpl @Inject constructor(private val context: Context) : PermissionManager {

    private val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

    override fun isDefaultSms(): Boolean {
        return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            context.getSystemService(RoleManager::class.java)?.isRoleHeld(RoleManager.ROLE_SMS) == true
@@ -49,6 +52,13 @@ class PermissionManagerImpl @Inject constructor(private val context: Context) :
        return hasPermission(Manifest.permission.READ_CONTACTS)
    }

    override fun hasNotifications(): Boolean {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
            return true
        }
        return notificationManager.areNotificationsEnabled()
    }

    override fun hasPhone(): Boolean {
        return hasPermission(Manifest.permission.READ_PHONE_STATE)
    }
+3 −1
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ interface PermissionManager {

    fun hasContacts(): Boolean

    fun hasNotifications(): Boolean

    fun hasPhone(): Boolean

    fun hasCalling(): Boolean
+1 −0
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ class Preferences @Inject constructor(
    val canUseSubId = rxPrefs.getBoolean("canUseSubId", true)
    val version = rxPrefs.getInteger("version", context.versionCode)
    val changelogVersion = rxPrefs.getInteger("changelogVersion", context.versionCode)
    val hasAskedForNotificationPermission = rxPrefs.getBoolean("hasAskedForNotificationPermission", false)
    @Deprecated("This should only be accessed when migrating to @blockingManager")
    val sia = rxPrefs.getBoolean("sia", false)

+8 −0
Original line number Diff line number Diff line
@@ -281,6 +281,14 @@ class Navigator @Inject constructor(
        startActivityExternal(intent)
    }

    fun showPermissions() {
        val intent = Intent()
        intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
        intent.data = Uri.fromParts("package", context.packageName, null)

        startActivity(intent)
    }

    fun showNotificationSettings(threadId: Long = 0) {
        val intent = Intent(context, NotificationPrefsActivity::class.java)
        intent.putExtra("threadId", threadId)
+6 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import com.moez.QKSMS.util.GlideApp
import com.moez.QKSMS.util.PhoneNumberUtils
import com.moez.QKSMS.util.Preferences
import com.moez.QKSMS.util.tryOrNull
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Singleton

@@ -94,6 +95,11 @@ class NotificationManagerImpl @Inject constructor(
            return
        }

        if (!permissions.hasNotifications()) {
            Timber.w("Cannot update notification because we don't have the notification permission")
            return
        }

        val messages = messageRepo.getUnreadUnseenMessages(threadId)

        // If there are no messages to be displayed, make sure that the notification is dismissed
Loading