sl@0: 
sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: 
sl@0: 
sl@0: // INCLUDE FILES
sl@0: #include <featmgr/featurecontrol.h>
sl@0: 
sl@0: // LOCAL CONSTANTS AND MACROS
sl@0: _LIT(KTxt,"featureinstaller: mainL failed");
sl@0: 
sl@0: 
sl@0: // ============================= LOCAL FUNCTIONS ===============================
sl@0: 
sl@0: // -----------------------------------------------------------------------------
sl@0: // mainL
sl@0: // -----------------------------------------------------------------------------
sl@0: //  
sl@0: LOCAL_C void mainL()
sl@0: 	{
sl@0: 	// Open Feature Control.
sl@0: 	RFeatureControl featureControl;
sl@0:     User::LeaveIfError( featureControl.Open() );
sl@0:     
sl@0:     // Example code adds a new persisted feature to the device.
sl@0:     // Comment or uncomment code when needed. 
sl@0:     
sl@0:     // Specify in your .pkg file:
sl@0:     // @"featureinstaller.sisx", (0x10283303)
sl@0: 
sl@0:     
sl@0:     // Replace UID 0x00000000 with real value
sl@0:     TUid featureUid( TUid::Uid( 0x00000000 ) ); 
sl@0:     
sl@0:     // Set feature flags of the feature!
sl@0:    
sl@0:     // Set all flags to zero.
sl@0:     // Comment when needed!
sl@0:     TBitFlags32 featureFlags( 0 );
sl@0: 
sl@0:     // If set, feature is supported and available for use; 
sl@0:     // if not, feature is not supported.
sl@0:     // Comment when needed!
sl@0:     featureFlags.Set( EFeatureSupported );
sl@0:     
sl@0:     // If set, feature is upgradeable. The feature is known to the device
sl@0:     // but it must be upgraded to enable it. If a feature s blacklisted, 
sl@0:     // its upgradeable flag is unset. 
sl@0:     // Uncomment when needed!
sl@0:     // featureFlags.Set( EFeatureUpgradeable );
sl@0:     
sl@0:     // If set, the feature is modifiable and may be enabled/disabled 
sl@0:     // at run-time. The initial flag values for such a feature flag are
sl@0:     // defined in a ROM image obey file.
sl@0:     // Comment when needed!
sl@0:     featureFlags.Set( EFeatureModifiable );
sl@0:     
sl@0:     // If set, the feature has been blacklisted, and may not be changed at 
sl@0:     // run-time. This also prevents a feature from being upgraded.
sl@0:     // Uncomment when needed!
sl@0:     // featureFlags.Set( EFeatureBlackListed );
sl@0: 
sl@0:     // If set, only clients with WriteDeviceData capability can modify it.
sl@0:     // This ensures only trusted software can set the feature Supported flag.
sl@0:     // Uncomment when needed!
sl@0:     // featureFlags.Set( EFeatureProtected );
sl@0:     
sl@0:     // If set, this flag is saved to the system drive when modified 
sl@0:     // preserving its value across reboots/power downs.
sl@0:     // Comment when needed!
sl@0:     featureFlags.Set( EFeaturePersisted );
sl@0:     
sl@0:     // If set, this flag Supported state is unknown at build-time and is
sl@0:     // initialised at run-time by system software. The Feature Manager will
sl@0:     // ignore the Supported flag in the file. A run-time call to RFeatureControl
sl@0:     // will be needed to set the feature's supported flag. Look ups of 
sl@0:     // uninitialised features result in a KErrNotReady error code
sl@0:     // Uncomment when needed!
sl@0:     // featureFlags.Set( EFeatureUninitialized );
sl@0: 
sl@0:     // Feature data is 32-bit quantity for client read and write. Feature data is
sl@0:     // defined by owner of the feature and can contain for example flags, 
sl@0:     // enumeratons and/or integers.
sl@0:     // Set feature data. Replace <featureData> with real value!
sl@0:     // Comment when needed!
sl@0:     TUint32 featureData( 0x00000000 );
sl@0:     
sl@0:     // Comment when needed!
sl@0:     TFeatureEntry entry( featureUid, featureFlags, featureData );
sl@0:     
sl@0:     TInt err( KErrNone );
sl@0:     
sl@0:     // Inform feature manager that your executable is launched by the software installer (SWI)
sl@0:     // and it wishes to set, add, delete, enable or disable features in feature manager. This
sl@0:     // function must be called before any API calls by RFeatureControl that add, set, delete 
sl@0:     // enable, or disable features so that changes in feature manager are cached to be rolled 
sl@0:     // back if the installationhas user-aborted or failed. Otherwise, feature manipulations will
sl@0:     // be committed directly into feature manager and will not be possible to undo them in the
sl@0:     // case of abort.
sl@0:     // A call to SWIStart must be accompanied by a call to SWIEnd after all API calls by
sl@0:     // RFeatureControl functions that manipulate features.
sl@0:     User::LeaveIfError(featureControl.SWIStart()); 
sl@0: 
sl@0:     // Add a new feature to the device.
sl@0:     // Comment when needed!
sl@0:     err = featureControl.AddFeature( entry );
sl@0:     
sl@0:     if ( err == KErrAlreadyExists ) // Existing feature cannot be added as a new feature.
sl@0:         {
sl@0:         // Enable an existing feature.
sl@0:         User::LeaveIfError( featureControl.EnableFeature( featureUid ) );
sl@0:         
sl@0:         // OR enable an exsiting feature and set feature data.
sl@0:         // Uncomment when needed!
sl@0:         //User::LeaveIfError( featureControl.SetFeature( featureUid, ETrue, featureData ) );
sl@0:         }
sl@0:   
sl@0:     // Inform feature manager that caching feature manipulations should stop and they should be 
sl@0:     // committed to feature manager.
sl@0:     // A call to this API should follow the call to SWIStart before any RFeatureControl API calls
sl@0:     // that manipulate features to feature manager.
sl@0:     User::LeaveIfError(featureControl.SWIEnd());
sl@0: 
sl@0:     featureControl.Close();
sl@0:     }
sl@0: // ============================ MEMBER FUNCTIONS ===============================
sl@0: 
sl@0: TInt E32Main() // main function called by E32
sl@0: 	{
sl@0: 	__UHEAP_MARK;
sl@0: 	CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack
sl@0: 	TRAPD( error,mainL() ); // Run main method
sl@0: 	__ASSERT_ALWAYS( !error,User::Panic(KTxt,error) );
sl@0: 	delete cleanup; // destroy clean-up stack
sl@0: 	__UHEAP_MARKEND;
sl@0: 	return 0; // and return
sl@0: 	}
sl@0: 
sl@0: 
sl@0: // End of file