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
This commit is contained in:
Nick Alexander 2015-10-26 14:43:50 -07:00
Родитель d1f8d18025
Коммит d205dfb7bd
5 изменённых файлов: 36 добавлений и 19 удалений

Просмотреть файл

@ -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<LocaleManager> instance = new AtomicReference<LocaleManager>();
@ReflectionTarget
public static LocaleManager getInstance() {
LocaleManager localeManager = instance.get();
if (localeManager != null) {

Просмотреть файл

@ -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;
* <code>LocaleAwareFragmentActivity</code> or <code>LocaleAwareActivity</code>.
*/
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 {

Просмотреть файл

@ -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.

Просмотреть файл

@ -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;

Просмотреть файл

@ -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',