Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Removing the dialer background service. #4737

Merged
merged 2 commits into from

2 participants

@etiennesegonzac

The emergency dialer living in the lockscreen now has it's own minimal
call screen.

This also fix a focus issue between the attention screen and the
lockscreen.

@etiennesegonzac etiennesegonzac Removing the dialer background service.
The emergency dialer living in the lockscreen now has it's own minimal
call screen.

This also fix a focus issue between the attention screen and the
lockscreen.
8bcd6b3
@etiennesegonzac

Sending this for review (hellloooo... @vingtetun how are you? :), oh eh, @arcturus nice to see you!).

In the meantime I'm going to smoke test the s**t out of this.

@vingtetun

@ian-liu you may be interested in the fix provided by this pull request concerning OOP and the attention screen.

@vingtetun vingtetun commented on the diff
apps/communications/dialer/js/dialer.js
@@ -214,3 +250,13 @@ window.onresize = function(e) {
}
};
+// Keeping the call history up to date
+document.addEventListener('mozvisibilitychange', function visibility(e) {
+ if (!document.mozHidden) {

nit:

  if (document.mozHidden) {
    return;
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@vingtetun vingtetun commented on the diff
apps/communications/dialer/js/oncall.js
((13 lines not shown))
this.incomingIgnore.addEventListener('mouseup',
- OnCallHandler.ignore.bind(OnCallHandler));
+ OnCallHandler.ignore);

mouseup/mouseup/mouseup/mouseup indent on the second line sounds broken

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@vingtetun vingtetun commented on the diff
apps/communications/dialer/js/oncall.js
((279 lines not shown))
- toggleSpeaker: function ch_toggleSpeaker() {
- this._telephony.speakerEnabled = !this._telephony.speakerEnabled;
- },
+ // The call wasn't picked up
+ if (call.state == 'disconnected') {

What about an early return?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@vingtetun

Lot of code moving but this should land sooner than later. What about the smoke tests?

@etiennesegonzac

All smoke tests green expect Test 8: Camera.
I think my sdcard is broken and it keeps telling me that there is no space left to take picture.
I can't see how it could be related.

We still have the vibrator platform issue:
https://bugzilla.mozilla.org/show_bug.cgi?id=791261

I don't think it should block this PR but if anyone disagrees, speak out :)

@etiennesegonzac

/botio test

@ghost

From: Bot.io (Main)


Received

Command cmd_test from @etiennesegonzac received. Current queue size: 0

Live output at: http://50.116.11.35:8000/b36a1c9113c55be/output.txt

@ghost

From: Bot.io (Main)


Success

Full output at http://50.116.11.35:8000/b36a1c9113c55be/output.txt

Total script time: 5.13 mins

@vingtetun

Merging to master. Let's see how the new |nightly| branch will handle that.

@vingtetun vingtetun merged commit d584eab into mozilla-b2g:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 14, 2012
  1. @etiennesegonzac

    Removing the dialer background service.

    etiennesegonzac authored
    The emergency dialer living in the lockscreen now has it's own minimal
    call screen.
    
    This also fix a focus issue between the attention screen and the
    lockscreen.
  2. @etiennesegonzac
This page is out of date. Refresh to see the latest.
View
17 apps/communications/dialer/background.html
@@ -1,17 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <meta charset="utf-8">
- <title>Dialer Background Service</title>
- <!-- Localization -->
- <link rel="resource" type="application/l10n" href="/dialer/locales/locales.ini">
- <script type="text/javascript" src="/shared/js/l10n.js"></script>
- <script type="text/javascript" src="/shared/js/settings_listener.js"></script>
- <script type="text/javascript" src="/shared/js/notification_helper.js"></script>
-
- <script type="text/javascript" src="/dialer/js/contacts.js"></script>
- <script type="text/javascript" src="/dialer/js/background.js"></script>
-</head>
-<body>
-</body>
-</html>
View
1  apps/communications/dialer/index.html
@@ -19,7 +19,6 @@
<script defer type="application/javascript" src="/dialer/js/fixed_header.js"></script>
<script defer type="application/javascript" src="/dialer/js/utils.js"></script>
<script defer type="application/javascript" src="/dialer/js/contacts.js"></script>
- <script defer type="application/javascript" src="/dialer/js/notification_helper.js"></script>
<script defer type="application/javascript" src="/dialer/js/keypad.js"></script>
<script defer type="application/javascript" src="/dialer/js/dialer.js"></script>
<script defer type="application/javascript" src="/dialer/js/recents_db.js"></script>
View
131 apps/communications/dialer/js/background.js
@@ -1,131 +0,0 @@
-'use strict';
-
-(function() {
- var telephony = navigator.mozTelephony;
- if (!telephony) {
- return;
- }
-
- /* === Setup === */
- var ringtonePlayer = new Audio();
- ringtonePlayer.loop = true;
-
- /* === Settings === */
- var activePhoneSound = true;
- SettingsListener.observe('phone.ring.incoming', true, function(value) {
- activePhoneSound = !!value;
- });
-
- var selectedPhoneSound = '';
- SettingsListener.observe('dialer.ringtone', 'classic.ogg', function(value) {
- selectedPhoneSound = 'style/ringtones/' + value;
- ringtonePlayer.src = selectedPhoneSound;
- });
-
- var activateVibration = false;
- SettingsListener.observe('phone.vibration.incoming', false, function(value) {
- activateVibration = !!value;
- });
-
- var preferredBrightness = 0.5;
- SettingsListener.observe('screen.brightness', 0.5, function(value) {
- preferredBrightness = parseFloat(value);
- });
-
- var callScreenDisplayed = false;
- window.addEventListener('message', function messageListener(evt) {
- if (evt.data == 'closing') {
- callScreenDisplayed = false;
- }
- });
-
- var screenState = 'locked';
- SettingsListener.observe('lockscreen.locked', false, function(value) {
- if (value) {
- screenState = 'locked';
- } else {
- screenState = 'unlocked';
- }
- });
-
- var _ = navigator.mozL10n.get;
-
- /* === Incoming handling === */
- telephony.addEventListener('callschanged', function bs_incomingHandler(evt) {
- // If the call screen is displayed we don't need
- // to handle new incoming calls here
- if (callScreenDisplayed) {
- return;
- }
-
- var call = null;
- telephony.calls.some(function(aCall) {
- if (aCall.state == 'incoming' || aCall.state == 'dialing') {
- call = aCall;
- return true;
- }
- return false;
- });
-
- if (!call)
- return;
-
- var host = document.location.host;
- var protocol = document.location.protocol;
- var urlBase = protocol + '//' + host + '/dialer/oncall.html';
- window.open(urlBase + '#' + call.state + '?' + screenState,
- 'call_screen', 'attention');
-
- callScreenDisplayed = true;
-
- if (call.state != 'incoming')
- return;
-
- var vibrateInterval = 0;
- if (activateVibration) {
- vibrateInterval = window.setInterval(function vibrate() {
- if ('vibrate' in navigator) {
- navigator.vibrate([200]);
- }
- }, 600);
- }
-
- if (activePhoneSound && selectedPhoneSound) {
- ringtonePlayer.play();
- }
-
- call.onstatechange = function callStateChange() {
- call.onstatechange = null;
-
- ringtonePlayer.pause();
- window.clearInterval(vibrateInterval);
-
- // The call wasn't picked up
- if (call.state == 'disconnected') {
- navigator.mozApps.getSelf().onsuccess = function getSelfCB(evt) {
- var app = evt.target.result;
-
- var iconURL = NotificationHelper.getIconURI(app);
-
- var notiClick = function() {
- // Asking to launch itself
- app.launch('#recents-view');
- };
-
- Contacts.findByNumber(call.number, function lookupContact(contact) {
- var title = _('missedCall');
- var sender = call.number.length ? call.number : _('unknown');
-
- if (contact && contact.name) {
- sender = contact.name;
- }
-
- var body = _('from', {sender: sender});
-
- NotificationHelper.send(title, body, iconURL, notiClick);
- });
- };
- }
- };
- });
-}());
View
111 apps/communications/dialer/js/custom_dialog.js
@@ -1,111 +0,0 @@
-
-'use strict';
-
-var CustomDialog = (function() {
-
- var screen = null;
- var dialog = null;
- var header = null;
- var message = null;
- var yes = null;
- var no = null;
-
- return {
- hide: function dialog_hide() {
- if (screen === null)
- return;
-
- document.body.removeChild(screen);
- screen = null;
- dialog = null;
- header = null;
- message = null;
- yes = null;
- no = null;
- },
-
- /**
- * Method that shows the dialog
- * @param {String} title the title of the dialog. null or empty for
- * no title.
- * @param {String} msg message for the dialog.
- * @param {Object} cancel {title, callback} object when confirm.
- * @param {Object} confirm {title, callback} object when cancel.
- */
- show: function dialog_show(title, msg, cancel, confirm) {
- if (screen === null) {
- screen = document.createElement('section');
- screen.setAttribute('role', 'region');
- screen.id = 'dialog-screen';
-
- dialog = document.createElement('div');
- dialog.id = 'dialog-dialog';
- dialog.setAttribute('role', 'dialog');
- screen.appendChild(dialog);
-
- var info = document.createElement('div');
- info.className = 'center';
-
- if (title && title != '') {
- header = document.createElement('h3');
- header.id = 'dialog-title';
- header.textContent = title;
- info.appendChild(header);
- }
-
- message = document.createElement('p');
- message.id = 'dialog-message';
- info.appendChild(message);
- dialog.appendChild(info);
-
- var menu = document.createElement('menu');
- menu.dataset['items'] = 1;
-
- no = document.createElement('button');
- var noText = document.createTextNode(cancel.title);
- no.appendChild(noText);
- no.id = 'dialog-no';
- no.addEventListener('click', clickHandler);
- menu.appendChild(no);
-
- if (confirm) {
- menu.dataset['items'] = 2;
- yes = document.createElement('button');
- var yesText = document.createTextNode(confirm.title);
- yes.appendChild(yesText);
- yes.id = 'dialog-yes';
- yes.className = 'negative';
- yes.addEventListener('click', clickHandler);
- menu.appendChild(yes);
- }
-
- dialog.appendChild(menu);
-
- document.body.appendChild(screen);
- }
-
- // Put the message in the dialog.
- // Note plain text since this may include text from
- // untrusted app manifests, for example.
- message.textContent = msg;
-
- // Make the screen visible
- screen.classList.add('visible');
-
- // This is the event listener function for the buttons
- function clickHandler(evt) {
-
- // Hide the dialog
- screen.classList.remove('visible');
-
- // Call the appropriate callback, if it is defined
- if (evt.target === yes && confirm.callback) {
- confirm.callback();
- } else if (evt.target === no && cancel.callback) {
- cancel.callback();
- }
- }
- }
- };
-}());
-
View
236 apps/communications/dialer/js/dialer.js
@@ -1,83 +1,93 @@
'use strict';
-document.addEventListener('mozvisibilitychange', function visibility(e) {
- if (!document.mozHidden) {
- RecentsDBManager.get(function(recents) {
- Recents.render(recents);
- });
+var CallHandler = (function callHandler() {
+ var telephony = navigator.mozTelephony;
+ var _ = navigator.mozL10n.get;
+
+ var callScreenDisplayed = false;
+ var currentActivity = null;
+
+ /* === Settings === */
+ var screenState = 'locked';
+ SettingsListener.observe('lockscreen.locked', false, function(value) {
+ if (value) {
+ screenState = 'locked';
+ } else {
+ screenState = 'unlocked';
+ }
+ });
+
+ /* === WebActivity === */
+ function handleActivity(activity) {
+ // Workaround here until the bug 787415 is fixed
+ // Gecko is sending an activity event in every multiple entry point
+ // instead only the one that the href match.
+ if (activity.source.name != 'dial')
+ return;
+
+ currentActivity = activity;
+
+ var number = activity.source.data.number;
+ var fillNumber = function actHandleDisplay() {
+ if (number) {
+ KeypadManager.updatePhoneNumber(number);
+ if (window.location.hash != '#keyboard-view') {
+ window.location.hash = '#keyboard-view';
+ }
+ call(number);
+ }
+ }
+
+ if (document.readyState == 'complete') {
+ fillNumber();
+ } else {
+ window.addEventListener('localized', function loadWait() {
+ window.removeEventListener('localized', loadWait);
+ fillNumber();
+ });
+ }
+
+ activity.postResult({ status: 'accepted' });
}
-});
+ window.navigator.mozSetMessageHandler('activity', handleActivity);
-var CallHandler = {
- call: function ch_call(number) {
+ /* === Incoming calls === */
+ function incoming() {
+ if (callScreenDisplayed)
+ return;
+
+ openCallScreen();
+ }
+ window.navigator.mozSetMessageHandler('telephony-incoming', incoming);
+
+ /* === Calls === */
+ function call(number) {
var settings = window.navigator.mozSettings, req;
if (settings) {
- // Once
- // https://bugzilla.mozilla.org/show_bug.cgi?id=788561
- // lands, we should get rid of `getLock()` call below.
- var settingsLock;
- if (settings.createLock) {
- settingsLock = settings.createLock();
- } else {
- settingsLock = settings.getLock();
- }
+ var settingsLock = settings.createLock();
req = settingsLock.get('ril.radio.disabled');
req.addEventListener('success', function onsuccess() {
var status = req.result['ril.radio.disabled'];
if (!status) {
- this.startDial(number);
+ startDial(number);
} else {
- CustomDialog.show(
- _('callFlightModeTitle'),
- _('callFlightModeBody'),
- {
- title: _('callFlightModeBtnOk'),
- callback: function() {
- CustomDialog.hide();
-
- if (CallHandler.activityCurrent) {
- CallHandler.activityCurrent.postError('canceled');
- CallHandler.activityCurrent = null;
- }
- }
- }
- );
+ handleFlightMode();
}
- }.bind(this));
+ });
} else {
- this.startDial(number);
+ startDial(number);
}
- },
-
- _isUSSD: function ch_isUSSD(number) {
- var ussdChars = ['*', '#'];
-
- var relevantNumbers = [];
- relevantNumbers.push(number.slice(0, 1));
- relevantNumbers.push(number.slice(-1));
-
- return relevantNumbers.every(function ussdTest(number) {
- return ussdChars.indexOf(number) !== -1;
- });
- },
+ }
- startDial: function ch_startDial(number) {
- if (this._isUSSD(number)) {
+ function startDial(number) {
+ if (isUSSD(number)) {
UssdManager.send(number);
} else {
var sanitizedNumber = number.replace(/-/g, '');
- var telephony = window.navigator.mozTelephony;
if (telephony) {
- var call;
- if (navigator.mozMobileConnection &&
- navigator.mozMobileConnection.voice &&
- navigator.mozMobileConnection.voice.emergencyCallsOnly) {
- call = telephony.dialEmergency(sanitizedNumber);
- } else {
- call = telephony.dial(sanitizedNumber);
- }
+ var call = telephony.dial(sanitizedNumber);
if (call) {
var cb = function clearPhoneView() {
@@ -85,14 +95,46 @@ var CallHandler = {
};
call.onconnected = cb;
call.ondisconnected = cb;
+ call.onerror = handleError;
- call.onerror = this.callError;
+ if (!callScreenDisplayed)
+ openCallScreen();
}
}
}
- },
+ }
+
+ function isUSSD(number) {
+ var ussdChars = ['*', '#'];
+
+ var relevantNumbers = [];
+ relevantNumbers.push(number.slice(0, 1));
+ relevantNumbers.push(number.slice(-1));
+
+ return relevantNumbers.every(function ussdTest(number) {
+ return ussdChars.indexOf(number) !== -1;
+ });
+ }
+
+ function handleFlightMode() {
+ CustomDialog.show(
+ _('callFlightModeTitle'),
+ _('callFlightModeBody'),
+ {
+ title: _('callFlightModeBtnOk'),
+ callback: function() {
+ CustomDialog.hide();
- callError: function callError(event) {
+ if (currentActivity) {
+ currentActivity.postError('canceled');
+ currentActivity = null;
+ }
+ }
+ }
+ );
+ }
+
+ function handleError(event) {
var erName = event.call.error.name, emgcyDialogBody,
errorRecognized = false;
@@ -117,7 +159,33 @@ var CallHandler = {
);
}
}
-};
+
+ /* === Attention Screen === */
+ function openCallScreen() {
+ if (callScreenDisplayed)
+ return;
+
+ callScreenDisplayed = true;
+
+ var host = document.location.host;
+ var protocol = document.location.protocol;
+ var urlBase = protocol + '//' + host + '/dialer/oncall.html';
+ window.open(urlBase + '#' + screenState,
+ 'call_screen', 'attention');
+ }
+
+ // We use a simple postMessage protocol to know when the call screen is closed
+ function handleMessage(evt) {
+ if (evt.data == 'closing') {
+ callScreenDisplayed = false;
+ }
+ }
+ window.addEventListener('message', handleMessage);
+
+ return {
+ call: call
+ };
+})();
var NavbarManager = {
init: function nm_init() {
@@ -172,38 +240,6 @@ window.addEventListener('localized', function startup(evt) {
document.body.classList.remove('hidden');
});
-window.navigator.mozSetMessageHandler('activity', function actHandle(activity) {
- // Workaround here until the bug 787415 is fixed
- // Gecko is sending an activity event in every multiple entry point
- // instead only the one that the href match.
- if (activity.source.name != 'dial')
- return;
-
- CallHandler.activityCurrent = activity;
-
- var number = activity.source.data.number;
- var fillNumber = function actHandleDisplay() {
- if (number) {
- KeypadManager.updatePhoneNumber(number);
- if (window.location.hash != '#keyboard-view') {
- window.location.hash = '#keyboard-view';
- }
- CallHandler.call(number);
- }
- }
-
- if (document.readyState == 'complete') {
- fillNumber();
- } else {
- window.addEventListener('localized', function loadWait() {
- window.removeEventListener('localized', loadWait);
- fillNumber();
- });
- }
-
- activity.postResult({ status: 'accepted' });
-});
-
// Listening to the keyboard being shown
// Waiting for issue 787444 being fixed
window.onresize = function(e) {
@@ -214,3 +250,13 @@ window.onresize = function(e) {
}
};
+// Keeping the call history up to date
+document.addEventListener('mozvisibilitychange', function visibility(e) {
+ if (!document.mozHidden) {

nit:

  if (document.mozHidden) {
    return;
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ RecentsDBManager.init(function dbReady() {
+ RecentsDBManager.get(function(recents) {
+ Recents.render(recents);
+ });
+ });
+ }
+});
View
440 apps/communications/dialer/js/oncall.js
@@ -7,6 +7,7 @@ var CallScreen = {
views: document.getElementById('views'),
calls: document.getElementById('calls'),
+
get activeCall() {
delete this.activeCall;
return this.activeCall = this.calls.querySelector(':not(.held)');
@@ -38,17 +39,17 @@ var CallScreen = {
this.answerButton.addEventListener('mouseup',
OnCallHandler.answer.bind(OnCallHandler));
this.rejectButton.addEventListener('mouseup',
- OnCallHandler.end.bind(OnCallHandler));
+ OnCallHandler.end);
this.incomingAnswer.addEventListener('mouseup',
- OnCallHandler.holdAndAnswer.bind(OnCallHandler));
+ OnCallHandler.holdAndAnswer);
this.incomingEnd.addEventListener('mouseup',
- OnCallHandler.endAndAnswer.bind(OnCallHandler));
+ OnCallHandler.endAndAnswer);
this.incomingIgnore.addEventListener('mouseup',
- OnCallHandler.ignore.bind(OnCallHandler));
+ OnCallHandler.ignore);

mouseup/mouseup/mouseup/mouseup indent on the second line sounds broken

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
this.calls.addEventListener('click',
- OnCallHandler.toggleCalls.bind(OnCallHandler));
+ OnCallHandler.toggleCalls);
},
@@ -149,154 +150,224 @@ var CallScreen = {
}
};
-var OnCallHandler = {
- CALLS_LIMIT: 2, // Changing this will probably require some markup changes
+var OnCallHandler = (function onCallHandler() {
+ // Changing this will probably require markup changes
+ var CALLS_LIMIT = 2;
+ var _ = navigator.mozL10n.get;
+
+ var handledCalls = [];
+ var telephony = window.navigator.mozTelephony;
+
+ var displayed = false;
+ var closing = false;
+ var ringing = false;
- handledCalls: [],
- _telephony: window.navigator.mozTelephony,
+ /* === Settings === */
+ var activePhoneSound = true;
+ SettingsListener.observe('phone.ring.incoming', true, function(value) {
+ activePhoneSound = !!value;
+ });
+
+ var selectedPhoneSound = 'style/ringtones/classic.ogg';
+ SettingsListener.observe('dialer.ringtone', 'classic.ogg', function(value) {
+ selectedPhoneSound = 'style/ringtones/' + value;
+ ringtonePlayer.pause();
+ ringtonePlayer.src = selectedPhoneSound;
+
+ if (ringing) {
+ ringtonePlayer.play();
+ }
+ });
- _displayed: false,
- _closing: false,
+ var ringtonePlayer = new Audio();
+ ringtonePlayer.src = selectedPhoneSound;
+ ringtonePlayer.loop = true;
- setup: function och_setup() {
+ var activateVibration = true;
+ SettingsListener.observe('phone.vibration.incoming', false, function(value) {
+ activateVibration = !!value;
+ });
+
+ /* === Setup === */
+ function setup() {
// Animating the screen in the viewport.
- this.toggleScreen();
+ toggleScreen();
ProximityHandler.enable();
- var telephony = this._telephony;
if (telephony) {
// Somehow the muted property appears to true after initialization.
// Set it to false.
telephony.muted = false;
- var self = this;
- var callsChanged = function och_callsChanged(evt) {
- // Adding any new calls to handledCalls
- telephony.calls.forEach(function callIterator(call) {
- if (call.state == 'incoming' || call.state == 'dialing') {
- var alreadyAdded = self.handledCalls.some(function hcIterator(hc) {
- return (hc.call == call);
- });
-
- if (!alreadyAdded) {
- self._addCall(call);
- }
- }
- });
+ // Needs to be called at least once
+ onCallsChanged();
+ telephony.oncallschanged = onCallsChanged;
- // Removing any ended calls to handledCalls
- self.handledCalls.forEach(function handledCallIterator(hc, index) {
- var stillHere = telephony.calls.some(function hcIterator(call) {
- return (call == hc.call);
- });
+ // If the call was ended before we got here we can close
+ // right away.
+ if (handledCalls.length === 0) {
+ exitCallScreen(false);
+ }
+ }
+ }
- if (!stillHere) {
- self._removeCall(index);
- return;
- }
+ /* === Handled calls === */
+ function onCallsChanged() {
+ // Adding any new calls to handledCalls
+ telephony.calls.forEach(function callIterator(call) {
+ if (call.state == 'incoming' || call.state == 'dialing') {
+ var alreadyAdded = handledCalls.some(function hcIterator(hc) {
+ return (hc.call == call);
});
- // Letting the layout know how many calls we're handling
- CallScreen.calls.dataset.count = self.handledCalls.length;
- };
+ if (!alreadyAdded) {
+ addCall(call);
+ }
+ }
+ });
- // Needs to be called at least once
- callsChanged();
- telephony.oncallschanged = callsChanged;
+ // Removing any ended calls to handledCalls
+ handledCalls.forEach(function handledCallIterator(hc, index) {
+ var stillHere = telephony.calls.some(function hcIterator(call) {
+ return (call == hc.call);
+ });
- // If the call was ended before we got here we can close
- // right away.
- if (this.handledCalls.length === 0) {
- this._close(false);
+ if (!stillHere) {
+ removeCall(index);
+ return;
}
- }
- },
+ });
- answer: function ch_answer() {
- // We should always have only 1 call here
- if (!this.handledCalls.length)
+ // Letting the layout know how many calls we're handling
+ CallScreen.calls.dataset.count = handledCalls.length;
+ }
+
+ function addCall(call) {
+ // Once we already have 1 call, we only care about incomings
+ if (handledCalls.length && (call.state != 'incoming'))
return;
- this.handledCalls[0].call.answer();
- CallScreen.render('connected');
- },
+ // No more room
+ if (handledCalls.length >= CALLS_LIMIT) {
+ call.hangUp();
+ return;
+ }
- holdAndAnswer: function och_holdAndAnswer() {
- var lastCallIndex = this.handledCalls.length - 1;
+ var node = CallScreen.calls.children[handledCalls.length];
+ var hc = new HandledCall(call, node);
+ handledCalls.push(hc);
- this._telephony.active.hold();
- this.handledCalls[lastCallIndex].call.answer();
+ // This is the initial incoming call, need to ring !
+ if (call.state === 'incoming' && handledCalls.length === 1) {
+ handleFirstIncoming(call);
+ }
- CallScreen.hideIncoming();
- },
+ if (handledCalls.length > 1) {
+ // signaling the user of the new call
+ navigator.vibrate([100, 100, 100]);
- endAndAnswer: function och_endAndAnswer() {
- var callToEnd = this._telephony.active;
- this.holdAndAnswer();
+ var number = (call.number.length ? call.number : _('unknown'));
+ Contacts.findByNumber(number, function lookupContact(contact) {
+ if (contact && contact.name) {
+ CallScreen.incomingNumber.textContent = contact.name;
+ return;
+ }
- callToEnd.onheld = function hangUpAfterHold() {
- callToEnd.hangUp();
- };
+ CallScreen.incomingNumber.textContent = number;
+ });
- CallScreen.hideIncoming();
- },
+ CallScreen.showIncoming();
+ } else {
+ if (window.location.hash === '#locked' &&
+ (call.state == 'incoming')) {
+ CallScreen.render('incoming-locked');
+ } else {
+ CallScreen.render(call.state);
+ }
+ }
+ }
- toggleCalls: function och_toggleCalls() {
- if (this.handledCalls.length < 2)
- return;
+ function removeCall(index) {
+ handledCalls.splice(index, 1);
- this._telephony.active.hold();
- },
+ if (handledCalls.length > 0) {
+ // Resuming the first remaining call
+ handledCalls[0].call.resume();
+ CallScreen.hideIncoming();
+ return;
+ }
- ignore: function ch_ignore() {
- var ignoreIndex = this.handledCalls.length - 1;
- this.handledCalls[ignoreIndex].call.hangUp();
+ exitCallScreen(true);
+ }
- CallScreen.hideIncoming();
- },
+ function handleFirstIncoming(call) {
+ var screenLock = navigator.requestWakeLock('screen');
- end: function ch_end() {
- // If there is an active call we end this one
- if (this._telephony.active) {
- this._telephony.active.hangUp();
- return;
+ var vibrateInterval = 0;
+ if (activateVibration) {
+ vibrateInterval = window.setInterval(function vibrate() {
+ if ('vibrate' in navigator) {
+ navigator.vibrate([200]);
+ }
+ }, 600);
}
- // If not we're rejecting the last incoming call
- if (!this.handledCalls.length) {
- this.toggleScreen();
- return;
+ if (activePhoneSound && selectedPhoneSound) {
+ ringtonePlayer.play();
+ ringing = true;
}
- var lastCallIndex = this.handledCalls.length - 1;
- this.handledCalls[lastCallIndex].call.hangUp();
- },
+ call.addEventListener('statechange', function callStateChange() {
+ call.removeEventListener('statechange', callStateChange);
- unmute: function ch_unmute() {
- this._telephony.muted = false;
- },
+ ringtonePlayer.pause();
+ ringing = false;
- toggleMute: function ch_toggleMute() {
- this._telephony.muted = !this._telephony.muted;
- },
+ window.clearInterval(vibrateInterval);
- turnSpeakerOff: function ch_turnSpeakeroff() {
- this._telephony.speakerEnabled = false;
- },
+ if (screenLock) {
+ screenLock.unlock();
+ screenLock = null;
+ }
- toggleSpeaker: function ch_toggleSpeaker() {
- this._telephony.speakerEnabled = !this._telephony.speakerEnabled;
- },
+ // The call wasn't picked up
+ if (call.state == 'disconnected') {

What about an early return?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ navigator.mozApps.getSelf().onsuccess = function getSelfCB(evt) {
+ var app = evt.target.result;
+
+ var iconURL = NotificationHelper.getIconURI(app);
+
+ var notiClick = function() {
+ // Asking to launch itself
+ app.launch('#recents-view');
+ };
+
+ Contacts.findByNumber(call.number, function lookup(contact) {
+ var title = _('missedCall');
+ var sender = call.number.length ?
+ call.number : _('unknown');
+
+ if (contact && contact.name) {
+ sender = contact.name;
+ }
+
+ var body = _('from', {sender: sender});
+
+ NotificationHelper.send(title, body, iconURL, notiClick);
+ });
+ };
+ }
+ });
+ }
+
+ /* === Call Screen === */
+ function toggleScreen() {
+ displayed = !displayed;
- toggleScreen: function ch_toggleScreen() {
CallScreen.screen.classList.remove('animate');
CallScreen.screen.classList.toggle('prerender');
- var displayed = this._displayed;
- this._displayed = !this._displayed;
-
- var self = this;
window.addEventListener('MozAfterPaint', function ch_finishAfterPaint() {
window.removeEventListener('MozAfterPaint', ch_finishAfterPaint);
@@ -309,90 +380,129 @@ var OnCallHandler = {
CallScreen.screen.removeEventListener('transitionend', trWait);
// We did animate the call screen off the viewport
// now closing the window.
- if (displayed) {
- self.closeWindow();
+ if (!displayed) {
+ closeWindow();
}
});
});
});
- },
+ }
+
+ function exitCallScreen(animate) {
+ if (closing)
+ return;
+
+ ProximityHandler.disable();
+
+ closing = true;
+
+ if (animate) {
+ toggleScreen();
+ } else {
+ closeWindow();
+ }
+ }
- closeWindow: function och_closeWindow() {
+ function closeWindow() {
var origin = document.location.protocol + '//' +
document.location.host;
window.opener.postMessage('closing', origin);
window.close();
- },
+ }
- _addCall: function och_addCall(call) {
- // Once we already have 1 call, we only care about incomings
- if (this.handledCalls.length && (call.state != 'incoming'))
+ /* === User Actions === */
+ function answer() {
+ // We should always have only 1 call here
+ if (!handledCalls.length)
return;
- // No more room
- if (this.handledCalls.length >= this.CALLS_LIMIT) {
- call.hangUp();
- return;
- }
+ handledCalls[0].call.answer();
+ CallScreen.render('connected');
+ }
- var node = CallScreen.calls.children[this.handledCalls.length];
- var hc = new HandledCall(call, node);
- this.handledCalls.push(hc);
+ function holdAndAnswer() {
+ var lastCallIndex = handledCalls.length - 1;
- if (this.handledCalls.length > 1) {
- // signaling the user of the new call
- navigator.vibrate([100, 100, 100]);
+ telephony.active.hold();
+ handledCalls[lastCallIndex].call.answer();
- var _ = navigator.mozL10n.get;
- var number = (call.number.length ? call.number : _('unknown'));
- Contacts.findByNumber(number, function lookupContact(contact) {
- if (contact && contact.name) {
- CallScreen.incomingNumber.textContent = contact.name;
- return;
- }
+ CallScreen.hideIncoming();
+ }
- CallScreen.incomingNumber.textContent = number;
- });
+ function endAndAnswer() {
+ var callToEnd = telephony.active;
+ holdAndAnswer();
- CallScreen.showIncoming();
- } else {
- if (window.location.hash.split('?')[1] === 'locked' &&
- (call.state == 'incoming')) {
- CallScreen.render('incoming-locked');
- } else {
- CallScreen.render(call.state);
- }
- }
- },
+ callToEnd.onheld = function hangUpAfterHold() {
+ callToEnd.hangUp();
+ };
- _removeCall: function och_removeCall(index) {
- this.handledCalls.splice(index, 1);
+ CallScreen.hideIncoming();
+ }
- if (this.handledCalls.length > 0) {
- // Resuming the first remaining call
- this.handledCalls[0].call.resume();
- CallScreen.hideIncoming();
+ function toggleCalls() {
+ if (handledCalls.length < 2)
return;
- }
- this._close(true);
- },
+ telephony.active.hold();
+ }
- _close: function och_close(animate) {
- if (this._closing)
- return;
+ function ignore() {
+ var ignoreIndex = handledCalls.length - 1;
+ handledCalls[ignoreIndex].call.hangUp();
- ProximityHandler.disable();
+ CallScreen.hideIncoming();
+ }
- this._closing = true;
+ function end() {
+ // If there is an active call we end this one
+ if (telephony.active) {
+ telephony.active.hangUp();
+ return;
+ }
- if (animate) {
- this.toggleScreen();
- } else {
- this.closeWindow();
+ // If not we're rejecting the last incoming call
+ if (!handledCalls.length) {
+ toggleScreen();
+ return;
}
+
+ var lastCallIndex = handledCalls.length - 1;
+ handledCalls[lastCallIndex].call.hangUp();
}
-};
+
+ function unmute() {
+ telephony.muted = false;
+ }
+
+ function turnSpeakerOff() {
+ telephony.speakerEnabled = false;
+ }
+
+ function toggleMute() {
+ telephony.muted = !telephony.muted;
+ }
+
+ function toggleSpeaker() {
+ telephony.speakerEnabled = !telephony.speakerEnabled;
+ }
+
+ return {
+ setup: setup,
+
+ answer: answer,
+ holdAndAnswer: holdAndAnswer,
+ endAndAnswer: endAndAnswer,
+ toggleCalls: toggleCalls,
+ ignore: ignore,
+ end: end,
+
+ toggleMute: toggleMute,
+ toggleSpeaker: toggleSpeaker,
+ unmute: unmute,
+ turnSpeakerOff: turnSpeakerOff
+ };
+})();
window.addEventListener('localized', function callSetup(evt) {
window.removeEventListener('localized', callSetup);
View
1  apps/communications/dialer/oncall.html
@@ -10,6 +10,7 @@
<link rel="resource" type="application/l10n" href="/dialer/locales/locales.ini">
<script type="application/javascript" src="/shared/js/l10n.js"></script>
<script defer type="application/javascript" src="/shared/js/settings_listener.js"></script>
+ <script defer type="text/javascript" src="/shared/js/notification_helper.js"></script>
<script defer type="application/javascript" src="/dialer/js/contacts.js"></script>
<script defer type="application/javascript" src="/dialer/js/keypad.js"></script>
View
7 apps/communications/manifest.webapp
@@ -29,7 +29,6 @@
"voicemail",
"contacts",
"mobileconnection",
- "background",
"attention",
"settings"
],
@@ -37,7 +36,6 @@
"120": "/style/icons/Dialer.png",
"60": "/style/icons/60/Dialer.png"
},
- "background_page": "/dialer/background.html",
"orientation": "portrait-primary",
"activities": {
"pick": {
@@ -63,5 +61,8 @@
"href": "/dialer/index.html",
"disposition": "window"
}
- }
+ },
+ "messages": [
+ { "telephony-incoming": "/dialer/index.html" }
+ ]
}
View
52 apps/system/emergency-call/index.html
@@ -6,8 +6,12 @@
<title>Emergency Call Dialer</title>
<link rel="stylesheet" type="text/css" href="style/dialer.css">
<link rel="stylesheet" type="text/css" href="style/keypad.css">
- <!-- Specific code -->
+ <!-- Shared code -->
<script defer type="application/javascript" src="../shared/js/settings_listener.js"></script>
+ <script src="../shared/js/l10n.js"></script>
+ <link rel="resource" type="application/l10n" href="../locales/locales.ini">
+
+ <!-- Specific code -->
<script defer type="application/javascript" src="js/keypad.js"></script>
<script defer type="application/javascript" src="js/dialer.js"></script>
</head>
@@ -144,5 +148,51 @@
</article>
</section>
</article>
+ <article id="call-screen" class="grid">
+ <article id="calls">
+ <section>
+ <div id="emergency-number" class="number">
+ </div>
+ <div class="fake-number">
+ </div>
+ <div class="additionalContactInfo">
+ <span >Emergency call</span>
+ </div>
+ <div class="duration">
+ <span></span>
+ <div class="direction">
+ <div>
+ </div>
+ </div>
+ </div>
+ </section>
+ </article>
+ <article id="main-container" class="grid-row">
+ <div id="actions-container" class="grid-wrapper grid">
+ <footer id="call-options" class="grid-row">
+ <div class="grid-wrapper grid">
+ <section id="co-advanced" class="grid-row">
+ <div class="grid-wrapper grid">
+ <span class="grid-cell options-column">
+ <button id="speaker" class="co-advanced-option grid-wraper grid">
+ <span>
+ </span>
+ </button>
+ </span>
+ </div>
+ </section>
+ <footer id="callbar">
+ <div id="callbar-hang-up">
+ <span role="button" id="callbar-hang-up-action" class="callbar-button">
+ <div>
+ </div>
+ </span>
+ </div>
+ </footer>
+ </div>
+ </footer>
+ </div>
+ </article>
+ </article>
</body>
</html>
View
63 apps/system/emergency-call/js/dialer.js
@@ -1,23 +1,80 @@
'use strict';
var CallHandler = {
+ _call: null,
+ _telephony: window.navigator.mozTelephony,
+
call: function ch_call(number) {
var sanitizedNumber = number.replace(/-/g, '');
- var telephony = window.navigator.mozTelephony;
+ var telephony = this._telephony;
if (telephony) {
- var call = telephony.dialEmergency(sanitizedNumber);
+ this._call = telephony.dialEmergency(sanitizedNumber);
+ var call = this._call;
if (call) {
var cb = function clearPhoneView() {
KeypadManager.updatePhoneNumber('');
};
call.onconnected = cb;
- call.ondisconnected = cb;
+
+ call.ondisconnected = function callEnded() {
+ cb();
+ CallScreen.hide();
+ };
+
+ CallScreen.number = call.number;
+ CallScreen.show();
}
}
+ },
+
+ end: function ch_end() {
+ if (!this._call) {
+ CallScreen.hide();
+ return;
+ }
+
+ this._call.hangUp();
+ this._call = null;
+ },
+
+ toggleSpeaker: function ch_toggleSpeaker() {
+ this._telephony.speakerEnabled = !this._telephony.speakerEnabled;
+ }
+};
+
+var CallScreen = {
+ screen: document.getElementById('call-screen'),
+ numberView: document.getElementById('emergency-number'),
+
+ hangUpButton: document.getElementById('callbar-hang-up'),
+ speakerButton: document.getElementById('speaker'),
+
+ set number(value) {
+ this.numberView.textContent = value;
+ },
+
+ init: function cs_init() {
+ this.hangUpButton.addEventListener('mouseup',
+ CallHandler.end.bind(CallHandler));
+ this.speakerButton.addEventListener('click', this.toggleSpeaker.bind(this));
+ },
+
+ show: function cs_show() {
+ this.screen.classList.add('displayed');
+ },
+
+ hide: function cs_hide() {
+ this.screen.classList.remove('displayed');
+ },
+
+ toggleSpeaker: function cs_toggleSpeaker() {
+ this.speakerButton.classList.toggle('speak');
+ CallHandler.toggleSpeaker();
}
};
window.addEventListener('load', function onload() {
window.removeEventListener('load', onload);
KeypadManager.init();
+ CallScreen.init();
});
View
164 apps/system/emergency-call/style/dialer.css
@@ -84,3 +84,167 @@ html * {
body.hidden *[data-l10n-id] {
visibility: hidden;
}
+
+/* Call screen */
+#call-screen {
+ position: absolute;
+ bottom: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ margin: 0;
+ border: 0;
+ border-radius: 10px;
+ background: black;
+ -moz-transform: translateY(-100%);
+ z-index: 100;
+
+ -moz-transition: -moz-transform 0.5s ease;
+}
+
+#call-screen.displayed {
+ -moz-transform: translateY(0);
+}
+
+#main-container {
+ position: relative;
+ height: 100%;
+ background: transparent;
+}
+
+#actions-container {
+ position: absolute;
+ bottom: 0;
+ width: 100%;
+ height: 15.5rem;
+}
+
+#call-options {
+ height:9.5rem;
+}
+
+#co-advanced {
+ opacity: 1.0;
+ height: 9.5rem;
+}
+
+.co-advanced-option {
+ background: rgba(0,0,0,.8);
+ height: 9.5rem;
+ width: 100%;
+ border: 0;
+ border-top: 1px solid #3A3A3A;
+ border-bottom: 1px solid #3A3A3A;
+ border-right: 1px solid #3A3A3A;
+}
+
+#co-advanced span.grid-cell:last-child .co-advanced-option {
+ border-right: 0px;
+}
+
+#speaker span {
+ display:inline-block;
+ background-color: #DDD;
+ background:url('images/ActionIcon_40x40_bluetooth.png') ;
+ background-size: 4rem 4rem;
+ width:4rem;
+ height:4rem;
+ opacity: 1.0;
+}
+
+#speaker.speak > span {
+ background:url('images/ActionIcon_40x40_bluetooth_active.png');
+}
+
+#callbar {
+ background:rgba(0,0,0,.8);
+ opacity: 1.0;
+}
+
+#callbar-hang-up {
+ float: left;
+ height: 6.5rem;
+ width: 100%;
+}
+
+.callbar-button {
+ height: 4rem;
+ border:0;
+ border-radius:.3rem;
+ display: block;
+}
+
+#callbar-hang-up-action {
+ background: -moz-linear-gradient(top, #ff0000 1%, #ce0000 100%);
+ opacity: 1.0;
+ margin: 1rem .5rem 1.5rem 1.5rem;
+}
+
+#callbar-hang-up.full-space > #callbar-hang-up-action {
+ margin: 1rem 1.5rem 1.5rem 1.5rem;
+}
+
+#callbar-hang-up-action > div {
+ margin: 0 auto;
+ background-image: url('images/ActionIcon_40x40_hangup.png');
+ background-repeat: no-repeat;
+ background-size: 4rem 4rem;
+ background-position: center;
+ width: 4rem;
+ height: 4rem;
+}
+
+#calls {
+ position: absolute;
+ top: 0;
+ width: 100%;
+ height: 22rem;
+
+ z-index: 500;
+}
+
+#calls > section {
+ position: relative;
+ height: 9rem;
+
+ font-size: 1.8em;
+ line-height: 7rem;
+ background-color: #01c5ed;
+
+ transition: opacity 0.3s linear;
+ opacity: 1;
+}
+
+#calls > section div {
+ padding-left: 2rem;
+ padding-right: 1.5rem;
+}
+
+#calls > section .number {
+ height: 4rem;
+ padding: 2rem 2rem 0 2rem;
+ background: #01c5ed;
+ font-size: 1.6em;
+ line-height: 4rem;
+ color: black;
+}
+
+#calls > section .additionalContactInfo {
+ height: 2rem;
+ padding: 0 2rem 2rem 2rem;
+ background: #01c5ed;
+ font-size: 1.4rem;
+ line-height: 2rem;
+ color: white;
+}
+
+#calls > section .duration {
+ position: absolute;
+ top: 12rem;
+ left: 0;
+ height: 8rem;
+ padding: 2rem;
+ font-size: 2.6em;
+ font-weight: 300;
+ line-height: 8rem;
+}
View
BIN  apps/system/emergency-call/style/images/ActionIcon_40x40_bluetooth.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  apps/system/emergency-call/style/images/ActionIcon_40x40_bluetooth_active.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  apps/system/emergency-call/style/images/ActionIcon_40x40_hangup.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
16 apps/system/js/attention_screen.js
@@ -49,6 +49,13 @@ var AttentionScreen = {
ListMenu.hide();
SleepMenu.hide();
+ // We want the user attention, so we need to turn the screen on
+ // if it's off. The lockscreen will grab the focus when we do that
+ // so we need to do it before adding the new iframe to the dom
+ this._screenInitiallyDisabled = !ScreenManager.screenEnabled;
+ if (this._screenInitiallyDisabled)
+ ScreenManager.turnScreenOn();
+
var attentionFrame = evt.detail.frameElement;
attentionFrame.dataset.frameType = 'attention';
attentionFrame.dataset.frameName = evt.detail.name;
@@ -57,13 +64,7 @@ var AttentionScreen = {
this.attentionScreen.appendChild(attentionFrame);
this.attentionScreen.classList.add('displayed');
- // We want the user attention, so we need to turn the screen on
- // if it's off.
- this._screenInitiallyDisabled = !ScreenManager.screenEnabled;
- if (this._screenInitiallyDisabled)
- ScreenManager.turnScreenOn();
-
- // Ensuring the proper mozvisibility changed on the displayed app
+ // Ensuring the proper mozvisibility change on the displayed app
var displayedOrigin = WindowManager.getDisplayedApp();
if (displayedOrigin) {
var frame = WindowManager.getAppFrame(displayedOrigin);
@@ -105,7 +106,6 @@ var AttentionScreen = {
// We just removed the focused window leaving the system
// without any focused window, let's fix this.
window.focus();
-
},
show: function as_show() {
Something went wrong with that request. Please try again.