Bug 1072808 - Part 1: Add TelephonyMessenger as a Wrapper for TelephonyService-Related System Messages. r=echen

This commit is contained in:
Bevis Tseng 2014-10-20 16:50:57 +08:00
Родитель 115a98a7b7
Коммит 17c1f46219
10 изменённых файлов: 309 добавлений и 18 удалений

Просмотреть файл

@ -449,6 +449,8 @@
@BINPATH@/components/RadioInterfaceLayer.js
@BINPATH@/components/RadioInterfaceLayer.manifest
@BINPATH@/components/RILContentHelper.js
@BINPATH@/components/RILSystemMessengerHelper.js
@BINPATH@/components/RILSystemMessengerHelper.manifest
@BINPATH@/components/TelephonyAudioService.js
@BINPATH@/components/TelephonyAudioService.manifest
@BINPATH@/components/TelephonyService.js

Просмотреть файл

@ -0,0 +1,56 @@
/* 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";
/**
* RILSystemMessenger
*/
this.RILSystemMessenger = function() {};
RILSystemMessenger.prototype = {
/**
* Hook of Broadcast function
*
* @param aType
* The type of the message to be sent.
* @param aMessage
* The message object to be broadcasted.
*/
broadcastMessage: function(aType, aMessage) {
// Function stub to be replaced by the owner of this messenger.
},
/**
* Wrapper to send "telephony-new-call" system message.
*/
notifyNewCall: function() {
this.broadcastMessage("telephony-new-call", {});
},
/**
* Wrapper to send "telephony-call-ended" system message.
*/
notifyCallEnded: function(aServiceId, aNumber, aCdmaWaitingNumber, aEmergency,
aDuration, aOutgoing, aHangUpLocal) {
let data = {
serviceId: aServiceId,
number: aNumber,
emergency: aEmergency,
duration: aDuration,
direction: aOutgoing ? "outgoing" : "incoming",
hangUpLocal: aHangUpLocal
};
if (aCdmaWaitingNumber != null) {
data.secondNumber = aCdmaWaitingNumber;
}
this.broadcastMessage("telephony-call-ended", data);
}
};
this.EXPORTED_SYMBOLS = [
'RILSystemMessenger'
];

Просмотреть файл

@ -0,0 +1,73 @@
/* 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");
let RSM = {};
Cu.import("resource://gre/modules/RILSystemMessenger.jsm", RSM);
const RILSYSTEMMESSENGERHELPER_CONTRACTID =
"@mozilla.org/ril/system-messenger-helper;1";
const RILSYSTEMMESSENGERHELPER_CID =
Components.ID("{19d9a4ea-580d-11e4-8f6c-37ababfaaea9}");
XPCOMUtils.defineLazyServiceGetter(this, "gSystemMessenger",
"@mozilla.org/system-message-internal;1",
"nsISystemMessagesInternal");
let DEBUG = false;
function debug(s) {
dump("-@- RILSystemMessenger: " + s + "\n");
};
// Read debug setting from pref.
try {
let debugPref = Services.prefs.getBoolPref("ril.debugging.enabled");
DEBUG = DEBUG || debugPref;
} catch (e) {}
/**
* RILSystemMessengerHelper
*/
function RILSystemMessengerHelper() {
this.messenger = new RSM.RILSystemMessenger();
this.messenger.broadcastMessage = (aType, aMessage) => {
if (DEBUG) {
debug("broadcastMessage: aType: " + aType +
", aMessage: "+ JSON.stringify(aMessage));
}
gSystemMessenger.broadcastMessage(aType, aMessage);
};
}
RILSystemMessengerHelper.prototype = {
classID: RILSYSTEMMESSENGERHELPER_CID,
QueryInterface: XPCOMUtils.generateQI([Ci.nsITelephonyMessenger]),
/**
* RILSystemMessenger instance.
*/
messenger: null,
/**
* nsITelephonyMessenger API
*/
notifyNewCall: function() {
this.messenger.notifyNewCall();
},
notifyCallEnded: function(aServiceId, aNumber, aCdmaWaitingNumber, aEmergency,
aDuration, aOutgoing, aHangUpLocal) {
this.messenger.notifyCallEnded(aServiceId, aNumber, aCdmaWaitingNumber, aEmergency,
aDuration, aOutgoing, aHangUpLocal);
}
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([RILSystemMessengerHelper]);

Просмотреть файл

@ -0,0 +1,6 @@
# 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/.
component {19d9a4ea-580d-11e4-8f6c-37ababfaaea9} RILSystemMessengerHelper.js
contract @mozilla.org/ril/system-messenger-helper;1 {19d9a4ea-580d-11e4-8f6c-37ababfaaea9}

Просмотреть файл

@ -90,10 +90,13 @@ if CONFIG['MOZ_B2G_RIL']:
'RadioInterfaceLayer.js',
'RadioInterfaceLayer.manifest',
'RILContentHelper.js',
'RILSystemMessengerHelper.js',
'RILSystemMessengerHelper.manifest',
]
EXTRA_JS_MODULES += [
'ril_consts.js',
'ril_worker.js',
'RILSystemMessenger.jsm',
]
FAIL_ON_WARNINGS = True

Просмотреть файл

@ -0,0 +1,111 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
/**
* Name space for RILSystemMessenger.jsm. Only initialized after first call to
* newRILSystemMessenger.
*/
let RSM;
let gReceivedMsgType = null;
let gReceivedMessage = null;
/**
* Create a new RILSystemMessenger instance.
*
* @return a RILSystemMessenger instance.
*/
function newRILSystemMessenger() {
if (!RSM) {
RSM = Cu.import("resource://gre/modules/RILSystemMessenger.jsm", {});
equal(typeof RSM.RILSystemMessenger, "function", "RSM.RILSystemMessenger");
}
let rsm = new RSM.RILSystemMessenger();
rsm.broadcastMessage = (aType, aMessage) => {
gReceivedMsgType = aType;
gReceivedMessage = aMessage;
};
return rsm;
}
function equal_received_system_message(aType, aMessage) {
equal(aType, gReceivedMsgType);
deepEqual(aMessage, gReceivedMessage);
gReceivedMsgType = null;
gReceivedMessage = null;
}
/**
* Verify that each nsIXxxMessenger could be retrieved.
*/
function run_test() {
let telephonyMessenger = Cc["@mozilla.org/ril/system-messenger-helper;1"]
.getService(Ci.nsITelephonyMessenger);
ok(telephonyMessenger !== null, "Get TelephonyMessenger.");
run_next_test();
}
/**
* Verify RILSystemMessenger.notifyNewCall()
*/
add_test(function test_telephony_messenger_notify_new_call() {
let messenger = newRILSystemMessenger();
messenger.notifyNewCall();
equal_received_system_message("telephony-new-call", {});
run_next_test();
});
/**
* Verify RILSystemMessenger.notifyCallEnded()
*/
add_test(function test_telephony_messenger_notify_call_ended() {
let messenger = newRILSystemMessenger();
messenger.notifyCallEnded(1,
"+0987654321",
null,
true,
500,
false,
true);
equal_received_system_message("telephony-call-ended", {
serviceId: 1,
number: "+0987654321",
emergency: true,
duration: 500,
direction: "incoming",
hangUpLocal: true
});
// Verify 'optional' parameter of secondNumber.
messenger.notifyCallEnded(1,
"+0987654321",
"+1234567890",
true,
500,
true,
false);
equal_received_system_message("telephony-call-ended", {
serviceId: 1,
number: "+0987654321",
emergency: true,
duration: 500,
direction: "outgoing",
hangUpLocal: false,
secondNumber: "+1234567890"
});
run_next_test();
});

Просмотреть файл

@ -37,3 +37,6 @@ skip-if = true
[test_ril_worker_stk.js]
[test_ril_worker_barring_password.js]
[test_ril_worker_cdma_info_rec.js]
[test_ril_system_messenger.js]
# header_helpers.js is not needed for test_ril_system_messenger.js
head =

Просмотреть файл

@ -70,9 +70,9 @@ XPCOMUtils.defineLazyServiceGetter(this, "gPowerManagerService",
"@mozilla.org/power/powermanagerservice;1",
"nsIPowerManagerService");
XPCOMUtils.defineLazyServiceGetter(this, "gSystemMessenger",
"@mozilla.org/system-message-internal;1",
"nsISystemMessagesInternal");
XPCOMUtils.defineLazyServiceGetter(this, "gTelephonyMessenger",
"@mozilla.org/ril/system-messenger-helper;1",
"nsITelephonyMessenger");
XPCOMUtils.defineLazyServiceGetter(this, "gAudioService",
"@mozilla.org/telephony/audio-service;1",
@ -1090,21 +1090,17 @@ TelephonyService.prototype = {
aCall.isEmergency = this._isEmergencyNumber(aCall.number);
let duration = ("started" in aCall && typeof aCall.started == "number") ?
new Date().getTime() - aCall.started : 0;
let data = {
number: aCall.number,
serviceId: aClientId,
emergency: aCall.isEmergency,
duration: duration,
direction: aCall.isOutgoing ? "outgoing" : "incoming",
hangUpLocal: aCall.hangUpLocal
};
if (this._cdmaCallWaitingNumber != null) {
data.secondNumber = this._cdmaCallWaitingNumber;
this._cdmaCallWaitingNumber = null;
}
gTelephonyMessenger.notifyCallEnded(aClientId,
aCall.number,
this._cdmaCallWaitingNumber,
aCall.isEmergency,
duration,
aCall.isOutgoing,
aCall.hangUpLocal);
gSystemMessenger.broadcastMessage("telephony-call-ended", data);
// Clear cache of this._cdmaCallWaitingNumber after call disconnected.
this._cdmaCallWaitingNumber = null;
let manualConfStateChange = false;
let childId = this._currentCalls[aClientId][aCall.callIndex].childId;
@ -1169,7 +1165,7 @@ TelephonyService.prototype = {
// the sleep mode when the RIL handles the incoming call.
this._acquireCallRingWakeLock();
gSystemMessenger.broadcastMessage("telephony-new-call", {});
gTelephonyMessenger.notifyNewCall();
},
/**
@ -1184,7 +1180,7 @@ TelephonyService.prototype = {
}
if (aCall.state == nsITelephonyService.CALL_STATE_DIALING) {
gSystemMessenger.broadcastMessage("telephony-new-call", {});
gTelephonyMessenger.notifyNewCall();
}
aCall.clientId = aClientId;

Просмотреть файл

@ -54,6 +54,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk' and CONFIG['MOZ_B2G_RIL']:
XPIDL_SOURCES += [
'nsIGonkTelephonyService.idl',
'nsITelephonyAudioService.idl',
'nsITelephonyMessenger.idl',
]
EXTRA_COMPONENTS += [
'gonk/TelephonyAudioService.js',

Просмотреть файл

@ -0,0 +1,40 @@
/* 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/. */
#include "nsISupports.idl"
[scriptable, uuid(998a48b2-5b54-11e4-833e-6b17c1427d49)]
interface nsITelephonyMessenger : nsISupports
{
/**
* To broadcast 'telephony-new-call' system message
*/
void notifyNewCall();
/**
* To broadcast 'telephony-call-ended' system message
*
* @param aServiceId
* The ID of Service where this info is notified from.
* @param aNumber
* The phone number of the call to be ended.
* @param aCdmaWaitingNumber
* The CDMA call waiting number to be ended if available.
* @param aEmergency
* true if it's a emergency number.
* @param aDuration
* The duration of this call.
* @param aOutgoing
* true if it's an outgoing call.
* @param aHangUpLocal
* true if this call was hung up by the user.
*/
void notifyCallEnded(in unsigned long aServiceId,
in DOMString aNumber,
in DOMString aCdmaWaitingNumber,
in boolean aEmergency,
in unsigned long aDuration,
in boolean aOutgoing,
in boolean aHangUpLocal);
};