Skip to content

Commit

Permalink
Core: Add permission for post notification
Browse files Browse the repository at this point in the history
  • Loading branch information
lolketch committed Apr 25, 2024
1 parent e874a3e commit aaab98f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions debug-panel-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application>
<activity
android:name="com.redmadrobot.debug_panel_core.ui.debugpanel.DebugActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.redmadrobot.debug_panel_core.util

import android.Manifest.permission.POST_NOTIFICATIONS
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager.PERMISSION_GRANTED
import android.net.Uri
import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.TaskStackBuilder
import androidx.core.content.ContextCompat
import com.redmadrobot.debug_panel_core.ui.debugpanel.DebugActivity
import com.redmadrobot.panel_core.R

Expand Down Expand Up @@ -51,7 +54,13 @@ internal class DebugPanelNotification(private val context: Context) {
)
.build()

notificationManager?.notify(NOTIFICATION_ID, notification)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (ContextCompat.checkSelfPermission(context, POST_NOTIFICATIONS) == PERMISSION_GRANTED) {
notificationManager?.notify(NOTIFICATION_ID, notification)
}
} else {
notificationManager?.notify(NOTIFICATION_ID, notification)
}
}

fun hide() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import java.time.format.DateTimeParseException

internal class DebugVariableWidgetsProvider : DebugDataProvider<List<VariableWidget<Any>>> {

@Suppress("UNCHECKED_CAST")
override fun provideData(): List<VariableWidget<Any>> {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.redmadrobot.flipper.config.FlipperValue
import com.redmadrobot.flipper_plugin.plugin.FlipperPlugin
import com.redmadrobot.servers_plugin.plugin.ServerSelectedEvent
import com.redmadrobot.variable_plugin.plugin.asDebugVariable
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.flowOn
Expand Down Expand Up @@ -146,6 +147,7 @@ class MainActivity : AppCompatActivity() {
DebugPanel.showPanel(supportFragmentManager)
}

@OptIn(DelicateCoroutinesApi::class)
private fun observeFeatureToggles() {
FlipperPlugin.addSource(
"Test 1",
Expand Down

0 comments on commit aaab98f

Please sign in to comment.