Skip to content

Commit

Permalink
MLS update (#2965)
Browse files Browse the repository at this point in the history
* MLS update

* Remove unused asset

* Add mls secret to build

* Log what Localization provider is being used for the SearchEngineManager

* Fix rebase conflicts

Co-authored-by: Randall E. Barker <simstorm@mac.com>
  • Loading branch information
keianhzo and bluemarvin committed Mar 17, 2020
1 parent 65a4aed commit 7f6d42c
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 125 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -75,3 +75,6 @@ tools/webgfx-tests-fxr/

# Room schemas
app/schemas/

# Token files
.mls_token
4 changes: 4 additions & 0 deletions .taskcluster.yml
Expand Up @@ -73,6 +73,7 @@ tasks:
- "secrets:get:project/firefoxreality/fr/github-deploy-key"
- "secrets:get:project/firefoxreality/fr/staging-signing-token"
- "secrets:get:project/firefoxreality/fr/symbols-token"
- "secrets:get:project/firefoxreality/fr/mls-key"
routes:
- notify.email.fxr-releng@mozilla.com.on-any
payload:
Expand All @@ -91,6 +92,7 @@ tasks:
&& rm -rf gvr-android-sdk && git clone https://github.com/MozillaReality/FirefoxReality-gvr-android-sdk.git gvr-android-sdk
&& git submodule update
&& . tools/taskcluster/get_third_party.sh
&& python tools/taskcluster/fetch_secret.py -s project/firefoxreality/fr/mls-key -o .mls_token -n key
&& cp tools/gradle/taskcluster.properties ./user.properties
&& ./gradlew --no-daemon --console=plain clean `python tools/taskcluster/build_targets.py =all`
&& python tools/taskcluster/fetch_secret.py -s project/firefoxreality/fr/staging-signing-token -o token -n token
Expand Down Expand Up @@ -123,6 +125,7 @@ tasks:
- "secrets:get:project/firefoxreality/fr/github-deploy-key"
- "secrets:get:project/firefoxreality/fr/release-signing-token"
- "secrets:get:project/firefoxreality/fr/symbols-token"
- "secrets:get:project/firefoxreality/fr/mls-key"
routes:
- notify.email.fxr-releng@mozilla.com.on-any
payload:
Expand All @@ -141,6 +144,7 @@ tasks:
&& rm -rf gvr-android-sdk && git clone https://github.com/MozillaReality/FirefoxReality-gvr-android-sdk.git gvr-android-sdk
&& git submodule update
&& . tools/taskcluster/get_third_party.sh
&& python tools/taskcluster/fetch_secret.py -s project/firefoxreality/fr/mls-key -o .mls_token -n key
&& cp tools/gradle/taskcluster.properties ./user.properties
&& ./gradlew --no-daemon --console=plain clean `python tools/taskcluster/build_targets.py ${event.release.tag_name}`
&& python tools/taskcluster/fetch_secret.py -s project/firefoxreality/fr/release-signing-token -o token -n token
Expand Down
19 changes: 19 additions & 0 deletions app/build.gradle
Expand Up @@ -477,6 +477,7 @@ dependencies {
implementation deps.android_components.browser_storage
implementation deps.android_components.browser_domains
implementation deps.android_components.service_accounts
implementation deps.android_components.mozilla_service_location
implementation deps.android_components.ui_autocomplete
implementation deps.android_components.concept_fetch
implementation deps.android_components.lib_fetch
Expand Down Expand Up @@ -558,6 +559,24 @@ if (gradle.hasProperty('localProperties.dependencySubstitutions.geckoviewTopsrcd
apply from: "${topsrcdir}/substitute-local-geckoview.gradle"
}

// -------------------------------------------------------------------------------------------------
// MLS: Read token from local file if it exists
// -------------------------------------------------------------------------------------------------

android.applicationVariants.all { variant ->
print("MLS token: ")

try {
def token = new File("${rootDir}/.mls_token").text.trim()
buildConfigField 'String', 'MLS_TOKEN', '"' + token + '"'
println "(Added from .mls_token file)"
} catch (FileNotFoundException ignored) {
buildConfigField 'String', 'MLS_TOKEN', '""'
println("X_X")
}

}

// -------------------------------------------------------------------------------------------------
// Dynamically set versionCode (See tools/build/versionCode.gradle
// -------------------------------------------------------------------------------------------------
Expand Down
Expand Up @@ -292,7 +292,7 @@ protected void onCreate(Bundle savedInstanceState) {
mSearchEngineWrapper = SearchEngineWrapper.get(this);
mSearchEngineWrapper.registerForUpdates();

GeolocationWrapper.update(this);
GeolocationWrapper.INSTANCE.update(this);

mConnectivityReceiver = new ConnectivityReceiver();
mPoorPerformanceWhiteList = new HashSet<>();
Expand Down
Expand Up @@ -16,6 +16,7 @@ object EngineProvider {

private var runtime: GeckoRuntime? = null
private var executor: GeckoWebExecutor? = null
private var client: GeckoViewFetchClient? = null

@Synchronized
fun getOrCreateRuntime(context: Context): GeckoRuntime {
Expand Down Expand Up @@ -74,4 +75,12 @@ object EngineProvider {
return GeckoViewFetchClient(context)
}

fun getDefaultClient(context: Context): GeckoViewFetchClient {
if (client == null) {
client = createClient(context)
}

return client!!
}

}
Expand Up @@ -1430,7 +1430,9 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
if (mContext != null) {
if (key.equals(mContext.getString(R.string.settings_key_geolocation_data))) {
GeolocationData data = GeolocationData.parse(sharedPreferences.getString(key, null));
setRegion(data.getCountryCode());
if (data != null) {
setRegion(data.getCountryCode());
}
}
}
}
Expand Down

This file was deleted.

Expand Up @@ -7,6 +7,7 @@
import org.mozilla.vrbrowser.utils.SystemUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
* Class representing a Geolocation success response (HTTP 200)
Expand All @@ -15,6 +16,9 @@ public class GeolocationData {

private static final String LOGTAG = SystemUtils.createLogtag(GeolocationData.class);

private static final String COUNTRY_CODE = "country_code";
private static final String COUNTRY_NAME = "country_name";

private JSONObject mData;

private GeolocationData(JSONObject data) {
Expand All @@ -27,6 +31,19 @@ public static GeolocationData create(JSONObject data) {
}

@NonNull
public static GeolocationData create(String countryCode, String countryName) {
JSONObject json = new JSONObject();
try {
json.put(COUNTRY_CODE, countryCode);
json.put(COUNTRY_NAME, countryName);

} catch (JSONException e) {
e.printStackTrace();
}
return GeolocationData.create(json);
}

@Nullable
public static GeolocationData parse(String aGeolocationJson) {
try {
return GeolocationData.create(new JSONObject(aGeolocationJson));
Expand All @@ -38,11 +55,11 @@ public static GeolocationData parse(String aGeolocationJson) {
}

public String getCountryCode() {
return mData.optString("country_code", "");
return mData.optString(COUNTRY_CODE, "");
}

public String getCountryName() {
return mData.optString("country_name", "");
return mData.optString(COUNTRY_NAME, "");
}

@Override
Expand Down

This file was deleted.

@@ -0,0 +1,40 @@
package org.mozilla.vrbrowser.geolocation

import android.content.Context
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.future.future
import kotlinx.coroutines.launch
import mozilla.components.service.location.MozillaLocationService
import org.mozilla.vrbrowser.browser.engine.EngineProvider
import org.mozilla.vrbrowser.browser.SettingsStore
import java.util.concurrent.CompletableFuture

object GeolocationWrapper {

fun update(context: Context) {
val locationService = MozillaLocationService(
context,
EngineProvider.getDefaultClient(context),
org.mozilla.vrbrowser.BuildConfig.MLS_TOKEN
)
CoroutineScope(Dispatchers.IO).launch {
locationService.fetchRegion(true)?.run {
val data: GeolocationData = GeolocationData.create(countryCode, countryName)
SettingsStore.getInstance(context).setGeolocationData(data.toString())
}
}
}

fun get(context: Context): CompletableFuture<MozillaLocationService.Region?> =
GlobalScope.future {
val locationService = MozillaLocationService(
context,
EngineProvider.getDefaultClient(context),
org.mozilla.vrbrowser.BuildConfig.MLS_TOKEN
)
locationService.fetchRegion(false)
}

}
Expand Up @@ -23,6 +23,12 @@ public class GeolocationLocalizationProvider implements SearchLocalizationProvid
mRegion = data.getCountryCode();
}

GeolocationLocalizationProvider(@NonNull String countryCode, @NonNull String region) {
mCountry = countryCode;
mLanguage = Locale.getDefault().getLanguage();
mRegion = region;
}

@Nullable
@Override
public SearchLocalization determineRegion(@NonNull Continuation<? super SearchLocalization> continuation) {
Expand Down
Expand Up @@ -7,6 +7,7 @@
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.util.Log;

import androidx.annotation.NonNull;

Expand Down Expand Up @@ -140,7 +141,7 @@ public String getIdentifier() {
private BroadcastReceiver mLocaleChangedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() == Intent.ACTION_LOCALE_CHANGED) {
if (intent.getAction().equals(Intent.ACTION_LOCALE_CHANGED)) {
setupSearchEngine(context, EMPTY);
}
}
Expand All @@ -157,10 +158,12 @@ private void setupSearchEngine(@NonNull Context aContext, String userPref) {

GeolocationData data = GeolocationData.parse(SettingsStore.getInstance(aContext).getGeolocationData());
if (data == null) {
Log.d(LOGTAG, "Using Locale based search localization provider");
// If we don't have geolocation data we default to the Locale search localization provider
mLocalizationProvider = new LocaleSearchLocalizationProvider();

} else {
Log.d(LOGTAG, "Using Geolocation based search localization provider: " + data.toString());
// If we have geolocation data we initialize the provider with the received data
// and setup a filter to filter the engines that we need to override for FxR.
mLocalizationProvider = new GeolocationLocalizationProvider(data);
Expand Down Expand Up @@ -199,7 +202,7 @@ private String getEngine(String aCountryCode) {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (mContext != null) {
if (key == mContext.getString(R.string.settings_key_geolocation_data)) {
if (key.equals(mContext.getString(R.string.settings_key_geolocation_data))) {
setupSearchEngine(mContext, EMPTY);
}
}
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values/non_L10n.xml
Expand Up @@ -181,8 +181,6 @@
<string name="keyboard_nl_NL_popup_i" translatable="false">ìíiïîįī</string>

<!-- SEARCH ENGINES -->
<!-- The MLS policy has been updated and now we can't use it without an API key anymore -->
<string name="geolocation_api_url" translatable="false">https://location.services.mozilla.com/v1/country?key=fff72d56-b040-4205-9a11-82feda9d83a3</string>
<!-- Google -->
<string name="search_google_params" translatable="false">q=%1$s&amp;client=firefox-b-o</string>
<string name="search_google_us_params" translatable="false">q=%1$s&amp;client=firefox-b-1-o</string>
Expand Down
1 change: 1 addition & 0 deletions versions.gradle
Expand Up @@ -71,6 +71,7 @@ android_components.browser_search = "org.mozilla.components:browser-search:$vers
android_components.browser_storage = "org.mozilla.components:browser-storage-sync:$versions.android_components"
android_components.browser_domains = "org.mozilla.components:browser-domains:$versions.android_components"
android_components.service_accounts = "org.mozilla.components:service-firefox-accounts:$versions.android_components"
android_components.mozilla_service_location = "org.mozilla.components:service-location:${versions.android_components}"
android_components.ui_autocomplete = "org.mozilla.components:ui-autocomplete:$versions.android_components"
android_components.concept_fetch = "org.mozilla.components:concept-fetch:$versions.android_components"
android_components.lib_fetch = "org.mozilla.components:lib-fetch-httpurlconnection:$versions.android_components"
Expand Down

0 comments on commit 7f6d42c

Please sign in to comment.