1 /* |
|
2 * Copyright (c) 2005-2006 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: Plugin activity PS tool |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "aipluginactivitypstool.h" |
|
20 #include "aipropertyextension.h" |
|
21 #include <activeidle2domainpskeys.h> |
|
22 #include <e32std.h> // for User |
|
23 #include <e32property.h> // for RProperty |
|
24 #include <e32capability.h> |
|
25 |
|
26 // Unnamed namespace for local definitions |
|
27 namespace |
|
28 { |
|
29 |
|
30 const TInt KStartOrdinal( KAIActivePluginRangeStart ); |
|
31 |
|
32 // All reads are allowed. |
|
33 _LIT_SECURITY_POLICY_PASS( KPluginActivityRegistryReadPolicy ); |
|
34 |
|
35 // Write requires WriteDeviceData capability |
|
36 _LIT_SECURITY_POLICY_C1( KPluginActivityRegistryWritePolicy, ECapabilityWriteDeviceData ); |
|
37 |
|
38 } |
|
39 |
|
40 CAiPluginActivityRegistry::CAiPluginActivityRegistry() |
|
41 : iRegistryOrdinal( KStartOrdinal ) |
|
42 { |
|
43 } |
|
44 |
|
45 CAiPluginActivityRegistry* CAiPluginActivityRegistry::NewL() |
|
46 { |
|
47 CAiPluginActivityRegistry* self = |
|
48 new (ELeave) CAiPluginActivityRegistry(); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL(); |
|
51 CleanupStack::Pop( self ); |
|
52 return self; |
|
53 } |
|
54 |
|
55 void CAiPluginActivityRegistry::ConstructL() |
|
56 { |
|
57 } |
|
58 |
|
59 CAiPluginActivityRegistry::~CAiPluginActivityRegistry() |
|
60 { |
|
61 CleanRegistry(); |
|
62 } |
|
63 |
|
64 TInt CAiPluginActivityRegistry::SetPluginActive( const TAiPublisherInfo& aPubInfo ) |
|
65 { |
|
66 TInt psErr = KErrArgument; |
|
67 TInt uid = aPubInfo.iUid.iUid; |
|
68 |
|
69 // Make sure the keys are within their assigned ranges |
|
70 if( uid >= KAIPluginNameRangeStart && |
|
71 uid <= KAIPluginNameRangeEnd && |
|
72 iRegistryOrdinal >= KAIActivePluginRangeStart && |
|
73 iRegistryOrdinal <= KAIActivePluginRangeEnd ) |
|
74 { |
|
75 psErr = UpdateOrdinalRegister( uid ); |
|
76 |
|
77 ++iPluginCount; // now there is partial data in registry for next item |
|
78 // so update count allready here, so that |
|
79 // the data may be cleaned in case on error |
|
80 |
|
81 psErr |= UpdateNameRegister( uid, aPubInfo.iName ); |
|
82 |
|
83 psErr |= UpdateCountRegister(); |
|
84 |
|
85 if( psErr != KErrNone ) |
|
86 { |
|
87 CleanLastEntry( uid, |
|
88 iRegistryOrdinal, |
|
89 iPluginCount - 1 ); |
|
90 // Decrement only after rollback so failures may be cleaned properly |
|
91 // in case there is interrupting error situations |
|
92 --iPluginCount; |
|
93 return psErr; |
|
94 } |
|
95 |
|
96 ++iRegistryOrdinal; |
|
97 } |
|
98 |
|
99 return psErr; |
|
100 } |
|
101 |
|
102 void CAiPluginActivityRegistry::CleanRegistry() |
|
103 { |
|
104 // The count in p&s might not be updated before |
|
105 // we end up here that why we use iPluginCount for count. |
|
106 for( TInt i = 0; i < iPluginCount; ++i ) |
|
107 { |
|
108 TInt categoryKey = i + KStartOrdinal; |
|
109 TInt pluginUid = 0; |
|
110 TInt err = RProperty::Get( |
|
111 KPSUidActiveIdle2, |
|
112 categoryKey, |
|
113 pluginUid ); |
|
114 if( err == KErrNone ) |
|
115 { |
|
116 // Delete name |
|
117 RProperty::Delete( KPSUidActiveIdle2, pluginUid ); |
|
118 } |
|
119 // Delete ordinal |
|
120 RProperty::Delete( KPSUidActiveIdle2, categoryKey ); |
|
121 } |
|
122 // Delete count |
|
123 RProperty::Delete( KPSUidActiveIdle2, KAIActivePluginCount ); |
|
124 iRegistryOrdinal = KStartOrdinal; |
|
125 } |
|
126 |
|
127 TInt CAiPluginActivityRegistry::UpdateCountRegister() |
|
128 { |
|
129 TInt err = RProperty::Define( |
|
130 KPSUidActiveIdle2, |
|
131 KAIActivePluginCount, |
|
132 RProperty::EInt, |
|
133 KPluginActivityRegistryReadPolicy, |
|
134 KPluginActivityRegistryWritePolicy ); |
|
135 if( err == KErrAlreadyExists && |
|
136 iRegistryOrdinal == KStartOrdinal ) |
|
137 { |
|
138 // Some error has occured |
|
139 CleanRegistry(); |
|
140 err = RProperty::Define( |
|
141 KPSUidActiveIdle2, |
|
142 KAIActivePluginCount, |
|
143 RProperty::EInt, |
|
144 KPluginActivityRegistryReadPolicy, |
|
145 KPluginActivityRegistryWritePolicy ); |
|
146 } |
|
147 if( err != KErrAlreadyExists && |
|
148 err != KErrNone ) |
|
149 { |
|
150 return err; |
|
151 } |
|
152 |
|
153 // iRegistryOrdinal starts from 1, so it can be used as count, but only |
|
154 // before incrementation. |
|
155 err = RProperty::Set( |
|
156 KPSUidActiveIdle2, |
|
157 KAIActivePluginCount, |
|
158 iPluginCount ); |
|
159 return err; |
|
160 } |
|
161 |
|
162 TInt CAiPluginActivityRegistry::UpdateOrdinalRegister( TInt aPluginUid ) |
|
163 { |
|
164 TInt categoryKey = iRegistryOrdinal; |
|
165 TInt err = RProperty::Define( |
|
166 KPSUidActiveIdle2, |
|
167 categoryKey, |
|
168 RProperty::EInt, |
|
169 KPluginActivityRegistryReadPolicy, |
|
170 KPluginActivityRegistryWritePolicy ); |
|
171 |
|
172 if( err == KErrNone || |
|
173 err == KErrAlreadyExists ) |
|
174 { |
|
175 // Set plugin uid to ordinal key |
|
176 err = RProperty::Set( |
|
177 KPSUidActiveIdle2, |
|
178 categoryKey, |
|
179 aPluginUid ); |
|
180 } |
|
181 return err; |
|
182 } |
|
183 |
|
184 TInt CAiPluginActivityRegistry::UpdateNameRegister( TInt aPluginUid, |
|
185 const TDesC& aName ) |
|
186 { |
|
187 TInt err = RProperty::Define( |
|
188 KPSUidActiveIdle2, |
|
189 aPluginUid, |
|
190 RProperty::EText, |
|
191 KPluginActivityRegistryReadPolicy, |
|
192 KPluginActivityRegistryWritePolicy ); |
|
193 |
|
194 if( err == KErrNone || |
|
195 err == KErrAlreadyExists ) |
|
196 { |
|
197 // Set plugin uid to ordinal key |
|
198 err = RProperty::Set( |
|
199 KPSUidActiveIdle2, |
|
200 aPluginUid, |
|
201 aName ); |
|
202 } |
|
203 return err; |
|
204 } |
|
205 |
|
206 void CAiPluginActivityRegistry::CleanLastEntry( TInt aPluginUid, |
|
207 TInt aOrdinal, |
|
208 TInt aLastCount ) |
|
209 { |
|
210 RProperty::Delete( KPSUidActiveIdle2, aOrdinal ); |
|
211 RProperty::Delete( KPSUidActiveIdle2, aPluginUid ); |
|
212 if( aLastCount == 0 ) |
|
213 { |
|
214 RProperty::Delete( KPSUidActiveIdle2, KAIActivePluginCount ); |
|
215 } |
|
216 else |
|
217 { |
|
218 RProperty::Set( |
|
219 KPSUidActiveIdle2, |
|
220 KAIActivePluginCount, |
|
221 aLastCount ); |
|
222 } |
|
223 } |
|