Beispiel #1
0
        protected override void OnResume()
        {
            base.OnResume();
            if (!IsFinishing && !LaunchingOther)
            {
                if (App.Kp2a.OpenDatabases.Any() == false)
                {
                    StartFileSelect();
                    return;
                }

                //database loaded
                if (App.Kp2a.QuickLocked)
                {
                    var i = new Intent(this, typeof(QuickUnlock));
                    Util.PutIoConnectionToIntent(App.Kp2a.GetDbForQuickUnlock().Ioc, i);
                    Kp2aLog.Log("Starting QuickUnlock");
                    StartActivityForResult(i, 0);
                    return;
                }

                //database(s) unlocked
                if (App.Kp2a.OpenDatabases.Count() == 1)
                {
                    LaunchingOther = true;
                    AppTask.LaunchFirstGroupActivity(this);
                    return;
                }

                //more than one database open or user requested to load another db. Don't launch another activity.
                _adapter.Update();
                _adapter.NotifyDataSetChanged();
            }
            base.OnResume();
        }
Beispiel #2
0
        private bool GetIocFromViewIntent(Intent intent)
        {
            IOConnectionInfo ioc = new IOConnectionInfo();

            //started from "view" intent (e.g. from file browser)
            ioc.Path = intent.DataString;

            if (ioc.Path.StartsWith("file://"))
            {
                ioc.Path = URLDecoder.Decode(ioc.Path.Substring(7));

                if (ioc.Path.Length == 0)
                {
                    // No file name
                    Toast.MakeText(this, Resource.String.FileNotFound, ToastLength.Long).Show();
                    return(false);
                }

                File dbFile = new File(ioc.Path);
                if (!dbFile.Exists())
                {
                    // File does not exist
                    Toast.MakeText(this, Resource.String.FileNotFound, ToastLength.Long).Show();
                    return(false);
                }
            }
            else
            {
                if (!ioc.Path.StartsWith("content://"))
                {
                    Toast.MakeText(this, Resource.String.error_can_not_handle_uri, ToastLength.Long).Show();
                    return(false);
                }
                IoUtil.TryTakePersistablePermissions(this.ContentResolver, intent.Data);
            }

            if (App.Kp2a.TrySelectCurrentDb(ioc))
            {
                if (OpenAutoExecEntries(App.Kp2a.CurrentDb))
                {
                    return(false);
                }
                LaunchingOther = true;
                AppTask.CanActivateSearchViewOnStart = true;
                AppTask.LaunchFirstGroupActivity(this);
            }
            else
            {
                Intent launchIntent = new Intent(this, typeof(PasswordActivity));
                Util.PutIoConnectionToIntent(ioc, launchIntent);
                LaunchingOther = true;
                StartActivityForResult(launchIntent, ReqCodeOpenNewDb);
            }


            return(true);
        }
Beispiel #3
0
        protected override void OnResume()
        {
            _isForeground = true;
            base.OnResume();
            if (!IsFinishing && !LaunchingOther)
            {
                if (App.Kp2a.OpenDatabases.Any() == false)
                {
                    StartFileSelect(true);
                    return;
                }

                //database loaded
                if (App.Kp2a.QuickLocked)
                {
                    AppTask.CanActivateSearchViewOnStart = true;
                    var i = new Intent(this, typeof(QuickUnlock));
                    Util.PutIoConnectionToIntent(App.Kp2a.GetDbForQuickUnlock().Ioc, i);
                    Kp2aLog.Log("Starting QuickUnlock");
                    StartActivityForResult(i, 0);
                    return;
                }

                //see if there are any AutoOpen items to open

                foreach (var db in App.Kp2a.OpenDatabases)
                {
                    try
                    {
                        if (OpenAutoExecEntries(db))
                        {
                            return;
                        }
                    }
                    catch (Exception e)
                    {
                        Toast.MakeText(this, "Failed to open child databases", ToastLength.Long).Show();
                        Kp2aLog.LogUnexpectedError(e);
                    }
                }

                //database(s) unlocked
                if ((App.Kp2a.OpenDatabases.Count() == 1) || (AppTask is SearchUrlTask))
                {
                    LaunchingOther = true;
                    AppTask.LaunchFirstGroupActivity(this);
                    return;
                }
            }

            //more than one database open or user requested to load another db. Don't launch another activity.
            _adapter.Update();
            _adapter.NotifyDataSetChanged();

            base.OnResume();
        }
Beispiel #4
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            Kp2aLog.Log("StackBaseActivity.OnActivityResult " + resultCode + "/" + requestCode);

            AppTask.TryGetFromActivityResult(data, ref AppTask);

            if (requestCode == ReqCodeOpenNewDb)
            {
                switch ((int)resultCode)
                {
                case (int)Result.Ok:

                    string           iocString = data?.GetStringExtra("ioc");
                    IOConnectionInfo ioc       = IOConnectionInfo.UnserializeFromString(iocString);
                    if (App.Kp2a.TrySelectCurrentDb(ioc))
                    {
                        if (OpenAutoExecEntries(App.Kp2a.CurrentDb))
                        {
                            return;
                        }
                        LaunchingOther = true;
                        AppTask.CanActivateSearchViewOnStart = true;
                        AppTask.LaunchFirstGroupActivity(this);
                    }


                    break;

                case PasswordActivity.ResultSelectOtherFile:
                    StartFileSelect(true, true);
                    break;

                case (int)Result.Canceled:
                    if (App.Kp2a.OpenDatabases.Any() == false)
                    {
                        //don't open fileselect/password activity again
                        OnBackPressed();
                    }
                    break;

                default:
                    break;
                }

                return;
            }

            switch (resultCode)
            {
            case KeePass.ExitNormal:     // Returned to this screen using the Back key
                if (App.Kp2a.OpenDatabases.Count() == 1)
                {
                    OnBackPressed();
                }
                break;

            case KeePass.ExitLock:
                // The database has already been locked, and the quick unlock screen will be shown if appropriate
                break;

            case KeePass.ExitCloseAfterTaskComplete:
                // Do not lock the database
                SetResult(KeePass.ExitCloseAfterTaskComplete);
                Finish();
                break;

            case KeePass.ExitClose:
                SetResult(KeePass.ExitClose);
                Finish();
                break;

            case KeePass.ExitReloadDb:

                if (App.Kp2a.CurrentDb != null)
                {
                    //remember the composite key for reloading:
                    var compositeKey = App.Kp2a.CurrentDb.KpDatabase.MasterKey;
                    var ioc          = App.Kp2a.CurrentDb.Ioc;

                    //lock the database:
                    App.Kp2a.CloseDatabase(App.Kp2a.CurrentDb);

                    LaunchPasswordActivityForReload(ioc, compositeKey);
                }

                break;

            case KeePass.ExitLoadAnotherDb:
                StartFileSelect(true, true);
                break;
            }
        }
Beispiel #5
0
 private void OnDatabaseSelected(Database selectedDatabase)
 {
     App.Kp2a.CurrentDb = selectedDatabase;
     LaunchingOther     = true;
     AppTask.LaunchFirstGroupActivity(this);
 }
Beispiel #6
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            Kp2aLog.Log("StackBaseActivity.OnActivityResult " + resultCode + "/" + requestCode);

            AppTask.TryGetFromActivityResult(data, ref AppTask);

            if (requestCode == ReqCodeOpenNewDb)
            {
                switch ((int)resultCode)
                {
                case (int)Result.Ok:

                    string           iocString = data?.GetStringExtra("ioc");
                    IOConnectionInfo ioc       = IOConnectionInfo.UnserializeFromString(iocString);
                    if (App.Kp2a.TrySelectCurrentDb(ioc))
                    {
                        if (OpenAutoExecEntries(App.Kp2a.CurrentDb))
                        {
                            return;
                        }
                        LaunchingOther = true;
                        AppTask.CanActivateSearchViewOnStart = true;
                        AppTask.LaunchFirstGroupActivity(this);
                    }


                    break;

                case PasswordActivity.ResultSelectOtherFile:
                    StartFileSelect(true, true);
                    break;

                case (int)Result.Canceled:
                    if (App.Kp2a.OpenDatabases.Any() == false)
                    {
                        //don't open fileselect/password activity again
                        OnBackPressed();
                    }
                    break;

                default:
                    break;
                }

                return;
            }

            switch (resultCode)
            {
            case KeePass.ExitNormal:     // Returned to this screen using the Back key
                if (App.Kp2a.OpenDatabases.Count() == 1)
                {
                    OnBackPressed();
                }
                break;

            case KeePass.ExitLock:
                // The database has already been locked. No need to immediately return to quick unlock. Especially as this causes trouble for users with face unlock
                // (db immediately unlocked again) and confused some users as the biometric prompt seemed to disable the device back button or at least they didn't understand
                // why they should unlock...
                SetResult(KeePass.ExitClose);
                if (!IsFinishing)
                {
                    Finish();
                }
                break;

            case KeePass.ExitLockByTimeout:
                //don't finish, bring up QuickUnlock
                break;

            case KeePass.ExitCloseAfterTaskComplete:
                // Do not lock the database
                SetResult(KeePass.ExitCloseAfterTaskComplete);
                if (!IsFinishing)
                {
                    Finish();
                }
                break;

            case KeePass.ExitClose:
                SetResult(KeePass.ExitClose);
                if (!IsFinishing)
                {
                    Finish();
                }
                break;

            case KeePass.ExitReloadDb:

                if (App.Kp2a.CurrentDb != null)
                {
                    //remember the composite key for reloading:
                    var compositeKey = App.Kp2a.CurrentDb.KpDatabase.MasterKey;
                    var ioc          = App.Kp2a.CurrentDb.Ioc;

                    //lock the database:
                    App.Kp2a.CloseDatabase(App.Kp2a.CurrentDb);

                    LaunchPasswordActivityForReload(ioc, compositeKey);
                }

                break;

            case KeePass.ExitLoadAnotherDb:
                StartFileSelect(true, true);
                break;
            }
        }
Beispiel #7
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.open_db_selection);

            var toolbar = FindViewById <AndroidX.AppCompat.Widget.Toolbar>(Resource.Id.mytoolbar);

            SetSupportActionBar(toolbar);

            SupportActionBar.Title = GetString(Resource.String.select_database);


            //only load the AppTask if this is the "first" OnCreate (not because of kill/resume, i.e. savedInstanceState==null)
            // and if the activity is not launched from history (i.e. recent tasks) because this would mean that
            // the Activity was closed already (user cancelling the task or task complete) but is restarted due recent tasks.
            // Don't re-start the task (especially bad if tak was complete already)
            if (Intent.Flags.HasFlag(ActivityFlags.LaunchedFromHistory))
            {
                AppTask = new NullTask();
            }
            else
            {
                AppTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent);
            }

            _adapter = new OpenDatabaseAdapter(this);
            var gridView = FindViewById <GridView>(Resource.Id.gridview);

            gridView.Adapter = _adapter;

            if (!string.IsNullOrEmpty(Intent.GetStringExtra(Util.KeyFilename)))
            {
                IOConnectionInfo ioc = new IOConnectionInfo();
                Util.SetIoConnectionFromIntent(ioc, Intent);

                if (App.Kp2a.TrySelectCurrentDb(ioc))
                {
                    if (!OpenAutoExecEntries(App.Kp2a.CurrentDb))
                    {
                        LaunchingOther = true;
                        AppTask.CanActivateSearchViewOnStart = true;
                        AppTask.LaunchFirstGroupActivity(this);
                    }
                }
                else
                {
                    //forward to password activity
                    Intent i = new Intent(this, typeof(PasswordActivity));
                    Util.PutIoConnectionToIntent(ioc, i);
                    i.PutExtra(PasswordActivity.KeyKeyfile, Intent.GetStringExtra(PasswordActivity.KeyKeyfile));
                    i.PutExtra(PasswordActivity.KeyPassword, Intent.GetStringExtra(PasswordActivity.KeyPassword));
                    i.PutExtra(PasswordActivity.LaunchImmediately, Intent.GetBooleanExtra(PasswordActivity.LaunchImmediately, false));
                    LaunchingOther = true;
                    StartActivityForResult(i, ReqCodeOpenNewDb);
                }
            }
            else
            {
                if (Intent.Action == Intent.ActionView)
                {
                    GetIocFromViewIntent(Intent);
                }
                else if (Intent.Action == Intent.ActionSend)
                {
                    AppTask = new SearchUrlTask {
                        UrlToSearchFor = Intent.GetStringExtra(Intent.ExtraText)
                    };
                }
            }
        }