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

View File

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

View File

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

View File

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

View File

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

View File

@@ -5,7 +5,6 @@ import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.preference.PreferenceManager; 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.lifecycle.LifecycleManager;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault; import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault; import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
@@ -24,8 +23,6 @@ import info.guardianproject.panic.PanicResponder;
import info.guardianproject.trustedintents.TrustedIntents; import info.guardianproject.trustedintents.TrustedIntents;
import static android.os.Build.VERSION.SDK_INT; 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_LOCK;
import static org.briarproject.briar.android.panic.PanicPreferencesFragment.KEY_PURGE; import static org.briarproject.briar.android.panic.PanicPreferencesFragment.KEY_PURGE;
@@ -39,8 +36,6 @@ public class PanicResponderActivity extends BriarActivity {
@Inject @Inject
protected LifecycleManager lifecycleManager; protected LifecycleManager lifecycleManager;
@Inject @Inject
protected AccountManager accountManager;
@Inject
protected AndroidExecutor androidExecutor; protected AndroidExecutor androidExecutor;
@Override @Override
@@ -74,7 +69,7 @@ public class PanicResponderActivity extends BriarActivity {
// non-destructive actions are allowed by non-connected trusted apps // non-destructive actions are allowed by non-connected trusted apps
if (sharedPref.getBoolean(KEY_LOCK, true)) { if (sharedPref.getBoolean(KEY_LOCK, true)) {
LOG.info("Signing out..."); LOG.info("Signing out...");
signOut(true); signOut(true, false);
} }
} }
} }
@@ -93,17 +88,8 @@ public class PanicResponderActivity extends BriarActivity {
private void deleteAllData() { private void deleteAllData() {
androidExecutor.runOnBackgroundThread(() -> { androidExecutor.runOnBackgroundThread(() -> {
lifecycleManager.stopServices(); LOG.info("Signing out...");
try { signOut(true, true);
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);
}
}); });
} }
} }