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