|
1 /* |
|
2 * Copyright (c) 2008-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 * This file implements a SIF Transport task for the SIF Server. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <e32base.h> |
|
21 #include <e32std.h> |
|
22 #include <usif/usiferror.h> |
|
23 #include <usif/sif/sifplugin.h> |
|
24 #include <usif/scr/scr.h> |
|
25 #include <apgcli.h> |
|
26 #include "sifservertask.h" |
|
27 #include "siftransportcommon.h" |
|
28 #include "usiflog.h" |
|
29 #include "sifutils.h" |
|
30 |
|
31 using namespace Usif; |
|
32 |
|
33 CSifServerTask* CSifServerTask::NewL(TransportTaskFactory::TTaskType aTaskType, TTransportTaskParams& aParams) |
|
34 { |
|
35 CSifServerTask* self = new (ELeave) CSifServerTask(aTaskType, aParams); |
|
36 CleanupStack::PushL(self); |
|
37 |
|
38 // Query AppArc about the (MIME) type of the package to be processed and instantiate an appropriate SIF plug-in |
|
39 self->SelectAndLoadPluginL(); |
|
40 |
|
41 CleanupStack::Pop(self); |
|
42 return self; |
|
43 } |
|
44 |
|
45 CSifServerTask::CSifServerTask(TransportTaskFactory::TTaskType aTaskType, TTransportTaskParams& aParams) |
|
46 : CSifTransportTask(aParams, EFalse), iTaskType(aTaskType) |
|
47 { |
|
48 } |
|
49 |
|
50 CSifServerTask::~CSifServerTask() |
|
51 { |
|
52 DEBUG_PRINTF2(_L8("CSifServerTask::~CSifServerTask() for aFunction = %d\n"),iTaskType); |
|
53 |
|
54 // Clean up the plugin |
|
55 delete iPlugin; |
|
56 iPlugin = NULL; |
|
57 REComSession::DestroyedImplementation(iEcomKey); |
|
58 REComSession::FinalClose(); |
|
59 } |
|
60 |
|
61 TBool CSifServerTask::ExecuteImplL() |
|
62 { |
|
63 DEBUG_PRINTF2(_L8("CSifServerTask::ExecuteImpl() for aRequest = %d\n"),iTaskType); |
|
64 |
|
65 // Plug-in does not exists and request is not for default uninstallation so leave. |
|
66 if (!iPlugin && iTaskType != TransportTaskFactory::EUninstall) |
|
67 User::Leave(KErrNotFound); |
|
68 |
|
69 // Hand over the software management request to the plug-in |
|
70 switch (iTaskType) |
|
71 { |
|
72 case TransportTaskFactory::EGetComponentInfo: |
|
73 { |
|
74 if (FileName()) |
|
75 { |
|
76 iPlugin->GetComponentInfo(*FileName(), *SecurityContext(), *ComponentInfo(), *RequestStatus()); |
|
77 } |
|
78 else |
|
79 { |
|
80 iPlugin->GetComponentInfo(*FileHandle(), *SecurityContext(), *ComponentInfo(), *RequestStatus()); |
|
81 } |
|
82 break; |
|
83 } |
|
84 |
|
85 case TransportTaskFactory::EInstall: |
|
86 { |
|
87 if (FileName()) |
|
88 { |
|
89 iPlugin->Install(*FileName(), *SecurityContext(), *CustomArguments(), *CustomResults(), *RequestStatus()); |
|
90 } |
|
91 else |
|
92 { |
|
93 iPlugin->Install(*FileHandle(), *SecurityContext(), *CustomArguments(), *CustomResults(), *RequestStatus()); |
|
94 } |
|
95 break; |
|
96 } |
|
97 |
|
98 case TransportTaskFactory::EUninstall: |
|
99 { |
|
100 if (!iPlugin) |
|
101 { |
|
102 // The default uninstaller is used when the Plugin is no longer present. |
|
103 UninstallL(ComponentId()); |
|
104 TRequestStatus* requestStatusPtr(RequestStatus()); |
|
105 User::RequestComplete(requestStatusPtr, KErrNone); |
|
106 } |
|
107 else |
|
108 { |
|
109 iPlugin->Uninstall(ComponentId(), *SecurityContext(), *CustomArguments(), *CustomResults(), *RequestStatus()); |
|
110 } |
|
111 break; |
|
112 } |
|
113 |
|
114 case TransportTaskFactory::EActivate: |
|
115 { |
|
116 iPlugin->Activate(ComponentId(), *SecurityContext(), *RequestStatus()); |
|
117 break; |
|
118 } |
|
119 |
|
120 case TransportTaskFactory::EDeactivate: |
|
121 { |
|
122 iPlugin->Deactivate(ComponentId(), *SecurityContext(), *RequestStatus()); |
|
123 break; |
|
124 } |
|
125 |
|
126 default: |
|
127 ASSERT(0); |
|
128 } |
|
129 return ETrue; |
|
130 } |
|
131 |
|
132 void CSifServerTask::CancelImpl() |
|
133 { |
|
134 DEBUG_PRINTF2(_L8("CSifServerTask::Cancel for aTaskType = %d\n"), iTaskType); |
|
135 ASSERT(iPlugin); |
|
136 iPlugin->CancelOperation(); |
|
137 } |
|
138 |
|
139 void CSifServerTask::SelectAndLoadPluginL() |
|
140 { |
|
141 DEBUG_PRINTF2(_L8("CSifServerTask::SelectAndLoadPluginL() for aFunction = %d\n"),iTaskType); |
|
142 |
|
143 // The code below assumes that each SIF request provides a component id xor a file handle xor a file name. |
|
144 // In case of changes that invalidate this assumption the code must be modified. |
|
145 |
|
146 TDataType dataType; |
|
147 if (iTaskType == TransportTaskFactory::EGetComponentInfo || iTaskType == TransportTaskFactory::EInstall) |
|
148 { |
|
149 // Get the MIME type of the component to be installed from AppArc |
|
150 DEBUG_PRINTF(_L8("Getting the MIME type of the component to be installed from AppArc\n")); |
|
151 RApaLsSession apa; |
|
152 TInt err = apa.Connect(); |
|
153 if (err != KErrNone) |
|
154 { |
|
155 DEBUG_PRINTF2(_L8("Failed to connect to the AppArc server, err = %d\n"),err); |
|
156 User::Leave(err); |
|
157 } |
|
158 CleanupClosePushL(apa); |
|
159 TUid appUid = TUid::Null(); |
|
160 if (FileName()) |
|
161 { |
|
162 err = apa.AppForDocument(*FileName(), appUid, dataType); |
|
163 } |
|
164 else |
|
165 { |
|
166 err = apa.AppForDocument(*FileHandle(), appUid, dataType); |
|
167 } |
|
168 // A possible problem with recognizers is returning a successful result, but forgetting to set the MIME type. The second condition below protects against that. |
|
169 if (err != KErrNone || dataType.Des8().Ptr() == NULL) |
|
170 { |
|
171 DEBUG_PRINTF2(_L8("Failed to obtain the MIME type of a component, err = %d\n"),err); |
|
172 User::Leave(err); |
|
173 } |
|
174 CleanupStack::PopAndDestroy(&apa); |
|
175 } |
|
176 |
|
177 // Get the uid of the matching plug-in from SCR for ... |
|
178 RSoftwareComponentRegistry scr; |
|
179 TInt err = scr.Connect(); |
|
180 if (err != KErrNone) |
|
181 { |
|
182 DEBUG_PRINTF2(_L8("Failed to connect to the SCR, err = %d\n"),err); |
|
183 User::Leave(err); |
|
184 } |
|
185 CleanupClosePushL(scr); |
|
186 |
|
187 //... iComponentId or the MIME type obtained above |
|
188 TUid pluginUid = TUid::Null(); |
|
189 if (iTaskType != TransportTaskFactory::EInstall && iTaskType != TransportTaskFactory::EGetComponentInfo) |
|
190 { |
|
191 // Verify the given component id |
|
192 CComponentEntry* entry = CComponentEntry::NewLC(); |
|
193 if (!scr.GetComponentL(ComponentId(), *entry)) |
|
194 { |
|
195 DEBUG_PRINTF2(_L8("ComponentId = %d not found in the SCR"), ComponentId()); |
|
196 User::Leave(KErrSifBadComponentId); |
|
197 } |
|
198 CleanupStack::PopAndDestroy(entry); |
|
199 |
|
200 // Get the PluginUid only when an Installer Plugin is present. |
|
201 if (!scr.IsComponentOrphanedL(ComponentId())) |
|
202 { |
|
203 pluginUid = scr.GetPluginUidL(ComponentId()); |
|
204 } |
|
205 } |
|
206 else |
|
207 { |
|
208 pluginUid = scr.GetPluginUidL(dataType.Des()); |
|
209 } |
|
210 CleanupStack::PopAndDestroy(&scr); |
|
211 |
|
212 // Load the plug-in |
|
213 if( pluginUid != TUid::Null() ) |
|
214 { |
|
215 iPlugin = reinterpret_cast<CSifPlugin*>(REComSession::CreateImplementationL(pluginUid, iEcomKey)); |
|
216 } |
|
217 } |