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