pull/2718/head
kunfei 2 years ago
parent 2ef579aff2
commit ac84d939a3
  1. 7
      app/src/app/AndroidManifest.xml
  2. 12
      app/src/google/AndroidManifest.xml
  3. 6
      app/src/main/AndroidManifest.xml
  4. 25
      app/src/main/java/io/legado/app/lib/permission/PermissionActivity.kt
  5. 4
      app/src/main/java/io/legado/app/lib/permission/Permissions.kt
  6. 22
      app/src/main/java/io/legado/app/lib/permission/Request.kt
  7. 1
      app/src/main/java/io/legado/app/ui/book/import/BaseImportBookActivity.kt
  8. 6
      app/src/main/java/io/legado/app/ui/document/HandleFileActivity.kt

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
</manifest>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission
android:name="android.permission.REQUEST_INSTALL_PACKAGES"
tools:node="remove" />
<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:node="remove" />
</manifest>

@ -12,10 +12,12 @@
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" /> <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission <uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" /> tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application <application
android:name=".App" android:name=".App"

@ -2,6 +2,7 @@ package io.legado.app.lib.permission
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.provider.Settings import android.provider.Settings
import android.view.KeyEvent import android.view.KeyEvent
@ -9,6 +10,7 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
import io.legado.app.R import io.legado.app.R
import io.legado.app.exception.NoStackTraceException
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
class PermissionActivity : AppCompatActivity() { class PermissionActivity : AppCompatActivity() {
@ -23,8 +25,8 @@ class PermissionActivity : AppCompatActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
when (intent.getIntExtra(KEY_INPUT_REQUEST_TYPE, Request.TYPE_REQUEST_PERMISSION)) { when (intent.getIntExtra(KEY_INPUT_REQUEST_TYPE, Request.TYPE_REQUEST_PERMISSION)) {
Request.TYPE_REQUEST_PERMISSION//权限请求 //权限请求
-> { Request.TYPE_REQUEST_PERMISSION -> {
val requestCode = intent.getIntExtra(KEY_INPUT_PERMISSIONS_CODE, 1000) val requestCode = intent.getIntExtra(KEY_INPUT_PERMISSIONS_CODE, 1000)
val permissions = intent.getStringArrayExtra(KEY_INPUT_PERMISSIONS) val permissions = intent.getStringArrayExtra(KEY_INPUT_PERMISSIONS)
if (permissions != null) { if (permissions != null) {
@ -33,8 +35,8 @@ class PermissionActivity : AppCompatActivity() {
finish() finish()
} }
} }
Request.TYPE_REQUEST_SETTING//跳转到设置界面 //跳转到设置界面
-> try { Request.TYPE_REQUEST_SETTING -> try {
val settingIntent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) val settingIntent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
settingIntent.data = Uri.fromParts("package", packageName, null) settingIntent.data = Uri.fromParts("package", packageName, null)
settingActivityResult.launch(settingIntent) settingActivityResult.launch(settingIntent)
@ -42,7 +44,19 @@ class PermissionActivity : AppCompatActivity() {
toastOnUi(R.string.tip_cannot_jump_setting_page) toastOnUi(R.string.tip_cannot_jump_setting_page)
finish() finish()
} }
//所有文件所有文件的管理权限
Request.TYPE_MANAGE_ALL_FILES_ACCESS_PERMISSION -> try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val settingIntent = Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
settingIntent.data = Uri.parse("package:$packageName")
settingActivityResult.launch(settingIntent)
} else {
throw NoStackTraceException("no MANAGE_ALL_FILES_ACCESS_PERMISSION")
}
} catch (e: Exception) {
toastOnUi(R.string.tip_cannot_jump_setting_page)
finish()
}
} }
} }
@ -59,6 +73,7 @@ class PermissionActivity : AppCompatActivity() {
finish() finish()
} }
override fun startActivity(intent: Intent) { override fun startActivity(intent: Intent) {
super.startActivity(intent) super.startActivity(intent)
overridePendingTransition(0, 0) overridePendingTransition(0, 0)

@ -35,11 +35,13 @@ object Permissions {
const val READ_EXTERNAL_STORAGE = "android.permission.READ_EXTERNAL_STORAGE" const val READ_EXTERNAL_STORAGE = "android.permission.READ_EXTERNAL_STORAGE"
const val WRITE_EXTERNAL_STORAGE = "android.permission.WRITE_EXTERNAL_STORAGE" const val WRITE_EXTERNAL_STORAGE = "android.permission.WRITE_EXTERNAL_STORAGE"
const val MANAGE_EXTERNAL_STORAGE = "android.permission.MANAGE_EXTERNAL_STORAGE"
const val ACCESS_MEDIA_LOCATION = "android.permission.ACCESS_MEDIA_LOCATION" const val ACCESS_MEDIA_LOCATION = "android.permission.ACCESS_MEDIA_LOCATION"
object Group { object Group {
val STORAGE = arrayOf(READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE) val STORAGE =
arrayOf(READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE, MANAGE_EXTERNAL_STORAGE)
val CAMERA = arrayOf(Permissions.CAMERA) val CAMERA = arrayOf(Permissions.CAMERA)

@ -84,10 +84,23 @@ internal class Request : OnRequestPermissionsResultCallback {
} }
} else { } else {
if (deniedPermissions != null) { if (deniedPermissions != null) {
source?.context?.startActivity<PermissionActivity> { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
putExtra(PermissionActivity.KEY_INPUT_REQUEST_TYPE, TYPE_REQUEST_PERMISSION) && deniedPermissions.contains(Permissions.MANAGE_EXTERNAL_STORAGE)
putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS_CODE, requestCode) ) {
putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS, deniedPermissions) source?.context?.startActivity<PermissionActivity> {
putExtra(
PermissionActivity.KEY_INPUT_REQUEST_TYPE,
TYPE_MANAGE_ALL_FILES_ACCESS_PERMISSION
)
putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS_CODE, requestCode)
putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS, deniedPermissions)
}
} else if (!deniedPermissions.contains(Permissions.MANAGE_EXTERNAL_STORAGE)) {
source?.context?.startActivity<PermissionActivity> {
putExtra(PermissionActivity.KEY_INPUT_REQUEST_TYPE, TYPE_REQUEST_PERMISSION)
putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS_CODE, requestCode)
putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS, deniedPermissions)
}
} }
} else { } else {
onPermissionsGranted() onPermissionsGranted()
@ -191,5 +204,6 @@ internal class Request : OnRequestPermissionsResultCallback {
companion object { companion object {
const val TYPE_REQUEST_PERMISSION = 1 const val TYPE_REQUEST_PERMISSION = 1
const val TYPE_REQUEST_SETTING = 2 const val TYPE_REQUEST_SETTING = 2
const val TYPE_MANAGE_ALL_FILES_ACCESS_PERMISSION = 3
} }
} }

@ -40,7 +40,6 @@ abstract class BaseImportBookActivity<VB : ViewBinding, VM : ViewModel> : VMBase
yesButton { yesButton {
localBookTreeSelect.launch { localBookTreeSelect.launch {
title = hint title = hint
mode = HandleFileContract.DIR_SYS
} }
} }
noButton { noButton {

@ -13,6 +13,7 @@ import io.legado.app.constant.AppLog
import io.legado.app.constant.Theme import io.legado.app.constant.Theme
import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.help.IntentData import io.legado.app.help.IntentData
import io.legado.app.help.config.AppConfig
import io.legado.app.lib.dialogs.SelectItem import io.legado.app.lib.dialogs.SelectItem
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.permission.Permissions import io.legado.app.lib.permission.Permissions
@ -160,7 +161,10 @@ class HandleFileActivity :
} }
private fun getDirActions(onlySys: Boolean = false): ArrayList<SelectItem<Int>> { private fun getDirActions(onlySys: Boolean = false): ArrayList<SelectItem<Int>> {
return if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q || onlySys) { return if (
onlySys ||
(Build.VERSION.SDK_INT > Build.VERSION_CODES.Q && AppConfig.isGooglePlay)
) {
arrayListOf(SelectItem(getString(R.string.sys_folder_picker), HandleFileContract.DIR)) arrayListOf(SelectItem(getString(R.string.sys_folder_picker), HandleFileContract.DIR))
} else { } else {
arrayListOf( arrayListOf(

Loading…
Cancel
Save