Refactor storage related permissions setup
On Android 11+, MANAGE_EXTERNAL_STORAGE permission is all we need to work nicely with storage Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -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
|
||||
@@ -121,8 +122,11 @@ class MainActivity : BaseActivity() {
|
||||
|
||||
/*Check only if download to external storage is enabled*/
|
||||
if (Preferences.getBoolean(this, Preferences.PREFERENCE_DOWNLOAD_EXTERNAL)) {
|
||||
checkExternalStorageAccessPermission()
|
||||
checkExternalStorageManagerPermission()
|
||||
if (isRAndAbove()) {
|
||||
checkExternalStorageManagerPermission()
|
||||
} else {
|
||||
checkExternalStorageAccessPermission()
|
||||
}
|
||||
}
|
||||
|
||||
/* Check self update only for stable release, skip debug & nightlies*/
|
||||
|
||||
@@ -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
|
||||
@@ -26,7 +27,9 @@ import android.content.Intent
|
||||
import android.content.ServiceConnection
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.os.IBinder
|
||||
import android.provider.Settings
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
@@ -485,18 +488,30 @@ class AppDetailsActivity : BaseDetailsActivity() {
|
||||
bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
updateActionState(State.PROGRESS)
|
||||
|
||||
runWithPermissions(
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
) {
|
||||
if (updateService == null) {
|
||||
listOfActionsWhenServiceAttaches.add({
|
||||
updateService?.updateApp(app, removeExisiting = true)
|
||||
})
|
||||
getUpdateServiceInstance()
|
||||
if (isRAndAbove()) {
|
||||
if (!Environment.isExternalStorageManager()) {
|
||||
startActivity(Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION))
|
||||
} else {
|
||||
updateService?.updateApp(app, removeExisiting = true)
|
||||
updateApp(app)
|
||||
}
|
||||
} else {
|
||||
runWithPermissions(
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
) {
|
||||
updateApp(app)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateApp(app: App) {
|
||||
if (updateService == null) {
|
||||
listOfActionsWhenServiceAttaches.add {
|
||||
updateService?.updateApp(app, true)
|
||||
}
|
||||
getUpdateServiceInstance()
|
||||
} else {
|
||||
updateService?.updateApp(app, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -70,19 +71,7 @@ class PermissionsFragment : BaseFragment() {
|
||||
|
||||
private fun updateController() {
|
||||
|
||||
val installerList: List<Permission> = listOf(
|
||||
Permission(
|
||||
0,
|
||||
getString(R.string.onboarding_permission_esa),
|
||||
getString(R.string.onboarding_permission_esa_desc)
|
||||
),
|
||||
|
||||
Permission(
|
||||
1,
|
||||
getString(R.string.onboarding_permission_esm),
|
||||
getString(R.string.onboarding_permission_esm_desc)
|
||||
),
|
||||
|
||||
val installerList = mutableListOf(
|
||||
Permission(
|
||||
2,
|
||||
getString(R.string.onboarding_permission_installer),
|
||||
@@ -90,11 +79,29 @@ class PermissionsFragment : BaseFragment() {
|
||||
)
|
||||
)
|
||||
|
||||
if (isRAndAbove()) {
|
||||
installerList.add(
|
||||
Permission(
|
||||
1,
|
||||
getString(R.string.onboarding_permission_esm),
|
||||
getString(R.string.onboarding_permission_esm_desc)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
installerList.add(
|
||||
Permission(
|
||||
0,
|
||||
getString(R.string.onboarding_permission_esa),
|
||||
getString(R.string.onboarding_permission_esa_desc)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
B.epoxyRecycler.withModels {
|
||||
val writeExternalStorage = ActivityCompat.checkSelfPermission(
|
||||
val writeExternalStorage = if (!isRAndAbove()) ActivityCompat.checkSelfPermission(
|
||||
requireContext(),
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
) == PackageManager.PERMISSION_GRANTED
|
||||
) == 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
|
||||
|
||||
@@ -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
|
||||
@@ -20,12 +21,16 @@
|
||||
package com.aurora.store.view.ui.sheets
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.provider.Settings
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.aurora.Constants
|
||||
import com.aurora.extensions.isRAndAbove
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.event.BusEvent
|
||||
@@ -123,12 +128,24 @@ class AppMenuSheet : BaseBottomSheet() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun export() = runWithPermissions(
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
) {
|
||||
task {
|
||||
ApkCopier(requireContext(), app.packageName).copy()
|
||||
private fun export() {
|
||||
if (isRAndAbove()) {
|
||||
if (!Environment.isExternalStorageManager()) {
|
||||
startActivity(Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION))
|
||||
} else {
|
||||
task {
|
||||
ApkCopier(requireContext(), app.packageName).copy()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
runWithPermissions(
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
) {
|
||||
task {
|
||||
ApkCopier(requireContext(), app.packageName).copy()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user