13 * |
13 * |
14 * Description: Extension to lockapp clients. |
14 * Description: Extension to lockapp clients. |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
|
18 |
18 #include "lockaccessextension.h" |
19 #include "lockaccessextension.h" |
19 #include <lockappclientserver.h> |
20 #include <lockappclientserver.h> |
20 #include <e32property.h> // P&S API |
21 #include <e32property.h> // P&S API |
21 #include <apgtask.h> // TApaTask, TApaTaskList |
22 #include <apgtask.h> // TApaTask, TApaTaskList |
22 #include <coemain.h> // CCoeEnv |
23 #include <coemain.h> // CCoeEnv |
23 #include "../../Autolock/PubSub/securityuisprivatepskeys.h" |
|
24 #include <apgcli.h> |
|
25 #include <apacmdln.h> |
|
26 |
24 |
27 #include <xqservicerequest.h> |
25 |
28 #include <xqserviceutil.h> |
26 // Constants |
29 #include <xqrequestinfo.h> |
27 const TInt KTimesToConnectServer( 2); |
30 #include <xqaiwrequest.h> |
28 const TInt KTimeoutBeforeRetrying( 50000); |
31 #include <xqappmgr.h> |
|
32 |
29 |
33 // --------------------------------------------------------------------------- |
30 // --------------------------------------------------------------------------- |
34 // Gets server version, needed for connection |
31 // Gets server version, needed for connection |
35 // --------------------------------------------------------------------------- |
32 // --------------------------------------------------------------------------- |
36 TVersion RLockAccessExtension::GetVersion( ) |
33 TVersion RLockAccessExtension::GetVersion( ) |
65 { |
60 { |
66 // LockApp task not found |
61 // LockApp task not found |
67 RDebug::Printf( "%s %s (%u) ???? LockApp task not found=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, KLockAppUid ); |
62 RDebug::Printf( "%s %s (%u) ???? LockApp task not found=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, KLockAppUid ); |
68 ret = KErrNotReady; |
63 ret = KErrNotReady; |
69 } |
64 } |
70 */ |
|
71 RDEBUG("ret", ret); |
|
72 return ret; |
65 return ret; |
73 } |
66 } |
74 |
67 |
75 // --------------------------------------------------------------------------- |
68 // --------------------------------------------------------------------------- |
76 // Ensures that the connection to the service is alive. |
69 // Ensures that the connection to the service is alive. |
77 // --------------------------------------------------------------------------- |
70 // --------------------------------------------------------------------------- |
78 TInt RLockAccessExtension::EnsureConnected( ) |
71 TInt RLockAccessExtension::EnsureConnected( ) |
79 { |
72 { |
80 TInt ret(KErrNone); |
73 TInt ret(KErrNone); |
81 |
|
82 // Now we use QtHighway, but nevertheless need to be sure that only 1 process is running |
|
83 // This is done because Autolock.exe should start at the beginning, but it might not be ready yet. |
|
84 // As Qthighway will start it, it's better to give time for the first one to prepare itself. |
|
85 TInt err = KErrNone; |
|
86 TInt numAttempts = 0; |
|
87 TInt numberOfInstances = 0; |
|
88 do |
|
89 { |
|
90 numberOfInstances=0; |
|
91 TFullName processName; |
|
92 TFindThread find(_L("*utolock*")); // first letter can can be uppercase or lowercase |
|
93 while( find.Next( processName ) == KErrNone ) |
|
94 { |
|
95 // Autolock[100059b5]0002::Autolock in device |
|
96 // autolock.exe[100059b5]0002::Main in emulator |
|
97 RDEBUG("found process", 1); |
|
98 numberOfInstances++; |
|
99 } // end while |
|
100 RDEBUG("numberOfInstances", numberOfInstances); |
|
101 if(numberOfInstances<=0) |
|
102 { |
|
103 RDEBUG("Autolock.exe not running already. Starting.", 0 ); |
|
104 RApaLsSession ls; |
|
105 User::LeaveIfError(ls.Connect()); |
|
106 CleanupClosePushL(ls); |
|
107 RDEBUG("commandLine", 0); |
|
108 CApaCommandLine* commandLine = CApaCommandLine::NewLC(); |
|
109 commandLine->SetExecutableNameL(_L("autolock.exe")); |
|
110 commandLine->SetCommandL(EApaCommandRun); |
|
111 // Try to launch the application. |
|
112 RDEBUG("StartApp", 0); |
|
113 TInt err = ls.StartApp(*commandLine); // this migh fail |
|
114 CleanupStack::PopAndDestroy(2); // commandLine, ls |
|
115 |
|
116 RDEBUG("Autolock.exe launched. Waiting a bit. err", err ); |
|
117 User::After(1000*1000); |
|
118 RDEBUG("re-verifying Autolock.exe process.", 1 ); |
|
119 } |
|
120 } while (numAttempts++ <3 && numberOfInstances<=0); |
|
121 |
|
122 |
|
123 |
|
124 TInt value = -1; |
|
125 err = KErrNone; |
|
126 numAttempts = 0; |
|
127 while( value<1 && numAttempts++ <10 ) // wait max 5 seconds |
|
128 { |
|
129 // process was started, but still not fully running. Give a bit more time |
|
130 err = RProperty::Get(KPSUidSecurityUIs, KSecurityUIsLockInitiatorUID, value); |
|
131 RDEBUG("err", err); |
|
132 RDEBUG("value", value); |
|
133 if(value<1) |
|
134 { |
|
135 RDEBUG("Autolock.exe has started but it's not fully running", value); |
|
136 User::After(5*100*1000); // half a second |
|
137 } |
|
138 } |
|
139 RDEBUG("numAttempts", numAttempts); |
|
140 /* |
|
141 this is the old method. |
|
142 // we need CCoeEnv because of window group list |
74 // we need CCoeEnv because of window group list |
143 const TInt KTimesToConnectServer( 2); |
|
144 const TInt KTimeoutBeforeRetrying( 50000); |
|
145 CCoeEnv* coeEnv = CCoeEnv::Static( ); |
75 CCoeEnv* coeEnv = CCoeEnv::Static( ); |
146 if ( coeEnv ) |
76 if ( coeEnv ) |
147 { |
77 { |
148 // All server connections are tried to be made KTriesToConnectServer times because |
78 // All server connections are tried to be made KTriesToConnectServer times because |
149 // occasional fails on connections are possible at least on some servers |
79 // occasional fails on connections are possible at least on some servers |
158 else |
88 else |
159 { |
89 { |
160 // No CCoeEnv |
90 // No CCoeEnv |
161 ret = KErrNotSupported; |
91 ret = KErrNotSupported; |
162 } |
92 } |
163 */ |
|
164 RDEBUG("ret", ret); |
|
165 return ret; |
93 return ret; |
166 } |
94 } |
167 |
95 |
168 // --------------------------------------------------------------------------- |
96 // --------------------------------------------------------------------------- |
169 // Sends blind message to lockapp if the session is connected. |
97 // Sends blind message to lockapp if the session is connected. |
170 // --------------------------------------------------------------------------- |
98 // --------------------------------------------------------------------------- |
171 TInt RLockAccessExtension::SendMessage( TInt aMessage ) |
99 TInt RLockAccessExtension::SendMessage( TInt aMessage ) |
172 { |
100 { |
173 RDEBUG("0", 0); |
101 TInt ret = EnsureConnected( ); |
174 TInt ret = KErrNone; |
|
175 if ( ret == KErrNone ) |
102 if ( ret == KErrNone ) |
176 { |
103 { |
177 // ret = SendReceive( aMessage ); |
104 ret = SendReceive( aMessage ); |
178 ret = SendMessage( aMessage, -1, -1 ); |
|
179 } |
105 } |
180 return ret; |
106 return ret; |
181 } |
107 } |
182 |
108 |
183 // --------------------------------------------------------------------------- |
109 // --------------------------------------------------------------------------- |
184 // Sends blind message to lockapp if the session is connected. |
110 // Sends blind message to lockapp if the session is connected. |
185 // --------------------------------------------------------------------------- |
111 // --------------------------------------------------------------------------- |
186 TInt RLockAccessExtension::SendMessage( TInt aMessage, TInt aParam1 ) |
112 TInt RLockAccessExtension::SendMessage( TInt aMessage, TInt aParam1 ) |
187 { |
113 { |
188 RDEBUG("0", 0); |
114 TInt ret = EnsureConnected( ); |
189 TInt ret = KErrNone; |
|
190 if ( ret == KErrNone ) |
115 if ( ret == KErrNone ) |
191 { |
116 { |
192 // assign parameters to IPC argument |
117 // assign parameters to IPC argument |
193 TIpcArgs args(aParam1); |
118 TIpcArgs args(aParam1); |
194 // ret = SendReceive( aMessage, args ); |
119 ret = SendReceive( aMessage, args ); |
195 ret = SendMessage( aMessage, aParam1, -1 ); |
|
196 } |
120 } |
197 return ret; |
121 return ret; |
198 } |
122 } |
199 |
123 |
200 // --------------------------------------------------------------------------- |
124 // --------------------------------------------------------------------------- |
201 // Sends blind message to lockapp if the session is connected. |
125 // Sends blind message to lockapp if the session is connected. |
202 // --------------------------------------------------------------------------- |
126 // --------------------------------------------------------------------------- |
203 TInt RLockAccessExtension::SendMessage( TInt aMessage, TInt aParam1, TInt aParam2 ) |
127 TInt RLockAccessExtension::SendMessage( TInt aMessage, TInt aParam1, TInt aParam2 ) |
204 { |
128 { |
205 RDEBUG("0", 0); |
|
206 TInt ret = EnsureConnected( ); |
129 TInt ret = EnsureConnected( ); |
207 RDEBUG("ret", ret); |
|
208 if ( ret == KErrNone ) |
130 if ( ret == KErrNone ) |
209 { |
131 { |
210 // assign parameters to IPC argument |
132 // assign parameters to IPC argument |
211 // TIpcArgs args( aParam1, aParam2); |
133 TIpcArgs args( aParam1, aParam2); |
212 // this is the old methd. Now we use QtHighway |
134 ret = SendReceive( aMessage, args ); |
213 // ret = SendReceive( aMessage, args ); |
|
214 RDEBUG("aMessage", aMessage); |
|
215 RDEBUG("aParam1", aParam1); |
|
216 RDEBUG("aParam2", aParam2); |
|
217 |
|
218 |
|
219 { // old method. Not used any more. Kept as reference |
|
220 /* |
|
221 XQServiceRequest* mServiceRequest; |
|
222 RDEBUG("XQServiceRequest", 0); |
|
223 mServiceRequest = new XQServiceRequest("com.nokia.services.Autolock.Autolock","service(QString,QString,QString)");// use , false to make async |
|
224 RDEBUG("aMessage", 0); |
|
225 QString label; |
|
226 label = "" + QString("%1").arg(aMessage); |
|
227 *mServiceRequest << QString(label); |
|
228 RDEBUG("aParam1", 0); |
|
229 label = "" + QString("%1").arg(aParam1); |
|
230 *mServiceRequest << QString(label); |
|
231 RDEBUG("aParam2", 0); |
|
232 label = "" + QString("%1").arg(aParam2); |
|
233 *mServiceRequest << QString(label); |
|
234 int returnvalue; |
|
235 RDEBUG("send", 0); |
|
236 bool ret = mServiceRequest->send(returnvalue); |
|
237 RDEBUG("ret", ret); |
|
238 RDEBUG("returnvalue", returnvalue); |
|
239 */ |
|
240 } |
|
241 |
|
242 RDEBUG("args", 0); |
|
243 QList<QVariant> args; |
|
244 args << QVariant(QString(QString::number(aMessage))); |
|
245 args << QVariant(QString(QString::number(aParam1))); |
|
246 args << QVariant(QString(QString::number(aParam2))); |
|
247 |
|
248 XQApplicationManager mAppManager; |
|
249 XQAiwRequest *request; |
|
250 RDEBUG("create", 0); |
|
251 request = mAppManager.create("com.nokia.services.Autolock", "Autolock", "service(QString,QString,QString)", false); |
|
252 // also works with create("Autolock", "service(QString,QString,QString)", false); |
|
253 if(request) |
|
254 { |
|
255 RDEBUG("got request", 0); |
|
256 } |
|
257 else |
|
258 { |
|
259 RDEBUG("not got request", 0); |
|
260 RDebug::Printf( "%s %s (%u) not got request=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 ); |
|
261 return KErrAbort; |
|
262 } |
|
263 |
|
264 RDEBUG("setArguments", 0); |
|
265 request->setArguments(args); |
|
266 RDEBUG("args", 0); |
|
267 int returnvalue=0; |
|
268 QVariant var = QVariant(returnvalue); |
|
269 RDEBUG("send", 0); |
|
270 bool retSend = request->send(var); |
|
271 returnvalue = var.toInt(); |
|
272 RDEBUG("retSend", retSend); |
|
273 RDEBUG("returnvalue", returnvalue); |
|
274 int error = request->lastError(); |
|
275 RDEBUG("error", error); |
|
276 ret = returnvalue; |
|
277 |
|
278 delete request; |
|
279 } |
135 } |
280 RDEBUG("ret", ret); |
|
281 return ret; |
136 return ret; |
282 } |
137 } |
283 |
138 |
284 // End of File |
139 // End of File |