Bug 1164248 - Handling of session/sessionEnded for notifyUssdReceived. r=edgar, a=kkuo
authorHsin-Yi Tsai <htsai@mozilla.com>
Wed, 13 May 2015 15:26:16 +0800
changeset 238408 ea3b70dd2b3fac37d3f0e7c24f075df0e516c44e
parent 238407 fe3cb392cc58eff5072f61783be3b7acd38c5c0d
child 238409 d50110422703de955c36e03e93e007e4d4b5c19e
push id610
push userryanvm@gmail.com
push dateTue, 19 May 2015 01:50:15 +0000
treeherdermozilla-b2g37_v2_2@d50110422703 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedgar, kkuo
bugs1164248
milestone37.0
Bug 1164248 - Handling of session/sessionEnded for notifyUssdReceived. r=edgar, a=kkuo
b2g/installer/package-manifest.in
dom/telephony/gonk/TelephonyService.js
dom/telephony/gonk/TelephonyService.manifest
dom/telephony/gonk/USSDReceivedWrapper.js
dom/telephony/gonk/USSDReceivedWrapper.manifest
dom/telephony/moz.build
--- a/b2g/installer/package-manifest.in
+++ b/b2g/installer/package-manifest.in
@@ -465,16 +465,18 @@
 @BINPATH@/components/SmsService.manifest
 #endif
 @BINPATH@/components/RILContentHelper.js
 @BINPATH@/components/RILContentHelper.manifest
 @BINPATH@/components/RILSystemMessengerHelper.js
 @BINPATH@/components/RILSystemMessengerHelper.manifest
 @BINPATH@/components/TelephonyAudioService.js
 @BINPATH@/components/TelephonyAudioService.manifest
+@BINPATH@/components/USSDReceivedWrapper.js
+@BINPATH@/components/USSDReceivedWrapper.manifest
 #ifndef DISABLE_MOZ_RIL_GEOLOC
 @BINPATH@/components/TelephonyService.js
 @BINPATH@/components/TelephonyService.manifest
 @BINPATH@/components/VoicemailService.js
 @BINPATH@/components/VoicemailService.manifest
 #endif
 #endif // MOZ_WIDGET_GONK && MOZ_B2G_RIL
 
--- a/dom/telephony/gonk/TelephonyService.js
+++ b/dom/telephony/gonk/TelephonyService.js
@@ -1363,42 +1363,9 @@ TelephonyService.prototype = {
         this._releaseCallRingWakeLock();
 
         Services.obs.removeObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
         break;
     }
   }
 };
 
-/**
- * This implements nsISystemMessagesWrapper.wrapMessage(), which provides a
- * plugable way to wrap a "ussd-received" type system message.
- *
- * Please see SystemMessageManager.js to know how it customizes the wrapper.
- */
-function USSDReceivedWrapper() {
-  if (DEBUG) debug("USSDReceivedWrapper()");
-}
-USSDReceivedWrapper.prototype = {
-  // nsISystemMessagesWrapper implementation.
-  wrapMessage: function(aMessage, aWindow) {
-    if (DEBUG) debug("wrapMessage: " + JSON.stringify(aMessage));
-
-    let session = aMessage.sessionEnded ? null :
-      new aWindow.USSDSession(aMessage.serviceId);
-
-    let event = new aWindow.USSDReceivedEvent("ussdreceived", {
-      serviceId: aMessage.serviceId,
-      message: aMessage.message,
-      session: session
-    });
-
-    return event;
-  },
-
-  classDescription: "USSDReceivedWrapper",
-  classID: Components.ID("{d03684ed-ede4-4210-8206-f4f32772d9f5}"),
-  contractID: "@mozilla.org/dom/system-messages/wrapper/ussd-received;1",
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsISystemMessagesWrapper])
-};
-
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TelephonyService,
-                                                    USSDReceivedWrapper]);
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TelephonyService]);
--- a/dom/telephony/gonk/TelephonyService.manifest
+++ b/dom/telephony/gonk/TelephonyService.manifest
@@ -1,5 +1,3 @@
 component {67d26434-d063-4d28-9f48-5b3189788155} TelephonyService.js
 contract @mozilla.org/telephony/gonktelephonyservice;1 {67d26434-d063-4d28-9f48-5b3189788155}
 
-component {d03684ed-ede4-4210-8206-f4f32772d9f5} TelephonyService.js
-contract @mozilla.org/dom/system-messages/wrapper/ussd-received;1 {d03684ed-ede4-4210-8206-f4f32772d9f5}
new file mode 100644
--- /dev/null
+++ b/dom/telephony/gonk/USSDReceivedWrapper.js
@@ -0,0 +1,82 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
+
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+const NS_PREFBRANCH_PREFCHANGE_TOPIC_ID = "nsPref:changed";
+const kPrefRilDebuggingEnabled = "ril.debugging.enabled";
+
+let DEBUG;
+function debug(s) {
+  dump("USSDReceivedWrapper: " + s + "\n");
+}
+
+XPCOMUtils.defineLazyGetter(this, "RIL", function () {
+  let obj = {};
+  Cu.import("resource://gre/modules/ril_consts.js", obj);
+  return obj;
+});
+
+/**
+ * This implements nsISystemMessagesWrapper.wrapMessage(), which provides a
+ * plugable way to wrap a "ussd-received" type system message.
+ *
+ * Please see SystemMessageManager.js to know how it customizes the wrapper.
+ */
+function USSDReceivedWrapper() {
+  this._updateDebugFlag();
+  Services.prefs.addObserver(kPrefRilDebuggingEnabled, this, false);
+  if (DEBUG) debug("USSDReceivedWrapper()");
+}
+USSDReceivedWrapper.prototype = {
+  _updateDebugFlag: function() {
+    try {
+      DEBUG = RIL.DEBUG_RIL ||
+              Services.prefs.getBoolPref(kPrefRilDebuggingEnabled);
+    } catch (e) {}
+  },
+
+  /**
+   * nsIObserver interface.
+   */
+  observe: function(aSubject, aTopic, aData) {
+    switch (aTopic) {
+      case NS_PREFBRANCH_PREFCHANGE_TOPIC_ID:
+        if (aData === kPrefRilDebuggingEnabled) {
+          this._updateDebugFlag();
+        }
+        break;
+    }
+  },
+
+  // nsISystemMessagesWrapper implementation.
+  wrapMessage: function(aMessage, aWindow) {
+    if (DEBUG) debug("wrapMessage: " + JSON.stringify(aMessage));
+
+    let session = aMessage.sessionEnded ? null :
+      new aWindow.USSDSession(aMessage.serviceId);
+
+    let event = new aWindow.USSDReceivedEvent("ussdreceived", {
+      serviceId: aMessage.serviceId,
+      message: aMessage.message,
+      session: session
+    });
+
+    return event;
+  },
+
+  classDescription: "USSDReceivedWrapper",
+  classID: Components.ID("{d03684ed-ede4-4210-8206-f4f32772d9f5}"),
+  contractID: "@mozilla.org/dom/system-messages/wrapper/ussd-received;1",
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
+                                         Ci.nsISystemMessagesWrapper])
+};
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([USSDReceivedWrapper]);
new file mode 100644
--- /dev/null
+++ b/dom/telephony/gonk/USSDReceivedWrapper.manifest
@@ -0,0 +1,2 @@
+component {d03684ed-ede4-4210-8206-f4f32772d9f5} USSDReceivedWrapper.js
+contract @mozilla.org/dom/system-messages/wrapper/ussd-received;1 {d03684ed-ede4-4210-8206-f4f32772d9f5}
--- a/dom/telephony/moz.build
+++ b/dom/telephony/moz.build
@@ -58,16 +58,18 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk
     XPIDL_SOURCES += [
         'nsIGonkTelephonyService.idl',
         'nsITelephonyAudioService.idl',
         'nsITelephonyMessenger.idl',
     ]
     EXTRA_COMPONENTS += [
         'gonk/TelephonyAudioService.js',
         'gonk/TelephonyAudioService.manifest',
+        'gonk/USSDReceivedWrapper.js',
+        'gonk/USSDReceivedWrapper.manifest',
     ]
     if not CONFIG['DISABLE_MOZ_RIL_GEOLOC']:
         EXTRA_COMPONENTS += [
             'gonk/TelephonyService.js',
             'gonk/TelephonyService.manifest',
         ]
 
 FAIL_ON_WARNINGS = True