Add permission and guard for notifications on Android 13
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?><!--
|
<?xml version="1.0" encoding="utf-8"?><!--
|
||||||
~ Aurora Store
|
~ Aurora Store
|
||||||
~ Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
~ 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
|
~ 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
|
~ 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_INSTALL_PACKAGES" />
|
||||||
<uses-permission android:name="android.permission.REQUEST_DELETE_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.UPDATE_PACKAGES_WITHOUT_USER_ACTION" />
|
||||||
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
|
|
||||||
<uses-feature
|
<uses-feature
|
||||||
android:name="android.software.leanback"
|
android:name="android.software.leanback"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Aurora Store
|
* Aurora Store
|
||||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
* 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
|
* 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
|
* 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
|
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isTAndAbove(): Boolean {
|
||||||
|
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
|
||||||
|
}
|
||||||
|
|
||||||
fun isMIUI(): Boolean {
|
fun isMIUI(): Boolean {
|
||||||
return getSystemProperty("ro.miui.ui.version.name").isNotEmpty()
|
return getSystemProperty("ro.miui.ui.version.name").isNotEmpty()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Aurora Store
|
* Aurora Store
|
||||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
* 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
|
* 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
|
* 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 android.util.ArrayMap
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
|
import androidx.core.app.NotificationManagerCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import com.aurora.Constants
|
import com.aurora.Constants
|
||||||
import com.aurora.extensions.getStyledAttributeColor
|
import com.aurora.extensions.getStyledAttributeColor
|
||||||
@@ -322,11 +324,13 @@ class NotificationService : Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationManager.notify(
|
if (NotificationManagerCompat.from(this).areNotificationsEnabled()) {
|
||||||
app.packageName,
|
notificationManager.notify(
|
||||||
app.id,
|
app.packageName,
|
||||||
builder.build()
|
app.id,
|
||||||
)
|
builder.build()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getPauseIntent(groupId: Int): PendingIntent {
|
private fun getPauseIntent(groupId: Int): PendingIntent {
|
||||||
@@ -447,11 +451,13 @@ class NotificationService : Service() {
|
|||||||
builder.setContentText(status)
|
builder.setContentText(status)
|
||||||
builder.setSubText(app.packageName)
|
builder.setSubText(app.packageName)
|
||||||
|
|
||||||
notificationManager.notify(
|
if (NotificationManagerCompat.from(this).areNotificationsEnabled()) {
|
||||||
app.packageName,
|
notificationManager.notify(
|
||||||
app.id,
|
app.packageName,
|
||||||
builder.build()
|
app.id,
|
||||||
)
|
builder.build()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import android.view.ViewGroup
|
|||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
import com.aurora.extensions.isOAndAbove
|
import com.aurora.extensions.isOAndAbove
|
||||||
import com.aurora.extensions.isRAndAbove
|
import com.aurora.extensions.isRAndAbove
|
||||||
|
import com.aurora.extensions.isTAndAbove
|
||||||
import com.aurora.extensions.toast
|
import com.aurora.extensions.toast
|
||||||
import com.aurora.store.BuildConfig
|
import com.aurora.store.BuildConfig
|
||||||
import com.aurora.store.R
|
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 {
|
B.epoxyRecycler.withModels {
|
||||||
val writeExternalStorage = if (!isRAndAbove()) ActivityCompat.checkSelfPermission(
|
val writeExternalStorage = if (!isRAndAbove()) ActivityCompat.checkSelfPermission(
|
||||||
requireContext(),
|
requireContext(),
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||||
) == PackageManager.PERMISSION_GRANTED else true
|
) == 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 storageManager = if (isRAndAbove()) Environment.isExternalStorageManager() else true
|
||||||
val canInstallPackages = if (isOAndAbove()) requireContext().packageManager.canRequestPackageInstalls() else true
|
val canInstallPackages = if (isOAndAbove()) requireContext().packageManager.canRequestPackageInstalls() else true
|
||||||
canGoForward = writeExternalStorage && storageManager && canInstallPackages
|
canGoForward = writeExternalStorage && storageManager && canInstallPackages
|
||||||
@@ -124,6 +139,7 @@ class PermissionsFragment : BaseFragment() {
|
|||||||
0 -> writeExternalStorage
|
0 -> writeExternalStorage
|
||||||
1 -> storageManager
|
1 -> storageManager
|
||||||
2 -> canInstallPackages
|
2 -> canInstallPackages
|
||||||
|
3 -> postNotifications
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -132,6 +148,7 @@ class PermissionsFragment : BaseFragment() {
|
|||||||
0 -> checkStorageAccessPermission()
|
0 -> checkStorageAccessPermission()
|
||||||
1 -> checkStorageManagerPermission()
|
1 -> checkStorageManagerPermission()
|
||||||
2 -> checkUnknownResourceInstallation()
|
2 -> checkUnknownResourceInstallation()
|
||||||
|
3 -> checkPostNotificationsPermission()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -147,6 +164,17 @@ class PermissionsFragment : BaseFragment() {
|
|||||||
B.epoxyRecycler.requestModelBuild()
|
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() {
|
private fun checkStorageManagerPermission() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
if (Environment.isExternalStorageManager()) {
|
if (Environment.isExternalStorageManager()) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<!--
|
<!--
|
||||||
~ Aurora Store
|
~ Aurora Store
|
||||||
~ Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
~ 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
|
~ 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
|
~ 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_esm">"External Storage Manager"</string>
|
||||||
<string name="onboarding_permission_installer">"Installer Permission"</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_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">"Force clear installation sessions"</string>
|
||||||
<string name="pref_abandon_session_desc">"Clear abandon or pending installation sessions"</string>
|
<string name="pref_abandon_session_desc">"Clear abandon or pending installation sessions"</string>
|
||||||
<string name="pref_app_download">"Downloads"</string>
|
<string name="pref_app_download">"Downloads"</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user