os/persistentdata/featuremgmt/featuremgr/tools/featureinstaller/featureinstaller.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/featuremgmt/featuremgr/tools/featureinstaller/featureinstaller.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,153 @@
1.4 +
1.5 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +// All rights reserved.
1.7 +// This component and the accompanying materials are made available
1.8 +// under the terms of "Eclipse Public License v1.0"
1.9 +// which accompanies this distribution, and is available
1.10 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +//
1.12 +// Initial Contributors:
1.13 +// Nokia Corporation - initial contribution.
1.14 +//
1.15 +// Contributors:
1.16 +//
1.17 +// Description:
1.18 +//
1.19 +
1.20 +
1.21 +
1.22 +// INCLUDE FILES
1.23 +#include <featmgr/featurecontrol.h>
1.24 +
1.25 +// LOCAL CONSTANTS AND MACROS
1.26 +_LIT(KTxt,"featureinstaller: mainL failed");
1.27 +
1.28 +
1.29 +// ============================= LOCAL FUNCTIONS ===============================
1.30 +
1.31 +// -----------------------------------------------------------------------------
1.32 +// mainL
1.33 +// -----------------------------------------------------------------------------
1.34 +//
1.35 +LOCAL_C void mainL()
1.36 + {
1.37 + // Open Feature Control.
1.38 + RFeatureControl featureControl;
1.39 + User::LeaveIfError( featureControl.Open() );
1.40 +
1.41 + // Example code adds a new persisted feature to the device.
1.42 + // Comment or uncomment code when needed.
1.43 +
1.44 + // Specify in your .pkg file:
1.45 + // @"featureinstaller.sisx", (0x10283303)
1.46 +
1.47 +
1.48 + // Replace UID 0x00000000 with real value
1.49 + TUid featureUid( TUid::Uid( 0x00000000 ) );
1.50 +
1.51 + // Set feature flags of the feature!
1.52 +
1.53 + // Set all flags to zero.
1.54 + // Comment when needed!
1.55 + TBitFlags32 featureFlags( 0 );
1.56 +
1.57 + // If set, feature is supported and available for use;
1.58 + // if not, feature is not supported.
1.59 + // Comment when needed!
1.60 + featureFlags.Set( EFeatureSupported );
1.61 +
1.62 + // If set, feature is upgradeable. The feature is known to the device
1.63 + // but it must be upgraded to enable it. If a feature s blacklisted,
1.64 + // its upgradeable flag is unset.
1.65 + // Uncomment when needed!
1.66 + // featureFlags.Set( EFeatureUpgradeable );
1.67 +
1.68 + // If set, the feature is modifiable and may be enabled/disabled
1.69 + // at run-time. The initial flag values for such a feature flag are
1.70 + // defined in a ROM image obey file.
1.71 + // Comment when needed!
1.72 + featureFlags.Set( EFeatureModifiable );
1.73 +
1.74 + // If set, the feature has been blacklisted, and may not be changed at
1.75 + // run-time. This also prevents a feature from being upgraded.
1.76 + // Uncomment when needed!
1.77 + // featureFlags.Set( EFeatureBlackListed );
1.78 +
1.79 + // If set, only clients with WriteDeviceData capability can modify it.
1.80 + // This ensures only trusted software can set the feature Supported flag.
1.81 + // Uncomment when needed!
1.82 + // featureFlags.Set( EFeatureProtected );
1.83 +
1.84 + // If set, this flag is saved to the system drive when modified
1.85 + // preserving its value across reboots/power downs.
1.86 + // Comment when needed!
1.87 + featureFlags.Set( EFeaturePersisted );
1.88 +
1.89 + // If set, this flag Supported state is unknown at build-time and is
1.90 + // initialised at run-time by system software. The Feature Manager will
1.91 + // ignore the Supported flag in the file. A run-time call to RFeatureControl
1.92 + // will be needed to set the feature's supported flag. Look ups of
1.93 + // uninitialised features result in a KErrNotReady error code
1.94 + // Uncomment when needed!
1.95 + // featureFlags.Set( EFeatureUninitialized );
1.96 +
1.97 + // Feature data is 32-bit quantity for client read and write. Feature data is
1.98 + // defined by owner of the feature and can contain for example flags,
1.99 + // enumeratons and/or integers.
1.100 + // Set feature data. Replace <featureData> with real value!
1.101 + // Comment when needed!
1.102 + TUint32 featureData( 0x00000000 );
1.103 +
1.104 + // Comment when needed!
1.105 + TFeatureEntry entry( featureUid, featureFlags, featureData );
1.106 +
1.107 + TInt err( KErrNone );
1.108 +
1.109 + // Inform feature manager that your executable is launched by the software installer (SWI)
1.110 + // and it wishes to set, add, delete, enable or disable features in feature manager. This
1.111 + // function must be called before any API calls by RFeatureControl that add, set, delete
1.112 + // enable, or disable features so that changes in feature manager are cached to be rolled
1.113 + // back if the installationhas user-aborted or failed. Otherwise, feature manipulations will
1.114 + // be committed directly into feature manager and will not be possible to undo them in the
1.115 + // case of abort.
1.116 + // A call to SWIStart must be accompanied by a call to SWIEnd after all API calls by
1.117 + // RFeatureControl functions that manipulate features.
1.118 + User::LeaveIfError(featureControl.SWIStart());
1.119 +
1.120 + // Add a new feature to the device.
1.121 + // Comment when needed!
1.122 + err = featureControl.AddFeature( entry );
1.123 +
1.124 + if ( err == KErrAlreadyExists ) // Existing feature cannot be added as a new feature.
1.125 + {
1.126 + // Enable an existing feature.
1.127 + User::LeaveIfError( featureControl.EnableFeature( featureUid ) );
1.128 +
1.129 + // OR enable an exsiting feature and set feature data.
1.130 + // Uncomment when needed!
1.131 + //User::LeaveIfError( featureControl.SetFeature( featureUid, ETrue, featureData ) );
1.132 + }
1.133 +
1.134 + // Inform feature manager that caching feature manipulations should stop and they should be
1.135 + // committed to feature manager.
1.136 + // A call to this API should follow the call to SWIStart before any RFeatureControl API calls
1.137 + // that manipulate features to feature manager.
1.138 + User::LeaveIfError(featureControl.SWIEnd());
1.139 +
1.140 + featureControl.Close();
1.141 + }
1.142 +// ============================ MEMBER FUNCTIONS ===============================
1.143 +
1.144 +TInt E32Main() // main function called by E32
1.145 + {
1.146 + __UHEAP_MARK;
1.147 + CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack
1.148 + TRAPD( error,mainL() ); // Run main method
1.149 + __ASSERT_ALWAYS( !error,User::Panic(KTxt,error) );
1.150 + delete cleanup; // destroy clean-up stack
1.151 + __UHEAP_MARKEND;
1.152 + return 0; // and return
1.153 + }
1.154 +
1.155 +
1.156 +// End of file