From bb2f1f0f5f0e0fd89135033e643dfa1f2291f184 Mon Sep 17 00:00:00 2001 From: mpbw2 <59324545+mpbw2@users.noreply.github.com> Date: Thu, 12 Oct 2023 08:58:11 -0400 Subject: [PATCH] [PM-3741] [PM-3750] Improvements to local storage handling (#2795) * [PM-3741] [PM-3750] Improvements to local storage handling * Update src/Android/MainActivity.cs Co-authored-by: Federico Maccaroni --------- Co-authored-by: Federico Maccaroni --- src/Android/Constants.cs | 6 ++++++ src/Android/MainActivity.cs | 12 ++++++++---- src/Android/Resources/xml/filepaths.xml | 2 +- src/Android/Services/FileService.cs | 3 ++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Android/Constants.cs b/src/Android/Constants.cs index 398bfb708..b6fe75d1e 100644 --- a/src/Android/Constants.cs +++ b/src/Android/Constants.cs @@ -3,5 +3,11 @@ public static class Constants { public const string PACKAGE_NAME = "com.x8bit.bitwarden"; + public const string TEMP_CAMERA_IMAGE_NAME = "temp_camera_image.jpg"; + + /// + /// This directory must also be declared in filepaths.xml + /// + public const string TEMP_CAMERA_IMAGE_DIR = "camera_temp"; } } diff --git a/src/Android/MainActivity.cs b/src/Android/MainActivity.cs index 6792f3567..90d2ed45a 100644 --- a/src/Android/MainActivity.cs +++ b/src/Android/MainActivity.cs @@ -239,18 +239,22 @@ namespace Bit.Droid string fileName = null; if (data != null && data.Data != null) { - uri = data.Data; - fileName = AndroidHelpers.GetFileName(ApplicationContext, uri); + if (data.Data.ToString()?.Contains(Constants.PACKAGE_NAME) != true) + { + uri = data.Data; + fileName = AndroidHelpers.GetFileName(ApplicationContext, uri); + } } else { // camera - var file = new Java.IO.File(FilesDir, "temp_camera_photo.jpg"); + var tmpDir = new Java.IO.File(FilesDir, Constants.TEMP_CAMERA_IMAGE_DIR); + var file = new Java.IO.File(tmpDir, Constants.TEMP_CAMERA_IMAGE_NAME); uri = FileProvider.GetUriForFile(this, "com.x8bit.bitwarden.fileprovider", file); fileName = $"photo_{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.jpg"; } - if (uri == null) + if (uri == null || fileName == null) { return; } diff --git a/src/Android/Resources/xml/filepaths.xml b/src/Android/Resources/xml/filepaths.xml index be754fbbb..d8e6022f2 100644 --- a/src/Android/Resources/xml/filepaths.xml +++ b/src/Android/Resources/xml/filepaths.xml @@ -1,5 +1,5 @@  - + diff --git a/src/Android/Services/FileService.cs b/src/Android/Services/FileService.cs index c217f7a51..621e7ca44 100644 --- a/src/Android/Services/FileService.cs +++ b/src/Android/Services/FileService.cs @@ -190,7 +190,8 @@ namespace Bit.Droid.Services { try { - var file = new Java.IO.File(activity.FilesDir, "temp_camera_photo.jpg"); + var tmpDir = new Java.IO.File(activity.FilesDir, Constants.TEMP_CAMERA_IMAGE_DIR); + var file = new Java.IO.File(tmpDir, Constants.TEMP_CAMERA_IMAGE_NAME); if (!file.Exists()) { file.ParentFile.Mkdirs();