|
1 /* |
|
2 * Copyright (c) 2004-2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "daemonbehaviour.h" |
|
19 #include "swispubsubdefs.h" |
|
20 #include "recsisx.h" |
|
21 #include "sisregistrywritablesession.h" |
|
22 #include "SWInstDebug.h" |
|
23 #include "sisregistryentry.h" |
|
24 |
|
25 |
|
26 namespace Swi |
|
27 { |
|
28 // For uninstaller |
|
29 CDaemonBehaviour* CDaemonBehaviour::NewL( CProgramStatus& aMainStatus ) |
|
30 { |
|
31 CDaemonBehaviour* self = NewLC( aMainStatus ); |
|
32 CleanupStack::Pop(self); |
|
33 return self; |
|
34 } |
|
35 |
|
36 CDaemonBehaviour* CDaemonBehaviour::NewLC( CProgramStatus& aMainStatus ) |
|
37 { |
|
38 CDaemonBehaviour* self = new (ELeave) CDaemonBehaviour; |
|
39 CleanupStack::PushL(self); |
|
40 self->ConstructL( aMainStatus ); |
|
41 return self; |
|
42 } |
|
43 |
|
44 void CDaemonBehaviour::ConstructL( CProgramStatus& aMainStatus ) |
|
45 { |
|
46 User::LeaveIfError(iFs.Connect()); |
|
47 User::LeaveIfError(iFs.ShareProtected()); |
|
48 |
|
49 // For uninstaller |
|
50 iSisInstaller = CSisInstaller::NewL( this, aMainStatus ); |
|
51 // Create plugin |
|
52 TRAP_IGNORE( iSwiDaemonPlugin = CSwiDaemonPlugin::NewL() ); |
|
53 } |
|
54 |
|
55 CDaemonBehaviour::~CDaemonBehaviour() |
|
56 { |
|
57 if ( iSwiDaemonPlugin ) |
|
58 { |
|
59 delete iSwiDaemonPlugin; |
|
60 REComSession::FinalClose(); |
|
61 } |
|
62 delete iSisInstaller; |
|
63 iSisInstaller = NULL; |
|
64 iFs.Close(); |
|
65 |
|
66 |
|
67 #ifdef RD_MULTIPLE_DRIVE |
|
68 iDriveArray.Close(); |
|
69 #endif |
|
70 } |
|
71 |
|
72 // from MDaemonBehaviour |
|
73 TBool CDaemonBehaviour::StartupL() |
|
74 { |
|
75 // Return state of Startup |
|
76 return ETrue; |
|
77 } |
|
78 |
|
79 void CDaemonBehaviour::MediaChangeL(TInt aDrive, TChangeType aChangeType) |
|
80 { |
|
81 FLOG_1( _L("Daemon: Media change %d"), aDrive ); |
|
82 RSisRegistryWritableSession registrySession; |
|
83 |
|
84 User::LeaveIfError(registrySession.Connect()); |
|
85 CleanupClosePushL(registrySession); |
|
86 |
|
87 if (aChangeType==EMediaInserted) |
|
88 { |
|
89 FLOG( _L("Daemon: Media inserted") ); |
|
90 // Scan directory on the card and run pre-installed through SWIS |
|
91 ProcessPreinstalledFilesL(aDrive); |
|
92 |
|
93 // notify IAR |
|
94 registrySession.AddDriveL(aDrive); |
|
95 |
|
96 #ifdef RD_MULTIPLE_DRIVE |
|
97 // Add inserted media drive to drive array. |
|
98 if ( iDriveArray.Find(aDrive) == KErrNotFound ) |
|
99 { |
|
100 iDriveArray.AppendL(aDrive); |
|
101 } |
|
102 #endif |
|
103 } |
|
104 else if (aChangeType==EMediaRemoved) |
|
105 { |
|
106 FLOG( _L("Daemon: Media removed") ); |
|
107 |
|
108 #ifdef RD_MULTIPLE_DRIVE |
|
109 // Get Installer state. |
|
110 TBool installerRunning = iSisInstaller->IsInstalling(); |
|
111 #endif |
|
112 |
|
113 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK |
|
114 // notify IAR |
|
115 registrySession.RemoveDriveL(aDrive); |
|
116 #endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK |
|
117 |
|
118 // Cancel all requests for install |
|
119 iSisInstaller->Cancel(); |
|
120 |
|
121 #ifdef RD_MULTIPLE_DRIVE |
|
122 // Notify plugin |
|
123 if(iSwiDaemonPlugin) |
|
124 { |
|
125 TInt index = iDriveArray.Find(aDrive); |
|
126 iSwiDaemonPlugin->MediaRemoved(index); |
|
127 } |
|
128 #else |
|
129 // Notify plugin |
|
130 if(iSwiDaemonPlugin) |
|
131 { |
|
132 iSwiDaemonPlugin->MediaRemoved(aDrive); |
|
133 } |
|
134 #endif //RD_MULTIPLE_DRIVE |
|
135 |
|
136 #ifdef RD_MULTIPLE_DRIVE |
|
137 // Get index of removed drive from array |
|
138 TInt index = iDriveArray.Find(aDrive); |
|
139 |
|
140 if ( index > KErrNotFound ) |
|
141 { |
|
142 iDriveArray.Remove(index); |
|
143 iDriveArray.Compress(); |
|
144 } |
|
145 |
|
146 // Continue installing from other drives if needed. |
|
147 if ( installerRunning ) |
|
148 { |
|
149 // Get count of inserted drives. |
|
150 TInt count = iDriveArray.Count(); |
|
151 |
|
152 if ( count ) |
|
153 { |
|
154 for(index = 0; index < count; index++ ) |
|
155 { |
|
156 ProcessPreinstalledFilesL(iDriveArray[index]); |
|
157 iSisInstaller->StartInstallingL(); |
|
158 } |
|
159 } |
|
160 } |
|
161 #endif |
|
162 } |
|
163 CleanupStack::PopAndDestroy(®istrySession); |
|
164 } |
|
165 |
|
166 void CDaemonBehaviour::ProcessPreinstalledFilesL(TInt aDrive) |
|
167 { |
|
168 _LIT(KDaemonPrivatePath,":\\private\\10202dce\\"); |
|
169 |
|
170 #ifndef RD_MULTIPLE_DRIVE |
|
171 iSisInstaller->Cancel(); |
|
172 #endif |
|
173 // For uninstaller |
|
174 // Set on installing mode. |
|
175 iGeneralProcessStatus = EStateInstalling; |
|
176 FLOG_1( _L("[CDaemonBehaviour] iGeneralProcessStatus = %d"), |
|
177 iGeneralProcessStatus ); |
|
178 |
|
179 ProcessPreinstalledFilesL(aDrive, KDaemonPrivatePath); |
|
180 iStartNotified = EFalse; |
|
181 iDrive = aDrive; |
|
182 iSisInstaller->StartInstallingL(); |
|
183 } |
|
184 |
|
185 void CDaemonBehaviour::ProcessPreinstalledFilesL(TInt aDrive, const TDesC& aDirectory) |
|
186 { |
|
187 FLOG( _L("Daemon: ProcessPreInstalledFilesL") ); |
|
188 TPath preInstalledPath; |
|
189 TChar drive; |
|
190 RFs::DriveToChar(aDrive, drive); |
|
191 preInstalledPath.Append(drive); |
|
192 preInstalledPath.Append(aDirectory); |
|
193 |
|
194 FLOG_1( _L("Daemon: ProcessPreInstalledFilesL Getting dir %S"), &preInstalledPath ); |
|
195 CDir* dir = NULL; |
|
196 TInt err = iFs.GetDir(preInstalledPath, KEntryAttNormal, ESortNone, dir); |
|
197 if (err != KErrNone && err != KErrPathNotFound) |
|
198 { |
|
199 FLOG_1( _L("Daemon: ProcessPreInstalledFilesL GetDir with error %d"), err ); |
|
200 User::Leave(err); |
|
201 } |
|
202 if(dir) |
|
203 { |
|
204 // dir will only exist if GetDir succeeded |
|
205 CleanupStack::PushL(dir); |
|
206 for(TInt i = 0; i < dir->Count(); i++) |
|
207 { |
|
208 const TEntry &entry = (*dir)[i]; |
|
209 if(!entry.IsDir()) |
|
210 { |
|
211 TFileName fileName(preInstalledPath); |
|
212 fileName.Append(entry.iName); |
|
213 iSisInstaller->AddFileToInstallL(fileName); |
|
214 } |
|
215 } |
|
216 CleanupStack::PopAndDestroy(dir); |
|
217 } |
|
218 } |
|
219 |
|
220 // For uninstaller |
|
221 TInt& CDaemonBehaviour::GetProcessStatus() |
|
222 { |
|
223 return iGeneralProcessStatus; |
|
224 } |
|
225 |
|
226 // For uninstaller |
|
227 void CDaemonBehaviour::SetProcessStatus( TInt aStatus ) |
|
228 { |
|
229 iGeneralProcessStatus = aStatus; |
|
230 } |
|
231 |
|
232 // For plugin support |
|
233 void CDaemonBehaviour::DoNotifyMediaProcessingComplete() |
|
234 { |
|
235 if ( iSwiDaemonPlugin && iStartNotified ) |
|
236 { |
|
237 iSwiDaemonPlugin->MediaProcessingComplete(); |
|
238 } |
|
239 } |
|
240 |
|
241 // For plugin support |
|
242 TBool CDaemonBehaviour::IsPlugin() |
|
243 { |
|
244 if ( iSwiDaemonPlugin ) |
|
245 { |
|
246 return ETrue; |
|
247 } |
|
248 return EFalse; |
|
249 } |
|
250 |
|
251 // For plugin support |
|
252 void CDaemonBehaviour::NotifyPlugin() |
|
253 { |
|
254 FLOG( _L("Daemon: NotifyPlugin")); |
|
255 if ( !iStartNotified ) |
|
256 { |
|
257 FLOG_1( _L("Daemon: MediaProcessingStart for drive = %d"), iDrive ); |
|
258 iSwiDaemonPlugin->MediaProcessingStart( iDrive ); |
|
259 iStartNotified = ETrue; |
|
260 } |
|
261 } |
|
262 |
|
263 // For plugin support |
|
264 void CDaemonBehaviour::RequestPluginInstall( TDesC& aSisFile ) |
|
265 { |
|
266 // Note We will open file in here but that is only because |
|
267 // plug-in interface has been designed this way. Original |
|
268 // Symbian SWI daemon did use RApaLsSession for installing |
|
269 // and thus RFile was open already. |
|
270 // Since current SWI Daemon does use SWI API it doesn't |
|
271 // open files and thus we need to open the file in here. |
|
272 FLOG( _L("Daemon: RequestPluginInstall ")); |
|
273 |
|
274 RFile file; |
|
275 User::LeaveIfError( file.Open( |
|
276 iFs, aSisFile, EFileRead | EFileShareReadersOnly ) ); |
|
277 CleanupClosePushL( file ); |
|
278 |
|
279 iSwiDaemonPlugin->RequestInstall( file ); |
|
280 |
|
281 // close file, original SWI Daemon do not leave file open. |
|
282 CleanupStack::PopAndDestroy( &file ); |
|
283 } |
|
284 |
|
285 } // namespace Swi |
|
286 //EOF |