Bug 816101 - Send a system message when a call is complete. r=hsinyi, a=blocking-basecamp
authorDale Harvey <dale@arandomurl.com>
Tue, 18 Dec 2012 14:54:18 +0100
changeset 122281 443cf9f1bf3ba17f505290e58fc8956f61f3e540
parent 122280 dfa3a86df2e79289a96705a6342ea8955357cc0c
child 122282 b2a6e3a1308d49513eef6acb6c89848e87c6e26e
push id1997
push userakeybl@mozilla.com
push dateMon, 07 Jan 2013 21:25:26 +0000
treeherdermozilla-beta@4baf45cdcf21 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsinyi, blocking-basecamp
bugs816101
milestone19.0a2
Bug 816101 - Send a system message when a call is complete. r=hsinyi, a=blocking-basecamp
dom/messages/SystemMessagePermissionsChecker.jsm
dom/system/gonk/RadioInterfaceLayer.js
dom/system/gonk/ril_worker.js
--- a/dom/messages/SystemMessagePermissionsChecker.jsm
+++ b/dom/messages/SystemMessagePermissionsChecker.jsm
@@ -74,16 +74,19 @@ this.SystemMessagePermissionsTable = {
     "desktop-notification": []
   },
   "sms-received": {
     "sms": []
   },
   "telephony-new-call": {
     "telephony": []
   },
+  "telephony-call-ended": {
+    "telephony": []
+  },
   "ussd-received": {
     "mobileconnection": []
   }
 };
 
 this.SystemMessagePermissionsChecker = {
   /**
    * Return all the needed permission names for the given system message.
--- a/dom/system/gonk/RadioInterfaceLayer.js
+++ b/dom/system/gonk/RadioInterfaceLayer.js
@@ -1222,16 +1222,24 @@ RadioInterfaceLayer.prototype = {
   },
 
   /**
    * Handle call disconnects by updating our current state and the audio system.
    */
   handleCallDisconnected: function handleCallDisconnected(call) {
     debug("handleCallDisconnected: " + JSON.stringify(call));
     call.state = nsIRadioInterfaceLayer.CALL_STATE_DISCONNECTED;
+    let duration = ("started" in call && typeof call.started == "number") ?
+      new Date().getTime() - call.started : 0;
+    let data = {
+      number: call.number,
+      duration: duration,
+      direction: call.direction
+    };
+    gSystemMessenger.broadcastMessage("telephony-call-ended", data);
     this.updateCallAudioState(call);
     this._sendTargetMessage("telephony", "RIL:CallStateChanged", call);
   },
 
   /**
    * Handle calls delivered in response to a 'enumerateCalls' request.
    */
   handleEnumerateCalls: function handleEnumerateCalls(options) {
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -4188,16 +4188,19 @@ let RIL = {
         newCall = newCalls[currentCall.callIndex];
         delete newCalls[currentCall.callIndex];
       }
 
       if (newCall) {
         // Call is still valid.
         if (newCall.state != currentCall.state) {
           // State has changed.
+          if (!currentCall.started && newCall.state == CALL_STATE_ACTIVE) {
+            currentCall.started = new Date().getTime();
+          }
           currentCall.state = newCall.state;
           this._handleChangedCallState(currentCall);
         }
       } else {
         // Call is no longer reported by the radio. Remove from our map and
         // send disconnected state change.
         delete this.currentCalls[currentCall.callIndex];
         this.getFailCauseCode(currentCall);
@@ -4208,16 +4211,21 @@ let RIL = {
     for each (let newCall in newCalls) {
       if (newCall.isVoice) {
         // Format international numbers appropriately.
         if (newCall.number &&
             newCall.toa == TOA_INTERNATIONAL &&
             newCall.number[0] != "+") {
           newCall.number = "+" + newCall.number;
         }
+        if (newCall.state == CALL_STATE_INCOMING) {
+          newCall.direction = 'incoming';
+        } else if (newCall.state == CALL_STATE_DIALING) {
+          newCall.direction = 'outgoing';
+        }
         // Add to our map.
         this.currentCalls[newCall.callIndex] = newCall;
         this._handleChangedCallState(newCall);
       }
     }
 
     // Update our mute status. If there is anything in our currentCalls map then
     // we know it's a voice call and we should leave audio on.