mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 23:29:52 +01:00
Move security settings into own screen
This commit is contained in:
@@ -37,6 +37,7 @@ import org.briarproject.briar.android.conversation.glide.BriarModelLoader;
|
|||||||
import org.briarproject.briar.android.logging.CachingLogHandler;
|
import org.briarproject.briar.android.logging.CachingLogHandler;
|
||||||
import org.briarproject.briar.android.login.SignInReminderReceiver;
|
import org.briarproject.briar.android.login.SignInReminderReceiver;
|
||||||
import org.briarproject.briar.android.settings.ConnectionsFragment;
|
import org.briarproject.briar.android.settings.ConnectionsFragment;
|
||||||
|
import org.briarproject.briar.android.settings.SecurityFragment;
|
||||||
import org.briarproject.briar.android.view.EmojiTextInputView;
|
import org.briarproject.briar.android.view.EmojiTextInputView;
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
import org.briarproject.briar.api.android.DozeWatchdog;
|
import org.briarproject.briar.api.android.DozeWatchdog;
|
||||||
@@ -196,4 +197,6 @@ public interface AndroidComponent
|
|||||||
void inject(BriarModelLoader briarModelLoader);
|
void inject(BriarModelLoader briarModelLoader);
|
||||||
|
|
||||||
void inject(ConnectionsFragment connectionsFragment);
|
void inject(ConnectionsFragment connectionsFragment);
|
||||||
|
|
||||||
|
void inject(SecurityFragment securityFragment);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ import static android.os.SystemClock.elapsedRealtime;
|
|||||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
import static org.briarproject.briar.android.settings.SettingsFragment.PREF_SCREEN_LOCK;
|
import static org.briarproject.briar.android.settings.SecurityFragment.PREF_SCREEN_LOCK;
|
||||||
import static org.briarproject.briar.android.settings.SettingsFragment.PREF_SCREEN_LOCK_TIMEOUT;
|
import static org.briarproject.briar.android.settings.SecurityFragment.PREF_SCREEN_LOCK_TIMEOUT;
|
||||||
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.hasScreenLock;
|
import static org.briarproject.briar.android.util.UiUtils.hasScreenLock;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
package org.briarproject.briar.android.settings;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
|
import org.briarproject.briar.R;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.preference.ListPreference;
|
||||||
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
|
import static org.briarproject.briar.android.AppModule.getAndroidComponent;
|
||||||
|
import static org.briarproject.briar.android.settings.SettingsActivity.enableAndPersist;
|
||||||
|
import static org.briarproject.briar.android.util.UiUtils.hasScreenLock;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
|
public class SecurityFragment extends PreferenceFragmentCompat {
|
||||||
|
|
||||||
|
public static final String PREF_SCREEN_LOCK = "pref_key_lock";
|
||||||
|
public static final String PREF_SCREEN_LOCK_TIMEOUT =
|
||||||
|
"pref_key_lock_timeout";
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
|
||||||
|
private SettingsViewModel viewModel;
|
||||||
|
private SwitchPreference screenLock;
|
||||||
|
private ListPreference screenLockTimeout;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(@NonNull Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
getAndroidComponent(context).inject(this);
|
||||||
|
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
|
||||||
|
.get(SettingsViewModel.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreatePreferences(Bundle bundle, String s) {
|
||||||
|
addPreferencesFromResource(R.xml.settings_security);
|
||||||
|
getPreferenceManager().setPreferenceDataStore(viewModel.settingsStore);
|
||||||
|
|
||||||
|
screenLock = findPreference(PREF_SCREEN_LOCK);
|
||||||
|
screenLockTimeout =
|
||||||
|
requireNonNull(findPreference(PREF_SCREEN_LOCK_TIMEOUT));
|
||||||
|
|
||||||
|
screenLockTimeout.setSummaryProvider(preference -> {
|
||||||
|
CharSequence timeout = screenLockTimeout.getValue();
|
||||||
|
String never = getString(R.string.pref_lock_timeout_value_never);
|
||||||
|
if (timeout.equals(never)) {
|
||||||
|
return getString(R.string.pref_lock_timeout_never_summary);
|
||||||
|
} else {
|
||||||
|
return getString(R.string.pref_lock_timeout_summary,
|
||||||
|
screenLockTimeout.getEntry());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
if (SDK_INT < 21) {
|
||||||
|
screenLock.setVisible(false);
|
||||||
|
screenLockTimeout.setVisible(false);
|
||||||
|
} else {
|
||||||
|
LifecycleOwner lifecycleOwner = getViewLifecycleOwner();
|
||||||
|
if (getActivity() != null && hasScreenLock(getActivity())) {
|
||||||
|
viewModel.getScreenLockEnabled().observe(lifecycleOwner, on -> {
|
||||||
|
screenLock.setChecked(on);
|
||||||
|
enableAndPersist(screenLock);
|
||||||
|
});
|
||||||
|
screenLock.setSummary(R.string.pref_lock_summary);
|
||||||
|
} else {
|
||||||
|
screenLock.setEnabled(false);
|
||||||
|
screenLock.setChecked(false);
|
||||||
|
screenLock.setSummary(R.string.pref_lock_disabled_summary);
|
||||||
|
}
|
||||||
|
// timeout depends on screenLock and gets disabled automatically
|
||||||
|
viewModel.getScreenLockTimeout().observe(lifecycleOwner, value -> {
|
||||||
|
screenLockTimeout.setValue(value);
|
||||||
|
enableAndPersist(screenLockTimeout);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
requireActivity().setTitle(R.string.security_settings_title);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -32,7 +32,6 @@ import javax.inject.Inject;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.preference.ListPreference;
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
@@ -61,7 +60,6 @@ import static org.briarproject.bramble.util.LogUtils.logException;
|
|||||||
import static org.briarproject.bramble.util.LogUtils.now;
|
import static org.briarproject.bramble.util.LogUtils.now;
|
||||||
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
||||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_RINGTONE;
|
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_RINGTONE;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.hasScreenLock;
|
|
||||||
import static org.briarproject.briar.android.util.UiUtils.triggerFeedback;
|
import static org.briarproject.briar.android.util.UiUtils.triggerFeedback;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.BLOG_CHANNEL_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.BLOG_CHANNEL_ID;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.CONTACT_CHANNEL_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.CONTACT_CHANNEL_ID;
|
||||||
@@ -82,17 +80,12 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
implements EventListener, OnPreferenceChangeListener {
|
implements EventListener, OnPreferenceChangeListener {
|
||||||
|
|
||||||
public static final String SETTINGS_NAMESPACE = "android-ui";
|
public static final String SETTINGS_NAMESPACE = "android-ui";
|
||||||
public static final String PREF_SCREEN_LOCK = "pref_key_lock";
|
|
||||||
public static final String PREF_SCREEN_LOCK_TIMEOUT =
|
|
||||||
"pref_key_lock_timeout";
|
|
||||||
public static final String NOTIFY_SIGN_IN = "pref_key_notify_sign_in";
|
public static final String NOTIFY_SIGN_IN = "pref_key_notify_sign_in";
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(SettingsFragment.class.getName());
|
Logger.getLogger(SettingsFragment.class.getName());
|
||||||
|
|
||||||
private SettingsActivity listener;
|
private SettingsActivity listener;
|
||||||
private SwitchPreference screenLock;
|
|
||||||
private ListPreference screenLockTimeout;
|
|
||||||
private SwitchPreference notifyPrivateMessages;
|
private SwitchPreference notifyPrivateMessages;
|
||||||
private SwitchPreference notifyGroupMessages;
|
private SwitchPreference notifyGroupMessages;
|
||||||
private SwitchPreference notifyForumPosts;
|
private SwitchPreference notifyForumPosts;
|
||||||
@@ -121,8 +114,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
public void onCreatePreferences(Bundle bundle, String s) {
|
public void onCreatePreferences(Bundle bundle, String s) {
|
||||||
addPreferencesFromResource(R.xml.settings);
|
addPreferencesFromResource(R.xml.settings);
|
||||||
|
|
||||||
screenLock = findPreference(PREF_SCREEN_LOCK);
|
|
||||||
screenLockTimeout = findPreference(PREF_SCREEN_LOCK_TIMEOUT);
|
|
||||||
notifyPrivateMessages =
|
notifyPrivateMessages =
|
||||||
findPreference("pref_key_notify_private_messages");
|
findPreference("pref_key_notify_private_messages");
|
||||||
notifyGroupMessages = findPreference("pref_key_notify_group_messages");
|
notifyGroupMessages = findPreference("pref_key_notify_group_messages");
|
||||||
@@ -131,9 +122,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
notifyVibration = findPreference("pref_key_notify_vibration");
|
notifyVibration = findPreference("pref_key_notify_vibration");
|
||||||
notifySound = findPreference("pref_key_notify_sound");
|
notifySound = findPreference("pref_key_notify_sound");
|
||||||
|
|
||||||
screenLock.setOnPreferenceChangeListener(this);
|
|
||||||
screenLockTimeout.setOnPreferenceChangeListener(this);
|
|
||||||
|
|
||||||
Preference prefFeedback =
|
Preference prefFeedback =
|
||||||
requireNonNull(findPreference("pref_key_send_feedback"));
|
requireNonNull(findPreference("pref_key_send_feedback"));
|
||||||
prefFeedback.setOnPreferenceClickListener(preference -> {
|
prefFeedback.setOnPreferenceClickListener(preference -> {
|
||||||
@@ -200,8 +188,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
// due to events, we might try to display before a load completed
|
// due to events, we might try to display before a load completed
|
||||||
if (!settingsLoaded) return;
|
if (!settingsLoaded) return;
|
||||||
|
|
||||||
displayScreenLockSetting();
|
|
||||||
|
|
||||||
if (SDK_INT < 26) {
|
if (SDK_INT < 26) {
|
||||||
notifyPrivateMessages.setChecked(settings.getBoolean(
|
notifyPrivateMessages.setChecked(settings.getBoolean(
|
||||||
PREF_NOTIFY_PRIVATE, true));
|
PREF_NOTIFY_PRIVATE, true));
|
||||||
@@ -253,12 +239,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
|
|
||||||
private void setSettingsEnabled(boolean enabled) {
|
private void setSettingsEnabled(boolean enabled) {
|
||||||
// preferences not needed here, because handled by SharedPreferences:
|
// preferences not needed here, because handled by SharedPreferences:
|
||||||
// - pref_key_theme
|
|
||||||
// - pref_key_notify_sign_in
|
// - pref_key_notify_sign_in
|
||||||
// preferences partly needed here, because they have their own logic
|
|
||||||
// - pref_key_lock (screenLock -> displayScreenLockSetting())
|
|
||||||
// - pref_key_lock_timeout (screenLockTimeout)
|
|
||||||
if (!enabled) screenLock.setEnabled(false);
|
|
||||||
notifyPrivateMessages.setEnabled(enabled);
|
notifyPrivateMessages.setEnabled(enabled);
|
||||||
notifyGroupMessages.setEnabled(enabled);
|
notifyGroupMessages.setEnabled(enabled);
|
||||||
notifyForumPosts.setEnabled(enabled);
|
notifyForumPosts.setEnabled(enabled);
|
||||||
@@ -267,42 +248,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
notifySound.setEnabled(enabled);
|
notifySound.setEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayScreenLockSetting() {
|
|
||||||
if (SDK_INT < 21) {
|
|
||||||
screenLock.setVisible(false);
|
|
||||||
screenLockTimeout.setVisible(false);
|
|
||||||
} else {
|
|
||||||
if (getActivity() != null && hasScreenLock(getActivity())) {
|
|
||||||
screenLock.setEnabled(true);
|
|
||||||
screenLock.setChecked(
|
|
||||||
settings.getBoolean(PREF_SCREEN_LOCK, false));
|
|
||||||
screenLock.setSummary(R.string.pref_lock_summary);
|
|
||||||
} else {
|
|
||||||
screenLock.setEnabled(false);
|
|
||||||
screenLock.setChecked(false);
|
|
||||||
screenLock.setSummary(R.string.pref_lock_disabled_summary);
|
|
||||||
}
|
|
||||||
// timeout depends on screenLock and gets disabled automatically
|
|
||||||
int timeout = settings.getInt(PREF_SCREEN_LOCK_TIMEOUT,
|
|
||||||
Integer.valueOf(getString(
|
|
||||||
R.string.pref_lock_timeout_value_default)));
|
|
||||||
String newValue = String.valueOf(timeout);
|
|
||||||
screenLockTimeout.setValue(newValue);
|
|
||||||
setScreenLockTimeoutSummary(newValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setScreenLockTimeoutSummary(String timeout) {
|
|
||||||
String never = getString(R.string.pref_lock_timeout_value_never);
|
|
||||||
if (timeout.equals(never)) {
|
|
||||||
screenLockTimeout
|
|
||||||
.setSummary(R.string.pref_lock_timeout_never_summary);
|
|
||||||
} else {
|
|
||||||
screenLockTimeout
|
|
||||||
.setSummary(R.string.pref_lock_timeout_summary);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@TargetApi(26)
|
@TargetApi(26)
|
||||||
private void setupNotificationPreference(SwitchPreference pref,
|
private void setupNotificationPreference(SwitchPreference pref,
|
||||||
String channelId, @StringRes int summary) {
|
String channelId, @StringRes int summary) {
|
||||||
@@ -352,17 +297,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
if (preference == screenLock) {
|
if (preference == notifyPrivateMessages) {
|
||||||
Settings s = new Settings();
|
|
||||||
s.putBoolean(PREF_SCREEN_LOCK, (Boolean) newValue);
|
|
||||||
storeSettings(s);
|
|
||||||
} else if (preference == screenLockTimeout) {
|
|
||||||
Settings s = new Settings();
|
|
||||||
String value = (String) newValue;
|
|
||||||
s.putInt(PREF_SCREEN_LOCK_TIMEOUT, Integer.parseInt(value));
|
|
||||||
storeSettings(s);
|
|
||||||
setScreenLockTimeoutSummary(value);
|
|
||||||
} else if (preference == notifyPrivateMessages) {
|
|
||||||
Settings s = new Settings();
|
Settings s = new Settings();
|
||||||
s.putBoolean(PREF_NOTIFY_PRIVATE, (Boolean) newValue);
|
s.putBoolean(PREF_NOTIFY_PRIVATE, (Boolean) newValue);
|
||||||
storeSettings(s);
|
storeSettings(s);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.preference.PreferenceDataStore;
|
import androidx.preference.PreferenceDataStore;
|
||||||
|
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||||
@@ -42,6 +43,8 @@ class SettingsStore extends PreferenceDataStore {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putBoolean(String key, boolean value) {
|
public void putBoolean(String key, boolean value) {
|
||||||
|
if (LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Store bool setting: " + key + "=" + value);
|
||||||
Settings s = new Settings();
|
Settings s = new Settings();
|
||||||
s.putBoolean(key, value);
|
s.putBoolean(key, value);
|
||||||
storeSettings(s);
|
storeSettings(s);
|
||||||
@@ -49,6 +52,8 @@ class SettingsStore extends PreferenceDataStore {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putInt(String key, int value) {
|
public void putInt(String key, int value) {
|
||||||
|
if (LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Store int setting: " + key + "=" + value);
|
||||||
Settings s = new Settings();
|
Settings s = new Settings();
|
||||||
s.putInt(key, value);
|
s.putInt(key, value);
|
||||||
storeSettings(s);
|
storeSettings(s);
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import org.briarproject.bramble.api.settings.event.SettingsUpdatedEvent;
|
|||||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
import org.briarproject.bramble.api.system.LocationUtils;
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
import org.briarproject.bramble.plugin.tor.CircumventionProvider;
|
import org.briarproject.bramble.plugin.tor.CircumventionProvider;
|
||||||
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.attachment.UnsupportedMimeTypeException;
|
import org.briarproject.briar.android.attachment.UnsupportedMimeTypeException;
|
||||||
import org.briarproject.briar.android.attachment.media.ImageCompressor;
|
import org.briarproject.briar.android.attachment.media.ImageCompressor;
|
||||||
import org.briarproject.briar.android.viewmodel.DbViewModel;
|
import org.briarproject.briar.android.viewmodel.DbViewModel;
|
||||||
@@ -50,6 +51,8 @@ import static org.briarproject.bramble.util.AndroidUtils.getSupportedImageConten
|
|||||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
import static org.briarproject.bramble.util.LogUtils.now;
|
import static org.briarproject.bramble.util.LogUtils.now;
|
||||||
|
import static org.briarproject.briar.android.settings.SecurityFragment.PREF_SCREEN_LOCK;
|
||||||
|
import static org.briarproject.briar.android.settings.SecurityFragment.PREF_SCREEN_LOCK_TIMEOUT;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class SettingsViewModel extends DbViewModel implements EventListener {
|
class SettingsViewModel extends DbViewModel implements EventListener {
|
||||||
@@ -81,6 +84,10 @@ class SettingsViewModel extends DbViewModel implements EventListener {
|
|||||||
new MutableLiveData<>();
|
new MutableLiveData<>();
|
||||||
private final MutableLiveEvent<Boolean> setAvatarFailed =
|
private final MutableLiveEvent<Boolean> setAvatarFailed =
|
||||||
new MutableLiveEvent<>();
|
new MutableLiveEvent<>();
|
||||||
|
private final MutableLiveData<Boolean> screenLockEnabled =
|
||||||
|
new MutableLiveData<>();
|
||||||
|
private final MutableLiveData<String> screenLockTimeout =
|
||||||
|
new MutableLiveData<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
SettingsViewModel(Application application,
|
SettingsViewModel(Application application,
|
||||||
@@ -128,6 +135,7 @@ class SettingsViewModel extends DbViewModel implements EventListener {
|
|||||||
try {
|
try {
|
||||||
long start = now();
|
long start = now();
|
||||||
settings = settingsManager.getSettings(SETTINGS_NAMESPACE);
|
settings = settingsManager.getSettings(SETTINGS_NAMESPACE);
|
||||||
|
updateSettings(settings);
|
||||||
connectionsManager.updateBtSetting(
|
connectionsManager.updateBtSetting(
|
||||||
settingsManager.getSettings(BT_NAMESPACE));
|
settingsManager.getSettings(BT_NAMESPACE));
|
||||||
connectionsManager.updateWifiSettings(
|
connectionsManager.updateWifiSettings(
|
||||||
@@ -159,7 +167,11 @@ class SettingsViewModel extends DbViewModel implements EventListener {
|
|||||||
if (e instanceof SettingsUpdatedEvent) {
|
if (e instanceof SettingsUpdatedEvent) {
|
||||||
SettingsUpdatedEvent s = (SettingsUpdatedEvent) e;
|
SettingsUpdatedEvent s = (SettingsUpdatedEvent) e;
|
||||||
String namespace = s.getNamespace();
|
String namespace = s.getNamespace();
|
||||||
if (namespace.equals(BT_NAMESPACE)) {
|
if (namespace.equals(SETTINGS_NAMESPACE)) {
|
||||||
|
LOG.info("Settings updated");
|
||||||
|
settings = s.getSettings();
|
||||||
|
updateSettings(settings);
|
||||||
|
} else if (namespace.equals(BT_NAMESPACE)) {
|
||||||
LOG.info("Bluetooth settings updated");
|
LOG.info("Bluetooth settings updated");
|
||||||
connectionsManager.updateBtSetting(s.getSettings());
|
connectionsManager.updateBtSetting(s.getSettings());
|
||||||
} else if (namespace.equals(WIFI_NAMESPACE)) {
|
} else if (namespace.equals(WIFI_NAMESPACE)) {
|
||||||
@@ -172,6 +184,16 @@ class SettingsViewModel extends DbViewModel implements EventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateSettings(Settings settings) {
|
||||||
|
screenLockEnabled.postValue(settings.getBoolean(PREF_SCREEN_LOCK,
|
||||||
|
false));
|
||||||
|
int defaultTimeout = Integer.parseInt(getApplication()
|
||||||
|
.getString(R.string.pref_lock_timeout_value_default));
|
||||||
|
screenLockTimeout.postValue(String.valueOf(
|
||||||
|
settings.getInt(PREF_SCREEN_LOCK_TIMEOUT, defaultTimeout)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
void setAvatar(Uri uri) {
|
void setAvatar(Uri uri) {
|
||||||
ioExecutor.execute(() -> {
|
ioExecutor.execute(() -> {
|
||||||
try {
|
try {
|
||||||
@@ -215,6 +237,14 @@ class SettingsViewModel extends DbViewModel implements EventListener {
|
|||||||
return setAvatarFailed;
|
return setAvatarFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LiveData<Boolean> getScreenLockEnabled() {
|
||||||
|
return screenLockEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
LiveData<String> getScreenLockTimeout() {
|
||||||
|
return screenLockTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
ConnectionsManager getConnectionsManager() {
|
ConnectionsManager getConnectionsManager() {
|
||||||
return connectionsManager;
|
return connectionsManager;
|
||||||
}
|
}
|
||||||
|
|||||||
10
briar-android/src/main/res/drawable/ic_settings_security.xml
Normal file
10
briar-android/src/main/res/drawable/ic_settings_security.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:tint="?android:attr/textColorPrimary"
|
||||||
|
android:viewportWidth="24.0"
|
||||||
|
android:viewportHeight="24.0">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM12,17c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2zM15.1,8L8.9,8L8.9,6c0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0 3.1,1.39 3.1,3.1v2z" />
|
||||||
|
</vector>
|
||||||
@@ -12,58 +12,10 @@
|
|||||||
app:fragment="org.briarproject.briar.android.settings.ConnectionsFragment"
|
app:fragment="org.briarproject.briar.android.settings.ConnectionsFragment"
|
||||||
app:icon="@drawable/ic_connect_without_contact" />
|
app:icon="@drawable/ic_connect_without_contact" />
|
||||||
|
|
||||||
<PreferenceCategory
|
<Preference
|
||||||
android:layout="@layout/preferences_category"
|
android:title="@string/security_settings_title"
|
||||||
android:title="@string/security_settings_title">
|
app:fragment="org.briarproject.briar.android.settings.SecurityFragment"
|
||||||
|
app:icon="@drawable/ic_settings_security" />
|
||||||
<SwitchPreference
|
|
||||||
android:enabled="false"
|
|
||||||
android:key="pref_key_lock"
|
|
||||||
android:persistent="false"
|
|
||||||
android:summary="@string/pref_lock_summary"
|
|
||||||
android:title="@string/pref_lock_title"
|
|
||||||
android:widgetLayout="@layout/preference_switch_compat"
|
|
||||||
app:iconSpaceReserved="false" />
|
|
||||||
|
|
||||||
<ListPreference
|
|
||||||
android:defaultValue="@string/pref_lock_timeout_value_default"
|
|
||||||
android:dependency="pref_key_lock"
|
|
||||||
android:entries="@array/pref_key_lock_timeout_entries"
|
|
||||||
android:entryValues="@array/pref_key_lock_timeout_values"
|
|
||||||
android:key="pref_key_lock_timeout"
|
|
||||||
android:persistent="false"
|
|
||||||
android:summary="@string/pref_lock_timeout_summary"
|
|
||||||
android:title="@string/pref_lock_timeout_title"
|
|
||||||
app:iconSpaceReserved="false" />
|
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:key="pref_key_change_password"
|
|
||||||
android:title="@string/change_password"
|
|
||||||
app:iconSpaceReserved="false">
|
|
||||||
|
|
||||||
<intent
|
|
||||||
android:targetClass="org.briarproject.briar.android.login.ChangePasswordActivity"
|
|
||||||
android:targetPackage="@string/app_package" />
|
|
||||||
</Preference>
|
|
||||||
|
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
<PreferenceCategory
|
|
||||||
android:layout="@layout/preferences_category"
|
|
||||||
android:title="@string/panic_setting_title">
|
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:summary="@string/panic_setting_hint"
|
|
||||||
android:title="@string/panic_setting"
|
|
||||||
app:iconSpaceReserved="false">
|
|
||||||
|
|
||||||
<intent
|
|
||||||
android:targetClass="org.briarproject.briar.android.panic.PanicPreferencesActivity"
|
|
||||||
android:targetPackage="@string/app_package" />
|
|
||||||
|
|
||||||
</Preference>
|
|
||||||
|
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:layout="@layout/preferences_category"
|
android:layout="@layout/preferences_category"
|
||||||
|
|||||||
54
briar-android/src/main/res/xml/settings_security.xml
Normal file
54
briar-android/src/main/res/xml/settings_security.xml
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:enabled="false"
|
||||||
|
android:key="pref_key_lock"
|
||||||
|
android:persistent="false"
|
||||||
|
android:summary="@string/pref_lock_summary"
|
||||||
|
android:title="@string/pref_lock_title"
|
||||||
|
android:widgetLayout="@layout/preference_switch_compat"
|
||||||
|
app:iconSpaceReserved="false" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="@string/pref_lock_timeout_value_default"
|
||||||
|
android:dependency="pref_key_lock"
|
||||||
|
android:enabled="false"
|
||||||
|
android:entries="@array/pref_key_lock_timeout_entries"
|
||||||
|
android:entryValues="@array/pref_key_lock_timeout_values"
|
||||||
|
android:key="pref_key_lock_timeout"
|
||||||
|
android:persistent="false"
|
||||||
|
android:title="@string/pref_lock_timeout_title"
|
||||||
|
app:iconSpaceReserved="false"
|
||||||
|
tools:summary="@string/pref_lock_timeout_summary" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="pref_key_change_password"
|
||||||
|
android:title="@string/change_password"
|
||||||
|
app:iconSpaceReserved="false">
|
||||||
|
|
||||||
|
<intent
|
||||||
|
android:targetClass="org.briarproject.briar.android.login.ChangePasswordActivity"
|
||||||
|
android:targetPackage="@string/app_package" />
|
||||||
|
</Preference>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:layout="@layout/preferences_category"
|
||||||
|
android:title="@string/panic_setting_title">
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:summary="@string/panic_setting_hint"
|
||||||
|
android:title="@string/panic_setting"
|
||||||
|
app:iconSpaceReserved="false">
|
||||||
|
|
||||||
|
<intent
|
||||||
|
android:targetClass="org.briarproject.briar.android.panic.PanicPreferencesActivity"
|
||||||
|
android:targetPackage="@string/app_package" />
|
||||||
|
|
||||||
|
</Preference>
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
||||||
Reference in New Issue
Block a user