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>
|
|
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 caCmdClose[] = "close";
|
|
50 |
static const char caAttrWindowGroupId[] = "window_group_id";
|
|
51 |
static const char caAttrComponentId[] = "component_id";
|
|
52 |
static const char caCmdRemove[] = "remove";
|
88
|
53 |
|
|
54 |
// ---------------------------------------------------------
|
96
|
55 |
//
|
88
|
56 |
// ---------------------------------------------------------
|
|
57 |
//
|
96
|
58 |
CaAppHandler::CaAppHandler(QObject *parent):
|
|
59 |
iEikEnv(CEikonEnv::Static()),
|
|
60 |
iUsifUninstallOperation(NULL)
|
88
|
61 |
{
|
96
|
62 |
Q_UNUSED(parent);
|
88
|
63 |
}
|
|
64 |
|
|
65 |
// ---------------------------------------------------------------------------
|
|
66 |
//
|
|
67 |
// ---------------------------------------------------------------------------
|
|
68 |
//
|
96
|
69 |
CaAppHandler::~CaAppHandler()
|
|
70 |
{
|
|
71 |
delete iUsifUninstallOperation;
|
|
72 |
}
|
|
73 |
|
|
74 |
int CaAppHandler::execute(const CaEntry &entry, const QString &command)
|
88
|
75 |
{
|
96
|
76 |
int result(KErrGeneral);
|
|
77 |
if (command == caCmdOpen && entry.entryTypeName() == caTypeApp) {
|
|
78 |
QString viewIdValue = entry.attribute(caAttrView);
|
|
79 |
bool viewIdIsCorrect(true);
|
|
80 |
int viewId(-1);
|
|
81 |
if (!viewIdValue.isNull()) {
|
|
82 |
viewId = viewIdValue.toInt(&viewIdIsCorrect, 0);
|
|
83 |
}
|
|
84 |
if (viewIdIsCorrect) {
|
|
85 |
QString uidValue =
|
|
86 |
entry.attribute(APPLICATION_UID_ATTRIBUTE_NAME);
|
|
87 |
int uid = uidValue.toInt();
|
|
88 |
TRAP(result, launchApplicationL(TUid::Uid(uid), viewId));
|
|
89 |
}
|
|
90 |
} else if (command == caCmdClose && entry.entryTypeName() == caTypeApp ) {
|
|
91 |
QString windowGroupId = entry.attribute(caAttrWindowGroupId);
|
|
92 |
if (!windowGroupId.isNull()) {
|
|
93 |
result = closeApplication(entry.flags(), windowGroupId.toInt());
|
|
94 |
}
|
|
95 |
} else if (command == caCmdRemove) {
|
|
96 |
QString componentId(entry.attribute(caAttrComponentId));
|
|
97 |
result = handleRemove(entry.flags(),
|
|
98 |
entry.entryTypeName(),
|
|
99 |
componentId);
|
|
100 |
} else {
|
|
101 |
result = KErrNotSupported;
|
|
102 |
}
|
|
103 |
|
|
104 |
return result;
|
88
|
105 |
}
|
|
106 |
|
89
|
107 |
// ---------------------------------------------------------------------------
|
|
108 |
//
|
|
109 |
// ---------------------------------------------------------------------------
|
|
110 |
//
|
96
|
111 |
void CaAppHandler::launchApplicationL(const TUid aUid, TInt aViewId)
|
88
|
112 |
{
|
89
|
113 |
if( aViewId > 0 && iEikEnv )
|
|
114 |
{
|
|
115 |
TUid viewId = TUid::Uid( aViewId );
|
|
116 |
TVwsViewId view( aUid, viewId );
|
|
117 |
iEikEnv->EikAppUi()->ActivateViewL( view );
|
88
|
118 |
}
|
89
|
119 |
else
|
|
120 |
{
|
|
121 |
RWsSession wsSession;
|
|
122 |
User::LeaveIfError( wsSession.Connect() );
|
|
123 |
CleanupClosePushL<RWsSession>( wsSession );
|
|
124 |
|
|
125 |
CCaTaskList* taskList = CCaTaskList::NewLC( wsSession );
|
|
126 |
TApaTask task = taskList->FindRootApp( aUid );
|
|
127 |
CleanupStack::PopAndDestroy( taskList );
|
|
128 |
|
|
129 |
if( task.Exists() )
|
|
130 |
{
|
|
131 |
task.BringToForeground();
|
|
132 |
}
|
|
133 |
else
|
|
134 |
{
|
92
|
135 |
// TApaAppInfo size is greater then 1024 bytes
|
|
136 |
// so its instances should not be created on the stack.
|
|
137 |
TApaAppInfo* appInfo = new( ELeave ) TApaAppInfo;
|
|
138 |
CleanupStack::PushL( appInfo );
|
89
|
139 |
TApaAppCapabilityBuf capabilityBuf;
|
|
140 |
RApaLsSession appArcSession;
|
|
141 |
User::LeaveIfError( appArcSession.Connect() );
|
|
142 |
CleanupClosePushL<RApaLsSession>( appArcSession );
|
|
143 |
|
92
|
144 |
User::LeaveIfError( appArcSession.GetAppInfo( *appInfo, aUid ) );
|
89
|
145 |
User::LeaveIfError( appArcSession.GetAppCapability(
|
|
146 |
capabilityBuf, aUid ) );
|
|
147 |
|
|
148 |
TApaAppCapability &caps = capabilityBuf();
|
|
149 |
CApaCommandLine *cmdLine = CApaCommandLine::NewLC();
|
92
|
150 |
cmdLine->SetExecutableNameL( appInfo->iFullName );
|
89
|
151 |
|
|
152 |
if( caps.iLaunchInBackground )
|
|
153 |
{
|
|
154 |
cmdLine->SetCommandL( EApaCommandBackground );
|
|
155 |
}
|
|
156 |
else
|
|
157 |
{
|
|
158 |
cmdLine->SetCommandL( EApaCommandRun );
|
|
159 |
}
|
|
160 |
|
96
|
161 |
cmdLine->SetTailEndL( KNullDesC8 );
|
89
|
162 |
|
|
163 |
User::LeaveIfError( appArcSession.StartApp( *cmdLine ) );
|
|
164 |
|
|
165 |
CleanupStack::PopAndDestroy( cmdLine );
|
|
166 |
CleanupStack::PopAndDestroy( &appArcSession );
|
92
|
167 |
CleanupStack::PopAndDestroy( appInfo );
|
88
|
168 |
}
|
89
|
169 |
CleanupStack::PopAndDestroy( &wsSession );
|
88
|
170 |
}
|
|
171 |
}
|
|
172 |
|
|
173 |
// ---------------------------------------------------------------------------
|
|
174 |
//
|
|
175 |
// ---------------------------------------------------------------------------
|
|
176 |
//
|
96
|
177 |
int CaAppHandler::closeApplication(const EntryFlags &flags, int windowGroupId)
|
88
|
178 |
{
|
96
|
179 |
int result(KErrNone);
|
|
180 |
if (flags.testFlag(RunningEntryFlag)
|
|
181 |
&& !( flags.testFlag(SystemEntryFlag))
|
|
182 |
&& windowGroupId > 0) {
|
|
183 |
RWsSession wsSession;
|
|
184 |
result = wsSession.Connect();
|
|
185 |
if (result==KErrNone) {
|
|
186 |
TWsEvent event;
|
|
187 |
event.SetTimeNow();
|
|
188 |
event.SetType( KAknShutOrHideApp );
|
|
189 |
wsSession.SendEventToWindowGroup( windowGroupId, event );
|
|
190 |
}
|
|
191 |
wsSession.Close();
|
89
|
192 |
}
|
96
|
193 |
return result;
|
88
|
194 |
}
|
|
195 |
|
92
|
196 |
// ---------------------------------------------------------------------------
|
|
197 |
//
|
|
198 |
// ---------------------------------------------------------------------------
|
|
199 |
//
|
96
|
200 |
int CaAppHandler::handleRemove(const EntryFlags &flags,
|
|
201 |
const QString &typeName,
|
|
202 |
const QString &componentId)
|
|
203 |
{
|
|
204 |
int result(KErrNone);
|
|
205 |
if (flags.testFlag(RemovableEntryFlag)) {
|
|
206 |
if (typeName == caTypeApp
|
|
207 |
|| typeName == caTypePackage
|
|
208 |
|| typeName == caTypeWidget) {
|
|
209 |
if(componentId.isNull()) {
|
|
210 |
result = KErrNotFound;
|
|
211 |
} else {
|
|
212 |
bool convertStatus(false);
|
|
213 |
int id = componentId.toInt(&convertStatus);
|
|
214 |
if (convertStatus) {
|
|
215 |
TRAP(result, startUsifUninstallL(id));
|
|
216 |
} else {
|
|
217 |
result = KErrGeneral;
|
|
218 |
}
|
94
|
219 |
}
|
92
|
220 |
}
|
96
|
221 |
else {
|
|
222 |
result = KErrNotSupported;
|
92
|
223 |
}
|
96
|
224 |
} else {
|
|
225 |
result = KErrAccessDenied;
|
94
|
226 |
}
|
96
|
227 |
return result;
|
92
|
228 |
}
|
|
229 |
|
|
230 |
// ---------------------------------------------------------------------------
|
|
231 |
//
|
|
232 |
// ---------------------------------------------------------------------------
|
|
233 |
//
|
96
|
234 |
void CaAppHandler::startUsifUninstallL(TInt aComponentId)
|
92
|
235 |
{
|
96
|
236 |
if (iUsifUninstallOperation && iUsifUninstallOperation->IsActive()) {
|
92
|
237 |
User::Leave( KErrInUse );
|
96
|
238 |
}
|
92
|
239 |
delete iUsifUninstallOperation;
|
|
240 |
iUsifUninstallOperation = NULL;
|
96
|
241 |
iUsifUninstallOperation = CCaUsifUninstallOperation::NewL(aComponentId);
|
92
|
242 |
}
|
|
243 |
|