mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 15:15:34 +03:00
More accurate push registration for android
This commit is contained in:
parent
b7448a7422
commit
7b9c00cd77
4 changed files with 28 additions and 12 deletions
|
@ -57,20 +57,16 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
|
||||
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
|
||||
<AndroidLinkSkip />
|
||||
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
|
||||
<BundleAssemblies>False</BundleAssemblies>
|
||||
<AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
|
||||
<AndroidSupportedAbis>
|
||||
</AndroidSupportedAbis>
|
||||
<AndroidStoreUncompressedFileExtensions />
|
||||
<MandroidI18n />
|
||||
<Debugger>Xamarin</Debugger>
|
||||
<AotAssemblies>False</AotAssemblies>
|
||||
<EnableLLVM>False</EnableLLVM>
|
||||
<AndroidEnableMultiDex>False</AndroidEnableMultiDex>
|
||||
<EnableProguard>False</EnableProguard>
|
||||
<DebugSymbols>False</DebugSymbols>
|
||||
<JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Acr.Support.Android, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
|
|
|
@ -41,8 +41,17 @@ namespace Bit.Android
|
|||
RegisterActivityLifecycleCallbacks(this);
|
||||
AppContext = ApplicationContext;
|
||||
StartPushService();
|
||||
Resolver.Resolve<IPushNotification>().Unregister();
|
||||
Resolver.Resolve<IPushNotification>().Register();
|
||||
|
||||
var pushNotification = Resolver.Resolve<IPushNotification>();
|
||||
#if DEBUG
|
||||
// When running in debug mode you must unregister the previous instance first or else things wont work
|
||||
// ref https://github.com/rdelrosario/xamarin-plugins/issues/65
|
||||
pushNotification.Unregister();
|
||||
#endif
|
||||
if(Resolver.Resolve<IAuthService>().IsAuthenticated)
|
||||
{
|
||||
pushNotification.Register();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnTerminate()
|
||||
|
@ -85,9 +94,10 @@ namespace Bit.Android
|
|||
public static void StartPushService()
|
||||
{
|
||||
AppContext.StartService(new Intent(AppContext, typeof(PushNotificationService)));
|
||||
if(global::Android.OS.Build.VERSION.SdkInt >= global::Android.OS.BuildVersionCodes.Kitkat)
|
||||
if(Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
|
||||
{
|
||||
PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext, typeof(PushNotificationService)), 0);
|
||||
PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext,
|
||||
typeof(PushNotificationService)), 0);
|
||||
AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(AlarmService);
|
||||
alarm.Cancel(pintent);
|
||||
}
|
||||
|
@ -96,9 +106,10 @@ namespace Bit.Android
|
|||
public static void StopPushService()
|
||||
{
|
||||
AppContext.StopService(new Intent(AppContext, typeof(PushNotificationService)));
|
||||
if(global::Android.OS.Build.VERSION.SdkInt >= global::Android.OS.BuildVersionCodes.Kitkat)
|
||||
if(Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
|
||||
{
|
||||
PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext, typeof(PushNotificationService)), 0);
|
||||
PendingIntent pintent = PendingIntent.GetService(AppContext, 0, new Intent(AppContext,
|
||||
typeof(PushNotificationService)), 0);
|
||||
AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(AlarmService);
|
||||
alarm.Cancel(pintent);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ using XLabs.Ioc;
|
|||
using Acr.UserDialogs;
|
||||
using System.Threading.Tasks;
|
||||
using Plugin.Settings.Abstractions;
|
||||
using PushNotification.Plugin.Abstractions;
|
||||
|
||||
namespace Bit.App.Pages
|
||||
{
|
||||
|
@ -23,6 +24,7 @@ namespace Bit.App.Pages
|
|||
private ISyncService _syncService;
|
||||
private ISettings _settings;
|
||||
private IGoogleAnalyticsService _googleAnalyticsService;
|
||||
private IPushNotification _pushNotification;
|
||||
private readonly string _email;
|
||||
|
||||
public LoginPage(string email = null)
|
||||
|
@ -37,6 +39,7 @@ namespace Bit.App.Pages
|
|||
_syncService = Resolver.Resolve<ISyncService>();
|
||||
_settings = Resolver.Resolve<ISettings>();
|
||||
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
|
||||
_pushNotification = Resolver.Resolve<IPushNotification>();
|
||||
|
||||
Init();
|
||||
}
|
||||
|
@ -201,6 +204,11 @@ namespace Bit.App.Pages
|
|||
_googleAnalyticsService.RefreshUserId();
|
||||
_googleAnalyticsService.TrackAppEvent("LoggedIn");
|
||||
|
||||
if(Device.OS == TargetPlatform.Android)
|
||||
{
|
||||
_pushNotification.Register();
|
||||
}
|
||||
|
||||
if(_authService.IsAuthenticatedTwoFactor)
|
||||
{
|
||||
await Navigation.PushAsync(new LoginTwoFactorPage());
|
||||
|
|
|
@ -83,7 +83,8 @@ namespace Bit.App.Services
|
|||
return;
|
||||
}
|
||||
|
||||
var response = await _deviceApiRepository.PutTokenAsync(_appIdService.AppId, new Models.Api.DeviceTokenRequest(token));
|
||||
var response = await _deviceApiRepository.PutTokenAsync(_appIdService.AppId,
|
||||
new Models.Api.DeviceTokenRequest(token));
|
||||
if(response.Succeeded)
|
||||
{
|
||||
Debug.WriteLine("Registered device with server.");
|
||||
|
|
Loading…
Reference in a new issue