mtpfws/mtpfw/dataproviders/devdp/src/cmtpgetstorageinfo.cpp
changeset 49 c20dd21d1eb4
parent 37 d9d8313203af
equal deleted inserted replaced
41:2c19c7cf5550 49:c20dd21d1eb4
    25 #include "mtpdevdppanic.h"
    25 #include "mtpdevdppanic.h"
    26 #include "rmtpdevicedpsingletons.h"
    26 #include "rmtpdevicedpsingletons.h"
    27 #include "cmtpdevicedpconfigmgr.h"
    27 #include "cmtpdevicedpconfigmgr.h"
    28 #include "mtpframeworkconst.h"
    28 #include "mtpframeworkconst.h"
    29 #include "mtpcommonconst.h"
    29 #include "mtpcommonconst.h"
       
    30 #include "mtpdebug.h"
       
    31 #include "OstTraceDefinitions.h"
       
    32 #ifdef OST_TRACE_COMPILER_IN_USE
       
    33 #include "cmtpgetstorageinfoTraces.h"
       
    34 #endif
       
    35 
    30 
    36 
    31 // Class constants.
    37 // Class constants.
    32 __FLOG_STMT(_LIT8(KComponent,"GetStorageInfo");)
       
    33 
    38 
    34 /**
    39 /**
    35 Verification data for GetStorageInfo request
    40 Verification data for GetStorageInfo request
    36 */
    41 */
    37 const TMTPRequestElementInfo KMTPGetStorageInfoPolicy[] = 
    42 const TMTPRequestElementInfo KMTPGetStorageInfoPolicy[] = 
    62 */	
    67 */	
    63 CMTPGetStorageInfo::~CMTPGetStorageInfo()
    68 CMTPGetStorageInfo::~CMTPGetStorageInfo()
    64 	{	
    69 	{	
    65 	delete iStorageInfo;
    70 	delete iStorageInfo;
    66 	iSingletons.Close();
    71 	iSingletons.Close();
    67 	__FLOG_CLOSE;
       
    68 	}
    72 	}
    69 	
    73 	
    70 /**
    74 /**
    71 Standard c++ constructor
    75 Standard c++ constructor
    72 */	
    76 */	
   119 /**
   123 /**
   120 Second-phase construction
   124 Second-phase construction
   121 */		
   125 */		
   122 void CMTPGetStorageInfo::ConstructL()
   126 void CMTPGetStorageInfo::ConstructL()
   123 	{
   127 	{
   124 	__FLOG_OPEN(KMTPSubsystem, KComponent);
       
   125 	iStorageInfo = CMTPTypeStorageInfo::NewL();
   128 	iStorageInfo = CMTPTypeStorageInfo::NewL();
   126 	iSingletons.OpenL();
   129 	iSingletons.OpenL();
   127 	}
   130 	}
   128 
   131 
   129 /**
   132 /**
   148 */
   151 */
   149 void CMTPGetStorageInfo::SetupDriveVolumeInfoL()
   152 void CMTPGetStorageInfo::SetupDriveVolumeInfoL()
   150 	{
   153 	{
   151 	TUint32 storageId = Request().Uint32(TMTPTypeRequest::ERequestParameter1);	
   154 	TUint32 storageId = Request().Uint32(TMTPTypeRequest::ERequestParameter1);	
   152 	TInt driveNo(iFramework.StorageMgr().DriveNumber(storageId));
   155 	TInt driveNo(iFramework.StorageMgr().DriveNumber(storageId));
   153 	User::LeaveIfError(driveNo);
   156 	LEAVEIFERROR(driveNo,
       
   157 	        OstTrace1( TRACE_ERROR, CMTPGETSTORAGEINFO_SETUPDRIVEVOLUMEINFOL, "can't get driver number for storageId %d", storageId));	        
   154 	RFs& fs = iFramework.Fs();
   158 	RFs& fs = iFramework.Fs();
   155 	User::LeaveIfError(fs.Drive(iDriveInfo, driveNo));
   159 	LEAVEIFERROR(fs.Drive(iDriveInfo, driveNo),
   156 	User::LeaveIfError(fs.Volume(iVolumeInfo, driveNo));
   160 	        OstTrace1( TRACE_ERROR, DUP1_CMTPGETSTORAGEINFO_SETUPDRIVEVOLUMEINFOL, "can't get drive info for driver number %d", driveNo));     
       
   161 	LEAVEIFERROR(fs.Volume(iVolumeInfo, driveNo),
       
   162             OstTrace1( TRACE_ERROR, DUP2_CMTPGETSTORAGEINFO_SETUPDRIVEVOLUMEINFOL, "can't get volume info for driver no %d", driveNo ));	        
   157 	
   163 	
   158 	const TInt KCDriveNo = 2;
   164 	const TInt KCDriveNo = 2;
   159 	if(KCDriveNo == driveNo)
   165 	if(KCDriveNo == driveNo)
   160 		{
   166 		{
   161 		iDriveInfo.iType = EMediaRom;
   167 		iDriveInfo.iType = EMediaRom;
   171 	TUint16 storageType = EMTPStorageUndefined;
   177 	TUint16 storageType = EMTPStorageUndefined;
   172 	
   178 	
   173 	switch(iDriveInfo.iType)
   179 	switch(iDriveInfo.iType)
   174 		{
   180 		{
   175 		case EMediaNotPresent:
   181 		case EMediaNotPresent:
       
   182 		    OstTrace0( TRACE_ERROR, DUP3_CMTPGETSTORAGEINFO_SETSTORAGETYPEL, "drive media not present!" );
   176 			User::Leave(KErrDisMounted);
   183 			User::Leave(KErrDisMounted);
   177 			break;
   184 			break;
   178 		case EMediaUnknown:		
   185 		case EMediaUnknown:		
   179 			break;
   186 			break;
   180 			
   187 			
   196 		        {
   203 		        {
   197 		        //E: is set as logically removable after eMMC image updated
   204 		        //E: is set as logically removable after eMMC image updated
   198 		        //So here we need to deal with this case to set it as FixedRam
   205 		        //So here we need to deal with this case to set it as FixedRam
   199 		        if(iDriveInfo.iDriveAtt & KDriveAttLogicallyRemovable)
   206 		        if(iDriveInfo.iDriveAtt & KDriveAttLogicallyRemovable)
   200 		            {
   207 		            {
   201 		            __FLOG(_L8("removable but internal drive, set as Fixed RAM"));
   208 		            OstTrace0( TRACE_NORMAL, CMTPGETSTORAGEINFO_SETSTORAGETYPEL, 
       
   209 		                    "removable but internal drive, set as Fixed RAM" );
   202 		            storageType = EMTPStorageFixedRAM;
   210 		            storageType = EMTPStorageFixedRAM;
   203 		            }
   211 		            }
   204 		        else
   212 		        else
   205 		            {
   213 		            {
   206 		            __FLOG(_L8("non internal,set as removable RAM"));
   214 		            OstTrace0( TRACE_NORMAL, DUP1_CMTPGETSTORAGEINFO_SETSTORAGETYPEL, 
       
   215 		                    "non internal,set as removable RAM" );
   207 		            storageType = EMTPStorageRemovableRAM;
   216 		            storageType = EMTPStorageRemovableRAM;
   208 		            }
   217 		            }
   209 		        }
   218 		        }
   210 		    else
   219 		    else
   211 		        {
   220 		        {
   212 		        __FLOG(_L8("Non removable, set as Fixed RAM"));
   221 		        OstTrace0( TRACE_NORMAL, DUP2_CMTPGETSTORAGEINFO_SETSTORAGETYPEL, 
       
   222 		                "Non removable, set as Fixed RAM" );        
   213 		        storageType = EMTPStorageFixedRAM;
   223 		        storageType = EMTPStorageFixedRAM;
   214 		        }
   224 		        }
   215 			break;
   225 			break;
   216 		default:
   226 		default:
   217 			break;
   227 			break;
   274 	    if (err == KErrNone)
   284 	    if (err == KErrNone)
   275 	        {
   285 	        {
   276 	        err = repository->Get(KUikOODDiskFreeSpaceWarningNoteLevelMassMemory,thresholdValue);
   286 	        err = repository->Get(KUikOODDiskFreeSpaceWarningNoteLevelMassMemory,thresholdValue);
   277 	        if (err == KErrNone)
   287 	        if (err == KErrNone)
   278 	            {
   288 	            {
   279 	            __FLOG_1(_L8("Read from central repo:%d"),thresholdValue);
   289 	            OstTrace1( TRACE_NORMAL, CMTPGETSTORAGEINFO_SETFREESPACEINBYTESL, 
       
   290 	                    "Read from central repo:%d",  thresholdValue);
       
   291 	            
   280 	            thresholdValue += KFreeSpaceExtraReserved;
   292 	            thresholdValue += KFreeSpaceExtraReserved;
   281 	            }	  
   293 	            }	  
   282 	        delete repository;
   294 	        delete repository;
   283 	        }
   295 	        }
   284 	    
   296 	    
   285 	    if (err != KErrNone)
   297 	    if (err != KErrNone)
   286 	        {
   298 	        {
   287 	        __FLOG(_L8("Fail in read ,use default"));
   299 	        OstTrace0( TRACE_WARNING, DUP1_CMTPGETSTORAGEINFO_SETFREESPACEINBYTESL, "Fail in read ,use default" );
   288 	        thresholdValue = KFreeSpaceThreshHoldDefaultValue + KFreeSpaceExtraReserved;
   300 	        thresholdValue = KFreeSpaceThreshHoldDefaultValue + KFreeSpaceExtraReserved;
   289 	        }
   301 	        }
   290 	    
   302 	    
   291 	    __FLOG_2(_L8("threshold:%d free space:%ld"),thresholdValue,iVolumeInfo.iFree);
   303 	    OstTraceExt2( TRACE_NORMAL, DUP2_CMTPGETSTORAGEINFO_SETFREESPACEINBYTESL, 
       
   304 	            "threshold:%d free space:%Ld",thresholdValue,iVolumeInfo.iFree );
       
   305 	    
   292 	    //Exclude the reserved disk space when reporting free space
   306 	    //Exclude the reserved disk space when reporting free space
   293 	    TInt64 free = (iVolumeInfo.iFree > thresholdValue) ?
   307 	    TInt64 free = (iVolumeInfo.iFree > thresholdValue) ?
   294 	        (iVolumeInfo.iFree - thresholdValue) : 0;
   308 	        (iVolumeInfo.iFree - thresholdValue) : 0;
   295 	    mtpFreeSpace.Set(free);
   309 	    mtpFreeSpace.Set(free);
   296 	    __FLOG_1(_L8("set free:%ld"),free);
   310 	    OstTrace1( TRACE_NORMAL, DUP3_CMTPGETSTORAGEINFO_SETFREESPACEINBYTESL, "set free:%ld", free);  
   297 	    }
   311 	    }
   298 	
   312 	
   299 	__FLOG_2(_L8("SetFreeSpaceInBytesL volume free:%ld report:%ld"),
   313 	OstTraceExt2( TRACE_NORMAL, DUP4_CMTPGETSTORAGEINFO_SETFREESPACEINBYTESL, 
   300 	        iVolumeInfo.iFree,mtpFreeSpace.Value());
   314 	        "SetFreeSpaceInBytesL volume free:%Ld report:%Ld", iVolumeInfo.iFree,mtpFreeSpace.Value());
       
   315 	
   301 	iStorageInfo->SetL(CMTPTypeStorageInfo::EFreeSpaceInBytes, mtpFreeSpace);	
   316 	iStorageInfo->SetL(CMTPTypeStorageInfo::EFreeSpaceInBytes, mtpFreeSpace);	
   302 	}
   317 	}
   303 	
   318 	
   304 /**
   319 /**
   305 Set the free space of in objects in the storage info data set
   320 Set the free space of in objects in the storage info data set
   313 /**
   328 /**
   314 Set the storage description (volume name) of the drive in the storage info data set
   329 Set the storage description (volume name) of the drive in the storage info data set
   315 */
   330 */
   316 void CMTPGetStorageInfo::SetStorageDescriptionL()
   331 void CMTPGetStorageInfo::SetStorageDescriptionL()
   317 	{
   332 	{
   318 	__FLOG(_L8("SetStorageDescriptionL - Entry"));
   333 	OstTraceFunctionEntry0( CMTPGETSTORAGEINFO_SETSTORAGEDESCRIPTIONL_ENTRY );
   319     TUint32 storage(Request().Uint32(TMTPTypeRequest::ERequestParameter1));
   334     TUint32 storage(Request().Uint32(TMTPTypeRequest::ERequestParameter1));
   320     TInt driveNumber = iFramework.StorageMgr().DriveNumber(storage);
   335     TInt driveNumber = iFramework.StorageMgr().DriveNumber(storage);
   321 	__FLOG_1(_L8("driveNumber:%d"),driveNumber);
   336 	OstTrace1( TRACE_NORMAL, CMTPGETSTORAGEINFO_SETSTORAGEDESCRIPTIONL, "driveNumber:%d", driveNumber);	
   322 	
   337 	
   323 	CMTPTypeString* mtpDescription = CMTPTypeString::NewLC();
   338 	CMTPTypeString* mtpDescription = CMTPTypeString::NewLC();
   324 	            
   339 	            
   325 	//Firstly, read name from VolumeInfo
   340 	//Firstly, read name from VolumeInfo
   326 	if (0 < iVolumeInfo.iName.Length())
   341 	if (0 < iVolumeInfo.iName.Length())
   327 	    {
   342 	    {
   328 	        __FLOG_1(_L8("Using standard volume name:%S"),&iVolumeInfo.iName);
   343 	        OstTraceExt1( TRACE_NORMAL, DUP1_CMTPGETSTORAGEINFO_SETSTORAGEDESCRIPTIONL, 
       
   344 	                "Using standard volume name:%S", iVolumeInfo.iName);        
   329 	        mtpDescription->SetL(iVolumeInfo.iName);	        
   345 	        mtpDescription->SetL(iVolumeInfo.iName);	        
   330 	    }
   346 	    }
   331 	else //If name not set, set name according to type
   347 	else //If name not set, set name according to type
   332 	    {
   348 	    {
   333 	    TMTPTypeUint16 storageType(EMTPStorageUndefined);
   349 	    TMTPTypeUint16 storageType(EMTPStorageUndefined);
   334 	    iStorageInfo->GetL(CMTPTypeStorageInfo::EStorageType,storageType);
   350 	    iStorageInfo->GetL(CMTPTypeStorageInfo::EStorageType,storageType);
   335 	    __FLOG_1(_L8("Set name according to storage type: %d"),storageType.Value());
   351 	    OstTrace1( TRACE_NORMAL, DUP2_CMTPGETSTORAGEINFO_SETSTORAGEDESCRIPTIONL, 
       
   352 	            "Set name according to storage type: %d",storageType.Value() );
       
   353     
   336 	    
   354 	    
   337 	    switch (storageType.Value())
   355 	    switch (storageType.Value())
   338 	        {
   356 	        {
   339 	        case EMTPStorageFixedROM:
   357 	        case EMTPStorageFixedROM:
   340 	            if (driveNumber == EDriveC)//Phone Memory
   358 	            if (driveNumber == EDriveC)//Phone Memory
   341 	                {
   359 	                {
   342 	                __FLOG(_L8("drive c"));
   360 	                OstTrace0( TRACE_NORMAL, DUP3_CMTPGETSTORAGEINFO_SETSTORAGEDESCRIPTIONL, "drive c" );
   343 	                mtpDescription->SetL(KPhoneMemory);
   361 	                mtpDescription->SetL(KPhoneMemory);
   344 	                }
   362 	                }
   345 	            break;
   363 	            break;
   346 	        case EMTPStorageRemovableROM:
   364 	        case EMTPStorageRemovableROM:
   347 	            break;
   365 	            break;
   360 	    //eg, 'A drive'
   378 	    //eg, 'A drive'
   361 	    if(mtpDescription->NumChars() == 0)
   379 	    if(mtpDescription->NumChars() == 0)
   362 	        {
   380 	        {
   363 	        TChar driveChar;
   381 	        TChar driveChar;
   364 	        TInt err = iFramework.Fs().DriveToChar(driveNumber,driveChar);
   382 	        TInt err = iFramework.Fs().DriveToChar(driveNumber,driveChar);
   365 	        __FLOG_2(_L8("Use default name,driveNumber:%d err:%d"),driveNumber,err);
   383 	        OstTraceExt2( TRACE_NORMAL, DUP4_CMTPGETSTORAGEINFO_SETSTORAGEDESCRIPTIONL, 
       
   384 	                "Use default name,driveNumber:%d err:%d",driveNumber,err  );	        
   366 	        if (err == KErrNone)
   385 	        if (err == KErrNone)
   367 	            {
   386 	            {
   368 	            TBuf<sizeof(KDefaultName) + 1> driveName;
   387 	            TBuf<sizeof(KDefaultName) + 1> driveName;
   369 	            driveName.Append(driveChar);
   388 	            driveName.Append(driveChar);
   370 	            driveName.Append(KDefaultName);
   389 	            driveName.Append(KDefaultName);
   377 	        }
   396 	        }
   378 	    }
   397 	    }
   379 	
   398 	
   380 	iStorageInfo->SetL(CMTPTypeStorageInfo::EStorageDescription,*mtpDescription);
   399 	iStorageInfo->SetL(CMTPTypeStorageInfo::EStorageDescription,*mtpDescription);
   381 	CleanupStack::PopAndDestroy(mtpDescription);	
   400 	CleanupStack::PopAndDestroy(mtpDescription);	
   382 	
   401 
   383 	__FLOG(_L8("SetStorageDescriptionL - Exit"));
   402 	OstTraceFunctionExit0( CMTPGETSTORAGEINFO_SETSTORAGEDESCRIPTIONL_EXIT );
   384 	}
   403 	}
   385 	
   404 	
   386 /**
   405 /**
   387 Set the volume identifier of the drive in the storage info data set
   406 Set the volume identifier of the drive in the storage info data set
   388 */
   407 */