-
-
Notifications
You must be signed in to change notification settings - Fork 326
/
Prefs.java
117 lines (90 loc) · 3.96 KB
/
Prefs.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package org.torproject.android.service.util;
import android.content.Context;
import android.content.SharedPreferences;
import org.torproject.android.service.OrbotConstants;
import java.util.Locale;
public class Prefs {
private final static String PREF_BRIDGES_ENABLED = "pref_bridges_enabled";
private final static String PREF_BRIDGES_LIST = "pref_bridges_list";
private final static String PREF_DEFAULT_LOCALE = "pref_default_locale";
private final static String PREF_ENABLE_LOGGING = "pref_enable_logging";
private final static String PREF_EXPANDED_NOTIFICATIONS = "pref_expanded_notifications";
private final static String PREF_PERSIST_NOTIFICATIONS = "pref_persistent_notifications";
private final static String PREF_START_ON_BOOT = "pref_start_boot";
private final static String PREF_ALLOW_BACKGROUND_STARTS = "pref_allow_background_starts";
private final static String PREF_OPEN_PROXY_ON_ALL_INTERFACES = "pref_open_proxy_on_all_interfaces";
private final static String PREF_USE_VPN = "pref_vpn";
private final static String PREF_EXIT_NODES = "pref_exit_nodes";
private static SharedPreferences prefs;
public static void setContext(Context context) {
if (prefs == null)
prefs = getSharedPrefs(context);
}
private static void putBoolean(String key, boolean value) {
prefs.edit().putBoolean(key, value).apply();
}
private static void putString(String key, String value) {
prefs.edit().putString(key, value).apply();
}
public static boolean bridgesEnabled() {
//if phone is in Farsi, enable bridges by default
boolean bridgesEnabledDefault = Locale.getDefault().getLanguage().equals("fa");
return prefs.getBoolean(PREF_BRIDGES_ENABLED, bridgesEnabledDefault);
}
public static void putBridgesEnabled(boolean value) {
putBoolean(PREF_BRIDGES_ENABLED, value);
}
public static String getBridgesList() {
String defaultBridgeType = "obfs4";
if (Locale.getDefault().getLanguage().equals("fa"))
defaultBridgeType = "meek"; //if Farsi, use meek as the default bridge type
return prefs.getString(PREF_BRIDGES_LIST, defaultBridgeType);
}
public static void setBridgesList(String value) {
putString(PREF_BRIDGES_LIST, value);
}
public static String getDefaultLocale() {
return prefs.getString(PREF_DEFAULT_LOCALE, Locale.getDefault().getLanguage());
}
public static void setDefaultLocale(String value) {
putString(PREF_DEFAULT_LOCALE, value);
}
public static boolean expandedNotifications() {
return prefs.getBoolean(PREF_EXPANDED_NOTIFICATIONS, true);
}
public static boolean useDebugLogging() {
return prefs.getBoolean(PREF_ENABLE_LOGGING, false);
}
public static boolean persistNotifications() {
return prefs.getBoolean(PREF_PERSIST_NOTIFICATIONS, true);
}
public static boolean allowBackgroundStarts() {
return prefs.getBoolean(PREF_ALLOW_BACKGROUND_STARTS, true);
}
public static boolean openProxyOnAllInterfaces() {
return prefs.getBoolean(PREF_OPEN_PROXY_ON_ALL_INTERFACES, false);
}
public static boolean useVpn() {
return prefs.getBoolean(PREF_USE_VPN, false);
}
public static void putUseVpn(boolean value) {
putBoolean(PREF_USE_VPN, value);
}
public static boolean startOnBoot() {
return prefs.getBoolean(PREF_START_ON_BOOT, true);
}
public static void putStartOnBoot(boolean value) {
putBoolean(PREF_START_ON_BOOT, value);
}
public static String getExitNodes ()
{
return prefs.getString(PREF_EXIT_NODES, "");
}
public static void setExitNodes (String exits)
{
putString(PREF_EXIT_NODES,exits);
}
public static SharedPreferences getSharedPrefs (Context context) {
return context.getSharedPreferences(OrbotConstants.PREF_TOR_SHARED_PREFS,0 | Context.MODE_MULTI_PROCESS);
}
}