80 } |
77 } |
81 |
78 |
82 // End of code from swi/inc/cleanuputils.h |
79 // End of code from swi/inc/cleanuputils.h |
83 // ---------------------------- |
80 // ---------------------------- |
84 |
81 |
85 // ----------------------------------------------------------------------- |
82 |
86 // CPreviouslyInstalledAppsCache::NewL |
|
87 // ----------------------------------------------------------------------- |
|
88 // |
|
89 CPreviouslyInstalledAppsCache *CPreviouslyInstalledAppsCache::NewL() |
83 CPreviouslyInstalledAppsCache *CPreviouslyInstalledAppsCache::NewL() |
90 { |
84 { |
91 CPreviouslyInstalledAppsCache *self = new(ELeave)CPreviouslyInstalledAppsCache; |
85 CPreviouslyInstalledAppsCache *self = new(ELeave)CPreviouslyInstalledAppsCache; |
92 CleanupStack::PushL(self); |
86 CleanupStack::PushL(self); |
93 self->ConstructL(); |
87 self->ConstructL(); |
94 CleanupStack::Pop(self); |
88 CleanupStack::Pop(self); |
95 return self; |
89 return self; |
96 } |
90 } |
97 |
91 |
98 // ----------------------------------------------------------------------- |
|
99 // CPreviouslyInstalledAppsCache::~CPreviouslyInstalledAppsCache |
|
100 // ----------------------------------------------------------------------- |
|
101 // |
|
102 CPreviouslyInstalledAppsCache::~CPreviouslyInstalledAppsCache() |
92 CPreviouslyInstalledAppsCache::~CPreviouslyInstalledAppsCache() |
103 { |
93 { |
104 iPrevPkgUids.Reset(); |
94 iPrevPkgUids.Reset(); |
105 } |
95 } |
106 |
96 |
107 // ----------------------------------------------------------------------- |
97 |
108 // CPreviouslyInstalledAppsCache::UpdateAllL |
|
109 // ----------------------------------------------------------------------- |
|
110 // |
|
111 void CPreviouslyInstalledAppsCache::UpdateAllL() |
98 void CPreviouslyInstalledAppsCache::UpdateAllL() |
112 { |
99 { |
113 FLOG( _L("Daemon: CPreviouslyInstalledAppsCache::UpdateAllL ") ); |
|
114 |
|
115 RThread ourThread; // nb. Default constructor gives handle to current thread. |
100 RThread ourThread; // nb. Default constructor gives handle to current thread. |
116 |
101 if(!ourThread.HasCapability(ECapabilityReadUserData, 0)) |
117 if( !ourThread.HasCapability(ECapabilityReadUserData, 0) ) |
|
118 { |
102 { |
119 // Have not got ReadUserData - if we try and enumerate package |
103 // Have not got ReadUserData - if we try and enumerate package |
120 // UIDs the registry server will panic us! |
104 // UIDs the registry server will panic us! |
121 User::Leave(KErrAccessDenied); |
105 User::Leave(KErrAccessDenied); |
122 } |
106 } |
123 ourThread.Close(); |
107 ourThread.Close(); |
124 |
108 |
125 // Let's use SisRegistry in this case since in SCR there is no |
109 |
126 // simple way to retriev sisx pacakge UIDs in one call. |
110 RSisRegistrySession registrySession; |
127 RSisRegistrySession registrySession; |
111 User::LeaveIfError(registrySession.Connect()); |
128 User::LeaveIfError( registrySession.Connect() ); |
112 CleanupClosePushL(registrySession); |
129 CleanupClosePushL( registrySession ); |
113 |
130 |
114 RPointerArray<CSisRegistryPackage> packages; |
131 RPointerArray<CSisRegistryPackage> packages; |
115 registrySession.InstalledPackagesL(packages); |
132 registrySession.InstalledPackagesL( packages ); |
116 CleanupResetAndDestroy<RPointerArray<CSisRegistryPackage> >::PushL(packages); |
133 CleanupResetAndDestroy< |
117 |
134 RPointerArray<CSisRegistryPackage> >::PushL( packages ); |
118 for (TInt i=0; i< packages.Count(); ++i) |
135 |
119 { |
136 for ( TInt i = 0; i < packages.Count(); ++i ) |
120 (void)iPrevPkgUids.InsertInSignedKeyOrder(packages[i]->Uid()); |
137 { |
121 } |
138 (void)iPrevPkgUids.InsertInSignedKeyOrder( packages[i]->Uid() ); |
122 |
139 |
123 CleanupStack::PopAndDestroy(&packages); |
140 FLOG_1( _L("Daemon: UpdateAllL: Add UID = 0x%x"), |
124 CleanupStack::PopAndDestroy(®istrySession); |
141 packages[i]->Uid().iUid ); |
125 } |
142 } |
126 |
143 |
127 void CPreviouslyInstalledAppsCache::UpdateAddL(TUid aUid) |
144 CleanupStack::PopAndDestroy( &packages ); |
128 { |
145 CleanupStack::PopAndDestroy( ®istrySession ); |
129 RSisRegistrySession registrySession; |
146 } |
130 User::LeaveIfError(registrySession.Connect()); |
147 |
131 CleanupClosePushL(registrySession); |
148 // ----------------------------------------------------------------------- |
132 |
149 // CPreviouslyInstalledAppsCache::UpdateAddL |
133 RSisRegistryEntry registryEntry; |
150 // ----------------------------------------------------------------------- |
134 TInt err = registryEntry.Open(registrySession, aUid); |
151 // |
135 if( err == KErrNone ) |
152 void CPreviouslyInstalledAppsCache::UpdateAddL( TUid aUid ) |
136 { |
153 { |
137 registryEntry.Close(); |
154 FLOG( _L("Daemon: CPreviouslyInstalledAppsCache::UpdateAddL ") ); |
138 (void)iPrevPkgUids.InsertInSignedKeyOrder(aUid); |
155 |
139 } |
156 // Let's use SisRegistry in this case since in SCR there is no |
140 |
157 // simple way to open entry with given package UIDs. |
141 FLOG_1( _L("Daemon: UpdateAddL: UID add error = %d"), err ); |
158 RSisRegistrySession registrySession; |
142 |
159 User::LeaveIfError( registrySession.Connect() ); |
143 CleanupStack::PopAndDestroy(®istrySession); |
160 CleanupClosePushL( registrySession ); |
144 } |
161 |
145 |
162 RSisRegistryEntry registryEntry; |
146 TBool CPreviouslyInstalledAppsCache::HasBeenPreviouslyInstalled(TUid aPackageUid) const |
163 TInt err = registryEntry.Open( registrySession, aUid ); |
147 { |
164 |
148 if(iPrevPkgUids.FindInSignedKeyOrder(aPackageUid) == KErrNotFound) |
165 if( err == KErrNone ) |
|
166 { |
|
167 // Ok close entry and add UID to cache. |
|
168 registryEntry.Close(); |
|
169 (void)iPrevPkgUids.InsertInSignedKeyOrder( aUid ); |
|
170 FLOG_1( _L("Daemon: UpdateAddL: Add UID = 0x%x"), aUid.iUid ); |
|
171 } |
|
172 |
|
173 CleanupStack::PopAndDestroy( ®istrySession ); |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------- |
|
177 // CPreviouslyInstalledAppsCache::HasBeenPreviouslyInstalled |
|
178 // ----------------------------------------------------------------------- |
|
179 // |
|
180 TBool CPreviouslyInstalledAppsCache::HasBeenPreviouslyInstalled( |
|
181 TUid aPackageUid ) const |
|
182 { |
|
183 if ( iPrevPkgUids.FindInSignedKeyOrder( aPackageUid ) == KErrNotFound ) |
|
184 { |
149 { |
185 return EFalse; |
150 return EFalse; |
186 } |
151 } |
187 return ETrue; |
152 return ETrue; |
188 } |
153 } |
189 |
154 |
190 // ----------------------------------------------------------------------- |
|
191 // CPreviouslyInstalledAppsCache::CPreviouslyInstalledAppsCache |
|
192 // ----------------------------------------------------------------------- |
|
193 // |
|
194 CPreviouslyInstalledAppsCache::CPreviouslyInstalledAppsCache() |
155 CPreviouslyInstalledAppsCache::CPreviouslyInstalledAppsCache() |
195 { |
156 { |
196 } |
157 } |
197 |
158 |
198 // ----------------------------------------------------------------------- |
|
199 // CPreviouslyInstalledAppsCache::ConstructL |
|
200 // ----------------------------------------------------------------------- |
|
201 // |
|
202 void CPreviouslyInstalledAppsCache::ConstructL() |
159 void CPreviouslyInstalledAppsCache::ConstructL() |
203 { |
160 { |
204 FLOG( _L("Daemon: CPreviouslyInstalledAppsCache::ConstructL ") ); |
|
205 User::LeaveIfError(iFs.Connect()); |
161 User::LeaveIfError(iFs.Connect()); |
206 TInt drive = 0; |
162 TInt drive = 0; |
207 iFs.CharToDrive( |
163 iFs.CharToDrive( TParsePtrC( PathInfo::PhoneMemoryRootPath() ).Drive()[0], drive ); |
208 TParsePtrC( PathInfo::PhoneMemoryRootPath() ).Drive()[0], |
|
209 drive ); |
|
210 |
|
211 iFs.CreatePrivatePath( drive ); |
164 iFs.CreatePrivatePath( drive ); |
212 |
165 |
213 // Read cache file |
166 // Read cache file |
214 TRAP_IGNORE(InitFromCacheFileL()); |
167 TRAP_IGNORE(InitFromCacheFileL()); |
215 |
168 |
216 //TODO: Test if this is really needed. Let's not do updateall 2 time in boot. |
169 TRAPD( err, UpdateAllL() ); |
217 // TRAPD( err, UpdateAllL() ); |
170 if(err == KErrNone) |
218 // if(err == KErrNone) |
171 { |
219 // { |
172 // If we managed to scan the registry, and update the cache, flush to disk. |
220 // TRAP_IGNORE(FlushToDiskL()); |
173 TRAP_IGNORE(FlushToDiskL()); |
221 // } |
174 } |
222 |
175 |
223 } |
176 } |
224 |
177 |
225 // ----------------------------------------------------------------------- |
178 |
226 // CPreviouslyInstalledAppsCache::InitFromCacheFileL |
|
227 // ----------------------------------------------------------------------- |
|
228 // |
|
229 void CPreviouslyInstalledAppsCache::InitFromCacheFileL() |
179 void CPreviouslyInstalledAppsCache::InitFromCacheFileL() |
230 { |
180 { |
231 // Read in existing cache file. |
181 // Read in existing cache file. |
232 RFile cacheFile; |
182 RFile cacheFile; |
233 TInt err = cacheFile.Open( iFs, |
183 TInt err = cacheFile.Open(iFs, KPreInstalledApps, EFileStream|EFileRead); |
234 KPreInstalledApps, |
184 if(err != KErrNone) |
235 EFileStream|EFileRead); |
|
236 if ( err != KErrNone ) |
|
237 { |
185 { |
238 return; // No existing cache file to read. |
186 return; // No existing cache file to read. |
239 } |
187 } |
240 CleanupClosePushL( cacheFile ); |
188 CleanupClosePushL(cacheFile); |
241 |
189 |
242 // Now read the cache |
190 // Now read the cache |
243 RFileReadStream cacheReadStream( cacheFile ); |
191 RFileReadStream cacheReadStream(cacheFile); |
244 cacheReadStream.PushL(); |
192 cacheReadStream.PushL(); |
245 |
193 |
246 iPrevPkgUids.Reset(); |
194 iPrevPkgUids.Reset(); |
247 TInt32 count( cacheReadStream.ReadInt32L() ); |
195 TInt32 count(cacheReadStream.ReadInt32L()); |
248 |
196 |
249 for ( TInt i = 0; i < count; i++ ) |
197 for (TInt i = 0; i < count; i++) |
250 { |
198 { |
251 TUid packageId; |
199 TUid packageId; |
252 packageId.iUid = cacheReadStream.ReadInt32L(); |
200 packageId.iUid = cacheReadStream.ReadInt32L(); |
253 (void)iPrevPkgUids.InsertInSignedKeyOrder( packageId ); |
201 (void)iPrevPkgUids.InsertInSignedKeyOrder(packageId); |
254 } |
202 } |
255 |
203 |
256 CleanupStack::PopAndDestroy(&cacheReadStream); |
204 CleanupStack::PopAndDestroy(&cacheReadStream); |
257 CleanupStack::PopAndDestroy(&cacheFile); |
205 CleanupStack::PopAndDestroy(&cacheFile); |
258 } |
206 } |
259 |
207 |
260 // ----------------------------------------------------------------------- |
|
261 // CPreviouslyInstalledAppsCache::FlushToDiskL |
|
262 // ----------------------------------------------------------------------- |
|
263 // |
|
264 void CPreviouslyInstalledAppsCache::FlushToDiskL() |
208 void CPreviouslyInstalledAppsCache::FlushToDiskL() |
265 { |
209 { |
266 // Write to disk |
210 // Write to disk |
267 RFile cacheFile; |
211 RFile cacheFile; |
268 TInt err = cacheFile.Open(iFs, KPreInstalledApps, EFileStream|EFileWrite); |
212 TInt err = cacheFile.Open(iFs, KPreInstalledApps, EFileStream|EFileWrite); |