adrian / upm-android

Android version of Universal Password Manager.
http://upm.sourceforge.net/
76 stars 46 forks source link

Protection from Database Loss #6

Open adrian opened 13 years ago

adrian commented 13 years ago

The password database is only backed up to SD card when explicitly carried out by the user. Most user's won't do this since the repercussions aren't obvious, i.e. if the device is lost or bricked there's no way to recover your password database.

This issue is really a placeholder for ideas as to what can be done. Some options,

appatalks commented 11 years ago

Here is something I did, though I'm very new at programming, I'm sure a better idea can be implemented. Basically I kept the manual backup option that creates the upm.db to sdcard and added an Auto Backup on application exit to aupm.db to sdcard. Restoring is still from upm.db, so if someone wants to restore from the auto backup, all they need to do is rename the file accordingly.

In EnterMasterPassword.java:

@Override
public void onBackPressed()
{
    File fileOnSDCard = new File(Environment.getExternalStorageDirectory(), Utilities.AUTOMATIC_DATABASE_FILE);
    File databaseFile = Utilities.getDatabaseFile(this);
    if (((UPMApplication) getApplication()).copyFile(databaseFile, fileOnSDCard, this)) {
        String message = String.format(getString(R.string.backup_complete), fileOnSDCard.getAbsolutePath());
        UIUtilities.showToast(this, message, false);
    }
    System.exit(0);
}

And in Utilities.java:

 public static final String AUTOMATIC_DATABASE_FILE = "aupm.db";

 public static File getDatabaseFile(Activity activity) {
        String dbFileName = getDatabaseFileName(activity);
        if (dbFileName == null || dbFileName.equals("")) {
            return new File(activity.getFilesDir(), DEFAULT_DATABASE_FILE);
            }
        /* ADDED FOR AUTOBACKUP */
        if (dbFileName == null || dbFileName.equals("")) {
            return new File(activity.getFilesDir(), AUTOMATIC_DATABASE_FILE);
        } /* END */
        else {
            return new File(activity.getFilesDir(), dbFileName);
        }
    }