Bug 1091790 - Check active call via nsITelephonyService. r=fabrice
authorShih-Chiang Chien <schien@mozilla.com>
Mon, 19 Jan 2015 09:42:20 +0800
changeset 251897 cb49fd041f7afbedb42c2566a4521446698a6f65
parent 251896 1b8de94f906b2daa9562ee50652baa52295e07f9
child 251898 a558364e10212b5e74b46f53af116009abb25bed
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice
bugs1091790
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1091790 - Check active call via nsITelephonyService. r=fabrice
b2g/components/ContentPermissionPrompt.js
--- a/b2g/components/ContentPermissionPrompt.js
+++ b/b2g/components/ContentPermissionPrompt.js
@@ -30,19 +30,19 @@ Cu.import("resource://gre/modules/Permis
 Cu.import("resource://gre/modules/PermissionsTable.jsm");
 
 var permissionManager = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
 var secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager);
 
 let permissionSpecificChecker = {};
 
 XPCOMUtils.defineLazyServiceGetter(this,
-                                   "AudioManager",
-                                   "@mozilla.org/telephony/audiomanager;1",
-                                   "nsIAudioManager");
+                                   "TelephonyService",
+                                   "@mozilla.org/telephony/telephonyservice;1",
+                                   "nsITelephonyService");
 
 XPCOMUtils.defineLazyModuleGetter(this, "SystemAppProxy",
                                   "resource://gre/modules/SystemAppProxy.jsm");
 
 /**
  * Determine if a permission should be prompt to user or not.
  *
  * @param aPerm requested permission
@@ -450,19 +450,36 @@ ContentPermissionPrompt.prototype = {
   classID: Components.ID("{8c719f03-afe0-4aac-91ff-6c215895d467}"),
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionPrompt])
 };
 
 (function() {
   // Do not allow GetUserMedia while in call.
   permissionSpecificChecker["audio-capture"] = function(request) {
-    if (AudioManager.phoneState === Ci.nsIAudioManager.PHONE_STATE_IN_CALL) {
-      request.cancel();
-      return true;
-    } else {
+    let forbid = false;
+
+    try {
+      // nsITelephonyService.enumerateCalls is synchronous.
+      TelephonyService.enumerateCalls({
+        QueryInterface: XPCOMUtils.generateQI([Ci.nsITelephonyListener]),
+        enumerateCallStateComplete: function() {},
+        enumerateCallState: function(callInfo) {
+          if (callInfo.callState == Ci.nsITelephonyService.CALL_STATE_CONNECTED) {
+            forbid = true;
+          }
+        },
+      });
+    } catch (e) {
+      // No restriction if Telephony service doesn't exist.
       return false;
     }
+
+    if (forbid) {
+      request.cancel();
+    }
+
+    return forbid;
   };
 })();
 
 //module initialization
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ContentPermissionPrompt]);