LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DisplayManager.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2008-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 DISPLAYMANAGER_H
23 #define DISPLAYMANAGER_H
24 
25 #include "Common.h"
26 
27 #include "Timer.h"
28 #include "Mutex.h"
29 #include "Event.h"
30 #include "sptr.h"
31 #include "AmbientLightSensor.h"
32 #include "DisplayStates.h"
33 
34 #include <QEvent>
35 #include <QObject>
36 
37 #include "lunaservice.h"
38 
39 #define DISPLAY_LOCK_SCREEN 1
40 #define DISPLAY_UNLOCK_SCREEN 2
41 #define DISPLAY_NIGHT_SCREEN 3
42 #define DISPLAY_DOCK_SCREEN 4
43 
44 #define DISPLAY_EXIT_NIGHT_STAND_MODE 1001
45 
46 #define DISPLAY_SIGNAL_OFF 2001
47 #define DISPLAY_SIGNAL_ON 2002
48 #define DISPLAY_SIGNAL_DIM 2003
49 #define DISPLAY_SIGNAL_DOCK 2004
50 #define DISPLAY_SIGNAL_OFF_ON_CALL 2005
51 
52 #define DISPLAY_ALERT_GENERIC_ACTIVATED 1
53 #define DISPLAY_ALERT_PHONECALL_ACTIVATED 2
54 #define DISPLAY_ALERT_GENERIC_DEACTIVATED 3
55 #define DISPLAY_ALERT_PHONECALL_DEACTIVATED 4
56 
57 #define DISPLAY_BANNER_ACTIVATED 5
58 #define DISPLAY_BANNER_DEACTIVATED 6
59 
60 #define DISPLAY_ALERT_CANCEL 7
61 
62 #define ACTIVE_MESSAGE_PATTERN_SIZE 6
63 
64 
65 class DisplayManager : public QObject
66 {
67  Q_OBJECT
68 
69 public:
70 
72  static DisplayManager* instance ();
73 
74  virtual ~DisplayManager();
75  GMainLoop* mainLoop();
76 
77  virtual bool handleEvent(QEvent *event);
78 
79  bool alert (int state);
80  uint32_t getCoreNaviBrightness();
81 
82  // service notifications for services used
83  static bool powerdServiceNotification(LSHandle *sh, const char *serviceName, bool connected, void *ctx);
84  static bool telephonyServiceNotification(LSHandle *sh, const char *serviceName, bool connected, void *ctx);
85  static bool audiodServiceNotification(LSHandle *sh, const char *serviceName, bool connected, void *ctx);
86  static bool keysServiceNotification(LSHandle *sh, const char *serviceName, bool connected, void *ctx);
87  static bool hiddServiceNotification(LSHandle *sh, const char *serviceName, bool connected, void *ctx);
88 
89  // luna-service methods
90  static bool controlSetState(LSHandle *sh, LSMessage *message, void *ctx);
91  static bool cancelSubscription(LSHandle *sh, LSMessage *message, void *ctx);
92  static bool controlStatus(LSHandle *sh, LSMessage *message, void *ctx);
93  static bool controlGetProperty(LSHandle *sh, LSMessage *message, void *ctx);
94  static bool controlSetProperty(LSHandle *sh, LSMessage *message, void *ctx);
95  static bool controlCallStatus(LSHandle *sh, LSMessage *message, void *ctx);
96 
97  // service callbacks
98  static bool timeoutCallback(LSHandle *sh, LSMessage *message, void *ctx);
99  static bool connectedOnCallback(LSHandle *sh, LSMessage *message, void *ctx);
100  static bool batteryCallback(LSHandle *sh, LSMessage *message, void *ctx);
101  static bool chargerCallback(LSHandle *sh, LSMessage *message, void *ctx);
102  static bool usbDockCallback(LSHandle *sh, LSMessage *message, void *ctx);
103  static bool sliderCallback(LSHandle *sh, LSMessage *message, void *ctx);
104  static bool audiodCallback(LSHandle *sh, LSMessage *message, void *ctx);
105  static void powerdCallback (void);
106 
107  static void getBearingInfo(double& latitude, double& longitude);
108  static void setBearingInfo(double latitude, double longitude);
109 
110  bool pushDNAST (const char *id);
111  bool popDNAST (const char *id);
112  bool updateState (int eventType);
113  bool cancelLockTimer();
114  void setActiveTouchpanel (bool enable);
115  void setAlsDisabled (bool disable);
116 
117  bool orientationSensorOn();
118  bool orientationSensorOff();
119 
120  bool updateNyxWithLocation(double latitude, double longitude);
121 
122  bool isOn() const;
123  bool isUSBCharging() const;
124  bool isOnCall() const;
125  bool isSliderOpen() const;
126  bool isDNAST() const;
127  bool isOnPuck() const;
128  bool hasSlider() const;
129  bool isProximityActivated() const;
130  bool isLocked() const;
131  bool isBacklightOn() const;
132  bool isDisplayOn() const;
133  bool isTouchpanelOn() const;
134  bool isDemo() const;
135 
136  std::string puckId() const;
137 
138  int dimTimeout() const;
139  int offTimeout() const;
140  int lockedOffTimeout() const;
141  int lastEvent() const;
142  int lastUserEvent() const;
143  int lastInternalEvent() const;
144 
145  bool setMaximumBrightness (int maxBrightness, bool save=true);
146  int getMaximumBrightness () { return m_maxBrightness; }
147 
148  void unlock();
149  void lock();
150 
151  bool dock();
152  bool undock();
153 
154  bool allowSuspend();
155  void setSuspended (bool suspended);
156 
157  static void forceVsyncOff(bool forceNoVsync);
158  static bool isVsyncOff();
159 
160 private:
161  static DisplayManager* m_instance;
162  static bool s_forceVsyncDisable;
163  static bool s_vsyncEnabled;
164  static double s_currentLatitude;
165  static double s_currentLongitude;
166 
167  LSPalmService* m_palmService;
168  LSHandle* m_service; // private bus
169  LSHandle* m_publicService; // public bus
170 
171  AmbientLightSensor* m_als;
172  bool m_alsDisabled;
173  bool m_powerdOnline;
174  int32_t m_chargerConnected;
175  int32_t m_batteryL;
176 
177  bool m_onWhenConnected;
178  bool m_drop_key;
179  bool m_drop_pen;
180  bool m_allow_move;
181  int32_t m_dnast;
182  int32_t m_blockedPowerKey;
183 
184  bool m_hasSlider;
185  bool m_sliderOpen;
186  enum {SLIDING_NOW = 2, SLIDING_WAIT = 1, NOT_SLIDING = 0} m_slidingNow;
187  uint32_t m_slidingStart;
188 
189  bool m_dropPowerKey;
190  bool m_penDown;
191  uint32_t m_blockId;
192  uint32_t m_metaId;
193  uint32_t m_lastEvent;
194  uint32_t m_lastUserEvent;
195  uint32_t m_lastInternalEvent;
196  uint32_t m_lastKey;
197  int32_t m_dimTimeout;
198  int32_t m_offTimeout;
199  int32_t m_totalTimeout;
200  int32_t m_lockedOffTimeout;
201  int32_t m_activityTimeout;
202  int32_t m_powerKeyTimeout;
203  bool m_onCall;
204  bool m_demo;
205  bool m_homeKeyDown;
206 
207  bool m_bootFinished;
208 
209  int32_t m_alertState;
210  int32_t m_proximityCount;
211  bool m_proximityEnabled;
212  bool m_proximityActivated;
213 
214  LSMessageToken m_calbackOnToken;
215  LSMessageToken m_calbackOffToken;
216 
217  bool m_displayOn;
218  bool m_touchpanelIsOn;
219  bool m_backlightIsOn;
220  bool m_activeTouchpanel;
221  Timer<DisplayManager>* m_activity;
222  Timer<DisplayManager>* m_power;
223  Timer<DisplayManager>* m_slider;
224  Timer<DisplayManager>* m_alertTimer;
225  int32_t m_maxBrightness;
226 
227  std::string m_puckId;
228 
229  DisplayStateBase* m_currentState;
230  DisplayStateBase** m_displayStates;
231  DisplayLockState m_lockState;
232 
233  bool off (sptr<Event> event = 0);
234  bool on (sptr<Event> event = 0);
235  bool dim (sptr<Event> event = 0);
236 
237  bool timeout();
238  bool activity();
239  bool power();
240  bool slider();
241  bool alertTimerCallback();
242  bool updateTimeout(int timeoutInMs);
243  bool setTimeout (int timeout);
244  bool notifySubscribers(int type, sptr<Event> event = 0);
245  bool updateBrightness ();
246  int32_t getDisplayBrightness ();
247  int32_t getKeypadBrightness ();
248  DisplayState currentState() const;
249  void setTouchpanelMode (bool active);
250 
251  friend class DisplayStateBase;
252 
253  void changeDisplayState (DisplayState newDisplayState, DisplayState oldDisplayState, DisplayEvent displayEvent, sptr<Event> event);
254  void updateLockState (DisplayLockState lockState, DisplayState state, DisplayEvent displayEvent);
255  // used by DisplayStateBase class to change current state
256 
257  void displayOn(bool als);
258  void displayAdjust();
259  void displayOff();
260  void displayDim();
261 
262  bool proximityOn();
263  bool proximityOff();
264 
265  void emitDisplayStateChange (int displaySignal);
266  void requestCurrentLocation();
267 
268  // internal methods
269  void backlightOn (int displayBrightness, int keyBrightness, bool als);
270  static void backlightOnCallback (void* ctx);
271  void backlightOff();
272  static void backlightOffCallback (void* ctx);
273 
274  bool touchPanelOn();
275  bool touchPanelOff();
276  static bool touchPanelOffCallback (LSHandle* sh, LSMessage* message, void* ctx);
277  static bool updateCompassBearingInfo(LSHandle* sh, LSMessage* message, void* ctx);
278 
279  void initStates();
280  void clearStates();
281 
282  static void changeVsyncControl(bool enable);
283 
284 private Q_SLOTS:
285 
286  void slotEmergencyMode (bool enable);
287  void slotAlsEnabled (bool enable);
288  void slotBootFinished();
289  void slotShowIME();
290  void slotHideIME();
291  void slotBluetoothKeyboardActive(bool active);
292  void slotAirplaneModeChanged(bool change);
293 
294 Q_SIGNALS:
295 
296  void signalDisplayStateChange(int state);
297  void signalPuckConnected(bool connected);
298  void signalLockStateChange(int state, int displayEvent);
299  void signalDisplayMaxBrightnessChanged(int brightness);
300 };
301 
302 
303 #endif /* DISPLAYMANAGER_H */
304