mirror of
https://github.com/bitwarden/mobile
synced 2025-12-05 23:53:33 +00:00
More accurate push registration for android
This commit is contained in:
@@ -57,20 +57,16 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
|
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
|
||||||
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
|
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
|
||||||
<AndroidLinkSkip />
|
|
||||||
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
|
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
|
||||||
<BundleAssemblies>False</BundleAssemblies>
|
<BundleAssemblies>False</BundleAssemblies>
|
||||||
<AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
|
<AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
|
||||||
<AndroidSupportedAbis>
|
|
||||||
</AndroidSupportedAbis>
|
|
||||||
<AndroidStoreUncompressedFileExtensions />
|
|
||||||
<MandroidI18n />
|
|
||||||
<Debugger>Xamarin</Debugger>
|
<Debugger>Xamarin</Debugger>
|
||||||
<AotAssemblies>False</AotAssemblies>
|
<AotAssemblies>False</AotAssemblies>
|
||||||
<EnableLLVM>False</EnableLLVM>
|
<EnableLLVM>False</EnableLLVM>
|
||||||
<AndroidEnableMultiDex>False</AndroidEnableMultiDex>
|
<AndroidEnableMultiDex>False</AndroidEnableMultiDex>
|
||||||
<EnableProguard>False</EnableProguard>
|
<EnableProguard>False</EnableProguard>
|
||||||
<DebugSymbols>False</DebugSymbols>
|
<DebugSymbols>False</DebugSymbols>
|
||||||
|
<JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Acr.Support.Android, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="Acr.Support.Android, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
|||||||
@@ -41,8 +41,17 @@ namespace Bit.Android
|
|||||||
RegisterActivityLifecycleCallbacks(this);
|
RegisterActivityLifecycleCallbacks(this);
|
||||||
AppContext = ApplicationContext;
|
AppContext = ApplicationContext;
|
||||||
StartPushService();
|
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()
|
public override void OnTerminate()
|
||||||
@@ -85,9 +94,10 @@ namespace Bit.Android
|
|||||||
public static void StartPushService()
|
public static void StartPushService()
|
||||||
{
|
{
|
||||||
AppContext.StartService(new Intent(AppContext, typeof(PushNotificationService)));
|
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);
|
AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(AlarmService);
|
||||||
alarm.Cancel(pintent);
|
alarm.Cancel(pintent);
|
||||||
}
|
}
|
||||||
@@ -96,9 +106,10 @@ namespace Bit.Android
|
|||||||
public static void StopPushService()
|
public static void StopPushService()
|
||||||
{
|
{
|
||||||
AppContext.StopService(new Intent(AppContext, typeof(PushNotificationService)));
|
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);
|
AlarmManager alarm = (AlarmManager)AppContext.GetSystemService(AlarmService);
|
||||||
alarm.Cancel(pintent);
|
alarm.Cancel(pintent);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ using XLabs.Ioc;
|
|||||||
using Acr.UserDialogs;
|
using Acr.UserDialogs;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Plugin.Settings.Abstractions;
|
using Plugin.Settings.Abstractions;
|
||||||
|
using PushNotification.Plugin.Abstractions;
|
||||||
|
|
||||||
namespace Bit.App.Pages
|
namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
@@ -23,6 +24,7 @@ namespace Bit.App.Pages
|
|||||||
private ISyncService _syncService;
|
private ISyncService _syncService;
|
||||||
private ISettings _settings;
|
private ISettings _settings;
|
||||||
private IGoogleAnalyticsService _googleAnalyticsService;
|
private IGoogleAnalyticsService _googleAnalyticsService;
|
||||||
|
private IPushNotification _pushNotification;
|
||||||
private readonly string _email;
|
private readonly string _email;
|
||||||
|
|
||||||
public LoginPage(string email = null)
|
public LoginPage(string email = null)
|
||||||
@@ -37,6 +39,7 @@ namespace Bit.App.Pages
|
|||||||
_syncService = Resolver.Resolve<ISyncService>();
|
_syncService = Resolver.Resolve<ISyncService>();
|
||||||
_settings = Resolver.Resolve<ISettings>();
|
_settings = Resolver.Resolve<ISettings>();
|
||||||
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
|
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
|
||||||
|
_pushNotification = Resolver.Resolve<IPushNotification>();
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
@@ -201,6 +204,11 @@ namespace Bit.App.Pages
|
|||||||
_googleAnalyticsService.RefreshUserId();
|
_googleAnalyticsService.RefreshUserId();
|
||||||
_googleAnalyticsService.TrackAppEvent("LoggedIn");
|
_googleAnalyticsService.TrackAppEvent("LoggedIn");
|
||||||
|
|
||||||
|
if(Device.OS == TargetPlatform.Android)
|
||||||
|
{
|
||||||
|
_pushNotification.Register();
|
||||||
|
}
|
||||||
|
|
||||||
if(_authService.IsAuthenticatedTwoFactor)
|
if(_authService.IsAuthenticatedTwoFactor)
|
||||||
{
|
{
|
||||||
await Navigation.PushAsync(new LoginTwoFactorPage());
|
await Navigation.PushAsync(new LoginTwoFactorPage());
|
||||||
|
|||||||
@@ -83,7 +83,8 @@ namespace Bit.App.Services
|
|||||||
return;
|
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)
|
if(response.Succeeded)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Registered device with server.");
|
Debug.WriteLine("Registered device with server.");
|
||||||
|
|||||||
Reference in New Issue
Block a user