Commit e2669721 authored by Arturo Mejia's avatar Arturo Mejia
Browse files

Closes #5091: Fix clashing file providers in feature-prompts and

feature-downloads.
parent f1717afd
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -29,9 +29,10 @@ data class DownloadState(
    val contentLength: Long? = null,
    val userAgent: String? = null,
    val destinationDirectory: String = Environment.DIRECTORY_DOWNLOADS,
    val filePath: String =
        Environment.getExternalStoragePublicDirectory(destinationDirectory).path + "/" + fileName,
    val referrerUrl: String? = null,
    val skipConfirmation: Boolean = false,
    val id: Long = Random.nextLong()
)
) {
    val filePath: String get() =
        Environment.getExternalStoragePublicDirectory(destinationDirectory).path + "/" + fileName
}
+11 −0
Original line number Diff line number Diff line
@@ -9,4 +9,15 @@
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
    <application>
        <provider
            android:name="mozilla.components.feature.downloads.provider.FileProvider"
            android:authorities="${applicationId}.feature.downloads.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/feature_downloads_file_paths" />
        </provider>
    </application>
</manifest>
+1 −1
Original line number Diff line number Diff line
@@ -411,7 +411,7 @@ abstract class AbstractFetchDownloadService : Service() {
            }
        }

        private const val FILE_PROVIDER_EXTENSION = ".fileprovider"
        private const val FILE_PROVIDER_EXTENSION = ".feature.downloads.fileprovider"
        private const val CHUNK_SIZE = 4 * 1024
        private const val PARTIAL_CONTENT_STATUS = 206
        private const val OK_STATUS = 200
+18 −0
Original line number Diff line number Diff line
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package mozilla.components.feature.downloads.provider

/**
 * A file provider to provide functionality for the feature downloads component.
 *
 * We need this class to create a fully qualified class name that doesn't clash with other
 * file providers in other components see https://stackoverflow.com/a/43444164/5533820.
 *
 * Be aware, when creating new file resources avoid using common names like "@xml/file_paths",
 * as other file providers could be using the same names and this could case unexpected behaviors.
 * As a convention try to use unique names like using the name of the component as a prefix of the
 * name of the file, like component_xxx_file_paths.xml.
 */
/** @suppress */
class FileProvider : androidx.core.content.FileProvider()
+7 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this file,
   - You can obtain one at http://mozilla.org/MPL/2.0/.  -->
<paths>
    <external-path name="Download" path="." />
</paths>
 No newline at end of file
Loading