Skip to content

Commit

Permalink
fix contentProvider security exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Atwa committed Jul 2, 2024
1 parent afef2dc commit 64591ef
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion filepicker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ afterEvaluate {

groupId = 'com.github.atwa'
artifactId = 'filepicker'
version = '1.0.9'
version = '1.0.10'
}
}
repositories {
Expand Down
2 changes: 1 addition & 1 deletion filepicker/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.atwa.filepicker.provider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class FilePickerProcessor(private val configuration: PickerConfiguration) : File

override fun captureCameraImage(onImagePicked: (ImageMeta?) -> Unit) {
with(configuration) {
val photoURI = decoder.createFile()
val photoURI = decoder.generateURI()
captureIntent.apply { putExtra(MediaStore.EXTRA_OUTPUT, photoURI) }.onPick {
decoder.getCameraImage(photoURI, onImagePicked)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ object PickIntent {
)
}

internal val captureIntent by lazy { Intent(MediaStore.ACTION_IMAGE_CAPTURE) }
internal val captureIntent
get() =
Intent(MediaStore.ACTION_IMAGE_CAPTURE).apply {
addFlags(
Intent.FLAG_GRANT_READ_URI_PERMISSION and
Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)
}

internal val pdfIntent by lazy {
Intent(Intent.ACTION_GET_CONTENT).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.atwa.filepicker.result.ImageMeta
import com.atwa.filepicker.result.VideoMeta

interface Decoder {
fun createFile(): Uri?
fun generateURI(): Uri?
fun getStorageImage(imageUri: Uri?, onImagePicked: (ImageMeta?) -> Unit)
fun getStoragePDF(pdfUri: Uri?, onPdfPicked: (FileMeta?) -> Unit)
fun getStorageFile(fileUri: Uri?, onFilePicked: (FileMeta?) -> Unit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import android.os.ParcelFileDescriptor
import android.provider.MediaStore
import android.provider.OpenableColumns
import androidx.core.content.FileProvider
import com.atwa.filepicker.BuildConfig
import com.atwa.filepicker.core.Executors
import com.atwa.filepicker.result.FileMeta
import com.atwa.filepicker.result.ImageMeta
Expand All @@ -31,13 +30,13 @@ internal class UriDecoder(

private val contentResolver by lazy { context?.contentResolver }

override fun createFile(): Uri? = try {
override fun generateURI(): Uri? = try {
context?.let {
val timeStamp = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()).toString()
val file = File.createTempFile(timeStamp, ".jpg", context.cacheDir)
FileProvider.getUriForFile(
it,
"${BuildConfig.LIBRARY_PACKAGE_NAME}.provider",
"${context.packageName}.provider",
file
)
}
Expand Down

0 comments on commit 64591ef

Please sign in to comment.