fixed propagating reading rights to open/set-as for non-media store entries opened by ACTION_VIEW
This commit is contained in:
parent
613fe45fc2
commit
8c607640dc
1 changed files with 16 additions and 7 deletions
|
@ -162,6 +162,7 @@ class AppAdapterHandler(private val context: Context) : MethodCallHandler {
|
||||||
uri ?: return false
|
uri ?: return false
|
||||||
|
|
||||||
val intent = Intent(Intent.ACTION_VIEW)
|
val intent = Intent(Intent.ACTION_VIEW)
|
||||||
|
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
.setDataAndType(uri, mimeType)
|
.setDataAndType(uri, mimeType)
|
||||||
return safeStartActivityChooser(title, intent)
|
return safeStartActivityChooser(title, intent)
|
||||||
}
|
}
|
||||||
|
@ -177,12 +178,14 @@ class AppAdapterHandler(private val context: Context) : MethodCallHandler {
|
||||||
uri ?: return false
|
uri ?: return false
|
||||||
|
|
||||||
val intent = Intent(Intent.ACTION_ATTACH_DATA)
|
val intent = Intent(Intent.ACTION_ATTACH_DATA)
|
||||||
|
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
.setDataAndType(uri, mimeType)
|
.setDataAndType(uri, mimeType)
|
||||||
return safeStartActivityChooser(title, intent)
|
return safeStartActivityChooser(title, intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun shareSingle(title: String?, uri: Uri, mimeType: String): Boolean {
|
private fun shareSingle(title: String?, uri: Uri, mimeType: String): Boolean {
|
||||||
val intent = Intent(Intent.ACTION_SEND)
|
val intent = Intent(Intent.ACTION_SEND)
|
||||||
|
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
.setType(mimeType)
|
.setType(mimeType)
|
||||||
when (uri.scheme?.toLowerCase(Locale.ROOT)) {
|
when (uri.scheme?.toLowerCase(Locale.ROOT)) {
|
||||||
ContentResolver.SCHEME_FILE -> {
|
ContentResolver.SCHEME_FILE -> {
|
||||||
|
@ -190,7 +193,6 @@ class AppAdapterHandler(private val context: Context) : MethodCallHandler {
|
||||||
val applicationId = context.applicationContext.packageName
|
val applicationId = context.applicationContext.packageName
|
||||||
val apkUri = FileProvider.getUriForFile(context, "$applicationId.fileprovider", File(path))
|
val apkUri = FileProvider.getUriForFile(context, "$applicationId.fileprovider", File(path))
|
||||||
intent.putExtra(Intent.EXTRA_STREAM, apkUri)
|
intent.putExtra(Intent.EXTRA_STREAM, apkUri)
|
||||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
||||||
}
|
}
|
||||||
else -> intent.putExtra(Intent.EXTRA_STREAM, uri)
|
else -> intent.putExtra(Intent.EXTRA_STREAM, uri)
|
||||||
}
|
}
|
||||||
|
@ -222,25 +224,32 @@ class AppAdapterHandler(private val context: Context) : MethodCallHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
val intent = Intent(Intent.ACTION_SEND_MULTIPLE)
|
val intent = Intent(Intent.ACTION_SEND_MULTIPLE)
|
||||||
|
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList)
|
.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList)
|
||||||
.setType(mimeType)
|
.setType(mimeType)
|
||||||
return safeStartActivityChooser(title, intent)
|
return safeStartActivityChooser(title, intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun safeStartActivity(intent: Intent): Boolean {
|
private fun safeStartActivity(intent: Intent): Boolean {
|
||||||
val canResolve = intent.resolveActivity(context.packageManager) != null
|
if (intent.resolveActivity(context.packageManager) == null) return false
|
||||||
if (canResolve) {
|
try {
|
||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
|
return true
|
||||||
|
} catch (e: SecurityException) {
|
||||||
|
Log.w(LOG_TAG, "failed to start activity for intent=$intent", e)
|
||||||
}
|
}
|
||||||
return canResolve
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun safeStartActivityChooser(title: String?, intent: Intent): Boolean {
|
private fun safeStartActivityChooser(title: String?, intent: Intent): Boolean {
|
||||||
val canResolve = intent.resolveActivity(context.packageManager) != null
|
if (intent.resolveActivity(context.packageManager) == null) return false
|
||||||
if (canResolve) {
|
try {
|
||||||
context.startActivity(Intent.createChooser(intent, title))
|
context.startActivity(Intent.createChooser(intent, title))
|
||||||
|
return true
|
||||||
|
} catch (e: SecurityException) {
|
||||||
|
Log.w(LOG_TAG, "failed to start activity chooser for intent=$intent", e)
|
||||||
}
|
}
|
||||||
return canResolve
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
Loading…
Reference in a new issue