private void MoveDbToInternalFolder()
        {
            Func <Action> copyAndReturnPostExecute = () =>
            {
                try
                {
                    var sourceIoc = App.Kp2a.GetDb().Ioc;
                    var newIoc    = ImportFileToInternalDirectory(sourceIoc);
                    return(() =>
                    {
                        var builder = new AlertDialog.Builder(Activity);
                        builder
                        .SetMessage(Resource.String.DatabaseFileMoved);
                        builder.SetPositiveButton(Android.Resource.String.Ok, (sender, args) =>
                                                  PasswordActivity.Launch(Activity, newIoc, new NullTask()));
                        builder.Show();
                    });
                }
                catch (Exception e)
                {
                    return(() =>
                    {
                        Toast.MakeText(Activity, App.Kp2a.GetResourceString(UiStringKey.ErrorOcurred) + " " + e.Message, ToastLength.Long).Show();
                    });
                }
            };

            new SimpleLoadingDialog(Activity, GetString(Resource.String.CopyingFile), false,
                                    copyAndReturnPostExecute
                                    ).Execute();
        }
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            //update app task.
            //this is important even if we're about to close, because then we should get a NullTask here
            //in order not to do the same task next time again!
            AppTask.TryGetFromActivityResult(data, ref AppTask);

            if (resultCode == KeePass.ExitCloseAfterTaskComplete)
            {
                //no need to set the result ExitCloseAfterTaskComplete here, there's no parent Activity on the stack
                Finish();
                return;
            }

            FillData();


            if (resultCode == (Result)FileStorageResults.FileUsagePrepared)
            {
                IOConnectionInfo ioc = new IOConnectionInfo();
                PasswordActivity.SetIoConnectionFromIntent(ioc, data);
                LaunchPasswordActivityForIoc(ioc);
            }

            if ((resultCode == Result.Ok) && (requestCode == RequestCodeSelectIoc))
            {
                IOConnectionInfo ioc = new IOConnectionInfo();
                PasswordActivity.SetIoConnectionFromIntent(ioc, data);
                LaunchPasswordActivityForIoc(ioc);
            }
        }
示例#3
0
        protected override void OnCreate(Bundle bundle)
        {
            _design.ApplyTheme();
            base.OnCreate(bundle);


            SetContentView(Resource.Layout.file_storage_setup);

            Ioc = new IOConnectionInfo();
            PasswordActivity.SetIoConnectionFromIntent(Ioc, Intent);

            Kp2aLog.Log("FSSA.OnCreate with " + Ioc.Path);

            ProcessName = Intent.GetStringExtra(FileStorageSetupDefs.ExtraProcessName);
            IsForSave   = Intent.GetBooleanExtra(FileStorageSetupDefs.ExtraIsForSave, false);
            if (bundle == null)
            {
                State = new Bundle();
            }
            else
            {
                State        = (Bundle)bundle.Clone();
                _isRecreated = true;
            }

            if (!_isRecreated)
            {
                App.Kp2a.GetFileStorage(Ioc).OnCreate(this, bundle);
            }
        }
示例#4
0
        public override void AfterUnlockDatabase(PasswordActivity act)
        {
            if (String.IsNullOrEmpty(UrlToSearchFor))
            {
                GroupActivity.Launch(act, new SelectEntryTask()
                {
                    ShowUserNotifications = ShowUserNotifications
                });
            }
            else
            {
                ShareUrlResults.Launch(act, this);
            }


            //removed. this causes an issue in the following workflow:
            //When the user wants to find an entry for a URL but has the wrong database open he needs
            //to switch to another database. But the Task is removed already the first time when going through PasswordActivity
            // (with the wrong db).
            //Then after switching to the right database, the task is gone.

            //A reason this code existed was the following workflow:
            //Using Chrome browser (with NEW_TASK flag for ActionSend): Share URL -> KP2A.
            //Now the AppTask was in PasswordActivity and didn't get out of it.
            //This is now solved by returning new tasks in ActivityResult.

            //RemoveTaskFromIntent(act);
            //act.AppTask = new NullTask();
        }
示例#5
0
        protected override void ReturnOk(IOConnectionInfo ioc)
        {
            Intent intent = new Intent();

            PasswordActivity.PutIoConnectionToIntent(ioc, intent);
            SetResult(Result.Ok, intent);
            Finish();
        }
示例#6
0
        public void StartFileUsageProcess(IOConnectionInfo ioc, int requestCode, bool alwaysReturnSuccess)
        {
            Intent fileStorageSetupIntent = new Intent(_activity, typeof(FileStorageSetupActivity));

            fileStorageSetupIntent.PutExtra(FileStorageSetupDefs.ExtraProcessName, FileStorageSetupDefs.ProcessNameFileUsageSetup);
            fileStorageSetupIntent.PutExtra(FileStorageSetupDefs.ExtraAlwaysReturnSuccess, alwaysReturnSuccess);
            PasswordActivity.PutIoConnectionToIntent(ioc, fileStorageSetupIntent);

            _activity.StartActivityForResult(fileStorageSetupIntent, requestCode);
        }
示例#7
0
        public void StartSelectFileProcess(IOConnectionInfo ioc, bool isForSave, int requestCode)
        {
            Kp2aLog.Log("FSSIA: StartSelectFileProcess " + ioc.Path);
            Intent fileStorageSetupIntent = new Intent(_activity, typeof(FileStorageSetupActivity));

            fileStorageSetupIntent.PutExtra(FileStorageSetupDefs.ExtraProcessName, FileStorageSetupDefs.ProcessNameSelectfile);
            fileStorageSetupIntent.PutExtra(FileStorageSetupDefs.ExtraIsForSave, isForSave);
            PasswordActivity.PutIoConnectionToIntent(ioc, fileStorageSetupIntent);

            _activity.StartActivityForResult(fileStorageSetupIntent, requestCode);
        }
示例#8
0
        void LaunchPasswordActivityForIoc(IOConnectionInfo ioc)
        {
            IFileStorage fileStorage = App.Kp2a.GetFileStorage(ioc);

            if (fileStorage.RequiresCredentials(ioc))
            {
                Util.QueryCredentials(ioc, AfterQueryCredentials, this);
            }
            else
            {
                try
                {
                    PasswordActivity.Launch(this, ioc, new ActivityLaunchModeForward(), Intent.GetBooleanExtra("MakeCurrent", true));
                    Finish();
                } catch (Java.IO.FileNotFoundException)
                {
                    Toast.MakeText(this, Resource.String.FileNotFound, ToastLength.Long).Show();
                }
            }
        }
示例#9
0
        private void LaunchNextActivity()
        {
            if (!App.Kp2a.GetDb().Loaded)
            {
                // Load default database
                ISharedPreferences prefs           = Android.Preferences.PreferenceManager.GetDefaultSharedPreferences(this);
                String             defaultFileName = prefs.GetString(PasswordActivity.KeyDefaultFilename, "");

                if (defaultFileName.Length > 0)
                {
                    try
                    {
                        PasswordActivity.Launch(this, LoadIoc(defaultFileName), _appTask);
                        Finish();
                        return;
                    }
                    catch (Exception e)
                    {
                        Toast.MakeText(this, e.Message, ToastLength.Long);
                        // Ignore exception
                    }
                }
            }
            else
            {
                PasswordActivity.Launch(this, App.Kp2a.GetDb().Ioc, _appTask);
                Finish();
                return;
            }

            Intent intent = new Intent(this, typeof(FileSelectActivity));

            _appTask.ToIntent(intent);
            intent.AddFlags(ActivityFlags.ForwardResult);
            StartActivity(intent);
            Finish();
        }
示例#10
0
 public virtual void AfterUnlockDatabase(PasswordActivity act)
 {
     GroupActivity.Launch(act, this);
 }
示例#11
0
 private void AfterQueryCredentials(IOConnectionInfo ioc)
 {
     PasswordActivity.Launch(this, ioc, new ActivityLaunchModeForward(), Intent.GetBooleanExtra("MakeCurrent", true));
     Finish();
 }
 private void AfterQueryCredentials(IOConnectionInfo ioc)
 {
     PasswordActivity.Launch(this, ioc, new ActivityLaunchModeForward());
     Finish();
 }
示例#13
0
 protected override void SetIoConnectionFromIntent(IOConnectionInfo ioc, Intent data)
 {
     PasswordActivity.SetIoConnectionFromIntent(ioc, data);
 }
示例#14
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (resultCode == KeePass.ResultOkPasswordGenerator)
            {
                String generatedPassword = data.GetStringExtra("keepass2android.password.generated_password");
                FindViewById <TextView>(Resource.Id.entry_password).Text     = generatedPassword;
                FindViewById <TextView>(Resource.Id.entry_confpassword).Text = generatedPassword;
            }

            if (resultCode == KeePass.ExitFileStorageSelectionOk)
            {
                string protocolId = data.GetStringExtra("protocolId");
                if (protocolId == "content")
                {
                    Util.ShowBrowseDialog(this, RequestCodeDbFilename, true, true);
                }
                else
                {
                    FileSelectHelper fileSelectHelper = new FileSelectHelper(this, true, RequestCodeDbFilename)
                    {
                        DefaultExtension = "kdbx"
                    };
                    fileSelectHelper.OnOpen += (sender, info) =>
                    {
                        _ioc = info;
                        UpdateIocView();
                    };
                    App.Kp2a.GetFileStorage(protocolId).StartSelectFile(
                        new FileStorageSetupInitiatorActivity(this, OnActivityResult, s => fileSelectHelper.PerformManualFileSelect(s)),
                        true,
                        RequestCodeDbFilename,
                        protocolId);
                }
            }

            if (resultCode == Result.Ok)
            {
                if (requestCode == RequestCodeKeyFile)
                {
                    if (data.Data.Scheme == "content")
                    {
                        if ((int)Build.VERSION.SdkInt >= 19)
                        {
                            //try to take persistable permissions
                            try
                            {
                                Kp2aLog.Log("TakePersistableUriPermission");
                                var takeFlags = data.Flags
                                                & (ActivityFlags.GrantReadUriPermission
                                                   | ActivityFlags.GrantWriteUriPermission);
                                this.ContentResolver.TakePersistableUriPermission(data.Data, takeFlags);
                            }
                            catch (Exception e)
                            {
                                Kp2aLog.Log(e.ToString());
                            }
                        }
                    }


                    string filename = Util.IntentToFilename(data, this);
                    if (filename == null)
                    {
                        filename = data.DataString;
                    }


                    _keyfileFilename = ConvertFilenameToIocPath(filename);
                    FindViewById <TextView>(Resource.Id.keyfile_filename).Text = _keyfileFilename;
                    FindViewById(Resource.Id.keyfile_filename).Visibility      = ViewStates.Visible;
                }
                if (requestCode == RequestCodeDbFilename)
                {
                    if (data.Data.Scheme == "content")
                    {
                        if ((int)Build.VERSION.SdkInt >= 19)
                        {
                            //try to take persistable permissions
                            try
                            {
                                Kp2aLog.Log("TakePersistableUriPermission");
                                var takeFlags = data.Flags
                                                & (ActivityFlags.GrantReadUriPermission
                                                   | ActivityFlags.GrantWriteUriPermission);
                                this.ContentResolver.TakePersistableUriPermission(data.Data, takeFlags);
                            }
                            catch (Exception e)
                            {
                                Kp2aLog.Log(e.ToString());
                            }
                        }
                    }


                    string filename = Util.IntentToFilename(data, this);
                    if (filename == null)
                    {
                        filename = data.DataString;
                    }

                    bool fileExists = data.GetBooleanExtra("group.pals.android.lib.ui.filechooser.FileChooserActivity.result_file_exists", true);

                    if (fileExists)
                    {
                        _ioc = new IOConnectionInfo {
                            Path = ConvertFilenameToIocPath(filename)
                        };
                        UpdateIocView();
                    }
                    else
                    {
                        var task = new CreateNewFilename(new ActionOnFinish((success, messageOrFilename) =>
                        {
                            if (!success)
                            {
                                Toast.MakeText(this, messageOrFilename, ToastLength.Long).Show();
                                return;
                            }
                            _ioc = new IOConnectionInfo {
                                Path = ConvertFilenameToIocPath(messageOrFilename)
                            };
                            UpdateIocView();
                        }), filename);

                        new ProgressTask(App.Kp2a, this, task).Run();
                    }
                }
            }
            if (resultCode == (Result)FileStorageResults.FileUsagePrepared)
            {
                _ioc = new IOConnectionInfo();
                PasswordActivity.SetIoConnectionFromIntent(_ioc, data);
                UpdateIocView();
            }
            if (resultCode == (Result)FileStorageResults.FileChooserPrepared)
            {
                IOConnectionInfo ioc = new IOConnectionInfo();
                PasswordActivity.SetIoConnectionFromIntent(ioc, data);

                new FileSelectHelper(this, true, RequestCodeDbFilename)
                {
                    DefaultExtension = "kdbx"
                }
                .StartFileChooser(ioc.Path);
            }
        }
示例#15
0
 public void IocToIntent(Intent intent, IOConnectionInfo ioc)
 {
     PasswordActivity.PutIoConnectionToIntent(ioc, intent);
 }
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (resultCode == KeePass.ExitFileStorageSelectionOk)
            {
                string protocolId = data.GetStringExtra("protocolId");
                if (protocolId == "content")
                {
                    Util.ShowBrowseDialog(this, RequestCodeDbFilename, true, true);
                }
                else
                {
                    FileSelectHelper fileSelectHelper = new FileSelectHelper(this, true, RequestCodeDbFilename)
                    {
                        DefaultExtension = _ffp[_fileFormatIndex].DefaultExtension
                    };
                    fileSelectHelper.OnOpen += (sender, ioc) =>
                    {
                        ExportTo(ioc);
                    };
                    App.Kp2a.GetFileStorage(protocolId).StartSelectFile(
                        new FileStorageSetupInitiatorActivity(this, OnActivityResult, s => fileSelectHelper.PerformManualFileSelect(s)),
                        true,
                        RequestCodeDbFilename,
                        protocolId);
                }
                return;
            }

            if (resultCode == Result.Ok)
            {
                if (requestCode == RequestCodeDbFilename)
                {
                    if (data.Data.Scheme == "content")
                    {
                        if ((int)Android.OS.Build.VERSION.SdkInt >= 19)
                        {
                            //try to take persistable permissions
                            try
                            {
                                Kp2aLog.Log("TakePersistableUriPermission");
                                var takeFlags = data.Flags
                                                & (ActivityFlags.GrantReadUriPermission
                                                   | ActivityFlags.GrantWriteUriPermission);
                                this.ContentResolver.TakePersistableUriPermission(data.Data, takeFlags);
                            }
                            catch (Exception e)
                            {
                                Kp2aLog.Log(e.ToString());
                            }
                        }
                    }


                    string filename = Util.IntentToFilename(data, this);
                    if (filename == null)
                    {
                        filename = data.DataString;
                    }

                    bool fileExists = data.GetBooleanExtra("group.pals.android.lib.ui.filechooser.FileChooserActivity.result_file_exists", true);

                    if (fileExists)
                    {
                        ExportTo(new IOConnectionInfo {
                            Path = ConvertFilenameToIocPath(filename)
                        });
                    }
                    else
                    {
                        var task = new CreateNewFilename(new ActionOnFinish((success, messageOrFilename) =>
                        {
                            if (!success)
                            {
                                Toast.MakeText(this, messageOrFilename, ToastLength.Long).Show();
                                return;
                            }
                            ExportTo(new IOConnectionInfo {
                                Path = ConvertFilenameToIocPath(messageOrFilename)
                            });
                        }), filename);

                        new ProgressTask(App.Kp2a, this, task).Run();
                    }

                    return;
                }
            }
            if (resultCode == (Result)FileStorageResults.FileUsagePrepared)
            {
                var ioc = new IOConnectionInfo();
                PasswordActivity.SetIoConnectionFromIntent(ioc, data);
                ExportTo(ioc);
                return;
            }
            if (resultCode == (Result)FileStorageResults.FileChooserPrepared)
            {
                IOConnectionInfo ioc = new IOConnectionInfo();
                PasswordActivity.SetIoConnectionFromIntent(ioc, data);
                new FileSelectHelper(this, true, RequestCodeDbFilename)
                {
                    DefaultExtension = _ffp[_fileFormatIndex].DefaultExtension
                }
                .StartFileChooser(ioc.Path);
                return;
            }
            Finish();
        }
示例#17
0
        public static bool AutoOpenEntry(Activity activity, AutoExecItem item, bool bManual,
                                         ActivityLaunchMode launchMode)
        {
            string           str;
            PwEntry          pe       = item.Entry;
            SprContext       ctxNoEsc = new SprContext(pe, item.Database, SprCompileFlags.All);
            IOConnectionInfo ioc;

            if (!TryGetDatabaseIoc(item, out ioc))
            {
                return(false);
            }

            var ob = GetBoolEx(pe, "SkipIfNotExists", ctxNoEsc);

            if (!ob.HasValue) // Backw. compat.
            {
                ob = GetBoolEx(pe, "Skip if not exists", ctxNoEsc);
            }
            if (ob.HasValue && ob.Value)
            {
                if (!CheckFileExsts(ioc))
                {
                    return(false);
                }
            }

            CompositeKey ck = new CompositeKey();

            if (GetString(pe, PwDefs.PasswordField, ctxNoEsc, false, out str))
            {
                ck.AddUserKey(new KcpPassword(str));
            }

            if (GetString(pe, PwDefs.UserNameField, ctxNoEsc, false, out str))
            {
                string           strAbs = str;
                IOConnectionInfo iocKey = IOConnectionInfo.FromPath(strAbs);
                if (iocKey.IsLocalFile() && !UrlUtil.IsAbsolutePath(strAbs))
                {
                    //local relative paths not supported on Android
                    return(false);
                }


                ob = GetBoolEx(pe, "SkipIfKeyFileNotExists", ctxNoEsc);
                if (ob.HasValue && ob.Value)
                {
                    IOConnectionInfo iocKeyAbs = IOConnectionInfo.FromPath(strAbs);
                    if (!CheckFileExsts(iocKeyAbs))
                    {
                        return(false);
                    }
                }

                try { ck.AddUserKey(new KcpKeyFile(strAbs)); }
                catch (InvalidOperationException)
                {
                    Toast.MakeText(Application.Context, Resource.String.error_adding_keyfile, ToastLength.Long).Show();
                    return(false);
                }
                catch (Exception) { throw; }
            }
            else // Try getting key file from attachments
            {
                ProtectedBinary pBin = pe.Binaries.Get("KeyFile.bin");
                if (pBin != null)
                {
                    ck.AddUserKey(new KcpKeyFile(IOConnectionInfo.FromPath(
                                                     StrUtil.DataToDataUri(pBin.ReadData(), null))));
                }
            }

            GetString(pe, "Focus", ctxNoEsc, true, out str);
            bool bRestoreFocus = str.Equals("Restore", StrUtil.CaseIgnoreCmp);

            PasswordActivity.Launch(activity, ioc, ck, launchMode, !
                                    bRestoreFocus);

            App.Kp2a.RegisterChildDatabase(ioc);

            return(true);
        }
示例#18
0
 private void AfterQueryCredentials(IOConnectionInfo ioc)
 {
     PasswordActivity.Launch(this, ioc, AppTask);
     Finish();
 }
示例#19
0
 private void LaunchPasswordActivityForReload(IOConnectionInfo ioc, CompositeKey compositeKey)
 {
     LaunchingOther = true;
     PasswordActivity.Launch(this, ioc, compositeKey, new ActivityLaunchModeRequestCode(ReqCodeOpenNewDb), false);
 }