Bug 843821 - Support reading distribution resources from a /system location. r=mfinkle
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Sun, 24 Feb 2013 20:15:23 -0800
changeset 122874 3c11909c216acc5b02052b43027e45cfb9dfabc3
parent 122873 03e5c19f88ca78c65b82c964c1ea234de2155a4b
child 122875 924c07c3cb32d4120380fafec06c1873322e1a63
push id1387
push userphilringnalda@gmail.com
push dateTue, 26 Feb 2013 22:32:56 +0000
treeherderfx-team@ad4cc4e97774 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs843821
milestone22.0a1
Bug 843821 - Support reading distribution resources from a /system location. r=mfinkle
mobile/android/base/Distribution.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/Distribution.java
+++ b/mobile/android/base/Distribution.java
@@ -51,31 +51,51 @@ public final class Distribution {
                 // Bail if we've already initialized the distribution.
                 SharedPreferences settings = context.getSharedPreferences(GeckoApp.PREFS_NAME, Activity.MODE_PRIVATE);
                 String keyName = context.getPackageName() + ".distribution_state";
                 int state = settings.getInt(keyName, STATE_UNKNOWN);
                 if (state == STATE_NONE) {
                     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();
                 }
             }
         });
     }
 
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -8147,39 +8147,45 @@ var MemoryObserver = {
 
   dumpMemoryStats: function(aLabel) {
     let memDumper = Cc["@mozilla.org/memory-info-dumper;1"].getService(Ci.nsIMemoryInfoDumper);
     memDumper.dumpMemoryReportsToFile(aLabel, false, true);
   },
 };
 
 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);
   },
 
   uninit: function dc_uninit() {
     Services.obs.removeObserver(this, "Distribution:Set");
     Services.obs.removeObserver(this, "prefservice:after-app-defaults");
     Services.obs.removeObserver(this, "Campaign:Set");
   },
 
   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;
 
       case "prefservice:after-app-defaults":
         this.getPrefs();
         break;
 
@@ -8210,20 +8216,26 @@ var Distribution = {
   update: function dc_update(aData) {
     // Force the distribution preferences on the default branch
     let defaults = Services.prefs.getDefaultBranch(null);
     defaults.setCharPref("distribution.id", aData.id);
     defaults.setCharPref("distribution.version", aData.version);
   },
 
   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);
   },
 
   applyPrefs: function dc_applyPrefs(aData) {
     // Check for required Global preferences
     let global = aData["Global"];