13 * |
13 * |
14 * Description: Extension to lockapp clients. |
14 * Description: Extension to lockapp clients. |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
|
19 #include "lockaccessextension.h" |
18 #include "lockaccessextension.h" |
20 #include <lockappclientserver.h> |
19 #include <lockappclientserver.h> |
21 #include <e32property.h> // P&S API |
20 #include <e32property.h> // P&S API |
22 #include <apgtask.h> // TApaTask, TApaTaskList |
21 #include <apgtask.h> // TApaTask, TApaTaskList |
23 #include <coemain.h> // CCoeEnv |
22 #include <coemain.h> // CCoeEnv |
|
23 #include "../../Autolock/PubSub/securityuisprivatepskeys.h" |
|
24 #include <apgcli.h> |
|
25 #include <apacmdln.h> |
24 |
26 |
25 #include <xqservicerequest.h> |
27 #include <xqservicerequest.h> |
26 #include <xqserviceutil.h> |
28 #include <xqserviceutil.h> |
27 #include <xqrequestinfo.h> |
29 #include <xqrequestinfo.h> |
28 #include <QDebug> |
|
29 #include <xqaiwrequest.h> |
30 #include <xqaiwrequest.h> |
30 #include <xqappmgr.h> |
31 #include <xqappmgr.h> |
31 |
|
32 // Constants |
|
33 const TInt KTimesToConnectServer( 2); |
|
34 const TInt KTimeoutBeforeRetrying( 50000); |
|
35 |
32 |
36 // --------------------------------------------------------------------------- |
33 // --------------------------------------------------------------------------- |
37 // Gets server version, needed for connection |
34 // Gets server version, needed for connection |
38 // --------------------------------------------------------------------------- |
35 // --------------------------------------------------------------------------- |
39 TVersion RLockAccessExtension::GetVersion( ) |
36 TVersion RLockAccessExtension::GetVersion( ) |
69 // LockApp task not found |
66 // LockApp task not found |
70 RDebug::Printf( "%s %s (%u) ???? LockApp task not found=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, KLockAppUid ); |
67 RDebug::Printf( "%s %s (%u) ???? LockApp task not found=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, KLockAppUid ); |
71 ret = KErrNotReady; |
68 ret = KErrNotReady; |
72 } |
69 } |
73 */ |
70 */ |
74 qDebug() << "============= RLockAccessExtension::TryConnect"; |
71 RDEBUG("ret", ret); |
75 qDebug() << ret; |
|
76 return ret; |
72 return ret; |
77 } |
73 } |
78 |
74 |
79 // --------------------------------------------------------------------------- |
75 // --------------------------------------------------------------------------- |
80 // Ensures that the connection to the service is alive. |
76 // Ensures that the connection to the service is alive. |
81 // --------------------------------------------------------------------------- |
77 // --------------------------------------------------------------------------- |
82 TInt RLockAccessExtension::EnsureConnected( ) |
78 TInt RLockAccessExtension::EnsureConnected( ) |
83 { |
79 { |
84 TInt ret(KErrNone); |
80 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); |
85 /* |
140 /* |
86 this is the old methd. Now we use QtHighway |
141 this is the old method. |
87 // we need CCoeEnv because of window group list |
142 // we need CCoeEnv because of window group list |
|
143 const TInt KTimesToConnectServer( 2); |
|
144 const TInt KTimeoutBeforeRetrying( 50000); |
88 CCoeEnv* coeEnv = CCoeEnv::Static( ); |
145 CCoeEnv* coeEnv = CCoeEnv::Static( ); |
89 if ( coeEnv ) |
146 if ( coeEnv ) |
90 { |
147 { |
91 // All server connections are tried to be made KTriesToConnectServer times because |
148 // All server connections are tried to be made KTriesToConnectServer times because |
92 // occasional fails on connections are possible at least on some servers |
149 // occasional fails on connections are possible at least on some servers |
142 // --------------------------------------------------------------------------- |
200 // --------------------------------------------------------------------------- |
143 // Sends blind message to lockapp if the session is connected. |
201 // Sends blind message to lockapp if the session is connected. |
144 // --------------------------------------------------------------------------- |
202 // --------------------------------------------------------------------------- |
145 TInt RLockAccessExtension::SendMessage( TInt aMessage, TInt aParam1, TInt aParam2 ) |
203 TInt RLockAccessExtension::SendMessage( TInt aMessage, TInt aParam1, TInt aParam2 ) |
146 { |
204 { |
|
205 RDEBUG("0", 0); |
147 TInt ret = EnsureConnected( ); |
206 TInt ret = EnsureConnected( ); |
|
207 RDEBUG("ret", ret); |
148 if ( ret == KErrNone ) |
208 if ( ret == KErrNone ) |
149 { |
209 { |
150 // assign parameters to IPC argument |
210 // assign parameters to IPC argument |
151 // TIpcArgs args( aParam1, aParam2); |
211 // TIpcArgs args( aParam1, aParam2); |
152 // this is the old methd. Now we use QtHighway |
212 // this is the old methd. Now we use QtHighway |
153 // ret = SendReceive( aMessage, args ); |
213 // ret = SendReceive( aMessage, args ); |
154 qDebug() << "============= RLockAccessExtension::SendMessage 123.2"; |
214 RDEBUG("aMessage", aMessage); |
155 qDebug() << aMessage; |
215 RDEBUG("aParam1", aParam1); |
156 qDebug() << aParam1; |
216 RDEBUG("aParam2", aParam2); |
157 qDebug() << aParam2; |
217 |
158 |
218 |
159 if(1==0) |
219 { // old method. Not used any more. Kept as reference |
160 { // old method. Not used any more |
220 /* |
161 XQServiceRequest* mServiceRequest; |
221 XQServiceRequest* mServiceRequest; |
162 qDebug() << "============= RLockAccessExtension::SendMessage 2"; |
222 RDEBUG("XQServiceRequest", 0); |
163 mServiceRequest = new XQServiceRequest("com.nokia.services.AutolockSrv.AutolockSrv","service(QString,QString,QString)");// use , false to make async |
223 mServiceRequest = new XQServiceRequest("com.nokia.services.Autolock.Autolock","service(QString,QString,QString)");// use , false to make async |
164 qDebug() << "============= RLockAccessExtension::SendMessage 2.1"; |
224 RDEBUG("aMessage", 0); |
165 qDebug() << mServiceRequest; |
|
166 QString label; |
225 QString label; |
167 label = "" + QString("%1").arg(aMessage); |
226 label = "" + QString("%1").arg(aMessage); |
168 *mServiceRequest << QString(label); |
227 *mServiceRequest << QString(label); |
169 qDebug() << "============= RLockAccessExtension::SendMessage aParam1"; |
228 RDEBUG("aParam1", 0); |
170 label = "" + QString("%1").arg(aParam1); |
229 label = "" + QString("%1").arg(aParam1); |
171 *mServiceRequest << QString(label); |
230 *mServiceRequest << QString(label); |
172 qDebug() << "============= RLockAccessExtension::SendMessage aParam2"; |
231 RDEBUG("aParam2", 0); |
173 label = "" + QString("%1").arg(aParam2); |
232 label = "" + QString("%1").arg(aParam2); |
174 *mServiceRequest << QString(label); |
233 *mServiceRequest << QString(label); |
175 qDebug() << "============= RLockAccessExtension::SendMessage 3"; |
|
176 int returnvalue; |
234 int returnvalue; |
|
235 RDEBUG("send", 0); |
177 bool ret = mServiceRequest->send(returnvalue); |
236 bool ret = mServiceRequest->send(returnvalue); |
178 qDebug() << "============= RLockAccessExtension::SendMessage ret=" << ret; |
237 RDEBUG("ret", ret); |
179 qDebug() << "============= RLockAccessExtension::SendMessage returnvalue=" << returnvalue; |
238 RDEBUG("returnvalue", returnvalue); |
180 } |
239 */ |
181 else |
240 } |
182 { |
241 |
183 // TODO this always seems to fail because request is NULL |
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 |
184 XQApplicationManager mAppManager; |
248 XQApplicationManager mAppManager; |
185 XQAiwRequest *request; |
249 XQAiwRequest *request; |
186 request = mAppManager.create("com.nokia.services.AutolockSrv", "AutolockSrv", "service(QString,QString,QString)", false); |
250 RDEBUG("create", 0); |
187 // also works with create("AutolockSrv", "service(QString,QString,QString)", false); |
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); |
188 if(request) |
253 if(request) |
189 qDebug() << "============= RLockAccessExtension::SendMessage got request"; |
254 { |
|
255 RDEBUG("got request", 0); |
|
256 } |
190 else |
257 else |
191 { |
258 { |
192 qDebug() << "============= RLockAccessExtension::SendMessage not got request"; |
259 RDEBUG("not got request", 0); |
|
260 RDebug::Printf( "%s %s (%u) not got request=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 ); |
|
261 return KErrAbort; |
193 } |
262 } |
194 |
263 |
195 qDebug() << "============= RLockAccessExtension::SendMessage 121.3"; |
264 RDEBUG("setArguments", 0); |
196 QList<QVariant> args; |
|
197 QString label ; |
|
198 label = "" + QString("%1").arg(aMessage); |
|
199 args << QVariant(QString(label)); |
|
200 qDebug() << "============= RLockAccessExtension::SendMessage 123.4"; |
|
201 label = "" + QString("%1").arg(aParam1); |
|
202 args << QVariant(QString(label)); |
|
203 label = "" + QString("%1").arg(aParam2); |
|
204 args << QVariant(QString(label)); |
|
205 qDebug() << "============= RLockAccessExtension::SendMessage 123.4"; |
|
206 request->setArguments(args); |
265 request->setArguments(args); |
207 qDebug() << "============= RLockAccessExtension::SendMessage 123.5"; |
266 RDEBUG("args", 0); |
208 bool ret = request->send(); |
267 int returnvalue=0; |
209 qDebug() << "============= RLockAccessExtension::SendMessage ret=" << ret; |
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); |
210 int error = request->lastError(); |
274 int error = request->lastError(); |
211 qDebug() << "============= RLockAccessExtension::SendMessage error=" << error; |
275 RDEBUG("error", error); |
|
276 ret = returnvalue; |
212 |
277 |
213 delete request; |
278 delete request; |
214 } |
279 } |
215 } |
280 RDEBUG("ret", ret); |
216 return ret; |
281 return ret; |
217 } |
282 } |
218 |
283 |
219 // End of File |
284 // End of File |