From a6c95d06b5c499e1c481f93a1fea7c86a1e5bd1d Mon Sep 17 00:00:00 2001
From: Matt Portune <59324545+mportune-bw@users.noreply.github.com>
Date: Tue, 29 Jun 2021 10:23:20 -0400
Subject: [PATCH] fix for vault timeout locking issue on android (#1442)
---
src/Android/Android.csproj | 1 -
src/Android/MainActivity.cs | 19 +------------------
src/Android/Receivers/LockAlarmReceiver.cs | 16 ----------------
src/App/App.xaml.cs | 11 +++++------
4 files changed, 6 insertions(+), 41 deletions(-)
delete mode 100644 src/Android/Receivers/LockAlarmReceiver.cs
diff --git a/src/Android/Android.csproj b/src/Android/Android.csproj
index 3ea651dfb..39541c4f1 100644
--- a/src/Android/Android.csproj
+++ b/src/Android/Android.csproj
@@ -118,7 +118,6 @@
-
diff --git a/src/Android/MainActivity.cs b/src/Android/MainActivity.cs
index 722e198c4..9be66fd8e 100644
--- a/src/Android/MainActivity.cs
+++ b/src/Android/MainActivity.cs
@@ -51,7 +51,6 @@ namespace Bit.Droid
private IAppIdService _appIdService;
private IStorageService _storageService;
private IEventService _eventService;
- private PendingIntent _vaultTimeoutAlarmPendingIntent;
private PendingIntent _clearClipboardPendingIntent;
private PendingIntent _eventUploadPendingIntent;
private AppOptions _appOptions;
@@ -64,9 +63,6 @@ namespace Bit.Droid
var eventUploadIntent = new Intent(this, typeof(EventUploadReceiver));
_eventUploadPendingIntent = PendingIntent.GetBroadcast(this, 0, eventUploadIntent,
PendingIntentFlags.UpdateCurrent);
- var alarmIntent = new Intent(this, typeof(LockAlarmReceiver));
- _vaultTimeoutAlarmPendingIntent = PendingIntent.GetBroadcast(this, 0, alarmIntent,
- PendingIntentFlags.UpdateCurrent);
var clearClipboardIntent = new Intent(this, typeof(ClearClipboardAlarmReceiver));
_clearClipboardPendingIntent = PendingIntent.GetBroadcast(this, 0, clearClipboardIntent,
PendingIntentFlags.UpdateCurrent);
@@ -104,20 +100,7 @@ namespace Bit.Droid
_broadcasterService.Subscribe(_activityKey, (message) =>
{
- if (message.Command == "scheduleVaultTimeoutTimer")
- {
- var alarmManager = GetSystemService(AlarmService) as AlarmManager;
- var vaultTimeoutMinutes = (int)message.Data;
- var vaultTimeoutMs = vaultTimeoutMinutes * 60000;
- var triggerMs = Java.Lang.JavaSystem.CurrentTimeMillis() + vaultTimeoutMs + 10;
- alarmManager.Set(AlarmType.RtcWakeup, triggerMs, _vaultTimeoutAlarmPendingIntent);
- }
- else if (message.Command == "cancelVaultTimeoutTimer")
- {
- var alarmManager = GetSystemService(AlarmService) as AlarmManager;
- alarmManager.Cancel(_vaultTimeoutAlarmPendingIntent);
- }
- else if (message.Command == "startEventTimer")
+ if (message.Command == "startEventTimer")
{
StartEventAlarm();
}
diff --git a/src/Android/Receivers/LockAlarmReceiver.cs b/src/Android/Receivers/LockAlarmReceiver.cs
deleted file mode 100644
index e774a367b..000000000
--- a/src/Android/Receivers/LockAlarmReceiver.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using Android.Content;
-using Bit.Core.Abstractions;
-using Bit.Core.Utilities;
-
-namespace Bit.Droid.Receivers
-{
- [BroadcastReceiver(Name = "com.x8bit.bitwarden.LockAlarmReceiver", Exported = false)]
- public class LockAlarmReceiver : BroadcastReceiver
- {
- public async override void OnReceive(Context context, Intent intent)
- {
- var vaultTimeoutService = ServiceContainer.Resolve("vaultTimeoutService");
- await vaultTimeoutService.CheckVaultTimeoutAsync();
- }
- }
-}
diff --git a/src/App/App.xaml.cs b/src/App/App.xaml.cs
index 70714f83c..d1c138271 100644
--- a/src/App/App.xaml.cs
+++ b/src/App/App.xaml.cs
@@ -178,6 +178,10 @@ namespace Bit.App
SyncIfNeeded();
}
}
+ if (Device.RuntimePlatform == Device.Android)
+ {
+ await _vaultTimeoutService.CheckVaultTimeoutAsync();
+ }
_messagingService.Send("startEventTimer");
}
@@ -216,7 +220,6 @@ namespace Bit.App
private async void ResumedAsync()
{
await _vaultTimeoutService.CheckVaultTimeoutAsync();
- _messagingService.Send("cancelVaultTimeoutTimer");
_messagingService.Send("startEventTimer");
await ClearCacheIfNeededAsync();
Prime();
@@ -313,11 +316,7 @@ namespace Bit.App
vaultTimeout = await _storageService.GetAsync(Constants.VaultTimeoutKey);
}
vaultTimeout = vaultTimeout.GetValueOrDefault(-1);
- if (vaultTimeout > 0)
- {
- _messagingService.Send("scheduleVaultTimeoutTimer", vaultTimeout.Value);
- }
- else if (vaultTimeout == 0)
+ if (vaultTimeout == 0)
{
var action = await _storageService.GetAsync(Constants.VaultTimeoutActionKey);
if (action == "logOut")