protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (requestCode == RequestCodePluginAccess)
            {
                if (new PluginDatabase(this).HasAcceptedScope(_pluginPackage, _requiredScope))
                {
                    //user granted access. Search for the requested credentials:
                    StartQuery();
                }
                else
                {
                    //user didn't grant access
                    SetResult(Result.Canceled);
                    Finish();
                }
            }
            if (requestCode == RequestCodeQuery)
            {
                if (resultCode == KeePass.ExitCloseAfterTaskComplete)
                {
                    //double check we really have the permission
                    if (!new PluginDatabase(this).HasAcceptedScope(_pluginPackage, _requiredScope))
                    {
                        Kp2aLog.LogUnexpectedError(new Exception("Ohoh! Scope not available, shouldn't get here. Malicious app somewhere?"));
                        SetResult(Result.Canceled);
                        Finish();
                        return;
                    }
                    //return credentials to caller:
                    Intent credentialData = new Intent();
                    PluginHost.AddEntryToIntent(credentialData, App.Kp2a.LastOpenedEntry);
                    credentialData.PutExtra(Strings.ExtraQueryString, _requestedUrl);
                    SetResult(Result.Ok, credentialData);
                    Finish();
                }
                else
                {
                    SetResult(Result.Canceled);
                    Finish();
                }
            }
        }
Пример #2
0
        private void AddPluginAction(string pluginPackage, string fieldId, string popupItemId, string displayText, int iconId, Bundle bundleExtra)
        {
            if (fieldId != null)
            {
                try
                {
                    if (!_popupMenuItems.ContainsKey(fieldId))
                    {
                        Kp2aLog.Log("Did not find field with key " + fieldId);
                        return;
                    }
                    //create a new popup item for the plugin action:
                    var newPopup = new PluginPopupMenuItem(this, pluginPackage, fieldId, popupItemId, displayText, iconId, bundleExtra);
                    //see if we already have a popup item for this field with the same item id
                    var popupsForField = _popupMenuItems[fieldId];
                    var popupItemPos   = popupsForField.FindIndex(0,
                                                                  item =>
                                                                  (item is PluginPopupMenuItem) &&
                                                                  ((PluginPopupMenuItem)item).PopupItemId == popupItemId);

                    //replace existing or add
                    if (popupItemPos >= 0)
                    {
                        popupsForField[popupItemPos] = newPopup;
                    }
                    else
                    {
                        popupsForField.Add(newPopup);
                    }
                }
                catch (Exception e)
                {
                    Kp2aLog.LogUnexpectedError(e);
                }
            }
            else
            {
                //we need to add an option to the  menu.
                //As it is not sure that OnCreateOptionsMenu was called yet, we cannot access _menu without a check:

                Intent i = new Intent(Strings.ActionEntryActionSelected);
                i.SetPackage(pluginPackage);
                i.PutExtra(Strings.ExtraActionData, bundleExtra);
                i.PutExtra(Strings.ExtraSender, PackageName);
                PluginHost.AddEntryToIntent(i, App.Kp2a.GetDb().LastOpenedEntry);

                var menuOption = new PluginMenuOption()
                {
                    DisplayText = displayText,
                    Icon        = PackageManager.GetResourcesForApplication(pluginPackage).GetDrawable(iconId),
                    Intent      = i
                };

                if (_menu != null)
                {
                    AddMenuOption(menuOption);
                }
                else
                {
                    lock (_pendingMenuOptions)
                    {
                        _pendingMenuOptions.Add(menuOption);
                    }
                }
            }
        }
Пример #3
0
 public void AddEntryToIntent(Intent intent)
 {
     PluginHost.AddEntryToIntent(intent, App.Kp2a.GetDb().LastOpenedEntry);
 }