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