Commit c8fed348 authored by akwizgran's avatar akwizgran
Browse files

Merge branch '263-delete-all-the-things' into 'master'

Delete all app data when deleting account. #263

When deleting the user's account, delete everything in the app's persistent storage directory except the libs directory, which is populated with native libs when the app is installed.

Fixes #263.

See merge request !119
parents 89606442 30c3a33a
......@@ -38,8 +38,9 @@ import static org.briarproject.android.TestingConstants.PREVENT_SCREENSHOTS;
public abstract class BaseActivity extends AppCompatActivity
implements RoboContext {
private final static String PREFS_DB = "db";
private final static String PREFS_KEY = "key";
public final static String PREFS_NAME = "db";
public final static String PREF_DB_KEY = "key";
public final static String PREF_SEEN_WELCOME_MESSAGE = "welcome_message";
private final HashMap<Key<?>, Object> scopedObjects =
new HashMap<Key<?>, Object>();
......@@ -128,18 +129,17 @@ public abstract class BaseActivity extends AppCompatActivity
return scopedObjects;
}
// FIXME: Factor out prefs code so it can be used by SplashScreenActivity
private SharedPreferences getSharedPrefs() {
return getSharedPreferences(PREFS_DB, MODE_PRIVATE);
return getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
}
protected String getEncryptedDatabaseKey() {
return getSharedPrefs().getString(PREFS_KEY, null);
return getSharedPrefs().getString(PREF_DB_KEY, null);
}
protected void storeEncryptedDatabaseKey(final String hex) {
SharedPreferences.Editor editor = getSharedPrefs().edit();
editor.putString(PREFS_KEY, hex);
editor.putString(PREF_DB_KEY, hex);
editor.apply();
}
......
package org.briarproject.android;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
......@@ -20,9 +19,9 @@ import android.widget.ImageView;
import android.widget.TextView;
import org.briarproject.R;
import org.briarproject.android.fragment.BaseFragment;
import org.briarproject.android.contact.ContactListFragment;
import org.briarproject.android.forum.ForumListFragment;
import org.briarproject.android.fragment.BaseFragment;
import org.briarproject.android.fragment.SettingsFragment;
import org.briarproject.android.util.CustomAnimations;
import org.briarproject.api.TransportId;
......@@ -59,9 +58,6 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
private static final Logger LOG =
Logger.getLogger(NavDrawerActivity.class.getName());
private final static String PREFS_USER_SETTINGS = "prefs_user_settings";
private final static String KEY_SEEN_WELCOME_MESSAGE = "welcome_message";
private ActionBarDrawerToggle drawerToggle;
@Inject
......@@ -149,12 +145,12 @@ public class NavDrawerActivity extends BriarFragmentActivity implements
}
private void welcomeMessageCheck() {
SharedPreferences prefs = getSharedPreferences(PREFS_USER_SETTINGS,
Context.MODE_PRIVATE);
if (!prefs.getBoolean(KEY_SEEN_WELCOME_MESSAGE, false)) {
SharedPreferences prefs = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
if (!prefs.getBoolean(PREF_SEEN_WELCOME_MESSAGE, false)) {
showMessageDialog(R.string.dialog_title_welcome,
R.string.dialog_welcome_message);
prefs.edit().putBoolean(KEY_SEEN_WELCOME_MESSAGE, true).apply();
prefs.edit().putBoolean(PREF_SEEN_WELCOME_MESSAGE, true).apply();
}
}
......
......@@ -21,7 +21,6 @@ import org.briarproject.api.crypto.CryptoComponent;
import org.briarproject.api.crypto.CryptoExecutor;
import org.briarproject.api.crypto.SecretKey;
import org.briarproject.api.db.DatabaseConfig;
import org.briarproject.util.FileUtils;
import org.briarproject.util.StringUtils;
import java.util.concurrent.Executor;
......@@ -53,7 +52,7 @@ public class PasswordActivity extends BaseActivity {
String hex = getEncryptedDatabaseKey();
if (hex == null || !databaseConfig.databaseExists()) {
clearSharedPrefsAndDeleteDatabase();
clearSharedPrefsAndDeleteEverything();
return;
}
encrypted = StringUtils.fromHexString(hex);
......@@ -96,9 +95,9 @@ public class PasswordActivity extends BaseActivity {
startActivity(intent);
}
private void clearSharedPrefsAndDeleteDatabase() {
private void clearSharedPrefsAndDeleteEverything() {
clearSharedPrefs();
FileUtils.deleteFileOrDir(databaseConfig.getDatabaseDirectory());
AndroidUtils.deleteAppData(this);
setResult(RESULT_CANCELED);
startActivity(new Intent(this, SetupActivity.class));
finish();
......@@ -118,7 +117,7 @@ public class PasswordActivity extends BaseActivity {
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
clearSharedPrefsAndDeleteDatabase();
clearSharedPrefsAndDeleteEverything();
}
});
AlertDialog dialog = builder.create();
......
......@@ -14,9 +14,9 @@ import android.widget.LinearLayout;
import com.google.inject.Injector;
import org.briarproject.R;
import org.briarproject.android.util.AndroidUtils;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.db.DatabaseConfig;
import org.briarproject.util.FileUtils;
import java.util.logging.Logger;
......@@ -26,6 +26,8 @@ import roboguice.activity.RoboSplashActivity;
import static android.view.Gravity.CENTER;
import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
import static java.util.logging.Level.INFO;
import static org.briarproject.android.BaseActivity.PREFS_NAME;
import static org.briarproject.android.BaseActivity.PREF_DB_KEY;
import static org.briarproject.android.TestingConstants.DEFAULT_LOG_LEVEL;
import static org.briarproject.android.TestingConstants.PREVENT_SCREENSHOTS;
import static org.briarproject.android.TestingConstants.TESTING;
......@@ -79,16 +81,16 @@ public class SplashScreenActivity extends RoboSplashActivity {
LOG.info("Expired");
startActivity(new Intent(this, ExpiredActivity.class));
} else {
SharedPreferences prefs = getSharedPreferences("db", MODE_PRIVATE);
String hex = prefs.getString("key", null);
SharedPreferences prefs = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
String hex = prefs.getString(PREF_DB_KEY, null);
Injector i = RoboGuice.getBaseApplicationInjector(getApplication());
DatabaseConfig databaseConfig = i.getInstance(DatabaseConfig.class);
if (hex != null && databaseConfig.databaseExists()) {
startActivity(new Intent(this, NavDrawerActivity.class));
} else {
prefs.edit().clear().apply();
FileUtils.deleteFileOrDir(
databaseConfig.getDatabaseDirectory());
AndroidUtils.deleteAppData(this);
startActivity(new Intent(this, SetupActivity.class));
}
}
......
......@@ -8,14 +8,11 @@ import android.os.Bundle;
import android.support.v7.preference.PreferenceManager;
import org.briarproject.android.BriarActivity;
import org.briarproject.api.db.DatabaseConfig;
import org.briarproject.util.FileUtils;
import org.briarproject.android.util.AndroidUtils;
import org.iilab.IilabEngineeringRSA2048Pin;
import java.util.logging.Logger;
import javax.inject.Inject;
import info.guardianproject.GuardianProjectRSA4096;
import info.guardianproject.panic.Panic;
import info.guardianproject.panic.PanicResponder;
......@@ -29,7 +26,6 @@ public class PanicResponderActivity extends BriarActivity {
private static final Logger LOG =
Logger.getLogger(PanicResponderActivity.class.getName());
@Inject private DatabaseConfig databaseConfig;
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -105,9 +101,7 @@ public class PanicResponderActivity extends BriarActivity {
public void run() {
clearSharedPrefs();
// TODO somehow delete/shred the database more thoroughly
FileUtils
.deleteFileOrDir(
databaseConfig.getDatabaseDirectory());
AndroidUtils.deleteAppData(PanicResponderActivity.this);
PanicResponder.deleteAllAppData(PanicResponderActivity.this);
// nothing left to do after everything is deleted,
......
......@@ -7,8 +7,10 @@ import android.os.Build;
import android.provider.Settings;
import android.support.design.widget.TextInputLayout;
import org.briarproject.util.FileUtils;
import org.briarproject.util.StringUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
......@@ -71,4 +73,15 @@ public class AndroidUtils {
&& BluetoothAdapter.checkBluetoothAddress(address)
&& !address.equals(FAKE_BLUETOOTH_ADDRESS);
}
public static void deleteAppData(Context ctx) {
File dataDir = new File(ctx.getApplicationInfo().dataDir);
File[] children = dataDir.listFiles();
if (children != null) {
for (File child : children) {
if (!child.getName().equals("lib"))
FileUtils.deleteFileOrDir(child);
}
}
}
}
......@@ -8,7 +8,9 @@ public class FileUtils {
if (f.isFile()) {
f.delete();
} else if (f.isDirectory()) {
for (File child : f.listFiles()) deleteFileOrDir(child);
File[] children = f.listFiles();
if (children != null)
for (File child : children) deleteFileOrDir(child);
f.delete();
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment