From d205dfb7bd73615cad2d81a168690ef0230eacc1 Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Mon, 26 Oct 2015 14:43:50 -0700 Subject: [PATCH] Bug 773050 - Decouple base and services: reflect BrowserLocaleManager. r=rnewman There are two pieces to this that are undesireable: * using reflection to access BrowserLocaleManager; * stuffing the contracts provided by base and consumed by services into the constants.jar. Expedience. --HG-- extra : commitid : 4iEPYo8ieFF extra : rebase_source : bbdbd98bc3b894994c487a083611d5b5e6ebabc2 --- mobile/android/base/BrowserLocaleManager.java | 2 ++ mobile/android/base/Locales.java | 15 ++++++++++-- .../upload/AndroidSubmissionClient.java | 23 +++++++++---------- .../sync/FxAccountNotificationManager.java | 4 ++-- mobile/android/base/moz.build | 11 ++++++--- 5 files changed, 36 insertions(+), 19 deletions(-) diff --git a/mobile/android/base/BrowserLocaleManager.java b/mobile/android/base/BrowserLocaleManager.java index c5433a02bdda..b77e56d61bcb 100644 --- a/mobile/android/base/BrowserLocaleManager.java +++ b/mobile/android/base/BrowserLocaleManager.java @@ -16,6 +16,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.mozilla.gecko.annotation.ReflectionTarget; import org.mozilla.gecko.util.GeckoJarReader; import android.content.BroadcastReceiver; @@ -61,6 +62,7 @@ public class BrowserLocaleManager implements LocaleManager { private static final AtomicReference instance = new AtomicReference(); + @ReflectionTarget public static LocaleManager getInstance() { LocaleManager localeManager = instance.get(); if (localeManager != null) { diff --git a/mobile/android/base/Locales.java b/mobile/android/base/Locales.java index 8b3c0538875d..902bb5fd3060 100644 --- a/mobile/android/base/Locales.java +++ b/mobile/android/base/Locales.java @@ -4,9 +4,9 @@ package org.mozilla.gecko; +import java.lang.reflect.Method; import java.util.Locale; -import org.mozilla.gecko.BrowserLocaleManager; import org.mozilla.gecko.LocaleManager; import android.app.Activity; @@ -25,8 +25,19 @@ import android.support.v4.app.FragmentActivity; * LocaleAwareFragmentActivity or LocaleAwareActivity. */ public class Locales { + public static LocaleManager getLocaleManager() { + try { + final Class clazz = Class.forName("org.mozilla.gecko.BrowserLocaleManager"); + final Method getInstance = clazz.getMethod("getInstance"); + final LocaleManager localeManager = (LocaleManager) getInstance.invoke(null); + return localeManager; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + public static void initializeLocale(Context context) { - final LocaleManager localeManager = BrowserLocaleManager.getInstance(); + final LocaleManager localeManager = getLocaleManager(); final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads(); StrictMode.allowThreadDiskWrites(); try { diff --git a/mobile/android/base/background/healthreport/upload/AndroidSubmissionClient.java b/mobile/android/base/background/healthreport/upload/AndroidSubmissionClient.java index b7ebfc28e1cf..b6b5481b8f05 100644 --- a/mobile/android/base/background/healthreport/upload/AndroidSubmissionClient.java +++ b/mobile/android/base/background/healthreport/upload/AndroidSubmissionClient.java @@ -4,15 +4,13 @@ package org.mozilla.gecko.background.healthreport.upload; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Collection; - +import android.content.ContentProviderClient; +import android.content.Context; +import android.content.SharedPreferences; +import ch.boye.httpclientandroidlib.HttpResponse; import org.json.JSONException; import org.json.JSONObject; -import org.mozilla.gecko.BrowserLocaleManager; +import org.mozilla.gecko.Locales; import org.mozilla.gecko.background.bagheera.BagheeraClient; import org.mozilla.gecko.background.bagheera.BagheeraRequestDelegate; import org.mozilla.gecko.background.common.GlobalConstants; @@ -30,10 +28,11 @@ import org.mozilla.gecko.background.healthreport.HealthReportStorage.Measurement import org.mozilla.gecko.background.healthreport.ProfileInformationCache; import org.mozilla.gecko.sync.net.BaseResource; -import android.content.ContentProviderClient; -import android.content.Context; -import android.content.SharedPreferences; -import ch.boye.httpclientandroidlib.HttpResponse; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Collection; public class AndroidSubmissionClient implements SubmissionClient { protected static final String LOG_TAG = AndroidSubmissionClient.class.getSimpleName(); @@ -410,7 +409,7 @@ public class AndroidSubmissionClient implements SubmissionClient { String generationProfilePath, ConfigurationProvider providedConfig) throws JSONException { // Let's make sure we have an accurate locale. - BrowserLocaleManager.getInstance().getAndApplyPersistedLocale(context); + Locales.getLocaleManager().getAndApplyPersistedLocale(context); final JSONObject document; // If the given profilePath matches the one we cached for the tracker, use the cached env. diff --git a/mobile/android/base/fxa/sync/FxAccountNotificationManager.java b/mobile/android/base/fxa/sync/FxAccountNotificationManager.java index e551c2e35508..b44da76fc5bd 100644 --- a/mobile/android/base/fxa/sync/FxAccountNotificationManager.java +++ b/mobile/android/base/fxa/sync/FxAccountNotificationManager.java @@ -10,7 +10,7 @@ import android.content.Context; import android.content.Intent; import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat.Builder; -import org.mozilla.gecko.BrowserLocaleManager; +import org.mozilla.gecko.Locales; import org.mozilla.gecko.R; import org.mozilla.gecko.background.common.log.Logger; import org.mozilla.gecko.background.common.telemetry.TelemetryWrapper; @@ -77,7 +77,7 @@ public class FxAccountNotificationManager { if (!localeUpdated) { localeUpdated = true; - BrowserLocaleManager.getInstance().getAndApplyPersistedLocale(context); + Locales.getLocaleManager().getAndApplyPersistedLocale(context); } final String title; diff --git a/mobile/android/base/moz.build b/mobile/android/base/moz.build index 387c4060712d..6123185a872c 100644 --- a/mobile/android/base/moz.build +++ b/mobile/android/base/moz.build @@ -19,12 +19,20 @@ constants_jar.sources = [ 'annotation/RobocopTarget.java', 'annotation/WebRTCJNITarget.java', 'annotation/WrapForJNI.java', + 'db/BrowserContract.java', + 'LocaleManager.java', + 'Locales.java', 'SysInfo.java', ] constants_jar.generated_sources = [ 'preprocessed/org/mozilla/gecko/AdjustConstants.java', 'preprocessed/org/mozilla/gecko/AppConstants.java', ] +constants_jar.extra_jars = [ + CONFIG['ANDROID_SUPPORT_ANNOTATIONS_JAR_LIB'], + CONFIG['ANDROID_SUPPORT_V4_AAR_LIB'], + CONFIG['ANDROID_SUPPORT_V4_AAR_INTERNAL_LIB'], +] if CONFIG['MOZ_INSTALL_TRACKING']: constants_jar.sources += [ @@ -188,7 +196,6 @@ gbjar.sources += [ 'db/AbstractPerProfileDatabaseProvider.java', 'db/AbstractTransactionalProvider.java', 'db/BaseTable.java', - 'db/BrowserContract.java', 'db/BrowserDatabaseHelper.java', 'db/BrowserDB.java', 'db/BrowserProvider.java', @@ -389,8 +396,6 @@ gbjar.sources += [ 'IntentHelper.java', 'javaaddons/JavaAddonManager.java', 'javaaddons/JavaAddonManagerV1.java', - 'LocaleManager.java', - 'Locales.java', 'lwt/LightweightTheme.java', 'lwt/LightweightThemeDrawable.java', 'mdns/MulticastDNSManager.java',