policymanagement/policyengine/PMRfsPlugin/src/PMRfsPlugin.cpp
changeset 0 b497e44ab2fc
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Implementation of policymanagement components
       
    15 *     
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "PMRfsPlugin.h"
       
    22 
       
    23 #include <rfsClient.h>
       
    24 
       
    25 #include <PolicyEngineClient.h>
       
    26 #include "DMUtilClient.h"
       
    27 #include "CentRepToolClient.h"
       
    28 #include "debug.h"
       
    29 #ifdef RD_MULTIPLE_DRIVE
       
    30 #include <driveinfo.h>
       
    31 #include <pathinfo.h>
       
    32 #include <s32file.h>
       
    33 #endif //RD_MULTIPLE_DRIVE
       
    34 
       
    35 #ifndef RD_MULTIPLE_DRIVE
       
    36 _LIT( KScriptFormat_E, "z:\\private\\1020783F\\format_e_.txt");
       
    37 #endif
       
    38 _LIT( KDMUtilServerPrivatePath, "\\private\\10207843\\" );
       
    39 _LIT( MDriveColon, ":");
       
    40 _LIT( KMMCEraseFlagFileName, "fmmc.dat");
       
    41 
       
    42 // ================= MEMBER FUNCTIONS =======================
       
    43 
       
    44 // C++ default constructor can NOT contain any code, that
       
    45 // might leave.
       
    46 //
       
    47 CPMRfsPlugin::CPMRfsPlugin()
       
    48     {
       
    49     RDEBUG("CPMRfsPlugin::CPMRfsPlugin()");
       
    50     }
       
    51 
       
    52 CPMRfsPlugin::CPMRfsPlugin(TAny* /*aInitParams*/)
       
    53     {
       
    54     RDEBUG("CPMRfsPlugin::CPMRfsPlugin()");
       
    55     }
       
    56 
       
    57 // Destructor
       
    58 CPMRfsPlugin::~CPMRfsPlugin()
       
    59     {
       
    60    	RDEBUG("CPMRfsPlugin::~CPMRfsPlugin()");
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------
       
    64 // NewL
       
    65 // ---------------------------------------------------------
       
    66 //
       
    67 CPMRfsPlugin* CPMRfsPlugin::NewL(TAny* aInitParams)
       
    68     {
       
    69     RDEBUG("CPMRfsPlugin::NewL()");
       
    70     CPMRfsPlugin* self = new (ELeave) CPMRfsPlugin(aInitParams);
       
    71     CleanupStack::PushL(self);
       
    72     self->ConstructL();
       
    73     CleanupStack::Pop();
       
    74     return self;
       
    75     }
       
    76 
       
    77 
       
    78 // ---------------------------------------------------------
       
    79 // ConstructL
       
    80 // ---------------------------------------------------------
       
    81 //
       
    82 void CPMRfsPlugin::ConstructL()
       
    83     {
       
    84     RDEBUG("CPMRfsPlugin::ConstructL()");
       
    85     }
       
    86 
       
    87 void CPMRfsPlugin::RestoreFactorySettingsL( const TRfsReason aType )
       
    88     {
       
    89     RDEBUG("CPMRfsPlugin::RestoreFactorySettingsL()");
       
    90     
       
    91     if( aType == ENormalRfs )
       
    92     	{
       
    93     	//Perform DMUtil RFS
       
    94     	RDEBUG("	-> CPMRfsPlugin: Perform DMUtil RFS ... ");
       
    95     	RDMUtil dmutil;
       
    96 		User::LeaveIfError( dmutil.Connect() );
       
    97 		CleanupClosePushL( dmutil );
       
    98     	User::LeaveIfError( dmutil.PerformRFS() );
       
    99 		CleanupStack::PopAndDestroy( &dmutil );
       
   100 		RDEBUG("	-> CPMRfsPlugin: Perform DMUtil RFS ... DONE!");
       
   101     	
       
   102     	//Perform CentRepToolClient RFS
       
   103     	RDEBUG("	-> CPMRfsPlugin: Perform CentRepToolClient RFS ... ");
       
   104 		RCentRepTool centRepTool;
       
   105 		User::LeaveIfError( centRepTool.Connect() );
       
   106 		CleanupClosePushL( centRepTool );
       
   107 		User::LeaveIfError( centRepTool.PerformRFS() );
       
   108 		CleanupStack::PopAndDestroy( &centRepTool );
       
   109 		RDEBUG("	-> CPMRfsPlugin: Perform CentRepToolClient RFS ... DONE!");
       
   110 		
       
   111 		//Perform PolicyEngine RFS
       
   112 		RDEBUG("	-> CPMRfsPlugin: Perform PolicyEngine RFS ... ");
       
   113 		RPolicyEngine policyEngine;
       
   114 		User::LeaveIfError( policyEngine.Connect() );
       
   115 		CleanupClosePushL( policyEngine );
       
   116 		User::LeaveIfError( policyEngine.PerformRFS() );
       
   117 		CleanupStack::PopAndDestroy( &policyEngine );
       
   118 		RDEBUG("	-> CPMRfsPlugin: Perform PolicyEngine RFS ... DONE!");
       
   119     	}
       
   120     	
       
   121     RDEBUG("CPMRfsPlugin::RestoreFactorySettingsL() ... DONE!");
       
   122 	}
       
   123 
       
   124 void CPMRfsPlugin::GetScriptL( const TRfsReason /*aType*/, TDes& aPath )
       
   125     {
       
   126     RDEBUG("CPMRfsPlugin::GetScriptL()");
       
   127     
       
   128         
       
   129     if( IsMMCFormatFlagEnabledL() )
       
   130         {
       
   131         RDEBUG("CPMRfsPlugin::GetScriptL() - Format MMC flag enabled");
       
   132     #ifndef RD_MULTIPLE_DRIVE
       
   133         aPath.Copy( KScriptFormat_E );
       
   134     #else
       
   135     	aPath.Copy( iFileName);
       
   136     	
       
   137     #endif
       
   138         }
       
   139     else
       
   140         {
       
   141         RDEBUG("CPMRfsPlugin::GetScriptL() - Format MMC flag disabled");
       
   142         }
       
   143     }
       
   144 
       
   145 void CPMRfsPlugin::ExecuteCustomCommandL( const TRfsReason /*aType*/,
       
   146                                         TDesC& /*aCommand*/ )
       
   147     {
       
   148     RDEBUG("CPMRfsPlugin::ExecuteCustomCommandL()");
       
   149     }
       
   150      
       
   151 
       
   152 
       
   153 TBool CPMRfsPlugin::IsMMCFormatFlagEnabledL()
       
   154 	{
       
   155 	RDEBUG("CPMRfsPlugin::IsMMCFormatFlagEnabledL()");
       
   156 	
       
   157 	RFs rfs;
       
   158 	User::LeaveIfError( rfs.Connect() );
       
   159 	CleanupClosePushL( rfs );	
       
   160 #ifndef RD_MULTIPLE_DRIVE
       
   161 	TFileName fullPath;
       
   162 	fullPath.Append( _L("e") );
       
   163 	fullPath.Append( MDriveColon );	
       
   164 	fullPath.Append( KDMUtilServerPrivatePath );
       
   165 	fullPath.Append( KMMCEraseFlagFileName );
       
   166 		
       
   167 	RFile file;
       
   168 	TInt err = file.Open( rfs, fullPath, EFileRead );
       
   169 	file.Close();
       
   170 	
       
   171 	CleanupStack::PopAndDestroy( &rfs );
       
   172 	
       
   173 	if( err == KErrNone )
       
   174 		{
       
   175 		RDEBUG("CPMRfsPlugin::IsMMCFormatFlagEnabled() - returned: ETrue");
       
   176 		return ETrue;
       
   177 		}
       
   178 	
       
   179 	RDEBUG_2("CPMRfsPlugin::IsMMCFormatFlagEnabled() - returned: EFalse: %d)", err);
       
   180 	return EFalse;
       
   181 #else
       
   182 	TDriveList driveList;
       
   183 	TInt driveCount;
       
   184 	TBool fileReplace = EFalse;
       
   185 	TInt err = KErrNone;
       
   186 	
       
   187 	//Get all removeable drive, both physically and logically
       
   188 	User::LeaveIfError(DriveInfo::GetUserVisibleDrives(
       
   189             rfs,  driveList,  driveCount, KDriveAttRemovable ));
       
   190     
       
   191     TInt max(driveList.Length());
       
   192     
       
   193     RFileWriteStream file;
       
   194     for(TInt i=0; i<max;++i)
       
   195     {
       
   196     	if (driveList[i])
       
   197     	{
       
   198     		TUint status;
       
   199     		DriveInfo::GetDriveStatus(rfs, i, status);
       
   200     		//To make sure the drive is physically removeable not logically removeable	
       
   201     		//need to format internal mass memory also. So no need to check the below condition
       
   202     		//if (status & DriveInfo::EDriveRemovable)
       
   203     		{
       
   204     			TChar driveLetter;
       
   205     			rfs.DriveToChar(i,driveLetter);
       
   206 				
       
   207 				TFileName fullPath;
       
   208 				fullPath.Append( driveLetter );
       
   209 				fullPath.Append( MDriveColon );
       
   210 				fullPath.Append( KDMUtilServerPrivatePath );
       
   211 				fullPath.Append( KMMCEraseFlagFileName );
       
   212 				
       
   213 				RFile flagfile;
       
   214 				err = flagfile.Open( rfs, fullPath, EFileRead );
       
   215 				flagfile.Close();
       
   216 
       
   217 				if( err == KErrNone )
       
   218 				{
       
   219 					if (!fileReplace)
       
   220 					{
       
   221 						User::LeaveIfError(file.Temp(rfs, _L("C:\\"),iFileName, EFileWrite));	
       
   222 						file.WriteInt16L(65279);
       
   223 						CleanupClosePushL(file);  
       
   224 							
       
   225 						fileReplace = ETrue;
       
   226 						RDEBUG("CPMRfsPlugin::IsMMCFormatFlagEnabled() - File created on private path");
       
   227 					}
       
   228 			
       
   229 					file.WriteL(_L("FORMAT"));
       
   230 					file.WriteL(_L(" "));
       
   231 					TBuf<4> DriveLetterBuf;
       
   232 					DriveLetterBuf.Append(driveLetter);
       
   233 					file.WriteL(DriveLetterBuf);
       
   234 					file.WriteL(_L(":"));
       
   235 					file.WriteL(_L("\r\n"));
       
   236 					
       
   237 				}
       
   238 					
       
   239 			}
       
   240     	}
       
   241      }
       
   242      
       
   243    	if (fileReplace)
       
   244    	{
       
   245    		file.CommitL();
       
   246    		CleanupStack::PopAndDestroy(); // pop file
       
   247    	}
       
   248 		
       
   249 	CleanupStack::PopAndDestroy( &rfs );	
       
   250      if (fileReplace)
       
   251      {
       
   252      	RDEBUG("CPMRfsPlugin::IsMMCFormatFlagEnabled() - returned: ETrue:");
       
   253      	return ETrue;
       
   254      }
       
   255      else
       
   256      {
       
   257      	RDEBUG_2("CPMRfsPlugin::IsMMCFormatFlagEnabled() - returned: EFalse: %d)", err);
       
   258      	return EFalse;
       
   259      }
       
   260     
       
   261 
       
   262 #endif //RD_MULTIPLE_DRIVE
       
   263 	}
       
   264 // End of file