Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ import ee.ria.DigiDoc.common.Constant.DEFAULT_FILENAME
import ee.ria.DigiDoc.utilsLib.file.FileUtil.getNameFromFileName
import ee.ria.DigiDoc.utilsLib.file.FileUtil.normalizeUri
import ee.ria.DigiDoc.utilsLib.file.FileUtil.sanitizeString
import ee.ria.DigiDoc.utilsLib.logging.LoggingUtil.Companion.debugLog
import ee.ria.DigiDoc.utilsLib.logging.LoggingUtil.Companion.errorLog
import java.io.File
import java.io.FileNotFoundException
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
import javax.inject.Singleton

@Singleton
Expand Down Expand Up @@ -91,14 +92,28 @@ class FileOpeningServiceImpl : FileOpeningService {

cursor?.close()

val inputStream: InputStream? = contentResolver.openInputStream(uri)
val uriInfo = "scheme: ${uri.scheme}, authority: ${uri.authority}"
debugLog(logTag, "Opening file: $uriInfo, name: $displayName")

val inputStream: InputStream =
contentResolver.openInputStream(uri)
?: run {
errorLog(logTag, "openInputStream returned null for $uriInfo, name: $displayName")
throw IOException("Cannot open input stream for URI: $uriInfo")
}
val outputFile = File(context.cacheDir, displayName)
val outputStream: OutputStream = outputFile.outputStream()

inputStream?.use { input ->
outputStream.use { output ->
input.copyTo(output)
try {
inputStream.use { input ->
outputFile.outputStream().use { output ->
input.copyTo(output)
}
}
debugLog(logTag, "File copied successfully - name: $displayName, size: ${outputFile.length()}")
} catch (e: Exception) {
errorLog(logTag, "Failed to copy file - $uriInfo name: $displayName", e)
outputFile.delete()
throw e
}

return outputFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fun EncryptRecipientScreen(

val focusManager = LocalFocusManager.current

val cryptoContainer by sharedContainerViewModel.cryptoContainer.asFlow().collectAsState(null)
val cryptoContainer by sharedContainerViewModel.cryptoContainer.collectAsState()

val showLoading = remember { mutableStateOf(false) }
val isSettingsMenuBottomSheetVisible = rememberSaveable { mutableStateOf(false) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fun CryptoFileOpeningNavigation(
) {
val context = LocalContext.current

val cryptoContainer by sharedContainerViewModel.cryptoContainer.asFlow().collectAsState(null)
val cryptoContainer by sharedContainerViewModel.cryptoContainer.collectAsState()
val externalFileUris by sharedContainerViewModel.externalFileUris.collectAsState()
var isExternalFile by remember { mutableStateOf(false) }
var fileUris by remember { mutableStateOf<List<Uri>>(emptyList()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fun EncryptNavigation(
encryptViewModel: EncryptViewModel = hiltViewModel(),
encryptRecipientViewModel: EncryptRecipientViewModel = hiltViewModel(),
) {
val cryptoContainer by sharedContainerViewModel.cryptoContainer.asFlow().collectAsState(null)
val cryptoContainer by sharedContainerViewModel.cryptoContainer.collectAsState()
val shouldResetContainer by encryptViewModel.shouldResetCryptoContainer.asFlow().collectAsState(false)
val context = LocalContext.current

Expand Down Expand Up @@ -503,7 +503,7 @@ fun EncryptNavigation(
}

LaunchedEffect(sharedContainerViewModel.decryptNFCStatus) {
sharedContainerViewModel.decryptNFCStatus.asFlow().collect { status ->
sharedContainerViewModel.decryptNFCStatus.collect { status ->
status?.let {
if (status == true) {
withContext(Main) {
Expand All @@ -523,7 +523,7 @@ fun EncryptNavigation(
}

LaunchedEffect(sharedContainerViewModel.decryptIDCardStatus) {
sharedContainerViewModel.decryptIDCardStatus.asFlow().collect { status ->
sharedContainerViewModel.decryptIDCardStatus.collect { status ->
status?.let {
if (status == true) {
withContext(Main) {
Expand Down Expand Up @@ -937,8 +937,9 @@ fun EncryptNavigation(
onDismissButton = dismissRemoveFileDialog,
onConfirmButton = {
if ((cryptoContainer?.dataFiles?.size ?: 0) == 1) {
cryptoContainer?.file?.delete()
val containerFile = cryptoContainer?.file
sharedContainerViewModel.resetCryptoContainer()
containerFile?.delete()
handleBackButtonClick(
navController,
encryptViewModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ fun FileOpeningNavigation(

val scope = rememberCoroutineScope()

val signedContainer by sharedContainerViewModel.signedContainer.asFlow().collectAsState(null)
val cryptoContainer by sharedContainerViewModel.cryptoContainer.asFlow().collectAsState(null)
val signedContainer by sharedContainerViewModel.signedContainer.collectAsState()
val cryptoContainer by sharedContainerViewModel.cryptoContainer.collectAsState()
val externalFileUris by sharedContainerViewModel.externalFileUris.collectAsState()
val showSivaDialog = rememberSaveable { mutableStateOf(false) }
var isExternalFile by rememberSaveable { mutableStateOf(false) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fun MobileIdView(
) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
val signedContainer by sharedContainerViewModel.signedContainer.asFlow().collectAsState(null)
val signedContainer by sharedContainerViewModel.signedContainer.collectAsState()
val dialogError by mobileIdViewModel.dialogError.asFlow().collectAsState(0)
val getSettingsAskRoleAndAddress = sharedSettingsViewModel.dataStore::getSettingsAskRoleAndAddress

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ fun NFCView(
) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
val signedContainer by sharedContainerViewModel.signedContainer.asFlow().collectAsState(null)
val cryptoContainer by sharedContainerViewModel.cryptoContainer.asFlow().collectAsState(null)
val signedContainer by sharedContainerViewModel.signedContainer.collectAsState()
val cryptoContainer by sharedContainerViewModel.cryptoContainer.collectAsState()
var nfcStatus by remember { mutableStateOf(nfcViewModel.getNFCStatus(activity)) }
var nfcImage by remember { mutableIntStateOf(R.drawable.ic_icon_nfc) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ fun SigningNavigation(
signingViewModel: SigningViewModel = hiltViewModel(),
encryptViewModel: EncryptViewModel = hiltViewModel(),
) {
val signedContainer by sharedContainerViewModel.signedContainer.asFlow().collectAsState(null)
val signedContainer by sharedContainerViewModel.signedContainer.collectAsState()
val shouldResetContainer by signingViewModel.shouldResetSignedContainer.asFlow().collectAsState(false)
val context = LocalContext.current

Expand Down Expand Up @@ -193,7 +193,7 @@ fun SigningNavigation(

var isSignaturesCountLoaded by remember { mutableStateOf(false) }

val isParentContainerSivaConfirmed = sharedContainerViewModel.isSivaConfirmed.value == true
val isParentContainerSivaConfirmed = sharedContainerViewModel.isSivaConfirmed.value
var isSivaConfirmed by remember { mutableStateOf(isParentContainerSivaConfirmed) }
var isTimestampedContainer by remember { mutableStateOf(false) }

Expand Down Expand Up @@ -490,7 +490,7 @@ fun SigningNavigation(
}

LaunchedEffect(sharedContainerViewModel.signedMidStatus) {
sharedContainerViewModel.signedMidStatus.asFlow().collect { status ->
sharedContainerViewModel.signedMidStatus.collect { status ->
status?.let {
if (status == MobileCreateSignatureProcessStatus.OK) {
signatures = signedContainer?.getSignatures() ?: emptyList()
Expand All @@ -507,7 +507,7 @@ fun SigningNavigation(
}

LaunchedEffect(sharedContainerViewModel.signedSidStatus) {
sharedContainerViewModel.signedSidStatus.asFlow().collect { status ->
sharedContainerViewModel.signedSidStatus.collect { status ->
status?.let {
if (status == SessionStatusResponseProcessStatus.OK) {
signatures = signedContainer?.getSignatures() ?: emptyList()
Expand All @@ -524,7 +524,7 @@ fun SigningNavigation(
}

LaunchedEffect(sharedContainerViewModel.signedNFCStatus) {
sharedContainerViewModel.signedNFCStatus.asFlow().collect { status ->
sharedContainerViewModel.signedNFCStatus.collect { status ->
status?.let {
if (status == true) {
signatures = signedContainer?.getSignatures() ?: emptyList()
Expand All @@ -541,7 +541,7 @@ fun SigningNavigation(
}

LaunchedEffect(sharedContainerViewModel.signedIDCardStatus) {
sharedContainerViewModel.signedIDCardStatus.asFlow().collect { status ->
sharedContainerViewModel.signedIDCardStatus.collect { status ->
status?.let {
if (status == true) {
signatures = signedContainer?.getSignatures() ?: emptyList()
Expand Down Expand Up @@ -1096,9 +1096,10 @@ fun SigningNavigation(
onDismissButton = dismissRemoveFileDialog,
onConfirmButton = {
if ((signedContainer?.rawContainer()?.dataFiles()?.size ?: 0) == 1) {
signedContainer?.getContainerFile()?.delete()
val containerFile = signedContainer?.getContainerFile()
sharedContainerViewModel.resetSignedContainer()
sharedContainerViewModel.resetContainerNotifications()
containerFile?.delete()
handleBackButtonClick(navController, signingViewModel, sharedContainerViewModel)
} else {
scope.launch(IO) {
Expand Down Expand Up @@ -1283,11 +1284,11 @@ fun SigningNavigation(
onConfirmButton = {
showContainerCloseConfirmationDialog.value = false
val containerFile = signedContainer?.getContainerFile()
sharedContainerViewModel.resetSignedContainer()
sharedContainerViewModel.resetContainerNotifications()
if (containerFile?.exists() == true) {
containerFile.delete()
}
sharedContainerViewModel.resetSignedContainer()
sharedContainerViewModel.resetContainerNotifications()
handleBackButtonClick(navController, signingViewModel, sharedContainerViewModel)
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fun SmartIdView(
) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
val signedContainer by sharedContainerViewModel.signedContainer.asFlow().collectAsState(null)
val signedContainer by sharedContainerViewModel.signedContainer.collectAsState()
val dialogError by smartIdViewModel.dialogError.asFlow().collectAsState(0)
val getSettingsAskRoleAndAddress = sharedSettingsViewModel.dataStore::getSettingsAskRoleAndAddress

Expand Down
Loading
Loading