-
Notifications
You must be signed in to change notification settings - Fork 215
/
SettingsStore.java
427 lines (347 loc) · 15.8 KB
/
SettingsStore.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
package org.mozilla.vrbrowser.browser;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.StrictMode;
import android.preference.PreferenceManager;
import org.mozilla.geckoview.GeckoSessionSettings;
import org.mozilla.telemetry.TelemetryHolder;
import org.mozilla.vrbrowser.BuildConfig;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.utils.LocaleUtils;
import androidx.annotation.NonNull;
import static org.mozilla.vrbrowser.utils.ServoUtils.isServoAvailable;
public class SettingsStore {
private static final String LOGTAG = "VRB";
private static SettingsStore mSettingsInstance;
public static synchronized @NonNull
SettingsStore getInstance(final @NonNull Context aContext) {
if (mSettingsInstance == null) {
mSettingsInstance = new SettingsStore(aContext);
}
return mSettingsInstance;
}
private Context mContext;
private SharedPreferences mPrefs;
// Developer options default values
public final static boolean REMOTE_DEBUGGING_DEFAULT = false;
public final static boolean CONSOLE_LOGS_DEFAULT = false;
public final static boolean ENV_OVERRIDE_DEFAULT = false;
public final static boolean MULTIPROCESS_DEFAULT = false;
public final static boolean TRACKING_DEFAULT = true;
public final static boolean SERVO_DEFAULT = false;
public final static int UA_MODE_DEFAULT = GeckoSessionSettings.USER_AGENT_MODE_VR;
public final static int INPUT_MODE_DEFAULT = 1;
public final static float DISPLAY_DENSITY_DEFAULT = 1.0f;
public final static int WINDOW_WIDTH_DEFAULT = 800;
public final static int WINDOW_HEIGHT_DEFAULT = 450;
public final static int DISPLAY_DPI_DEFAULT = 96;
public final static int MAX_WINDOW_WIDTH_DEFAULT = 1200;
public final static int MAX_WINDOW_HEIGHT_DEFAULT = 1200;
public final static int POINTER_COLOR_DEFAULT_DEFAULT = Color.parseColor("#FFFFFF");
public final static int SCROLL_DIRECTION_DEFAULT = 0;
public final static String ENV_DEFAULT = "offworld";
public final static float BROWSER_WORLD_WIDTH_DEFAULT = 4.0f;
public final static float BROWSER_WORLD_HEIGHT_DEFAULT = 2.25f;
public final static int MSAA_DEFAULT_LEVEL = 1;
public final static boolean AUDIO_ENABLED = false;
public final static float CYLINDER_DENSITY_ENABLED_DEFAULT = 4680.0f;
public final static int FOVEATED_APP_DEFAULT_LEVEL = 1;
public final static int FOVEATED_WEBVR_DEFAULT_LEVEL = 0;
// Enable telemetry by default (opt-out).
private final static boolean enableCrashReportingByDefault = false;
private final static boolean enableTelemetryByDefault = true;
private int mCachedScrollDirection = -1;
public SettingsStore(Context aContext) {
mContext = aContext;
mPrefs = PreferenceManager.getDefaultSharedPreferences(aContext);
}
public boolean isCrashReportingEnabled() {
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_crash), enableCrashReportingByDefault);
}
public void setCrashReportingEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_crash), isEnabled);
editor.commit();
}
public boolean isTelemetryEnabled() {
// The first access to shared preferences will require a disk read.
final StrictMode.ThreadPolicy threadPolicy = StrictMode.allowThreadDiskReads();
try {
return mPrefs.getBoolean(
mContext.getString(R.string.settings_key_telemetry), enableTelemetryByDefault);
} finally {
StrictMode.setThreadPolicy(threadPolicy);
}
}
public void setTelemetryEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_telemetry), isEnabled);
editor.commit();
// If the state of Telemetry is not the same, we reinitialize it.
final boolean hasEnabled = isTelemetryEnabled();
if (hasEnabled != isEnabled) {
TelemetryWrapper.init(mContext);
}
TelemetryHolder.get().getConfiguration().setUploadEnabled(isEnabled);
TelemetryHolder.get().getConfiguration().setCollectionEnabled(isEnabled);
}
public void setGeolocationData(String aGeolocationData) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString(mContext.getString(R.string.settings_key_geolocation_data), aGeolocationData);
editor.commit();
}
public String getGeolocationData() {
return mPrefs.getString(mContext.getString(R.string.settings_key_geolocation_data), "");
}
public boolean isRemoteDebuggingEnabled() {
return mPrefs.getBoolean(
mContext.getString(R.string.settings_key_remote_debugging), REMOTE_DEBUGGING_DEFAULT);
}
public void setRemoteDebuggingEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_remote_debugging), isEnabled);
editor.commit();
}
public boolean isConsoleLogsEnabled() {
return mPrefs.getBoolean(
mContext.getString(R.string.settings_key_console_logs), CONSOLE_LOGS_DEFAULT);
}
public void setConsoleLogsEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_console_logs), isEnabled);
editor.commit();
}
public boolean isTrackingProtectionEnabled() {
return mPrefs.getBoolean(
mContext.getString(R.string.settings_key_tracking_protection), TRACKING_DEFAULT);
}
public void setTrackingProtectionEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_tracking_protection), isEnabled);
editor.commit();
}
public boolean isEnvironmentOverrideEnabled() {
return mPrefs.getBoolean(
mContext.getString(R.string.settings_key_environment_override), ENV_OVERRIDE_DEFAULT);
}
public void setEnvironmentOverrideEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_environment_override), isEnabled);
editor.commit();
}
public boolean isMultiprocessEnabled() {
return mPrefs.getBoolean(
mContext.getString(R.string.settings_key_multiprocess), MULTIPROCESS_DEFAULT);
}
public void setMultiprocessEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_multiprocess), isEnabled);
editor.commit();
}
public boolean isServoEnabled() {
return isServoAvailable() && mPrefs.getBoolean(mContext.getString(R.string.settings_key_servo), SERVO_DEFAULT);
}
public void setServoEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_servo), isEnabled);
editor.commit();
}
public int getUaMode() {
return mPrefs.getInt(
mContext.getString(R.string.settings_key_user_agent_version), UA_MODE_DEFAULT);
}
public void setUaMode(int mode) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putInt(mContext.getString(R.string.settings_key_user_agent_version), mode);
editor.commit();
}
public int getInputMode() {
return mPrefs.getInt(
mContext.getString(R.string.settings_key_input_mode), INPUT_MODE_DEFAULT);
}
public void setInputMode(int aTouchMode) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putInt(mContext.getString(R.string.settings_key_input_mode), aTouchMode);
editor.commit();
}
public String getHomepage() {
return mPrefs.getString(
mContext.getString(R.string.settings_key_homepage),
mContext.getString(R.string.homepage_url));
}
public void setHomepage(String aHomepage) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString(mContext.getString(R.string.settings_key_homepage), aHomepage);
editor.commit();
}
public float getDisplayDensity() {
return mPrefs.getFloat(
mContext.getString(R.string.settings_key_display_density), DISPLAY_DENSITY_DEFAULT);
}
public void setDisplayDensity(float aDensity) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putFloat(mContext.getString(R.string.settings_key_display_density), aDensity);
editor.commit();
}
public int getWindowWidth() {
return mPrefs.getInt(
mContext.getString(R.string.settings_key_window_width), WINDOW_WIDTH_DEFAULT);
}
public void setWindowWidth(int aWindowWidth) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putInt(mContext.getString(R.string.settings_key_window_width), aWindowWidth);
editor.commit();
}
public int getWindowHeight() {
return mPrefs.getInt(
mContext.getString(R.string.settings_key_window_height), WINDOW_HEIGHT_DEFAULT);
}
public void setWindowHeight(int aWindowHeight) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putInt(mContext.getString(R.string.settings_key_window_height), aWindowHeight);
editor.commit();
}
public float getWindowAspect() {
return (float)getWindowWidth() / (float)getWindowHeight();
}
public int getDisplayDpi() {
return mPrefs.getInt(
mContext.getString(R.string.settings_key_display_dpi), DISPLAY_DPI_DEFAULT);
}
public void setDisplayDpi(int aDpi) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putInt(mContext.getString(R.string.settings_key_display_dpi), aDpi);
editor.commit();
}
public int getMaxWindowWidth() {
return mPrefs.getInt(
mContext.getString(R.string.settings_key_max_window_width), MAX_WINDOW_WIDTH_DEFAULT);
}
public void setMaxWindowWidth(int aMaxWindowWidth) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putInt(mContext.getString(R.string.settings_key_max_window_width), aMaxWindowWidth);
editor.commit();
}
public int getMaxWindowHeight() {
return mPrefs.getInt(
mContext.getString(R.string.settings_key_max_window_height), MAX_WINDOW_HEIGHT_DEFAULT);
}
public void setMaxWindowHeight(int aMaxWindowHeight) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putInt(mContext.getString(R.string.settings_key_max_window_height), aMaxWindowHeight);
editor.commit();
}
public String getEnvironment() {
return mPrefs.getString(mContext.getString(R.string.settings_key_env), ENV_DEFAULT);
}
public void setEnvironment(String aEnv) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString(mContext.getString(R.string.settings_key_env), aEnv);
editor.commit();
}
public float getBrowserWorldWidth() {
return mPrefs.getFloat(
mContext.getString(R.string.settings_key_browser_world_width), BROWSER_WORLD_WIDTH_DEFAULT);
}
public void setBrowserWorldWidth(float aBrowserWorldWidth) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putFloat(mContext.getString(R.string.settings_key_browser_world_width), aBrowserWorldWidth);
editor.commit();
}
public float getBrowserWorldHeight() {
return mPrefs.getFloat(
mContext.getString(R.string.settings_key_browser_world_height), BROWSER_WORLD_HEIGHT_DEFAULT);
}
public void setBrowserWorldHeight(float aBrowserWorldHeight) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putFloat(mContext.getString(R.string.settings_key_browser_world_height), aBrowserWorldHeight);
editor.commit();
}
public int getPointerColor() {
return mPrefs.getInt(
mContext.getString(R.string.settings_key_pointer_color), POINTER_COLOR_DEFAULT_DEFAULT);
}
public void setPointerColor(int color) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putInt(mContext.getString(R.string.settings_key_pointer_color), color);
editor.commit();
}
public int getScrollDirection() {
if (mCachedScrollDirection < 0) {
mCachedScrollDirection = mPrefs.getInt(mContext.getString(R.string.settings_key_scroll_direction), SCROLL_DIRECTION_DEFAULT);
}
return mCachedScrollDirection;
}
public void setScrollDirection(int aScrollDirection) {
mCachedScrollDirection = aScrollDirection;
SharedPreferences.Editor editor = mPrefs.edit();
editor.putInt(mContext.getString(R.string.settings_key_scroll_direction), aScrollDirection);
editor.commit();
}
public int getMSAALevel() {
return mPrefs.getInt(
mContext.getString(R.string.settings_key_msaa), MSAA_DEFAULT_LEVEL);
}
public void setMSAALevel(int level) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putInt(mContext.getString(R.string.settings_key_msaa), level);
editor.commit();
}
public boolean getLayersEnabled() {
if (BuildConfig.FLAVOR_platform.equalsIgnoreCase("oculusvr")) {
return true;
}
return false;
}
public int getTransparentBorderWidth() {
return 1;
}
public boolean isAudioEnabled() {
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_audio), AUDIO_ENABLED);
}
public void setAudioEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_audio), isEnabled);
editor.commit();
}
public String getVoiceSearchLanguage() {
String language = mPrefs.getString(
mContext.getString(R.string.settings_key_voice_search_language), null);
if (language == null) {
return LocaleUtils.getDefaultVoiceSearchLanguage(mContext);
}
return language;
}
public void setVoiceSearchLanguage(String language) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString(mContext.getString(R.string.settings_key_voice_search_language), language);
editor.commit();
}
public float getCylinderDensity() {
return mPrefs.getFloat(mContext.getString(R.string.settings_key_cylinder_density), 0);
}
public void setCylinderDensity(float aDensity) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putFloat(mContext.getString(R.string.settings_key_cylinder_density), aDensity);
}
public int getFoveatedLevelApp() {
return mPrefs.getInt(
mContext.getString(R.string.settings_key_foveated_app), FOVEATED_APP_DEFAULT_LEVEL);
}
public int getFoveatedLevelWebVR() {
return mPrefs.getInt(
mContext.getString(R.string.settings_key_foveated_webvr), FOVEATED_WEBVR_DEFAULT_LEVEL);
}
public void setFoveatedLevelApp(int level) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putInt(mContext.getString(R.string.settings_key_foveated_app), level);
editor.commit();
}
public void setFoveatedLevelWebVR(int level) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putInt(mContext.getString(R.string.settings_key_foveated_webvr), level);
editor.commit();
}
}