2014-10-22 16:38:44 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
2015-04-19 16:08:13 +00:00
|
|
|
import android.app.AlertDialog;
|
2015-04-14 13:53:50 +00:00
|
|
|
import android.app.FragmentManager;
|
2015-04-19 16:08:13 +00:00
|
|
|
import android.content.DialogInterface;
|
2016-02-23 22:58:42 +00:00
|
|
|
import android.content.Intent;
|
2014-10-22 16:38:44 +00:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
2016-02-23 22:58:42 +00:00
|
|
|
import android.content.pm.PackageManager;
|
2014-10-22 16:38:44 +00:00
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.ListPreference;
|
2015-04-19 16:08:13 +00:00
|
|
|
import android.preference.Preference;
|
2015-12-01 21:41:58 +00:00
|
|
|
import android.preference.PreferenceCategory;
|
2014-10-22 16:38:44 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2015-12-01 21:41:58 +00:00
|
|
|
import android.preference.PreferenceScreen;
|
2015-04-19 16:08:13 +00:00
|
|
|
import android.widget.Toast;
|
2014-10-22 16:38:44 +00:00
|
|
|
|
2015-07-20 12:26:29 +00:00
|
|
|
import java.security.KeyStoreException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
2016-03-01 18:00:18 +00:00
|
|
|
import java.util.List;
|
2015-07-20 12:26:29 +00:00
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
import de.duenndns.ssl.MemorizingTrustManager;
|
2015-12-01 21:41:58 +00:00
|
|
|
import eu.siacs.conversations.Config;
|
2015-07-20 12:26:29 +00:00
|
|
|
import eu.siacs.conversations.R;
|
|
|
|
import eu.siacs.conversations.entities.Account;
|
2016-02-23 22:58:42 +00:00
|
|
|
import eu.siacs.conversations.services.ExportLogsService;
|
2015-07-20 12:26:29 +00:00
|
|
|
import eu.siacs.conversations.xmpp.XmppConnection;
|
2016-09-28 10:24:50 +00:00
|
|
|
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
|
|
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
2015-07-20 12:26:29 +00:00
|
|
|
|
2014-10-22 16:38:44 +00:00
|
|
|
public class SettingsActivity extends XmppActivity implements
|
|
|
|
OnSharedPreferenceChangeListener {
|
2016-02-23 22:58:42 +00:00
|
|
|
|
2016-11-30 09:45:39 +00:00
|
|
|
public static final String KEEP_FOREGROUND_SERVICE = "enable_foreground_service";
|
2016-11-21 10:03:38 +00:00
|
|
|
public static final String AWAY_WHEN_SCREEN_IS_OFF = "away_when_screen_off";
|
|
|
|
public static final String TREAT_VIBRATE_AS_SILENT = "treat_vibrate_as_silent";
|
|
|
|
public static final String MANUALLY_CHANGE_PRESENCE = "manually_change_presence";
|
2016-11-23 09:42:27 +00:00
|
|
|
public static final String BLIND_TRUST_BEFORE_VERIFICATION = "btbv";
|
2016-11-21 10:03:38 +00:00
|
|
|
|
2016-02-23 22:58:42 +00:00
|
|
|
public static final int REQUEST_WRITE_LOGS = 0xbf8701;
|
2014-10-22 16:38:44 +00:00
|
|
|
private SettingsFragment mSettingsFragment;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2015-04-14 13:53:50 +00:00
|
|
|
FragmentManager fm = getFragmentManager();
|
|
|
|
mSettingsFragment = (SettingsFragment) fm.findFragmentById(android.R.id.content);
|
|
|
|
if (mSettingsFragment == null || !mSettingsFragment.getClass().equals(SettingsFragment.class)) {
|
|
|
|
mSettingsFragment = new SettingsFragment();
|
|
|
|
fm.beginTransaction().replace(android.R.id.content, mSettingsFragment).commit();
|
|
|
|
}
|
Dark theme, theme switch, icons, style, strings
added some white icons,
changed hardcoded icons to theme attributes,
changed icon_edit_dark to icon_edit_body to reflect icons position,
grey message bubbles in dark theme,
misc
purged ic_action_chat as it wasn't used
preference use_white_background changed to use_green_background, default true
grey chat bubbles darker, text white
replaced all grey600 with black icons and 0.54 alpha attribute
highlightColor in dark grey chat bubble now darker than background
2016-05-12 18:00:18 +00:00
|
|
|
|
|
|
|
this.mTheme = findTheme();
|
|
|
|
setTheme(this.mTheme);
|
|
|
|
|
|
|
|
int bgcolor = getPrimaryBackgroundColor();
|
|
|
|
getWindow().getDecorView().setBackgroundColor(bgcolor);
|
|
|
|
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
void onBackendConnected() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
2015-04-14 13:53:50 +00:00
|
|
|
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
|
|
|
ListPreference resources = (ListPreference) mSettingsFragment.findPreference("resource");
|
2014-10-22 16:38:44 +00:00
|
|
|
if (resources != null) {
|
2015-04-14 13:53:50 +00:00
|
|
|
ArrayList<CharSequence> entries = new ArrayList<>(Arrays.asList(resources.getEntries()));
|
|
|
|
if (!entries.contains(Build.MODEL)) {
|
|
|
|
entries.add(0, Build.MODEL);
|
|
|
|
resources.setEntries(entries.toArray(new CharSequence[entries.size()]));
|
|
|
|
resources.setEntryValues(entries.toArray(new CharSequence[entries.size()]));
|
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
2015-04-19 16:08:13 +00:00
|
|
|
|
2015-12-14 09:54:55 +00:00
|
|
|
if (Config.FORCE_ORBOT) {
|
2015-12-01 21:41:58 +00:00
|
|
|
PreferenceCategory connectionOptions = (PreferenceCategory) mSettingsFragment.findPreference("connection_options");
|
|
|
|
PreferenceScreen expert = (PreferenceScreen) mSettingsFragment.findPreference("expert");
|
|
|
|
if (connectionOptions != null) {
|
|
|
|
expert.removePreference(connectionOptions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-19 16:08:13 +00:00
|
|
|
final Preference removeCertsPreference = mSettingsFragment.findPreference("remove_trusted_certificates");
|
|
|
|
removeCertsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
final MemorizingTrustManager mtm = xmppConnectionService.getMemorizingTrustManager();
|
|
|
|
final ArrayList<String> aliases = Collections.list(mtm.getCertificates());
|
|
|
|
if (aliases.size() == 0) {
|
|
|
|
displayToast(getString(R.string.toast_no_trusted_certs));
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-28 10:24:50 +00:00
|
|
|
final ArrayList selectedItems = new ArrayList<>();
|
2015-04-19 16:08:13 +00:00
|
|
|
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(SettingsActivity.this);
|
|
|
|
dialogBuilder.setTitle(getResources().getString(R.string.dialog_manage_certs_title));
|
|
|
|
dialogBuilder.setMultiChoiceItems(aliases.toArray(new CharSequence[aliases.size()]), null,
|
|
|
|
new DialogInterface.OnMultiChoiceClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int indexSelected,
|
|
|
|
boolean isChecked) {
|
|
|
|
if (isChecked) {
|
|
|
|
selectedItems.add(indexSelected);
|
|
|
|
} else if (selectedItems.contains(indexSelected)) {
|
|
|
|
selectedItems.remove(Integer.valueOf(indexSelected));
|
|
|
|
}
|
|
|
|
if (selectedItems.size() > 0)
|
|
|
|
((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
|
|
|
|
else {
|
|
|
|
((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dialogBuilder.setPositiveButton(
|
|
|
|
getResources().getString(R.string.dialog_manage_certs_positivebutton), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
int count = selectedItems.size();
|
|
|
|
if (count > 0) {
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
try {
|
|
|
|
Integer item = Integer.valueOf(selectedItems.get(i).toString());
|
|
|
|
String alias = aliases.get(item);
|
|
|
|
mtm.deleteCertificate(alias);
|
|
|
|
} catch (KeyStoreException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
displayToast("Error: " + e.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (xmppConnectionServiceBound) {
|
|
|
|
reconnectAccounts();
|
|
|
|
}
|
|
|
|
displayToast(getResources().getQuantityString(R.plurals.toast_delete_certificates, count, count));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogBuilder.setNegativeButton(getResources().getString(R.string.dialog_manage_certs_negativebutton), null);
|
|
|
|
AlertDialog removeCertsDialog = dialogBuilder.create();
|
|
|
|
removeCertsDialog.show();
|
|
|
|
removeCertsDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2016-02-23 22:58:42 +00:00
|
|
|
|
|
|
|
final Preference exportLogsPreference = mSettingsFragment.findPreference("export_logs");
|
|
|
|
exportLogsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
2016-09-28 10:35:52 +00:00
|
|
|
if (hasStoragePermission(REQUEST_WRITE_LOGS)) {
|
|
|
|
startExport();
|
|
|
|
}
|
2016-02-23 22:58:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2016-09-28 10:24:50 +00:00
|
|
|
|
|
|
|
final Preference deleteOmemoPreference = mSettingsFragment.findPreference("delete_omemo_identities");
|
|
|
|
deleteOmemoPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
deleteOmemoIdentities();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void deleteOmemoIdentities() {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setTitle(R.string.pref_delete_omemo_identities);
|
|
|
|
final List<CharSequence> accounts = new ArrayList<>();
|
|
|
|
for(Account account : xmppConnectionService.getAccounts()) {
|
|
|
|
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
|
|
|
accounts.add(account.getJid().toBareJid().toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
final boolean[] checkedItems = new boolean[accounts.size()];
|
|
|
|
builder.setMultiChoiceItems(accounts.toArray(new CharSequence[accounts.size()]), checkedItems, new DialogInterface.OnMultiChoiceClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
|
|
|
checkedItems[which] = isChecked;
|
|
|
|
final AlertDialog alertDialog = (AlertDialog) dialog;
|
|
|
|
for(boolean item : checkedItems) {
|
|
|
|
if (item) {
|
|
|
|
alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(R.string.cancel,null);
|
|
|
|
builder.setPositiveButton(R.string.delete_selected_keys, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
for(int i = 0; i < checkedItems.length; ++i) {
|
|
|
|
if (checkedItems[i]) {
|
|
|
|
try {
|
|
|
|
Jid jid = Jid.fromString(accounts.get(i).toString());
|
|
|
|
Account account = xmppConnectionService.findAccountByJid(jid);
|
|
|
|
if (account != null) {
|
|
|
|
account.getAxolotlService().regenerateKeys(true);
|
|
|
|
}
|
|
|
|
} catch (InvalidJidException e) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AlertDialog dialog = builder.create();
|
|
|
|
dialog.show();
|
|
|
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(this)
|
|
|
|
.unregisterOnSharedPreferenceChangeListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-01 18:00:18 +00:00
|
|
|
public void onSharedPreferenceChanged(SharedPreferences preferences, String name) {
|
|
|
|
final List<String> resendPresence = Arrays.asList(
|
|
|
|
"confirm_messages",
|
|
|
|
"xa_on_silent_mode",
|
2016-11-21 10:03:38 +00:00
|
|
|
AWAY_WHEN_SCREEN_IS_OFF,
|
2016-03-01 18:00:18 +00:00
|
|
|
"allow_message_correction",
|
2016-11-21 10:03:38 +00:00
|
|
|
TREAT_VIBRATE_AS_SILENT,
|
|
|
|
MANUALLY_CHANGE_PRESENCE,
|
2016-06-04 14:16:14 +00:00
|
|
|
"last_activity");
|
2014-10-22 16:38:44 +00:00
|
|
|
if (name.equals("resource")) {
|
|
|
|
String resource = preferences.getString("resource", "mobile")
|
|
|
|
.toLowerCase(Locale.US);
|
|
|
|
if (xmppConnectionServiceBound) {
|
|
|
|
for (Account account : xmppConnectionService.getAccounts()) {
|
2015-04-09 10:46:54 +00:00
|
|
|
if (account.setResource(resource)) {
|
|
|
|
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
|
|
|
XmppConnection connection = account.getXmppConnection();
|
|
|
|
if (connection != null) {
|
|
|
|
connection.resetStreamId();
|
|
|
|
}
|
|
|
|
xmppConnectionService.reconnectAccountInBackground(account);
|
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-21 10:03:38 +00:00
|
|
|
} else if (name.equals(KEEP_FOREGROUND_SERVICE)) {
|
|
|
|
boolean foreground_service = preferences.getBoolean(KEEP_FOREGROUND_SERVICE,false);
|
2016-11-08 20:37:44 +00:00
|
|
|
if (!foreground_service) {
|
|
|
|
xmppConnectionService.clearStartTimeCounter();
|
|
|
|
}
|
2014-11-12 13:41:43 +00:00
|
|
|
xmppConnectionService.toggleForegroundService();
|
2016-03-01 18:00:18 +00:00
|
|
|
} else if (resendPresence.contains(name)) {
|
2015-01-25 23:48:56 +00:00
|
|
|
if (xmppConnectionServiceBound) {
|
2016-11-21 10:03:38 +00:00
|
|
|
if (name.equals(AWAY_WHEN_SCREEN_IS_OFF) || name.equals(MANUALLY_CHANGE_PRESENCE)) {
|
2015-10-07 22:35:04 +00:00
|
|
|
xmppConnectionService.toggleScreenEventReceiver();
|
2015-01-25 23:48:56 +00:00
|
|
|
}
|
2016-11-21 10:03:38 +00:00
|
|
|
if (name.equals(MANUALLY_CHANGE_PRESENCE) && !noAccountUsesPgp()) {
|
2016-05-05 11:17:04 +00:00
|
|
|
Toast.makeText(this, R.string.republish_pgp_keys, Toast.LENGTH_LONG).show();
|
|
|
|
}
|
2015-10-07 22:35:04 +00:00
|
|
|
xmppConnectionService.refreshAllPresences();
|
2015-01-25 23:48:56 +00:00
|
|
|
}
|
2015-04-02 11:35:42 +00:00
|
|
|
} else if (name.equals("dont_trust_system_cas")) {
|
|
|
|
xmppConnectionService.updateMemorizingTrustmanager();
|
2015-04-19 16:08:13 +00:00
|
|
|
reconnectAccounts();
|
2015-11-28 19:11:38 +00:00
|
|
|
} else if (name.equals("use_tor")) {
|
|
|
|
reconnectAccounts();
|
2015-04-19 16:08:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-23 22:58:42 +00:00
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
|
|
|
if (grantResults.length > 0)
|
|
|
|
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
|
if (requestCode == REQUEST_WRITE_LOGS) {
|
2016-09-28 10:35:52 +00:00
|
|
|
startExport();
|
2016-02-23 22:58:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-28 10:35:52 +00:00
|
|
|
private void startExport() {
|
|
|
|
startService(new Intent(getApplicationContext(), ExportLogsService.class));
|
|
|
|
}
|
|
|
|
|
2015-04-19 16:08:13 +00:00
|
|
|
private void displayToast(final String msg) {
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
Toast.makeText(SettingsActivity.this, msg, Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void reconnectAccounts() {
|
|
|
|
for (Account account : xmppConnectionService.getAccounts()) {
|
|
|
|
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
|
|
|
xmppConnectionService.reconnectAccountInBackground(account);
|
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-19 16:08:13 +00:00
|
|
|
|
2015-07-20 13:48:58 +00:00
|
|
|
public void refreshUiReal() {
|
|
|
|
//nothing to do. This Activity doesn't implement any listeners
|
|
|
|
}
|
|
|
|
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|