88
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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 "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: ?Description
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
96
|
18 |
#include <QString>
|
|
19 |
#include <e32base.h>
|
88
|
20 |
#include <w32std.h>
|
|
21 |
#include <apgtask.h>
|
|
22 |
#include <apgcli.h>
|
|
23 |
#include <eikenv.h>
|
|
24 |
#include <eikappui.h>
|
|
25 |
#include <vwsdef.h>
|
|
26 |
#include <AknDef.h>
|
|
27 |
#include <AknTaskList.h>
|
|
28 |
|
92
|
29 |
#include <usif/usifcommon.h>
|
|
30 |
#include <usif/scr/scr.h>
|
116
|
31 |
#include <usif/usiferror.h>
|
92
|
32 |
|
96
|
33 |
#include <cadefs.h>
|
|
34 |
#include <caentry.h>
|
|
35 |
|
88
|
36 |
#include "caapphandler.h"
|
|
37 |
#include "cainnerentry.h"
|
92
|
38 |
#include "causifuninstalloperation.h"
|
|
39 |
#include "catasklist.h"
|
88
|
40 |
#include "cautils.h"
|
96
|
41 |
#include "caclient_defines.h"
|
88
|
42 |
#include "cadef.h"
|
|
43 |
|
92
|
44 |
using namespace Usif;
|
88
|
45 |
|
96
|
46 |
static const char caTypeApp[] = "application";
|
|
47 |
static const char caTypePackage[] = "package";
|
|
48 |
static const char caTypeWidget[] = "widget";
|
|
49 |
static const char caAttrView[] = "view";
|
|
50 |
static const char caCmdClose[] = "close";
|
|
51 |
static const char caAttrWindowGroupId[] = "window_group_id";
|
|
52 |
static const char caAttrComponentId[] = "component_id";
|
88
|
53 |
|
98
|
54 |
/*!
|
|
55 |
* Command handler for application entries.
|
|
56 |
*
|
|
57 |
* \lib caclient.lib
|
|
58 |
*/
|
|
59 |
|
|
60 |
/*!
|
|
61 |
* Constructor.
|
|
62 |
*/
|
96
|
63 |
CaAppHandler::CaAppHandler(QObject *parent):
|
|
64 |
iEikEnv(CEikonEnv::Static()),
|
|
65 |
iUsifUninstallOperation(NULL)
|
88
|
66 |
{
|
96
|
67 |
Q_UNUSED(parent);
|
88
|
68 |
}
|
|
69 |
|
98
|
70 |
/*!
|
|
71 |
* Destructor.
|
|
72 |
*/
|
96
|
73 |
CaAppHandler::~CaAppHandler()
|
|
74 |
{
|
|
75 |
delete iUsifUninstallOperation;
|
|
76 |
}
|
|
77 |
|
98
|
78 |
/*!
|
|
79 |
* Execute a given command.
|
|
80 |
* \param entry a reference to a CaEntry instance.
|
|
81 |
* \param command a given command.
|
116
|
82 |
* \param receiver a QObject class with slot to invoke.
|
|
83 |
* \param member a slot to invoke.
|
98
|
84 |
* \retval an error code.
|
|
85 |
*/
|
116
|
86 |
int CaAppHandler::execute(const CaEntry &entry, const QString &command,
|
|
87 |
QObject* receiver, const char* member)
|
88
|
88 |
{
|
116
|
89 |
if ( receiver && member ) {
|
|
90 |
connect( this, SIGNAL(uninstallFailed(int)), receiver, member, Qt::UniqueConnection );
|
|
91 |
}
|
|
92 |
|
96
|
93 |
int result(KErrGeneral);
|
|
94 |
if (command == caCmdOpen && entry.entryTypeName() == caTypeApp) {
|
|
95 |
QString viewIdValue = entry.attribute(caAttrView);
|
|
96 |
bool viewIdIsCorrect(true);
|
|
97 |
int viewId(-1);
|
|
98 |
if (!viewIdValue.isNull()) {
|
|
99 |
viewId = viewIdValue.toInt(&viewIdIsCorrect, 0);
|
|
100 |
}
|
|
101 |
if (viewIdIsCorrect) {
|
|
102 |
QString uidValue =
|
|
103 |
entry.attribute(APPLICATION_UID_ATTRIBUTE_NAME);
|
|
104 |
int uid = uidValue.toInt();
|
|
105 |
TRAP(result, launchApplicationL(TUid::Uid(uid), viewId));
|
|
106 |
}
|
|
107 |
} else if (command == caCmdClose && entry.entryTypeName() == caTypeApp ) {
|
|
108 |
QString windowGroupId = entry.attribute(caAttrWindowGroupId);
|
|
109 |
if (!windowGroupId.isNull()) {
|
|
110 |
result = closeApplication(entry.flags(), windowGroupId.toInt());
|
|
111 |
}
|
|
112 |
} else if (command == caCmdRemove) {
|
|
113 |
QString componentId(entry.attribute(caAttrComponentId));
|
|
114 |
result = handleRemove(entry.flags(),
|
|
115 |
entry.entryTypeName(),
|
|
116 |
componentId);
|
|
117 |
} else {
|
|
118 |
result = KErrNotSupported;
|
|
119 |
}
|
|
120 |
|
|
121 |
return result;
|
88
|
122 |
}
|
|
123 |
|
98
|
124 |
/*!
|
|
125 |
* Launch application
|
|
126 |
* \param uid UID of the application to launch.
|
|
127 |
* \param viewId id of the view the application is to start in.
|
|
128 |
*/
|
|
129 |
void CaAppHandler::launchApplicationL(const TUid uid, TInt viewId)
|
88
|
130 |
{
|
98
|
131 |
if (viewId > 0 && iEikEnv) {
|
|
132 |
TVwsViewId view(uid, TUid::Uid(viewId));
|
89
|
133 |
iEikEnv->EikAppUi()->ActivateViewL( view );
|
98
|
134 |
} else {
|
89
|
135 |
RWsSession wsSession;
|
98
|
136 |
User::LeaveIfError(wsSession.Connect());
|
|
137 |
CleanupClosePushL<RWsSession>(wsSession);
|
89
|
138 |
|
98
|
139 |
CCaTaskList* taskList = CCaTaskList::NewLC(wsSession);
|
|
140 |
TApaTask task = taskList->FindRootApp(uid);
|
|
141 |
CleanupStack::PopAndDestroy(taskList);
|
89
|
142 |
|
98
|
143 |
if (task.Exists()) {
|
89
|
144 |
task.BringToForeground();
|
98
|
145 |
} else {
|
92
|
146 |
// TApaAppInfo size is greater then 1024 bytes
|
|
147 |
// so its instances should not be created on the stack.
|
98
|
148 |
TApaAppInfo* appInfo = new(ELeave) TApaAppInfo;
|
|
149 |
CleanupStack::PushL(appInfo);
|
89
|
150 |
TApaAppCapabilityBuf capabilityBuf;
|
|
151 |
RApaLsSession appArcSession;
|
98
|
152 |
User::LeaveIfError(appArcSession.Connect());
|
|
153 |
CleanupClosePushL<RApaLsSession>(appArcSession);
|
89
|
154 |
|
98
|
155 |
User::LeaveIfError(appArcSession.GetAppInfo(*appInfo, uid));
|
|
156 |
User::LeaveIfError(appArcSession.GetAppCapability(
|
|
157 |
capabilityBuf, uid));
|
89
|
158 |
|
|
159 |
TApaAppCapability &caps = capabilityBuf();
|
|
160 |
CApaCommandLine *cmdLine = CApaCommandLine::NewLC();
|
98
|
161 |
cmdLine->SetExecutableNameL(appInfo->iFullName);
|
|
162 |
|
|
163 |
if (caps.iLaunchInBackground) {
|
|
164 |
cmdLine->SetCommandL(EApaCommandBackground);
|
|
165 |
} else {
|
|
166 |
cmdLine->SetCommandL(EApaCommandRun);
|
|
167 |
}
|
89
|
168 |
|
98
|
169 |
cmdLine->SetTailEndL(KNullDesC8);
|
|
170 |
|
|
171 |
User::LeaveIfError(appArcSession.StartApp(*cmdLine));
|
89
|
172 |
|
98
|
173 |
CleanupStack::PopAndDestroy(cmdLine);
|
|
174 |
CleanupStack::PopAndDestroy(&appArcSession);
|
|
175 |
CleanupStack::PopAndDestroy(appInfo);
|
88
|
176 |
}
|
89
|
177 |
CleanupStack::PopAndDestroy( &wsSession );
|
88
|
178 |
}
|
|
179 |
}
|
|
180 |
|
98
|
181 |
/*!
|
|
182 |
* Closes application.
|
|
183 |
* \param flags an entry flags.
|
|
184 |
* \param windowGroupId window group id.
|
|
185 |
* \retval an error code.
|
|
186 |
*/
|
96
|
187 |
int CaAppHandler::closeApplication(const EntryFlags &flags, int windowGroupId)
|
88
|
188 |
{
|
96
|
189 |
int result(KErrNone);
|
116
|
190 |
if (windowGroupId > 0) {
|
96
|
191 |
RWsSession wsSession;
|
|
192 |
result = wsSession.Connect();
|
|
193 |
if (result==KErrNone) {
|
|
194 |
TWsEvent event;
|
|
195 |
event.SetTimeNow();
|
98
|
196 |
event.SetType(KAknShutOrHideApp);
|
|
197 |
wsSession.SendEventToWindowGroup(windowGroupId, event);
|
96
|
198 |
}
|
|
199 |
wsSession.Close();
|
89
|
200 |
}
|
96
|
201 |
return result;
|
88
|
202 |
}
|
|
203 |
|
98
|
204 |
/*!
|
|
205 |
* Uninstall application.
|
|
206 |
* \param flags flags of the application which is to uninstall.
|
|
207 |
* \param typeName type name of the entry.
|
|
208 |
* \param componentId component id.
|
|
209 |
* \retval an error code.
|
|
210 |
*/
|
96
|
211 |
int CaAppHandler::handleRemove(const EntryFlags &flags,
|
|
212 |
const QString &typeName,
|
|
213 |
const QString &componentId)
|
|
214 |
{
|
|
215 |
int result(KErrNone);
|
|
216 |
if (flags.testFlag(RemovableEntryFlag)) {
|
|
217 |
if (typeName == caTypeApp
|
|
218 |
|| typeName == caTypePackage
|
|
219 |
|| typeName == caTypeWidget) {
|
|
220 |
if(componentId.isNull()) {
|
|
221 |
result = KErrNotFound;
|
|
222 |
} else {
|
|
223 |
bool convertStatus(false);
|
|
224 |
int id = componentId.toInt(&convertStatus);
|
|
225 |
if (convertStatus) {
|
|
226 |
TRAP(result, startUsifUninstallL(id));
|
|
227 |
} else {
|
|
228 |
result = KErrGeneral;
|
|
229 |
}
|
94
|
230 |
}
|
92
|
231 |
}
|
96
|
232 |
else {
|
|
233 |
result = KErrNotSupported;
|
92
|
234 |
}
|
96
|
235 |
} else {
|
|
236 |
result = KErrAccessDenied;
|
94
|
237 |
}
|
96
|
238 |
return result;
|
92
|
239 |
}
|
|
240 |
|
98
|
241 |
/*!
|
|
242 |
* Start uninstall operation via usif.
|
|
243 |
* \param componentId component id.
|
|
244 |
*/
|
|
245 |
void CaAppHandler::startUsifUninstallL(TInt componentId)
|
92
|
246 |
{
|
96
|
247 |
if (iUsifUninstallOperation && iUsifUninstallOperation->IsActive()) {
|
116
|
248 |
uninstallError(Usif::EInstallerBusy);
|
|
249 |
} else {
|
|
250 |
delete iUsifUninstallOperation;
|
|
251 |
iUsifUninstallOperation = NULL;
|
|
252 |
iUsifUninstallOperation = CCaUsifUninstallOperation::NewL(componentId);
|
|
253 |
iUsifUninstallOperation->AddObserver(this);
|
96
|
254 |
}
|
92
|
255 |
}
|
|
256 |
|
116
|
257 |
#ifdef COVERAGE_MEASUREMENT
|
|
258 |
#pragma CTC SKIP
|
|
259 |
#endif //COVERAGE_MEASUREMENT
|
|
260 |
/*!
|
|
261 |
* Show information message about unninstall error.
|
|
262 |
* \param error uninstall error.
|
|
263 |
* \retval void.
|
|
264 |
*/
|
|
265 |
void CaAppHandler::uninstallError(int error)
|
|
266 |
{
|
|
267 |
emit uninstallFailed(error);
|
|
268 |
}
|
|
269 |
#ifdef COVERAGE_MEASUREMENT
|
|
270 |
#pragma CTC ENDSKIP
|
|
271 |
#endif //COVERAGE_MEASUREMENT
|
|
272 |
|
|
273 |
|