LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
StatusBarServicesConnector.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2010-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef STATUSBARSERVICESCONNECTOR_H
23 #define STATUSBARSERVICESCONNECTOR_H
24 
25 
26 #include <QObject>
27 #include <lunaservice.h>
28 #include <set>
29 
30 #include "StatusBar.h"
31 
32 struct json_object;
33 
34 
35 typedef struct WifiAccessPoint {
36  char ssid[40];
37  int profileId;
39  char securityType[20];
40  bool connected;
41  char connectionState[20];
43 
44 typedef struct BluetoothDevice {
45  char displayName[80];
46  char connectionState[20];
47  char btAddress[20];
48  unsigned int cod;
51 
52 typedef struct VpnProfile {
53  char displayName[80];
54  char connectionState[20];
55  char profInfo[255];
56 } t_vpnProfile;
57 
58 typedef enum RadioState {
59  RADIO_OFF = 0,
63 } t_radioState;
64 
65 typedef enum AirplaneModeState {
71 
72 typedef enum PhoneType {
77 } t_phoneType;
78 
79 
81 {
82  Q_OBJECT
83 
84 public:
86 
88 
91  void connectToWifiNetwork(std::string ssid, int profileId, std::string security);
92  void setWifiOnState(bool on);
93  void setBluetoothOnState(bool on);
97  void bluetoothProfileConnect(std::string profile, std::string address);
98  void bluetoothProfileDisconnect(std::string profile, std::string address);
99  bool isDeviceConnectedOnMenuProfiles(std::string address);
100  void disconnectAllBtMenuProfiles(std::string address);
101  bool isDeviceConnected(std::string address);
102  void vpnConnectionRequest(bool connect, std::string profileInfo);
103  void requestVpnProfilesList();
104 
105  t_phoneType getPhoneType() { return m_phoneType; }
106 
107 private:
108 
109  void setDemoBuild(bool demo);
110  void requestNetworkAndSignalStatus();
111  void handleTILDisconnected();
112  void setAirplaneMode(bool on);
113  void setRadioStatesForMSMMode(bool on);
114  void setTelephonyPowerState(bool on, bool saveState, bool msmMode = false);
115  void updateAirplaneModeProgress(int radio);
116 
117  static bool statusBarStorageMSMEntryCallback(LSHandle* handle, LSMessage* message, void* ctxt);
118  static bool statusBarStorageMSMProgressCallback(LSHandle* handle, LSMessage* message, void* ctxt);
119  static bool statusBarPowerdServiceUpCallback(LSHandle* handle, LSMessage* message, void* ctxt);
120  static bool statusBarPowerdBatteryEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
121  static bool statusBarPowerdChargerEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
122  static bool statusBarGetBuildNameCallback(LSHandle* handle, LSMessage* message, void* ctxt);
123  static bool statusBarPlatformQueryCallback(LSHandle* handle, LSMessage* message, void* ctxt);
124  static bool statusBarTelephonyServiceUpCallback(LSHandle* handle, LSMessage* message, void* ctxt);
125  static bool statusBarTelephonyPowerEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
126  static bool statusBarTelephonyNetworkEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
127  static bool statusBarTelephonySignalEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
128  static bool statusBarTelephonySIMEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
129  static bool statusBarTelephonyPowerStateChangeCallback(LSHandle* handle, LSMessage* message, void* ctxt);
130  static bool statusBarTelephonyTTYEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
131  static bool statusBarTelephonyHACEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
132  static bool statusBarWanServiceUpCallback(LSHandle* handle, LSMessage* message, void* ctxt);
133  static bool statusBarWanStatusEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
134  static bool statusBarBtMonitorServiceUpCallback(LSHandle* handle, LSMessage* message, void* ctxt);
135  static bool statusBarBtMonitorEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
136  static bool statusBarBtConnectedProfilesInfoCallback(LSHandle* handle, LSMessage* message, void* ctxt);
137  static bool statusBarCallForwardRequestCallback(LSHandle* handle, LSMessage* message, void* ctxt);
138  static bool statusBarBluetoothServiceUpCallback(LSHandle* handle, LSMessage* message, void* ctxt);
139  static bool statusBarBluetoothEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
140  static bool statusBarBluetoothTurnOnCallback(LSHandle* handle, LSMessage* message, void* ctxt);
141  static bool statusBarBluetoothTurnOffCallback(LSHandle* handle, LSMessage* message, void* ctxt);
142  static bool statusBarBluetoothTruestedListCallback(LSHandle* handle, LSMessage* message, void* ctxt);
143  static bool statusBarBluetoothNumProfilesCallback(LSHandle* handle, LSMessage* message, void* ctxt);
144  static bool statusBarConnMgrServiceUpCallback(LSHandle* handle, LSMessage* message, void* ctxt);
145  static bool statusBarConnMgrEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
146  static bool statusBarWiFiServiceUpCallback(LSHandle* handle, LSMessage* message, void* ctxt);
147  static bool statusBarWifiEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
148  static bool statusBarWifiAvailableNetworksListCallback(LSHandle* handle, LSMessage* message, void* ctxt);
149  static bool statusBarWifiConnectCallback(LSHandle* handle, LSMessage* message, void* ctxt);
150  static bool statusBarWifiPowerStateChangeCallback(LSHandle* handle, LSMessage* message, void* ctxt);
151  static bool statusBarVpnServiceUpCallback(LSHandle* handle, LSMessage* message, void* ctxt);
152  static bool statusBarHandleVPNStatusNotification(LSHandle* handle, LSMessage* message, void* ctxt);
153  static bool statusBarVpnDisconnectResponse(LSHandle* handle, LSMessage* message, void* ctxt);
154  static bool statusBarGetSystemTimeCallback(LSHandle* handle, LSMessage* message, void* ctxt);
155 
156  bool storageMSMEntryCallback(LSHandle* handle, LSMessage* message, void* ctxt);
157  bool storageMSMProgressCallback(LSHandle* handle, LSMessage* message, void* ctxt);
158  bool powerdServiceUpCallback(LSHandle* handle, LSMessage* message, void* ctxt);
159  bool powerdBatteryEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
160  bool powerdChargerEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
161  bool platformQueryCallback(LSHandle* handle, LSMessage* message, void* ctxt);
162  bool telephonyServiceUpCallback(LSHandle* handle, LSMessage* message, void* ctxt);
163  bool telephonyPowerEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
164  bool telephonyNetworkEventsCallback(LSHandle* handle, const char* messagePayload, void* ctxt);
165  bool telephonySignalEventsCallback(LSHandle* handle, const char* messagePayload, void* ctxt);
166  bool telephonySIMEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
167  bool telephonyPowerStateChangeCallback(LSHandle* handle, LSMessage* message, void* ctxt);
168  bool telephonyTTYEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
169  bool telephonyHACEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
170  bool wanServiceUpCallback(LSHandle* handle, LSMessage* message, void* ctxt);
171  bool wanStatusEventsCallback(LSHandle* handle, const char* messagePayload, void* ctxt);
172  bool btMonitorServiceUpCallback(LSHandle* handle, LSMessage* message, void* ctxt);
173  bool btMonitorEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
174  bool btConnectedProfilesInfoCallback(LSHandle* handle, LSMessage* message, void* ctxt);
175  bool callForwardRequestCallback(LSHandle* handle, LSMessage* message, void* ctxt);
176  bool bluetoothServiceUpCallback(LSHandle* handle, LSMessage* message, void* ctxt);
177  bool bluetoothEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
178  bool bluetoothTurnOnCallback(LSHandle* handle, LSMessage* message, void* ctxt);
179  bool bluetoothTurnOffCallback(LSHandle* handle, LSMessage* message, void* ctxt);
180  bool bluetoothTruestedListCallback(LSHandle* handle, LSMessage* message, void* ctxt);
181  bool bluetoothNumProfilesCallback(LSHandle* handle, LSMessage* message, void* ctxt);
182  bool connMgrServiceUpCallback(LSHandle* handle, LSMessage* message, void* ctxt);
183  bool connMgrEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
184  bool wiFiServiceUpCallback(LSHandle* handle, LSMessage* message, void* ctxt);
185  bool wifiEventsCallback(LSHandle* handle, LSMessage* message, void* ctxt);
186  bool wifiAvailableNetworksListCallback(LSHandle* handle, LSMessage* message, void* ctxt);
187  bool wifiConnectCallback(LSHandle* handle, LSMessage* message, void* ctxt);
188  bool wifiPowerStateChangeCallback(LSHandle* handle, LSMessage* message, void* ctxt);
189  bool vpnServiceUpCallback(LSHandle* handle, LSMessage* message, void* ctxt);
190  bool handleVPNStatusNotification(LSHandle* handle, LSMessage* message, void* ctxt);
191  bool vpnDisconnectResponse(LSHandle* handle, LSMessage* message, void* ctxt);
192  bool getSystemTimeCallback(LSHandle* handle, LSMessage* message, void* ctxt);
193 
194  void handlePowerStatus(const char* radioState, bool queryResponse = false);
195  void handleNetworkStatus(const char* networkState, struct json_object* event);
196 
197 
198 Q_SIGNALS:
199 
200  void signalPhoneTypeUpdated();
201  void signalPowerdConnectionStateChanged(bool connected);
202  void signalBatteryLevelUpdated(int percentage);
203  void signalChargingStateUpdated(bool charging);
204  void signalCarrierTextChanged(const char* text);
205  void signalRssiIndexChanged(bool show, StatusBar::IndexRSSI index);
206  void signalRssi1xIndexChanged(bool show, StatusBar::IndexRSSI1x index);
207  void signalTTYStateChanged(bool enabled);
208  void signalHACStateChanged(bool enabled);
209  void signalCallForwardStateChanged(bool enabled);
210  void signalRoamingStateChanged(bool enabled);
211  void signalVpnStateChanged(bool enabled);
212  void signalWanIndexChanged(bool show, StatusBar::IndexWAN index);
214  void signalWifiIndexChanged(bool show, StatusBar::IndexWiFi index);
216 
217 
218  // Signals for the System Menu
219  void signalWifiStateChanged(bool wifiOn, bool wifiConnected, std::string wifiSSID, std::string wifiConnState);
220  void signalWifiAvailableNetworksListUpdate(int numNetworks, t_wifiAccessPoint* list);
223  void signalBluetoothConnStateChanged(bool btConnected, std::string deviceName);
224  void signalBluetoothTrustedDevicesUpdate(int numTrustedDevices, t_bluetoothDevice* list);
225  void signalBluetoothParedDevicesAvailable(bool available);
227  void signalVpnProfileListUpdate(int numProfiles, t_vpnProfile* list);
229 
230 
231 private Q_SLOTS:
232  void slotAirplaneModeChanged(bool enabled);
233  void slotRoamingIndicatorChanged();
234  void slotEnterBrickMode(bool);
235  void slotExitBrickMode();
236 
237 private:
238 
239  char m_carrierText[kMaxTitleLength];
240  char m_appTitle[kMaxTitleLength];
241  bool m_appMaximized;
242  bool m_showAppTitle;
243 
244  enum PhoneService {
245  NoService = 0,
246  Service,
247  Limited,
248  Searching
249  };
250 
251  enum BluetoothState {
252  BT_DISCONNECTED = 0,
253  BT_CONNECTING,
254  BT_CONNECTED,
255  BT_DISCONNECTING
256  };
257 
258  struct BluetoothProfState {
259  BluetoothState status;
260  std::string address;
261  std::string name;
262  };
263 
264  std::vector<unsigned int> m_SIMRejectCodes;
265  std::vector<std::string> m_bluetoothProfiles;
266  std::set<std::string> m_bluetoothMenuProfiles;
267  std::map<std::string, BluetoothProfState> m_bluetoothProfileStates;
268 
269  static const int kNumChargeSources = 2;
270  static const char* m_chargeSource[kNumChargeSources];
271  bool m_powerdConnected;
272  int m_batteryLevel;
273  bool m_charging;
274 
275  PhoneType m_phoneType;
276  bool m_phoneRadioState;
277  bool m_simBad;
278  bool m_ruim;
279  bool m_simLocked;
280  bool m_phoneInLimitedService;
281  PhoneService m_phoneService;
282 
283  bool m_callFwdStatusRequested;
284 
285  int m_rssi;
286 
287  bool m_demoBuild;
288  bool m_airplaneMode;
289  bool m_initialAirplaneModeStatus;
290  bool m_airplaneModeTriggered;
291  bool m_apModePhone;
292  bool m_apModeWifi;
293  bool m_apModeBluetooth;
294  bool m_msmStartingRadiosInProgress;
295  bool m_msmModePhone;
296  bool m_msmModeWifi;
297  bool m_msmModeBluetooth;
298 
299  bool m_showBlankStatusOnLimited;
300  bool m_bluetoothRadionOn;
301  bool m_btRadioTurningOn;
302  std::string m_wifiSSID;
303  bool m_wifiRadioOn;
304  bool m_wifiConnected;
305  LSMessageToken m_wifiFindNetworksReq;
306  LSMessageToken m_bluetoothDeviceListReq;
307 
308  bool m_vpnConnected;
309  std::string m_connectedVpnInfo;
310  std::string m_pendingVpnProfile;
311 
312  bool m_hideDataIcon;
313  bool m_isInternetConnectionAvailable;
314 
315  LSHandle* m_service;
316 
317  std::string m_cmPayloadBuffer;
318  std::string m_signalMsgPayloadBuffer;
319  std::string m_phoneEventNetworkPayload;
320 
321 
323  void init();
324 
325  void requestBluetoothConnectedProfilesInfo();
326  void requestCallForwardStatus();
327 
328  void updateBluetoothIcon();
329  void updateBtDeviceInfo(BluetoothProfState* info);
330 
331  bool validSIMRejectCode(unsigned int code);
332  void updateRSSIIcon(bool show, StatusBar::IndexRSSI index);
333  void updateRSSI1xIcon(bool show, StatusBar::IndexRSSI1x index);
334  StatusBar::IndexWAN getWanIndex(bool connected, const char* type);
335 
336 };
337 
338 
339 #endif /* STATUSBARSERVICESCONNECTOR_H */