|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <hal.h> |
|
17 #include <e32base.h> |
|
18 #include "SaPrivate.h" |
|
19 #include "SaCls.h" |
|
20 #include <saclsdefines.h> |
|
21 #include <saclscommon.h> |
|
22 |
|
23 /** |
|
24 Count of the properties registered at startup. |
|
25 50 Uids issued from 0x100052C3 to 0x100052F4 |
|
26 0x100052C3 is not used, 0x100052C4 is used for KUidSystemAgentExe |
|
27 leaving 48 for property uids |
|
28 @internalComponent |
|
29 */ |
|
30 const TInt KPropertyCount = 48; |
|
31 |
|
32 //Security policy definitions for the KPropertyCount predefined properties. |
|
33 _LIT_SECURITY_POLICY_C1(KSecurityPolicyNone, ECapability_None); |
|
34 _LIT_SECURITY_POLICY_C1(KSecurityPolicyWriteDeviceData, ECapabilityWriteDeviceData); |
|
35 _LIT_SECURITY_POLICY_S1(KSecurityPolicySwiSIDTrustedUi, 0x101F7295, ECapabilityTrustedUI); |
|
36 _LIT_SECURITY_POLICY_S0(KSecurityPolicyJavaSID, 0x1020329F); |
|
37 |
|
38 // Security policy for secure backup engine |
|
39 const TInt KSBESID = 0x10202D56; |
|
40 _LIT_SECURITY_POLICY_S0(KSBEWritePolicy, KSBESID); |
|
41 _LIT_SECURITY_POLICY_PASS(KSBEReadPolicy); |
|
42 |
|
43 // Security policy definitions for LBS |
|
44 _LIT_SECURITY_POLICY_C1(KLBSLastKnownLocationReadPolicy, ECapabilityReadDeviceData); |
|
45 _LIT_SECURITY_POLICY_S0(KLBSLastKnownLocationWritePolicy, 0x101f97b2); |
|
46 _LIT_SECURITY_POLICY_PASS(KLBSGpsHwStatusReadPolicy); |
|
47 _LIT_SECURITY_POLICY_C1(KLBSGpsHwStatusWritePolicy, ECapabilityWriteDeviceData); |
|
48 |
|
49 //The function initializes aWritePolicy parameter with the appropriate |
|
50 //value, depending on the value of aPropertyUid parameter. |
|
51 static void GetPropertyPolicies(const TUid& aPropertyUid, const TSecurityPolicy*& aWritePolicy) |
|
52 { |
|
53 switch(aPropertyUid.iUid) |
|
54 { |
|
55 case KUidPhonePwrValue: |
|
56 case KUidSIMStatusValue: |
|
57 case KUidNetworkStatusValue: |
|
58 case KUidNetworkStrengthValue: |
|
59 case KUidChargerStatusValue: |
|
60 case KUidBatteryStrengthValue: |
|
61 case KUidCurrentCallValue: |
|
62 aWritePolicy = &KSecurityPolicyWriteDeviceData; |
|
63 break; |
|
64 default: |
|
65 aWritePolicy = &KSecurityPolicyNone; |
|
66 break; |
|
67 }; |
|
68 } |
|
69 |
|
70 /** |
|
71 This function tries to define a property, and if it is not already defined, it sets its value to a default value. |
|
72 @internalComponent |
|
73 @leave Some of the system-wide error codes. |
|
74 @param aCategory The UID that identifies the property category. |
|
75 @param aKey The property sub-key, i.e. the key that identifies the specific property within the category. |
|
76 @param aAttr This describes the property type, a TType value; persistence, as defined by the KPersistent bit, may be ORed in. |
|
77 @param aReadPolicy A security policy defining the security attributes a process must have in order to read this value. |
|
78 @param aWritePolicy A security policy defining the security attributes a process must have in order to write this value. |
|
79 @param aDefaultValue The default value to assign to the property, if the property does not already exist and we define it. If the default value is zero (0) the property will not be set, since this is the default. |
|
80 */ |
|
81 static void DefinePSPropertyL(TUid aCategory, TInt aKey, TInt aAttr, const TSecurityPolicy &aReadPolicy, const TSecurityPolicy &aWritePolicy, TInt aDefaultValue) |
|
82 { |
|
83 TInt err = RProperty::Define(aCategory, aKey, aAttr, aReadPolicy, aWritePolicy); |
|
84 |
|
85 if (err != KErrAlreadyExists) |
|
86 { |
|
87 // Leave if the error is not one of KErrNone or KErrAlreadyExists |
|
88 User::LeaveIfError(err); |
|
89 } |
|
90 |
|
91 if (err == KErrNone && aDefaultValue != 0) |
|
92 { |
|
93 // Initialise the value if it was not already defined, and the value is not already set |
|
94 User::LeaveIfError(RProperty::Set(aCategory, aKey, aDefaultValue)); |
|
95 } |
|
96 |
|
97 } |
|
98 |
|
99 |
|
100 /** |
|
101 The function creates P&S properties with uid's from 0x100052C5 to 0x100052C5 + KPropertyCount. |
|
102 They were (and are) used by the implementation of SystemAgent server. |
|
103 If a property is registered for the first time, its initial value will be set to KErrUnknown. |
|
104 @internalComponent |
|
105 @leave Some of the system-wide error codes. |
|
106 */ |
|
107 static void CreatePSPropertiesL() |
|
108 { |
|
109 TUid saUid = TUid::Uid(KUidPhonePwrValue); |
|
110 for(TInt i=0;i<KPropertyCount;++i) |
|
111 { |
|
112 const TSecurityPolicy* writePolicy = NULL; |
|
113 ::GetPropertyPolicies(saUid, writePolicy); |
|
114 |
|
115 DefinePSPropertyL(KUidSystemCategory, saUid.iUid, RProperty::EInt, KSecurityPolicyNone, *writePolicy, KErrUnknown); |
|
116 ++saUid.iUid; |
|
117 } |
|
118 } |
|
119 |
|
120 /** |
|
121 The function creates P&S properties with uids KUidJavaInstallKey and Swi::KUidSoftwareInstallKey. |
|
122 If a property is registered for the first time, its initial value will be set to 0, indicating |
|
123 no operations are currently being performed. |
|
124 @internalComponent |
|
125 @leave Some of the system-wide error codes. |
|
126 */ |
|
127 static void CreateSwiPropertiesL() |
|
128 { |
|
129 |
|
130 // Java properties are policed on the JavaHelperServer SID |
|
131 |
|
132 DefinePSPropertyL(KUidSystemCategory, KSAUidJavaInstallKeyValue, RProperty::EInt, KSecurityPolicyNone, KSecurityPolicyJavaSID, 0); |
|
133 DefinePSPropertyL(KUidSystemCategory, KUidJmiLatestInstallation, RProperty::EInt, KSecurityPolicyNone, KSecurityPolicyJavaSID, 0); |
|
134 |
|
135 // Native properties are policed on the TrustedUI capability |
|
136 |
|
137 DefinePSPropertyL(KUidSystemCategory, KSAUidSoftwareInstallKeyValue, RProperty::EInt, KSecurityPolicyNone, KSecurityPolicySwiSIDTrustedUi, 0); |
|
138 DefinePSPropertyL(KUidSystemCategory, KUidSwiLatestInstallation, RProperty::EInt, KSecurityPolicyNone, KSecurityPolicySwiSIDTrustedUi, 0); |
|
139 |
|
140 } |
|
141 |
|
142 /** |
|
143 The function creates the P&S property with uid KUidUnifiedCertstoreFlag |
|
144 If a property is registered for the first time, its initial value will be set to 0, indicating |
|
145 no operations are currently being performed. |
|
146 @internalComponent |
|
147 @leave Some of the system-wide error codes. |
|
148 */ |
|
149 static void CreateUnifiedCertstorePropertiesL() |
|
150 { |
|
151 // Allow any process to read or write this value |
|
152 // initial value of zero |
|
153 DefinePSPropertyL(KUidSystemCategory, KUidUnifiedCertstoreFlag, RProperty::EInt, KSecurityPolicyNone, KSecurityPolicyNone, 0); |
|
154 } |
|
155 |
|
156 |
|
157 /** |
|
158 The function creates P&S properties with uids KUidBackupRestoreKey. |
|
159 If a property is registered for the first time, its initial value will be set to 0, indicating |
|
160 no operations are currently being performed. |
|
161 @internalComponent |
|
162 @leave Some of the system-wide error codes. |
|
163 */ |
|
164 static void CreateSBEPropertiesL() |
|
165 { |
|
166 // We define two properties currently, one for Java MIDlet install and one for native |
|
167 // Software Install |
|
168 TInt properties[]= |
|
169 { |
|
170 KUidBackupRestoreKey // backup and restore key |
|
171 }; |
|
172 |
|
173 for (TInt i=0; i < sizeof(properties)/sizeof(properties[0]); ++i) |
|
174 { |
|
175 DefinePSPropertyL(KUidSystemCategory, properties[i], RProperty::EInt, KSBEReadPolicy, KSBEWritePolicy, 0); |
|
176 } |
|
177 } |
|
178 |
|
179 |
|
180 /** |
|
181 The function creates the P&S property with uids KSAPosLastKnownLocation & KSAPosIntGpsHwStatus |
|
182 If a property is registered for the first time, its initial value will be set to 0, indicating |
|
183 no operations are currently being performed. |
|
184 @internalComponent |
|
185 @leave Some of the system-wide error codes. |
|
186 */ |
|
187 static void CreateLBSPropertiesL() |
|
188 { |
|
189 DefinePSPropertyL(KSAPosLastKnownLocationCategory, KSAPosLastKnownLocation, RProperty::EText, KLBSLastKnownLocationReadPolicy, KLBSLastKnownLocationWritePolicy, 0); |
|
190 DefinePSPropertyL(KSAPosIndicatorCategory, KSAPosIntGpsHwStatus, RProperty::EInt, KLBSGpsHwStatusReadPolicy, KLBSGpsHwStatusWritePolicy, 0); |
|
191 } |
|
192 |
|
193 |
|
194 static void RunServerL() |
|
195 { |
|
196 // naming the server thread after the server helps to debug panics |
|
197 User::LeaveIfError(User::RenameThread(KSystemAgentServerName)); |
|
198 |
|
199 ::CreatePSPropertiesL(); |
|
200 ::CreateSwiPropertiesL(); |
|
201 ::CreateUnifiedCertstorePropertiesL(); |
|
202 ::CreateSBEPropertiesL(); |
|
203 ::CreateLBSPropertiesL(); |
|
204 |
|
205 RProcess::Rendezvous(KErrNone); |
|
206 } |
|
207 |
|
208 // Server process entry-point |
|
209 // Recover the startup parameters and run the server |
|
210 TInt E32Main() |
|
211 { |
|
212 __UHEAP_MARK; |
|
213 // |
|
214 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
215 TInt r=KErrNoMemory; |
|
216 if (cleanup) |
|
217 { |
|
218 TRAP(r,RunServerL()); |
|
219 delete cleanup; |
|
220 } |
|
221 // |
|
222 __UHEAP_MARKEND; |
|
223 return r; |
|
224 } |
|
225 |
|
226 |