mirror of
https://github.com/bitwarden/mobile
synced 2025-12-05 23:53:33 +00:00
conditionals if device has camera or not
This commit is contained in:
@@ -13,6 +13,9 @@
|
|||||||
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
|
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
|
||||||
<uses-permission android:name="com.x8bit.bitwarden.permission.C2D_MESSAGE" />
|
<uses-permission android:name="com.x8bit.bitwarden.permission.C2D_MESSAGE" />
|
||||||
|
|
||||||
|
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
||||||
|
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
|
||||||
|
|
||||||
<application android:label="bitwarden" android:theme="@style/BitwardenTheme" android:allowBackup="false">
|
<application android:label="bitwarden" android:theme="@style/BitwardenTheme" android:allowBackup="false">
|
||||||
<provider
|
<provider
|
||||||
android:name="android.support.v4.content.FileProvider"
|
android:name="android.support.v4.content.FileProvider"
|
||||||
|
|||||||
@@ -139,6 +139,10 @@ namespace Bit.Android.Services
|
|||||||
MessagingCenter.Unsubscribe<Application>(Application.Current, "SelectFileCameraPermissionDenied");
|
MessagingCenter.Unsubscribe<Application>(Application.Current, "SelectFileCameraPermissionDenied");
|
||||||
|
|
||||||
var hasStorageWritePermission = !_cameraPermissionsDenied && HasPermission(Manifest.Permission.WriteExternalStorage);
|
var hasStorageWritePermission = !_cameraPermissionsDenied && HasPermission(Manifest.Permission.WriteExternalStorage);
|
||||||
|
|
||||||
|
var additionalIntents = new List<IParcelable>();
|
||||||
|
if(Forms.Context.PackageManager.HasSystemFeature(PackageManager.FeatureCamera))
|
||||||
|
{
|
||||||
var hasCameraPermission = !_cameraPermissionsDenied && HasPermission(Manifest.Permission.Camera);
|
var hasCameraPermission = !_cameraPermissionsDenied && HasPermission(Manifest.Permission.Camera);
|
||||||
|
|
||||||
if(!_cameraPermissionsDenied && !hasStorageWritePermission)
|
if(!_cameraPermissionsDenied && !hasStorageWritePermission)
|
||||||
@@ -153,14 +157,6 @@ namespace Bit.Android.Services
|
|||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
var additionalIntents = new List<IParcelable>();
|
|
||||||
|
|
||||||
var docIntent = new Intent(Intent.ActionOpenDocument);
|
|
||||||
docIntent.AddCategory(Intent.CategoryOpenable);
|
|
||||||
docIntent.SetType("*/*");
|
|
||||||
|
|
||||||
var chooserIntent = Intent.CreateChooser(docIntent, AppResources.FileSource);
|
|
||||||
|
|
||||||
if(!_cameraPermissionsDenied && hasCameraPermission && hasStorageWritePermission)
|
if(!_cameraPermissionsDenied && hasCameraPermission && hasStorageWritePermission)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -177,7 +173,13 @@ namespace Bit.Android.Services
|
|||||||
}
|
}
|
||||||
catch(Java.IO.IOException) { }
|
catch(Java.IO.IOException) { }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var docIntent = new Intent(Intent.ActionOpenDocument);
|
||||||
|
docIntent.AddCategory(Intent.CategoryOpenable);
|
||||||
|
docIntent.SetType("*/*");
|
||||||
|
|
||||||
|
var chooserIntent = Intent.CreateChooser(docIntent, AppResources.FileSource);
|
||||||
if(additionalIntents.Count > 0)
|
if(additionalIntents.Count > 0)
|
||||||
{
|
{
|
||||||
chooserIntent.PutExtra(Intent.ExtraInitialIntents, additionalIntents.ToArray());
|
chooserIntent.PutExtra(Intent.ExtraInitialIntents, additionalIntents.ToArray());
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Android.App;
|
using Android.App;
|
||||||
|
using Android.Content.PM;
|
||||||
using Android.OS;
|
using Android.OS;
|
||||||
using Bit.App.Abstractions;
|
using Bit.App.Abstractions;
|
||||||
|
|
||||||
@@ -42,5 +43,6 @@ namespace Bit.Android.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public bool NfcEnabled => Utilities.NfcEnabled();
|
public bool NfcEnabled => Utilities.NfcEnabled();
|
||||||
|
public bool HasCamera => Xamarin.Forms.Forms.Context.PackageManager.HasSystemFeature(PackageManager.FeatureCamera);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,5 +6,6 @@
|
|||||||
int Version { get; }
|
int Version { get; }
|
||||||
float Scale { get; }
|
float Scale { get; }
|
||||||
bool NfcEnabled { get; }
|
bool NfcEnabled { get; }
|
||||||
|
bool HasCamera { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace Bit.App.Pages
|
|||||||
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
||||||
private readonly ISettings _settings;
|
private readonly ISettings _settings;
|
||||||
private readonly IAppInfoService _appInfoService;
|
private readonly IAppInfoService _appInfoService;
|
||||||
|
private readonly IDeviceInfoService _deviceInfo;
|
||||||
private readonly string _defaultUri;
|
private readonly string _defaultUri;
|
||||||
private readonly string _defaultName;
|
private readonly string _defaultName;
|
||||||
private readonly bool _fromAutofill;
|
private readonly bool _fromAutofill;
|
||||||
@@ -43,6 +44,7 @@ namespace Bit.App.Pages
|
|||||||
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
|
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
|
||||||
_settings = Resolver.Resolve<ISettings>();
|
_settings = Resolver.Resolve<ISettings>();
|
||||||
_appInfoService = Resolver.Resolve<IAppInfoService>();
|
_appInfoService = Resolver.Resolve<IAppInfoService>();
|
||||||
|
_deviceInfo = Resolver.Resolve<IDeviceInfoService>();
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
@@ -61,8 +63,11 @@ namespace Bit.App.Pages
|
|||||||
NotesCell = new FormEditorCell(height: 180);
|
NotesCell = new FormEditorCell(height: 180);
|
||||||
|
|
||||||
TotpCell = new FormEntryCell(AppResources.AuthenticatorKey, nextElement: NotesCell.Editor,
|
TotpCell = new FormEntryCell(AppResources.AuthenticatorKey, nextElement: NotesCell.Editor,
|
||||||
useButton: true);
|
useButton: _deviceInfo.HasCamera);
|
||||||
|
if(_deviceInfo.HasCamera)
|
||||||
|
{
|
||||||
TotpCell.Button.Image = "camera";
|
TotpCell.Button.Image = "camera";
|
||||||
|
}
|
||||||
TotpCell.Entry.DisableAutocapitalize = true;
|
TotpCell.Entry.DisableAutocapitalize = true;
|
||||||
TotpCell.Entry.Autocorrect = false;
|
TotpCell.Entry.Autocorrect = false;
|
||||||
TotpCell.Entry.FontFamily = Helpers.OnPlatform(iOS: "Courier", Android: "monospace", WinPhone: "Courier");
|
TotpCell.Entry.FontFamily = Helpers.OnPlatform(iOS: "Courier", Android: "monospace", WinPhone: "Courier");
|
||||||
@@ -142,7 +147,12 @@ namespace Bit.App.Pages
|
|||||||
}
|
}
|
||||||
else if(Device.RuntimePlatform == Device.Android)
|
else if(Device.RuntimePlatform == Device.Android)
|
||||||
{
|
{
|
||||||
PasswordCell.Button.WidthRequest = TotpCell.Button.WidthRequest = 40;
|
PasswordCell.Button.WidthRequest = 40;
|
||||||
|
|
||||||
|
if(TotpCell.Button != null)
|
||||||
|
{
|
||||||
|
TotpCell.Button.WidthRequest = 40;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
|
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
|
||||||
@@ -234,7 +244,10 @@ namespace Bit.App.Pages
|
|||||||
TotpCell.InitEvents();
|
TotpCell.InitEvents();
|
||||||
FolderCell.InitEvents();
|
FolderCell.InitEvents();
|
||||||
PasswordCell.Button.Clicked += PasswordButton_Clicked;
|
PasswordCell.Button.Clicked += PasswordButton_Clicked;
|
||||||
|
if(TotpCell?.Button != null)
|
||||||
|
{
|
||||||
TotpCell.Button.Clicked += TotpButton_Clicked;
|
TotpCell.Button.Clicked += TotpButton_Clicked;
|
||||||
|
}
|
||||||
GenerateCell.Tapped += GenerateCell_Tapped;
|
GenerateCell.Tapped += GenerateCell_Tapped;
|
||||||
|
|
||||||
if(!_fromAutofill && !_settings.GetValueOrDefault(AddedLoginAlertKey, false))
|
if(!_fromAutofill && !_settings.GetValueOrDefault(AddedLoginAlertKey, false))
|
||||||
@@ -266,7 +279,10 @@ namespace Bit.App.Pages
|
|||||||
TotpCell.Dispose();
|
TotpCell.Dispose();
|
||||||
FolderCell.Dispose();
|
FolderCell.Dispose();
|
||||||
PasswordCell.Button.Clicked -= PasswordButton_Clicked;
|
PasswordCell.Button.Clicked -= PasswordButton_Clicked;
|
||||||
|
if(TotpCell?.Button != null)
|
||||||
|
{
|
||||||
TotpCell.Button.Clicked -= TotpButton_Clicked;
|
TotpCell.Button.Clicked -= TotpButton_Clicked;
|
||||||
|
}
|
||||||
GenerateCell.Tapped -= GenerateCell_Tapped;
|
GenerateCell.Tapped -= GenerateCell_Tapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ namespace Bit.App.Pages
|
|||||||
private readonly IFolderService _folderService;
|
private readonly IFolderService _folderService;
|
||||||
private readonly IUserDialogs _userDialogs;
|
private readonly IUserDialogs _userDialogs;
|
||||||
private readonly IConnectivity _connectivity;
|
private readonly IConnectivity _connectivity;
|
||||||
|
private readonly IDeviceInfoService _deviceInfo;
|
||||||
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
||||||
private DateTime? _lastAction;
|
private DateTime? _lastAction;
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@ namespace Bit.App.Pages
|
|||||||
_folderService = Resolver.Resolve<IFolderService>();
|
_folderService = Resolver.Resolve<IFolderService>();
|
||||||
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
_userDialogs = Resolver.Resolve<IUserDialogs>();
|
||||||
_connectivity = Resolver.Resolve<IConnectivity>();
|
_connectivity = Resolver.Resolve<IConnectivity>();
|
||||||
|
_deviceInfo = Resolver.Resolve<IDeviceInfoService>();
|
||||||
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
|
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
@@ -58,9 +60,12 @@ namespace Bit.App.Pages
|
|||||||
NotesCell.Editor.Text = login.Notes?.Decrypt(login.OrganizationId);
|
NotesCell.Editor.Text = login.Notes?.Decrypt(login.OrganizationId);
|
||||||
|
|
||||||
TotpCell = new FormEntryCell(AppResources.AuthenticatorKey, nextElement: NotesCell.Editor,
|
TotpCell = new FormEntryCell(AppResources.AuthenticatorKey, nextElement: NotesCell.Editor,
|
||||||
useButton: true);
|
useButton: _deviceInfo.HasCamera);
|
||||||
TotpCell.Entry.Text = login.Totp?.Decrypt(login.OrganizationId);
|
if(_deviceInfo.HasCamera)
|
||||||
|
{
|
||||||
TotpCell.Button.Image = "camera";
|
TotpCell.Button.Image = "camera";
|
||||||
|
}
|
||||||
|
TotpCell.Entry.Text = login.Totp?.Decrypt(login.OrganizationId);
|
||||||
TotpCell.Entry.DisableAutocapitalize = true;
|
TotpCell.Entry.DisableAutocapitalize = true;
|
||||||
TotpCell.Entry.Autocorrect = false;
|
TotpCell.Entry.Autocorrect = false;
|
||||||
TotpCell.Entry.FontFamily = Helpers.OnPlatform(iOS: "Courier", Android: "monospace", WinPhone: "Courier");
|
TotpCell.Entry.FontFamily = Helpers.OnPlatform(iOS: "Courier", Android: "monospace", WinPhone: "Courier");
|
||||||
@@ -161,7 +166,12 @@ namespace Bit.App.Pages
|
|||||||
}
|
}
|
||||||
else if(Device.RuntimePlatform == Device.Android)
|
else if(Device.RuntimePlatform == Device.Android)
|
||||||
{
|
{
|
||||||
PasswordCell.Button.WidthRequest = TotpCell.Button.WidthRequest = 40;
|
PasswordCell.Button.WidthRequest = 40;
|
||||||
|
|
||||||
|
if(TotpCell.Button != null)
|
||||||
|
{
|
||||||
|
TotpCell.Button.WidthRequest = 40;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
|
var saveToolBarItem = new ToolbarItem(AppResources.Save, null, async () =>
|
||||||
|
|||||||
@@ -23,5 +23,6 @@ namespace Bit.iOS.Core.Services
|
|||||||
}
|
}
|
||||||
public float Scale => (float)UIScreen.MainScreen.Scale;
|
public float Scale => (float)UIScreen.MainScreen.Scale;
|
||||||
public bool NfcEnabled => false;
|
public bool NfcEnabled => false;
|
||||||
|
public bool HasCamera => true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user