using System;
using System.Collections.Generic;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using Android.App;
using System.IO;
using Android.Content;
using Android.OS;
using KeePassLib;
using KeePassLib.Keys;
using KeePassLib.Serialization;
using keepass2android.Io;
using KeePassLib.Interfaces;
#if !NoNet && !EXCLUDE_JAVAFILESTORAGE
using Keepass2android.Javafilestorage;
#endif
namespace keepass2android
{
public interface ICertificateValidationHandler
{
///
/// Handles a failed certificate validation. Returns true if the users wants to continue, false otherwise.
/// see http://msdn.microsoft.com/en-us/library/system.net.icertificatepolicy(v=vs.110).aspx
///
//bool OnServerCertificateError(int certificateProblem);
RemoteCertificateValidationCallback CertificateValidationCallback { get; }
}
///
/// Interface through which Activities and the logic layer can access some app specific functionalities and Application static data
///
/// This also contains methods which are UI specific and should be replacable for testing.
public interface IKp2aApp : ICertificateValidationHandler
{
///
/// Locks all currently open databases, quicklocking if available (unless false is passed for allowQuickUnlock)
///
void Lock(bool allowQuickUnlock, bool lockWasTriggeredByTimeout);
///
/// Loads the specified data as the currently open database, as unlocked.
///
Database LoadDatabase(IOConnectionInfo ioConnectionInfo, MemoryStream memoryStream, CompositeKey compKey, ProgressDialogStatusLogger statusLogger, IDatabaseFormat databaseFormat, bool makeCurrent);
HashSet DirtyGroups { get; }
void MarkAllGroupsAsDirty();
///
/// Returns the current database
///
Database CurrentDb { get; }
IEnumerable OpenDatabases { get; }
void CloseDatabase(Database db);
Database FindDatabaseForElement(IStructureItem element);
///
/// Tell the app that the file from ioc was opened with keyfile.
///
void StoreOpenedFileAsRecent(IOConnectionInfo ioc, string keyfile, bool updateTimestamp, string displayName = "");
///
/// Creates a new database and returns it
///
Database CreateNewDatabase(bool makeCurrent);
///
/// Returns the user-displayable string identified by stringKey
///
string GetResourceString(UiStringKey stringKey);
///
/// Returns the value from the preferences corresponding to key
///
bool GetBooleanPreference(PreferenceKey key);
///
/// Asks the user the question "messageKey" with the options Yes/No/Cancel, calls the handler corresponding to the answer.
///
void AskYesNoCancel(UiStringKey titleKey, UiStringKey messageKey,
EventHandler yesHandler,
EventHandler noHandler,
EventHandler cancelHandler,
Context ctx,
string messageSuffix = "");
///
/// Asks the user the question "messageKey" with the options Yes/No/Cancel, but the yes/no strings can be selected freely, calls the handler corresponding to the answer.
///
void AskYesNoCancel(UiStringKey titleKey, UiStringKey messageKey,
UiStringKey yesString, UiStringKey noString,
EventHandler yesHandler,
EventHandler noHandler,
EventHandler cancelHandler,
Context ctx,
string messageSuffix = "");
///
/// Returns a Handler object which can run tasks on the UI thread
///
Handler UiThreadHandler { get; }
IProgressDialog CreateProgressDialog(Context ctx);
///
/// returns the file storage for the given ioc. might be a caching file storage
///
IFileStorage GetFileStorage(IOConnectionInfo iocInfo);
///
/// returns the file storage for the given ioc. if allowCache=false, no cached file storage is returned
///
IFileStorage GetFileStorage(IOConnectionInfo iocInfo, bool allowCache);
void TriggerReload(Context context, Action actionOnResult /*if not null, called when the user selected yes (true) or no (false)*/);
bool CheckForDuplicateUuids { get; }
#if !NoNet && !EXCLUDE_JAVAFILESTORAGE
ICertificateErrorHandler CertificateErrorHandler { get; }
#endif
}
}