mirror of
https://github.com/moparisthebest/keepass2android
synced 2025-02-07 02:10:10 -05:00
Working, OngoingNotifications foreground only when QuickLocked
This commit is contained in:
parent
8c8c94c454
commit
e3b707b529
@ -216,17 +216,6 @@ namespace keepass2android
|
||||
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
|
||||
if (!App.Kp2a.QuickUnlockEnabled)
|
||||
{
|
||||
// We're exiting (probably task-killed), so stop the service, if it's still running - don't want it hanging around with an icon shown.
|
||||
StopService(new Intent(this, typeof(OngoingNotificationsService)));
|
||||
}
|
||||
}
|
||||
|
||||
internal AppTask AppTask;
|
||||
|
||||
protected override void OnCreate(Bundle savedInstanceState)
|
||||
|
@ -116,6 +116,8 @@ namespace keepass2android
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
Kp2aLog.Log("CopyToClipboardService.OnDestroy");
|
||||
|
||||
// These members might never get initialized if the app timed out
|
||||
if (_stopOnLockBroadcastReceiver != null)
|
||||
{
|
||||
@ -130,7 +132,10 @@ namespace keepass2android
|
||||
UnregisterReceiver(_notificationDeletedBroadcastReceiver);
|
||||
}
|
||||
if ( _notificationManager != null ) {
|
||||
_notificationManager.CancelAll();
|
||||
_notificationManager.Cancel(NotifyPassword);
|
||||
_notificationManager.Cancel(NotifyUsername);
|
||||
_notificationManager.Cancel(NotifyKeyboard);
|
||||
|
||||
_numElementsToWaitFor= 0;
|
||||
clearKeyboard();
|
||||
}
|
||||
@ -158,8 +163,10 @@ namespace keepass2android
|
||||
{
|
||||
// Notification Manager
|
||||
_notificationManager = (NotificationManager)GetSystemService(NotificationService);
|
||||
|
||||
_notificationManager.CancelAll();
|
||||
|
||||
_notificationManager.Cancel(NotifyPassword);
|
||||
_notificationManager.Cancel(NotifyUsername);
|
||||
_notificationManager.Cancel(NotifyKeyboard);
|
||||
_numElementsToWaitFor = 0;
|
||||
clearKeyboard();
|
||||
|
||||
|
@ -44,18 +44,38 @@ namespace keepass2android
|
||||
{
|
||||
Kp2aLog.Log("Starting/Updating OngoingNotificationsService. Database " + (App.Kp2a.DatabaseIsUnlocked ? "Unlocked" : (App.Kp2a.QuickLocked ? "QuickLocked" : "Locked")));
|
||||
|
||||
// Clear current foreground status and QuickUnlock icon
|
||||
StopForeground(true);
|
||||
|
||||
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
|
||||
|
||||
// Set the icon to reflect the current state
|
||||
if (App.Kp2a.DatabaseIsUnlocked && ShowUnlockedNotification)
|
||||
if (App.Kp2a.DatabaseIsUnlocked)
|
||||
{
|
||||
StartForeground(UnlockedWarningId, GetUnlockedNotification());
|
||||
// Clear current foreground status and QuickUnlock icon
|
||||
StopForeground(true);
|
||||
|
||||
if (ShowUnlockedNotification)
|
||||
{
|
||||
// No need for task to get foreground priority, we don't need any special treatment just for showing that the database is unlocked
|
||||
notificationManager.Notify(UnlockedWarningId, GetUnlockedNotification());
|
||||
}
|
||||
else
|
||||
{
|
||||
notificationManager.Cancel(UnlockedWarningId);
|
||||
}
|
||||
}
|
||||
else if (App.Kp2a.QuickLocked)
|
||||
else
|
||||
{
|
||||
// Show the Quick Unlock notification
|
||||
StartForeground(QuickUnlockId, GetQuickUnlockNotification());
|
||||
notificationManager.Cancel(UnlockedWarningId);
|
||||
|
||||
if (App.Kp2a.QuickLocked)
|
||||
{
|
||||
// Show the Quick Unlock notification
|
||||
StartForeground(QuickUnlockId, GetQuickUnlockNotification());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not showing any notification, database is locked, no point in keeping running
|
||||
StopSelf();
|
||||
}
|
||||
}
|
||||
|
||||
return StartCommandResult.NotSticky;
|
||||
@ -70,7 +90,7 @@ namespace keepass2android
|
||||
{
|
||||
base.OnTaskRemoved(rootIntent);
|
||||
|
||||
Kp2aLog.Log("OngoingNotificationsService.OnTaskRemoved");
|
||||
Kp2aLog.Log("OngoingNotificationsService.OnTaskRemoved: " + rootIntent.Action);
|
||||
|
||||
// If the user has closed the task (probably by swiping it out of the recent apps list) then lock the database
|
||||
App.Kp2a.LockDatabase();
|
||||
@ -80,11 +100,15 @@ namespace keepass2android
|
||||
{
|
||||
base.OnDestroy();
|
||||
|
||||
Kp2aLog.Log("OngoingNotificationsService.OnDestroy2");
|
||||
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
|
||||
notificationManager.Cancel(UnlockedWarningId);
|
||||
// Quick Unlock notification should be removed automatically by the service (if present), as it was the foreground notification.
|
||||
|
||||
if (ShowUnlockedNotification)
|
||||
Kp2aLog.Log("OngoingNotificationsService.OnDestroy");
|
||||
|
||||
// If the service is killed, then lock the database immediately (as the unlocked warning icon will no longer display).
|
||||
if (App.Kp2a.DatabaseIsUnlocked)
|
||||
{
|
||||
// If the service is killed, then lock the database immediately (as the unlocked warning icon will no longer display).
|
||||
App.Kp2a.LockDatabase();
|
||||
}
|
||||
}
|
||||
@ -94,20 +118,6 @@ namespace keepass2android
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void OnLowMemory()
|
||||
{
|
||||
base.OnLowMemory();
|
||||
|
||||
Kp2aLog.Log("OngoingNotificationsService.OnLowMemory");
|
||||
|
||||
if (App.Kp2a.DatabaseIsUnlocked && !App.Kp2a.QuickUnlockEnabled)
|
||||
{
|
||||
// Although this is a foreground service, if it is only indicating that the database is unlocked then it isn't of foreground-importance,
|
||||
// and can be killed if Android requests it (which will clear the database and free up some memory)
|
||||
StopSelf();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region QuickUnlock
|
||||
|
Loading…
Reference in New Issue
Block a user