mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 16:25:38 +00:00
Bug 843821 - Support reading distribution resources from a /system location. r=mfinkle
This commit is contained in:
parent
5f44ab0ead
commit
c43fe3d9b7
@ -56,21 +56,41 @@ public final class Distribution {
|
||||
return;
|
||||
}
|
||||
|
||||
// This pref stores the path to the distribution directory. If it is null, Gecko
|
||||
// looks for distribution files in /data/data/org.mozilla.xxx/distribution.
|
||||
String pathKeyName = context.getPackageName() + ".distribution_path";
|
||||
String distPath = null;
|
||||
|
||||
// Send a message to Gecko if we've set a distribution.
|
||||
if (state == STATE_SET) {
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Distribution:Set", null));
|
||||
distPath = settings.getString(pathKeyName, null);
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Distribution:Set", distPath));
|
||||
return;
|
||||
}
|
||||
|
||||
boolean distributionSet = false;
|
||||
try {
|
||||
// First, try copying distribution files out of the APK.
|
||||
distributionSet = copyFiles(context, packagePath);
|
||||
} catch (IOException e) {
|
||||
Log.e(LOGTAG, "Error copying distribution files", e);
|
||||
}
|
||||
|
||||
if (!distributionSet) {
|
||||
// If there aren't any distribution files in the APK, look in the /system directory.
|
||||
File distDir = new File("/system/" + context.getPackageName() + "/distribution");
|
||||
if (distDir.exists()) {
|
||||
distributionSet = true;
|
||||
distPath = distDir.getPath();
|
||||
settings.edit().putString(pathKeyName, distPath).commit();
|
||||
}
|
||||
}
|
||||
|
||||
Log.i("BOOM", "distributionSet: " + distributionSet);
|
||||
Log.i("BOOM", "distPath: " + distPath);
|
||||
|
||||
if (distributionSet) {
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Distribution:Set", null));
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Distribution:Set", distPath));
|
||||
settings.edit().putInt(keyName, STATE_SET).commit();
|
||||
} else {
|
||||
settings.edit().putInt(keyName, STATE_NONE).commit();
|
||||
|
@ -8152,15 +8152,19 @@ var MemoryObserver = {
|
||||
};
|
||||
|
||||
var Distribution = {
|
||||
// File used to store campaign data
|
||||
_file: null,
|
||||
|
||||
// Path to distribution directory for distribution customizations
|
||||
_path: null,
|
||||
|
||||
init: function dc_init() {
|
||||
Services.obs.addObserver(this, "Distribution:Set", false);
|
||||
Services.obs.addObserver(this, "prefservice:after-app-defaults", false);
|
||||
Services.obs.addObserver(this, "Campaign:Set", false);
|
||||
|
||||
// Look for file outside the APK:
|
||||
// /data/data/org.mozilla.fennec/distribution.json
|
||||
// /data/data/org.mozilla.xxx/distribution.json
|
||||
this._file = Services.dirsvc.get("XCurProcD", Ci.nsIFile);
|
||||
this._file.append("distribution.json");
|
||||
this.readJSON(this._file, this.update);
|
||||
@ -8175,6 +8179,8 @@ var Distribution = {
|
||||
observe: function dc_observe(aSubject, aTopic, aData) {
|
||||
switch (aTopic) {
|
||||
case "Distribution:Set":
|
||||
this._path = aData;
|
||||
|
||||
// Reload the default prefs so we can observe "prefservice:after-app-defaults"
|
||||
Services.prefs.QueryInterface(Ci.nsIObserver).observe(null, "reload-default-prefs", null);
|
||||
break;
|
||||
@ -8215,10 +8221,16 @@ var Distribution = {
|
||||
},
|
||||
|
||||
getPrefs: function dc_getPrefs() {
|
||||
// Look for preferences file outside the APK:
|
||||
// /data/data/org.mozilla.fennec/distribution/preferences.json
|
||||
let file = Services.dirsvc.get("XCurProcD", Ci.nsIFile);
|
||||
file.append("distribution");
|
||||
let file;
|
||||
if (this._path) {
|
||||
file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
|
||||
file.initWithPath(this._path);
|
||||
} else {
|
||||
// If a path isn't specified, look in the data directory:
|
||||
// /data/data/org.mozilla.xxx/distribution
|
||||
file = Services.dirsvc.get("XCurProcD", Ci.nsIFile);
|
||||
file.append("distribution");
|
||||
}
|
||||
file.append("preferences.json");
|
||||
|
||||
this.readJSON(file, this.applyPrefs);
|
||||
|
Loading…
Reference in New Issue
Block a user