mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Merge branch '211-panic-uninstall-briar' into 'master'
Offer option to uninstall Briar in a panic event (#211) Due to the nature of how Android app uninstall works without root access, this requires manual confirmation after a panic event was triggered. See merge request !63
This commit is contained in:
@@ -122,6 +122,8 @@
|
||||
<string name="lock_setting_summary">Sign out of Briar if a panic button is pressed</string>
|
||||
<string name="purge_setting_title">Delete Account</string>
|
||||
<string name="purge_setting_summary">Delete your Briar account if a panic button is pressed. Caution: This will permanently delete your identities, contacts and messages</string>
|
||||
<string name="uninstall_setting_title">Uninstall Briar</string>
|
||||
<string name="uninstall_setting_summary">This requires manual confirmation in a panic event</string>
|
||||
<string name="step">Step %1$d/%2$d</string>
|
||||
<string name="online">Online</string>
|
||||
<string name="offline">Offline</string>
|
||||
|
||||
@@ -24,6 +24,13 @@
|
||||
android:enabled="false"
|
||||
android:defaultValue="false"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="pref_key_uninstall"
|
||||
android:title="@string/uninstall_setting_title"
|
||||
android:summary="@string/uninstall_setting_summary"
|
||||
android:enabled="false"
|
||||
android:defaultValue="false"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -27,13 +27,17 @@ import info.guardianproject.panic.PanicResponder;
|
||||
public class PanicPreferencesFragment extends PreferenceFragmentCompat
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
public static final String KEY_LOCK = "pref_key_lock";
|
||||
public static final String KEY_PANIC_APP = "pref_key_panic_app";
|
||||
public static final String KEY_PURGE = "pref_key_purge";
|
||||
public static final String KEY_UNINSTALL = "pref_key_uninstall";
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(PanicPreferencesFragment.class.getName());
|
||||
|
||||
private PackageManager pm;
|
||||
private CheckBoxPreference lockPref;
|
||||
private CheckBoxPreference lockPref, purgePref, uninstallPref;
|
||||
private ListPreference panicAppPref;
|
||||
private CheckBoxPreference purgePref;
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle bundle, String s) {
|
||||
@@ -41,9 +45,10 @@ public class PanicPreferencesFragment extends PreferenceFragmentCompat
|
||||
|
||||
pm = getActivity().getPackageManager();
|
||||
|
||||
lockPref = (CheckBoxPreference) findPreference("pref_key_lock");
|
||||
panicAppPref = (ListPreference) findPreference("pref_key_panic_app");
|
||||
purgePref = (CheckBoxPreference) findPreference("pref_key_purge");
|
||||
lockPref = (CheckBoxPreference) findPreference(KEY_LOCK);
|
||||
panicAppPref = (ListPreference) findPreference(KEY_PANIC_APP);
|
||||
purgePref = (CheckBoxPreference) findPreference(KEY_PURGE);
|
||||
uninstallPref = (CheckBoxPreference) findPreference(KEY_UNINSTALL);
|
||||
|
||||
// check for connect/disconnect intents from panic trigger apps
|
||||
if (PanicResponder.checkForDisconnectIntent(getActivity())) {
|
||||
@@ -98,9 +103,12 @@ public class PanicPreferencesFragment extends PreferenceFragmentCompat
|
||||
if (packageName.equals(Panic.PACKAGE_NAME_NONE)) {
|
||||
purgePref.setChecked(false);
|
||||
purgePref.setEnabled(false);
|
||||
uninstallPref.setChecked(false);
|
||||
uninstallPref.setEnabled(false);
|
||||
getActivity().setResult(Activity.RESULT_CANCELED);
|
||||
} else {
|
||||
purgePref.setEnabled(true);
|
||||
uninstallPref.setEnabled(true);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -141,16 +149,27 @@ public class PanicPreferencesFragment extends PreferenceFragmentCompat
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
||||
String key) {
|
||||
// enable locking if purging gets enabled
|
||||
if (key.equals("pref_key_purge")
|
||||
&& sharedPreferences.getBoolean("pref_key_purge", false)) {
|
||||
lockPref.setChecked(true);
|
||||
if (key.equals(KEY_PURGE)) {
|
||||
// enable locking if purging gets enabled
|
||||
if (sharedPreferences.getBoolean(KEY_PURGE, false)) {
|
||||
lockPref.setChecked(true);
|
||||
}
|
||||
// disable uninstall if purging gets disabled
|
||||
else {
|
||||
uninstallPref.setChecked(false);
|
||||
}
|
||||
}
|
||||
// disable purging if locking gets disabled
|
||||
if (key.equals("pref_key_lock")
|
||||
&& !sharedPreferences.getBoolean("pref_key_lock", true)
|
||||
&& sharedPreferences.getBoolean("pref_key_purge", false)) {
|
||||
// enable purging and locking if uninstall gets enabled
|
||||
if (key.equals(KEY_UNINSTALL) &&
|
||||
sharedPreferences.getBoolean(KEY_UNINSTALL, false)) {
|
||||
lockPref.setChecked(true);
|
||||
purgePref.setChecked(true);
|
||||
}
|
||||
// disable purging and uninstalling if locking gets disabled
|
||||
if (key.equals(KEY_LOCK) &&
|
||||
!sharedPreferences.getBoolean(KEY_LOCK, true)) {
|
||||
purgePref.setChecked(false);
|
||||
uninstallPref.setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +182,9 @@ public class PanicPreferencesFragment extends PreferenceFragmentCompat
|
||||
.setSummary(getString(R.string.panic_app_setting_summary));
|
||||
panicAppPref.setIcon(
|
||||
android.R.drawable.ic_menu_close_clear_cancel);
|
||||
|
||||
purgePref.setEnabled(false);
|
||||
uninstallPref.setEnabled(false);
|
||||
} else {
|
||||
// display connected panic app
|
||||
try {
|
||||
@@ -172,7 +193,9 @@ public class PanicPreferencesFragment extends PreferenceFragmentCompat
|
||||
pm.getApplicationInfo(triggerPackageName, 0)));
|
||||
panicAppPref.setIcon(
|
||||
pm.getApplicationIcon(triggerPackageName));
|
||||
|
||||
purgePref.setEnabled(true);
|
||||
uninstallPref.setEnabled(true);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
// revert back to no app, just to be safe
|
||||
PanicResponder.setTriggerPackageName(getActivity(),
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.briarproject.android.panic;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
@@ -20,6 +21,10 @@ import info.guardianproject.panic.Panic;
|
||||
import info.guardianproject.panic.PanicResponder;
|
||||
import info.guardianproject.trustedintents.TrustedIntents;
|
||||
|
||||
import static org.briarproject.android.panic.PanicPreferencesFragment.KEY_LOCK;
|
||||
import static org.briarproject.android.panic.PanicPreferencesFragment.KEY_PURGE;
|
||||
import static org.briarproject.android.panic.PanicPreferencesFragment.KEY_UNINSTALL;
|
||||
|
||||
public class PanicResponderActivity extends BriarActivity {
|
||||
|
||||
private static final Logger LOG =
|
||||
@@ -50,23 +55,29 @@ public class PanicResponderActivity extends BriarActivity {
|
||||
LOG.info("Performing destructive responses...");
|
||||
|
||||
// Performing destructive panic responses
|
||||
if (sharedPref.getBoolean("pref_key_purge", false)) {
|
||||
if (sharedPref.getBoolean(KEY_UNINSTALL, false)) {
|
||||
LOG.info("Purging all data...");
|
||||
deleteAllData();
|
||||
|
||||
LOG.info("Uninstalling...");
|
||||
Intent uninstall = new Intent(Intent.ACTION_DELETE);
|
||||
uninstall.setData(
|
||||
Uri.parse("package:" + getPackageName()));
|
||||
startActivity(uninstall);
|
||||
}
|
||||
else if (sharedPref.getBoolean(KEY_PURGE, false)) {
|
||||
LOG.info("Purging all data...");
|
||||
deleteAllData();
|
||||
}
|
||||
// still sign out if enabled
|
||||
else if (sharedPref.getBoolean("pref_key_lock", true)) {
|
||||
else if (sharedPref.getBoolean(KEY_LOCK, true)) {
|
||||
LOG.info("Signing out...");
|
||||
signOut(true);
|
||||
}
|
||||
|
||||
// TODO add other panic behavior such as:
|
||||
// * send a pre-defined message to certain contacts (#212)
|
||||
// * uninstall the app (#211)
|
||||
|
||||
// TODO send a pre-defined message to certain contacts (#212)
|
||||
}
|
||||
// Performing non-destructive default panic response
|
||||
else if (sharedPref.getBoolean("pref_key_lock", true)) {
|
||||
else if (sharedPref.getBoolean(KEY_LOCK, true)) {
|
||||
LOG.info("Signing out...");
|
||||
signOut(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user