genericservices/systemagent/src/server/sysagt2svr.cpp
changeset 31 ce057bb09d0b
child 45 4b03adbd26ca
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     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 	DefinePSPropertyL(KUidSystemCategory, KSWIUidsCurrentlyBeingProcessed, RProperty::EByteArray, KSecurityPolicyNone, KSecurityPolicySwiSIDTrustedUi, 0);
       
   141 		
       
   142 	}
       
   143 
       
   144 /** 
       
   145 The function creates the P&S property with uid KUidUnifiedCertstoreFlag
       
   146 If a property is registered for the first time, its initial value will be set to 0, indicating
       
   147 no operations are currently being performed.
       
   148 @internalComponent
       
   149 @leave Some of the system-wide error codes.
       
   150 */
       
   151 static void CreateUnifiedCertstorePropertiesL()
       
   152 	{
       
   153 	// Allow any process to read or write this value
       
   154 	// initial value of zero
       
   155 	DefinePSPropertyL(KUidSystemCategory, KUidUnifiedCertstoreFlag, RProperty::EInt, KSecurityPolicyNone, KSecurityPolicyNone, 0);
       
   156 	}
       
   157 
       
   158 
       
   159 /** 
       
   160 The function creates P&S properties with uids KUidBackupRestoreKey.
       
   161 If a property is registered for the first time, its initial value will be set to 0, indicating
       
   162 no operations are currently being performed.
       
   163 @internalComponent
       
   164 @leave Some of the system-wide error codes.
       
   165 */
       
   166 static void CreateSBEPropertiesL()
       
   167 	{
       
   168 	// We define two properties currently, one for Java MIDlet install and one for native
       
   169 	// Software Install
       
   170 	TInt properties[]=
       
   171  		{
       
   172 		KUidBackupRestoreKey // backup and restore key
       
   173 		};
       
   174 	
       
   175 	for (TInt i=0; i < sizeof(properties)/sizeof(properties[0]); ++i)
       
   176 		{
       
   177 		DefinePSPropertyL(KUidSystemCategory, properties[i], RProperty::EInt, KSBEReadPolicy, KSBEWritePolicy, 0);
       
   178 		}
       
   179 	}
       
   180 
       
   181 
       
   182 /** 
       
   183 The function creates the P&S property with uids KSAPosLastKnownLocation & KSAPosIntGpsHwStatus
       
   184 If a property is registered for the first time, its initial value will be set to 0, indicating
       
   185 no operations are currently being performed.
       
   186 @internalComponent
       
   187 @leave Some of the system-wide error codes.
       
   188 */
       
   189 static void CreateLBSPropertiesL()
       
   190 	{
       
   191 	DefinePSPropertyL(KSAPosLastKnownLocationCategory, KSAPosLastKnownLocation, RProperty::EText, KLBSLastKnownLocationReadPolicy, KLBSLastKnownLocationWritePolicy, 0);
       
   192 	DefinePSPropertyL(KSAPosIndicatorCategory, KSAPosIntGpsHwStatus, RProperty::EInt, KLBSGpsHwStatusReadPolicy, KLBSGpsHwStatusWritePolicy, 0);
       
   193 	}
       
   194 
       
   195 
       
   196 static void RunServerL()
       
   197 	{
       
   198 	// naming the server thread after the server helps to debug panics
       
   199     User::LeaveIfError(User::RenameThread(KSystemAgentServerName));
       
   200 
       
   201 	::CreatePSPropertiesL();
       
   202 	::CreateSwiPropertiesL();
       
   203 	::CreateUnifiedCertstorePropertiesL();
       
   204 	::CreateSBEPropertiesL();
       
   205 	::CreateLBSPropertiesL();
       
   206 	
       
   207 	RProcess::Rendezvous(KErrNone);
       
   208 	}
       
   209 
       
   210 // Server process entry-point
       
   211 // Recover the startup parameters and run the server
       
   212 TInt E32Main()
       
   213 	{
       
   214 	__UHEAP_MARK;
       
   215 	//
       
   216 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
   217 	TInt r=KErrNoMemory;
       
   218 	if (cleanup)
       
   219 		{
       
   220 		TRAP(r,RunServerL());
       
   221 		delete cleanup;
       
   222 		}
       
   223 	//
       
   224 	__UHEAP_MARKEND;
       
   225 	return r;
       
   226 	}
       
   227 
       
   228