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