Skip to content

Commit

Permalink
Bump sdk, update storage permissions trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
VishalNehra committed Oct 30, 2023
1 parent fa4f92c commit c9f4bbf
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ android {
release
}

compileSdk 32
compileSdk 33

defaultConfig {
applicationId "com.amaze.fileutilities"
minSdk 21
targetSdk 32
targetSdk 33

Integer sudoVersionCode = 29
String versionNameText = "1.89"
Expand Down
33 changes: 23 additions & 10 deletions app/src/main/java/com/amaze/fileutilities/PermissionsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package com.amaze.fileutilities

import android.Manifest
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
Expand Down Expand Up @@ -54,22 +55,22 @@ open class PermissionsActivity :
* Invokes permission check when we don't show welcome screen.
*/
fun invokePermissionCheck() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!checkStoragePermission()) {
if (VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (VERSION.SDK_INT < Build.VERSION_CODES.R && !checkStoragePermission()) {
requestStoragePermission(onPermissionGranted, true)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (VERSION.SDK_INT >= Build.VERSION_CODES.R) {
requestAllFilesAccess(onPermissionGranted)
}
}
}

fun haveStoragePermissions(): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!checkStoragePermission()) {
if (VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (VERSION.SDK_INT < Build.VERSION_CODES.R && !checkStoragePermission()) {
return false
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R &&
if (VERSION.SDK_INT >= Build.VERSION_CODES.R &&
!Environment.isExternalStorageManager()
) {
return false
Expand Down Expand Up @@ -176,7 +177,7 @@ open class PermissionsActivity :
}

fun initLocationResources(onPermissionGranted: OnPermissionGranted) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !checkLocationPermission()) {
if (VERSION.SDK_INT >= Build.VERSION_CODES.M && !checkLocationPermission()) {
val builder: AlertDialog.Builder = this.let {
AlertDialog.Builder(this, R.style.Custom_Dialog_Dark)
}
Expand Down Expand Up @@ -296,7 +297,7 @@ open class PermissionsActivity :
* @param onPermissionGranted permission granted callback
*/
private fun requestAllFilesAccess(onPermissionGranted: OnPermissionGranted) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R &&
if (VERSION.SDK_INT >= Build.VERSION_CODES.R &&
!Environment.isExternalStorageManager()
) {
val builder: AlertDialog.Builder = this.let {
Expand All @@ -315,11 +316,23 @@ open class PermissionsActivity :
permissionCallbacks[ALL_FILES_PERMISSION] = onPermissionGranted
try {
val intent =
Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
.setData(Uri.parse("package:$packageName"))
startActivity(intent)
} catch (anf: ActivityNotFoundException) {
// fallback
log.warn("Failed to find activity for all files access", anf)
try {
val intent =
Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
.setData(Uri.parse("package:$packageName"))
startActivity(intent)
} catch (e: Exception) {
log.error("Failed to initial activity to grant all files access", e)
applicationContext.showToastInCenter(getString(R.string.grantfailed))
}
} catch (e: Exception) {
log.error("Failed to initial activity to grant all files access", e)
log.error("Failed to grant all files access", e)
applicationContext.showToastInCenter(getString(R.string.grantfailed))
}
dialog.cancel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class PermissionFragmentWelcome : Fragment() {
val activity = requireActivity() as WelcomeScreen
activity.run {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!checkStoragePermission()) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R && !checkStoragePermission()) {
requestStoragePermission(onPermissionGranted, true)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package com.amaze.fileutilities.home_page

import android.Manifest
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
Expand Down Expand Up @@ -56,7 +57,7 @@ abstract class WelcomePermissionScreen :

fun haveStoragePermissions(): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!checkStoragePermission()) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R && !checkStoragePermission()) {
return false
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R &&
Expand Down Expand Up @@ -311,11 +312,23 @@ abstract class WelcomePermissionScreen :
permissionCallbacks[ALL_FILES_PERMISSION] = onPermissionGranted
try {
val intent =
Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
.setData(Uri.parse("package:$packageName"))
startActivity(intent)
} catch (anf: ActivityNotFoundException) {
// fallback
log.warn("Failed to find activity for all files access", anf)
try {
val intent =
Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
.setData(Uri.parse("package:$packageName"))
startActivity(intent)
} catch (e: Exception) {
log.error("Failed to initial activity to grant all files access", e)
applicationContext.showToastInCenter(getString(R.string.grantfailed))
}
} catch (e: Exception) {
log.error("Failed to initial activity to grant all files access", e)
log.error("Failed to grant all files access", e)
applicationContext.showToastInCenter(getString(R.string.grantfailed))
}
dialog.cancel()
Expand Down

0 comments on commit c9f4bbf

Please sign in to comment.