1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-12-27 17:08:00 +01:00

activity key and unsub when activity destroyed

This commit is contained in:
Kyle Spearrin 2019-06-12 21:49:43 -04:00
parent cd60c3da2a
commit 028ebff102

View File

@ -29,6 +29,8 @@ namespace Bit.Droid
[Register("com.x8bit.bitwarden.MainActivity")] [Register("com.x8bit.bitwarden.MainActivity")]
public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{ {
private const string HockeyAppId = "d3834185b4a643479047b86c65293d42";
private IDeviceActionService _deviceActionService; private IDeviceActionService _deviceActionService;
private IMessagingService _messagingService; private IMessagingService _messagingService;
private IBroadcasterService _broadcasterService; private IBroadcasterService _broadcasterService;
@ -39,7 +41,7 @@ namespace Bit.Droid
private PendingIntent _lockAlarmPendingIntent; private PendingIntent _lockAlarmPendingIntent;
private PendingIntent _clearClipboardPendingIntent; private PendingIntent _clearClipboardPendingIntent;
private AppOptions _appOptions; private AppOptions _appOptions;
private const string HockeyAppId = "d3834185b4a643479047b86c65293d42"; private string _activityKey = $"{nameof(MainActivity)}_{Java.Lang.JavaSystem.CurrentTimeMillis().ToString()}";
private Java.Util.Regex.Pattern _otpPattern = private Java.Util.Regex.Pattern _otpPattern =
Java.Util.Regex.Pattern.Compile("^.*?([cbdefghijklnrtuv]{32,64})$"); Java.Util.Regex.Pattern.Compile("^.*?([cbdefghijklnrtuv]{32,64})$");
@ -84,7 +86,7 @@ namespace Bit.Droid
_appOptions = GetOptions(); _appOptions = GetOptions();
LoadApplication(new App.App(_appOptions)); LoadApplication(new App.App(_appOptions));
_broadcasterService.Subscribe(nameof(MainActivity), (message) => _broadcasterService.Subscribe(_activityKey, (message) =>
{ {
if(message.Command == "scheduleLockTimer") if(message.Command == "scheduleLockTimer")
{ {
@ -227,6 +229,12 @@ namespace Bit.Droid
} }
} }
protected override void OnDestroy()
{
base.OnDestroy();
_broadcasterService.Unsubscribe(_activityKey);
}
private void ListenYubiKey(bool listen) private void ListenYubiKey(bool listen)
{ {
if(!_deviceActionService.SupportsNfc()) if(!_deviceActionService.SupportsNfc())