Bug 1437699 - Expand Leanplum in other countries/locales for our Android users; r?mcomella
Added a new SwitchBoard check for locale [language_country] to allow for better targeting of specific SwitchBoard experiments.
MozReview-Commit-ID: DxVljJwCeoo
--- a/mobile/android/base/java/org/mozilla/gecko/switchboard/SwitchBoard.java
+++ b/mobile/android/base/java/org/mozilla/gecko/switchboard/SwitchBoard.java
@@ -76,16 +76,17 @@ public class SwitchBoard {
private static final String KEY_DATA = "data";
private static final String KEY_NAME = "name";
private static final String KEY_MATCH = "match";
private static final String KEY_BUCKETS = "buckets";
private static final String KEY_VALUES = "values";
// Match keys.
private static final String KEY_APP_ID = "appId";
+ private static final String KEY_LOCALE = "locale";
private static final String KEY_COUNTRY = "country";
private static final String KEY_REGION = "regions";
private static final String KEY_DEVICE = "device";
private static final String KEY_LANG = "lang";
private static final String KEY_MANUFACTURER = "manufacturer";
private static final String KEY_VERSION = "version";
// Bucket keys.
@@ -231,17 +232,33 @@ public class SwitchBoard {
&& !packageName.matches(expectedAppIdPattern)) {
return false;
}
} catch (JSONException e) {
Log.e(TAG, "Exception matching appId", e);
}
}
- if (matchKeys.has(KEY_COUNTRY)) {
+ // Allows for checking [language_country] locale. See Bug 1437699
+ if (matchKeys.has(KEY_LOCALE)) {
+ try {
+ final String locale = Locale.getDefault().toString();
+ final String expectedLocalePattern = matchKeys.getString(KEY_LOCALE);
+
+ if (!TextUtils.isEmpty(expectedLocalePattern)
+ && !locale.matches(expectedLocalePattern)) {
+ return false;
+ }
+ } catch (MissingResourceException | JSONException e) {
+ Log.e(TAG, "Exception matching locale", e);
+ }
+ }
+
+ // Full locale [language_country] means country alone should not be checked
+ if (matchKeys.has(KEY_COUNTRY) && !matchKeys.has(KEY_LOCALE)) {
try {
final String country = Locale.getDefault().getISO3Country();
final String expectedCountryPattern = matchKeys.getString(KEY_COUNTRY);
if (!TextUtils.isEmpty(expectedCountryPattern)
&& !country.matches(expectedCountryPattern)) {
return false;
}
@@ -259,17 +276,18 @@ public class SwitchBoard {
&& !device.matches(expectedDevicePattern)) {
return false;
}
} catch (JSONException e) {
Log.e(TAG, "Exception matching device", e);
}
}
- if (matchKeys.has(KEY_LANG)) {
+ // Full locale [language_country] means language alone should not be checked
+ if (matchKeys.has(KEY_LANG) && !matchKeys.has(KEY_LOCALE)) {
try {
final String lang = Locale.getDefault().getISO3Language();
final String expectedLanguagePattern = matchKeys.getString(KEY_LANG);
if (!TextUtils.isEmpty(expectedLanguagePattern)
&& !lang.matches(expectedLanguagePattern)) {
return false;
}