|
1 /* |
|
2 * Copyright (c) 2007 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: CNcdSilentInstallActiveObserver |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdsilentinstallactiveobserver.h" |
|
20 #include "ncdasyncsilentinstallobserver.h" |
|
21 |
|
22 |
|
23 CNcdSilentInstallActiveObserver* CNcdSilentInstallActiveObserver::NewL( MNcdAsyncSilentInstallObserver& aObserver ) |
|
24 { |
|
25 CNcdSilentInstallActiveObserver* self = |
|
26 CNcdSilentInstallActiveObserver::NewLC( aObserver ); |
|
27 CleanupStack::Pop( self ); |
|
28 return self; |
|
29 } |
|
30 |
|
31 |
|
32 CNcdSilentInstallActiveObserver* CNcdSilentInstallActiveObserver::NewLC( MNcdAsyncSilentInstallObserver& aObserver ) |
|
33 { |
|
34 CNcdSilentInstallActiveObserver* self = |
|
35 new( ELeave ) CNcdSilentInstallActiveObserver( aObserver ); |
|
36 CleanupStack::PushL( self ); |
|
37 self->ConstructL(); |
|
38 return self; |
|
39 } |
|
40 |
|
41 |
|
42 CNcdSilentInstallActiveObserver::CNcdSilentInstallActiveObserver( MNcdAsyncSilentInstallObserver& aObserver ) |
|
43 : CActive( CActive::EPriorityStandard ), |
|
44 iObserver( aObserver ) |
|
45 { |
|
46 |
|
47 } |
|
48 |
|
49 |
|
50 void CNcdSilentInstallActiveObserver::ConstructL() |
|
51 { |
|
52 CActiveScheduler::Add( this ); |
|
53 } |
|
54 |
|
55 |
|
56 CNcdSilentInstallActiveObserver::~CNcdSilentInstallActiveObserver() |
|
57 { |
|
58 // It is always good and safe to do cancel in CActive objects. |
|
59 // If silent installation is going on, this operation will |
|
60 // cancel install operation and closes the silent installer. |
|
61 // If no operation is going on, the installer is already closed. |
|
62 // So, no need to close the silent launcher here separately. |
|
63 CancelAsyncOperation(); |
|
64 } |
|
65 |
|
66 |
|
67 void CNcdSilentInstallActiveObserver::DoCancel() |
|
68 { |
|
69 // Notice, that the active observer Cancel-function waits for the |
|
70 // silent launcher to send request complete before cancel of this |
|
71 // active object can finish. This is normal active object canel operation behaviour. |
|
72 // Notice, that we do not call the callback functions of the observer here |
|
73 // because we suppose that the observer has started the cancel operation itself |
|
74 // or the caller will inform the observer itself. |
|
75 SilentLauncher().CancelAsyncRequest( iCancelCode ); |
|
76 } |
|
77 |
|
78 |
|
79 void CNcdSilentInstallActiveObserver::StartToObserveL( const TDesC& aFileName, |
|
80 const SwiUI::TInstallOptionsPckg& aSilentInstallOptionsPckg ) |
|
81 { |
|
82 // For silent installation |
|
83 // Notice that if the user does not have TrustedUI capabilities |
|
84 // then this will given KErrPermissionDenied. |
|
85 // Connect to the launcher here just before it is needed, |
|
86 // because the launcher will be shown in the application list. |
|
87 // So, it would not be nice to connect in the ConstructL and to show |
|
88 // the icon in the list all the time. |
|
89 User::LeaveIfError( SilentLauncher().Connect() ); |
|
90 |
|
91 iCancelCode = SwiUI::ERequestSilentInstall; |
|
92 SilentLauncher().SilentInstall( iStatus, |
|
93 aFileName, |
|
94 aSilentInstallOptionsPckg ); |
|
95 |
|
96 SetActive(); |
|
97 } |
|
98 |
|
99 |
|
100 void CNcdSilentInstallActiveObserver::StartToObserveL( RFile& aFile, |
|
101 const SwiUI::TInstallOptionsPckg& aSilentInstallOptionsPckg ) |
|
102 { |
|
103 // For silent installation |
|
104 // Notice that if the user does not have TrustedUI capabilities |
|
105 // then this will given KErrPermissionDenied. |
|
106 // Connect to the launcher here just before it is needed, |
|
107 // because the launcher will be shown in the application list. |
|
108 // So, it would not be nice to connect in the ConstructL and to show |
|
109 // the icon in the list all the time. |
|
110 User::LeaveIfError( SilentLauncher().Connect() ); |
|
111 |
|
112 iCancelCode = SwiUI::ERequestSilentInstallHandle; |
|
113 SilentLauncher().SilentInstall( iStatus, |
|
114 aFile, |
|
115 aSilentInstallOptionsPckg ); |
|
116 |
|
117 SetActive(); |
|
118 } |
|
119 |
|
120 |
|
121 TInt CNcdSilentInstallActiveObserver::CancelAsyncOperation() |
|
122 { |
|
123 // Normal active object cancel. |
|
124 // This will wait for the request complete. |
|
125 // So, close the launcher after request has been gotten. |
|
126 Cancel(); |
|
127 |
|
128 // Release launcher, now that the launcher has cancelled its operation. |
|
129 SilentLauncher().Close(); |
|
130 |
|
131 TInt errorCode( ConvertErrorCode( iStatus.Int() ) ); |
|
132 |
|
133 return errorCode; |
|
134 } |
|
135 |
|
136 |
|
137 void CNcdSilentInstallActiveObserver::RunL() |
|
138 { |
|
139 // This is called when the silent installer has done its job. |
|
140 // Close the installer. |
|
141 // The launcher is shown in the application list. |
|
142 // So, it would not be nice to leave it there after operation is completed. |
|
143 SilentLauncher().Close(); |
|
144 |
|
145 TInt errorCode( ConvertErrorCode( iStatus.Int() ) ); |
|
146 |
|
147 // Just forward the information to the observer. |
|
148 AsyncObserver().AsyncSilentInstallComplete( errorCode ); |
|
149 } |
|
150 |
|
151 |
|
152 MNcdAsyncSilentInstallObserver& CNcdSilentInstallActiveObserver::AsyncObserver() const |
|
153 { |
|
154 return iObserver; |
|
155 } |
|
156 |
|
157 |
|
158 SwiUI::RSWInstSilentLauncher& CNcdSilentInstallActiveObserver::SilentLauncher() |
|
159 { |
|
160 return iSilentLauncher; |
|
161 } |
|
162 |
|
163 |
|
164 TInt CNcdSilentInstallActiveObserver::ConvertErrorCode( TInt aErrorCode ) |
|
165 { |
|
166 switch ( aErrorCode ) |
|
167 { |
|
168 case SwiUI::KSWInstErrUserCancel: |
|
169 // To simplify the cancel response and cancel handling, |
|
170 // convert the error code to normal cancel error code. |
|
171 aErrorCode = KErrCancel; |
|
172 break; |
|
173 |
|
174 case SwiUI::KSWInstErrInsufficientMemory: |
|
175 // To simplify the insufficient memory response and its handling, |
|
176 // convert the error code to normal no memory code. |
|
177 aErrorCode = KErrNoMemory; |
|
178 break; |
|
179 |
|
180 default: |
|
181 // Nothing to do here. |
|
182 break; |
|
183 } |
|
184 |
|
185 return aErrorCode; |
|
186 } |
|
187 |