Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated SmartStorage Repo #15

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.iml
.gradle
.idea
/local.properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package com.ss.smart_storage
import android.Manifest
import android.content.pm.PackageManager
import android.os.Build
import android.os.Build.VERSION_CODES.M
import android.os.Build.VERSION_CODES.Q
import android.os.Environment
import androidx.activity.ComponentActivity
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import com.ss.smart_storage.util.PermissionStatus
import com.ss.smart_storage.util.SmartDirectory
Expand Down Expand Up @@ -55,27 +59,21 @@ class PermissionManager(

private fun checkOsForPermissions(location: String) {
when {
isVersionInBetween(Build.VERSION_CODES.M, Build.VERSION_CODES.Q) -> {
checkIfPermissionGranted(
onPermissionGranted = {
onPermissionGranted(PermissionStatus.ACCEPTED)
})
Build.VERSION.SDK_INT in M..Q -> {
checkIfPermissionGranted(onPermissionGranted = {
onPermissionGranted(PermissionStatus.ACCEPTED)
})
}
isVersionInBetween(
Build.VERSION_CODES.R, Build.VERSION_CODES.S
) && location == SmartDirectory.EXTERNAL_PUBLIC -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
checkIfManagePermissionGranted(
onPermissionGranted = { granted ->
if(granted) onPermissionGranted(PermissionStatus.ACCEPTED)
else onPermissionGranted(PermissionStatus.REDIRECT_TO_SETTINGS)
})
}

(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) && location == SmartDirectory.EXTERNAL_PUBLIC -> {

checkIfManagePermissionGranted(onPermissionGranted = { granted ->
if (granted) onPermissionGranted(PermissionStatus.ACCEPTED)
else onPermissionGranted(PermissionStatus.REDIRECT_TO_SETTINGS)
})

}
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && location == SmartDirectory.EXTERNAL_PUBLIC -> {
onPermissionGranted(PermissionStatus.NOT_AVAILABLE)
}

else -> {
onPermissionGranted(PermissionStatus.ACCEPTED)
}
Expand All @@ -94,10 +92,9 @@ class PermissionManager(
}
}

private fun checkIfManagePermissionGranted( onPermissionGranted: (Boolean) -> Unit) {
if (ContextCompat.checkSelfPermission(
activity, Manifest.permission.MANAGE_EXTERNAL_STORAGE ,
) == PackageManager.PERMISSION_GRANTED
@RequiresApi(Build.VERSION_CODES.R)
private fun checkIfManagePermissionGranted(onPermissionGranted: (Boolean) -> Unit) {
if (Environment.isExternalStorageManager()
) {
onPermissionGranted(true)
} else {
Expand All @@ -107,10 +104,4 @@ class PermissionManager(




private fun isVersionInBetween(min: Int, max: Int): Boolean {
return Build.VERSION.SDK_INT in min..max
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ class SmartStorage(private val activity: ComponentActivity) {
launchBaseDirectoryPicker()
}

PermissionStatus.NOT_AVAILABLE -> {
Toast.makeText(
activity,
activity.getString(R.string.feature_not_available),
Toast.LENGTH_SHORT
).show()
}

PermissionStatus.REDIRECT_TO_SETTINGS -> {
requestFullStorageAccess()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.ss.smart_storage.util

enum class PermissionStatus {
ACCEPTED, DENIED, NOT_APPLICABLE, NOT_NEEDED, NOT_AVAILABLE, REDIRECT_TO_SETTINGS
ACCEPTED, DENIED, NOT_APPLICABLE, NOT_NEEDED, REDIRECT_TO_SETTINGS
}
Loading