This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
/
signal_icon.js
156 lines (147 loc) · 5.56 KB
/
signal_icon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* global Service, BaseIcon */
'use strict';
(function(exports) {
var SignalIcon = function(manager, index) {
BaseIcon.call(this, manager, index);
};
SignalIcon.prototype = Object.create(BaseIcon.prototype);
SignalIcon.prototype.name = 'SignalIcon';
SignalIcon.prototype.view = function() {
// jshint ignore: start
var index = this.index;
return `<div class="sb-icon sb-icon-signal statusbar-signal"
role="listitem" data-index="${index}">
<div class="sb-icon statusbar-data"></div>
</div>`;
// jshint ignore: end
};
SignalIcon.prototype.render = function() {
this.containerElement =
document.getElementById('statusbar-mobile-connection');
this.containerElement.insertAdjacentHTML('beforeend', this.view());
this.element =
this.containerElement.querySelector('.sb-icon-signal[data-index="' +
this.index + '"]');
this.dataText = this.element.querySelector('.statusbar-data');
};
SignalIcon.prototype.update = function() {
var simslot = this.manager;
var conn = simslot.conn;
var voice = conn.voice;
var data = conn.data;
var _ = document.l10n.setAttributes;
if (!voice || !this.element) {
this.debug('No element or no voice');
return;
}
if (!Service.query('Radio.settingEnabled')) {
this.debug('radio is disabled');
this.hide();
return;
}
if (simslot.isAbsent()) {
// no SIM
this.debug('sim card absent');
delete this.element.dataset.level;
delete this.element.dataset.searching;
this.hide();
this.element.dataset.inactive = true;
_(this.element, 'statusbarSignalNoSimCard');
} else if (data && data.connected &&
data.type && data.type.startsWith('evdo')) {
// "Carrier" / "Carrier (Roaming)" (EVDO)
// Show signal strength of data call as EVDO only supports data call.
this.debug('data connection, level=', data.relSignalStrength);
this.updateSignal(data);
} else if (voice.connected || Service.query('hasActiveCall', this.index)) {
// "Carrier" / "Carrier (Roaming)"
// If voice.connected is false but there is an active call, we should
// check whether the service id of that call equals the current index
// of the target sim card. If yes, that means the user is making an
// emergency call using the target sim card. In such case we should
// also display the signal bar as the normal cases.
this.debug('voice connection, level=', voice.relSignalStrength);
this.updateSignal(voice);
} else if (simslot.isLocked()) {
this.debug('locked simcard');
// SIM locked
// We check if the sim card is locked after checking hasActiveCall
// because we still need to show the signal bars in the case of
// making emergency calls when the sim card is locked.
this.hide();
} else {
this.debug('emergency call only');
// emergencyCallsOnly is always true if voice.connected is false. Show
// searching icon if the device is searching. Or show the signal bars
// with a red "x", which stands for emergency calls only.
this.updateSignal(voice, true);
}
};
SignalIcon.prototype.updateSignal = function(connInfo, emergency) {
if (!this.element) {
return;
}
this.show();
var _ = document.l10n.setAttributes, level;
var previousSearching = (this.element.dataset.searching === 'true');
var previousLevel = parseInt(this.element.dataset.level, 10);
var searching = true;
level = emergency ? -1 : Math.ceil(connInfo.relSignalStrength / 20) || 0;
if (connInfo.state === 'searching') {
this.element.dataset.searching = 'true';
_(this.element, 'statusbarSignalNoneSearching');
} else {
delete this.element.dataset.searching;
_(this.element, 'statusbarEmergencyCallsOnly');
searching = false;
}
this.element.dataset.level = level;
document.l10n.setAttributes(this.element,
connInfo.roaming ? 'statusbarSignalRoaming' : 'statusbarSignal',
{
level: this.element.dataset.level,
operator: connInfo.network && connInfo.network.shortName
}
);
if (previousSearching !== searching || previousLevel !== level) {
this.publish('changed');
}
};
SignalIcon.prototype.updateDataText = function() {
if (!this.element) {
return;
}
var previousHidden = this.dataText.hidden;
var previousText = this.dataText.textContent;
var data = this.manager.conn.data;
if (!data.connected || Service.query('Radio.settingEnabled') === false) {
this.dataText.hidden = true;
if (!previousHidden) {
this.publish('changed');
}
return;
}
// XXX: Maybe we need another icon for this.
this.dataText.hidden = false;
var type = Service.query('getDataConnectionType', this.index);
this.debug('connection type = ', type);
this.element.classList.remove('sb-icon-data-circle');
this.dataText.textContent = '';
if (type) {
if (Service.query('isCDMA', this.index) && Service.query('inCall')) {
// If the current data connection is CDMA types, we need to check
// if there exist any calls. If yes, we have to set the status
// text to empty.
this.dataText.textContent = '';
} else {
this.dataText.textContent = type;
}
} else {
this.element.classList.add('sb-icon-data-circle');
}
if (previousHidden || previousText !== this.dataText.textContent) {
this.publish('changed');
}
};
exports.SignalIcon = SignalIcon;
}(window));