os/persistentdata/featuremgmt/featuremgr/tools/featureinstaller/featureinstaller.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
sl@0
     2
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
// All rights reserved.
sl@0
     4
// This component and the accompanying materials are made available
sl@0
     5
// under the terms of "Eclipse Public License v1.0"
sl@0
     6
// which accompanies this distribution, and is available
sl@0
     7
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
//
sl@0
     9
// Initial Contributors:
sl@0
    10
// Nokia Corporation - initial contribution.
sl@0
    11
//
sl@0
    12
// Contributors:
sl@0
    13
//
sl@0
    14
// Description:
sl@0
    15
//
sl@0
    16
sl@0
    17
sl@0
    18
sl@0
    19
// INCLUDE FILES
sl@0
    20
#include <featmgr/featurecontrol.h>
sl@0
    21
sl@0
    22
// LOCAL CONSTANTS AND MACROS
sl@0
    23
_LIT(KTxt,"featureinstaller: mainL failed");
sl@0
    24
sl@0
    25
sl@0
    26
// ============================= LOCAL FUNCTIONS ===============================
sl@0
    27
sl@0
    28
// -----------------------------------------------------------------------------
sl@0
    29
// mainL
sl@0
    30
// -----------------------------------------------------------------------------
sl@0
    31
//  
sl@0
    32
LOCAL_C void mainL()
sl@0
    33
	{
sl@0
    34
	// Open Feature Control.
sl@0
    35
	RFeatureControl featureControl;
sl@0
    36
    User::LeaveIfError( featureControl.Open() );
sl@0
    37
    
sl@0
    38
    // Example code adds a new persisted feature to the device.
sl@0
    39
    // Comment or uncomment code when needed. 
sl@0
    40
    
sl@0
    41
    // Specify in your .pkg file:
sl@0
    42
    // @"featureinstaller.sisx", (0x10283303)
sl@0
    43
sl@0
    44
    
sl@0
    45
    // Replace UID 0x00000000 with real value
sl@0
    46
    TUid featureUid( TUid::Uid( 0x00000000 ) ); 
sl@0
    47
    
sl@0
    48
    // Set feature flags of the feature!
sl@0
    49
   
sl@0
    50
    // Set all flags to zero.
sl@0
    51
    // Comment when needed!
sl@0
    52
    TBitFlags32 featureFlags( 0 );
sl@0
    53
sl@0
    54
    // If set, feature is supported and available for use; 
sl@0
    55
    // if not, feature is not supported.
sl@0
    56
    // Comment when needed!
sl@0
    57
    featureFlags.Set( EFeatureSupported );
sl@0
    58
    
sl@0
    59
    // If set, feature is upgradeable. The feature is known to the device
sl@0
    60
    // but it must be upgraded to enable it. If a feature s blacklisted, 
sl@0
    61
    // its upgradeable flag is unset. 
sl@0
    62
    // Uncomment when needed!
sl@0
    63
    // featureFlags.Set( EFeatureUpgradeable );
sl@0
    64
    
sl@0
    65
    // If set, the feature is modifiable and may be enabled/disabled 
sl@0
    66
    // at run-time. The initial flag values for such a feature flag are
sl@0
    67
    // defined in a ROM image obey file.
sl@0
    68
    // Comment when needed!
sl@0
    69
    featureFlags.Set( EFeatureModifiable );
sl@0
    70
    
sl@0
    71
    // If set, the feature has been blacklisted, and may not be changed at 
sl@0
    72
    // run-time. This also prevents a feature from being upgraded.
sl@0
    73
    // Uncomment when needed!
sl@0
    74
    // featureFlags.Set( EFeatureBlackListed );
sl@0
    75
sl@0
    76
    // If set, only clients with WriteDeviceData capability can modify it.
sl@0
    77
    // This ensures only trusted software can set the feature Supported flag.
sl@0
    78
    // Uncomment when needed!
sl@0
    79
    // featureFlags.Set( EFeatureProtected );
sl@0
    80
    
sl@0
    81
    // If set, this flag is saved to the system drive when modified 
sl@0
    82
    // preserving its value across reboots/power downs.
sl@0
    83
    // Comment when needed!
sl@0
    84
    featureFlags.Set( EFeaturePersisted );
sl@0
    85
    
sl@0
    86
    // If set, this flag Supported state is unknown at build-time and is
sl@0
    87
    // initialised at run-time by system software. The Feature Manager will
sl@0
    88
    // ignore the Supported flag in the file. A run-time call to RFeatureControl
sl@0
    89
    // will be needed to set the feature's supported flag. Look ups of 
sl@0
    90
    // uninitialised features result in a KErrNotReady error code
sl@0
    91
    // Uncomment when needed!
sl@0
    92
    // featureFlags.Set( EFeatureUninitialized );
sl@0
    93
sl@0
    94
    // Feature data is 32-bit quantity for client read and write. Feature data is
sl@0
    95
    // defined by owner of the feature and can contain for example flags, 
sl@0
    96
    // enumeratons and/or integers.
sl@0
    97
    // Set feature data. Replace <featureData> with real value!
sl@0
    98
    // Comment when needed!
sl@0
    99
    TUint32 featureData( 0x00000000 );
sl@0
   100
    
sl@0
   101
    // Comment when needed!
sl@0
   102
    TFeatureEntry entry( featureUid, featureFlags, featureData );
sl@0
   103
    
sl@0
   104
    TInt err( KErrNone );
sl@0
   105
    
sl@0
   106
    // Inform feature manager that your executable is launched by the software installer (SWI)
sl@0
   107
    // and it wishes to set, add, delete, enable or disable features in feature manager. This
sl@0
   108
    // function must be called before any API calls by RFeatureControl that add, set, delete 
sl@0
   109
    // enable, or disable features so that changes in feature manager are cached to be rolled 
sl@0
   110
    // back if the installationhas user-aborted or failed. Otherwise, feature manipulations will
sl@0
   111
    // be committed directly into feature manager and will not be possible to undo them in the
sl@0
   112
    // case of abort.
sl@0
   113
    // A call to SWIStart must be accompanied by a call to SWIEnd after all API calls by
sl@0
   114
    // RFeatureControl functions that manipulate features.
sl@0
   115
    User::LeaveIfError(featureControl.SWIStart()); 
sl@0
   116
sl@0
   117
    // Add a new feature to the device.
sl@0
   118
    // Comment when needed!
sl@0
   119
    err = featureControl.AddFeature( entry );
sl@0
   120
    
sl@0
   121
    if ( err == KErrAlreadyExists ) // Existing feature cannot be added as a new feature.
sl@0
   122
        {
sl@0
   123
        // Enable an existing feature.
sl@0
   124
        User::LeaveIfError( featureControl.EnableFeature( featureUid ) );
sl@0
   125
        
sl@0
   126
        // OR enable an exsiting feature and set feature data.
sl@0
   127
        // Uncomment when needed!
sl@0
   128
        //User::LeaveIfError( featureControl.SetFeature( featureUid, ETrue, featureData ) );
sl@0
   129
        }
sl@0
   130
  
sl@0
   131
    // Inform feature manager that caching feature manipulations should stop and they should be 
sl@0
   132
    // committed to feature manager.
sl@0
   133
    // A call to this API should follow the call to SWIStart before any RFeatureControl API calls
sl@0
   134
    // that manipulate features to feature manager.
sl@0
   135
    User::LeaveIfError(featureControl.SWIEnd());
sl@0
   136
sl@0
   137
    featureControl.Close();
sl@0
   138
    }
sl@0
   139
// ============================ MEMBER FUNCTIONS ===============================
sl@0
   140
sl@0
   141
TInt E32Main() // main function called by E32
sl@0
   142
	{
sl@0
   143
	__UHEAP_MARK;
sl@0
   144
	CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack
sl@0
   145
	TRAPD( error,mainL() ); // Run main method
sl@0
   146
	__ASSERT_ALWAYS( !error,User::Panic(KTxt,error) );
sl@0
   147
	delete cleanup; // destroy clean-up stack
sl@0
   148
	__UHEAP_MARKEND;
sl@0
   149
	return 0; // and return
sl@0
   150
	}
sl@0
   151
sl@0
   152
sl@0
   153
// End of file