Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit a3dcb87

Browse files
authored
Support for remote environments + seasons cubemaps (#3561)
* Remote Environments * Remove environments
1 parent 4945fc7 commit a3dcb87

58 files changed

Lines changed: 950 additions & 68 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ android {
100100
targetCompatibility JavaVersion.VERSION_1_8
101101
}
102102

103+
kotlinOptions {
104+
jvmTarget = JavaVersion.VERSION_1_8.toString()
105+
}
106+
103107
buildTypes {
104108
release {
105109
minifyEnabled true

app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ protected void attachBaseContext(Context base) {
230230
protected void onCreate(Bundle savedInstanceState) {
231231
Bundle extras = getIntent() != null ? getIntent().getExtras() : null;
232232
SessionStore.prefOverrides(this, extras);
233-
((VRBrowserApplication)getApplication()).onActivityCreate();
233+
((VRBrowserApplication)getApplication()).onActivityCreate(this);
234234
SettingsStore.getInstance(getBaseContext()).setPid(Process.myPid());
235235
// Fix for infinite restart on startup crashes.
236236
long count = SettingsStore.getInstance(getBaseContext()).getCrashRestartCount();
@@ -316,6 +316,7 @@ protected void onCreate(Bundle savedInstanceState) {
316316
mLifeCycle.setCurrentState(Lifecycle.State.CREATED);
317317

318318
getServicesProvider().getDownloadsManager().init();
319+
getServicesProvider().getEnvironmentsManager().start();
319320
}
320321

321322
protected void initializeWidgets() {
@@ -519,6 +520,7 @@ protected void onDestroy() {
519520

520521
SessionStore.get().onDestroy();
521522

523+
getServicesProvider().getEnvironmentsManager().stop();
522524
getServicesProvider().getDownloadsManager().end();
523525

524526
super.onDestroy();
@@ -1140,7 +1142,7 @@ public boolean areLayersEnabled() {
11401142
@Keep
11411143
@SuppressWarnings("unused")
11421144
public String getActiveEnvironment() {
1143-
return SettingsStore.getInstance(this).getEnvironment();
1145+
return getServicesProvider().getEnvironmentsManager().getOrDownloadEnvironment();
11441146
}
11451147

11461148
@Keep

app/src/common/shared/org/mozilla/vrbrowser/VRBrowserApplication.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import android.content.Context;
1010
import android.content.res.Configuration;
1111

12+
import androidx.annotation.NonNull;
13+
1214
import com.mozilla.speechlibrary.SpeechService;
1315

1416
import org.mozilla.vrbrowser.browser.Accounts;
@@ -23,6 +25,7 @@
2325
import org.mozilla.vrbrowser.ui.adapters.Language;
2426
import org.mozilla.vrbrowser.ui.widgets.AppServicesProvider;
2527
import org.mozilla.vrbrowser.utils.BitmapCache;
28+
import org.mozilla.vrbrowser.utils.EnvironmentsManager;
2629
import org.mozilla.vrbrowser.utils.LocaleUtils;
2730

2831
public class VRBrowserApplication extends Application implements AppServicesProvider {
@@ -34,20 +37,22 @@ public class VRBrowserApplication extends Application implements AppServicesProv
3437
private Accounts mAccounts;
3538
private DownloadsManager mDownloadsManager;
3639
private SpeechService mSpeechService;
40+
private EnvironmentsManager mEnvironmentsManager;
3741

3842
@Override
3943
public void onCreate() {
4044
super.onCreate();
4145
}
4246

43-
protected void onActivityCreate() {
47+
protected void onActivityCreate(@NonNull Context activityContext) {
4448
mPlaces = new Places(this);
4549
mServices = new Services(this, mPlaces);
4650
mAccounts = new Accounts(this);
4751
mDownloadsManager = new DownloadsManager(this);
4852
mSpeechService = new SpeechService(this);
4953
mAppExecutors = new AppExecutors();
5054
mBitmapCache = new BitmapCache(this, mAppExecutors.diskIO(), mAppExecutors.mainThread());
55+
mEnvironmentsManager = new EnvironmentsManager(activityContext);
5156

5257
TelemetryWrapper.init(this, EngineProvider.INSTANCE.getDefaultClient(this));
5358
GleanMetricsService.init(this, EngineProvider.INSTANCE.getDefaultClient(this));
@@ -104,4 +109,9 @@ public DownloadsManager getDownloadsManager() {
104109
public SpeechService getSpeechService() {
105110
return mSpeechService;
106111
}
112+
113+
@Override
114+
public EnvironmentsManager getEnvironmentsManager() {
115+
return mEnvironmentsManager;
116+
}
107117
}

app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99

1010
import androidx.annotation.IntDef;
1111
import androidx.annotation.NonNull;
12+
import androidx.annotation.Nullable;
1213
import androidx.lifecycle.ViewModelProvider;
1314

15+
import com.google.gson.Gson;
16+
import com.google.gson.GsonBuilder;
17+
import com.google.gson.reflect.TypeToken;
18+
1419
import org.json.JSONArray;
1520
import org.json.JSONObject;
1621
import org.mozilla.geckoview.ContentBlocking;
@@ -26,15 +31,18 @@
2631
import org.mozilla.vrbrowser.ui.viewmodel.SettingsViewModel;
2732
import org.mozilla.vrbrowser.ui.widgets.menus.library.SortingContextMenuWidget;
2833
import org.mozilla.vrbrowser.utils.DeviceType;
34+
import org.mozilla.vrbrowser.utils.RemoteProperties;
2935
import org.mozilla.vrbrowser.utils.StringUtils;
3036
import org.mozilla.vrbrowser.utils.SystemUtils;
3137

3238
import java.io.IOException;
39+
import java.lang.reflect.Type;
3340
import java.nio.charset.StandardCharsets;
3441
import java.util.ArrayList;
3542
import java.util.Iterator;
3643
import java.util.List;
3744
import java.util.Locale;
45+
import java.util.Map;
3846

3947
import mozilla.components.concept.fetch.Request;
4048
import mozilla.components.concept.fetch.Response;
@@ -88,6 +96,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
8896
public final static int POINTER_COLOR_DEFAULT_DEFAULT = Color.parseColor("#FFFFFF");
8997
public final static int SCROLL_DIRECTION_DEFAULT = 0;
9098
public final static String ENV_DEFAULT = "offworld";
99+
public final static boolean ENV_EXTERNAL_DEFAULT = false;
91100
public final static int MSAA_DEFAULT_LEVEL = 0;
92101
public final static boolean AUDIO_ENABLED = false;
93102
public final static float CYLINDER_DENSITY_ENABLED_DEFAULT = 4680.0f;
@@ -129,7 +138,13 @@ public void initModel(@NonNull Context context) {
129138
(VRBrowserActivity)context,
130139
ViewModelProvider.AndroidViewModelFactory.getInstance(((VRBrowserActivity) context).getApplication()))
131140
.get(SettingsViewModel.class);
141+
142+
// Setup the stored properties until we get updated ones
143+
String json = mPrefs.getString(mContext.getString(R.string.settings_key_remote_props), null);
144+
mSettingsViewModel.setProps(json);
145+
132146
mSettingsViewModel.refresh();
147+
133148
update();
134149
}
135150

@@ -150,6 +165,7 @@ private void update() {
150165
Request.CookiePolicy.INCLUDE,
151166
false
152167
);
168+
153169
try {
154170
Response response = EngineProvider.INSTANCE.getDefaultClient(mContext).fetch(request);
155171
if (response.getStatus() == 200) {
@@ -159,15 +175,10 @@ private void update() {
159175
editor.commit();
160176

161177
mSettingsViewModel.setProps(json);
162-
163-
} else {
164-
String json = mPrefs.getString(mContext.getString(R.string.settings_key_remote_props), null);
165-
mSettingsViewModel.setProps(json);
166178
}
167179

168180
} catch (IOException e) {
169-
String json = mPrefs.getString(mContext.getString(R.string.settings_key_remote_props), null);
170-
mSettingsViewModel.setProps(json);
181+
Log.d(LOGTAG, "Remote properties error: " + e.getLocalizedMessage());
171182
}
172183
});
173184
}
@@ -806,4 +817,26 @@ public boolean isAutocompleteEnabled() {
806817
return mPrefs.getBoolean(mContext.getString(R.string.settings_key_autocomplete), AUTOCOMPLETE_ENABLED);
807818
}
808819

820+
@Nullable
821+
public Map<String, RemoteProperties> getRemoteProperties() {
822+
String json = mPrefs.getString(mContext.getString(R.string.settings_key_remote_props), null);
823+
824+
Gson gson = new GsonBuilder().create();
825+
Type type = new TypeToken<Map<String, RemoteProperties>>() {}.getType();
826+
827+
Map<String, RemoteProperties> propertiesMap = null;
828+
try {
829+
propertiesMap = gson.fromJson(json, type);
830+
831+
} catch (Exception ignored) { }
832+
833+
return propertiesMap;
834+
}
835+
836+
public void setRemoteProperties(@Nullable String json) {
837+
SharedPreferences.Editor editor = mPrefs.edit();
838+
editor.putString(mContext.getString(R.string.settings_key_remote_props), json);
839+
editor.commit();
840+
}
841+
809842
}

app/src/common/shared/org/mozilla/vrbrowser/downloads/Download.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.mozilla.vrbrowser.utils.LocaleUtils;
1313

1414
import java.io.File;
15+
import java.net.URI;
1516
import java.net.URL;
1617

1718
public class Download {
@@ -95,10 +96,18 @@ public long getDownloadedBytes() {
9596
return mDownloadedBytes;
9697
}
9798

98-
public String getOutputFile() {
99+
public String getOutputFileUri() {
99100
return mOutputFile;
100101
}
101102

103+
public String getOutputFilePath() {
104+
if (mOutputFile != null) {
105+
return URI.create(mOutputFile).getPath();
106+
}
107+
108+
return null;
109+
}
110+
102111
public String getTitle() {
103112
return mTitle;
104113
}

app/src/common/shared/org/mozilla/vrbrowser/downloads/DownloadJob.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public class DownloadJob {
1919
private String mDescription;
2020
private String mOutputPath;
2121

22+
public static DownloadJob create(@NonNull String uri) {
23+
return create(uri, null, 0, null, null);
24+
}
25+
2226
public static DownloadJob create(@NonNull String uri, @Nullable String contentType,
2327
long contentLength, @Nullable String filename) {
2428
return create(uri, contentType, contentLength, filename, null);

app/src/common/shared/org/mozilla/vrbrowser/downloads/DownloadsManager.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.mozilla.vrbrowser.downloads;
22

3-
import android.app.DownloadManager;
3+
import android.app.DownloadManager;
44
import android.content.BroadcastReceiver;
55
import android.content.Context;
66
import android.content.Intent;
@@ -10,14 +10,11 @@
1010
import android.os.Environment;
1111
import android.os.Handler;
1212
import android.os.Looper;
13-
import android.util.Log;
1413
import android.webkit.URLUtil;
1514

1615
import androidx.annotation.NonNull;
1716
import androidx.annotation.Nullable;
1817

19-
import com.mozilla.speechlibrary.utils.StorageUtils;
20-
2118
import org.mozilla.vrbrowser.browser.SettingsStore;
2219
import org.mozilla.vrbrowser.utils.UrlUtils;
2320

@@ -60,7 +57,7 @@ public void init() {
6057
List<Download> downloads = getDownloads();
6158
downloads.forEach(download -> {
6259
if (mDownloadManager != null &&
63-
!new File(UrlUtils.stripProtocol(download.getOutputFile())).exists()) {
60+
!new File(UrlUtils.stripProtocol(download.getOutputFileUri())).exists()) {
6461
mDownloadManager.remove(download.getId());
6562
}
6663
});
@@ -154,9 +151,9 @@ public void removeDownload(long downloadId, boolean deleteFiles) {
154151
Download download = getDownload(downloadId);
155152
if (download != null) {
156153
if (!deleteFiles) {
157-
File file = new File(UrlUtils.stripProtocol(download.getOutputFile()));
154+
File file = new File(UrlUtils.stripProtocol(download.getOutputFileUri()));
158155
if (file.exists()) {
159-
File newFile = new File(UrlUtils.stripProtocol(download.getOutputFile().concat(".bak")));
156+
File newFile = new File(UrlUtils.stripProtocol(download.getOutputFileUri().concat(".bak")));
160157
file.renameTo(newFile);
161158
if (mDownloadManager != null) {
162159
mDownloadManager.remove(downloadId);

app/src/common/shared/org/mozilla/vrbrowser/ui/viewmodel/SettingsViewModel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public void refresh() {
6464
}
6565

6666
private void isWhatsNewVisible() {
67-
boolean value = !BuildConfig.VERSION_NAME.equals(propsVersionName.getValue()) &&
67+
boolean value = props.getValue() != null &&
68+
!BuildConfig.VERSION_NAME.equals(propsVersionName.getValue()) &&
6869
props.getValue().containsKey(BuildConfig.VERSION_NAME);
6970
isWhatsNewVisible.postValue(new ObservableBoolean(value));
7071
}

app/src/common/shared/org/mozilla/vrbrowser/ui/views/library/DownloadsView.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void onHide() {
145145
public void onClick(@NonNull View view, @NonNull Download item) {
146146
mBinding.downloadsList.requestFocusFromTouch();
147147

148-
SessionStore.get().getActiveSession().loadUri(item.getOutputFile());
148+
SessionStore.get().getActiveSession().loadUri(item.getOutputFileUri());
149149

150150
WindowWidget window = mWidgetManager.getFocusedWindow();
151151
window.hidePanel(Windows.PanelType.HISTORY);
@@ -223,7 +223,7 @@ public void onShowContextMenu(@NonNull View view, Download item, boolean isLastV
223223
view,
224224
new DownloadsContextMenuWidget(getContext(),
225225
new DownloadsContextMenuWidget.DownloadsContextMenuItem(
226-
item.getOutputFile(),
226+
item.getOutputFileUri(),
227227
item.getTitle(),
228228
item.getId()),
229229
mWidgetManager.canOpenNewWindow()),

0 commit comments

Comments
 (0)