Fix for P130628-1037
[platform/framework/native/content.git] / src / FCnt_ContentManagerImpl.cpp
index a2f1827..948c622 100644 (file)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
@@ -22,6 +21,7 @@
  */
 
 #include <stdlib.h>
+#include <aul/aul.h>
 #include <FBaseSysLog.h>
 #include <FAppApp.h>
 #include <FBaseInteger.h>
@@ -120,10 +120,10 @@ OnScanCompleted(media_content_error_e error, void* user_data)
 
        pScanResult = unique_ptr< ScanResult >(static_cast< ScanResult* >(user_data));
 
-       SysTryLogCatch(NID_CNT, pScanResult != null && pScanResult->pScanPath != null, , "OnScanCompleted failed.");
+       SysTryLogCatch(NID_CNT, pScanResult != null, , "OnScanCompleted failed.");
        SysTryLogCatch(NID_CNT, pScanResult->pScanListener != null, , "Listener is null. OnScanCompleted succeeded.");
 
-       scanPath = pScanResult->pScanPath;
+       scanPath = pScanResult->scanPath;
        pListener = pScanResult->pScanListener;
        reqId = pScanResult->requestId;
 
@@ -148,6 +148,7 @@ OnContentUpdateCompleted(media_content_error_e error, int pid, media_content_db_
        SysTryLogReturn(NID_CNT, user_data != null, , "OnContentUpdateCompleted failed.");
 
        _ContentManagerImpl* pTempManagerImpl = static_cast< _ContentManagerImpl* >(user_data);
+       SysTryLogReturn(NID_CNT, pTempManagerImpl != null, , "pTempManagerImpl is null.");
 
        IContentUpdateEventListener* pListener = pTempManagerImpl->GetListener();
        SysTryLogReturn(NID_CNT, pListener != null, , "IContentUpdateEventListener is null.");
@@ -213,6 +214,7 @@ OnContentUpdateCompleted(media_content_error_e error, int pid, media_content_db_
                        SysLog(NID_CNT, "update_type is invalid.");
                        break;
                }
+               break;
        }
 
        case MEDIA_ITEM_DIRECTORY:
@@ -241,7 +243,17 @@ _ContentManagerImpl::_ContentManagerImpl(void)
 
 _ContentManagerImpl::~_ContentManagerImpl(void)
 {
-       int val = media_content_disconnect();
+       int val;
+
+       if (GetListener())
+       {
+               val = media_content_unset_db_updated_cb();
+               SysLog(NID_CNT, "media_content_unset_db_updated_cb result[%d].", val);
+
+               SetListener(null);
+       }
+
+       val = media_content_disconnect();
        SysLog(NID_CNT, "media_content_disconnect result[%d].", val);
 
        __isConnected = false;
@@ -331,18 +343,18 @@ _ContentManagerImpl::CreateContent(const ContentInfo& contentInfo)
        SysTryReturn(NID_CNT, pStr != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
                        "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
-       media_info_h __pMediaInfo = null;
-       unique_ptr<media_info_h, MediaInfoDeleter> pMediaInfo(null);
+       media_info_h tempMediaInfo = null;
+       unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
 
        // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
-       int val = media_info_insert_to_db(pStr.get(), &__pMediaInfo);
+       int val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
        SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, UuId::GetInvalidUuId(), ConvertError(val),
                        "The registration to database failed[%d].", val);
 
-       pMediaInfo.reset(&__pMediaInfo);
+       pMediaInfo.reset(tempMediaInfo);
 
        // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
-       ContentId contentId = SaveDataToDatabase(*(pMediaInfo.get()), pContentData);
+       ContentId contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
        result r = GetLastResult();
        SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
                        "[%s] The registration to database failed.", GetErrorMessage(r));
@@ -415,8 +427,8 @@ _ContentManagerImpl::CreateContent(const ByteBuffer& byteBuffer, const String& d
        ContentId contentId;
        ContentInfo::_ContentData contentData;
        ContentInfo::_ContentData* pContentData = null;
-       media_info_h __pMediaInfo = null;
-       unique_ptr<media_info_h, MediaInfoDeleter> pMediaInfo(null);
+       media_info_h tempMediaInfo = null;
+       unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
        unique_ptr<char[]> pStr(null);
 
        if (pContentInfo != null)
@@ -458,14 +470,14 @@ _ContentManagerImpl::CreateContent(const ByteBuffer& byteBuffer, const String& d
        pStr.reset(_StringConverter::CopyToCharArrayN(destinationPath));
        SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
-       val = media_info_insert_to_db(pStr.get(), &__pMediaInfo);
+       val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
        SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
                        "media_info_insert_to_db failed[%d].", val);
 
-       pMediaInfo.reset(&__pMediaInfo);
+       pMediaInfo.reset(tempMediaInfo);
 
        // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
-       contentId = SaveDataToDatabase(*(pMediaInfo.get()), pContentData);
+       contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
        r = GetLastResult();
        SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
                        "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
@@ -522,6 +534,7 @@ _ContentManagerImpl::CreateContent(const String& sourcePath, const String& desti
                        E_INVALID_ARG, "[E_INVALID_ARG] %ls is not compatible.", destinationPath.GetPointer());
 
        result r = E_SUCCESS;
+       bool isCopy = false;
 
        if (deleteSource) // move
        {
@@ -534,14 +547,16 @@ _ContentManagerImpl::CreateContent(const String& sourcePath, const String& desti
                //  Exception : E_SUCCESS, E_INVALID_ARG, E_ILLEGAL_ACCESS, E_FILE_NOT_FOUND, E_FILE_ALREADY_EXIST, E_MAX_EXCEEDED, E_STORAGE_FULL, E_IO
                r = _FileImpl::Copy(sourcePath, destinationPath, true);
                SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), r, "[%s] Copying the file failed.", GetErrorMessage(r));
+
+               isCopy = true;
        }
 
        int val = 0;
        ContentId contentId;
        ContentInfo::_ContentData contentData;
        ContentInfo::_ContentData* pContentData = null;
-       media_info_h __pMediaInfo = null;
-       unique_ptr<media_info_h, MediaInfoDeleter> pMediaInfo(null);
+       media_info_h tempMediaInfo = null;
+       unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
        unique_ptr<char[]> pStr(null);
 
        if (pContentInfo != null)
@@ -582,13 +597,13 @@ _ContentManagerImpl::CreateContent(const String& sourcePath, const String& desti
        pStr.reset(_StringConverter::CopyToCharArrayN(destinationPath));
        SysTryCatch(NID_CNT, pStr != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
-       val = media_info_insert_to_db(pStr.get(), &__pMediaInfo);
+       val = media_info_insert_to_db(pStr.get(), &tempMediaInfo);
        SysTryCatch(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, , ConvertError(val),
                        "media_info_insert_to_db failed[%d].", val);
 
-       pMediaInfo.reset(&__pMediaInfo);
+       pMediaInfo.reset(tempMediaInfo);
 
-       contentId = SaveDataToDatabase(*(pMediaInfo.get()), pContentData);
+       contentId = SaveDataToDatabase(pMediaInfo.get(), pContentData);
        r = GetLastResult();
        SysTryCatch(NID_CNT, contentId != UuId::GetInvalidUuId(), , r,
                        "[%s] SaveDataToDatabase failed.", GetErrorMessage(r));
@@ -598,9 +613,16 @@ _ContentManagerImpl::CreateContent(const String& sourcePath, const String& desti
 CATCH:
        result saveResult = GetLastResult();
 
-       // If the destination file is made by this method, it should be deleted when error occurs.
-       r = _FileImpl::Remove(destinationPath);
-       SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
+       if (isCopy)
+       {
+               r = _FileImpl::Remove(destinationPath);
+               SysLog(NID_CNT, "Remove[%s].", GetErrorMessage(r));
+       }
+       else
+       {
+               r = _FileImpl::Move(destinationPath, sourcePath);
+               SysLog(NID_CNT, "Move[%s].", GetErrorMessage(r));
+       }
 
        if (pMediaInfo != null)
        {
@@ -634,21 +656,21 @@ _ContentManagerImpl::GetContentInfoN(const ContentId& contentId) const
        unique_ptr<char[]> pStr(_StringConverter::CopyToCharArrayN(contentId.ToString()));
        SysTryReturn(NID_CNT, pStr != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
-       media_info_h __pMediaInfo = null;
-       unique_ptr<media_info_h, MediaInfoDeleter> pMediaInfo(null);
-       int val = media_info_get_media_from_db(pStr.get(), &__pMediaInfo);
+       media_info_h tempMediaInfo = null;
+       unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
+       int val = media_info_get_media_from_db(pStr.get(), &tempMediaInfo);
        SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
                        "media_info_get_media_from_db failed[%d].", val);
 
-       pMediaInfo.reset(&__pMediaInfo);
+       pMediaInfo.reset(tempMediaInfo);
 
        media_content_type_e systemType = MEDIA_CONTENT_TYPE_IMAGE;
-       val = media_info_get_media_type(*(pMediaInfo.get()), &systemType);
+       val = media_info_get_media_type(pMediaInfo.get(), &systemType);
        SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
                        "media_info_get_media_type failed[%d].", val);
 
        char* __pFilePath = null;
-       val = media_info_get_file_path(*(pMediaInfo.get()), &__pFilePath);
+       val = media_info_get_file_path(pMediaInfo.get(), &__pFilePath);
        SysTryReturn(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, null, ConvertError(val),
                        "media_info_get_file_path failed[%d].", val);
 
@@ -677,7 +699,7 @@ _ContentManagerImpl::GetContentInfoN(const ContentId& contentId) const
 
                // Set data
                // Exception : E_SUCCESS, E_INVALID_ARG, E_OUT_OF_MEMORY, E_SERVICE_BUSY, E_SYSTEM
-               r = MakeContentInfo(*(pMediaInfo.get()), pContentData, systemType, pImageContentData);
+               r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pImageContentData);
                SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
 
                return pImageContentInfo.release();
@@ -696,7 +718,7 @@ _ContentManagerImpl::GetContentInfoN(const ContentId& contentId) const
                SysTryReturn(NID_CNT, pAudioContentData != null, null, E_OUT_OF_MEMORY,
                                "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
-               r = MakeContentInfo(*(pMediaInfo.get()), pContentData, systemType, pAudioContentData);
+               r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pAudioContentData);
                SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
 
                return pAudioContentInfo.release();
@@ -715,7 +737,7 @@ _ContentManagerImpl::GetContentInfoN(const ContentId& contentId) const
                SysTryReturn(NID_CNT, pVideoContentData != null, null, E_OUT_OF_MEMORY,
                                "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
-               r = MakeContentInfo(*(pMediaInfo.get()), pContentData, systemType, pVideoContentData);
+               r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, pVideoContentData);
                SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
 
                return pVideoContentInfo.release();
@@ -730,7 +752,7 @@ _ContentManagerImpl::GetContentInfoN(const ContentId& contentId) const
                SysTryReturn(NID_CNT, pContentData != null, null, E_OUT_OF_MEMORY,
                                "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
-               r = MakeContentInfo(*(pMediaInfo.get()), pContentData, systemType, null);
+               r = MakeContentInfo(pMediaInfo.get(), pContentData, systemType, null);
                SysTryReturn(NID_CNT, !IsFailed(r), null, r, "[%s] MakeContentInfo failed.", GetErrorMessage(r));
 
                return pOtherContentInfo.release();
@@ -798,18 +820,18 @@ _ContentManagerImpl::DeleteContent(const ContentId& contentId)
 
        result r = E_SUCCESS;
        int val = 0;
-       media_info_h __pMediaInfo = null;
-       unique_ptr<media_info_h, MediaInfoDeleter> pMediaInfo(null);
+       media_info_h tempMediaInfo = null;
+       unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
 
-       val = media_info_get_media_from_db(pContentId.get(), &__pMediaInfo);
+       val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
        SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
                        "media_info_get_media_from_db failed[%d].", val);
 
-       pMediaInfo.reset(&__pMediaInfo);
+       pMediaInfo.reset(tempMediaInfo);
 
        char* __pContentPath = null;
 
-       val = media_info_get_file_path(*(pMediaInfo.get()), &__pContentPath);
+       val = media_info_get_file_path(pMediaInfo.get(), &__pContentPath);
        SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
                        "media_info_get_file_path failed[%d].", val);
 
@@ -923,11 +945,11 @@ _ContentManagerImpl::ScanDirectory(const Tizen::Base::String& directoryPath, boo
 
        reqId = requestId++;
 
-       pScanResult->pScanPath = pDirPath.get();
+       pScanResult->scanPath = directoryPath;
        pScanResult->pScanListener = pListener;
        pScanResult->requestId = reqId;
 
-       val = media_content_scan_folder(pDirPath.release(), recursive, OnScanCompleted, pScanResult.release());
+       val = media_content_scan_folder(pDirPath.get(), recursive, OnScanCompleted, pScanResult.release());
        SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val), "media_content_scan_folder failed[%d].", val);
 
        return E_SUCCESS;
@@ -947,16 +969,16 @@ _ContentManagerImpl::UpdateDataToDatabase(const ContentInfo::_ContentData* pCont
 
        SysTryReturnResult(NID_CNT, pContentData != null, E_INVALID_ARG, "pContentData is null.");
 
-       media_info_h __pMediaInfo = null;
-       unique_ptr<media_info_h, MediaInfoDeleter> pMediaInfo(null);
+       media_info_h tempMediaInfo = null;
+       unique_ptr<media_info_s, MediaInfoDeleter> pMediaInfo(null);
        unique_ptr<char[]> pContentId(_StringConverter::CopyToCharArrayN((pContentData->contentId).ToString()));
        SysTryReturnResult(NID_CNT, pContentId != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
 
-       int val = media_info_get_media_from_db(pContentId.get(), &__pMediaInfo);
+       int val = media_info_get_media_from_db(pContentId.get(), &tempMediaInfo);
        SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
                        "media_info_get_media_from_db failed[%d].", val);
 
-       pMediaInfo.reset(&__pMediaInfo);
+       pMediaInfo.reset(tempMediaInfo);
 
        result r = E_SUCCESS;
        unique_ptr<char[]> pValue(null);
@@ -966,7 +988,7 @@ _ContentManagerImpl::UpdateDataToDatabase(const ContentInfo::_ContentData* pCont
                pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pAuthor)));
                SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
 
-               val = media_info_set_author(*(pMediaInfo.get()), pValue.get());
+               val = media_info_set_author(pMediaInfo.get(), pValue.get());
                SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
                                "media_info_set_author failed[%d].", val);
        }
@@ -975,7 +997,7 @@ _ContentManagerImpl::UpdateDataToDatabase(const ContentInfo::_ContentData* pCont
                pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pCategory)));
                SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
 
-               val = media_info_set_category(*(pMediaInfo.get()), pValue.get());
+               val = media_info_set_category(pMediaInfo.get(), pValue.get());
                SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
                                "media_info_set_category failed[%d].", val);
        }
@@ -984,7 +1006,7 @@ _ContentManagerImpl::UpdateDataToDatabase(const ContentInfo::_ContentData* pCont
                pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pContentName)));
                SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
 
-               val = media_info_set_content_name(*(pMediaInfo.get()), pValue.get());
+               val = media_info_set_content_name(pMediaInfo.get(), pValue.get());
                SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
                                "media_info_set_content_name failed[%d].", val);
        }
@@ -993,7 +1015,7 @@ _ContentManagerImpl::UpdateDataToDatabase(const ContentInfo::_ContentData* pCont
                pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pDescription)));
                SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
 
-               val = media_info_set_description(*(pMediaInfo.get()), pValue.get());
+               val = media_info_set_description(pMediaInfo.get(), pValue.get());
                SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
                                "media_info_set_description failed[%d].", val);
        }
@@ -1002,7 +1024,7 @@ _ContentManagerImpl::UpdateDataToDatabase(const ContentInfo::_ContentData* pCont
                pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pKeyword)));
                SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
 
-               val = media_info_set_keyword(*(pMediaInfo.get()), pValue.get());
+               val = media_info_set_keyword(pMediaInfo.get(), pValue.get());
                SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
                                "media_info_set_keyword failed[%d].", val);
        }
@@ -1011,7 +1033,7 @@ _ContentManagerImpl::UpdateDataToDatabase(const ContentInfo::_ContentData* pCont
                pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pLocationTag)));
                SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
 
-               val = media_info_set_location_tag(*(pMediaInfo.get()), pValue.get());
+               val = media_info_set_location_tag(pMediaInfo.get(), pValue.get());
                SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
                                "media_info_set_location_tag failed[%d].", val);
        }
@@ -1020,7 +1042,7 @@ _ContentManagerImpl::UpdateDataToDatabase(const ContentInfo::_ContentData* pCont
                pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pProvider)));
                SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
 
-               val = media_info_set_provider(*(pMediaInfo.get()), pValue.get());
+               val = media_info_set_provider(pMediaInfo.get(), pValue.get());
                SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
                                "media_info_set_provider failed[%d].", val);
        }
@@ -1029,30 +1051,30 @@ _ContentManagerImpl::UpdateDataToDatabase(const ContentInfo::_ContentData* pCont
                pValue.reset(_StringConverter::CopyToCharArrayN(*(pContentData->pRating)));
                SysTryReturnResult(NID_CNT, pValue != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
 
-               val = media_info_set_age_rating(*(pMediaInfo.get()), pValue.get());
+               val = media_info_set_age_rating(pMediaInfo.get(), pValue.get());
                SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
                                "media_info_set_age_rating failed[%d].", val);
        }
        if (Double::Compare(pContentData->latitude, DEFAULT_COORDINATE) != 0 &&
                        Double::Compare(pContentData->longitude, DEFAULT_COORDINATE) != 0)
        {
-               val = media_info_set_latitude(*(pMediaInfo.get()), pContentData->latitude);
+               val = media_info_set_latitude(pMediaInfo.get(), pContentData->latitude);
                SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
                                "media_info_set_latitude failed[%d].", val);
 
-               val = media_info_set_longitude(*(pMediaInfo.get()), pContentData->longitude);
+               val = media_info_set_longitude(pMediaInfo.get(), pContentData->longitude);
                SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
                                "media_info_set_longitude failed[%d].", val);
 
                if (Double::Compare(pContentData->altitude, DEFAULT_COORDINATE) != 0)
                {
-                       val = media_info_set_altitude(*(pMediaInfo.get()), pContentData->altitude);
+                       val = media_info_set_altitude(pMediaInfo.get(), pContentData->altitude);
                        SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
                                        "media_info_set_altitude failed[%d].", val);
                }
        }
 
-       val = media_info_update_to_db(*(pMediaInfo.get()));
+       val = media_info_update_to_db(pMediaInfo.get());
        SysTryReturnResult(NID_CNT, val == MEDIA_CONTENT_ERROR_NONE, ConvertError(val),
                        "media_info_update_to_db failed[%d].", val);
 
@@ -1075,13 +1097,32 @@ _ContentManagerImpl::SaveDataToDatabase(const media_info_h pMediaInfo,
        SysTryReturn(NID_CNT, pContentData != null, UuId::GetInvalidUuId(), E_INVALID_ARG,
                        "[E_INVALID_ARG] pContentData is null.");
 
-       // Exception : E_SUCCESS, E_INVALID_ARG
+       String mimeType(L"");
        String extension = _FileImpl::GetFileExtension(pContentData->contentPath);
        result r = GetLastResult();
-       SysTryReturn(NID_CNT, !(IsFailed(r)), UuId::GetInvalidUuId(), r, "[%s] Propagating.", GetErrorMessage(r));
+       if (IsFailed(r))
+       {
+               ClearLastResult();
+
+               SysLog(NID_CNT, "[%s] Failed to perform GetFileExtension operation.", GetErrorMessage(r));
+
+               unique_ptr<char[]> pTempPath(_StringConverter::CopyToCharArrayN(pContentData->contentPath));
+               SysTryReturn(NID_CNT, pTempPath != null, UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
+                               "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
+               char tempType[255] = {0, };
+               int ret = aul_get_mime_from_file(pTempPath.get(), tempType, sizeof(tempType));
+               SysTryReturn(NID_CNT, ret == AUL_R_OK, UuId::GetInvalidUuId(), E_INVALID_ARG,
+                               "[E_INVALID_ARG] Failed to perform aul_get_mime_from_file operation.");
+
+               r = mimeType.Append(tempType);
+               SysTryReturn(NID_CNT, !IsFailed(r), UuId::GetInvalidUuId(), E_OUT_OF_MEMORY,
+                               "[E_OUT_OF_MEMORY] Failed to perform Append operation.");
+
+       }
 
        // If the content format is JPG and it has GPS data, it will be saved in database automatically.
-       if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG")
+       if (extension == L"jpg" || extension == L"jpeg" || extension == L"JPG" || extension == L"JPEG" || mimeType.Contains(L"jpeg"))
        {
                SysLog(NID_CNT, "The format of content is jpg.");
 
@@ -1092,7 +1133,6 @@ _ContentManagerImpl::SaveDataToDatabase(const media_info_h pMediaInfo,
                        pContentData->longitude = pImageMetadata->GetLongitude();
 
                        delete pImageMetadata;
-                       pImageMetadata = null;
                }
        }
 
@@ -1902,7 +1942,7 @@ _ContentManagerImpl::VerifyMediaFilePathCompatibility(const String& contentPath,
                if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0) ||
                                contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
                {
-                       SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] %ls is not supported.", contentPath.GetPointer());
+                       SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] This path is not supported.");
                        return false;
                }
        }