Exemple #1
0
        public void Lock(bool allowQuickUnlock = true, bool lockWasTriggeredByTimeout = false)
        {
            if (OpenDatabases.Any())
            {
                if (QuickUnlockEnabled && allowQuickUnlock &&
                    GetDbForQuickUnlock().KpDatabase.MasterKey.ContainsType(typeof(KcpPassword)) &&
                    !((KcpPassword)App.Kp2a.GetDbForQuickUnlock().KpDatabase.MasterKey.GetUserKey(typeof(KcpPassword))).Password.IsEmpty)
                {
                    if (!QuickLocked)
                    {
                        Kp2aLog.Log("QuickLocking database");
                        QuickLocked     = true;
                        LastOpenedEntry = null;
                        BroadcastDatabaseAction(LocaleManager.LocalizedAppContext, Strings.ActionLockDatabase);
                    }
                    else
                    {
                        Kp2aLog.Log("Database already QuickLocked");
                    }
                }
                else
                {
                    Kp2aLog.Log("Locking database");

                    BroadcastDatabaseAction(LocaleManager.LocalizedAppContext, Strings.ActionCloseDatabase);

                    // Couldn't quick-lock, so unload database(s) instead
                    _openAttempts.Clear();
                    _openDatabases.Clear();
                    _currentDatabase = null;
                    LastOpenedEntry  = null;
                    QuickLocked      = false;
                }
            }
            else
            {
                Kp2aLog.Log("Database not loaded, couldn't lock");
            }
            _currentlyWaitingXcKey = null;

            UpdateOngoingNotification();
            var intent = new Intent(Intents.DatabaseLocked);

            if (lockWasTriggeredByTimeout)
            {
                intent.PutExtra("ByTimeout", true);
            }
            LocaleManager.LocalizedAppContext.SendBroadcast(intent);
        }
Exemple #2
0
        public void Lock(bool allowQuickUnlock = true)
        {
            if (OpenDatabases.Any())
            {
                if (QuickUnlockEnabled && allowQuickUnlock &&
                    GetDbForQuickUnlock().KpDatabase.MasterKey.ContainsType(typeof(KcpPassword)) &&
                    !((KcpPassword)App.Kp2a.GetDbForQuickUnlock().KpDatabase.MasterKey.GetUserKey(typeof(KcpPassword))).Password.IsEmpty)
                {
                    if (!QuickLocked)
                    {
                        Kp2aLog.Log("QuickLocking database");
                        QuickLocked     = true;
                        LastOpenedEntry = null;
                        BroadcastDatabaseAction(Application.Context, Strings.ActionLockDatabase);
                    }
                    else
                    {
                        Kp2aLog.Log("Database already QuickLocked");
                    }
                }
                else
                {
                    Kp2aLog.Log("Locking database");

                    BroadcastDatabaseAction(Application.Context, Strings.ActionCloseDatabase);

                    // Couldn't quick-lock, so unload database(s) instead
                    _openAttempts.Clear();
                    _openDatabases.Clear();
                    _currentDatabase = null;
                    LastOpenedEntry  = null;
                    QuickLocked      = false;
                }
            }
            else
            {
                Kp2aLog.Log("Database not loaded, couldn't lock");
            }

            UpdateOngoingNotification();
            Application.Context.SendBroadcast(new Intent(Intents.DatabaseLocked));
        }