|
1 /* |
|
2 * Copyright (c) 2004 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 "daemon.h" |
|
19 #include "drivewatcher.h" |
|
20 #include "SWInstDebug.h" |
|
21 #include "securitypolicy.h" |
|
22 #include "sisregistrysession.h" |
|
23 |
|
24 namespace Swi |
|
25 { |
|
26 // CDaemon |
|
27 |
|
28 /*static*/ CDaemon* CDaemon::NewL(MDaemonBehaviour& aBehaviour) |
|
29 { |
|
30 CDaemon* self=NewLC(aBehaviour); |
|
31 CleanupStack::Pop(self); |
|
32 return self; |
|
33 } |
|
34 |
|
35 /*static*/ CDaemon* CDaemon::NewLC(MDaemonBehaviour& aBehaviour) |
|
36 { |
|
37 CDaemon* self=new(ELeave) CDaemon(aBehaviour); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(); |
|
40 return self; |
|
41 } |
|
42 |
|
43 CDaemon::~CDaemon() |
|
44 { |
|
45 iPolicyLockFile.Close(); |
|
46 |
|
47 iWatchers.ResetAndDestroy(); |
|
48 iFs.Close(); |
|
49 } |
|
50 |
|
51 CDaemon::CDaemon(MDaemonBehaviour& aBehaviour) |
|
52 : iBehaviour(aBehaviour) |
|
53 { |
|
54 } |
|
55 |
|
56 void CDaemon::ConstructL() |
|
57 { |
|
58 User::LeaveIfError(iFs.Connect()); |
|
59 |
|
60 LockSensitiveFiles(); |
|
61 StartRecoveryL(); |
|
62 |
|
63 iBehaviour.StartupL(); |
|
64 StartWatchersL(); |
|
65 } |
|
66 |
|
67 void CDaemon::StartWatchersL() |
|
68 { |
|
69 FLOG( _L("Daemon: Start watchers") ); |
|
70 RFs fs; |
|
71 User::LeaveIfError(fs.Connect()); |
|
72 CleanupClosePushL(fs); |
|
73 User::LeaveIfError(fs.ShareProtected()); |
|
74 |
|
75 TDriveList driveList; |
|
76 |
|
77 User::LeaveIfError(fs.DriveList(driveList)); |
|
78 |
|
79 for (TInt drive=0; drive < KMaxDrives; ++drive) |
|
80 { |
|
81 if (driveList[drive] == 0) |
|
82 { |
|
83 continue; |
|
84 } |
|
85 TDriveInfo info; |
|
86 FLOG_1( _L("Daemon: Checking drive %d"), drive ); |
|
87 // Ignore errors since the next drive might work |
|
88 if (KErrNone != fs.Drive(info, drive)) |
|
89 { |
|
90 FLOG_1( _L("Daemon: drive error = %d"), fs.Drive(info, drive) ); |
|
91 /// @todo, log error |
|
92 continue; |
|
93 } |
|
94 |
|
95 FLOG_1( _L("Daemon: info.iDriveAtt %d"), info.iDriveAtt ); |
|
96 FLOG_1( _L("Daemon: iDriveAtt & KDriveAttRemovable %d"), |
|
97 (info.iDriveAtt & KDriveAttRemovable) ); |
|
98 FLOG_1( _L("Daemon: iDriveAtt & KDriveAttLogicallyRemovable %d"), |
|
99 info.iDriveAtt & KDriveAttLogicallyRemovable ); |
|
100 |
|
101 if (info.iDriveAtt & KDriveAttRemovable || |
|
102 info.iDriveAtt & KDriveAttLogicallyRemovable ) |
|
103 { |
|
104 FLOG( _L("Daemon: Ok Drive is Removable or LogicallyRemovable") ); |
|
105 CDriveWatcher* driveWatcher=CDriveWatcher::NewLC(iFs, drive, iBehaviour); |
|
106 User::LeaveIfError(iWatchers.Append(driveWatcher)); |
|
107 CleanupStack::Pop(driveWatcher); |
|
108 } |
|
109 |
|
110 |
|
111 #ifdef __WINS__ |
|
112 // If drive is not seen as removable in wins env., check if |
|
113 // there is Daemon folder and start watcher if needed. |
|
114 if ( ! ( info.iDriveAtt & KDriveAttRemovable || |
|
115 info.iDriveAtt & KDriveAttLogicallyRemovable) ) |
|
116 { |
|
117 // Watcher is not needed for C. |
|
118 if ( drive == 2 ) |
|
119 { |
|
120 continue; |
|
121 } |
|
122 |
|
123 FLOG( _L("Daemon: Drive found. Check private folder") ); |
|
124 _LIT( KDaemonPrivateFolder,":\\private\\10202dce\\" ); |
|
125 TChar driveLetter; |
|
126 User::LeaveIfError( fs.DriveToChar( drive, driveLetter ) ); |
|
127 |
|
128 CDir* list = NULL; |
|
129 HBufC* path = HBufC::NewLC( KMaxFileName ); |
|
130 TPtr pathPtr = path->Des(); |
|
131 pathPtr.Append( driveLetter ); |
|
132 pathPtr.Append( KDaemonPrivateFolder ); |
|
133 |
|
134 // Check if folder exists in this drive. |
|
135 if ( KErrNone == iFs.GetDir( pathPtr, KEntryAttNormal, ESortNone, list ) ) |
|
136 { |
|
137 FLOG_1( _L("Daemon: Private folder found from drive %d."), drive ); |
|
138 |
|
139 CDriveWatcher* driveWatcher = |
|
140 CDriveWatcher::NewLC( iFs, drive, iBehaviour ); |
|
141 |
|
142 User::LeaveIfError( iWatchers.Append( driveWatcher ) ); |
|
143 CleanupStack::Pop( driveWatcher ); |
|
144 } |
|
145 |
|
146 CleanupStack::Pop( path ); |
|
147 } |
|
148 #endif //__WINS__ |
|
149 |
|
150 } |
|
151 CleanupStack::PopAndDestroy(&fs); |
|
152 } // StartWatchersL() |
|
153 |
|
154 |
|
155 void CDaemon::LockSensitiveFiles() |
|
156 { |
|
157 TInt err = iPolicyLockFile.Open( |
|
158 iFs, |
|
159 KSwisPolicyFile, |
|
160 EFileShareReadersOnly | EFileRead); |
|
161 |
|
162 FLOG_1( _L("Daemon: Policy file lock error = %d."), err ); |
|
163 } |
|
164 |
|
165 |
|
166 void CDaemon::StartRecoveryL() |
|
167 { |
|
168 FLOG( _L("Daemon: StartRecoveryL: Check to see if a recovery is needed.") ); |
|
169 RSisRegistrySession registrySession; |
|
170 User::LeaveIfError( registrySession.Connect() ); |
|
171 CleanupClosePushL( registrySession ); |
|
172 |
|
173 // A recovery failure should not affect SWI Daemon start up. |
|
174 TRAP_IGNORE( registrySession.RecoverL() ); |
|
175 |
|
176 CleanupStack::PopAndDestroy( ®istrySession ); |
|
177 |
|
178 FLOG( _L("Daemon: StartRecoveryL: Recovery check finished.") ); |
|
179 } // StartRecoveryL() |
|
180 |
|
181 } // namespace Swi |