Bug 792992 - Make update URL configurable via pref. r=snorp

This commit is contained in:
Eugen Sawin 2015-02-03 17:18:13 +01:00
parent f22a8d86eb
commit 13fb4549cf
6 changed files with 77 additions and 42 deletions

View File

@ -346,6 +346,7 @@ class RemoteReftest(RefTest):
profileDir = profile.profile
prefs = {}
prefs["app.update.url.android"] = ""
prefs["browser.firstrun.show.localepicker"] = False
prefs["font.size.inflation.emPerLine"] = 0
prefs["font.size.inflation.minTwips"] = 0

View File

@ -504,14 +504,13 @@ pref("app.update.timerMinimumDelay", 30); // seconds
// used by update service to decide whether or not to
// automatically download an update
pref("app.update.autodownload", "wifi");
pref("app.update.url.android", "https://aus4.mozilla.org/update/4/%PRODUCT%/%VERSION%/%BUILD_ID%/%BUILD_TARGET%/%LOCALE%/%CHANNEL%/%OS_VERSION%/%DISTRIBUTION%/%DISTRIBUTION_VERSION%/%MOZ_VERSION%/update.xml");
#ifdef MOZ_UPDATER
/* prefs used specifically for updating the app */
pref("app.update.enabled", false);
pref("app.update.channel", "@MOZ_UPDATE_CHANNEL@");
// If you are looking for app.update.url, we no longer use it.
// See mobile/android/base/updater/UpdateServiceHelper.java
#endif
// replace newlines with spaces on paste into single-line text boxes

View File

@ -116,6 +116,7 @@ OnSharedPreferenceChangeListener
private static final String PREFS_MENU_CHAR_ENCODING = "browser.menu.showCharacterEncoding";
private static final String PREFS_MP_ENABLED = "privacy.masterpassword.enabled";
private static final String PREFS_UPDATER_AUTODOWNLOAD = "app.update.autodownload";
private static final String PREFS_UPDATER_URL = "app.update.url.android";
private static final String PREFS_GEO_REPORTING = NON_PREF_PREFIX + "app.geo.reportdata";
private static final String PREFS_GEO_LEARN_MORE = NON_PREF_PREFIX + "geo.learn_more";
private static final String PREFS_HEALTHREPORT_LINK = NON_PREF_PREFIX + "healthreport.link";
@ -1059,6 +1060,8 @@ OnSharedPreferenceChangeListener
setCharEncodingState(((String) newValue).equals("true"));
} else if (PREFS_UPDATER_AUTODOWNLOAD.equals(prefName)) {
UpdateServiceHelper.setAutoDownloadPolicy(this, UpdateService.AutoDownloadPolicy.get((String) newValue));
} else if (PREFS_UPDATER_URL.equals(prefName)) {
UpdateServiceHelper.setUpdateUrl(this, (String) newValue);
} else if (PREFS_HEALTHREPORT_UPLOAD_ENABLED.equals(prefName)) {
// The healthreport pref only lives in Android, so we do not persist
// to Gecko, but we do broadcast intent to the health report

View File

@ -72,6 +72,7 @@ public class UpdateService extends IntentService {
private static final String KEY_LAST_FILE_NAME = "UpdateService.lastFileName";
private static final String KEY_LAST_ATTEMPT_DATE = "UpdateService.lastAttemptDate";
private static final String KEY_AUTODOWNLOAD_POLICY = "UpdateService.autoDownloadPolicy";
private static final String KEY_UPDATE_URL = "UpdateService.updateUrl";
private SharedPreferences mPrefs;
@ -187,6 +188,11 @@ public class UpdateService extends IntentService {
setAutoDownloadPolicy(policy);
}
String url = intent.getStringExtra(UpdateServiceHelper.EXTRA_UPDATE_URL_NAME);
if (url != null) {
setUpdateUrl(url);
}
registerForUpdates(false);
} else if (UpdateServiceHelper.ACTION_CHECK_FOR_UPDATE.equals(intent.getAction())) {
startUpdate(intent.getIntExtra(UpdateServiceHelper.EXTRA_UPDATE_FLAGS_NAME, 0));
@ -359,7 +365,12 @@ public class UpdateService extends IntentService {
private UpdateInfo findUpdate(boolean force) {
try {
URL url = UpdateServiceHelper.getUpdateUrl(this, force);
URL url = getUpdateUrl(force);
if (url == null) {
Log.e(LOGTAG, "failed to get update URL");
return null;
}
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document dom = builder.parse(openConnectionWithProxy(url).getInputStream());
@ -698,6 +709,16 @@ public class UpdateService extends IntentService {
editor.commit();
}
private URL getUpdateUrl(boolean force) {
return UpdateServiceHelper.expandUpdateUrl(this, mPrefs.getString(KEY_UPDATE_URL, null), force);
}
private void setUpdateUrl(String url) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString(KEY_UPDATE_URL, url);
editor.commit();
}
private void saveUpdateInfo(UpdateInfo info, File downloaded) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString(KEY_LAST_BUILDID, info.buildID);

View File

@ -45,16 +45,18 @@ public class UpdateServiceHelper {
// Name of the Intent extra that holds the APK path, used with ACTION_APPLY_UPDATE
protected static final String EXTRA_PACKAGE_PATH_NAME = "packagePath";
// Name of the Intent extra for the update URL, used with ACTION_REGISTER_FOR_UPDATES
protected static final String EXTRA_UPDATE_URL_NAME = "updateUrl";
private static final String LOGTAG = "UpdateServiceHelper";
private static final String DEFAULT_UPDATE_LOCALE = "en-US";
private static final String UPDATE_URL;
// So that updates can be disabled by tests.
private static volatile boolean isEnabled = true;
private enum Pref {
AUTO_DOWNLOAD_POLICY("app.update.autodownload");
AUTO_DOWNLOAD_POLICY("app.update.autodownload"),
UPDATE_URL("app.update.url.android");
public final String name;
@ -80,49 +82,46 @@ public class UpdateServiceHelper {
}
}
static {
final String pkgSpecial;
if (AppConstants.MOZ_PKG_SPECIAL != null) {
pkgSpecial = "-" + AppConstants.MOZ_PKG_SPECIAL;
} else {
pkgSpecial = "";
}
UPDATE_URL = "https://aus4.mozilla.org/update/4/" + AppConstants.MOZ_APP_BASENAME + "/" +
AppConstants.MOZ_APP_VERSION +
"/%BUILDID%/Android_" + AppConstants.MOZ_APP_ABI + pkgSpecial +
"/%LOCALE%/" + AppConstants.MOZ_UPDATE_CHANNEL +
"/%OS_VERSION%/default/default/" + AppConstants.MOZILLA_VERSION +
"/update.xml";
}
@RobocopTarget
public static void setEnabled(final boolean enabled) {
isEnabled = enabled;
}
public static URL getUpdateUrl(Context context, boolean force) {
public static URL expandUpdateUrl(Context context, String updateUrl, boolean force) {
if (updateUrl == null) {
return null;
}
PackageManager pm = context.getPackageManager();
String locale = null;
String pkgSpecial = AppConstants.MOZ_PKG_SPECIAL != null ?
"-" + AppConstants.MOZ_PKG_SPECIAL :
"";
String locale = DEFAULT_UPDATE_LOCALE;
try {
ApplicationInfo info = pm.getApplicationInfo(AppConstants.ANDROID_PACKAGE_NAME, 0);
String updateLocaleUrl = "jar:jar:file://" + info.sourceDir + "!/" + AppConstants.OMNIJAR_NAME + "!/update.locale";
locale = GeckoJarReader.getText(updateLocaleUrl);
if (locale != null)
locale = locale.trim();
else
locale = DEFAULT_UPDATE_LOCALE;
final String jarLocale = GeckoJarReader.getText(updateLocaleUrl);
if (jarLocale != null) {
locale = jarLocale.trim();
}
} catch (android.content.pm.PackageManager.NameNotFoundException e) {
// Shouldn't really be possible, but fallback to default locale
Log.i(LOGTAG, "Failed to read update locale file, falling back to " + DEFAULT_UPDATE_LOCALE);
locale = DEFAULT_UPDATE_LOCALE;
Log.i(LOGTAG, "Failed to read update locale file, falling back to " + locale);
}
String url = UPDATE_URL.replace("%LOCALE%", locale).
replace("%OS_VERSION%", Build.VERSION.RELEASE).
replace("%BUILDID%", force ? "0" : AppConstants.MOZ_APP_BUILDID);
String url = updateUrl.replace("%PRODUCT%", AppConstants.MOZ_APP_BASENAME)
.replace("%VERSION%", AppConstants.MOZ_APP_VERSION)
.replace("%BUILD_ID%", force ? "0" : AppConstants.MOZ_APP_BUILDID)
.replace("%BUILD_TARGET%", "Android_" + AppConstants.MOZ_APP_ABI + pkgSpecial)
.replace("%LOCALE%", locale)
.replace("%CHANNEL%", AppConstants.MOZ_UPDATE_CHANNEL)
.replace("%OS_VERSION%", Build.VERSION.RELEASE)
.replace("%DISTRIBUTION%", "default")
.replace("%DISTRIBUTION_VERSION%", "default")
.replace("%MOZ_VERSION%", AppConstants.MOZILLA_VERSION);
try {
return new URL(url);
@ -136,8 +135,12 @@ public class UpdateServiceHelper {
return AppConstants.MOZ_UPDATER && isEnabled;
}
public static void setUpdateUrl(Context context, String url) {
registerForUpdates(context, null, url);
}
public static void setAutoDownloadPolicy(Context context, UpdateService.AutoDownloadPolicy policy) {
registerForUpdates(context, policy);
registerForUpdates(context, policy, null);
}
public static void checkForUpdate(Context context) {
@ -175,19 +178,26 @@ public class UpdateServiceHelper {
@Override public void finish() {
UpdateServiceHelper.registerForUpdates(context,
UpdateService.AutoDownloadPolicy.get(
(String) prefs.get(Pref.AUTO_DOWNLOAD_POLICY.toString())));
(String) prefs.get(Pref.AUTO_DOWNLOAD_POLICY.toString())),
(String) prefs.get(Pref.UPDATE_URL.toString()));
}
});
}
public static void registerForUpdates(Context context, UpdateService.AutoDownloadPolicy policy) {
if (!isUpdaterEnabled())
return;
Log.i(LOGTAG, "register for updates policy: " + policy.toString());
public static void registerForUpdates(Context context, UpdateService.AutoDownloadPolicy policy, String url) {
if (!isUpdaterEnabled()) {
return;
}
Intent intent = createIntent(context, ACTION_REGISTER_FOR_UPDATES);
intent.putExtra(EXTRA_AUTODOWNLOAD_NAME, policy.value);
if (policy != null) {
intent.putExtra(EXTRA_AUTODOWNLOAD_NAME, policy.value);
}
if (url != null) {
intent.putExtra(EXTRA_UPDATE_URL_NAME, url);
}
context.startService(intent);
}

View File

@ -43,6 +43,7 @@ user_pref("media.volume_scale", "0.01");
user_pref("security.warn_viewing_mixed", false);
user_pref("app.update.enabled", false);
user_pref("app.update.staging.enabled", false);
user_pref("app.update.url.android", "");
// Make sure GMPInstallManager won't hit the network.
user_pref("media.gmp-manager.url.override", "http://%(server)s/dummy-gmp-manager.xml");
user_pref("browser.panorama.experienced_first_run", true); // Assume experienced