[android] add review comments for panic induced account deletion

This commit is contained in:
Torsten Grote
2019-03-08 17:14:03 -03:00
parent 31d3324701
commit 270b8af39f
7 changed files with 28 additions and 26 deletions

View File

@@ -93,10 +93,14 @@ class AndroidAccountManager extends AccountManagerImpl
LOG.warning("Could not clear shared preferences");
}
// Delete files, except lib and shared_prefs directories
HashSet<File> files = new HashSet<>();
File dataDir = new File(appContext.getApplicationInfo().dataDir);
HashSet<File> files = new HashSet<>(asList(dataDir.listFiles()));
if (files.isEmpty()) {
@Nullable
File[] fileArray = dataDir.listFiles();
if (fileArray == null) {
LOG.warning("Could not list files in app data dir");
} else {
files.addAll(asList(fileArray));
}
files.add(appContext.getFilesDir());
files.add(appContext.getCacheDir());

View File

@@ -168,7 +168,6 @@ class LifecycleManagerImpl implements LifecycleManager, MigrationListener {
@Override
public void stopServices() {
if (state == STOPPING) return;
try {
startStopSemaphore.acquire();
} catch (InterruptedException e) {

View File

@@ -185,13 +185,15 @@ public abstract class BriarActivity extends BaseActivity {
b.show();
}
protected void signOut(boolean removeFromRecentApps) {
protected void signOut(boolean removeFromRecentApps,
boolean deleteAccount) {
if (briarController.accountSignedIn()) {
// Don't use UiResultHandler because we want the result even if
// this activity has been destroyed
briarController.signOut(result -> runOnUiThread(
() -> exit(removeFromRecentApps)));
() -> exit(removeFromRecentApps)), deleteAccount);
} else {
if (deleteAccount) briarController.deleteAccount();
exit(removeFromRecentApps);
}
}

View File

@@ -16,5 +16,8 @@ public interface BriarController extends ActivityLifecycleController {
void doNotAskAgainForDozeWhiteListing();
void signOut(ResultHandler<Void> eventHandler);
void signOut(ResultHandler<Void> eventHandler, boolean deleteAccount);
void deleteAccount();
}

View File

@@ -120,7 +120,8 @@ public class BriarControllerImpl implements BriarController {
}
@Override
public void signOut(ResultHandler<Void> eventHandler) {
public void signOut(ResultHandler<Void> eventHandler,
boolean deleteAccount) {
new Thread(() -> {
try {
// Wait for the service to finish starting up
@@ -134,11 +135,18 @@ public class BriarControllerImpl implements BriarController {
service.waitForShutdown();
} catch (InterruptedException e) {
LOG.warning("Interrupted while waiting for service");
} finally {
if (deleteAccount) accountManager.deleteAccount();
}
eventHandler.onResult(null);
}).start();
}
@Override
public void deleteAccount() {
accountManager.deleteAccount();
}
private void unbindService() {
if (bound) activity.unbindService(serviceConnection);
}

View File

@@ -109,7 +109,7 @@ public class NavDrawerActivity extends BriarActivity implements
} else if (intent.getBooleanExtra(INTENT_BLOGS, false)) {
startFragment(FeedFragment.newInstance(), R.id.nav_btn_blogs);
} else if (intent.getBooleanExtra(INTENT_SIGN_OUT, false)) {
signOut(false);
signOut(false, false);
}
setIntent(null);
}
@@ -279,7 +279,7 @@ public class NavDrawerActivity extends BriarActivity implements
private void signOut() {
drawerLayout.setDrawerLockMode(LOCK_MODE_LOCKED_CLOSED);
signOut(false);
signOut(false, false);
finish();
}

View File

@@ -5,7 +5,6 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.preference.PreferenceManager;
import org.briarproject.bramble.api.account.AccountManager;
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
@@ -24,8 +23,6 @@ import info.guardianproject.panic.PanicResponder;
import info.guardianproject.trustedintents.TrustedIntents;
import static android.os.Build.VERSION.SDK_INT;
import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.briar.android.panic.PanicPreferencesFragment.KEY_LOCK;
import static org.briarproject.briar.android.panic.PanicPreferencesFragment.KEY_PURGE;
@@ -39,8 +36,6 @@ public class PanicResponderActivity extends BriarActivity {
@Inject
protected LifecycleManager lifecycleManager;
@Inject
protected AccountManager accountManager;
@Inject
protected AndroidExecutor androidExecutor;
@Override
@@ -74,7 +69,7 @@ public class PanicResponderActivity extends BriarActivity {
// non-destructive actions are allowed by non-connected trusted apps
if (sharedPref.getBoolean(KEY_LOCK, true)) {
LOG.info("Signing out...");
signOut(true);
signOut(true, false);
}
}
}
@@ -93,17 +88,8 @@ public class PanicResponderActivity extends BriarActivity {
private void deleteAllData() {
androidExecutor.runOnBackgroundThread(() -> {
lifecycleManager.stopServices();
try {
lifecycleManager.waitForShutdown();
} catch (InterruptedException e) {
logException(LOG, WARNING, e);
} finally {
accountManager.deleteAccount();
// nothing left to do after everything is deleted, so sign out
LOG.info("Signing out...");
signOut(true);
}
LOG.info("Signing out...");
signOut(true, true);
});
}
}