Add permission and guard for notifications on Android 13

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2022-08-29 19:30:38 +05:30
parent 298fcb1150
commit 852cba87b1
5 changed files with 54 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Aurora Store
~ Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
~ Copyright (C) 2022, The Calyx Institute
~
~ Aurora Store is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
@@ -42,6 +43,7 @@
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
<uses-permission android:name="android.permission.UPDATE_PACKAGES_WITHOUT_USER_ACTION" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-feature
android:name="android.software.leanback"

View File

@@ -1,6 +1,7 @@
/*
* Aurora Store
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
* Copyright (C) 2022, The Calyx Institute
*
* Aurora Store is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -56,6 +57,10 @@ fun isSAndAbove(): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
}
fun isTAndAbove(): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
}
fun isMIUI(): Boolean {
return getSystemProperty("ro.miui.ui.version.name").isNotEmpty()
}

View File

@@ -1,6 +1,7 @@
/*
* Aurora Store
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
* Copyright (C) 2022, The Calyx Institute
*
* Aurora Store is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -28,6 +29,7 @@ import android.os.IBinder
import android.util.ArrayMap
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import com.aurora.Constants
import com.aurora.extensions.getStyledAttributeColor
@@ -322,11 +324,13 @@ class NotificationService : Service() {
}
}
notificationManager.notify(
app.packageName,
app.id,
builder.build()
)
if (NotificationManagerCompat.from(this).areNotificationsEnabled()) {
notificationManager.notify(
app.packageName,
app.id,
builder.build()
)
}
}
private fun getPauseIntent(groupId: Int): PendingIntent {
@@ -447,11 +451,13 @@ class NotificationService : Service() {
builder.setContentText(status)
builder.setSubText(app.packageName)
notificationManager.notify(
app.packageName,
app.id,
builder.build()
)
if (NotificationManagerCompat.from(this).areNotificationsEnabled()) {
notificationManager.notify(
app.packageName,
app.id,
builder.build()
)
}
}
override fun onDestroy() {

View File

@@ -34,6 +34,7 @@ import android.view.ViewGroup
import androidx.core.app.ActivityCompat
import com.aurora.extensions.isOAndAbove
import com.aurora.extensions.isRAndAbove
import com.aurora.extensions.isTAndAbove
import com.aurora.extensions.toast
import com.aurora.store.BuildConfig
import com.aurora.store.R
@@ -97,11 +98,25 @@ class PermissionsFragment : BaseFragment() {
)
}
if (isTAndAbove()) {
installerList.add(
Permission(
3,
getString(R.string.onboarding_permission_notifications),
getString(R.string.onboarding_permission_notifications_desc)
)
)
}
B.epoxyRecycler.withModels {
val writeExternalStorage = if (!isRAndAbove()) ActivityCompat.checkSelfPermission(
requireContext(),
Manifest.permission.WRITE_EXTERNAL_STORAGE
) == PackageManager.PERMISSION_GRANTED else true
val postNotifications = if (isTAndAbove()) ActivityCompat.checkSelfPermission(
requireContext(),
Manifest.permission.POST_NOTIFICATIONS
) == PackageManager.PERMISSION_GRANTED else true
val storageManager = if (isRAndAbove()) Environment.isExternalStorageManager() else true
val canInstallPackages = if (isOAndAbove()) requireContext().packageManager.canRequestPackageInstalls() else true
canGoForward = writeExternalStorage && storageManager && canInstallPackages
@@ -124,6 +139,7 @@ class PermissionsFragment : BaseFragment() {
0 -> writeExternalStorage
1 -> storageManager
2 -> canInstallPackages
3 -> postNotifications
else -> false
}
)
@@ -132,6 +148,7 @@ class PermissionsFragment : BaseFragment() {
0 -> checkStorageAccessPermission()
1 -> checkStorageManagerPermission()
2 -> checkUnknownResourceInstallation()
3 -> checkPostNotificationsPermission()
}
}
)
@@ -147,6 +164,17 @@ class PermissionsFragment : BaseFragment() {
B.epoxyRecycler.requestModelBuild()
}
private fun checkPostNotificationsPermission() {
if (isTAndAbove()) {
runWithPermissions(
Manifest.permission.POST_NOTIFICATIONS
) {
toast(R.string.toast_permission_granted)
B.epoxyRecycler.requestModelBuild()
}
}
}
private fun checkStorageManagerPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (Environment.isExternalStorageManager()) {

View File

@@ -2,6 +2,7 @@
<!--
~ Aurora Store
~ Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
~ Copyright (C) 2022, The Calyx Institute
~
~ Aurora Store is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
@@ -258,6 +259,8 @@
<string name="onboarding_permission_esm">"External Storage Manager"</string>
<string name="onboarding_permission_installer">"Installer Permission"</string>
<string name="onboarding_permission_installer_desc">"Allow installing apps from Aurora Store"</string>
<string name="onboarding_permission_notifications">"Notifications"</string>
<string name="onboarding_permission_notifications_desc">"Send notifications regarding installations status"</string>
<string name="pref_abandon_session">"Force clear installation sessions"</string>
<string name="pref_abandon_session_desc">"Clear abandon or pending installation sessions"</string>
<string name="pref_app_download">"Downloads"</string>