Log SecurityException on openUri
This commit is contained in:
@@ -120,6 +120,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
setContent {
|
setContent {
|
||||||
|
val logger = appContainer.logger
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val currentScreen by viewModel.currentScreen.collectAsStateWithLifecycle()
|
val currentScreen by viewModel.currentScreen.collectAsStateWithLifecycle()
|
||||||
val liveAnalysisState by cameraViewModel.liveAnalysisState.collectAsStateWithLifecycle()
|
val liveAnalysisState by cameraViewModel.liveAnalysisState.collectAsStateWithLifecycle()
|
||||||
@@ -164,7 +165,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
navigation = navigation,
|
navigation = navigation,
|
||||||
onClearScan = { viewModel.startNewDocument() },
|
onClearScan = { viewModel.startNewDocument() },
|
||||||
recentDocuments = recentDocs,
|
recentDocuments = recentDocs,
|
||||||
onOpenPdf = { fileUri -> openUri(fileUri, ExportFormat.PDF.mimeType) }
|
onOpenPdf = { fileUri -> openUri(fileUri, ExportFormat.PDF.mimeType, logger) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
is Screen.Main.Camera -> {
|
is Screen.Main.Camera -> {
|
||||||
@@ -210,7 +211,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
setFilename = exportViewModel::setFilename,
|
setFilename = exportViewModel::setFilename,
|
||||||
share = { exportViewModel.onShareClicked() },
|
share = { exportViewModel.onShareClicked() },
|
||||||
save = { exportViewModel.onSaveClicked() },
|
save = { exportViewModel.onSaveClicked() },
|
||||||
open = { item -> openUri(item.uri, item.format.mimeType) },
|
open = { item -> openUri(item.uri, item.format.mimeType, logger) },
|
||||||
),
|
),
|
||||||
onCloseScan = {
|
onCloseScan = {
|
||||||
exportViewModel.resetFilename()
|
exportViewModel.resetFilename()
|
||||||
@@ -236,7 +237,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
LibrariesScreen(onBack = navigation.back)
|
LibrariesScreen(onBack = navigation.back)
|
||||||
}
|
}
|
||||||
is Screen.Overlay.Settings -> {
|
is Screen.Overlay.Settings -> {
|
||||||
SettingsScreenWrapper(settingsViewModel, navigation, appContainer.logger)
|
SettingsScreenWrapper(settingsViewModel, navigation, logger)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -428,7 +429,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openUri(fileUri: Uri?, mimeType: String) {
|
private fun openUri(fileUri: Uri?, mimeType: String, logger: FileLogger) {
|
||||||
if (fileUri == null) return
|
if (fileUri == null) return
|
||||||
val uriToOpen: Uri =
|
val uriToOpen: Uri =
|
||||||
if (fileUri.scheme == ContentResolver.SCHEME_CONTENT) {
|
if (fileUri.scheme == ContentResolver.SCHEME_CONTENT) {
|
||||||
@@ -446,6 +447,11 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
startActivity(chooser)
|
startActivity(chooser)
|
||||||
|
} catch (e: SecurityException) {
|
||||||
|
val errorMessage =
|
||||||
|
"Failed to open URI, scheme=${uriToOpen.scheme}, authority=${uriToOpen.authority}"
|
||||||
|
logger.e("OpenUri", errorMessage, e)
|
||||||
|
throw OpenUriException(errorMessage, e)
|
||||||
} catch (_: ActivityNotFoundException) {
|
} catch (_: ActivityNotFoundException) {
|
||||||
showToast(getString(R.string.error_no_app))
|
showToast(getString(R.string.error_no_app))
|
||||||
}
|
}
|
||||||
@@ -485,3 +491,4 @@ class MainActivity : ComponentActivity() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class OpenUriException(message: String, cause: Throwable) : RuntimeException(message, cause)
|
||||||
|
|||||||
Reference in New Issue
Block a user