[#1051] Fix Export Data FileProvider
- Both debug and production builds of the app can now be deployed on the same device - Closes #1051
This commit is contained in:
parent
771dc114da
commit
8966615a39
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<application
|
||||
android:name="co.electriccoin.zcash.app.ZcashApplication"
|
||||
android:allowBackup="false"
|
||||
android:icon="@mipmap/ic_launcher_square"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:label="@string/app_name">
|
||||
|
||||
<provider
|
||||
android:name="co.electriccoin.zcash.ui.screen.exportdata.util.ShareFileProvider"
|
||||
android:authorities="co.electriccoin.zcash.debug.provider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true"
|
||||
tools:replace="android:authorities" >
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/share_file_provider_paths" />
|
||||
</provider>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -2,6 +2,7 @@ package co.electriccoin.zcash.ui.screen.exportdata.util
|
|||
|
||||
import android.content.Intent
|
||||
import androidx.test.filters.SmallTest
|
||||
import co.electriccoin.zcash.ui.fixture.VersionInfoFixture
|
||||
import co.electriccoin.zcash.ui.test.getAppContext
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
@ -22,8 +23,9 @@ class FileShareUtilTest {
|
|||
suffix = ".sqlite3"
|
||||
)
|
||||
val intent = FileShareUtil.newShareContentIntent(
|
||||
getAppContext(),
|
||||
tempFilePath.pathString
|
||||
context = getAppContext(),
|
||||
dataFilePath = tempFilePath.pathString,
|
||||
versionInfo = VersionInfoFixture.new()
|
||||
)
|
||||
assertEquals(intent.action, Intent.ACTION_VIEW)
|
||||
assertEquals(
|
||||
|
|
|
@ -14,6 +14,7 @@ import cash.z.ecc.android.sdk.model.ZcashNetwork
|
|||
import cash.z.ecc.sdk.type.fromResources
|
||||
import co.electriccoin.zcash.ui.MainActivity
|
||||
import co.electriccoin.zcash.ui.R
|
||||
import co.electriccoin.zcash.ui.common.model.VersionInfo
|
||||
import co.electriccoin.zcash.ui.screen.exportdata.util.FileShareUtil
|
||||
import co.electriccoin.zcash.ui.screen.exportdata.view.ExportPrivateData
|
||||
import co.electriccoin.zcash.ui.screen.home.viewmodel.WalletViewModel
|
||||
|
@ -78,13 +79,14 @@ fun shareData(
|
|||
snackbarHostState: SnackbarHostState,
|
||||
): Flow<Boolean> = callbackFlow {
|
||||
val shareIntent = FileShareUtil.newShareContentIntent(
|
||||
context,
|
||||
context = context,
|
||||
// Example of the expected db file absolute path:
|
||||
// /data/user/0/co.electriccoin.zcash.debug/no_backup/co.electricoin.zcash/zcash_sdk_mainnet_data.sqlite3
|
||||
(synchronizer as SdkSynchronizer).getExistingDataDbFilePath(
|
||||
dataFilePath = (synchronizer as SdkSynchronizer).getExistingDataDbFilePath(
|
||||
context = context,
|
||||
network = ZcashNetwork.fromResources(context)
|
||||
)
|
||||
),
|
||||
versionInfo = VersionInfo.new(context.applicationContext)
|
||||
)
|
||||
runCatching {
|
||||
context.startActivity(shareIntent)
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import androidx.core.content.FileProvider
|
||||
import co.electriccoin.zcash.ui.R
|
||||
import co.electriccoin.zcash.ui.common.model.VersionInfo
|
||||
import java.io.File
|
||||
|
||||
object FileShareUtil {
|
||||
|
@ -15,6 +16,7 @@ object FileShareUtil {
|
|||
const val ZASHI_INTERNAL_DATA_MIME_TYPE = "application/octet-stream" // NON-NLS
|
||||
|
||||
const val ZASHI_INTERNAL_DATA_AUTHORITY = "co.electriccoin.zcash.provider" // NON-NLS
|
||||
const val ZASHI_INTERNAL_DATA_AUTHORITY_DEBUG = "co.electriccoin.zcash.debug.provider" // NON-NLS
|
||||
|
||||
/**
|
||||
* Returns a new share internal app data intent with necessary permission granted exclusively to the data file.
|
||||
|
@ -25,11 +27,16 @@ object FileShareUtil {
|
|||
*/
|
||||
internal fun newShareContentIntent(
|
||||
context: Context,
|
||||
dataFilePath: String
|
||||
dataFilePath: String,
|
||||
versionInfo: VersionInfo
|
||||
): Intent {
|
||||
val fileUri = FileProvider.getUriForFile(
|
||||
context,
|
||||
ZASHI_INTERNAL_DATA_AUTHORITY,
|
||||
if (versionInfo.isDebuggable) {
|
||||
ZASHI_INTERNAL_DATA_AUTHORITY_DEBUG
|
||||
} else {
|
||||
ZASHI_INTERNAL_DATA_AUTHORITY
|
||||
},
|
||||
File(dataFilePath)
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue