|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Keylock policy implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef ___CKEYLOCKPOLICYAPIIMPL__ |
|
20 #define ___CKEYLOCKPOLICYAPIIMPL__ |
|
21 |
|
22 #include <w32std.h> |
|
23 #include <e32base.h> |
|
24 #include <cenrepnotifyhandler.h> |
|
25 #include "keylockpolicyapi.h" |
|
26 |
|
27 /** |
|
28 * Keylock policy component supports three policy types: |
|
29 * |
|
30 * EPolicyActivateKeyguard keys used for keyguard locking |
|
31 * EPolicyDeactivateKeyguard keys used for keyguard unlocking |
|
32 * EPolicyDevicelockQuery keys used for showing devicelock query |
|
33 */ |
|
34 |
|
35 /** |
|
36 * CKeyLockPolicyApi. Trough CKeyLockPolicyApi users can |
|
37 * |
|
38 * @lib keylockpolicy.lib |
|
39 * @since 3.2 |
|
40 */ |
|
41 class CKeyLockPolicyApiImpl : public CBase, public MCenRepNotifyHandlerCallback |
|
42 { |
|
43 public: |
|
44 |
|
45 /** |
|
46 * Use this to create keylock policy |
|
47 * @param TLockPolicyType aType the policy used |
|
48 */ |
|
49 static CKeyLockPolicyApiImpl* NewL( TLockPolicyType aType ); |
|
50 |
|
51 /** |
|
52 * Destructor. |
|
53 */ |
|
54 ~CKeyLockPolicyApiImpl( ); |
|
55 |
|
56 /** |
|
57 * If no policy has been defined for the type it cannot be used. |
|
58 * @return ETrue if has succesfully loaded policy |
|
59 */ |
|
60 TBool HasConfiguration( ); |
|
61 |
|
62 /** |
|
63 * Activates support for keyguard feature so the phone keys cannot |
|
64 * be locked with keyguard. Does not affect the devicelock. |
|
65 * @return standard Symbian error code |
|
66 */ |
|
67 TInt EnableKeyguardFeature( ); |
|
68 |
|
69 /** |
|
70 * Disables support for keyguard feature so the phone keys cannot |
|
71 * be locked with keyguard. Does not affect the devicelock. |
|
72 * @return standard Symbian error code |
|
73 */ |
|
74 TInt DisableKeyguardFeature( ); |
|
75 |
|
76 /** |
|
77 * Whether keyguard feature is currently enabled or disabled. |
|
78 * @return ETrue if keyguard can be locked. |
|
79 */ |
|
80 TBool static KeyguardAllowed( ); |
|
81 |
|
82 /** |
|
83 * Adds a key combination for the policy type defined in the construction. |
|
84 * |
|
85 * @param TUint scan code for primary key |
|
86 * @param TUint scan code for secondary key |
|
87 * @return standard Symbian error code |
|
88 */ |
|
89 TInt AddKeyCombination(TUint32 aPrimaryKey, TUint32 aSecondaryKey ); |
|
90 |
|
91 /** |
|
92 * Removes a key combination for the policy type defined in the construction. |
|
93 * |
|
94 * @param TUint scan code for primary key |
|
95 * @param TUint scan code for secondary key |
|
96 * @return standard Symbian error code |
|
97 */ |
|
98 TInt RemoveKeyCombination(TUint32 aPrimaryKey, TUint32 aSecondaryKey ); |
|
99 |
|
100 /** |
|
101 * Retrieve a key combination on the given index. |
|
102 * |
|
103 * @param TInt aIndex index on the list that stores key combinations |
|
104 * @param TUint key code for primary key |
|
105 * @param TUint key code for secondary key |
|
106 * @return standard Symbian error code |
|
107 */ |
|
108 TInt GetKeyCombination(TInt aIndex, TUint32 &aPrimaryKey, TUint32 &aSecondaryKey ); |
|
109 |
|
110 /** |
|
111 * Clears all the defined key combinations from the policy. |
|
112 * |
|
113 * @return standard Symbian error code |
|
114 */ |
|
115 TInt ClearKeycombinations( ); |
|
116 |
|
117 /** |
|
118 * Handles Key events, returns ETrue the key events match any of the |
|
119 * defined key combinations. Only uses scancodes with type EEventKeyDown. |
|
120 * |
|
121 * @param TKeyEvent aKeyEvent the actual key event |
|
122 * @param TEventCode aType the type of the received key event |
|
123 * @return ETrue if a match was found. |
|
124 */ |
|
125 TBool HandleKeyEventL(const TKeyEvent& aKeyEvent, const TEventCode aType ); |
|
126 |
|
127 /** |
|
128 * Returns true if primary button is pressed and note should be shown. |
|
129 * @return boolean true if primary key is pressed. |
|
130 */ |
|
131 TBool PrimaryKeyPressed( ); |
|
132 |
|
133 /** |
|
134 * Returns Primary key scan code that has been pressed last. |
|
135 * @return scan code value of the primary key if found, NULL if not |
|
136 */ |
|
137 TUint GetLastPrimaryKey( ); |
|
138 |
|
139 private: |
|
140 |
|
141 /** |
|
142 * C++ default constructor (private so cannot be derived). |
|
143 * @param TLockPolicyType aType the policy (TLockPolicyType) used |
|
144 */ |
|
145 CKeyLockPolicyApiImpl( TLockPolicyType aType ); |
|
146 |
|
147 /** |
|
148 * Second constructor initializes the policy |
|
149 */ |
|
150 void ConstructL( ); |
|
151 |
|
152 TInt SetKeyCombination(TUint32 aPrimaryKey, TUint32 aSecondaryKey, TInt aIndex ); |
|
153 |
|
154 TInt FindKeyCombinationIndex(TUint32 aPrimaryKey, TUint32 aSecondaryKey, TInt &aIndex ); |
|
155 |
|
156 TInt GetNewKeyCombinationIndex(TInt &aIndex ); |
|
157 |
|
158 /** |
|
159 * From @c MCenRepNotifyHandlerCallback. Changes in the observed |
|
160 * central repository keys are communicated trough this method. |
|
161 * @param TUint32 aId central repository key |
|
162 * @param TInt aNewValue the new value |
|
163 */ |
|
164 void HandleNotifyInt( TUint32 aId, TInt aNewValue ); |
|
165 |
|
166 /** |
|
167 * A call back to the keylock timer |
|
168 * param TAny aSelf a pointer to the parent class |
|
169 */ |
|
170 static TInt HandleKeyLockTimerTimeout(TAny* aSelf ); |
|
171 |
|
172 private: |
|
173 |
|
174 // handle to central repository |
|
175 CRepository* iRep; |
|
176 |
|
177 // defined configuration |
|
178 RArray<TUint> iPrimaryKeys; |
|
179 RArray<TUint> iSecondaryKeys; |
|
180 RArray<TUint> iWaitingKeys; |
|
181 |
|
182 // defined timeout |
|
183 TUint iTimeout; |
|
184 |
|
185 // first key pressed |
|
186 TBool iPrimaryKeyDown; |
|
187 |
|
188 // index of last primary key in the policy |
|
189 TUint iLastPrimaryKeyIndex; |
|
190 |
|
191 // key configuration mask |
|
192 TUint iMask; |
|
193 |
|
194 // current policy mode |
|
195 TUint iMode; |
|
196 |
|
197 // initialized policy type |
|
198 TUint iType; |
|
199 |
|
200 // if the keyguard is allowed or not |
|
201 TUint iAllowed; |
|
202 |
|
203 // if the keylock policy exists |
|
204 TBool iInitialised; |
|
205 |
|
206 // timer used between primary and secondary keys |
|
207 CPeriodic* iKeyLockTimer; |
|
208 |
|
209 // notifies the changes in keyguard block |
|
210 CCenRepNotifyHandler* iAllowNotif; |
|
211 |
|
212 // notifies the changes in mode |
|
213 CCenRepNotifyHandler* iModeNotif; |
|
214 }; |
|
215 |
|
216 #endif // ___CKEYLOCKPOLICYAPIIMPL__ |