mirror of
https://github.com/bitwarden/android.git
synced 2024-12-25 02:18:27 +03:00
clear clipboard alarm
This commit is contained in:
parent
49705b1074
commit
70fa41ca3e
6 changed files with 68 additions and 2 deletions
|
@ -112,6 +112,7 @@
|
||||||
<Compile Include="Autofill\SavedItem.cs" />
|
<Compile Include="Autofill\SavedItem.cs" />
|
||||||
<Compile Include="Push\FirebaseInstanceIdService.cs" />
|
<Compile Include="Push\FirebaseInstanceIdService.cs" />
|
||||||
<Compile Include="Push\FirebaseMessagingService.cs" />
|
<Compile Include="Push\FirebaseMessagingService.cs" />
|
||||||
|
<Compile Include="Receivers\ClearClipboardAlarmReceiver.cs" />
|
||||||
<Compile Include="Receivers\LockAlarmReceiver.cs" />
|
<Compile Include="Receivers\LockAlarmReceiver.cs" />
|
||||||
<Compile Include="Receivers\PackageReplacedReceiver.cs" />
|
<Compile Include="Receivers\PackageReplacedReceiver.cs" />
|
||||||
<Compile Include="Renderers\ExtendedSliderRenderer.cs" />
|
<Compile Include="Renderers\ExtendedSliderRenderer.cs" />
|
||||||
|
|
|
@ -16,6 +16,7 @@ using Bit.App.Models;
|
||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using Android.Nfc;
|
using Android.Nfc;
|
||||||
using Bit.App.Utilities;
|
using Bit.App.Utilities;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Bit.Droid
|
namespace Bit.Droid
|
||||||
{
|
{
|
||||||
|
@ -33,7 +34,10 @@ namespace Bit.Droid
|
||||||
private IBroadcasterService _broadcasterService;
|
private IBroadcasterService _broadcasterService;
|
||||||
private IUserService _userService;
|
private IUserService _userService;
|
||||||
private IAppIdService _appIdService;
|
private IAppIdService _appIdService;
|
||||||
|
private IStorageService _storageService;
|
||||||
|
private IStateService _stateService;
|
||||||
private PendingIntent _lockAlarmPendingIntent;
|
private PendingIntent _lockAlarmPendingIntent;
|
||||||
|
private PendingIntent _clearClipboardPendingIntent;
|
||||||
private AppOptions _appOptions;
|
private AppOptions _appOptions;
|
||||||
private const string HockeyAppId = "d3834185b4a643479047b86c65293d42";
|
private const string HockeyAppId = "d3834185b4a643479047b86c65293d42";
|
||||||
private Java.Util.Regex.Pattern _otpPattern =
|
private Java.Util.Regex.Pattern _otpPattern =
|
||||||
|
@ -44,6 +48,9 @@ namespace Bit.Droid
|
||||||
var alarmIntent = new Intent(this, typeof(LockAlarmReceiver));
|
var alarmIntent = new Intent(this, typeof(LockAlarmReceiver));
|
||||||
_lockAlarmPendingIntent = PendingIntent.GetBroadcast(this, 0, alarmIntent,
|
_lockAlarmPendingIntent = PendingIntent.GetBroadcast(this, 0, alarmIntent,
|
||||||
PendingIntentFlags.UpdateCurrent);
|
PendingIntentFlags.UpdateCurrent);
|
||||||
|
var clearClipboardIntent = new Intent(this, typeof(ClearClipboardAlarmReceiver));
|
||||||
|
_clearClipboardPendingIntent = PendingIntent.GetBroadcast(this, 0, clearClipboardIntent,
|
||||||
|
PendingIntentFlags.UpdateCurrent);
|
||||||
|
|
||||||
var policy = new StrictMode.ThreadPolicy.Builder().PermitAll().Build();
|
var policy = new StrictMode.ThreadPolicy.Builder().PermitAll().Build();
|
||||||
StrictMode.SetThreadPolicy(policy);
|
StrictMode.SetThreadPolicy(policy);
|
||||||
|
@ -53,6 +60,8 @@ namespace Bit.Droid
|
||||||
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
|
_broadcasterService = ServiceContainer.Resolve<IBroadcasterService>("broadcasterService");
|
||||||
_userService = ServiceContainer.Resolve<IUserService>("userService");
|
_userService = ServiceContainer.Resolve<IUserService>("userService");
|
||||||
_appIdService = ServiceContainer.Resolve<IAppIdService>("appIdService");
|
_appIdService = ServiceContainer.Resolve<IAppIdService>("appIdService");
|
||||||
|
_storageService = ServiceContainer.Resolve<IStorageService>("storageService");
|
||||||
|
_stateService = ServiceContainer.Resolve<IStateService>("stateService");
|
||||||
|
|
||||||
TabLayoutResource = Resource.Layout.Tabbar;
|
TabLayoutResource = Resource.Layout.Tabbar;
|
||||||
ToolbarResource = Resource.Layout.Toolbar;
|
ToolbarResource = Resource.Layout.Toolbar;
|
||||||
|
@ -105,6 +114,10 @@ namespace Bit.Droid
|
||||||
{
|
{
|
||||||
ExitApp();
|
ExitApp();
|
||||||
}
|
}
|
||||||
|
else if(message.Command == "copiedToClipboard")
|
||||||
|
{
|
||||||
|
var task = ClearClipboardAlarmAsync(message.Data as Tuple<string, int?, bool>);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,5 +306,30 @@ namespace Bit.Droid
|
||||||
FinishAffinity();
|
FinishAffinity();
|
||||||
Java.Lang.JavaSystem.Exit(0);
|
Java.Lang.JavaSystem.Exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task ClearClipboardAlarmAsync(Tuple<string, int?, bool> data)
|
||||||
|
{
|
||||||
|
if(data.Item3)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var clearMs = data.Item2;
|
||||||
|
if(clearMs == null)
|
||||||
|
{
|
||||||
|
var clearSeconds = await _storageService.GetAsync<int?>(Constants.ClearClipboardKey);
|
||||||
|
if(clearSeconds != null)
|
||||||
|
{
|
||||||
|
clearMs = clearSeconds.Value * 1000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(clearMs == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await _stateService.SaveAsync(Constants.LastClipboardValueKey, data.Item1);
|
||||||
|
var triggerMs = Java.Lang.JavaSystem.CurrentTimeMillis() + clearMs.Value;
|
||||||
|
var alarmManager = GetSystemService(AlarmService) as AlarmManager;
|
||||||
|
alarmManager.Set(AlarmType.Rtc, triggerMs, _clearClipboardPendingIntent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
23
src/Android/Receivers/ClearClipboardAlarmReceiver.cs
Normal file
23
src/Android/Receivers/ClearClipboardAlarmReceiver.cs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
using Android.Content;
|
||||||
|
using Bit.Core;
|
||||||
|
using Bit.Core.Abstractions;
|
||||||
|
using Bit.Core.Utilities;
|
||||||
|
|
||||||
|
namespace Bit.Droid.Receivers
|
||||||
|
{
|
||||||
|
[BroadcastReceiver(Name = "com.x8bit.bitwarden.ClearClipboardAlarmReceiver", Exported = false)]
|
||||||
|
public class ClearClipboardAlarmReceiver : BroadcastReceiver
|
||||||
|
{
|
||||||
|
public async override void OnReceive(Context context, Intent intent)
|
||||||
|
{
|
||||||
|
var stateService = ServiceContainer.Resolve<IStateService>("stateService");
|
||||||
|
var clipboardManager = context.GetSystemService(Context.ClipboardService) as ClipboardManager;
|
||||||
|
var lastClipboardValue = await stateService.GetAsync<string>(Constants.LastClipboardValueKey);
|
||||||
|
await stateService.RemoveAsync(Constants.LastClipboardValueKey);
|
||||||
|
if(lastClipboardValue == clipboardManager.Text)
|
||||||
|
{
|
||||||
|
clipboardManager.Text = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,7 +9,6 @@ namespace Bit.Droid.Receivers
|
||||||
{
|
{
|
||||||
public async override void OnReceive(Context context, Intent intent)
|
public async override void OnReceive(Context context, Intent intent)
|
||||||
{
|
{
|
||||||
System.Diagnostics.Debug.WriteLine("LockAlarmReceiver OnReceive");
|
|
||||||
var lockService = ServiceContainer.Resolve<ILockService>("lockService");
|
var lockService = ServiceContainer.Resolve<ILockService>("lockService");
|
||||||
await lockService.CheckLockAsync();
|
await lockService.CheckLockAsync();
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,8 +179,12 @@ namespace Bit.App.Services
|
||||||
public async Task CopyToClipboardAsync(string text, Dictionary<string, object> options = null)
|
public async Task CopyToClipboardAsync(string text, Dictionary<string, object> options = null)
|
||||||
{
|
{
|
||||||
var clearMs = options != null && options.ContainsKey("clearMs") ? (int?)options["clearMs"] : null;
|
var clearMs = options != null && options.ContainsKey("clearMs") ? (int?)options["clearMs"] : null;
|
||||||
|
var clearing = options != null && options.ContainsKey("clearing") ? (bool)options["clearing"] : false;
|
||||||
await Clipboard.SetTextAsync(text);
|
await Clipboard.SetTextAsync(text);
|
||||||
_messagingService.Send("copiedToClipboard", new Tuple<string, int?>(text, clearMs));
|
if(!clearing)
|
||||||
|
{
|
||||||
|
_messagingService.Send("copiedToClipboard", new Tuple<string, int?, bool>(text, clearMs, clearing));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> ReadFromClipboardAsync(Dictionary<string, object> options = null)
|
public async Task<string> ReadFromClipboardAsync(Dictionary<string, object> options = null)
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
public static string PushInitialPromptShownKey = "pushInitialPromptShown";
|
public static string PushInitialPromptShownKey = "pushInitialPromptShown";
|
||||||
public static string ThemeKey = "theme";
|
public static string ThemeKey = "theme";
|
||||||
public static string ClearClipboardKey = "clearClipboard";
|
public static string ClearClipboardKey = "clearClipboard";
|
||||||
|
public static string LastClipboardValueKey = "lastClipboardValue";
|
||||||
public const int SelectFileRequestCode = 42;
|
public const int SelectFileRequestCode = 42;
|
||||||
public const int SelectFilePermissionRequestCode = 43;
|
public const int SelectFilePermissionRequestCode = 43;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue