1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-06-25 10:26:02 +02:00

[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 <fedemkr@gmail.com>

---------

Co-authored-by: Federico Maccaroni <fedemkr@gmail.com>
This commit is contained in:
mpbw2 2023-10-12 08:58:11 -04:00 committed by GitHub
parent 5a0c2115a1
commit bb2f1f0f5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 6 deletions

View File

@ -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";
/// <summary>
/// This directory must also be declared in filepaths.xml
/// </summary>
public const string TEMP_CAMERA_IMAGE_DIR = "camera_temp";
}
}

View File

@ -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;
}

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<cache-path name="cache" path="." />
<files-path name="internal" path="." />
<files-path name="temp_camera_images" path="camera_temp/" />
</paths>

View File

@ -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();