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