|
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: LockApp server session requested by lockclient |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "lockapptrace.h" |
|
20 #include "lockappsession.h" |
|
21 #include "lockappappui.h" |
|
22 #include "lockappstatecontrolinterface.h" |
|
23 #include "lockapputils.h" |
|
24 #include <lockappclientserver.h> |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // Default Constructor. |
|
28 // --------------------------------------------------------------------------- |
|
29 CLockAppSession::CLockAppSession( ) |
|
30 { |
|
31 |
|
32 // no implementation required |
|
33 } |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // Default Destructor. |
|
37 // --------------------------------------------------------------------------- |
|
38 CLockAppSession::~CLockAppSession( ) |
|
39 { |
|
40 // no implementation required |
|
41 } |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // From @c CApaAppServiceBase. Handles possible error in the lock app session |
|
45 // Method is empty. |
|
46 // --------------------------------------------------------------------------- |
|
47 void CLockAppSession::ServiceError( const RMessage2& aMessage, TInt aError ) |
|
48 { |
|
49 |
|
50 if ( aError == KErrNotReady ) |
|
51 { |
|
52 // initialization not yet ready |
|
53 aMessage.Complete( KErrNotReady ); |
|
54 ERROR( aError, "LockApp initialization not yet ready, KErrNotReady" ); |
|
55 } |
|
56 else |
|
57 { |
|
58 ERROR_1( aError, "Service request has caused a leave, message: %d", aMessage.Function()); |
|
59 CApaAppServiceBase::ServiceError( aMessage, aError ); |
|
60 #ifdef _DEBUG |
|
61 if ( aMessage.Function( )== ELockAppTestDestruct ) |
|
62 { |
|
63 User::Leave( KErrGeneral ); |
|
64 } |
|
65 #endif |
|
66 } |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // From @c CApaAppServiceBase. Handles a client request. Leaving is handled by |
|
71 // CLockAppSession::ServiceError() which reports the error code to the client |
|
72 // --------------------------------------------------------------------------- |
|
73 void CLockAppSession::ServiceL(const RMessage2& aMessage ) |
|
74 { |
|
75 RThread clientThread; |
|
76 TInt err=aMessage.Client(clientThread); |
|
77 // RDebug::Print( _L("called by %S"), &(clientThread.FullName()) ); |
|
78 // RDebug::Print( clientThread.FullName() ); |
|
79 |
|
80 TInt response = KErrNone; |
|
81 // log the message |
|
82 // whole provided server API is implemented here |
|
83 |
|
84 switch ( aMessage.Function( ) ) |
|
85 { |
|
86 case ELockAppEnableKeyguard: |
|
87 // enable with or without note (depends on first parameter) |
|
88 response = DoEnableKeyguardL( aMessage.Int0() ); |
|
89 break; |
|
90 case ELockAppDisableKeyguard: |
|
91 // disable with or without note (depends on first parameter) |
|
92 response = DoDisableKeyguardL( aMessage.Int0() ); |
|
93 break; |
|
94 case ELockAppEnableDevicelock: |
|
95 // check that client has needed capabilities to enable devicelock |
|
96 if ( aMessage.HasCapability( ECapabilityWriteDeviceData ) ) |
|
97 { |
|
98 // first parameter contains the reason |
|
99 response = DoEnableDevicelockL( (TDevicelockReason) aMessage.Int0() ); |
|
100 } |
|
101 else |
|
102 { |
|
103 response = KErrPermissionDenied; |
|
104 } |
|
105 break; |
|
106 case ELockAppDisableDevicelock: |
|
107 // check that client has needed capabilities to disable devicelock |
|
108 if ( aMessage.HasCapability( ECapabilityWriteDeviceData ) ) |
|
109 { |
|
110 response = DoDisableDevicelockL( ); |
|
111 } |
|
112 else |
|
113 { |
|
114 response = KErrPermissionDenied; |
|
115 } |
|
116 break; |
|
117 case ELockAppOfferKeyguard: |
|
118 // offer to lock keyguard |
|
119 response = DoOfferKeyguardL( ); |
|
120 break; |
|
121 case ELockAppOfferDevicelock: |
|
122 // TODO implement this someday if needed |
|
123 response = KErrNotSupported; |
|
124 break; |
|
125 case ELockAppShowKeysLockedNote: |
|
126 response = DoShowKeysLockedNoteL( ); |
|
127 break; |
|
128 #ifdef _DEBUG |
|
129 case ELockAppTestDestruct: |
|
130 // test for leave |
|
131 User::Leave( KErrGeneral ); |
|
132 break; |
|
133 case ELockAppTestInternal: |
|
134 // test internal functions (which cannot be tested trough client API) |
|
135 response = StateControlL()->ExecuteInternalTest( ); |
|
136 break; |
|
137 #endif |
|
138 default: |
|
139 // illegal message call, panic the client process |
|
140 PanicClient( aMessage, ELockPanicIllegalMessage ); |
|
141 return; |
|
142 } |
|
143 |
|
144 INFO_2( "CLockAppSession received service message: %d. Result: %d", aMessage.Function(), response ); |
|
145 aMessage.Complete( response ); |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // Request lockapp to enable keyguard on device (might not be approved, e.g. |
|
150 // devicelock activated). |
|
151 // --------------------------------------------------------------------------- |
|
152 TInt CLockAppSession::DoEnableKeyguardL( TBool aShowNote ) |
|
153 { |
|
154 // calls the main control |
|
155 |
|
156 return StateControlL()->EnableKeyguardL( aShowNote ); |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------------------------- |
|
160 // Request lockapp to disable keyguard on device (might not be approved, e.g. |
|
161 // already disabled). |
|
162 // --------------------------------------------------------------------------- |
|
163 TInt CLockAppSession::DoDisableKeyguardL( TBool aShowNote ) |
|
164 { |
|
165 // calls the main control |
|
166 |
|
167 return StateControlL()->DisableKeyguardL( aShowNote ); |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------------------------- |
|
171 // Request lockapp to enable devicelock on device (might not be approved). |
|
172 // --------------------------------------------------------------------------- |
|
173 TInt CLockAppSession::DoEnableDevicelockL( TDevicelockReason aReason ) |
|
174 { |
|
175 // calls the main control |
|
176 |
|
177 return StateControlL()->EnableDevicelockL( aReason ); |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // Request lockapp to disable devicelock on device (might not be approved). |
|
182 // --------------------------------------------------------------------------- |
|
183 TInt CLockAppSession::DoDisableDevicelockL( ) |
|
184 { |
|
185 // TODO Investigate if this should be allowed in API or not |
|
186 // calls the main control |
|
187 // StateControlL()->DisableDevicelockL( ); |
|
188 return KErrPermissionDenied; |
|
189 } |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // Request to offer keyguard on device (might not be approved, e.g. |
|
193 // already locked). |
|
194 // --------------------------------------------------------------------------- |
|
195 TInt CLockAppSession::DoOfferKeyguardL( ) |
|
196 { |
|
197 // calls the main control |
|
198 return StateControlL()->OfferKeyguard( ); |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // Request to show keys locked note, only works if keyguard is enabled |
|
203 // --------------------------------------------------------------------------- |
|
204 TInt CLockAppSession::DoShowKeysLockedNoteL( ) |
|
205 { |
|
206 // calls the main control |
|
207 |
|
208 return StateControlL()->ShowKeysLockedNote( ); |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // Return the main state control to the server session. |
|
213 // Application appui and the main state control might not be constructed yet. |
|
214 // --------------------------------------------------------------------------- |
|
215 MLockAppStateControl* CLockAppSession::StateControlL( ) |
|
216 { |
|
217 |
|
218 // other parts of lockapp construction may not be finished |
|
219 if ( !iStateControl ) |
|
220 { |
|
221 CLockAppAppUi* appUi = (CLockAppAppUi*) CEikonEnv::Static()->EikAppUi(); |
|
222 if ( appUi ) |
|
223 { |
|
224 iStateControl = appUi->StateControl( ); |
|
225 if ( !iStateControl ) |
|
226 { |
|
227 User::Leave( KErrNotReady ); |
|
228 } |
|
229 } |
|
230 else |
|
231 { |
|
232 User::Leave( KErrNotReady ); |
|
233 } |
|
234 } |
|
235 return iStateControl; |
|
236 } |