Search in sources :

Example 6 with Database

use of com.keepassdroid.database.Database in project KeePassDX by Kunzisoft.

the class PasswordActivity method loadDatabase.

private void loadDatabase(String pass, Uri keyfile) {
    // Clear before we load
    Database db = App.getDB();
    db.clear();
    // Clear the shutdown flag
    App.clearShutdown();
    Handler handler = new Handler();
    AfterLoad afterLoad = new AfterLoad(handler, db);
    LoadDB task = new LoadDB(db, PasswordActivity.this, mDbUri, pass, keyfile, afterLoad);
    ProgressTask pt = new ProgressTask(PasswordActivity.this, task, R.string.loading_database);
    pt.run();
}
Also used : ProgressTask(com.keepassdroid.tasks.ProgressTask) Database(com.keepassdroid.database.Database) Handler(android.os.Handler) LoadDB(com.keepassdroid.database.edit.LoadDB)

Example 7 with Database

use of com.keepassdroid.database.Database in project KeePassDX by Kunzisoft.

the class NestedSettingsFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    int key = getArguments().getInt(TAG_KEY);
    // Load the preferences from an XML resource
    switch(key) {
        case NESTED_SCREEN_APP_KEY:
            setPreferencesFromResource(R.xml.app_preferences, rootKey);
            Preference keyFile = findPreference(getString(R.string.keyfile_key));
            keyFile.setOnPreferenceChangeListener((preference, newValue) -> {
                Boolean value = (Boolean) newValue;
                if (!value) {
                    App.getFileHistory().deleteAllKeys();
                }
                return true;
            });
            Preference recentHistory = findPreference(getString(R.string.recentfile_key));
            recentHistory.setOnPreferenceChangeListener((preference, newValue) -> {
                Boolean value = (Boolean) newValue;
                if (value == null) {
                    value = true;
                }
                if (!value) {
                    App.getFileHistory().deleteAll();
                }
                return true;
            });
            Preference stylePreference = findPreference(getString(R.string.setting_style_key));
            stylePreference.setOnPreferenceChangeListener((preference, newValue) -> {
                String styleString = (String) newValue;
                Stylish.assignStyle(getActivity(), styleString);
                getActivity().recreate();
                return true;
            });
            SwitchPreference fingerprintEnablePreference = (SwitchPreference) findPreference(getString(R.string.fingerprint_enable_key));
            // < M solve verifyError exception
            boolean fingerprintSupported = false;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
                fingerprintSupported = FingerPrintHelper.isFingerprintSupported(FingerprintManagerCompat.from(getContext()));
            if (!fingerprintSupported) {
                // False if under Marshmallow
                fingerprintEnablePreference.setChecked(false);
                fingerprintEnablePreference.setOnPreferenceClickListener(preference -> {
                    FragmentManager fragmentManager = getFragmentManager();
                    assert fragmentManager != null;
                    ((SwitchPreference) preference).setChecked(false);
                    UnavailableFeatureDialogFragment.getInstance(Build.VERSION_CODES.M).show(getFragmentManager(), "unavailableFeatureDialog");
                    return false;
                });
            }
            Preference deleteKeysFingerprints = findPreference(getString(R.string.fingerprint_delete_all_key));
            if (!fingerprintSupported) {
                deleteKeysFingerprints.setEnabled(false);
            } else {
                deleteKeysFingerprints.setOnPreferenceClickListener(preference -> {
                    new AlertDialog.Builder(getContext()).setMessage(getResources().getString(R.string.fingerprint_delete_all_warning)).setIcon(getResources().getDrawable(android.R.drawable.ic_dialog_alert)).setPositiveButton(getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() {

                        @RequiresApi(api = Build.VERSION_CODES.M)
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            FingerPrintHelper.deleteEntryKeyInKeystoreForFingerprints(getContext(), new FingerPrintHelper.FingerPrintErrorCallback() {

                                @Override
                                public void onInvalidKeyException(Exception e) {
                                }

                                @Override
                                public void onFingerPrintException(Exception e) {
                                    Toast.makeText(getContext(), getString(R.string.fingerprint_error, e.getLocalizedMessage()), Toast.LENGTH_SHORT).show();
                                }
                            });
                            PreferencesUtil.deleteAllValuesFromNoBackupPreferences(getContext());
                        }
                    }).setNegativeButton(getResources().getString(android.R.string.no), (dialog, which) -> {
                    }).show();
                    return false;
                });
            }
            break;
        case NESTED_SCREEN_FORM_FILLING_KEY:
            setPreferencesFromResource(R.xml.form_filling_preferences, rootKey);
            SwitchPreference autoFillEnablePreference = (SwitchPreference) findPreference(getString(R.string.settings_autofill_enable_key));
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                AutofillManager autofillManager = getActivity().getSystemService(AutofillManager.class);
                if (autofillManager != null && autofillManager.hasEnabledAutofillServices())
                    autoFillEnablePreference.setChecked(autofillManager.hasEnabledAutofillServices());
                autoFillEnablePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

                    @RequiresApi(api = Build.VERSION_CODES.O)
                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        if (((SwitchPreference) preference).isChecked()) {
                            try {
                                startEnableService();
                            } catch (ActivityNotFoundException e) {
                                String error = getString(R.string.error_autofill_enable_service);
                                ((SwitchPreference) preference).setChecked(false);
                                Log.d(getClass().getName(), error, e);
                                Toast.makeText(getContext(), error, Toast.LENGTH_SHORT).show();
                            }
                        } else {
                            disableService();
                        }
                        return false;
                    }

                    @RequiresApi(api = Build.VERSION_CODES.O)
                    private void disableService() {
                        if (autofillManager != null && autofillManager.hasEnabledAutofillServices()) {
                            autofillManager.disableAutofillServices();
                        } else {
                            Log.d(getClass().getName(), "Sample service already disabled.");
                        }
                    }

                    @RequiresApi(api = Build.VERSION_CODES.O)
                    private void startEnableService() throws ActivityNotFoundException {
                        if (autofillManager != null && !autofillManager.hasEnabledAutofillServices()) {
                            Intent intent = new Intent(Settings.ACTION_REQUEST_SET_AUTOFILL_SERVICE);
                            intent.setData(Uri.parse("package:com.example.android.autofill.service"));
                            Log.d(getClass().getName(), "enableService(): intent=" + intent);
                            startActivityForResult(intent, REQUEST_CODE_AUTOFILL);
                        } else {
                            Log.d(getClass().getName(), "Sample service already enabled.");
                        }
                    }
                });
            } else {
                autoFillEnablePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
                            ((SwitchPreference) preference).setChecked(false);
                            FragmentManager fragmentManager = getFragmentManager();
                            assert fragmentManager != null;
                            UnavailableFeatureDialogFragment.getInstance(Build.VERSION_CODES.O).show(fragmentManager, "unavailableFeatureDialog");
                        }
                        return false;
                    }
                });
            }
            break;
        case NESTED_SCREEN_DB_KEY:
            setPreferencesFromResource(R.xml.db_preferences, rootKey);
            Database db = App.getDB();
            if (db.Loaded()) {
                if (db.pm.algorithmSettingsEnabled()) {
                    Preference roundPref = findPreference(getString(R.string.rounds_key));
                    roundPref.setEnabled(true);
                    roundPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

                        public boolean onPreferenceChange(Preference preference, Object newValue) {
                            setRounds(App.getDB(), preference);
                            return true;
                        }
                    });
                    setRounds(db, roundPref);
                    // TODO Algo
                    Preference algorithmPref = findPreference(getString(R.string.algorithm_key));
                    // algorithmPref.setEnabled(true);
                    setAlgorithm(db, algorithmPref);
                }
                if (db.pm.isRecycleBinAvailable()) {
                    SwitchPreference recycleBinPref = (SwitchPreference) findPreference(getString(R.string.recycle_bin_key));
                    // TODO Recycle
                    // recycleBinPref.setEnabled(true);
                    recycleBinPref.setChecked(db.pm.isRecycleBinEnable());
                }
            } else {
                Log.e(getClass().getName(), "Database isn't ready");
            }
            break;
        default:
            break;
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) R(com.kunzisoft.keepass.R) Bundle(android.os.Bundle) PreferenceFragmentCompat(android.support.v7.preference.PreferenceFragmentCompat) Uri(android.net.Uri) Intent(android.content.Intent) RequiresApi(android.support.annotation.RequiresApi) DialogFragment(android.support.v4.app.DialogFragment) AutofillManager(android.view.autofill.AutofillManager) FingerprintManagerCompat(android.support.v4.hardware.fingerprint.FingerprintManagerCompat) PwEncryptionAlgorithm(com.keepassdroid.database.PwEncryptionAlgorithm) Toast(android.widget.Toast) Settings(android.provider.Settings) Build(android.os.Build) Log(android.util.Log) DialogInterface(android.content.DialogInterface) UnavailableFeatureDialogFragment(com.keepassdroid.dialogs.UnavailableFeatureDialogFragment) Database(com.keepassdroid.database.Database) Stylish(com.keepassdroid.stylish.Stylish) App(com.keepassdroid.app.App) Preference(android.support.v7.preference.Preference) FragmentManager(android.support.v4.app.FragmentManager) AlertDialog(android.support.v7.app.AlertDialog) ActivityNotFoundException(android.content.ActivityNotFoundException) SwitchPreference(android.support.v14.preference.SwitchPreference) Resources(android.content.res.Resources) FingerPrintHelper(com.keepassdroid.fingerprint.FingerPrintHelper) SwitchPreference(android.support.v14.preference.SwitchPreference) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) AutofillManager(android.view.autofill.AutofillManager) ActivityNotFoundException(android.content.ActivityNotFoundException) FragmentManager(android.support.v4.app.FragmentManager) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) ActivityNotFoundException(android.content.ActivityNotFoundException) RequiresApi(android.support.annotation.RequiresApi) Database(com.keepassdroid.database.Database)

Example 8 with Database

use of com.keepassdroid.database.Database in project KeePassDX by Kunzisoft.

the class CreateDB method run.

@Override
public void run() {
    // Create new database record
    Database db = new Database();
    App.setDB(db);
    PwDatabase pm = PwDatabase.getNewDBInstance(mFilename);
    pm.initNew(mFilename);
    // Set Database state
    db.pm = pm;
    db.mUri = UriUtil.parseDefaultFile(mFilename);
    db.setLoaded();
    App.clearShutdown();
    // Commit changes
    SaveDB save = new SaveDB(ctx, db, mFinish, mDontSave);
    mFinish = null;
    save.run();
}
Also used : PwDatabase(com.keepassdroid.database.PwDatabase) PwDatabase(com.keepassdroid.database.PwDatabase) Database(com.keepassdroid.database.Database)

Example 9 with Database

use of com.keepassdroid.database.Database in project KeePassDX by Kunzisoft.

the class EntryEditActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.entry_edit);
    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.app_name));
    setSupportActionBar(toolbar);
    assert getSupportActionBar() != null;
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    scrollView = findViewById(R.id.entry_scroll);
    scrollView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
    entryTitleView = findViewById(R.id.entry_title);
    entryUserNameView = findViewById(R.id.entry_user_name);
    entryUrlView = findViewById(R.id.entry_url);
    entryPasswordView = findViewById(R.id.entry_password);
    entryConfirmationPasswordView = findViewById(R.id.entry_confpassword);
    entryCommentView = findViewById(R.id.entry_comment);
    entryExtraFieldsContainer = findViewById(R.id.advanced_container);
    // Likely the app has been killed exit the activity
    Database db = App.getDB();
    if (!db.Loaded()) {
        finish();
        return;
    }
    Intent intent = getIntent();
    byte[] uuidBytes = intent.getByteArrayExtra(KEY_ENTRY);
    PwDatabase pm = db.pm;
    if (uuidBytes == null) {
        PwGroupId parentId = (PwGroupId) intent.getSerializableExtra(KEY_PARENT);
        PwGroup parent = pm.groups.get(parentId);
        mEntry = PwEntry.getInstance(parent);
        mIsNew = true;
    } else {
        UUID uuid = Types.bytestoUUID(uuidBytes);
        mEntry = pm.entries.get(uuid);
        mIsNew = false;
        fillData();
    }
    View iconButton = findViewById(R.id.icon_button);
    iconButton.setOnClickListener(v -> IconPickerDialogFragment.launch(EntryEditActivity.this));
    // Generate password button
    View generatePassword = findViewById(R.id.generate_button);
    generatePassword.setOnClickListener(v -> {
        GeneratePasswordDialogFragment generatePasswordDialogFragment = new GeneratePasswordDialogFragment();
        generatePasswordDialogFragment.show(getSupportFragmentManager(), "PasswordGeneratorFragment");
    });
    // Save button
    View save = findViewById(R.id.entry_save);
    save.setOnClickListener(v -> {
        if (!validateBeforeSaving()) {
            return;
        }
        mCallbackNewEntry = populateNewEntry();
        OnFinish onFinish = new AfterSave();
        EntryEditActivity act = EntryEditActivity.this;
        RunnableOnFinish task;
        if (mIsNew) {
            task = new AddEntry(act, App.getDB(), mCallbackNewEntry, onFinish);
        } else {
            task = new UpdateEntry(act, App.getDB(), mEntry, mCallbackNewEntry, onFinish);
        }
        ProgressTask pt = new ProgressTask(act, task, R.string.saving_database);
        pt.run();
    });
    if (mEntry.allowExtraFields()) {
        View add = findViewById(R.id.add_new_field);
        add.setVisibility(View.VISIBLE);
        add.setOnClickListener(v -> {
            EntryEditNewField ees = new EntryEditNewField(EntryEditActivity.this);
            ees.setData("", new ProtectedString(false, ""));
            entryExtraFieldsContainer.addView(ees);
            // Scroll bottom
            scrollView.post(() -> scrollView.fullScroll(ScrollView.FOCUS_DOWN));
        });
    }
}
Also used : ProgressTask(com.keepassdroid.tasks.ProgressTask) UpdateEntry(com.keepassdroid.database.edit.UpdateEntry) PwDatabase(com.keepassdroid.database.PwDatabase) RunnableOnFinish(com.keepassdroid.database.edit.RunnableOnFinish) Intent(android.content.Intent) OnFinish(com.keepassdroid.database.edit.OnFinish) RunnableOnFinish(com.keepassdroid.database.edit.RunnableOnFinish) EntryEditNewField(com.keepassdroid.view.EntryEditNewField) View(android.view.View) ScrollView(android.widget.ScrollView) AddEntry(com.keepassdroid.database.edit.AddEntry) GeneratePasswordDialogFragment(com.keepassdroid.dialogs.GeneratePasswordDialogFragment) PwGroupId(com.keepassdroid.database.PwGroupId) PwDatabase(com.keepassdroid.database.PwDatabase) Database(com.keepassdroid.database.Database) ProtectedString(com.keepassdroid.database.security.ProtectedString) PwGroup(com.keepassdroid.database.PwGroup) UUID(java.util.UUID) Toolbar(android.support.v7.widget.Toolbar)

Example 10 with Database

use of com.keepassdroid.database.Database in project KeePassDX by Kunzisoft.

the class GroupActivity method initCurrentGroup.

protected PwGroup initCurrentGroup() {
    PwGroup currentGroup;
    Database db = App.getDB();
    readOnly = db.readOnly;
    PwGroup root = db.pm.rootGroup;
    Log.w(TAG, "Creating tree view");
    PwGroupId pwGroupId = (PwGroupId) getIntent().getSerializableExtra(GROUP_ID_KEY);
    if (pwGroupId == null) {
        currentGroup = root;
    } else {
        currentGroup = db.pm.groups.get(pwGroupId);
    }
    if (currentGroup != null) {
        addGroupEnabled = !readOnly;
        // TODO ReadOnly
        addEntryEnabled = !readOnly;
        isRoot = (currentGroup == root);
        if (!currentGroup.allowAddEntryIfIsRoot())
            addEntryEnabled = !isRoot && addEntryEnabled;
    }
    return currentGroup;
}
Also used : PwGroupId(com.keepassdroid.database.PwGroupId) Database(com.keepassdroid.database.Database) PwGroup(com.keepassdroid.database.PwGroup)

Aggregations

Database (com.keepassdroid.database.Database)11 PwDatabase (com.keepassdroid.database.PwDatabase)6 Intent (android.content.Intent)3 PwGroup (com.keepassdroid.database.PwGroup)3 Uri (android.net.Uri)2 Preference (android.support.v7.preference.Preference)2 Toolbar (android.support.v7.widget.Toolbar)2 View (android.view.View)2 PwGroupId (com.keepassdroid.database.PwGroupId)2 ProgressTask (com.keepassdroid.tasks.ProgressTask)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 AssetManager (android.content.res.AssetManager)1 Resources (android.content.res.Resources)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 Settings (android.provider.Settings)1 RequiresApi (android.support.annotation.RequiresApi)1