18 #include "lockaccessextension.h" |
18 #include "lockaccessextension.h" |
19 #include <lockappclientserver.h> |
19 #include <lockappclientserver.h> |
20 #include <e32property.h> // P&S API |
20 #include <e32property.h> // P&S API |
21 #include <apgtask.h> // TApaTask, TApaTaskList |
21 #include <apgtask.h> // TApaTask, TApaTaskList |
22 #include <coemain.h> // CCoeEnv |
22 #include <coemain.h> // CCoeEnv |
|
23 #include "../../Autolock/PubSub/securityuisprivatepskeys.h" |
|
24 #include <apgcli.h> |
|
25 #include <apacmdln.h> |
23 |
26 |
24 #include <xqservicerequest.h> |
27 #include <xqservicerequest.h> |
25 #include <xqserviceutil.h> |
28 #include <xqserviceutil.h> |
26 #include <xqrequestinfo.h> |
29 #include <xqrequestinfo.h> |
27 #include <xqaiwrequest.h> |
30 #include <xqaiwrequest.h> |
73 // Ensures that the connection to the service is alive. |
76 // Ensures that the connection to the service is alive. |
74 // --------------------------------------------------------------------------- |
77 // --------------------------------------------------------------------------- |
75 TInt RLockAccessExtension::EnsureConnected( ) |
78 TInt RLockAccessExtension::EnsureConnected( ) |
76 { |
79 { |
77 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); |
78 /* |
140 /* |
79 this is the old method. Now we use QtHighway |
141 this is the old method. |
80 // we need CCoeEnv because of window group list |
142 // we need CCoeEnv because of window group list |
81 const TInt KTimesToConnectServer( 2); |
143 const TInt KTimesToConnectServer( 2); |
82 const TInt KTimeoutBeforeRetrying( 50000); |
144 const TInt KTimeoutBeforeRetrying( 50000); |
83 CCoeEnv* coeEnv = CCoeEnv::Static( ); |
145 CCoeEnv* coeEnv = CCoeEnv::Static( ); |
84 if ( coeEnv ) |
146 if ( coeEnv ) |
106 // --------------------------------------------------------------------------- |
168 // --------------------------------------------------------------------------- |
107 // Sends blind message to lockapp if the session is connected. |
169 // Sends blind message to lockapp if the session is connected. |
108 // --------------------------------------------------------------------------- |
170 // --------------------------------------------------------------------------- |
109 TInt RLockAccessExtension::SendMessage( TInt aMessage ) |
171 TInt RLockAccessExtension::SendMessage( TInt aMessage ) |
110 { |
172 { |
111 TInt ret = EnsureConnected( ); |
173 RDEBUG("0", 0); |
|
174 TInt ret = KErrNone; |
112 if ( ret == KErrNone ) |
175 if ( ret == KErrNone ) |
113 { |
176 { |
114 // ret = SendReceive( aMessage ); |
177 // ret = SendReceive( aMessage ); |
115 ret = SendMessage( aMessage, -1, -1 ); |
178 ret = SendMessage( aMessage, -1, -1 ); |
116 } |
179 } |
120 // --------------------------------------------------------------------------- |
183 // --------------------------------------------------------------------------- |
121 // Sends blind message to lockapp if the session is connected. |
184 // Sends blind message to lockapp if the session is connected. |
122 // --------------------------------------------------------------------------- |
185 // --------------------------------------------------------------------------- |
123 TInt RLockAccessExtension::SendMessage( TInt aMessage, TInt aParam1 ) |
186 TInt RLockAccessExtension::SendMessage( TInt aMessage, TInt aParam1 ) |
124 { |
187 { |
125 TInt ret = EnsureConnected( ); |
188 RDEBUG("0", 0); |
|
189 TInt ret = KErrNone; |
126 if ( ret == KErrNone ) |
190 if ( ret == KErrNone ) |
127 { |
191 { |
128 // assign parameters to IPC argument |
192 // assign parameters to IPC argument |
129 TIpcArgs args(aParam1); |
193 TIpcArgs args(aParam1); |
130 // ret = SendReceive( aMessage, args ); |
194 // ret = SendReceive( aMessage, args ); |
136 // --------------------------------------------------------------------------- |
200 // --------------------------------------------------------------------------- |
137 // Sends blind message to lockapp if the session is connected. |
201 // Sends blind message to lockapp if the session is connected. |
138 // --------------------------------------------------------------------------- |
202 // --------------------------------------------------------------------------- |
139 TInt RLockAccessExtension::SendMessage( TInt aMessage, TInt aParam1, TInt aParam2 ) |
203 TInt RLockAccessExtension::SendMessage( TInt aMessage, TInt aParam1, TInt aParam2 ) |
140 { |
204 { |
|
205 RDEBUG("0", 0); |
141 TInt ret = EnsureConnected( ); |
206 TInt ret = EnsureConnected( ); |
142 RDEBUG("ret", ret); |
207 RDEBUG("ret", ret); |
143 if ( ret == KErrNone ) |
208 if ( ret == KErrNone ) |
144 { |
209 { |
145 // assign parameters to IPC argument |
210 // assign parameters to IPC argument |