mirror of
https://github.com/bitwarden/android.git
synced 2024-12-25 02:18:27 +03:00
added broadcast receiver for when android updated
This commit is contained in:
parent
7490ba3179
commit
e4d9dfc128
6 changed files with 44 additions and 11 deletions
|
@ -348,6 +348,7 @@
|
||||||
<Compile Include="Services\ReflectionService.cs" />
|
<Compile Include="Services\ReflectionService.cs" />
|
||||||
<Compile Include="Services\SqlService.cs" />
|
<Compile Include="Services\SqlService.cs" />
|
||||||
<Compile Include="SplashActivity.cs" />
|
<Compile Include="SplashActivity.cs" />
|
||||||
|
<Compile Include="PackageReplacedReceiver.cs" />
|
||||||
<Compile Include="Utilities.cs" />
|
<Compile Include="Utilities.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
22
src/Android/PackageReplacedReceiver.cs
Normal file
22
src/Android/PackageReplacedReceiver.cs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
using Android.App;
|
||||||
|
using Android.Content;
|
||||||
|
using Bit.App.Abstractions;
|
||||||
|
using Bit.App.Utilities;
|
||||||
|
using Plugin.Settings.Abstractions;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using XLabs.Ioc;
|
||||||
|
|
||||||
|
namespace Bit.Android
|
||||||
|
{
|
||||||
|
[BroadcastReceiver(Name = "com.x8bit.bitwarden.PackageReplacedReceiver", Exported = true)]
|
||||||
|
[IntentFilter(new[] { Intent.ActionMyPackageReplaced })]
|
||||||
|
public class PackageReplacedReceiver : BroadcastReceiver
|
||||||
|
{
|
||||||
|
public override void OnReceive(Context context, Intent intent)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("App updated!");
|
||||||
|
Helpers.PerformUpdateTasks(Resolver.Resolve<ISettings>(), Resolver.Resolve<IAppInfoService>(),
|
||||||
|
Resolver.Resolve<IDatabaseService>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -95,7 +95,7 @@ namespace Bit.Android.Services
|
||||||
var pm = CrossCurrentActivity.Current.Activity.PackageManager;
|
var pm = CrossCurrentActivity.Current.Activity.PackageManager;
|
||||||
var intent = new Intent(Intent.ActionView);
|
var intent = new Intent(Intent.ActionView);
|
||||||
intent.SetType(mimeType);
|
intent.SetType(mimeType);
|
||||||
var activities = pm.QueryIntentActivities(intent, global::Android.Content.PM.PackageInfoFlags.MatchDefaultOnly);
|
var activities = pm.QueryIntentActivities(intent, PackageInfoFlags.MatchDefaultOnly);
|
||||||
return (activities?.Count ?? 0) > 0;
|
return (activities?.Count ?? 0) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,12 @@ using Acr.UserDialogs;
|
||||||
using XLabs.Ioc;
|
using XLabs.Ioc;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Bit.App.Resources;
|
using Bit.App.Resources;
|
||||||
|
using Bit.App.Utilities;
|
||||||
|
|
||||||
namespace Bit.App
|
namespace Bit.App
|
||||||
{
|
{
|
||||||
public class App : Application
|
public class App : Application
|
||||||
{
|
{
|
||||||
private const string LastBuildKey = "LastBuild";
|
|
||||||
|
|
||||||
private string _uri;
|
private string _uri;
|
||||||
private readonly IDatabaseService _databaseService;
|
private readonly IDatabaseService _databaseService;
|
||||||
private readonly IConnectivity _connectivity;
|
private readonly IConnectivity _connectivity;
|
||||||
|
@ -103,13 +102,7 @@ namespace Bit.App
|
||||||
|
|
||||||
if(string.IsNullOrWhiteSpace(_uri))
|
if(string.IsNullOrWhiteSpace(_uri))
|
||||||
{
|
{
|
||||||
var lastBuild = _settings.GetValueOrDefault<string>(LastBuildKey);
|
Helpers.PerformUpdateTasks(_settings, _appInfoService, _databaseService);
|
||||||
if(Utilities.Helpers.InDebugMode() || lastBuild == null || lastBuild != _appInfoService.Build)
|
|
||||||
{
|
|
||||||
_settings.AddOrUpdateValue(LastBuildKey, _appInfoService.Build);
|
|
||||||
_databaseService.CreateTables();
|
|
||||||
}
|
|
||||||
|
|
||||||
await Task.Run(() => FullSyncAsync()).ConfigureAwait(false);
|
await Task.Run(() => FullSyncAsync()).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
public const string Locked = "other:locked";
|
public const string Locked = "other:locked";
|
||||||
public const string LastLoginEmail = "other:lastLoginEmail";
|
public const string LastLoginEmail = "other:lastLoginEmail";
|
||||||
public const string LastSync = "other:lastSync";
|
public const string LastSync = "other:lastSync";
|
||||||
|
public const string LastBuildKey = "LastBuild";
|
||||||
|
|
||||||
public const int SelectFileRequestCode = 42;
|
public const int SelectFileRequestCode = 42;
|
||||||
public const int SelectFilePermissionRequestCode = 43;
|
public const int SelectFilePermissionRequestCode = 43;
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
using System;
|
using Bit.App.Abstractions;
|
||||||
|
using Plugin.Settings.Abstractions;
|
||||||
|
using System;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
|
|
||||||
namespace Bit.App.Utilities
|
namespace Bit.App.Utilities
|
||||||
|
@ -38,5 +40,19 @@ namespace Bit.App.Utilities
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool PerformUpdateTasks(ISettings settings, IAppInfoService appInfoService,
|
||||||
|
IDatabaseService databaseService)
|
||||||
|
{
|
||||||
|
var lastBuild = settings.GetValueOrDefault<string>(Constants.LastBuildKey);
|
||||||
|
if(InDebugMode() || lastBuild == null || lastBuild != appInfoService.Build)
|
||||||
|
{
|
||||||
|
settings.AddOrUpdateValue(Constants.LastBuildKey, appInfoService.Build);
|
||||||
|
databaseService.CreateTables();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue