public void DisplayAccessNotifications(PwEntryOutput entry, bool closeAfterCreate, string searchUrl)
        {
            var hadKeyboardData = ClearNotifications();

            String entryName = entry.OutputStrings.ReadSafe(PwDefs.TitleField);

            ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            var notBuilder           = new PasswordAccessNotificationBuilder(this, _notificationManager);

            if (prefs.GetBoolean(GetString(Resource.String.CopyToClipboardNotification_key), Resources.GetBoolean(Resource.Boolean.CopyToClipboardNotification_default)))
            {
                if (entry.OutputStrings.ReadSafe(PwDefs.PasswordField).Length > 0)
                {
                    notBuilder.AddPasswordAccess();
                }

                if (entry.OutputStrings.ReadSafe(PwDefs.UserNameField).Length > 0)
                {
                    notBuilder.AddUsernameAccess();
                }
            }

            bool hasKeyboardDataNow = false;

            if (prefs.GetBoolean(GetString(Resource.String.UseKp2aKeyboard_key), Resources.GetBoolean(Resource.Boolean.UseKp2aKeyboard_default)))
            {
                //keyboard
                hasKeyboardDataNow = MakeAccessibleForKeyboard(entry, searchUrl);
                if (hasKeyboardDataNow)
                {
                    notBuilder.AddKeyboardAccess();

                    if (closeAfterCreate && Keepass2android.Autofill.AutoFillService.IsAvailable)
                    {
                        if (IsKp2aInputMethodEnabled)
                        {
                            ActivateKeyboardIfAppropriate(closeAfterCreate, prefs);
                        }
                        else if (Keepass2android.Autofill.AutoFillService.IsRunning)
                        {
                            //don't do anything, service is notified
                        }
                        else                         //neither keyboard nor activity service are running/enabled. Ask the user what to do.
                        {
                            var i = new Intent(this, typeof(ActivateAutoFillActivity));
                            i.AddFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
                            StartActivity(i);
                            prefs.Edit().PutBoolean("has_asked_autofillservice", true).Commit();
                        }
                    }
                    else
                    {
                        ActivateKeyboardIfAppropriate(closeAfterCreate, prefs);
                    }
                }
            }

            if ((!hasKeyboardDataNow) && (hadKeyboardData))
            {
                ClearKeyboard(true);                 //this clears again and then (this is the point) broadcasts that we no longer have keyboard data
            }
            _numElementsToWaitFor = notBuilder.CreateNotifications(entryName);

            if (_numElementsToWaitFor == 0)
            {
                StopSelf();
                return;
            }

            IntentFilter filter = new IntentFilter();

            filter.AddAction(Intents.CopyUsername);
            filter.AddAction(Intents.CopyPassword);
            filter.AddAction(Intents.CheckKeyboard);

            //register receiver to get notified when notifications are discarded in which case we can shutdown the service
            _notificationDeletedBroadcastReceiver = new NotificationDeletedBroadcastReceiver(this);
            IntentFilter deletefilter = new IntentFilter();

            deletefilter.AddAction(ActionNotificationCancelled);
            RegisterReceiver(_notificationDeletedBroadcastReceiver, deletefilter);
        }
예제 #2
0
        public void DisplayAccessNotifications(PwEntryOutput entry, bool closeAfterCreate)
        {
            var hadKeyboardData = ClearNotifications();

            String entryName = entry.OutputStrings.ReadSafe(PwDefs.TitleField);

            ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            var notBuilder = new PasswordAccessNotificationBuilder(this, _notificationManager);
            if (prefs.GetBoolean(GetString(Resource.String.CopyToClipboardNotification_key), Resources.GetBoolean(Resource.Boolean.CopyToClipboardNotification_default)))
            {

                if (entry.OutputStrings.ReadSafe(PwDefs.PasswordField).Length > 0)
                {
                    notBuilder.AddPasswordAccess();

                }

                if (entry.OutputStrings.ReadSafe(PwDefs.UserNameField).Length > 0)
                {
                    notBuilder.AddUsernameAccess();
                }
            }

            bool hasKeyboardDataNow = false;
            if (prefs.GetBoolean(GetString(Resource.String.UseKp2aKeyboard_key), Resources.GetBoolean(Resource.Boolean.UseKp2aKeyboard_default)))
            {

                //keyboard
                hasKeyboardDataNow = MakeAccessibleForKeyboard(entry);
                if (hasKeyboardDataNow)
                {
                    notBuilder.AddKeyboardAccess();
                    if (prefs.GetBoolean("kp2a_switch_rooted", false))
                    {
                        //switch rooted
                        bool onlySwitchOnSearch = prefs.GetBoolean(GetString(Resource.String.OpenKp2aKeyboardAutomaticallyOnlyAfterSearch_key), false);
                        if (closeAfterCreate || (!onlySwitchOnSearch))
                        {
                            ActivateKp2aKeyboard();
                        }
                    }
                    else
                    {
                        //if the app is about to be closed again (e.g. after searching for a URL and returning to the browser:
                        // automatically bring up the Keyboard selection dialog
                        if ((closeAfterCreate) && prefs.GetBoolean(GetString(Resource.String.OpenKp2aKeyboardAutomatically_key), Resources.GetBoolean(Resource.Boolean.OpenKp2aKeyboardAutomatically_default)))
                        {
                            ActivateKp2aKeyboard();
                        }
                    }

                }

            }

            if ((!hasKeyboardDataNow) && (hadKeyboardData))
            {
                ClearKeyboard(true); //this clears again and then (this is the point) broadcasts that we no longer have keyboard data
            }
            _numElementsToWaitFor = notBuilder.CreateNotifications(entryName);

            if (_numElementsToWaitFor == 0)
            {
                StopSelf();
                return;
            }

            IntentFilter filter = new IntentFilter();
            filter.AddAction(Intents.CopyUsername);
            filter.AddAction(Intents.CopyPassword);
            filter.AddAction(Intents.CheckKeyboard);

            //register receiver to get notified when notifications are discarded in which case we can shutdown the service
            _notificationDeletedBroadcastReceiver = new NotificationDeletedBroadcastReceiver(this);
            IntentFilter deletefilter = new IntentFilter();
            deletefilter.AddAction(ActionNotificationCancelled);
            RegisterReceiver(_notificationDeletedBroadcastReceiver, deletefilter);
        }
예제 #3
0
        public void DisplayAccessNotifications(PwEntryOutput entry, bool closeAfterCreate, string searchUrl)
        {
            var hadKeyboardData = ClearNotifications();

            String   entryName = entry.OutputStrings.ReadSafe(PwDefs.TitleField);
            Database db        = App.Kp2a.FindDatabaseForElement(entry.Entry);

            var bmp = Util.DrawableToBitmap(db.DrawableFactory.GetIconDrawable(this,
                                                                               db.KpDatabase, entry.Entry.IconId, entry.Entry.CustomIconUuid, false));


            if (!(((entry.Entry.CustomIconUuid != null) && (!entry.Entry.CustomIconUuid.Equals(PwUuid.Zero)))) &&
                PreferenceManager.GetDefaultSharedPreferences(this).GetString("IconSetKey", PackageName) == PackageName)
            {
                Color drawingColor = new Color(189, 189, 189);
                bmp = Util.ChangeImageColor(bmp, drawingColor);
            }

            Bitmap entryIcon = Util.MakeLargeIcon(bmp, this);

            ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            var notBuilder           = new PasswordAccessNotificationBuilder(this, _notificationManager);

            if (prefs.GetBoolean(GetString(Resource.String.CopyToClipboardNotification_key), Resources.GetBoolean(Resource.Boolean.CopyToClipboardNotification_default)))
            {
                if (entry.OutputStrings.ReadSafe(PwDefs.PasswordField).Length > 0)
                {
                    notBuilder.AddPasswordAccess();
                }

                if (entry.OutputStrings.ReadSafe(PwDefs.UserNameField).Length > 0)
                {
                    notBuilder.AddUsernameAccess();
                }
            }

            bool hasKeyboardDataNow = false;

            if (prefs.GetBoolean(GetString(Resource.String.UseKp2aKeyboard_key), Resources.GetBoolean(Resource.Boolean.UseKp2aKeyboard_default)))
            {
                //keyboard
                hasKeyboardDataNow = MakeAccessibleForKeyboard(entry, searchUrl);
                if (hasKeyboardDataNow)
                {
                    notBuilder.AddKeyboardAccess();
                    if (prefs.GetBoolean("kp2a_switch_rooted", false))
                    {
                        //switch rooted
                        bool onlySwitchOnSearch = prefs.GetBoolean(GetString(Resource.String.OpenKp2aKeyboardAutomaticallyOnlyAfterSearch_key), false);
                        if (closeAfterCreate || (!onlySwitchOnSearch))
                        {
                            ActivateKp2aKeyboard();
                        }
                    }
                    else
                    {
                        //if the app is about to be closed again (e.g. after searching for a URL and returning to the browser:
                        // automatically bring up the Keyboard selection dialog
                        if ((closeAfterCreate) && prefs.GetBoolean(GetString(Resource.String.OpenKp2aKeyboardAutomatically_key), Resources.GetBoolean(Resource.Boolean.OpenKp2aKeyboardAutomatically_default)))
                        {
                            ActivateKp2aKeyboard();
                        }
                    }
                }
            }

            if ((!hasKeyboardDataNow) && (hadKeyboardData))
            {
                ClearKeyboard(true); //this clears again and then (this is the point) broadcasts that we no longer have keyboard data
            }
            _numElementsToWaitFor = notBuilder.CreateNotifications(entryName, entryIcon);

            if (_numElementsToWaitFor == 0)
            {
                StopSelf();
                return;
            }

            //register receiver to get notified when notifications are discarded in which case we can shutdown the service
            _notificationDeletedBroadcastReceiver = new NotificationDeletedBroadcastReceiver(this);
            IntentFilter deletefilter = new IntentFilter();

            deletefilter.AddAction(ActionNotificationCancelled);
            RegisterReceiver(_notificationDeletedBroadcastReceiver, deletefilter);
        }
        public void DisplayAccessNotifications(PwEntryOutput entry, bool closeAfterCreate, string searchUrl)
        {
            var hadKeyboardData = ClearNotifications();

            String entryName = entry.OutputStrings.ReadSafe(PwDefs.TitleField);

            ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            var notBuilder           = new PasswordAccessNotificationBuilder(this, _notificationManager);

            if (prefs.GetBoolean(GetString(Resource.String.CopyToClipboardNotification_key), Resources.GetBoolean(Resource.Boolean.CopyToClipboardNotification_default)))
            {
                if (entry.OutputStrings.ReadSafe(PwDefs.PasswordField).Length > 0)
                {
                    notBuilder.AddPasswordAccess();
                }

                if (entry.OutputStrings.ReadSafe(PwDefs.UserNameField).Length > 0)
                {
                    notBuilder.AddUsernameAccess();
                }
            }

            bool hasKeyboardDataNow = false;

            if (prefs.GetBoolean(GetString(Resource.String.UseKp2aKeyboard_key), Resources.GetBoolean(Resource.Boolean.UseKp2aKeyboard_default)))
            {
                //keyboard
                hasKeyboardDataNow = MakeAccessibleForKeyboard(entry, searchUrl);
                if (hasKeyboardDataNow)
                {
                    notBuilder.AddKeyboardAccess();
                    if (prefs.GetBoolean("kp2a_switch_rooted", false))
                    {
                        //switch rooted
                        bool onlySwitchOnSearch = prefs.GetBoolean(GetString(Resource.String.OpenKp2aKeyboardAutomaticallyOnlyAfterSearch_key), false);
                        if (closeAfterCreate || (!onlySwitchOnSearch))
                        {
                            ActivateKp2aKeyboard();
                        }
                    }
                    else
                    {
                        //if the app is about to be closed again (e.g. after searching for a URL and returning to the browser:
                        // automatically bring up the Keyboard selection dialog
                        if ((closeAfterCreate) && prefs.GetBoolean(GetString(Resource.String.OpenKp2aKeyboardAutomatically_key), Resources.GetBoolean(Resource.Boolean.OpenKp2aKeyboardAutomatically_default)))
                        {
                            ActivateKp2aKeyboard();
                        }
                    }
                }
            }

            if ((!hasKeyboardDataNow) && (hadKeyboardData))
            {
                ClearKeyboard(true);                 //this clears again and then (this is the point) broadcasts that we no longer have keyboard data
            }
            _numElementsToWaitFor = notBuilder.CreateNotifications(entryName);

            if (_numElementsToWaitFor == 0)
            {
                StopSelf();
                return;
            }

            IntentFilter filter = new IntentFilter();

            filter.AddAction(Intents.CopyUsername);
            filter.AddAction(Intents.CopyPassword);
            filter.AddAction(Intents.CheckKeyboard);

            //register receiver to get notified when notifications are discarded in which case we can shutdown the service
            _notificationDeletedBroadcastReceiver = new NotificationDeletedBroadcastReceiver(this);
            IntentFilter deletefilter = new IntentFilter();

            deletefilter.AddAction(ActionNotificationCancelled);
            RegisterReceiver(_notificationDeletedBroadcastReceiver, deletefilter);
        }