show toast warning about unavailable calls when using tor

closes #4103
This commit is contained in:
Daniel Gultsch 2022-09-03 15:51:12 +02:00
parent eb49a7f5e5
commit e204457c31
3 changed files with 438 additions and 366 deletions

View file

@ -293,6 +293,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
} }
binding.hostnameLayout.setError(null); binding.hostnameLayout.setError(null);
binding.portLayout.setError(null); binding.portLayout.setError(null);
if (mAccount.isOnion()) {
Toast.makeText(EditAccountActivity.this, R.string.audio_video_disabled_tor, Toast.LENGTH_LONG).show();
}
if (mAccount.isEnabled() if (mAccount.isEnabled()
&& !registerNewAccount && !registerNewAccount
&& !mInitMode) { && !mInitMode) {

View file

@ -38,409 +38,477 @@ import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.services.ExportBackupService; import eu.siacs.conversations.services.ExportBackupService;
import eu.siacs.conversations.services.MemorizingTrustManager; import eu.siacs.conversations.services.MemorizingTrustManager;
import eu.siacs.conversations.services.QuickConversationsService; import eu.siacs.conversations.services.QuickConversationsService;
import eu.siacs.conversations.ui.util.SettingsUtils;
import eu.siacs.conversations.ui.util.StyledAttributes; import eu.siacs.conversations.ui.util.StyledAttributes;
import eu.siacs.conversations.utils.GeoHelper; import eu.siacs.conversations.utils.GeoHelper;
import eu.siacs.conversations.ui.util.SettingsUtils;
import eu.siacs.conversations.utils.TimeFrameUtils; import eu.siacs.conversations.utils.TimeFrameUtils;
import eu.siacs.conversations.xmpp.Jid; import eu.siacs.conversations.xmpp.Jid;
public class SettingsActivity extends XmppActivity implements public class SettingsActivity extends XmppActivity implements OnSharedPreferenceChangeListener {
OnSharedPreferenceChangeListener {
public static final String KEEP_FOREGROUND_SERVICE = "enable_foreground_service"; public static final String KEEP_FOREGROUND_SERVICE = "enable_foreground_service";
public static final String AWAY_WHEN_SCREEN_IS_OFF = "away_when_screen_off"; 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 TREAT_VIBRATE_AS_SILENT = "treat_vibrate_as_silent";
public static final String DND_ON_SILENT_MODE = "dnd_on_silent_mode"; public static final String DND_ON_SILENT_MODE = "dnd_on_silent_mode";
public static final String MANUALLY_CHANGE_PRESENCE = "manually_change_presence"; public static final String MANUALLY_CHANGE_PRESENCE = "manually_change_presence";
public static final String BLIND_TRUST_BEFORE_VERIFICATION = "btbv"; public static final String BLIND_TRUST_BEFORE_VERIFICATION = "btbv";
public static final String AUTOMATIC_MESSAGE_DELETION = "automatic_message_deletion"; public static final String AUTOMATIC_MESSAGE_DELETION = "automatic_message_deletion";
public static final String BROADCAST_LAST_ACTIVITY = "last_activity"; public static final String BROADCAST_LAST_ACTIVITY = "last_activity";
public static final String THEME = "theme"; public static final String THEME = "theme";
public static final String SHOW_DYNAMIC_TAGS = "show_dynamic_tags"; public static final String SHOW_DYNAMIC_TAGS = "show_dynamic_tags";
public static final String OMEMO_SETTING = "omemo"; public static final String OMEMO_SETTING = "omemo";
public static final String PREVENT_SCREENSHOTS = "prevent_screenshots"; public static final String PREVENT_SCREENSHOTS = "prevent_screenshots";
public static final int REQUEST_CREATE_BACKUP = 0xbf8701; public static final int REQUEST_CREATE_BACKUP = 0xbf8701;
private SettingsFragment mSettingsFragment; private SettingsFragment mSettingsFragment;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings); setContentView(R.layout.activity_settings);
FragmentManager fm = getFragmentManager(); FragmentManager fm = getFragmentManager();
mSettingsFragment = (SettingsFragment) fm.findFragmentById(R.id.settings_content); mSettingsFragment = (SettingsFragment) fm.findFragmentById(R.id.settings_content);
if (mSettingsFragment == null || !mSettingsFragment.getClass().equals(SettingsFragment.class)) { if (mSettingsFragment == null
mSettingsFragment = new SettingsFragment(); || !mSettingsFragment.getClass().equals(SettingsFragment.class)) {
fm.beginTransaction().replace(R.id.settings_content, mSettingsFragment).commit(); mSettingsFragment = new SettingsFragment();
} fm.beginTransaction().replace(R.id.settings_content, mSettingsFragment).commit();
mSettingsFragment.setActivityIntent(getIntent()); }
this.mTheme = findTheme(); mSettingsFragment.setActivityIntent(getIntent());
setTheme(this.mTheme); this.mTheme = findTheme();
getWindow().getDecorView().setBackgroundColor(StyledAttributes.getColor(this, R.attr.color_background_primary)); setTheme(this.mTheme);
setSupportActionBar(findViewById(R.id.toolbar)); getWindow()
configureActionBar(getSupportActionBar()); .getDecorView()
} .setBackgroundColor(
StyledAttributes.getColor(this, R.attr.color_background_primary));
setSupportActionBar(findViewById(R.id.toolbar));
configureActionBar(getSupportActionBar());
}
@Override @Override
void onBackendConnected() { void onBackendConnected() {}
} @Override
public void onStart() {
super.onStart();
PreferenceManager.getDefaultSharedPreferences(this)
.registerOnSharedPreferenceChangeListener(this);
@Override changeOmemoSettingSummary();
public void onStart() {
super.onStart();
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
changeOmemoSettingSummary(); if (QuickConversationsService.isQuicksy()) {
final PreferenceCategory connectionOptions =
(PreferenceCategory) mSettingsFragment.findPreference("connection_options");
final PreferenceCategory groupChats =
(PreferenceCategory) mSettingsFragment.findPreference("group_chats");
final Preference channelDiscoveryMethod =
mSettingsFragment.findPreference("channel_discovery_method");
PreferenceScreen expert = (PreferenceScreen) mSettingsFragment.findPreference("expert");
if (connectionOptions != null) {
expert.removePreference(connectionOptions);
}
if (groupChats != null && channelDiscoveryMethod != null) {
groupChats.removePreference(channelDiscoveryMethod);
}
}
if (QuickConversationsService.isQuicksy()) { PreferenceScreen mainPreferenceScreen =
final PreferenceCategory connectionOptions = (PreferenceCategory) mSettingsFragment.findPreference("connection_options"); (PreferenceScreen) mSettingsFragment.findPreference("main_screen");
final PreferenceCategory groupChats = (PreferenceCategory) mSettingsFragment.findPreference("group_chats");
final Preference channelDiscoveryMethod = mSettingsFragment.findPreference("channel_discovery_method");
PreferenceScreen expert = (PreferenceScreen) mSettingsFragment.findPreference("expert");
if (connectionOptions != null) {
expert.removePreference(connectionOptions);
}
if (groupChats != null && channelDiscoveryMethod != null) {
groupChats.removePreference(channelDiscoveryMethod);
}
}
PreferenceScreen mainPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("main_screen"); PreferenceCategory attachmentsCategory =
(PreferenceCategory) mSettingsFragment.findPreference("attachments");
CheckBoxPreference locationPlugin =
(CheckBoxPreference) mSettingsFragment.findPreference("use_share_location_plugin");
if (attachmentsCategory != null && locationPlugin != null) {
if (!GeoHelper.isLocationPluginInstalled(this)) {
attachmentsCategory.removePreference(locationPlugin);
}
}
PreferenceCategory attachmentsCategory = (PreferenceCategory) mSettingsFragment.findPreference("attachments"); // this feature is only available on Huawei Android 6.
CheckBoxPreference locationPlugin = (CheckBoxPreference) mSettingsFragment.findPreference("use_share_location_plugin"); PreferenceScreen huaweiPreferenceScreen =
if (attachmentsCategory != null && locationPlugin != null) { (PreferenceScreen) mSettingsFragment.findPreference("huawei");
if (!GeoHelper.isLocationPluginInstalled(this)) { if (huaweiPreferenceScreen != null) {
attachmentsCategory.removePreference(locationPlugin); Intent intent = huaweiPreferenceScreen.getIntent();
} // remove when Api version is above M (Version 6.0) or if the intent is not callable
} if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M || !isCallable(intent)) {
PreferenceCategory generalCategory =
(PreferenceCategory) mSettingsFragment.findPreference("general");
generalCategory.removePreference(huaweiPreferenceScreen);
if (generalCategory.getPreferenceCount() == 0) {
if (mainPreferenceScreen != null) {
mainPreferenceScreen.removePreference(generalCategory);
}
}
}
}
//this feature is only available on Huawei Android 6. ListPreference automaticMessageDeletionList =
PreferenceScreen huaweiPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("huawei"); (ListPreference) mSettingsFragment.findPreference(AUTOMATIC_MESSAGE_DELETION);
if (huaweiPreferenceScreen != null) { if (automaticMessageDeletionList != null) {
Intent intent = huaweiPreferenceScreen.getIntent(); final int[] choices =
//remove when Api version is above M (Version 6.0) or if the intent is not callable getResources().getIntArray(R.array.automatic_message_deletion_values);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M || !isCallable(intent)) { CharSequence[] entries = new CharSequence[choices.length];
PreferenceCategory generalCategory = (PreferenceCategory) mSettingsFragment.findPreference("general"); CharSequence[] entryValues = new CharSequence[choices.length];
generalCategory.removePreference(huaweiPreferenceScreen); for (int i = 0; i < choices.length; ++i) {
if (generalCategory.getPreferenceCount() == 0) { entryValues[i] = String.valueOf(choices[i]);
if (mainPreferenceScreen != null) { if (choices[i] == 0) {
mainPreferenceScreen.removePreference(generalCategory); entries[i] = getString(R.string.never);
} } else {
} entries[i] = TimeFrameUtils.resolve(this, 1000L * choices[i]);
} }
} }
automaticMessageDeletionList.setEntries(entries);
automaticMessageDeletionList.setEntryValues(entryValues);
}
ListPreference automaticMessageDeletionList = (ListPreference) mSettingsFragment.findPreference(AUTOMATIC_MESSAGE_DELETION); boolean removeLocation =
if (automaticMessageDeletionList != null) { new Intent("eu.siacs.conversations.location.request")
final int[] choices = getResources().getIntArray(R.array.automatic_message_deletion_values); .resolveActivity(getPackageManager())
CharSequence[] entries = new CharSequence[choices.length]; == null;
CharSequence[] entryValues = new CharSequence[choices.length]; boolean removeVoice =
for (int i = 0; i < choices.length; ++i) { new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION)
entryValues[i] = String.valueOf(choices[i]); .resolveActivity(getPackageManager())
if (choices[i] == 0) { == null;
entries[i] = getString(R.string.never);
} else {
entries[i] = TimeFrameUtils.resolve(this, 1000L * choices[i]);
}
}
automaticMessageDeletionList.setEntries(entries);
automaticMessageDeletionList.setEntryValues(entryValues);
}
ListPreference quickAction =
(ListPreference) mSettingsFragment.findPreference("quick_action");
if (quickAction != null && (removeLocation || removeVoice)) {
ArrayList<CharSequence> entries =
new ArrayList<>(Arrays.asList(quickAction.getEntries()));
ArrayList<CharSequence> entryValues =
new ArrayList<>(Arrays.asList(quickAction.getEntryValues()));
int index = entryValues.indexOf("location");
if (index > 0 && removeLocation) {
entries.remove(index);
entryValues.remove(index);
}
index = entryValues.indexOf("voice");
if (index > 0 && removeVoice) {
entries.remove(index);
entryValues.remove(index);
}
quickAction.setEntries(entries.toArray(new CharSequence[entries.size()]));
quickAction.setEntryValues(entryValues.toArray(new CharSequence[entryValues.size()]));
}
boolean removeLocation = new Intent("eu.siacs.conversations.location.request").resolveActivity(getPackageManager()) == null; final Preference removeCertsPreference =
boolean removeVoice = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION).resolveActivity(getPackageManager()) == null; mSettingsFragment.findPreference("remove_trusted_certificates");
if (removeCertsPreference != null) {
removeCertsPreference.setOnPreferenceClickListener(
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;
}
final ArrayList<Integer> selectedItems = new ArrayList<>();
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,
(dialog, indexSelected, isChecked) -> {
if (isChecked) {
selectedItems.add(indexSelected);
} else if (selectedItems.contains(indexSelected)) {
selectedItems.remove(Integer.valueOf(indexSelected));
}
((AlertDialog) dialog)
.getButton(DialogInterface.BUTTON_POSITIVE)
.setEnabled(selectedItems.size() > 0);
});
ListPreference quickAction = (ListPreference) mSettingsFragment.findPreference("quick_action"); dialogBuilder.setPositiveButton(
if (quickAction != null && (removeLocation || removeVoice)) { getResources()
ArrayList<CharSequence> entries = new ArrayList<>(Arrays.asList(quickAction.getEntries())); .getString(R.string.dialog_manage_certs_positivebutton),
ArrayList<CharSequence> entryValues = new ArrayList<>(Arrays.asList(quickAction.getEntryValues())); (dialog, which) -> {
int index = entryValues.indexOf("location"); int count = selectedItems.size();
if (index > 0 && removeLocation) { if (count > 0) {
entries.remove(index); for (int i = 0; i < count; i++) {
entryValues.remove(index); try {
} Integer item =
index = entryValues.indexOf("voice"); Integer.valueOf(
if (index > 0 && removeVoice) { selectedItems.get(i).toString());
entries.remove(index); String alias = aliases.get(item);
entryValues.remove(index); mtm.deleteCertificate(alias);
} } catch (KeyStoreException e) {
quickAction.setEntries(entries.toArray(new CharSequence[entries.size()])); e.printStackTrace();
quickAction.setEntryValues(entryValues.toArray(new CharSequence[entryValues.size()])); 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;
});
}
final Preference removeCertsPreference = mSettingsFragment.findPreference("remove_trusted_certificates"); final Preference createBackupPreference = mSettingsFragment.findPreference("create_backup");
if (removeCertsPreference != null) { if (createBackupPreference != null) {
removeCertsPreference.setOnPreferenceClickListener(preference -> { createBackupPreference.setSummary(
final MemorizingTrustManager mtm = xmppConnectionService.getMemorizingTrustManager(); getString(
final ArrayList<String> aliases = Collections.list(mtm.getCertificates()); R.string.pref_create_backup_summary,
if (aliases.size() == 0) { FileBackend.getBackupDirectory(this).getAbsolutePath()));
displayToast(getString(R.string.toast_no_trusted_certs)); createBackupPreference.setOnPreferenceClickListener(
return true; preference -> {
} if (hasStoragePermission(REQUEST_CREATE_BACKUP)) {
final ArrayList<Integer> selectedItems = new ArrayList<>(); createBackup();
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(SettingsActivity.this); }
dialogBuilder.setTitle(getResources().getString(R.string.dialog_manage_certs_title)); return true;
dialogBuilder.setMultiChoiceItems(aliases.toArray(new CharSequence[aliases.size()]), null, });
(dialog, indexSelected, isChecked) -> { }
if (isChecked) {
selectedItems.add(indexSelected);
} else if (selectedItems.contains(indexSelected)) {
selectedItems.remove(Integer.valueOf(indexSelected));
}
((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(selectedItems.size() > 0);
});
dialogBuilder.setPositiveButton( if (Config.ONLY_INTERNAL_STORAGE) {
getResources().getString(R.string.dialog_manage_certs_positivebutton), (dialog, which) -> { final Preference cleanCachePreference = mSettingsFragment.findPreference("clean_cache");
int count = selectedItems.size(); if (cleanCachePreference != null) {
if (count > 0) { cleanCachePreference.setOnPreferenceClickListener(preference -> cleanCache());
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;
});
}
final Preference createBackupPreference = mSettingsFragment.findPreference("create_backup"); final Preference cleanPrivateStoragePreference =
if (createBackupPreference != null) { mSettingsFragment.findPreference("clean_private_storage");
createBackupPreference.setSummary(getString(R.string.pref_create_backup_summary, FileBackend.getBackupDirectory(this).getAbsolutePath())); if (cleanPrivateStoragePreference != null) {
createBackupPreference.setOnPreferenceClickListener(preference -> { cleanPrivateStoragePreference.setOnPreferenceClickListener(
if (hasStoragePermission(REQUEST_CREATE_BACKUP)) { preference -> cleanPrivateStorage());
createBackup(); }
} }
return true;
});
}
if (Config.ONLY_INTERNAL_STORAGE) { final Preference deleteOmemoPreference =
final Preference cleanCachePreference = mSettingsFragment.findPreference("clean_cache"); mSettingsFragment.findPreference("delete_omemo_identities");
if (cleanCachePreference != null) { if (deleteOmemoPreference != null) {
cleanCachePreference.setOnPreferenceClickListener(preference -> cleanCache()); deleteOmemoPreference.setOnPreferenceClickListener(
} preference -> deleteOmemoIdentities());
}
}
final Preference cleanPrivateStoragePreference = mSettingsFragment.findPreference("clean_private_storage"); private void changeOmemoSettingSummary() {
if (cleanPrivateStoragePreference != null) { ListPreference omemoPreference =
cleanPrivateStoragePreference.setOnPreferenceClickListener(preference -> cleanPrivateStorage()); (ListPreference) mSettingsFragment.findPreference(OMEMO_SETTING);
} if (omemoPreference != null) {
} String value = omemoPreference.getValue();
switch (value) {
case "always":
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_always);
break;
case "default_on":
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_on);
break;
case "default_off":
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_off);
break;
}
} else {
Log.d(Config.LOGTAG, "unable to find preference named " + OMEMO_SETTING);
}
}
final Preference deleteOmemoPreference = mSettingsFragment.findPreference("delete_omemo_identities"); private boolean isCallable(final Intent i) {
if (deleteOmemoPreference != null) { return i != null
deleteOmemoPreference.setOnPreferenceClickListener(preference -> deleteOmemoIdentities()); && getPackageManager()
} .queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY)
} .size()
> 0;
}
private void changeOmemoSettingSummary() { private boolean cleanCache() {
ListPreference omemoPreference = (ListPreference) mSettingsFragment.findPreference(OMEMO_SETTING); Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
if (omemoPreference != null) { intent.setData(Uri.parse("package:" + getPackageName()));
String value = omemoPreference.getValue(); startActivity(intent);
switch (value) { return true;
case "always": }
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_always);
break;
case "default_on":
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_on);
break;
case "default_off":
omemoPreference.setSummary(R.string.pref_omemo_setting_summary_default_off);
break;
}
} else {
Log.d(Config.LOGTAG,"unable to find preference named "+OMEMO_SETTING);
}
}
private boolean isCallable(final Intent i) { private boolean cleanPrivateStorage() {
return i != null && getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY).size() > 0; for (String type : Arrays.asList("Images", "Videos", "Files", "Recordings")) {
} cleanPrivateFiles(type);
}
return true;
}
private void cleanPrivateFiles(final String type) {
try {
File dir = new File(getFilesDir().getAbsolutePath(), "/" + type + "/");
File[] array = dir.listFiles();
if (array != null) {
for (int b = 0; b < array.length; b++) {
String name = array[b].getName().toLowerCase();
if (name.equals(".nomedia")) {
continue;
}
if (array[b].isFile()) {
array[b].delete();
}
}
}
} catch (Throwable e) {
Log.e("CleanCache", e.toString());
}
}
private boolean cleanCache() { private boolean deleteOmemoIdentities() {
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS); AlertDialog.Builder builder = new AlertDialog.Builder(this);
intent.setData(Uri.parse("package:" + getPackageName())); builder.setTitle(R.string.pref_delete_omemo_identities);
startActivity(intent); final List<CharSequence> accounts = new ArrayList<>();
return true; for (Account account : xmppConnectionService.getAccounts()) {
} if (account.isEnabled()) {
accounts.add(account.getJid().asBareJid().toString());
}
}
final boolean[] checkedItems = new boolean[accounts.size()];
builder.setMultiChoiceItems(
accounts.toArray(new CharSequence[accounts.size()]),
checkedItems,
(dialog, which, 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,
(dialog, which) -> {
for (int i = 0; i < checkedItems.length; ++i) {
if (checkedItems[i]) {
try {
Jid jid = Jid.of(accounts.get(i).toString());
Account account = xmppConnectionService.findAccountByJid(jid);
if (account != null) {
account.getAxolotlService().regenerateKeys(true);
}
} catch (IllegalArgumentException e) {
//
}
}
}
});
AlertDialog dialog = builder.create();
dialog.show();
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
return true;
}
private boolean cleanPrivateStorage() { @Override
for(String type : Arrays.asList("Images", "Videos", "Files", "Recordings")) { public void onStop() {
cleanPrivateFiles(type); super.onStop();
} PreferenceManager.getDefaultSharedPreferences(this)
return true; .unregisterOnSharedPreferenceChangeListener(this);
} }
private void cleanPrivateFiles(final String type) { @Override
try { public void onSharedPreferenceChanged(SharedPreferences preferences, String name) {
File dir = new File(getFilesDir().getAbsolutePath(), "/" + type + "/"); final List<String> resendPresence =
File[] array = dir.listFiles(); Arrays.asList(
if (array != null) { "confirm_messages",
for (int b = 0; b < array.length; b++) { DND_ON_SILENT_MODE,
String name = array[b].getName().toLowerCase(); AWAY_WHEN_SCREEN_IS_OFF,
if (name.equals(".nomedia")) { "allow_message_correction",
continue; TREAT_VIBRATE_AS_SILENT,
} MANUALLY_CHANGE_PRESENCE,
if (array[b].isFile()) { BROADCAST_LAST_ACTIVITY);
array[b].delete(); if (name.equals(OMEMO_SETTING)) {
} OmemoSetting.load(this, preferences);
} changeOmemoSettingSummary();
} } else if (name.equals(KEEP_FOREGROUND_SERVICE)) {
} catch (Throwable e) { xmppConnectionService.toggleForegroundService();
Log.e("CleanCache", e.toString()); } else if (resendPresence.contains(name)) {
} if (xmppConnectionServiceBound) {
} if (name.equals(AWAY_WHEN_SCREEN_IS_OFF) || name.equals(MANUALLY_CHANGE_PRESENCE)) {
xmppConnectionService.toggleScreenEventReceiver();
}
xmppConnectionService.refreshAllPresences();
}
} else if (name.equals("dont_trust_system_cas")) {
xmppConnectionService.updateMemorizingTrustmanager();
reconnectAccounts();
} else if (name.equals("use_tor")) {
if (preferences.getBoolean(name, false)) {
displayToast(getString(R.string.audio_video_disabled_tor));
}
reconnectAccounts();
xmppConnectionService.reinitializeMuclumbusService();
} else if (name.equals(AUTOMATIC_MESSAGE_DELETION)) {
xmppConnectionService.expireOldMessages(true);
} else if (name.equals(THEME)) {
final int theme = findTheme();
if (this.mTheme != theme) {
recreate();
}
} else if (name.equals(PREVENT_SCREENSHOTS)) {
SettingsUtils.applyScreenshotPreventionSetting(this);
}
}
private boolean deleteOmemoIdentities() { @Override
AlertDialog.Builder builder = new AlertDialog.Builder(this); public void onResume() {
builder.setTitle(R.string.pref_delete_omemo_identities); super.onResume();
final List<CharSequence> accounts = new ArrayList<>(); SettingsUtils.applyScreenshotPreventionSetting(this);
for (Account account : xmppConnectionService.getAccounts()) { }
if (account.isEnabled()) {
accounts.add(account.getJid().asBareJid().toString());
}
}
final boolean[] checkedItems = new boolean[accounts.size()];
builder.setMultiChoiceItems(accounts.toArray(new CharSequence[accounts.size()]), checkedItems, (dialog, which, 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, (dialog, which) -> {
for (int i = 0; i < checkedItems.length; ++i) {
if (checkedItems[i]) {
try {
Jid jid = Jid.of(accounts.get(i).toString());
Account account = xmppConnectionService.findAccountByJid(jid);
if (account != null) {
account.getAxolotlService().regenerateKeys(true);
}
} catch (IllegalArgumentException e) {
//
}
} @Override
} public void onRequestPermissionsResult(
}); int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
AlertDialog dialog = builder.create(); super.onRequestPermissionsResult(requestCode, permissions, grantResults);
dialog.show(); if (grantResults.length > 0)
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false); if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
return true; if (requestCode == REQUEST_CREATE_BACKUP) {
} createBackup();
}
} else {
Toast.makeText(
this,
getString(
R.string.no_storage_permission,
getString(R.string.app_name)),
Toast.LENGTH_SHORT)
.show();
}
}
@Override private void createBackup() {
public void onStop() { ContextCompat.startForegroundService(this, new Intent(this, ExportBackupService.class));
super.onStop(); final AlertDialog.Builder builder = new AlertDialog.Builder(this);
PreferenceManager.getDefaultSharedPreferences(this) builder.setMessage(R.string.backup_started_message);
.unregisterOnSharedPreferenceChangeListener(this); builder.setPositiveButton(R.string.ok, null);
} builder.create().show();
}
@Override private void displayToast(final String msg) {
public void onSharedPreferenceChanged(SharedPreferences preferences, String name) { runOnUiThread(() -> Toast.makeText(SettingsActivity.this, msg, Toast.LENGTH_LONG).show());
final List<String> resendPresence = Arrays.asList( }
"confirm_messages",
DND_ON_SILENT_MODE,
AWAY_WHEN_SCREEN_IS_OFF,
"allow_message_correction",
TREAT_VIBRATE_AS_SILENT,
MANUALLY_CHANGE_PRESENCE,
BROADCAST_LAST_ACTIVITY);
if (name.equals(OMEMO_SETTING)) {
OmemoSetting.load(this, preferences);
changeOmemoSettingSummary();
} else if (name.equals(KEEP_FOREGROUND_SERVICE)) {
xmppConnectionService.toggleForegroundService();
} else if (resendPresence.contains(name)) {
if (xmppConnectionServiceBound) {
if (name.equals(AWAY_WHEN_SCREEN_IS_OFF) || name.equals(MANUALLY_CHANGE_PRESENCE)) {
xmppConnectionService.toggleScreenEventReceiver();
}
xmppConnectionService.refreshAllPresences();
}
} else if (name.equals("dont_trust_system_cas")) {
xmppConnectionService.updateMemorizingTrustmanager();
reconnectAccounts();
} else if (name.equals("use_tor")) {
reconnectAccounts();
xmppConnectionService.reinitializeMuclumbusService();
} else if (name.equals(AUTOMATIC_MESSAGE_DELETION)) {
xmppConnectionService.expireOldMessages(true);
} else if (name.equals(THEME)) {
final int theme = findTheme();
if (this.mTheme != theme) {
recreate();
}
} else if(name.equals(PREVENT_SCREENSHOTS)){
SettingsUtils.applyScreenshotPreventionSetting(this);
}
}
@Override private void reconnectAccounts() {
public void onResume(){ for (Account account : xmppConnectionService.getAccounts()) {
super.onResume(); if (account.isEnabled()) {
SettingsUtils.applyScreenshotPreventionSetting(this); xmppConnectionService.reconnectAccountInBackground(account);
} }
}
@Override }
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (grantResults.length > 0)
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (requestCode == REQUEST_CREATE_BACKUP) {
createBackup();
}
} else {
Toast.makeText(this, getString(R.string.no_storage_permission, getString(R.string.app_name)), Toast.LENGTH_SHORT).show();
}
}
private void createBackup() {
ContextCompat.startForegroundService(this, new Intent(this, ExportBackupService.class));
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.backup_started_message);
builder.setPositiveButton(R.string.ok, null);
builder.create().show();
}
private void displayToast(final String msg) {
runOnUiThread(() -> Toast.makeText(SettingsActivity.this, msg, Toast.LENGTH_LONG).show());
}
private void reconnectAccounts() {
for (Account account : xmppConnectionService.getAccounts()) {
if (account.isEnabled()) {
xmppConnectionService.reconnectAccountInBackground(account);
}
}
}
public void refreshUiReal() {
//nothing to do. This Activity doesn't implement any listeners
}
public void refreshUiReal() {
// nothing to do. This Activity doesn't implement any listeners
}
} }

View file

@ -986,5 +986,6 @@
<string name="no_xmpp_adddress_found">No XMPP address found</string> <string name="no_xmpp_adddress_found">No XMPP address found</string>
<string name="account_status_temporary_auth_failure">Temporary authentication failure</string> <string name="account_status_temporary_auth_failure">Temporary authentication failure</string>
<string name="delete_avatar">Delete avatar</string> <string name="delete_avatar">Delete avatar</string>
<string name="audio_video_disabled_tor">Calls are disabled when using Tor</string>
</resources> </resources>