Bug 790158 - Add os version and hardware info to mozSettings. r=cjones
authorShelly Lin <slin@mozilla.com>
Wed, 19 Sep 2012 18:06:40 +0800
changeset 107823 f1ad620dab86067f108e09ab7aead4457a6dc5b3
parent 107822 e5dda6269c225a6767ab6f589b003fe35e02b6a9
child 107824 929786a618f4f124a49479b920acdd7c9a757fce
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewerscjones
bugs790158
milestone18.0a1
Bug 790158 - Add os version and hardware info to mozSettings. r=cjones
b2g/chrome/content/settings.js
b2g/chrome/jar.mn
b2g/confvars.sh
configure.in
--- a/b2g/chrome/content/settings.js
+++ b/b2g/chrome/content/settings.js
@@ -76,16 +76,55 @@ SettingsListener.observe('language.curre
     SettingsListener.observe(key, null, function(value) {
       if (value != null) {
         Services.prefs.setIntPref(key, value);
       }
     });
   });
 })();
 
+//=================== DeviceInfo ====================
+Components.utils.import('resource://gre/modules/XPCOMUtils.jsm');
+Components.utils.import('resource://gre/modules/ctypes.jsm');
+(function DeviceInfoToSettings() {
+  XPCOMUtils.defineLazyServiceGetter(this, 'gSettingsService',
+                                     '@mozilla.org/settingsService;1',
+                                     'nsISettingsService');
+  let lock = gSettingsService.createLock();
+  //MOZ_B2G_VERSION is set in b2g/confvars.sh, and is outputed as a #define value
+  //from configure.in, defaults to 1.0.0 if this value is not exist
+#filter attemptSubstitution
+  let os_version = '@MOZ_B2G_VERSION@';
+#unfilter attemptSubstitution
+  lock.set('deviceinfo.os', os_version, null, null);
+
+  //Get the hardware info from android properties
+  var hardware_version = null;
+  try {
+    let cutils = ctypes.open('libcutils.so');
+    let cbuf = ctypes.char.array(128)();
+    let c_property_get = cutils.declare('property_get', ctypes.default_abi,
+                                        ctypes.int,       // return value: length
+                                        ctypes.char.ptr,  // key
+                                        ctypes.char.ptr,  // value
+                                        ctypes.char.ptr); // default
+    let property_get = function (key, defaultValue) {
+      if (defaultValue === undefined) {
+        defaultValue = null;
+      }
+      c_property_get(key, cbuf, defaultValue);
+      return cbuf.readString();
+    }
+    hardware_version = property_get('ro.hardware');
+    cutils.close();
+  } catch(e) {
+    //Error
+  }
+  lock.set('deviceinfo.hardware', hardware_version, null, null);
+})();
 
 // =================== Debugger ====================
 SettingsListener.observe('devtools.debugger.remote-enabled', false, function(enabled) {
   Services.prefs.setBoolPref('devtools.debugger.remote-enabled', value);
 });
 
 SettingsListener.observe('devtools.debugger.log', false, function(value) {
   Services.prefs.setBoolPref('devtools.debugger.log', value);
@@ -105,9 +144,9 @@ SettingsListener.observe('debug.log-anim
 
 SettingsListener.observe('debug.dev-mode', false, function(value) {
   Services.prefs.setBoolPref('dom.mozApps.dev_mode', value);
 });
 
 // =================== Privacy ====================
 SettingsListener.observe('privacy.donottrackheader.enabled', false, function(value) {
   Services.prefs.setBoolPref('privacy.donottrackheader.enabled', value);
-});
\ No newline at end of file
+});
--- a/b2g/chrome/jar.mn
+++ b/b2g/chrome/jar.mn
@@ -6,17 +6,17 @@
 
 chrome.jar:
 % content branding %content/branding/
 % content browser %content/
 
   content/arrow.svg                     (content/arrow.svg)
   content/dbg-browser-actors.js         (content/dbg-browser-actors.js)
   content/forms.js                      (content/forms.js)
-  content/settings.js                   (content/settings.js)
+* content/settings.js                   (content/settings.js)
 * content/shell.xul                     (content/shell.xul)
 * content/shell.js                      (content/shell.js)
 #ifndef ANDROID
   content/screen.js                     (content/screen.js)
   content/runapp.js                     (content/runapp.js)
 #endif
   content/content.css                   (content/content.css)
   content/touchcontrols.css             (content/touchcontrols.css)
--- a/b2g/confvars.sh
+++ b/b2g/confvars.sh
@@ -3,16 +3,18 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 MOZ_APP_BASENAME=B2G
 MOZ_APP_VENDOR=Mozilla
 
 MOZ_APP_VERSION=18.0a1
 MOZ_APP_UA_NAME=Firefox
 
+MOZ_B2G_VERSION=1.0.0
+
 MOZ_BRANDING_DIRECTORY=b2g/branding/unofficial
 MOZ_OFFICIAL_BRANDING_DIRECTORY=b2g/branding/official
 # MOZ_APP_DISPLAYNAME is set by branding/configure.sh
 
 MOZ_SAFE_BROWSING=
 MOZ_SERVICES_SYNC=1
 
 MOZ_WEBSMS_BACKEND=1
--- a/configure.in
+++ b/configure.in
@@ -8348,16 +8348,19 @@ IS_ALPHA=`echo $MOZ_APP_VERSION | grep a
 if test -z "$IS_ALPHA"; then
   changequote(,)
   MOZ_APP_MAXVERSION=`echo $MOZ_APP_VERSION | sed "s|\(^[0-9]*.[0-9]*\).*|\1|"`.*
   changequote([,])
 else
   MOZ_APP_MAXVERSION=$MOZ_APP_VERSION
 fi
 
+MOZ_B2G_VERSION=${MOZ_B2G_VERSION:-"1.0.0"}
+AC_DEFINE_UNQUOTED(MOZ_B2G_VERSION,"$MOZ_B2G_VERSION")
+
 AC_SUBST(MOZ_APP_NAME)
 AC_SUBST(MOZ_APP_DISPLAYNAME)
 AC_SUBST(MOZ_APP_BASENAME)
 AC_SUBST(MOZ_APP_VENDOR)
 AC_SUBST(MOZ_APP_PROFILE)
 AC_SUBST(MOZ_APP_ID)
 AC_SUBST(MAR_CHANNEL_ID)
 AC_SUBST(ACCEPTED_MAR_CHANNEL_IDS)