|
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 the License "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 |
|
19 #include <s32mem.h> |
|
20 #include <caf/caf.h> |
|
21 #include <bautils.h> |
|
22 #include "sishelperclient.h" |
|
23 #include "log.h" |
|
24 |
|
25 using namespace Swi; |
|
26 |
|
27 // |
|
28 // RSisHelper |
|
29 // |
|
30 |
|
31 EXPORT_C TInt RSisHelper::Connect() |
|
32 { |
|
33 return CreateSession(KSisHelperServerName, |
|
34 TVersion(KSisHelperVersionMajor, |
|
35 KSisHelperVersionMinor, |
|
36 KSisHelperVersionBuild)); |
|
37 } |
|
38 |
|
39 EXPORT_C void RSisHelper::Close() |
|
40 { |
|
41 RSessionBase::Close(); |
|
42 } |
|
43 |
|
44 // Request SISController data from SISHelper |
|
45 EXPORT_C HBufC8* RSisHelper::SisControllerLC() |
|
46 { |
|
47 // Allocate a buffer |
|
48 const TInt KDefaultControllerBuffer=1024; // 1KB |
|
49 HBufC8* controllerData=HBufC8::NewMaxLC(KDefaultControllerBuffer); |
|
50 TPtr8 des=controllerData->Des(); |
|
51 |
|
52 TInt err=SendReceive(ESisHelperGetController, TIpcArgs(&des)); |
|
53 if (err == KErrOverflow) |
|
54 { |
|
55 // is there enough space for an integer? |
|
56 if(des.Length() != sizeof(TInt)) |
|
57 { |
|
58 User::Leave(KErrCorrupt); |
|
59 } |
|
60 |
|
61 // Get needed size |
|
62 TInt neededSize=0; |
|
63 TPckg<TInt> neededSizePackage(neededSize); |
|
64 neededSizePackage.Copy(des); |
|
65 |
|
66 // Re-allocate buffer |
|
67 CleanupStack::PopAndDestroy(controllerData); |
|
68 controllerData=HBufC8::NewMaxLC(neededSize); |
|
69 TPtr8 neededDes=controllerData->Des(); |
|
70 |
|
71 // Rerequest |
|
72 err=SendReceive(ESisHelperGetController, TIpcArgs(&neededDes)); |
|
73 } |
|
74 |
|
75 User::LeaveIfError(err); |
|
76 return controllerData; |
|
77 } |
|
78 |
|
79 EXPORT_C TInt RSisHelper::ExtractFileL(RFs& /*aFs*/, RFile& aFile, TInt aFileIndex, |
|
80 TInt aDataUnit, RUiHandler& /*aUiHandler*/) |
|
81 { |
|
82 TIpcArgs args; |
|
83 aFile.TransferToServer(args, 0, 1); |
|
84 args.Set(2, aFileIndex); |
|
85 args.Set(3, aDataUnit); |
|
86 return SendReceive(ESisHelperExtractFile, args); |
|
87 } |
|
88 |
|
89 void RSisHelper::SetupAsyncExtractionL(RFs& aFs, RFile& aFile, TInt aFileIndex,TInt aDataUnit) |
|
90 { |
|
91 User::LeaveIfError(SendReceive(ESisHelperSetupAsyncExtraction, TIpcArgs(aFs, aFile.SubSessionHandle(), aFileIndex, aDataUnit))); |
|
92 } |
|
93 |
|
94 void RSisHelper::AsyncExtractionL(TInt64 length, TRequestStatus& aStatus) |
|
95 { |
|
96 SendReceive(ESisHelperAsyncExtraction, TIpcArgs(I64HIGH(length), I64LOW(length)), aStatus); |
|
97 } |
|
98 |
|
99 void RSisHelper::EndAsyncExtractionL() |
|
100 { |
|
101 User::LeaveIfError(SendReceive(ESisHelperEndAsyncExtraction, TIpcArgs())); |
|
102 } |
|
103 |
|
104 EXPORT_C void RSisHelper::FillDrivesAndSpacesL(RArray<TChar>& aDriveLetters, |
|
105 RArray<TInt64>& aDriveSpaces) |
|
106 { |
|
107 // calculate the likely size of the data transfer buffer |
|
108 const TInt KMaxBufSize= |
|
109 sizeof(TInt)+ // number of entries |
|
110 KMaxDrives*sizeof(TUint)+ // drive letters stored as TUints |
|
111 KMaxDrives*sizeof(TInt64); // drive free spaces |
|
112 |
|
113 // allocate buffer for the returned arrays |
|
114 HBufC8* buf=HBufC8::NewMaxLC(KMaxBufSize); |
|
115 TPtr8 pBuf=buf->Des(); |
|
116 User::LeaveIfError(SendReceive(ESisHelperFillDrivesAndSpaces, |
|
117 TIpcArgs(&pBuf))); |
|
118 |
|
119 // got the buffer, internalise the arrays |
|
120 RDesReadStream ins(*buf); |
|
121 CleanupClosePushL(ins); |
|
122 |
|
123 // first comes the number of entries (TInt) |
|
124 TInt count=ins.ReadInt32L(); |
|
125 |
|
126 // then drive letters |
|
127 TInt i; |
|
128 for (i = 0; i < count; ++i) |
|
129 { |
|
130 TUint chVal=ins.ReadUint32L(); |
|
131 TChar ch(chVal); |
|
132 aDriveLetters.AppendL(ch); |
|
133 } |
|
134 |
|
135 // then drive spaces |
|
136 for (i = 0; i < count; ++i) |
|
137 { |
|
138 TInt32 l=ins.ReadInt32L(); |
|
139 TInt32 h=ins.ReadInt32L(); |
|
140 TInt64 space=MAKE_TINT64(h, l); |
|
141 aDriveSpaces.AppendL(space); |
|
142 } |
|
143 |
|
144 // cleanup |
|
145 CleanupStack::PopAndDestroy(2, buf); // ins, buf |
|
146 } |
|
147 |
|
148 EXPORT_C void RSisHelper::OpenDrmContentL(ContentAccess::TIntent aIntent) |
|
149 { |
|
150 TInt intent = static_cast<TInt>(aIntent); |
|
151 User::LeaveIfError(SendReceive(ESisHelperOpenDrmContent, TIpcArgs(intent))); |
|
152 } |
|
153 |
|
154 EXPORT_C void RSisHelper::ExecuteDrmIntentL(ContentAccess::TIntent aIntent) |
|
155 { |
|
156 TInt intent = static_cast<TInt>(aIntent); |
|
157 User::LeaveIfError(SendReceive(ESisHelperExecuteDrmIntent, TIpcArgs(intent))); |
|
158 } |
|
159 |
|
160 TInt RSisHelper::CreateSisStub(RFile& aFile) |
|
161 { |
|
162 TIpcArgs ipcArgs; |
|
163 aFile.TransferToServer(ipcArgs, 0, 1); |
|
164 return SendReceive(ESisHelperCreateSisStub, ipcArgs); |
|
165 } |
|
166 |
|
167 TBool RSisHelper::IsStubL() |
|
168 { |
|
169 TBool stub = EFalse; |
|
170 TPckg<TBool> stubPckg(stub); |
|
171 User::LeaveIfError(SendReceive(ESisHelperIsStub, TIpcArgs(&stubPckg))); |
|
172 return stub; |
|
173 } |
|
174 |
|
175 TChar RSisHelper::GetSisFileDriveL() |
|
176 { |
|
177 TChar drive(0); |
|
178 TPckg<TChar> drivePckg(drive); |
|
179 User::LeaveIfError(SendReceive(ESisHelperGetSisFileDrive, TIpcArgs(&drivePckg))); |
|
180 return drive; |
|
181 } |
|
182 |
|
183 TBool RSisHelper::IsSisFileReadOnlyL() |
|
184 { |
|
185 TBool readOnly = EFalse; |
|
186 TPckg<TBool> readOnlyPckg(readOnly); |
|
187 User::LeaveIfError(SendReceive(ESisHelperIsSisFileReadOnly, TIpcArgs(&readOnlyPckg))); |
|
188 return readOnly; |
|
189 } |
|
190 |
|
191 // Request SIS file name from SISHelper |
|
192 void RSisHelper::GetSisFileNameL(TDes& aFileName) |
|
193 { |
|
194 TInt err = SendReceive(ESisHelperGetSisFileName, TIpcArgs(&aFileName)); |
|
195 User::LeaveIfError(err); |
|
196 } |
|
197 |
|
198 // Retrieve Controller from the specified SIS file |
|
199 EXPORT_C HBufC8* RSisHelper::GetControllerFromSisFileLC(const TDesC& aFileName) |
|
200 { |
|
201 // Open the file and pass the handle securely to SisHelper since |
|
202 // it does not have the capability to read files from private folders |
|
203 // of other processes |
|
204 RFs fs; |
|
205 User::LeaveIfError(fs.Connect()); |
|
206 CleanupClosePushL(fs); |
|
207 User::LeaveIfError(fs.ShareProtected()); |
|
208 RFile file; |
|
209 User::LeaveIfError(file.Open(fs, aFileName, EFileRead | EFileShareReadersOnly)); |
|
210 CleanupClosePushL(file); |
|
211 |
|
212 // Allocate a buffer |
|
213 const TInt KDefaultControllerBuffer = 1024; // 1KB |
|
214 HBufC8* controllerData = HBufC8::NewMaxLC(KDefaultControllerBuffer); |
|
215 TPtr8 ptr(controllerData->Des()); |
|
216 |
|
217 // Store the RFs handle in message slot 1 and the RFile handle in slot 2 |
|
218 TIpcArgs ipcArgs; |
|
219 User::LeaveIfError(file.TransferToServer(ipcArgs, 1, 2)); |
|
220 |
|
221 ipcArgs.Set(0, &ptr); |
|
222 TInt err = SendReceive(ESisHelperGetControllerFromSis, ipcArgs); |
|
223 if (err == KErrOverflow) |
|
224 { |
|
225 // is there enough space for an integer? |
|
226 if(ptr.Length() != sizeof(TInt)) |
|
227 { |
|
228 User::Leave(KErrCorrupt); |
|
229 } |
|
230 |
|
231 // Get needed size |
|
232 TInt neededSize = 0; |
|
233 TPckg<TInt> neededSizePackage(neededSize); |
|
234 neededSizePackage.Copy(ptr); |
|
235 |
|
236 // Re-allocate buffer |
|
237 CleanupStack::PopAndDestroy(controllerData); |
|
238 controllerData = HBufC8::NewMaxLC(neededSize); |
|
239 TPtr8 neededPtr(controllerData->Des()); |
|
240 |
|
241 // Rerequest |
|
242 User::LeaveIfError(file.TransferToServer(ipcArgs, 1, 2)); |
|
243 ipcArgs.Set(0, &neededPtr); |
|
244 err = SendReceive(ESisHelperGetControllerFromSis, ipcArgs); |
|
245 } |
|
246 |
|
247 User::LeaveIfError(err); |
|
248 |
|
249 CleanupStack::Pop(controllerData); |
|
250 CleanupStack::PopAndDestroy(2, &fs); |
|
251 CleanupStack::PushL(controllerData); |
|
252 return controllerData; |
|
253 } |
|
254 |
|
255 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK |
|
256 TBool RSisHelper::IsDrmProtectedL() |
|
257 { |
|
258 TPckgBuf<TBool> isContentProtected; |
|
259 TInt returnCode = SendReceive(ESisHelperIsDrmProtected, TIpcArgs(&isContentProtected)); |
|
260 User::LeaveIfError(returnCode); |
|
261 |
|
262 return isContentProtected(); |
|
263 } |
|
264 #endif |
|
265 void RSisHelper::GetEquivalentLanguageListL(TLanguage aLangId,RArray<TLanguage>& aEquivLangs) |
|
266 { |
|
267 // calculate the likely size of the data transfer buffer |
|
268 const TInt KMaxBufSize= |
|
269 sizeof(TInt)+ // number of entries |
|
270 (KMaxDowngradeLanguages+1)*sizeof(TLanguage); // Languages IDs stored as TLanguage |
|
271 |
|
272 // allocate buffer for the returned arrays |
|
273 HBufC8* buf=HBufC8::NewMaxLC(KMaxBufSize); |
|
274 TPtr8 pBuf=buf->Des(); |
|
275 User::LeaveIfError(SendReceive(ESisHelperGetEquivalentLanguages, |
|
276 TIpcArgs(&pBuf,aLangId))); |
|
277 |
|
278 // got the buffer, internalise the arrays |
|
279 RDesReadStream ins(*buf); |
|
280 CleanupClosePushL(ins); |
|
281 |
|
282 // first comes the number of entries (TInt) |
|
283 TInt count=ins.ReadInt32L(); |
|
284 |
|
285 // then language ID's |
|
286 TInt i; |
|
287 for (i = 0; i < count; ++i) |
|
288 { |
|
289 TLanguage langId=(TLanguage)ins.ReadInt32L(); |
|
290 aEquivLangs.AppendL(langId); |
|
291 } |
|
292 // cleanup |
|
293 CleanupStack::PopAndDestroy(2, buf); // buf |
|
294 } |