mirror of
https://github.com/openharmony/multimedia_medialibrary_standard.git
synced 2026-07-01 22:34:01 -04:00
!2396 media_library_event
Merge pull request !2396 from caochuan/develop
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
"eventhandler",
|
||||
"file_api",
|
||||
"hilog",
|
||||
"hisysevent",
|
||||
"hitrace",
|
||||
"huks",
|
||||
"init",
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#ifndef FRAMEWORKS_INNERKITSIMPL_MEDIA_LIBRARY_INCLUDE_MEDIA_FILE_UTILS_H_
|
||||
#define FRAMEWORKS_INNERKITSIMPL_MEDIA_LIBRARY_INCLUDE_MEDIA_FILE_UTILS_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
@@ -72,13 +73,13 @@ public:
|
||||
static std::string GetLastDentry(const std::string &path);
|
||||
static std::string GetParentPath(const std::string &path);
|
||||
static std::string GetTitleFromDisplayName(const std::string &displayName);
|
||||
static bool IsDirectory(const std::string &dirName);
|
||||
static bool IsDirectory(const std::string &dirName, std::shared_ptr<int> errCodePtr = nullptr);
|
||||
static std::string GetFirstDirName(const std::string &filePath);
|
||||
static bool MoveFile(const std::string &oldPath, const std::string &newPath);
|
||||
static bool CopyFile(const std::string &filePath, const std::string &newPath);
|
||||
static bool CopyFileUtil(const std::string &filePath, const std::string &newPath);
|
||||
static bool RenameDir(const std::string &oldPath, const std::string &newPath);
|
||||
static bool CreateDirectory(const std::string &dirPath);
|
||||
static bool CreateDirectory(const std::string &dirPath, std::shared_ptr<int> errCodePtr = nullptr);
|
||||
static int32_t CheckStringSize(const std::string &str, const size_t max);
|
||||
static int32_t CheckAlbumName(const std::string &albumName);
|
||||
static int32_t CheckDentryName(const std::string &dentryName);
|
||||
@@ -128,6 +129,9 @@ public:
|
||||
static bool IsFileTablePath(const std::string &path);
|
||||
static bool IsPhotoTablePath(const std::string &path);
|
||||
static std::string StrCreateTime(const std::string &format, int64_t time);
|
||||
|
||||
private:
|
||||
static bool Mkdir(const std::string &subStr, std::shared_ptr<int> errCodePtr);
|
||||
};
|
||||
} // namespace OHOS::Media
|
||||
|
||||
|
||||
@@ -130,10 +130,10 @@ bool AlbumAsset::GetAlbumVirtual() const
|
||||
return albumVirtual_;
|
||||
}
|
||||
|
||||
bool AlbumAsset::CreateAlbumAsset()
|
||||
bool AlbumAsset::CreateAlbumAsset(shared_ptr<int> errCodePtr)
|
||||
{
|
||||
if (!(MediaFileUtils::IsDirectory(albumPath_))) {
|
||||
return MediaFileUtils::CreateDirectory(albumPath_);
|
||||
if (!(MediaFileUtils::IsDirectory(albumPath_, errCodePtr))) {
|
||||
return MediaFileUtils::CreateDirectory(albumPath_, errCodePtr);
|
||||
} else {
|
||||
MEDIA_ERR_LOG("Cannot create album that already exists: %{private}s", albumPath_.c_str());
|
||||
return false;
|
||||
|
||||
@@ -164,7 +164,22 @@ int32_t MediaFileUtils::RemoveDirectory(const string &path)
|
||||
return nftw(path.c_str(), UnlinkCb, OPEN_FDS, FTW_DEPTH | FTW_PHYS);
|
||||
}
|
||||
|
||||
bool MediaFileUtils::CreateDirectory(const string &dirPath)
|
||||
bool MediaFileUtils::Mkdir(const string &subStr, shared_ptr<int> errCodePtr)
|
||||
{
|
||||
mode_t mask = umask(0);
|
||||
if (mkdir(subStr.c_str(), CHOWN_RWX_USR_GRP) == -1) {
|
||||
if (errCodePtr != nullptr) {
|
||||
*errCodePtr = errno;
|
||||
}
|
||||
MEDIA_ERR_LOG("Failed to create directory %{public}d", errno);
|
||||
umask(mask);
|
||||
return (errno == EEXIST) ? true : false;
|
||||
}
|
||||
umask(mask);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MediaFileUtils::CreateDirectory(const string &dirPath, shared_ptr<int> errCodePtr)
|
||||
{
|
||||
string subStr;
|
||||
string segment;
|
||||
@@ -181,14 +196,10 @@ bool MediaFileUtils::CreateDirectory(const string &dirPath)
|
||||
}
|
||||
|
||||
subStr.append(SLASH_CHAR + segment);
|
||||
if (!IsDirectory(subStr)) {
|
||||
mode_t mask = umask(0);
|
||||
if (mkdir(subStr.c_str(), CHOWN_RWX_USR_GRP) == -1) {
|
||||
MEDIA_ERR_LOG("Failed to create directory %{public}d", errno);
|
||||
umask(mask);
|
||||
return (errno == EEXIST) ? true : false;
|
||||
if (!IsDirectory(subStr, errCodePtr)) {
|
||||
if (!Mkdir(subStr, errCodePtr)) {
|
||||
return false;
|
||||
}
|
||||
umask(mask);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,13 +249,17 @@ string MediaFileUtils::GetFileName(const string &filePath)
|
||||
return fileName;
|
||||
}
|
||||
|
||||
bool MediaFileUtils::IsDirectory(const string &dirName)
|
||||
bool MediaFileUtils::IsDirectory(const string &dirName, shared_ptr<int> errCodePtr)
|
||||
{
|
||||
struct stat statInfo {};
|
||||
|
||||
if (stat(dirName.c_str(), &statInfo) == SUCCESS) {
|
||||
if (statInfo.st_mode & S_IFDIR) {
|
||||
return true;
|
||||
}
|
||||
} else if (errCodePtr != nullptr) {
|
||||
*errCodePtr = errno;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -165,6 +165,7 @@ ohos_shared_library("medialibrary_data_extension") {
|
||||
"${MEDIALIB_SERVICES_PATH}/media_backup_extension:mediabackup",
|
||||
"${MEDIALIB_UTILS_PATH}:medialibrary_common_utils",
|
||||
"${MEDIALIB_UTILS_PATH}:permission_utils",
|
||||
"${MEDIALIB_UTILS_PATH}:post_event_utils",
|
||||
]
|
||||
|
||||
include_dirs = [ "${MEDIALIB_CLOUD_SYNC_PATH}/include" ]
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@
|
||||
#ifndef OHOS_MEDIALIBRARY_ALBUM_OPERATIONS_H
|
||||
#define OHOS_MEDIALIBRARY_ALBUM_OPERATIONS_H
|
||||
|
||||
#include <memory>
|
||||
#include <securec.h>
|
||||
#include <string>
|
||||
|
||||
@@ -42,7 +43,7 @@ public:
|
||||
static int32_t DeletePhotoAlbum(NativeRdb::RdbPredicates &predicates);
|
||||
static int32_t AddPhotoAssets(const vector<DataShare::DataShareValuesBucket> &values);
|
||||
static int32_t HandlePhotoAlbum(const OperationType &opType, const NativeRdb::ValuesBucket &values,
|
||||
const DataShare::DataSharePredicates &predicates);
|
||||
const DataShare::DataSharePredicates &predicates, std::shared_ptr<int> countPtr = nullptr);
|
||||
|
||||
private:
|
||||
static std::string GetDistributedAlbumSql(const std::string &strQueryCondition, const std::string &tableName);
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ public:
|
||||
static int32_t Delete(MediaLibraryCommand &cmd);
|
||||
static int32_t Open(MediaLibraryCommand &cmd, const std::string &mode);
|
||||
static int32_t Close(MediaLibraryCommand &cmd);
|
||||
static int32_t TrashAging();
|
||||
static int32_t TrashAging(std::shared_ptr<int> countPtr = nullptr);
|
||||
|
||||
private:
|
||||
static int32_t CreateV9(MediaLibraryCommand &cmd);
|
||||
|
||||
+6
-1
@@ -16,6 +16,7 @@
|
||||
#ifndef OHOS_MEDIALIBRARY_DATA_MANAGER_H
|
||||
#define OHOS_MEDIALIBRARY_DATA_MANAGER_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <shared_mutex>
|
||||
@@ -73,7 +74,7 @@ public:
|
||||
EXPORT int32_t GenerateThumbnails();
|
||||
EXPORT void InterruptBgworker();
|
||||
EXPORT int32_t DoAging();
|
||||
EXPORT int32_t DoTrashAging();
|
||||
EXPORT int32_t DoTrashAging(std::shared_ptr<int> countPtr = nullptr);
|
||||
/**
|
||||
* @brief Revert the pending state through the package name
|
||||
* @param bundleName packageName
|
||||
@@ -97,6 +98,8 @@ public:
|
||||
std::shared_ptr<MediaDataShareExtAbility> GetOwner();
|
||||
void SetOwner(const std::shared_ptr<MediaDataShareExtAbility> &datashareExtension);
|
||||
int GetThumbnail(const std::string &uri);
|
||||
int32_t GetAgingDataSize(const int64_t &time, int &count);
|
||||
int32_t QueryNewThumbnailCount(const int64_t &time, int &count);
|
||||
|
||||
private:
|
||||
#ifdef DISTRIBUTED
|
||||
@@ -110,6 +113,8 @@ private:
|
||||
void ScanFile(const NativeRdb::ValuesBucket &values, const std::shared_ptr<NativeRdb::RdbStore> &rdbStore1);
|
||||
int32_t InitDeviceData();
|
||||
int32_t InitialiseThumbnailService(const std::shared_ptr<OHOS::AbilityRuntime::Context> &extensionContext);
|
||||
std::shared_ptr<NativeRdb::ResultSet> QuerySet(MediaLibraryCommand &cmd, const std::vector<std::string> &columns,
|
||||
const DataShare::DataSharePredicates &predicates, int &errCode);
|
||||
#ifdef DISTRIBUTED
|
||||
int32_t LcdDistributeAging();
|
||||
int32_t DistributeDeviceAging();
|
||||
|
||||
+2
@@ -39,6 +39,8 @@ const std::string MEDIA_NO_FILE = ".nofile";
|
||||
|
||||
class MediaLibraryObjectUtils {
|
||||
public:
|
||||
static int32_t BuildFileAsset(MediaLibraryCommand &cmd, FileAsset &fileAsset, NativeAlbumAsset &dirAsset,
|
||||
std::string &path, int32_t &mediaType);
|
||||
static int32_t CreateFileObj(MediaLibraryCommand &cmd);
|
||||
static int32_t CreateDirWithPath(const std::string &path);
|
||||
static int32_t CreateDirObj(MediaLibraryCommand &cmd, int64_t &rowId);
|
||||
|
||||
+2
-1
@@ -19,6 +19,7 @@
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <grp.h>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <securec.h>
|
||||
#include <unistd.h>
|
||||
@@ -44,7 +45,7 @@ public:
|
||||
const int32_t childAlbumId, MediaLibraryCommand &cmd);
|
||||
static int32_t HandleRemoveAssetOperation(const int32_t albumId, const int32_t childFileAssetId,
|
||||
MediaLibraryCommand &cmd);
|
||||
static int32_t HandleAgingOperation();
|
||||
static int32_t HandleAgingOperation(std::shared_ptr<int> countPtr = nullptr);
|
||||
static void SetInterrupt(bool interrupt);
|
||||
static bool GetInterrupt();
|
||||
|
||||
|
||||
+6
-1
@@ -36,12 +36,17 @@ private:
|
||||
static const std::vector<std::string> events_;
|
||||
bool isScreenOff_;
|
||||
bool isPowerConnected_;
|
||||
|
||||
int32_t agingCount_;
|
||||
int32_t scanCount_;
|
||||
int64_t lockTime_;
|
||||
void DoBackgroundOperation();
|
||||
void StopBackgroundOperation();
|
||||
|
||||
void DoStartMtpService();
|
||||
void RevertPendingByPackage(const std::string &bundleName);
|
||||
void WriteThumbnailStat();
|
||||
int64_t GetNowTime();
|
||||
void Init();
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
+9
-6
@@ -526,21 +526,24 @@ static inline int32_t DeletePhotoAssets(const DataSharePredicates &predicates, b
|
||||
return DoDeletePhotoAssets(rdbPredicates, isAging, false);
|
||||
}
|
||||
|
||||
int32_t AgingPhotoAssets()
|
||||
int32_t AgingPhotoAssets(shared_ptr<int> countPtr)
|
||||
{
|
||||
auto time = MediaFileUtils::UTCTimeSeconds();
|
||||
DataSharePredicates predicates;
|
||||
predicates.GreaterThan(MediaColumn::MEDIA_DATE_TRASHED, to_string(0));
|
||||
predicates.And()->LessThanOrEqualTo(MediaColumn::MEDIA_DATE_TRASHED, to_string(time - AGING_TIME));
|
||||
int32_t err = DeletePhotoAssets(predicates, true);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
int32_t ret = DeletePhotoAssets(predicates, true);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
if (countPtr != nullptr) {
|
||||
*countPtr = ret;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t MediaLibraryAlbumOperations::HandlePhotoAlbum(const OperationType &opType, const ValuesBucket &values,
|
||||
const DataSharePredicates &predicates)
|
||||
const DataSharePredicates &predicates, shared_ptr<int> countPtr)
|
||||
{
|
||||
switch (opType) {
|
||||
case OperationType::UPDATE:
|
||||
@@ -552,7 +555,7 @@ int32_t MediaLibraryAlbumOperations::HandlePhotoAlbum(const OperationType &opTyp
|
||||
case OperationType::COMPAT_ALBUM_DELETE_ASSETS:
|
||||
return CompatDeletePhotoAssets(predicates, false);
|
||||
case OperationType::AGING:
|
||||
return AgingPhotoAssets();
|
||||
return AgingPhotoAssets(countPtr);
|
||||
default:
|
||||
MEDIA_ERR_LOG("Unknown operation type: %{public}d", opType);
|
||||
return E_ERR;
|
||||
|
||||
+4
-1
@@ -481,7 +481,7 @@ int32_t MediaLibraryAudioOperations::UpdateV9(MediaLibraryCommand &cmd)
|
||||
return rowId;
|
||||
}
|
||||
|
||||
int32_t MediaLibraryAudioOperations::TrashAging()
|
||||
int32_t MediaLibraryAudioOperations::TrashAging(shared_ptr<int> countPtr)
|
||||
{
|
||||
auto time = MediaFileUtils::UTCTimeSeconds();
|
||||
RdbPredicates predicates(AudioColumn::AUDIOS_TABLE);
|
||||
@@ -491,6 +491,9 @@ int32_t MediaLibraryAudioOperations::TrashAging()
|
||||
if (deletedRows < 0) {
|
||||
return deletedRows;
|
||||
}
|
||||
if (countPtr != nullptr) {
|
||||
*countPtr = deletedRows;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
} // namespace Media
|
||||
|
||||
+72
-11
@@ -64,6 +64,7 @@
|
||||
#include "timer.h"
|
||||
#include "trash_async_worker.h"
|
||||
#include "value_object.h"
|
||||
#include "post_event_utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
@@ -787,6 +788,9 @@ shared_ptr<ResultSetBridge> MediaLibraryDataManager::Query(MediaLibraryCommand &
|
||||
if (refCnt_.load() <= 0) {
|
||||
errCode = E_FAIL;
|
||||
MEDIA_DEBUG_LOG("MediaLibraryDataManager is not initialized");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, errCode},
|
||||
{KEY_OPT_TYPE, OptType::QUERY}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -795,12 +799,18 @@ shared_ptr<ResultSetBridge> MediaLibraryDataManager::Query(MediaLibraryCommand &
|
||||
if (rdbStore_ == nullptr) {
|
||||
errCode = E_FAIL;
|
||||
MEDIA_ERR_LOG("Rdb Store is not initialized");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, errCode},
|
||||
{KEY_OPT_TYPE, OptType::QUERY}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto absResultSet = QueryRdb(cmd, columns, predicates, errCode);
|
||||
if (absResultSet == nullptr) {
|
||||
errCode = (errCode != E_OK) ? errCode : E_FAIL;
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, errCode},
|
||||
{KEY_OPT_TYPE, OptType::QUERY}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return nullptr;
|
||||
}
|
||||
return RdbUtils::ToResultSetBridge(absResultSet);
|
||||
@@ -848,15 +858,9 @@ int32_t MediaLibraryDataManager::SyncPullThumbnailKeys(const Uri &uri)
|
||||
}
|
||||
#endif
|
||||
|
||||
shared_ptr<NativeRdb::ResultSet> MediaLibraryDataManager::QueryRdb(MediaLibraryCommand &cmd,
|
||||
shared_ptr<NativeRdb::ResultSet> MediaLibraryDataManager::QuerySet(MediaLibraryCommand &cmd,
|
||||
const vector<string> &columns, const DataSharePredicates &predicates, int &errCode)
|
||||
{
|
||||
shared_lock<shared_mutex> sharedLock(mgrSharedMutex_);
|
||||
if (refCnt_.load() <= 0) {
|
||||
errCode = E_FAIL;
|
||||
MEDIA_DEBUG_LOG("MediaLibraryDataManager is not initialized");
|
||||
return nullptr;
|
||||
}
|
||||
MediaLibraryTracer tracer;
|
||||
tracer.Start("QueryRdb");
|
||||
static const map<OperationObject, string> queryConditionMap {
|
||||
@@ -875,6 +879,9 @@ shared_ptr<NativeRdb::ResultSet> MediaLibraryDataManager::QueryRdb(MediaLibraryC
|
||||
if (!MediaLibraryCommonUtils::CheckWhereClause(whereClause)) {
|
||||
errCode = E_INVALID_VALUES;
|
||||
MEDIA_ERR_LOG("illegal query whereClause input %{private}s", whereClause.c_str());
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, errCode},
|
||||
{KEY_OPT_TYPE, OptType::QUERY}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return nullptr;
|
||||
}
|
||||
tracer.Finish();
|
||||
@@ -908,6 +915,22 @@ shared_ptr<NativeRdb::ResultSet> MediaLibraryDataManager::QueryRdb(MediaLibraryC
|
||||
return queryResultSet;
|
||||
}
|
||||
|
||||
shared_ptr<NativeRdb::ResultSet> MediaLibraryDataManager::QueryRdb(MediaLibraryCommand &cmd,
|
||||
const vector<string> &columns, const DataSharePredicates &predicates, int &errCode)
|
||||
{
|
||||
shared_lock<shared_mutex> sharedLock(mgrSharedMutex_);
|
||||
if (refCnt_.load() <= 0) {
|
||||
errCode = E_FAIL;
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, errCode},
|
||||
{KEY_OPT_TYPE, OptType::QUERY}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
MEDIA_DEBUG_LOG("MediaLibraryDataManager is not initialized");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return QuerySet(cmd, columns, predicates, errCode);
|
||||
}
|
||||
|
||||
#ifdef DISTRIBUTED
|
||||
bool MediaLibraryDataManager::QuerySync(const string &networkId, const string &tableName)
|
||||
{
|
||||
@@ -1029,11 +1052,20 @@ int32_t MediaLibraryDataManager::SetCmdBundleAndDevice(MediaLibraryCommand &outC
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t MediaLibraryDataManager::DoTrashAging()
|
||||
int32_t MediaLibraryDataManager::DoTrashAging(shared_ptr<int> countPtr)
|
||||
{
|
||||
MediaLibrarySmartAlbumMapOperations::HandleAgingOperation();
|
||||
MediaLibraryAlbumOperations::HandlePhotoAlbum(OperationType::AGING, {}, {});
|
||||
MediaLibraryAudioOperations::TrashAging();
|
||||
shared_ptr<int> smartAlbumTrashPtr = make_shared<int>();
|
||||
MediaLibrarySmartAlbumMapOperations::HandleAgingOperation(smartAlbumTrashPtr);
|
||||
|
||||
shared_ptr<int> albumTrashtPtr = make_shared<int>();
|
||||
MediaLibraryAlbumOperations::HandlePhotoAlbum(OperationType::AGING, {}, {}, albumTrashtPtr);
|
||||
|
||||
shared_ptr<int> audioTrashtPtr = make_shared<int>();
|
||||
MediaLibraryAudioOperations::TrashAging(audioTrashtPtr);
|
||||
|
||||
if (countPtr != nullptr) {
|
||||
*countPtr = *smartAlbumTrashPtr + *albumTrashtPtr + *audioTrashtPtr;
|
||||
}
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1109,5 +1141,34 @@ int32_t MediaLibraryDataManager::HandleRevertPending()
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t MediaLibraryDataManager::GetAgingDataSize(const int64_t &time, int &count)
|
||||
{
|
||||
shared_lock<shared_mutex> sharedLock(mgrSharedMutex_);
|
||||
if (refCnt_.load() <= 0) {
|
||||
MEDIA_DEBUG_LOG("MediaLibraryDataManager is not initialized");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (thumbnailService_ == nullptr) {
|
||||
return E_THUMBNAIL_SERVICE_NULLPTR;
|
||||
}
|
||||
return thumbnailService_->GetAgingDataSize(time, count);
|
||||
}
|
||||
|
||||
|
||||
int32_t MediaLibraryDataManager::QueryNewThumbnailCount(const int64_t &time, int &count)
|
||||
{
|
||||
shared_lock<shared_mutex> sharedLock(mgrSharedMutex_);
|
||||
if (refCnt_.load() <= 0) {
|
||||
MEDIA_DEBUG_LOG("MediaLibraryDataManager is not initialized");
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (thumbnailService_ == nullptr) {
|
||||
return E_THUMBNAIL_SERVICE_NULLPTR;
|
||||
}
|
||||
return thumbnailService_->QueryNewThumbnailCount(time, count);
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
+62
-9
@@ -53,6 +53,7 @@
|
||||
#include "thumbnail_service.h"
|
||||
#include "value_object.h"
|
||||
#include "medialibrary_tracer.h"
|
||||
#include "post_event_utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS::NativeRdb;
|
||||
@@ -194,22 +195,26 @@ void GetRelativePathFromValues(ValuesBucket &values, string &relativePath, int32
|
||||
}
|
||||
}
|
||||
|
||||
// create
|
||||
int32_t MediaLibraryObjectUtils::CreateFileObj(MediaLibraryCommand &cmd)
|
||||
int32_t MediaLibraryObjectUtils::BuildFileAsset(MediaLibraryCommand &cmd, FileAsset &fileAsset,
|
||||
NativeAlbumAsset &dirAsset, string &path, int32_t &mediaType)
|
||||
{
|
||||
string relativePath;
|
||||
string path;
|
||||
string displayName;
|
||||
int32_t mediaType = static_cast<int32_t>(MEDIA_TYPE_FILE);
|
||||
FileAsset fileAsset;
|
||||
|
||||
ValueObject valueObject;
|
||||
ValuesBucket &values = cmd.GetValueBucket();
|
||||
if (!values.GetObject(MEDIA_DATA_DB_NAME, valueObject)) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::CREATE}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return E_HAS_DB_ERROR;
|
||||
}
|
||||
valueObject.GetString(displayName);
|
||||
fileAsset.SetDisplayName(displayName);
|
||||
if (!values.GetObject(MEDIA_DATA_DB_MEDIA_TYPE, valueObject)) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::CREATE}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return E_HAS_DB_ERROR;
|
||||
}
|
||||
valueObject.GetInt(mediaType);
|
||||
@@ -224,33 +229,70 @@ int32_t MediaLibraryObjectUtils::CreateFileObj(MediaLibraryCommand &cmd)
|
||||
|
||||
// check dir and extension
|
||||
int32_t errCode = CheckDirExtension(relativePath, displayName);
|
||||
if (errCode != E_SUCCESS) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, errCode},
|
||||
{KEY_OPT_FILE, path}, {KEY_OPT_TYPE, OptType::CREATE}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
}
|
||||
CHECK_AND_RETURN_RET_LOG(errCode == E_SUCCESS, errCode, "CreateFileAsset: check file asset failed");
|
||||
NativeAlbumAsset dirAsset = GetDirAsset(ROOT_MEDIA_DIR + relativePath);
|
||||
dirAsset = GetDirAsset(ROOT_MEDIA_DIR + relativePath);
|
||||
if (dirAsset.GetAlbumId() < 0) {
|
||||
return dirAsset.GetAlbumId();
|
||||
}
|
||||
fileAsset.SetTimePending(0);
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
// create
|
||||
int32_t MediaLibraryObjectUtils::CreateFileObj(MediaLibraryCommand &cmd)
|
||||
{
|
||||
FileAsset fileAsset;
|
||||
NativeAlbumAsset dirAsset;
|
||||
string path;
|
||||
int32_t mediaType = static_cast<int32_t>(MEDIA_TYPE_FILE);
|
||||
int errCode = BuildFileAsset(cmd, fileAsset, dirAsset, path, mediaType);
|
||||
if (errCode != E_SUCCESS) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, errCode},
|
||||
{KEY_OPT_TYPE, OptType::CREATE}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
MEDIA_ERR_LOG("Build file asset error");
|
||||
return errCode;
|
||||
}
|
||||
// delete rows in database but not in real filesystem
|
||||
errCode = DeleteInvalidRowInDb(path);
|
||||
if (errCode != E_SUCCESS) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, errCode},
|
||||
{KEY_OPT_TYPE, OptType::CREATE}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
MEDIA_ERR_LOG("Delete invalid row in database failed");
|
||||
return errCode;
|
||||
}
|
||||
|
||||
errCode = MediaFileUtils::CreateAsset(path);
|
||||
if (errCode != E_SUCCESS) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, errCode},
|
||||
{KEY_OPT_FILE, path}, {KEY_OPT_TYPE, OptType::CREATE}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
MEDIA_ERR_LOG("CreateFileAsset: create file asset failed");
|
||||
return errCode;
|
||||
}
|
||||
|
||||
if (mediaType == MEDIA_TYPE_NOFILE) {
|
||||
UpdateDateModified(MediaFileUtils::GetParentPath(MediaFileUtils::GetParentPath(fileAsset.GetPath())));
|
||||
errCode = UpdateDateModified(MediaFileUtils::GetParentPath(MediaFileUtils::GetParentPath(fileAsset.GetPath())));
|
||||
if (errCode == E_HAS_DB_ERROR) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, errCode},
|
||||
{KEY_OPT_TYPE, OptType::CREATE}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
}
|
||||
return dirAsset.GetAlbumId();
|
||||
}
|
||||
auto ret = InsertFileInDb(cmd, fileAsset, dirAsset);
|
||||
if (ret > 0) {
|
||||
UpdateDateModified(MediaFileUtils::GetParentPath(fileAsset.GetPath()));
|
||||
} else if (ret < 0) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_TYPE, OptType::CREATE}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -381,6 +423,9 @@ int32_t MediaLibraryObjectUtils::CreateDirObj(MediaLibraryCommand &cmd, int64_t
|
||||
}
|
||||
if (dirPath.empty()) {
|
||||
MEDIA_ERR_LOG("Dir path is empty!");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_INVALID_PATH},
|
||||
{KEY_OPT_TYPE, OptType::CREATE}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return E_INVALID_PATH;
|
||||
}
|
||||
|
||||
@@ -388,11 +433,19 @@ int32_t MediaLibraryObjectUtils::CreateDirObj(MediaLibraryCommand &cmd, int64_t
|
||||
MEDIA_DEBUG_LOG("dirPath %{private}s id in database is %{private}d", dirPath.c_str(), static_cast<int>(rowId));
|
||||
if ((rowId < 0) || (!MediaFileUtils::IsDirectory(dirPath))) {
|
||||
if ((!MediaFileUtils::CreateDirectory(dirPath)) && (errno != EEXIST)) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, -errno},
|
||||
{KEY_OPT_FILE, dirPath}, {KEY_OPT_TYPE, OptType::CREATE}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return E_FAIL;
|
||||
}
|
||||
return InsertDirToDbRecursively(dirPath, rowId);
|
||||
auto ret = InsertDirToDbRecursively(dirPath, rowId);
|
||||
if (ret != E_SUCCESS) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_TYPE, OptType::CREATE}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
return E_FILE_EXIST;
|
||||
}
|
||||
|
||||
|
||||
+124
-32
@@ -19,6 +19,7 @@
|
||||
#include <mutex>
|
||||
|
||||
#include "cloud_sync_helper.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "media_file_uri.h"
|
||||
#include "media_file_utils.h"
|
||||
#include "media_log.h"
|
||||
@@ -37,6 +38,7 @@
|
||||
#include "photo_map_column.h"
|
||||
#include "rdb_sql_utils.h"
|
||||
#include "result_set_utils.h"
|
||||
#include "post_event_utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS::NativeRdb;
|
||||
@@ -117,6 +119,14 @@ void MediaLibraryRdbStore::Stop()
|
||||
rdbStore_ = nullptr;
|
||||
}
|
||||
|
||||
bool g_upgradeErr = false;
|
||||
void UpdateFail(const string &errFile, const int &errLine)
|
||||
{
|
||||
g_upgradeErr = true;
|
||||
VariantMap map = {{KEY_ERR_FILE, errFile}, {KEY_ERR_LINE, errLine}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_UPGRADE_ERR, map);
|
||||
}
|
||||
|
||||
static int32_t ExecSqls(const vector<string> &sqls, RdbStore &store)
|
||||
{
|
||||
int32_t err = NativeRdb::E_OK;
|
||||
@@ -125,6 +135,7 @@ static int32_t ExecSqls(const vector<string> &sqls, RdbStore &store)
|
||||
if (err != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("Failed to exec: %{private}s", sql.c_str());
|
||||
/* try update as much as possible */
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -252,6 +263,9 @@ shared_ptr<NativeRdb::ResultSet> MediaLibraryRdbStore::Query(MediaLibraryCommand
|
||||
{
|
||||
if (rdbStore_ == nullptr) {
|
||||
MEDIA_ERR_LOG("rdbStore_ is nullptr");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::QUERY}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -275,7 +289,13 @@ shared_ptr<NativeRdb::ResultSet> MediaLibraryRdbStore::Query(MediaLibraryCommand
|
||||
* Reuse predicates-based query so that no need to modify both func
|
||||
* if later logic changes take place
|
||||
*/
|
||||
return Query(*cmd.GetAbsRdbPredicates(), columns);
|
||||
auto resultSet = Query(*cmd.GetAbsRdbPredicates(), columns);
|
||||
if (resultSet == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::QUERY}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
}
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
shared_ptr<NativeRdb::ResultSet> MediaLibraryRdbStore::Query(const AbsRdbPredicates &predicates,
|
||||
@@ -283,6 +303,9 @@ shared_ptr<NativeRdb::ResultSet> MediaLibraryRdbStore::Query(const AbsRdbPredica
|
||||
{
|
||||
if (rdbStore_ == nullptr) {
|
||||
MEDIA_ERR_LOG("rdbStore_ is nullptr");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::QUERY}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -291,7 +314,13 @@ shared_ptr<NativeRdb::ResultSet> MediaLibraryRdbStore::Query(const AbsRdbPredica
|
||||
|
||||
MediaLibraryTracer tracer;
|
||||
tracer.Start("RdbStore->QueryByPredicates");
|
||||
return rdbStore_->Query(predicates, columns);
|
||||
auto resultSet = rdbStore_->Query(predicates, columns);
|
||||
if (resultSet == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::QUERY}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
}
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
int32_t MediaLibraryRdbStore::ExecuteSql(const string &sql)
|
||||
@@ -407,12 +436,22 @@ shared_ptr<NativeRdb::ResultSet> MediaLibraryRdbStore::QuerySql(const string &sq
|
||||
{
|
||||
if (rdbStore_ == nullptr) {
|
||||
MEDIA_ERR_LOG("Pointer rdbStore_ is nullptr. Maybe it didn't init successfully.");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::QUERY}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MediaLibraryTracer tracer;
|
||||
tracer.Start("RdbStore->QuerySql");
|
||||
return rdbStore_->QuerySql(sql, selectionArgs);
|
||||
auto resultSet = rdbStore_->QuerySql(sql, selectionArgs);
|
||||
if (resultSet == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::QUERY}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
}
|
||||
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
shared_ptr<NativeRdb::RdbStore> MediaLibraryRdbStore::GetRaw() const
|
||||
@@ -644,6 +683,7 @@ static int32_t PrepareUniqueMemberTable(RdbStore &store)
|
||||
auto resultSet = store.QuerySql(queryRowSql);
|
||||
if (resultSet == nullptr || resultSet->GoToFirstRow() != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("Can not get AssetUniqueNumberTable count");
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
return NativeRdb::E_ERROR;
|
||||
}
|
||||
if (GetInt32Val("count", resultSet) != 0) {
|
||||
@@ -662,6 +702,7 @@ static int32_t PrepareUniqueMemberTable(RdbStore &store)
|
||||
for (const auto& uniqueNumberValueBucket : uniqueNumberValueBuckets) {
|
||||
if (InsertUniqueMemberTableValues(uniqueNumberValueBucket, store) != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("Prepare smartAlbum failed");
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
return NativeRdb::E_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -881,24 +922,28 @@ void VersionAddCloud(RdbStore &store)
|
||||
" ADD COLUMN " + MEDIA_DATA_DB_CLOUD_ID +" TEXT";
|
||||
int32_t result = store.ExecuteSql(alterCloudId);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("Upgrade rdb cloud_id error %{private}d", result);
|
||||
}
|
||||
const std::string alterDirty = "ALTER TABLE " + MEDIALIBRARY_TABLE +
|
||||
" ADD COLUMN " + MEDIA_DATA_DB_DIRTY +" INT DEFAULT 0";
|
||||
result = store.ExecuteSql(alterDirty);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("Upgrade rdb dirty error %{private}d", result);
|
||||
}
|
||||
const std::string alterSyncStatus = "ALTER TABLE " + MEDIALIBRARY_TABLE +
|
||||
" ADD COLUMN " + MEDIA_DATA_DB_SYNC_STATUS +" INT DEFAULT 0";
|
||||
result = store.ExecuteSql(alterSyncStatus);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("Upgrade rdb syncStatus error %{private}d", result);
|
||||
}
|
||||
const std::string alterPosition = "ALTER TABLE " + MEDIALIBRARY_TABLE +
|
||||
" ADD COLUMN " + MEDIA_DATA_DB_POSITION +" INT DEFAULT 1";
|
||||
result = store.ExecuteSql(alterPosition);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("Upgrade rdb position error %{private}d", result);
|
||||
}
|
||||
}
|
||||
@@ -910,12 +955,14 @@ void AddMetaModifiedColumn(RdbStore &store)
|
||||
MEDIA_DATA_DB_META_DATE_MODIFIED + " BIGINT DEFAULT 0";
|
||||
int32_t result = store.ExecuteSql(alterMetaModified);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("Upgrade rdb meta_date_modified error %{private}d", result);
|
||||
}
|
||||
const std::string alterSyncStatus = "ALTER TABLE " + MEDIALIBRARY_TABLE +
|
||||
" ADD COLUMN " + MEDIA_DATA_DB_SYNC_STATUS + " INT DEFAULT 0";
|
||||
result = store.ExecuteSql(alterSyncStatus);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("Upgrade rdb syncStatus error %{private}d", result);
|
||||
}
|
||||
}
|
||||
@@ -927,6 +974,7 @@ void AddTableType(RdbStore &store)
|
||||
PERMISSION_TABLE_TYPE + " INT";
|
||||
int32_t result = store.ExecuteSql(alterTableName);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("Upgrade rdb table_name error %{private}d", result);
|
||||
}
|
||||
}
|
||||
@@ -959,6 +1007,7 @@ void API10TableCreate(RdbStore &store)
|
||||
|
||||
for (size_t i = 0; i < executeSqlStrs.size(); i++) {
|
||||
if (store.ExecuteSql(executeSqlStrs[i]) != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("upgrade fail idx:%{public}zu", i);
|
||||
}
|
||||
}
|
||||
@@ -969,6 +1018,7 @@ void ModifySyncStatus(RdbStore &store)
|
||||
const std::string dropSyncStatus = "ALTER TABLE " + MEDIALIBRARY_TABLE + " DROP column syncing";
|
||||
auto result = store.ExecuteSql(dropSyncStatus);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("Upgrade rdb syncing error %{private}d", result);
|
||||
}
|
||||
|
||||
@@ -976,6 +1026,7 @@ void ModifySyncStatus(RdbStore &store)
|
||||
MEDIA_DATA_DB_SYNC_STATUS +" INT DEFAULT 0";
|
||||
result = store.ExecuteSql(addSyncStatus);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("Upgrade rdb syncStatus error %{private}d", result);
|
||||
}
|
||||
}
|
||||
@@ -985,11 +1036,13 @@ void ModifyDeleteTrigger(RdbStore &store)
|
||||
/* drop old delete trigger */
|
||||
const std::string dropDeleteTrigger = "DROP TRIGGER IF EXISTS photos_delete_trigger";
|
||||
if (store.ExecuteSql(dropDeleteTrigger) != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("upgrade fail: drop old delete trigger");
|
||||
}
|
||||
|
||||
/* create new delete trigger */
|
||||
if (store.ExecuteSql(PhotoColumn::CREATE_PHOTOS_DELETE_TRIGGER) != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("upgrade fail: create new delete trigger");
|
||||
}
|
||||
}
|
||||
@@ -1000,6 +1053,7 @@ void AddCloudVersion(RdbStore &store)
|
||||
PhotoColumn::PHOTO_CLOUD_VERSION +" BIGINT DEFAULT 0";
|
||||
auto result = store.ExecuteSql(addSyncStatus);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("Upgrade rdb cloudVersion error %{private}d", result);
|
||||
}
|
||||
}
|
||||
@@ -1029,7 +1083,11 @@ static int32_t UpdateCloudPath(RdbStore &store)
|
||||
UpdateCloudPathSql(MEDIALIBRARY_ERROR_TABLE, MEDIA_DATA_ERROR),
|
||||
UpdateCloudPathSql(PhotoColumn::PHOTOS_TABLE, MediaColumn::MEDIA_FILE_PATH),
|
||||
};
|
||||
return ExecSqls(updateCloudPath, store);
|
||||
auto result = ExecSqls(updateCloudPath, store);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void UpdateAPI10Table(RdbStore &store)
|
||||
@@ -1060,8 +1118,13 @@ void UpdateAPI10Table(RdbStore &store)
|
||||
store.ExecuteSql("DROP TABLE IF EXISTS PhotoMap");
|
||||
|
||||
API10TableCreate(store);
|
||||
PrepareSystemAlbums(store);
|
||||
PrepareUniqueMemberTable(store);
|
||||
if (PrepareSystemAlbums(store) != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
}
|
||||
|
||||
if (PrepareUniqueMemberTable(store) != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
}
|
||||
|
||||
// set scan error
|
||||
MediaScannerManager::GetInstance()->ErrorRecord();
|
||||
@@ -1088,14 +1151,17 @@ static void AddPackageNameColumnOnTables(RdbStore &store)
|
||||
|
||||
int32_t result = store.ExecuteSql(ADD_PACKAGE_NAME_ON_PHOTOS);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("Failed to update PHOTOS");
|
||||
}
|
||||
result = store.ExecuteSql(ADD_PACKAGE_NAME_ON_AUDIOS);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("Failed to update AUDIOS");
|
||||
}
|
||||
result = store.ExecuteSql(ADD_PACKAGE_NAME_ON_FILES);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("Failed to update FILES");
|
||||
}
|
||||
}
|
||||
@@ -1109,25 +1175,30 @@ void UpdateCloudAlbum(RdbStore &store)
|
||||
int32_t ret = store.ExecuteSql(addAlbumDirty);
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("upgrade fail %{public}d: add ablum dirty", ret);
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
}
|
||||
const std::string addAlbumCloudId = "ALTER TABLE " + PhotoAlbumColumns::TABLE +
|
||||
" ADD COLUMN " + PhotoAlbumColumns::ALBUM_CLOUD_ID + " TEXT;";
|
||||
ret = store.ExecuteSql(addAlbumCloudId);
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("upgrade fail %{public}d: add ablum cloud id", ret);
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
}
|
||||
/* album - add triggers */
|
||||
ret = store.ExecuteSql(PhotoAlbumColumns::CREATE_ALBUM_INSERT_TRIGGER);
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("upgrade fail %{public}d: create album insert trigger", ret);
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
}
|
||||
ret = store.ExecuteSql(PhotoAlbumColumns::CREATE_ALBUM_MDIRTY_TRIGGER);
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("upgrade fail %{public}d: create album modify trigger", ret);
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
}
|
||||
ret = store.ExecuteSql(PhotoAlbumColumns::CREATE_ALBUM_DELETE_TRIGGER);
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("upgrade fail %{public}d: create album delete trigger", ret);
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
}
|
||||
/* album map - add columns */
|
||||
const std::string addAlbumMapColumns = "ALTER TABLE " + PhotoMap::TABLE +
|
||||
@@ -1136,15 +1207,18 @@ void UpdateCloudAlbum(RdbStore &store)
|
||||
ret = store.ExecuteSql(addAlbumMapColumns);
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("upgrade fail %{public}d: add ablum columns", ret);
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
}
|
||||
/* album map - add triggers */
|
||||
ret = store.ExecuteSql(PhotoMap::CREATE_NEW_TRIGGER);
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("upgrade fail %{public}d: create album map insert trigger", ret);
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
}
|
||||
ret = store.ExecuteSql(PhotoMap::CREATE_DELETE_TRIGGER);
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("upgrade fail %{public}d: create album map delete trigger", ret);
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1154,10 +1228,12 @@ static void AddCameraShotKey(RdbStore &store)
|
||||
" ADD COLUMN " + PhotoColumn::CAMERA_SHOT_KEY + " TEXT";
|
||||
int32_t result = store.ExecuteSql(ADD_CAMERA_SHOT_KEY_ON_PHOTOS);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("Failed to update PHOTOS");
|
||||
}
|
||||
result = store.ExecuteSql(PhotoColumn::INDEX_CAMERA_SHOT_KEY);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("Failed to create CAMERA_SHOT_KEY index");
|
||||
}
|
||||
}
|
||||
@@ -1198,6 +1274,7 @@ void SetYearMonthDayData(AsyncTaskData *data)
|
||||
auto resultSet = taskData->store_->QuerySql(queryRowSql);
|
||||
if (resultSet == nullptr || resultSet->GoToFirstRow() != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("Can not get dataAdded");
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
return;
|
||||
}
|
||||
while (resultSet->GoToNextRow() == NativeRdb::E_OK) {
|
||||
@@ -1224,6 +1301,7 @@ void AddYearMonthDayColumn(RdbStore &store)
|
||||
PhotoColumn::PHOTO_DATE_YEAR + " TEXT";
|
||||
int32_t result = store.ExecuteSql(alterYear);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("Upgrade rdb year error %{private}d", result);
|
||||
}
|
||||
const std::string alterMonth =
|
||||
@@ -1231,6 +1309,7 @@ void AddYearMonthDayColumn(RdbStore &store)
|
||||
PhotoColumn::PHOTO_DATE_MONTH + " TEXT";
|
||||
result = store.ExecuteSql(alterMonth);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("Upgrade rdb month error %{private}d", result);
|
||||
}
|
||||
const std::string alterDay =
|
||||
@@ -1238,10 +1317,12 @@ void AddYearMonthDayColumn(RdbStore &store)
|
||||
PhotoColumn::PHOTO_DATE_DAY + " TEXT";
|
||||
result = store.ExecuteSql(alterDay);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("Upgrade rdb day error %{private}d", result);
|
||||
}
|
||||
shared_ptr<MediaLibraryAsyncWorker> asyncWorker = MediaLibraryAsyncWorker::GetInstance();
|
||||
if (asyncWorker == nullptr) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("asyncWorker is nullptr");
|
||||
return;
|
||||
}
|
||||
@@ -1249,6 +1330,7 @@ void AddYearMonthDayColumn(RdbStore &store)
|
||||
MediaLibraryUnistoreManager::GetInstance().GetRdbStoreRaw();
|
||||
auto *taskData = new (nothrow) AddYearTaskData(rdbStore);
|
||||
if (taskData == nullptr) {
|
||||
UpdateFail(__FILE__, __LINE__);
|
||||
MEDIA_ERR_LOG("taskData is nullptr");
|
||||
return;
|
||||
}
|
||||
@@ -1259,9 +1341,41 @@ void AddYearMonthDayColumn(RdbStore &store)
|
||||
}
|
||||
}
|
||||
|
||||
void UpgradeOtherTable(RdbStore &store, int32_t oldVersion)
|
||||
{
|
||||
if (oldVersion < VERSION_ADD_PACKAGE_NAME) {
|
||||
AddPackageNameColumnOnTables(store);
|
||||
}
|
||||
|
||||
if (oldVersion < VERSION_ADD_CLOUD_ALBUM) {
|
||||
UpdateCloudAlbum(store);
|
||||
}
|
||||
|
||||
if (oldVersion < VERSION_ADD_CAMERA_SHOT_KEY) {
|
||||
AddCameraShotKey(store);
|
||||
}
|
||||
|
||||
if (oldVersion < VERSION_REMOVE_ALBUM_COUNT_TRIGGER) {
|
||||
RemoveAlbumCountTrigger(store);
|
||||
}
|
||||
|
||||
if (oldVersion < VERSION_ADD_ALL_EXIF) {
|
||||
AddExifAndUserComment(store);
|
||||
}
|
||||
|
||||
if (oldVersion < VERSION_ADD_UPDATE_CLOUD_SYNC_TRIGGER) {
|
||||
AddUpdateCloudSyncTrigger(store);
|
||||
}
|
||||
|
||||
if (oldVersion < VERSION_ADD_YEAR_MONTH_DAY) {
|
||||
AddYearMonthDayColumn(store);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t MediaLibraryDataCallBack::OnUpgrade(RdbStore &store, int32_t oldVersion, int32_t newVersion)
|
||||
{
|
||||
MEDIA_DEBUG_LOG("OnUpgrade old:%d, new:%d", oldVersion, newVersion);
|
||||
g_upgradeErr = false;
|
||||
if (oldVersion < VERSION_ADD_CLOUD) {
|
||||
VersionAddCloud(store);
|
||||
}
|
||||
@@ -1298,34 +1412,12 @@ int32_t MediaLibraryDataCallBack::OnUpgrade(RdbStore &store, int32_t oldVersion,
|
||||
AddTableType(store);
|
||||
}
|
||||
|
||||
if (oldVersion < VERSION_ADD_PACKAGE_NAME) {
|
||||
AddPackageNameColumnOnTables(store);
|
||||
}
|
||||
UpgradeOtherTable(store, oldVersion);
|
||||
|
||||
if (oldVersion < VERSION_ADD_CLOUD_ALBUM) {
|
||||
UpdateCloudAlbum(store);
|
||||
if (!g_upgradeErr) {
|
||||
VariantMap map = {{KEY_PRE_VERSION, oldVersion}, {KEY_AFTER_VERSION, newVersion}};
|
||||
PostEventUtils::GetInstance().PostStatProcess(StatType::DB_UPGRADE_STAT, map);
|
||||
}
|
||||
|
||||
if (oldVersion < VERSION_ADD_CAMERA_SHOT_KEY) {
|
||||
AddCameraShotKey(store);
|
||||
}
|
||||
|
||||
if (oldVersion < VERSION_REMOVE_ALBUM_COUNT_TRIGGER) {
|
||||
RemoveAlbumCountTrigger(store);
|
||||
}
|
||||
|
||||
if (oldVersion < VERSION_ADD_ALL_EXIF) {
|
||||
AddExifAndUserComment(store);
|
||||
}
|
||||
|
||||
if (oldVersion < VERSION_ADD_UPDATE_CLOUD_SYNC_TRIGGER) {
|
||||
AddUpdateCloudSyncTrigger(store);
|
||||
}
|
||||
|
||||
if (oldVersion < VERSION_ADD_YEAR_MONTH_DAY) {
|
||||
AddYearMonthDayColumn(store);
|
||||
}
|
||||
|
||||
return NativeRdb::E_OK;
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -88,7 +88,7 @@ static shared_ptr<NativeRdb::ResultSet> QueryAgeingTrashFiles()
|
||||
return MediaLibraryObjectUtils::QueryWithCondition(cmd, {});
|
||||
}
|
||||
|
||||
int32_t MediaLibrarySmartAlbumMapOperations::HandleAgingOperation()
|
||||
int32_t MediaLibrarySmartAlbumMapOperations::HandleAgingOperation(shared_ptr<int> countPtr)
|
||||
{
|
||||
auto resultSet = QueryAgeingTrashFiles();
|
||||
CHECK_AND_RETURN_RET_LOG(resultSet != nullptr, E_HAS_DB_ERROR, "Failed to query ageing trash files");
|
||||
@@ -121,6 +121,9 @@ int32_t MediaLibrarySmartAlbumMapOperations::HandleAgingOperation()
|
||||
}
|
||||
CHECK_AND_RETURN_RET_LOG(errCode >= 0, errCode, "Failed to delete during trash aging: %{public}d", errCode);
|
||||
}
|
||||
if (countPtr != nullptr) {
|
||||
*countPtr = count;
|
||||
}
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
+55
-1
@@ -16,11 +16,13 @@
|
||||
|
||||
#include "medialibrary_subscriber.h"
|
||||
|
||||
#include <memory>
|
||||
#include "appexecfwk_errors.h"
|
||||
#include "bundle_info.h"
|
||||
#include "common_event_manager.h"
|
||||
#include "common_event_support.h"
|
||||
#include "want.h"
|
||||
#include "post_event_utils.h"
|
||||
|
||||
#include "medialibrary_bundle_manager.h"
|
||||
#include "medialibrary_data_manager.h"
|
||||
@@ -85,13 +87,35 @@ void MedialibrarySubscriber::OnReceiveEvent(const EventFwk::CommonEventData &eve
|
||||
}
|
||||
}
|
||||
|
||||
int64_t MedialibrarySubscriber::GetNowTime()
|
||||
{
|
||||
struct timespec t;
|
||||
constexpr int64_t SEC_TO_MSEC = 1e3;
|
||||
constexpr int64_t MSEC_TO_NSEC = 1e6;
|
||||
clock_gettime(CLOCK_REALTIME, &t);
|
||||
return t.tv_sec * SEC_TO_MSEC + t.tv_nsec / MSEC_TO_NSEC;
|
||||
}
|
||||
|
||||
void MedialibrarySubscriber::Init()
|
||||
{
|
||||
lockTime_ = GetNowTime();
|
||||
agingCount_ = 0;
|
||||
scanCount_ = 0;
|
||||
}
|
||||
|
||||
void MedialibrarySubscriber::DoBackgroundOperation()
|
||||
{
|
||||
if (isScreenOff_ && isPowerConnected_) {
|
||||
Init();
|
||||
std::shared_ptr<MediaLibraryDataManager> dataManager = MediaLibraryDataManager::GetInstance();
|
||||
if (dataManager == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto err = dataManager->GetAgingDataSize(lockTime_, agingCount_);
|
||||
if (err < 0) {
|
||||
MEDIA_ERR_LOG("GetAgingDataSize faild, err:%{public}d", err);
|
||||
}
|
||||
|
||||
auto result = dataManager->GenerateThumbnails();
|
||||
if (result != E_OK) {
|
||||
MEDIA_ERR_LOG("GenerateThumbnails faild");
|
||||
@@ -102,10 +126,15 @@ void MedialibrarySubscriber::DoBackgroundOperation()
|
||||
MEDIA_ERR_LOG("DoAging faild");
|
||||
}
|
||||
|
||||
result = dataManager->DoTrashAging();
|
||||
shared_ptr<int> trashCountPtr = make_shared<int>();
|
||||
result = dataManager->DoTrashAging(trashCountPtr);
|
||||
if (result != E_OK) {
|
||||
MEDIA_ERR_LOG("DoTrashAging faild");
|
||||
}
|
||||
|
||||
VariantMap map = {{KEY_COUNT, *trashCountPtr}};
|
||||
PostEventUtils::GetInstance().PostStatProcess(StatType::AGING_STAT, map);
|
||||
|
||||
auto watch = MediaLibraryInotify::GetInstance();
|
||||
if (watch != nullptr) {
|
||||
watch->DoAging();
|
||||
@@ -121,9 +150,34 @@ void MedialibrarySubscriber::DoBackgroundOperation()
|
||||
}
|
||||
}
|
||||
|
||||
void MedialibrarySubscriber::WriteThumbnailStat()
|
||||
{
|
||||
std::shared_ptr<MediaLibraryDataManager> dataManager = MediaLibraryDataManager::GetInstance();
|
||||
if (dataManager == nullptr) {
|
||||
return;
|
||||
}
|
||||
int agingCount = 0;
|
||||
int32_t err = dataManager->GetAgingDataSize(lockTime_, agingCount);
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("failed to get aging data size,err:%{public}d", err);
|
||||
return;
|
||||
}
|
||||
int agingSize = agingCount_ - agingCount;
|
||||
int generateSize = 0;
|
||||
err = dataManager->QueryNewThumbnailCount(lockTime_, generateSize);
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("failed to query thumbnail count,err:%{public}d", err);
|
||||
}
|
||||
|
||||
VariantMap map = {{KEY_GNUMS, generateSize}, {KEY_ANUMS, agingSize}};
|
||||
PostEventUtils::GetInstance().PostStatProcess(StatType::THUMBNAIL_STAT, map);
|
||||
}
|
||||
|
||||
|
||||
void MedialibrarySubscriber::StopBackgroundOperation()
|
||||
{
|
||||
MediaLibraryDataManager::GetInstance()->InterruptBgworker();
|
||||
WriteThumbnailStat();
|
||||
}
|
||||
|
||||
void MedialibrarySubscriber::DoStartMtpService()
|
||||
|
||||
@@ -15,6 +15,7 @@ group("test") {
|
||||
testonly = true
|
||||
|
||||
deps = [
|
||||
"unittest/media_event_test:unittest",
|
||||
"unittest/medialib_statistic_test:unittest",
|
||||
"unittest/medialibrary_audio_operations_test:unittest",
|
||||
"unittest/medialibrary_common_utils_test:unittest",
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
# Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/test.gni")
|
||||
import("//foundation/multimedia/media_library/media_library.gni")
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
deps = [
|
||||
":event_create_test",
|
||||
":event_query_test",
|
||||
":event_scan_test",
|
||||
":event_thumbnail_test",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("event_create_test") {
|
||||
module_out_path = "media_library/medialibraryextention"
|
||||
include_dirs = [
|
||||
"./include",
|
||||
"../get_self_permissions/include",
|
||||
"../medialibrary_unittest_utils/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"../get_self_permissions/src/get_self_permissions.cpp",
|
||||
"../medialibrary_unittest_utils/src/medialibrary_unittest_utils.cpp",
|
||||
"./src/event_create_test.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${MEDIALIB_INNERKITS_PATH}/media_library_helper:media_library",
|
||||
"${MEDIALIB_INNERKITS_PATH}/medialibrary_data_extension:medialibrary_data_extension",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:ability_context_native",
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:abilitykit_native",
|
||||
"ability_runtime:app_context",
|
||||
"ability_runtime:runtime",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libnativetoken",
|
||||
"access_token:libtoken_setproc",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"data_share:datashare_common",
|
||||
"data_share:datashare_provider",
|
||||
"ipc:ipc_single",
|
||||
"kv_store:distributeddata_inner",
|
||||
"napi:ace_napi",
|
||||
"relational_store:native_rdb",
|
||||
"relational_store:rdb_data_share_adapter",
|
||||
]
|
||||
|
||||
if (is_standard_system) {
|
||||
external_deps += [ "hilog:libhilog" ]
|
||||
} else {
|
||||
external_deps += [ "hilog:libhilog" ]
|
||||
}
|
||||
|
||||
resource_config_file =
|
||||
"${MEDIALIB_INNERKITS_PATH}/test/unittest/resources/ohos_test.xml"
|
||||
}
|
||||
|
||||
ohos_unittest("event_scan_test") {
|
||||
module_out_path = "media_library/medialibraryextention"
|
||||
include_dirs = [
|
||||
"./include",
|
||||
"../medialibrary_unittest_utils/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"../medialibrary_unittest_utils/src/medialibrary_unittest_utils.cpp",
|
||||
"./src/event_scan_test.cpp",
|
||||
]
|
||||
|
||||
deps = [ "${MEDIALIB_INNERKITS_PATH}/medialibrary_data_extension:medialibrary_data_extension" ]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:ability_context_native",
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:abilitykit_native",
|
||||
"ability_runtime:app_context",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"data_share:datashare_common",
|
||||
"data_share:datashare_provider",
|
||||
"device_manager:devicemanagersdk",
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_single",
|
||||
"kv_store:distributeddata_inner",
|
||||
"napi:ace_napi",
|
||||
"player_framework:media_client",
|
||||
"relational_store:native_rdb",
|
||||
"relational_store:rdb_data_share_adapter",
|
||||
]
|
||||
|
||||
resource_config_file =
|
||||
"${MEDIALIB_INNERKITS_PATH}/test/unittest/resources/ohos_test.xml"
|
||||
}
|
||||
|
||||
ohos_unittest("event_query_test") {
|
||||
module_out_path = "media_library/medialibraryextention"
|
||||
include_dirs = [
|
||||
"./include",
|
||||
"../get_self_permissions/include",
|
||||
"../medialibrary_unittest_utils/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"../get_self_permissions/src/get_self_permissions.cpp",
|
||||
"../medialibrary_unittest_utils/src/medialibrary_unittest_utils.cpp",
|
||||
"./src/event_query_test.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${MEDIALIB_INNERKITS_PATH}/media_library_helper:media_library",
|
||||
"${MEDIALIB_INNERKITS_PATH}/medialibrary_data_extension:medialibrary_data_extension",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:ability_context_native",
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:abilitykit_native",
|
||||
"ability_runtime:app_context",
|
||||
"ability_runtime:runtime",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libnativetoken",
|
||||
"access_token:libtoken_setproc",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"data_share:datashare_common",
|
||||
"data_share:datashare_provider",
|
||||
"ipc:ipc_single",
|
||||
"kv_store:distributeddata_inner",
|
||||
"napi:ace_napi",
|
||||
"relational_store:native_rdb",
|
||||
"relational_store:rdb_data_share_adapter",
|
||||
]
|
||||
|
||||
if (is_standard_system) {
|
||||
external_deps += [ "hilog:libhilog" ]
|
||||
} else {
|
||||
external_deps += [ "hilog:libhilog" ]
|
||||
}
|
||||
|
||||
resource_config_file =
|
||||
"${MEDIALIB_INNERKITS_PATH}/test/unittest/resources/ohos_test.xml"
|
||||
}
|
||||
|
||||
ohos_unittest("event_thumbnail_test") {
|
||||
module_out_path = "media_library/medialibraryextention"
|
||||
include_dirs = [ "./include" ]
|
||||
|
||||
sources = [ "./src/event_thumbnail_test.cpp" ]
|
||||
deps = [ "${MEDIALIB_INNERKITS_PATH}/medialibrary_data_extension:medialibrary_data_extension" ]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:ability_context_native",
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:abilitykit_native",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"data_share:datashare_provider",
|
||||
"hilog:libhilog",
|
||||
"kv_store:distributeddata_inner",
|
||||
"napi:ace_napi",
|
||||
"player_framework:media_client",
|
||||
"relational_store:native_rdb",
|
||||
]
|
||||
|
||||
resource_config_file =
|
||||
"${MEDIALIB_INNERKITS_PATH}/test/unittest/resources/ohos_test.xml"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef EVENT_CREATE_TEST_H
|
||||
#define EVENT_CREATE_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
class EventCreateTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef EVENT_QUERY_TEST_H
|
||||
#define EVENT_QUERY_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
class EventQueryTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef EVENT_SCAN_TEST_H
|
||||
#define EVENT_SCAN_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
class EventScanTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
#endif
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef EVENT_THUMBNAIL_TEST_H
|
||||
#define EVENT_THUMBNAIL_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
class EventThumbnailTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#define MLOG_TAG "EventCreateTest"
|
||||
|
||||
#include "event_create_test.h"
|
||||
|
||||
#include "ability_context_impl.h"
|
||||
#include "get_self_permissions.h"
|
||||
#include "medialibrary_data_manager.h"
|
||||
#include "medialibrary_object_utils.h"
|
||||
#include "medialibrary_unittest_utils.h"
|
||||
#include "medialibrary_uripermission_operations.h"
|
||||
using namespace std;
|
||||
using namespace OHOS;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
||||
void EventCreateTest::SetUpTestCase(void)
|
||||
{
|
||||
MediaLibraryUnitTestUtils::Init();
|
||||
vector<string> perms = { "ohos.permission.MEDIA_LOCATION" };
|
||||
uint64_t tokenId = 0;
|
||||
PermissionUtilsUnitTest::SetAccessTokenPermission("MediaLibraryQueryPerfUnitTest", perms, tokenId);
|
||||
ASSERT_TRUE(tokenId != 0);
|
||||
}
|
||||
|
||||
void EventCreateTest::TearDownTestCase(void) {}
|
||||
|
||||
// SetUp:Execute before each test case
|
||||
void EventCreateTest::SetUp()
|
||||
{
|
||||
MediaLibraryUnitTestUtils::CleanTestFiles();
|
||||
MediaLibraryUnitTestUtils::CleanBundlePermission();
|
||||
MediaLibraryUnitTestUtils::InitRootDirs();
|
||||
MediaLibraryUnitTestUtils::Init();
|
||||
}
|
||||
|
||||
void EventCreateTest::TearDown(void) {}
|
||||
|
||||
string ReturnUri(string UriType, string MainUri, string SubUri = "")
|
||||
{
|
||||
if (SubUri.empty()) {
|
||||
return (UriType + "/" + MainUri);
|
||||
} else {
|
||||
return (UriType + "/" + MainUri + "/" + SubUri);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t CreateFileAsset(const string &relativePath, const string &displayName, const MediaType &mediaType)
|
||||
{
|
||||
Uri createAssetUri(ReturnUri(MEDIALIBRARY_DATA_URI, MEDIA_FILEOPRN, MEDIA_FILEOPRN_CREATEASSET));
|
||||
DataShare::DataShareValuesBucket valuesBucket;
|
||||
valuesBucket.Put(MEDIA_DATA_DB_MEDIA_TYPE, mediaType);
|
||||
valuesBucket.Put(MEDIA_DATA_DB_NAME, displayName);
|
||||
valuesBucket.Put(MEDIA_DATA_DB_RELATIVE_PATH, relativePath);
|
||||
MediaLibraryCommand cmd(createAssetUri);
|
||||
return MediaLibraryDataManager::GetInstance()->Insert(cmd, valuesBucket);
|
||||
}
|
||||
|
||||
int32_t CreateAlbum(const string &albumName, const string &dirPath)
|
||||
{
|
||||
Uri createAlbumUri(ReturnUri(MEDIALIBRARY_DATA_URI, MEDIA_ALBUMOPRN, MEDIA_ALBUMOPRN_CREATEALBUM));
|
||||
DataShare::DataShareValuesBucket valuesBucket;
|
||||
valuesBucket.Put(MEDIA_DATA_DB_NAME, albumName);
|
||||
valuesBucket.Put(MEDIA_DATA_DB_FILE_PATH, dirPath);
|
||||
MediaLibraryCommand cmd(createAlbumUri);
|
||||
return MediaLibraryDataManager::GetInstance()->Insert(cmd, valuesBucket);
|
||||
}
|
||||
|
||||
int32_t DeleteAsset(const int &id)
|
||||
{
|
||||
Uri deleteAssetUri(ReturnUri(MEDIALIBRARY_DATA_URI, MEDIA_FILEOPRN, MEDIA_FILEOPRN_DELETEASSET));
|
||||
DataShare::DataSharePredicates predicates;
|
||||
predicates.EqualTo(MEDIA_DATA_DB_ID, to_string(id));
|
||||
MediaLibraryCommand cmd(deleteAssetUri, Media::OperationType::DELETE);
|
||||
return MediaLibraryDataManager::GetInstance()->Delete(cmd, predicates);
|
||||
}
|
||||
|
||||
|
||||
HWTEST_F(EventCreateTest, medialib_event_CreateFileAsset_test_001, TestSize.Level0)
|
||||
{
|
||||
MEDIA_INFO_LOG("medialib_event_CreateFileAsset_test_001::Start");
|
||||
string relativePath = "Pictures/";
|
||||
string displayName = "CreateAsset_Test_001.jpg";
|
||||
MediaType mediaType = MEDIA_TYPE_IMAGE;
|
||||
int rowId = CreateFileAsset(relativePath, displayName, mediaType);
|
||||
EXPECT_GT(rowId, 0);
|
||||
|
||||
auto retVal = CreateFileAsset(relativePath, displayName, mediaType);
|
||||
EXPECT_LT(retVal, 0);
|
||||
|
||||
retVal = DeleteAsset(rowId);
|
||||
EXPECT_EQ(retVal, 0);
|
||||
MEDIA_INFO_LOG("medialib_event_CreateFileAsset_test_001::retVal = %{public}d. End", retVal);
|
||||
}
|
||||
|
||||
HWTEST_F(EventCreateTest, medialib_event_CreateFileAsset_test_002, TestSize.Level0)
|
||||
{
|
||||
MEDIA_INFO_LOG("medialib_event_CreateFileAsset_test_002::Start");
|
||||
string relativePath = "";
|
||||
string displayName = "CreateAsset_Test_001.jpg";
|
||||
MediaType mediaType = MEDIA_TYPE_IMAGE;
|
||||
auto retVal = CreateFileAsset(relativePath, displayName, mediaType);
|
||||
EXPECT_LT(retVal, 0);
|
||||
MEDIA_INFO_LOG("medialib_event_CreateFileAsset_test_002::retVal = %{public}d. End", retVal);
|
||||
}
|
||||
|
||||
HWTEST_F(EventCreateTest, medialib_event_CreateFileAsset_test_003, TestSize.Level0)
|
||||
{
|
||||
MEDIA_INFO_LOG("medialib_event_CreateFileAsset_test_003::Start");
|
||||
string relativePath = "Pictures/";
|
||||
string displayName = "";
|
||||
MediaType mediaType = MEDIA_TYPE_IMAGE;
|
||||
auto retVal = CreateFileAsset(relativePath, displayName, mediaType);
|
||||
EXPECT_LT(retVal, 0);
|
||||
MEDIA_INFO_LOG("medialib_event_CreateFileAsset_test_003::retVal = %{public}d. End", retVal);
|
||||
}
|
||||
|
||||
HWTEST_F(EventCreateTest, medialib_event_CreateAlbum_test_001, TestSize.Level0)
|
||||
{
|
||||
MEDIA_INFO_LOG("medialib_event_CreateAlbum_test_001::Start");
|
||||
string path = "";
|
||||
string displayName = "CreateAlbum_test_001";
|
||||
auto retVal = CreateAlbum(displayName, path);
|
||||
EXPECT_LT(retVal, 0);
|
||||
MEDIA_INFO_LOG("medialib_event_CreateAlbum_test_001::retVal = %{public}d. End", retVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#define MLOG_TAG "EventQueryTest"
|
||||
|
||||
#include "event_query_test.h"
|
||||
|
||||
#include "ability_context_impl.h"
|
||||
#include "get_self_permissions.h"
|
||||
#include "medialibrary_data_manager.h"
|
||||
#include "medialibrary_object_utils.h"
|
||||
#include "medialibrary_unittest_utils.h"
|
||||
#include "medialibrary_uripermission_operations.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
shared_ptr <MediaLibraryRdbStore> rdbStorePtr = nullptr;
|
||||
void EventQueryTest::SetUpTestCase(void) {}
|
||||
void EventQueryTest::TearDownTestCase(void) {}
|
||||
|
||||
// SetUp:Execute before each test case
|
||||
void EventQueryTest::SetUp() {}
|
||||
|
||||
void EventQueryTest::TearDown(void) {}
|
||||
|
||||
string ReturnUri(string UriType, string MainUri, string SubUri = "")
|
||||
{
|
||||
if (SubUri.empty()) {
|
||||
return (UriType + "/" + MainUri);
|
||||
} else {
|
||||
return (UriType + "/" + MainUri + "/" + SubUri);
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST_F(EventQueryTest, medialib_event_Query_test_001, TestSize.Level0)
|
||||
{
|
||||
MEDIA_INFO_LOG("medialib_event_Query_test_001::Start");
|
||||
vector<string> columns;
|
||||
DataShare::DataSharePredicates predicates;
|
||||
string prefix = MEDIA_DATA_DB_MEDIA_TYPE + " <> " + to_string(MEDIA_TYPE_ALBUM);
|
||||
predicates.SetWhereClause(prefix);
|
||||
Uri queryFileUri(ReturnUri(MEDIALIBRARY_DATA_URI, MEDIA_ALBUMOPRN_QUERYALBUM));
|
||||
int errCode = 0;
|
||||
MediaLibraryCommand cmd(queryFileUri, Media::OperationType::QUERY);
|
||||
auto resultSet = MediaLibraryDataManager::GetInstance()->Query(cmd, columns, predicates, errCode);
|
||||
EXPECT_EQ(resultSet, nullptr);
|
||||
MEDIA_INFO_LOG("medialib_event_Query_test_001::end");
|
||||
}
|
||||
|
||||
HWTEST_F(EventQueryTest, medialib_event_QueryRdb_test_001, TestSize.Level0)
|
||||
{
|
||||
MEDIA_INFO_LOG("medialib_event_QueryRdb_test_001::Start");
|
||||
DataShare::DataSharePredicates predicates;
|
||||
vector<string> columns;
|
||||
Uri queryUri(MEDIALIBRARY_DATA_URI);
|
||||
MediaLibraryCommand queryCmd(queryUri, OperationType::QUERY);
|
||||
int32_t errCode = 0;
|
||||
auto resultSet = MediaLibraryDataManager::GetInstance()->QueryRdb(queryCmd, columns, predicates, errCode);
|
||||
EXPECT_EQ(resultSet, nullptr);
|
||||
MEDIA_INFO_LOG("medialib_event_QueryRdb_test_001::end");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#define MLOG_TAG "EventScanTest"
|
||||
|
||||
#include "event_scan_test.h"
|
||||
|
||||
#include "medialibrary_errno.h"
|
||||
#include "media_log.h"
|
||||
#define private public
|
||||
#include "media_scanner.h"
|
||||
#include "media_scanner_db.h"
|
||||
#undef private
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
||||
void EventScanTest::SetUpTestCase(void) {}
|
||||
|
||||
void EventScanTest::TearDownTestCase(void) {}
|
||||
|
||||
// SetUp:Execute before each test case
|
||||
void EventScanTest::SetUp() {}
|
||||
|
||||
void EventScanTest::TearDown(void) {}
|
||||
|
||||
HWTEST_F(EventScanTest, medialib_event_ScanFileInternal_test_001, TestSize.Level0)
|
||||
{
|
||||
MEDIA_INFO_LOG("medialib_event_ScanFileInternal_test_001::start");
|
||||
string path = "medialib_ScanFileInternal_test_001/.test";
|
||||
shared_ptr<IMediaScannerCallback> callback = nullptr;
|
||||
MediaScannerObj mediaScannerObj(path, callback, MediaScannerObj::FILE);
|
||||
int32_t ret = mediaScannerObj.ScanFileInternal();
|
||||
EXPECT_EQ(ret, E_FILE_HIDDEN);
|
||||
MEDIA_INFO_LOG("medialib_event_ScanFileInternal_test_001::ret = %{public}d. End", ret);
|
||||
}
|
||||
|
||||
HWTEST_F(EventScanTest, medialib_event_ScanFileInTraversal_test_001, TestSize.Level0)
|
||||
{
|
||||
string dir = "/storage/cloud/files/";
|
||||
shared_ptr<IMediaScannerCallback> callback = nullptr;
|
||||
string parent = "ScanDirInternal";
|
||||
MediaScannerObj mediaScannerObj(dir, callback, MediaScannerObj::DIRECTORY);
|
||||
int32_t ret = mediaScannerObj.ScanFileInTraversal(dir, parent, UNKNOWN_ID);
|
||||
EXPECT_NE(ret, E_FILE_HIDDEN);
|
||||
|
||||
string path = "medialib_event_ScanDirInternal_test_001/.test";
|
||||
string pathTest = "medialib_event_ScanDirInternal_test_001/test";
|
||||
ret = mediaScannerObj.ScanFileInTraversal(path, parent, UNKNOWN_ID);
|
||||
EXPECT_EQ(ret, E_FILE_HIDDEN);
|
||||
}
|
||||
|
||||
HWTEST_F(EventScanTest, medialib_event_InsertOrUpdateAlbumInfo_test_001, TestSize.Level0)
|
||||
{
|
||||
string dir = "/storage/cloud/files";
|
||||
shared_ptr<IMediaScannerCallback> callback = nullptr;
|
||||
MediaScannerObj mediaScannerObj(dir, callback, MediaScannerObj::DIRECTORY);
|
||||
int32_t parentId= -1;
|
||||
const string albumName = "InsertOrUpdateAlbumInfo";
|
||||
int32_t ret = mediaScannerObj.InsertOrUpdateAlbumInfo("", parentId, albumName);
|
||||
EXPECT_EQ(ret, UNKNOWN_ID);
|
||||
}
|
||||
|
||||
HWTEST_F(EventScanTest, medialib_event_ReadAlbums_test_001, TestSize.Level0)
|
||||
{
|
||||
MediaScannerDb mediaScannerDb;
|
||||
unordered_map<string, Metadata> albumMap_;
|
||||
string pathTest = "";
|
||||
int32_t ret = mediaScannerDb.ReadAlbums(pathTest, albumMap_);
|
||||
EXPECT_EQ(ret, E_INVALID_ARGUMENTS);
|
||||
}
|
||||
|
||||
HWTEST_F(EventScanTest, medialib_event_GetFileDBUriFromPath_test_001, TestSize.Level0)
|
||||
{
|
||||
MediaScannerDb mediaScannerDb;
|
||||
string path = "";
|
||||
string uri = mediaScannerDb.GetFileDBUriFromPath(path);
|
||||
EXPECT_EQ(uri, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#define MLOG_TAG "EventThumbTest"
|
||||
|
||||
#include "event_thumbnail_test.h"
|
||||
|
||||
#define private public
|
||||
#include "thumbnail_service.h"
|
||||
#include "thumbnail_utils.h"
|
||||
#undef private
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS;
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::NativeRdb;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
||||
class ConfigTestOpenCall : public NativeRdb::RdbOpenCallback {
|
||||
public:
|
||||
int OnCreate(NativeRdb::RdbStore &rdbStore) override;
|
||||
int OnUpgrade(NativeRdb::RdbStore &rdbStore, int oldVersion, int newVersion) override;
|
||||
static const string CREATE_TABLE_TEST;
|
||||
};
|
||||
|
||||
const string ConfigTestOpenCall::CREATE_TABLE_TEST = string("CREATE TABLE IF NOT EXISTS test ") +
|
||||
"(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, age INTEGER, salary REAL, blobType BLOB)";
|
||||
|
||||
int ConfigTestOpenCall::OnCreate(RdbStore &store)
|
||||
{
|
||||
return store.ExecuteSql(CREATE_TABLE_TEST);
|
||||
}
|
||||
|
||||
int ConfigTestOpenCall::OnUpgrade(RdbStore &store, int oldVersion, int newVersion)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
shared_ptr<NativeRdb::RdbStore> storePtr = nullptr;
|
||||
|
||||
void EventThumbnailTest::SetUpTestCase(void)
|
||||
{
|
||||
const string dbPath = "/data/test/medialibrary_utils_test.db";
|
||||
NativeRdb::RdbStoreConfig config(dbPath);
|
||||
ConfigTestOpenCall helper;
|
||||
int errCode = 0;
|
||||
shared_ptr<NativeRdb::RdbStore> store = NativeRdb::RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
storePtr = store;
|
||||
}
|
||||
|
||||
void EventThumbnailTest::TearDownTestCase(void) {}
|
||||
|
||||
// SetUp:Execute before each test case
|
||||
void EventThumbnailTest::SetUp() {}
|
||||
|
||||
void EventThumbnailTest::TearDown(void) {}
|
||||
|
||||
HWTEST_F(EventThumbnailTest, medialib_event_GetThumbnail_test_001, TestSize.Level0)
|
||||
{
|
||||
shared_ptr<ThumbnailService> serverTest = ThumbnailService::GetInstance();
|
||||
string uri = "";
|
||||
auto fd = serverTest->GetThumbnailFd(uri);
|
||||
EXPECT_LT(fd, 0);
|
||||
serverTest->ReleaseService();
|
||||
}
|
||||
|
||||
HWTEST_F(EventThumbnailTest, medialib_event_UpdateLcdInfo_test_001, TestSize.Level0)
|
||||
{
|
||||
string row = "medialib_UpdateLcdInfo_test_001";
|
||||
string table = "medialib_UpdateLcdInfo_test_001";
|
||||
ThumbRdbOpt opts = {
|
||||
.store = storePtr,
|
||||
.table = table,
|
||||
.row = row
|
||||
};
|
||||
ThumbnailData data;
|
||||
int err = 0;
|
||||
bool ret = ThumbnailUtils::UpdateLcdInfo(opts, data, err);
|
||||
EXPECT_EQ(ret, false);
|
||||
}
|
||||
|
||||
HWTEST_F(EventThumbnailTest, medialib_event_UpdateVisitTime_test_001, TestSize.Level0)
|
||||
{
|
||||
ThumbRdbOpt opts = {
|
||||
.store = storePtr,
|
||||
.networkId = "",
|
||||
};
|
||||
ThumbnailData data;
|
||||
int err = 0;
|
||||
bool ret = ThumbnailUtils::UpdateVisitTime(opts, data, err);
|
||||
EXPECT_EQ(ret, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -384,7 +384,7 @@ HWTEST_F(MediaLibraryDataManagerUnitTest, Revert_Package_Test_001, TestSize.Leve
|
||||
MEDIA_INFO_LOG("DataManager_Revert_Package_Test_001::Start");
|
||||
shared_ptr<FileAsset> fileAsset = nullptr;
|
||||
ASSERT_EQ(MediaLibraryUnitTestUtils::CreateFile("Revert_Package_Test_001.jpg", g_pictures, fileAsset), true);
|
||||
|
||||
|
||||
DataShare::DataShareValuesBucket valuesBucketUpdate;
|
||||
valuesBucketUpdate.Put(MEDIA_DATA_DB_MEDIA_TYPE, fileAsset->GetMediaType());
|
||||
valuesBucketUpdate.Put(MEDIA_DATA_DB_DATE_MODIFIED, MediaFileUtils::UTCTimeSeconds());
|
||||
@@ -400,7 +400,7 @@ HWTEST_F(MediaLibraryDataManagerUnitTest, Revert_Package_Test_001, TestSize.Leve
|
||||
MediaLibraryCommand cmd(updateAssetUri);
|
||||
auto retVal = MediaLibraryDataManager::GetInstance()->Update(cmd, valuesBucketUpdate, predicates);
|
||||
EXPECT_GT(retVal, 0);
|
||||
|
||||
|
||||
string package = fileAsset->GetOwnerPackage();
|
||||
MEDIA_INFO_LOG("DataManager_Revert_Package_Test_001 package:%{publc}s", package.c_str());
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
#include "medialibrary_errno.h"
|
||||
#include "media_log.h"
|
||||
|
||||
#include "post_event_utils.h"
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace std;
|
||||
@@ -63,6 +63,9 @@ void CloudSyncHelper::StartSync()
|
||||
}
|
||||
timerId_ = timer_.Register(bind(&CloudSyncHelper::OnTimerCallback, this),
|
||||
SYNC_INTERVAL, true);
|
||||
|
||||
VariantMap map;
|
||||
PostEventUtils::GetInstance().PostStatProcess(StatType::SYNC_STAT, map);
|
||||
}
|
||||
|
||||
void CloudSyncHelper::OnTimerCallback()
|
||||
|
||||
@@ -88,6 +88,8 @@ private:
|
||||
/* file */
|
||||
int32_t ScanFile();
|
||||
int32_t ScanFileInternal();
|
||||
int32_t BuildFileInfo(const std::string &parent, int32_t parentId);
|
||||
int32_t BuildData(const struct stat &statInfo);
|
||||
int32_t GetFileMetadata();
|
||||
int32_t GetParentDirInfo(const std::string &parent, int32_t parentId);
|
||||
int32_t GetMediaInfo();
|
||||
|
||||
@@ -69,15 +69,17 @@ public:
|
||||
int32_t RecordError(const std::string &err);
|
||||
std::set<std::string> ReadError();
|
||||
int32_t DeleteError(const std::string &err);
|
||||
|
||||
static void UpdateAlbumInfo(const std::vector<std::string> &subtypes = {},
|
||||
const std::vector<std::string> &userAlbumIds = {});
|
||||
|
||||
private:
|
||||
int32_t FillMetadata(const std::shared_ptr<NativeRdb::ResultSet> &resultSet,
|
||||
std::unique_ptr<Metadata> &ptr);
|
||||
int32_t GetFileSet(MediaLibraryCommand &cmd, const vector<string> &columns,
|
||||
std::shared_ptr<NativeRdb::ResultSet> &resultSet);
|
||||
void ExtractMetaFromColumn(const std::shared_ptr<NativeRdb::ResultSet> &resultSet,
|
||||
std::unique_ptr<Metadata> &metadata, const std::string &col);
|
||||
bool InsertData(const NativeRdb::ValuesBucket values, const std::string &tableName, int64_t &rowNum);
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -41,7 +41,6 @@ public:
|
||||
int32_t ScanFileSync(const std::string &path, const std::shared_ptr<IMediaScannerCallback> &callback,
|
||||
MediaLibraryApi api = MediaLibraryApi::API_OLD);
|
||||
int32_t ScanDir(const std::string &path, const std::shared_ptr<IMediaScannerCallback> &callback);
|
||||
|
||||
private:
|
||||
MediaScannerManager() = default;
|
||||
|
||||
|
||||
@@ -19,11 +19,13 @@
|
||||
|
||||
#include "directory_ex.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "media_log.h"
|
||||
#include "medialibrary_data_manager_utils.h"
|
||||
#include "medialibrary_errno.h"
|
||||
#include "medialibrary_notify.h"
|
||||
#include "mimetype_utils.h"
|
||||
#include "post_event_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
@@ -63,6 +65,9 @@ int32_t MediaScannerObj::ScanFile()
|
||||
int32_t ret = ScanFileInternal();
|
||||
if (ret != E_OK) {
|
||||
MEDIA_ERR_LOG("ScanFileInternal err %{public}d", ret);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
}
|
||||
|
||||
(void)InvokeCallback(ret);
|
||||
@@ -77,6 +82,9 @@ int32_t MediaScannerObj::ScanDir()
|
||||
int32_t ret = ScanDirInternal();
|
||||
if (ret != E_OK) {
|
||||
MEDIA_ERR_LOG("ScanDirInternal err %{public}d", ret);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
}
|
||||
|
||||
(void)InvokeCallback(ret);
|
||||
@@ -262,6 +270,9 @@ int32_t MediaScannerObj::GetParentDirInfo(const string &parent, int32_t parentId
|
||||
|
||||
if (parentPath.find(ROOT_MEDIA_DIR) != 0) {
|
||||
MEDIA_ERR_LOG("invaid path %{private}s, not managed by scanner", path_.c_str());
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_DATA},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return E_DATA;
|
||||
}
|
||||
|
||||
@@ -279,6 +290,9 @@ int32_t MediaScannerObj::GetParentDirInfo(const string &parent, int32_t parentId
|
||||
parentId = 0;
|
||||
} else {
|
||||
MEDIA_ERR_LOG("failed to get parent id");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_DATA},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return E_DATA;
|
||||
}
|
||||
}
|
||||
@@ -288,31 +302,30 @@ int32_t MediaScannerObj::GetParentDirInfo(const string &parent, int32_t parentId
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t MediaScannerObj::GetFileMetadata()
|
||||
int32_t MediaScannerObj::BuildData(const struct stat &statInfo)
|
||||
{
|
||||
if (path_.empty()) {
|
||||
return E_INVALID_ARGUMENTS;
|
||||
}
|
||||
|
||||
struct stat statInfo = { 0 };
|
||||
if (stat(path_.c_str(), &statInfo) != 0) {
|
||||
MEDIA_ERR_LOG("stat syscall err %{public}d", errno);
|
||||
return E_SYSCALL;
|
||||
}
|
||||
|
||||
data_ = make_unique<Metadata>();
|
||||
if (data_ == nullptr) {
|
||||
MEDIA_ERR_LOG("failed to make unique ptr for metadata");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_DATA},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return E_DATA;
|
||||
}
|
||||
|
||||
if (S_ISDIR(statInfo.st_mode)) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_INVALID_ARGUMENTS},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return E_INVALID_ARGUMENTS;
|
||||
}
|
||||
|
||||
int32_t err = mediaScannerDb_->GetFileBasicInfo(path_, data_, api_);
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("failed to get file basic info");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return err;
|
||||
}
|
||||
if (data_->GetFileDateModified() == 0) {
|
||||
@@ -347,10 +360,41 @@ int32_t MediaScannerObj::GetFileMetadata()
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t MediaScannerObj::GetFileMetadata()
|
||||
{
|
||||
if (path_.empty()) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_INVALID_ARGUMENTS},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return E_INVALID_ARGUMENTS;
|
||||
}
|
||||
struct stat statInfo = { 0 };
|
||||
if (stat(path_.c_str(), &statInfo) != 0) {
|
||||
MEDIA_ERR_LOG("stat syscall err %{public}d", errno);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_SYSCALL},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return E_SYSCALL;
|
||||
}
|
||||
|
||||
int errCode = BuildData(statInfo);
|
||||
if (errCode != E_OK) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, errCode},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return errCode;
|
||||
}
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t MediaScannerObj::ScanFileInternal()
|
||||
{
|
||||
if (ScannerUtils::IsFileHidden(path_)) {
|
||||
MEDIA_ERR_LOG("the file is hidden");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_FILE_HIDDEN},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return E_FILE_HIDDEN;
|
||||
}
|
||||
|
||||
@@ -358,12 +402,50 @@ int32_t MediaScannerObj::ScanFileInternal()
|
||||
if (err != E_OK) {
|
||||
if (err != E_SCANNED) {
|
||||
MEDIA_ERR_LOG("failed to get file metadata");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
string parent = ScannerUtils::GetParentPath(path_);
|
||||
err = GetParentDirInfo(parent, UNKNOWN_ID);
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("failed to get dir info");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = GetMediaInfo();
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("failed to get media info");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
// no return here for fs metadata being updated or inserted
|
||||
}
|
||||
|
||||
err = Commit();
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("failed to commit err %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return err;
|
||||
}
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t MediaScannerObj::BuildFileInfo(const string &parent, int32_t parentId)
|
||||
{
|
||||
int32_t err = GetParentDirInfo(parent, parentId);
|
||||
if (err != E_OK) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
MEDIA_ERR_LOG("failed to get dir info");
|
||||
return err;
|
||||
}
|
||||
@@ -372,14 +454,20 @@ int32_t MediaScannerObj::ScanFileInternal()
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("failed to get media info");
|
||||
// no return here for fs metadata being updated or inserted
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
}
|
||||
|
||||
err = Commit();
|
||||
err = AddToTransaction();
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("failed to commit err %{public}d", err);
|
||||
MEDIA_ERR_LOG("failed to add to transaction err %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
@@ -389,6 +477,9 @@ int32_t MediaScannerObj::ScanFileInTraversal(const string &path, const string &p
|
||||
|
||||
if (ScannerUtils::IsFileHidden(path_)) {
|
||||
MEDIA_ERR_LOG("the file is hidden");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_FILE_HIDDEN},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return E_FILE_HIDDEN;
|
||||
}
|
||||
|
||||
@@ -396,36 +487,34 @@ int32_t MediaScannerObj::ScanFileInTraversal(const string &path, const string &p
|
||||
if (err != E_OK) {
|
||||
if (err != E_SCANNED) {
|
||||
MEDIA_ERR_LOG("failed to get file metadata");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
if (data_->GetTimePending() != 0) {
|
||||
MEDIA_INFO_LOG("File %{private}s is pending", path.c_str());
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_IS_PENDING},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return E_IS_PENDING;
|
||||
}
|
||||
|
||||
#ifdef MEDIALIBRARY_COMPATIBILITY
|
||||
SetPhotoSubType(parent);
|
||||
#endif
|
||||
err = GetParentDirInfo(parent, parentId);
|
||||
|
||||
err = BuildFileInfo(parent, parentId);
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("failed to get dir info");
|
||||
MEDIA_ERR_LOG("failed to get other file metadata");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_FILE, path_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = GetMediaInfo();
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("failed to get media info");
|
||||
// no return here for fs metadata being updated or inserted
|
||||
}
|
||||
|
||||
err = AddToTransaction();
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("failed to add to transaction err %{public}d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
@@ -438,6 +527,9 @@ int32_t MediaScannerObj::InsertOrUpdateAlbumInfo(const string &albumPath, int32_
|
||||
|
||||
if (stat(albumPath.c_str(), &statInfo)) {
|
||||
MEDIA_ERR_LOG("stat dir error %{public}d", errno);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, -errno},
|
||||
{KEY_OPT_FILE, albumPath}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return UNKNOWN_ID;
|
||||
}
|
||||
if (SkipBucket(albumPath)) {
|
||||
@@ -550,6 +642,9 @@ int32_t MediaScannerObj::WalkFileTree(const string &path, int32_t parentId)
|
||||
if ((dirPath = opendir(path.c_str())) == nullptr) {
|
||||
MEDIA_ERR_LOG("Failed to opendir %{private}s, errno %{private}d", path.c_str(), errno);
|
||||
FREE_MEMORY_AND_SET_NULL(fName);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, -errno},
|
||||
{KEY_OPT_FILE, path}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return ERR_NOT_ACCESSIBLE;
|
||||
}
|
||||
|
||||
@@ -600,6 +695,9 @@ int32_t MediaScannerObj::ScanDirInternal()
|
||||
{
|
||||
if (ScannerUtils::IsDirHiddenRecursive(dir_)) {
|
||||
MEDIA_ERR_LOG("the dir %{private}s is hidden", dir_.c_str());
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_DIR_HIDDEN},
|
||||
{KEY_OPT_FILE, dir_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return E_DIR_HIDDEN;
|
||||
}
|
||||
|
||||
@@ -610,6 +708,9 @@ int32_t MediaScannerObj::ScanDirInternal()
|
||||
int32_t err = mediaScannerDb_->ReadAlbums(dir_, albumMap_);
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("read albums err %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -617,18 +718,27 @@ int32_t MediaScannerObj::ScanDirInternal()
|
||||
err = WalkFileTree(dir_, NO_PARENT);
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("walk file tree err %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_FILE, dir_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = CommitTransaction();
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("commit transaction err %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = CleanupDirectory();
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("clean up dir err %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_FILE, dir_}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -649,6 +759,9 @@ int32_t MediaScannerObj::Start()
|
||||
ret = mediaScannerDb_->RecordError(ROOT_MEDIA_DIR);
|
||||
if (ret != E_OK) {
|
||||
MEDIA_ERR_LOG("record err fail %{public}d", ret);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -662,6 +775,9 @@ int32_t MediaScannerObj::ScanError(bool isBoot)
|
||||
string realPath;
|
||||
if (!PathToRealPath(err, realPath)) {
|
||||
MEDIA_ERR_LOG("failed to get real path %{private}s, errno %{public}d", err.c_str(), errno);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, -errno},
|
||||
{KEY_OPT_FILE, err}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
(void)mediaScannerDb_->DeleteError(err);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "media_scanner_db.h"
|
||||
|
||||
#include "abs_rdb_predicates.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "medialibrary_asset_operations.h"
|
||||
#include "media_column.h"
|
||||
#include "media_file_utils.h"
|
||||
@@ -36,6 +37,7 @@
|
||||
#include "userfile_manager_types.h"
|
||||
#include "userfilemgr_uri.h"
|
||||
#include "values_bucket.h"
|
||||
#include "post_event_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
@@ -198,6 +200,45 @@ static void GetTableNameByPath(int32_t mediaType, string &tableName, const strin
|
||||
}
|
||||
}
|
||||
|
||||
bool MediaScannerDb::InsertData(const ValuesBucket values, const string &tableName, int64_t &rowNum)
|
||||
{
|
||||
auto rdbStore = MediaLibraryUnistoreManager::GetInstance().GetRdbStoreRaw();
|
||||
if (rdbStore == nullptr) {
|
||||
MEDIA_ERR_LOG("MediaDataAbility Insert functionality rdbStore is null");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
auto rdbStorePtr = rdbStore->GetRaw();
|
||||
if (rdbStorePtr == nullptr) {
|
||||
MEDIA_ERR_LOG("MediaDataAbility Insert functionality rdbStorePtr is null");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t result = rdbStorePtr->Insert(rowNum, tableName, values);
|
||||
if (rowNum <= 0) {
|
||||
MEDIA_ERR_LOG("MediaDataAbility Insert functionality is failed, rowNum %{public}ld", (long)rowNum);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__},
|
||||
{KEY_ERR_CODE, static_cast<int32_t>(rowNum)}, {KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (result != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("MediaDataAbility Insert functionality is failed, return %{public}d", result);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, result},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
string MediaScannerDb::InsertMetadata(const Metadata &metadata, string &tableName, MediaLibraryApi api)
|
||||
{
|
||||
MediaType mediaType = metadata.GetFileMediaType();
|
||||
@@ -228,15 +269,8 @@ string MediaScannerDb::InsertMetadata(const Metadata &metadata, string &tableNam
|
||||
SetValuesFromMetaDataApi9(metadata, values, true, tableName);
|
||||
}
|
||||
|
||||
auto rdbStore = MediaLibraryUnistoreManager::GetInstance().GetRdbStoreRaw();
|
||||
CHECK_AND_RETURN_RET(rdbStore != nullptr, "");
|
||||
auto rdbStorePtr = rdbStore->GetRaw();
|
||||
CHECK_AND_RETURN_RET(rdbStorePtr != nullptr, "");
|
||||
|
||||
int64_t rowNum = 0;
|
||||
int32_t result = rdbStorePtr->Insert(rowNum, tableName, values);
|
||||
if (rowNum <= 0 || result != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("MediaDataAbility Insert functionality is failed, return %{public}ld", (long)rowNum);
|
||||
if (!InsertData(values, tableName, rowNum)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -317,6 +351,16 @@ string MediaScannerDb::UpdateMetadata(const Metadata &metadata, string &tableNam
|
||||
int32_t result = rdbStorePtr->Update(updateCount, tableName, values, whereClause, whereArgs);
|
||||
if (result != NativeRdb::E_OK || updateCount <= 0) {
|
||||
MEDIA_ERR_LOG("Update operation failed. Result %{public}d. Updated %{public}d", result, updateCount);
|
||||
if (result != NativeRdb::E_OK) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, result},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
}
|
||||
if (updateCount <= 0) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, updateCount},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
if (mediaTypeUri.empty()) {
|
||||
@@ -344,6 +388,9 @@ bool MediaScannerDb::DeleteMetadata(const vector<string> &idList, const string &
|
||||
|
||||
auto rdbStore = MediaLibraryUnistoreManager::GetInstance().GetRdbStoreRaw();
|
||||
if (rdbStore == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
MEDIA_ERR_LOG("rdbStore is nullptr");
|
||||
return E_ERR;
|
||||
}
|
||||
@@ -418,6 +465,50 @@ static void GetQueryParamsByPath(const string &path, MediaLibraryApi api, vector
|
||||
}
|
||||
}
|
||||
|
||||
int32_t MediaScannerDb::GetFileSet(MediaLibraryCommand &cmd, const vector<string> &columns,
|
||||
shared_ptr<NativeRdb::ResultSet> &resultSet)
|
||||
{
|
||||
auto rdbStore = MediaLibraryUnistoreManager::GetInstance().GetRdbStoreRaw();
|
||||
if (rdbStore == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_RDB},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return E_RDB;
|
||||
}
|
||||
resultSet = rdbStore->Query(cmd, columns);
|
||||
if (resultSet == nullptr) {
|
||||
MEDIA_ERR_LOG("return nullptr when query rdb");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_RDB},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return E_RDB;
|
||||
}
|
||||
|
||||
int32_t rowCount = 0;
|
||||
int32_t ret = resultSet->GetRowCount(rowCount);
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("failed to get row count");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return E_RDB;
|
||||
}
|
||||
|
||||
if (rowCount == 0) {
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
ret = resultSet->GoToFirstRow();
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
MEDIA_ERR_LOG("failed to go to first row");
|
||||
return E_RDB;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get date modified, id, size and name info for a file
|
||||
*
|
||||
@@ -442,31 +533,13 @@ int32_t MediaScannerDb::GetFileBasicInfo(const string &path, unique_ptr<Metadata
|
||||
cmd.GetAbsRdbPredicates()->SetWhereClause(whereClause);
|
||||
cmd.GetAbsRdbPredicates()->SetWhereArgs(args);
|
||||
|
||||
auto rdbStore = MediaLibraryUnistoreManager::GetInstance().GetRdbStoreRaw();
|
||||
if (rdbStore == nullptr) {
|
||||
return E_RDB;
|
||||
}
|
||||
auto resultSet = rdbStore->Query(cmd, columns);
|
||||
if (resultSet == nullptr) {
|
||||
MEDIA_ERR_LOG("return nullptr when query rdb");
|
||||
return E_RDB;
|
||||
}
|
||||
|
||||
int32_t rowCount = 0;
|
||||
int32_t ret = resultSet->GetRowCount(rowCount);
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("failed to get row count");
|
||||
return E_RDB;
|
||||
}
|
||||
|
||||
if (rowCount == 0) {
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
ret = resultSet->GoToFirstRow();
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("failed to go to first row");
|
||||
return E_RDB;
|
||||
shared_ptr<NativeRdb::ResultSet> resultSet;
|
||||
int32_t ret = GetFileSet(cmd, columns, resultSet);
|
||||
if (ret != E_OK) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return ret;
|
||||
}
|
||||
ptr->SetTableName(cmd.GetTableName());
|
||||
|
||||
@@ -524,14 +597,23 @@ unordered_map<int32_t, MediaType> MediaScannerDb::GetIdsFromFilePath(const strin
|
||||
|
||||
auto rdbStore = MediaLibraryUnistoreManager::GetInstance().GetRdbStoreRaw();
|
||||
if (rdbStore == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return idMap;
|
||||
}
|
||||
auto rdbStorePtr = rdbStore->GetRaw();
|
||||
if (rdbStorePtr == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return idMap;
|
||||
}
|
||||
auto resultSet = rdbStorePtr->Query(predicates, columns);
|
||||
if (resultSet == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return idMap;
|
||||
}
|
||||
|
||||
@@ -565,9 +647,19 @@ string MediaScannerDb::GetFileDBUriFromPath(const string &path)
|
||||
MediaLibraryCommand cmd(queryUri, OperationType::QUERY);
|
||||
int errCode = 0;
|
||||
auto resultSet = MediaLibraryDataManager::GetInstance()->QueryRdb(cmd, columns, predicates, errCode);
|
||||
CHECK_AND_RETURN_RET_LOG(resultSet != nullptr, uri, "No entries found for this path");
|
||||
if ((resultSet == nullptr) || (resultSet->GoToFirstRow() != NativeRdb::E_OK)) {
|
||||
if (resultSet == nullptr) {
|
||||
MEDIA_ERR_LOG("No result found for this path");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return uri;
|
||||
}
|
||||
auto ret = resultSet->GoToFirstRow();
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("Get data error for this path");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return uri;
|
||||
}
|
||||
|
||||
@@ -594,8 +686,19 @@ int32_t MediaScannerDb::GetIdFromPath(const string &path)
|
||||
vector<string> columns = {MEDIA_DATA_DB_ID};
|
||||
int errCode = 0;
|
||||
auto resultSet = MediaLibraryDataManager::GetInstance()->QueryRdb(cmd, columns, predicates, errCode);
|
||||
if ((resultSet == nullptr) || (resultSet->GoToFirstRow() != NativeRdb::E_OK)) {
|
||||
if (resultSet == nullptr) {
|
||||
MEDIA_ERR_LOG("No data found for the given path %{private}s", path.c_str());
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return id;
|
||||
}
|
||||
auto ret = resultSet->GoToFirstRow();
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("Get data for the given path %{private}s error", path.c_str());
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -608,6 +711,9 @@ int32_t MediaScannerDb::GetIdFromPath(const string &path)
|
||||
int32_t MediaScannerDb::ReadAlbums(const string &path, unordered_map<string, Metadata> &albumMap)
|
||||
{
|
||||
if ((path + "/").find(ROOT_MEDIA_DIR) != 0) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_INVALID_ARGUMENTS},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return E_INVALID_ARGUMENTS;
|
||||
}
|
||||
|
||||
@@ -622,14 +728,23 @@ int32_t MediaScannerDb::ReadAlbums(const string &path, unordered_map<string, Met
|
||||
|
||||
auto rdbStore = MediaLibraryUnistoreManager::GetInstance().GetRdbStoreRaw();
|
||||
if (rdbStore == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return E_HAS_DB_ERROR;
|
||||
}
|
||||
auto rdbStorePtr = rdbStore->GetRaw();
|
||||
if (rdbStorePtr == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return E_HAS_DB_ERROR;
|
||||
}
|
||||
auto resultSet = rdbStorePtr->Query(predicates, columns);
|
||||
if (resultSet == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return E_HAS_DB_ERROR;
|
||||
}
|
||||
|
||||
@@ -708,6 +823,9 @@ int32_t MediaScannerDb::FillMetadata(const shared_ptr<NativeRdb::ResultSet> &res
|
||||
int32_t err = resultSet->GetAllColumnNames(columnNames);
|
||||
if (err != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("failed to get all column names");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return E_RDB;
|
||||
}
|
||||
|
||||
@@ -722,6 +840,9 @@ int32_t MediaScannerDb::RecordError(const std::string &err)
|
||||
{
|
||||
auto rdbStore = MediaLibraryUnistoreManager::GetInstance().GetRdbStoreRaw();
|
||||
if (rdbStore == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
MEDIA_ERR_LOG("rdbStore is nullptr");
|
||||
return E_ERR;
|
||||
}
|
||||
@@ -731,12 +852,18 @@ int32_t MediaScannerDb::RecordError(const std::string &err)
|
||||
int64_t outRowId = -1;
|
||||
auto rdbStorePtr = rdbStore->GetRaw();
|
||||
if (rdbStorePtr == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
MEDIA_ERR_LOG("rdbStorePtr is nullptr");
|
||||
return E_ERR;
|
||||
}
|
||||
int32_t ret = rdbStorePtr->Insert(outRowId, MEDIALIBRARY_ERROR_TABLE, valuesBucket);
|
||||
if (ret) {
|
||||
MEDIA_ERR_LOG("rdb insert err %{public}d", ret);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return E_ERR;
|
||||
}
|
||||
|
||||
@@ -748,6 +875,9 @@ std::set<std::string> MediaScannerDb::ReadError()
|
||||
auto rdbStore = MediaLibraryUnistoreManager::GetInstance().GetRdbStoreRaw();
|
||||
if (rdbStore == nullptr) {
|
||||
MEDIA_ERR_LOG("rdbStore is nullptr");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -756,17 +886,27 @@ std::set<std::string> MediaScannerDb::ReadError()
|
||||
auto rdbStorePtr = rdbStore->GetRaw();
|
||||
if (rdbStorePtr == nullptr) {
|
||||
MEDIA_ERR_LOG("rdbStorePtr is nullptr");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return {};
|
||||
}
|
||||
auto resultSet = rdbStorePtr->Query(predicates, columns);
|
||||
if (resultSet == nullptr) {
|
||||
MEDIA_ERR_LOG("rdb query return nullptr");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return {};
|
||||
}
|
||||
|
||||
int32_t rowCount = 0;
|
||||
if (resultSet->GetRowCount(rowCount) != NativeRdb::E_OK) {
|
||||
auto ret = resultSet->GetRowCount(rowCount);
|
||||
if (ret != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("failed to get row count");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -789,6 +929,9 @@ int32_t MediaScannerDb::DeleteError(const std::string &err)
|
||||
auto rdbStore = MediaLibraryUnistoreManager::GetInstance().GetRdbStoreRaw();
|
||||
if (rdbStore == nullptr) {
|
||||
MEDIA_ERR_LOG("rdbStore is nullptr");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return E_ERR;
|
||||
}
|
||||
|
||||
@@ -798,11 +941,17 @@ int32_t MediaScannerDb::DeleteError(const std::string &err)
|
||||
auto rdbStorePtr = rdbStore->GetRaw();
|
||||
if (rdbStorePtr == nullptr) {
|
||||
MEDIA_ERR_LOG("rdbStorePtr is nullptr");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return E_ERR;
|
||||
}
|
||||
int32_t ret = rdbStorePtr->Delete(outRowId, MEDIALIBRARY_ERROR_TABLE, whereClause, whereArgs);
|
||||
if (ret) {
|
||||
MEDIA_ERR_LOG("rdb delete err %{public}d", ret);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_TYPE, OptType::SCAN}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return E_ERR;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#define FRAMEWORKS_SERVICES_THUMBNAIL_SERVICE_INCLUDE_ITHUMBNAIL_HELPER_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <shared_mutex>
|
||||
|
||||
#include "ability_connect_callback_stub.h"
|
||||
|
||||
@@ -45,12 +45,14 @@ public:
|
||||
static int32_t ClearRemoteLcdFromFileTable(ThumbRdbOpt &opts);
|
||||
#endif
|
||||
static int32_t ClearLcdFromFileTable(ThumbRdbOpt &opts);
|
||||
static int32_t GetAgingDataCount(const int64_t &time, const bool &before, ThumbRdbOpt &opts, int &count);
|
||||
private:
|
||||
static int32_t GetLcdCount(ThumbRdbOpt &opts, int &outLcdCount);
|
||||
static int32_t GetAgingLcdData(ThumbRdbOpt &opts, int LcdLimit, std::vector<ThumbnailData> &outDatas);
|
||||
static int32_t GetDistributeLcdCount(ThumbRdbOpt &opts, int &outLcdCount);
|
||||
static int32_t GetAgingDistributeLcdData(ThumbRdbOpt &opts,
|
||||
int LcdLimit, std::vector<ThumbnailData> &outDatas);
|
||||
static int32_t GetLcdCountByTime(const int64_t &time, const bool &before, ThumbRdbOpt &opts, int &outLcdCount);
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -28,6 +28,7 @@ public:
|
||||
virtual ~ThumbnailGenerateHelper() = delete;
|
||||
static int32_t CreateThumbnailBatch(ThumbRdbOpt &opts);
|
||||
static int32_t CreateLcdBatch(ThumbRdbOpt &opts);
|
||||
static int32_t GetNewThumbnailCount(ThumbRdbOpt &opts, const int64_t &time, int &count);
|
||||
private:
|
||||
static int32_t GetLcdCount(ThumbRdbOpt &opts, int &outLcdCount);
|
||||
static int32_t GetNoLcdData(ThumbRdbOpt &opts, int LcdLimit, std::vector<ThumbnailData> &outDatas);
|
||||
|
||||
@@ -54,10 +54,17 @@ public:
|
||||
THUMBNAIL_API_EXPORT void Init(const std::shared_ptr<NativeRdb::RdbStore> &rdbStore,
|
||||
const std::shared_ptr<DistributedKv::SingleKvStore> &kvStore,
|
||||
const std::shared_ptr<OHOS::AbilityRuntime::Context> &context);
|
||||
THUMBNAIL_API_EXPORT int32_t GetAgingDataSize(const int64_t &time, int &count);
|
||||
THUMBNAIL_API_EXPORT int32_t QueryNewThumbnailCount(const int64_t &time, int &count);
|
||||
private:
|
||||
ThumbnailService();
|
||||
bool CheckSizeValid();
|
||||
|
||||
int32_t ParseThumbnailParam(const std::string &uri, std::string &fileId, std::string &networkId,
|
||||
std::string &tableName);
|
||||
int GetThumbFd(const std::string &path, const std::string &table, const std::string &id,
|
||||
const std::string &uri, const Size &size);
|
||||
int32_t CreateThumbnailInfo(const std::string &path, const std::string &tableName, const std::string &fileId,
|
||||
const std::string &uri, const bool &isSync);
|
||||
static std::shared_ptr<ThumbnailService> thumbnailServiceInstance_;
|
||||
static std::mutex instanceLock_;
|
||||
std::shared_ptr<DistributedKv::SingleKvStore> kvStorePtr_;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "ability_context.h"
|
||||
#include "avmetadatahelper.h"
|
||||
#include "datashare_result_set.h"
|
||||
#include "image_source.h"
|
||||
#include "rdb_helper.h"
|
||||
#include "single_kvstore.h"
|
||||
#include "thumbnail_const.h"
|
||||
@@ -71,7 +72,7 @@ public:
|
||||
// utils
|
||||
static bool ResizeImage(const std::vector<uint8_t> &data, const Size &size, std::unique_ptr<PixelMap> &pixelMap);
|
||||
static bool CompressImage(std::shared_ptr<PixelMap> &pixelMap, std::vector<uint8_t> &data,
|
||||
bool isHigh = false);
|
||||
bool isHigh = false, std::shared_ptr<std::string> pathPtr = nullptr);
|
||||
static bool CleanThumbnailInfo(ThumbRdbOpt &opts, bool withThumb, bool withLcd = false);
|
||||
static int GetPixelMapFromResult(const std::shared_ptr<DataShare::DataShareResultSet> &resultSet, const Size &size,
|
||||
std::unique_ptr<PixelMap> &outPixelMap);
|
||||
@@ -109,6 +110,9 @@ public:
|
||||
static DistributedKv::Status SaveLcdData(ThumbnailData &data, const std::string &networkId,
|
||||
const std::shared_ptr<DistributedKv::SingleKvStore> &kvStore);
|
||||
static int TrySaveFile(ThumbnailData &Data, ThumbnailType type);
|
||||
static int ToSaveFile(ThumbnailData &data, const ThumbnailType &type, const std::string &fileName,
|
||||
uint8_t *output, const int &writeSize);
|
||||
static int SaveFileCreateDir(const std::string &path, const std::string &suffix, std::string &fileName);
|
||||
static bool UpdateLcdInfo(ThumbRdbOpt &opts, ThumbnailData &data, int &err);
|
||||
static bool UpdateVisitTime(ThumbRdbOpt &opts, ThumbnailData &data, int &err);
|
||||
static bool DoUpdateRemoteThumbnail(ThumbRdbOpt &opts, ThumbnailData &data, int &err);
|
||||
@@ -124,8 +128,10 @@ public:
|
||||
std::vector<ThumbnailData> &infos, int &err);
|
||||
static bool QueryNoLcdInfos(ThumbRdbOpt &opts, int LcdLimit, std::vector<ThumbnailData> &infos, int &err);
|
||||
static bool QueryNoThumbnailInfos(ThumbRdbOpt &opts, std::vector<ThumbnailData> &infos, int &err);
|
||||
static bool QueryNewThumbnailCount(ThumbRdbOpt &opts, const int64_t &time, int &count, int &err);
|
||||
static bool QueryDeviceThumbnailRecords(ThumbRdbOpt &opts, std::vector<ThumbnailData> &infos, int &err);
|
||||
|
||||
static bool QueryLcdCountByTime(const int64_t &time, const bool &before, ThumbRdbOpt &opts, int &outLcdCount,
|
||||
int &err);
|
||||
private:
|
||||
static int32_t SetSource(std::shared_ptr<AVMetadataHelper> avMetadataHelper, const std::string &path);
|
||||
static int64_t UTCTimeMilliSeconds();
|
||||
@@ -139,6 +145,8 @@ private:
|
||||
static Size ConvertDecodeSize(const Size &sourceSize, const Size &desiredSize, const bool isThumbnail);
|
||||
static bool LoadImageFile(ThumbnailData &data, const bool isThumbnail, const Size &desiredSize);
|
||||
static bool LoadVideoFile(ThumbnailData &data, const bool isThumbnail, const Size &desiredSize);
|
||||
static bool LoadAudioFileInfo(std::shared_ptr<AVMetadataHelper> avMetadataHelper, ThumbnailData &data,
|
||||
const bool isThumbnail, const Size &desiredSize, uint32_t &errCode);
|
||||
static bool LoadAudioFile(ThumbnailData &data, const bool isThumbnail, const Size &desiredSize);
|
||||
static std::string GetUdid();
|
||||
// KV Store
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "ability_manager_client.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "media_column.h"
|
||||
#include "medialibrary_errno.h"
|
||||
#include "media_file_utils.h"
|
||||
@@ -25,6 +26,7 @@
|
||||
#include "rdb_helper.h"
|
||||
#include "single_kvstore.h"
|
||||
#include "thumbnail_const.h"
|
||||
#include "post_event_utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS::DistributedKv;
|
||||
@@ -181,6 +183,9 @@ bool IThumbnailHelper::TryLoadSource(ThumbRdbOpt &opts, ThumbnailData &data, con
|
||||
if (!ThumbnailUtils::LoadSourceImage(data, size, suffix == THUMBNAIL_THUMB_SUFFIX)) {
|
||||
if (opts.path.empty()) {
|
||||
MEDIA_ERR_LOG("LoadSourceImage faild, %{private}s", data.path.c_str());
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_THUMBNAIL_UNKNOWN},
|
||||
{KEY_OPT_FILE, data.path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
} else {
|
||||
opts.path = "";
|
||||
@@ -190,6 +195,9 @@ bool IThumbnailHelper::TryLoadSource(ThumbRdbOpt &opts, ThumbnailData &data, con
|
||||
return true;
|
||||
}
|
||||
if (!ThumbnailUtils::LoadSourceImage(data, size, suffix == THUMBNAIL_THUMB_SUFFIX)) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__},
|
||||
{KEY_ERR_CODE, E_THUMBNAIL_UNKNOWN}, {KEY_OPT_FILE, data.path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -207,14 +215,24 @@ bool IThumbnailHelper::DoCreateLcd(ThumbRdbOpt &opts, ThumbnailData &data)
|
||||
}
|
||||
|
||||
if (!TryLoadSource(opts, data, opts.screenSize, THUMBNAIL_LCD_SUFFIX)) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_THUMBNAIL_UNKNOWN},
|
||||
{KEY_OPT_FILE, opts.path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (data.source == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_THUMBNAIL_UNKNOWN},
|
||||
{KEY_OPT_FILE, opts.path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ThumbnailUtils::CompressImage(data.source, data.lcd, data.mediaType == MEDIA_TYPE_AUDIO)) {
|
||||
shared_ptr<string> pathPtr = make_shared<string>(data.path);
|
||||
if (!ThumbnailUtils::CompressImage(data.source, data.lcd, data.mediaType == MEDIA_TYPE_AUDIO, pathPtr)) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_THUMBNAIL_UNKNOWN},
|
||||
{KEY_OPT_FILE, opts.path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
MEDIA_ERR_LOG("CompressImage faild");
|
||||
return false;
|
||||
}
|
||||
@@ -222,12 +240,18 @@ bool IThumbnailHelper::DoCreateLcd(ThumbRdbOpt &opts, ThumbnailData &data)
|
||||
int err = ThumbnailUtils::TrySaveFile(data, ThumbnailType::LCD);
|
||||
if (err < 0) {
|
||||
MEDIA_ERR_LOG("SaveLcd faild %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_FILE, opts.path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
data.lcd.clear();
|
||||
if (!ThumbnailUtils::UpdateLcdInfo(opts, data, err)) {
|
||||
MEDIA_INFO_LOG("UpdateLcdInfo faild err : %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -244,6 +268,9 @@ bool IThumbnailHelper::GenThumbnail(ThumbRdbOpt &opts, ThumbnailData &data, cons
|
||||
if (isThumb) {
|
||||
size = { DEFAULT_THUMB_SIZE, DEFAULT_THUMB_SIZE };
|
||||
if (!TryLoadSource(opts, data, size, THUMBNAIL_THUMB_SUFFIX)) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_THUMBNAIL_UNKNOWN},
|
||||
{KEY_OPT_FILE, opts.path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -253,6 +280,9 @@ bool IThumbnailHelper::GenThumbnail(ThumbRdbOpt &opts, ThumbnailData &data, cons
|
||||
|
||||
if (!ThumbnailUtils::CompressImage(data.source, data.thumbnail)) {
|
||||
MEDIA_ERR_LOG("CompressImage faild id %{private}s", opts.row.c_str());
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_THUMBNAIL_UNKNOWN},
|
||||
{KEY_OPT_FILE, opts.path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@@ -267,6 +297,9 @@ bool IThumbnailHelper::GenThumbnail(ThumbRdbOpt &opts, ThumbnailData &data, cons
|
||||
int err = ThumbnailUtils::TrySaveFile(data, type);
|
||||
if (err < 0) {
|
||||
MEDIA_ERR_LOG("SaveThumbnailData faild %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_FILE, opts.path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
data.thumbnail.clear();
|
||||
@@ -282,17 +315,26 @@ bool IThumbnailHelper::DoCreateThumbnail(ThumbRdbOpt &opts, ThumbnailData &data)
|
||||
}
|
||||
|
||||
if (!GenThumbnail(opts, data, ThumbnailType::THUMB)) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_THUMBNAIL_UNKNOWN},
|
||||
{KEY_OPT_FILE, opts.path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
if (opts.table != AudioColumn::AUDIOS_TABLE) {
|
||||
if (!GenThumbnail(opts, data, ThumbnailType::MTH)) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_THUMBNAIL_UNKNOWN},
|
||||
{KEY_OPT_FILE, opts.path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
if (!GenThumbnail(opts, data, ThumbnailType::YEAR)) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_THUMBNAIL_UNKNOWN},
|
||||
{KEY_OPT_FILE, opts.path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace Media
|
||||
|
||||
@@ -89,6 +89,16 @@ int32_t ThumbnailAgingHelper::AgingLcdBatch(ThumbRdbOpt &opts)
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t ThumbnailAgingHelper::GetAgingDataCount(const int64_t &time, const bool &before, ThumbRdbOpt &opts, int &count)
|
||||
{
|
||||
int err = GetLcdCountByTime(time, before, opts, count);
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("Failed to GetAgingDataCount %{public}d", err);
|
||||
return err;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t ThumbnailAgingHelper::ClearLcdFromFileTable(ThumbRdbOpt &opts)
|
||||
{
|
||||
int lcdCount = 0;
|
||||
@@ -185,6 +195,18 @@ int32_t ThumbnailAgingHelper::GetLcdCount(ThumbRdbOpt &opts, int &outLcdCount)
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t ThumbnailAgingHelper::GetLcdCountByTime(const int64_t &time, const bool &before, ThumbRdbOpt &opts,
|
||||
int &outLcdCount)
|
||||
{
|
||||
int32_t err = E_ERR;
|
||||
if (!ThumbnailUtils::QueryLcdCountByTime(time, before, opts, outLcdCount, err)) {
|
||||
MEDIA_ERR_LOG("Failed to QueryLcdCountByTime %{public}d", err);
|
||||
return err;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
#ifdef DISTRIBUTED
|
||||
int32_t ThumbnailAgingHelper::GetDistributeLcdCount(ThumbRdbOpt &opts, int &outLcdCount)
|
||||
{
|
||||
|
||||
@@ -113,5 +113,15 @@ int32_t ThumbnailGenerateHelper::GetNoThumbnailData(ThumbRdbOpt &opts, vector<Th
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t ThumbnailGenerateHelper::GetNewThumbnailCount(ThumbRdbOpt &opts, const int64_t &time, int &count)
|
||||
{
|
||||
int32_t err = E_ERR;
|
||||
if (!ThumbnailUtils::QueryNewThumbnailCount(opts, time, count, err)) {
|
||||
MEDIA_ERR_LOG("Failed to QueryNoThumbnailInfos %{private}d", err);
|
||||
return err;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "thumbnail_service.h"
|
||||
|
||||
#include "ipc_skeleton.h"
|
||||
#include "display_manager.h"
|
||||
#include "media_column.h"
|
||||
#include "medialibrary_async_worker.h"
|
||||
@@ -28,6 +29,7 @@
|
||||
#include "thumbnail_generate_helper.h"
|
||||
#include "thumbnail_helper_factory.h"
|
||||
#include "thumbnail_uri_utils.h"
|
||||
#include "post_event_utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS::DistributedKv;
|
||||
@@ -120,6 +122,9 @@ static int32_t GetPathFromDb(const shared_ptr<NativeRdb::RdbStore> &rdbStorePtr,
|
||||
const string &table, string &path)
|
||||
{
|
||||
if (rdbStorePtr == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return E_HAS_DB_ERROR;
|
||||
}
|
||||
if (!all_of(fileId.begin(), fileId.end(), ::isdigit)) {
|
||||
@@ -130,6 +135,9 @@ static int32_t GetPathFromDb(const shared_ptr<NativeRdb::RdbStore> &rdbStorePtr,
|
||||
vector<string> selectionArgs = { fileId };
|
||||
auto resultSet = rdbStorePtr->QuerySql(querySql, selectionArgs);
|
||||
if (resultSet == nullptr || resultSet->GoToFirstRow() != NativeRdb::E_OK) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return E_HAS_DB_ERROR;
|
||||
}
|
||||
path = GetStringVal(MediaColumn::MEDIA_FILE_PATH, resultSet);
|
||||
@@ -140,25 +148,9 @@ static int32_t GetPathFromDb(const shared_ptr<NativeRdb::RdbStore> &rdbStorePtr,
|
||||
}
|
||||
#endif
|
||||
|
||||
int ThumbnailService::GetThumbnailFd(const string &uri)
|
||||
int ThumbnailService::GetThumbFd(const string &path, const string &table, const string &id, const string &uri,
|
||||
const Size &size)
|
||||
{
|
||||
if (!CheckSizeValid()) {
|
||||
return E_THUMBNAIL_INVALID_SIZE;
|
||||
}
|
||||
string id, path, table;
|
||||
Size size;
|
||||
if (!ThumbnailUriUtils::ParseThumbnailInfo(uri, id, size, path, table)) {
|
||||
return E_FAIL;
|
||||
}
|
||||
#ifdef MEDIALIBRARY_COMPATIBILITY
|
||||
if (path.empty()) {
|
||||
int32_t errCode = GetPathFromDb(rdbStorePtr_, id, table, path);
|
||||
if (errCode != E_OK) {
|
||||
MEDIA_ERR_LOG("GetPathFromDb failed, errCode = %{public}d", errCode);
|
||||
return errCode;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
ThumbRdbOpt opts = {
|
||||
.store = rdbStorePtr_,
|
||||
.path = path,
|
||||
@@ -168,6 +160,9 @@ int ThumbnailService::GetThumbnailFd(const string &uri)
|
||||
};
|
||||
shared_ptr<IThumbnailHelper> thumbnailHelper = ThumbnailHelperFactory::GetThumbnailHelper(size);
|
||||
if (thumbnailHelper == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_NO_MEMORY},
|
||||
{KEY_OPT_FILE, uri}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return E_NO_MEMORY;
|
||||
}
|
||||
if (!IsThumbnail(size.width, size.height)) {
|
||||
@@ -175,24 +170,67 @@ int ThumbnailService::GetThumbnailFd(const string &uri)
|
||||
}
|
||||
int fd = thumbnailHelper->GetThumbnailPixelMap(opts, size);
|
||||
if (fd < 0) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, fd},
|
||||
{KEY_OPT_FILE, uri}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
MEDIA_ERR_LOG("GetThumbnailPixelMap failed : %{public}d", fd);
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
int32_t ThumbnailService::CreateThumbnail(const std::string &uri, const string &path, bool isSync)
|
||||
int ThumbnailService::GetThumbnailFd(const string &uri)
|
||||
{
|
||||
if (!CheckSizeValid()) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_THUMBNAIL_INVALID_SIZE},
|
||||
{KEY_OPT_FILE, uri}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return E_THUMBNAIL_INVALID_SIZE;
|
||||
}
|
||||
string id, path, table;
|
||||
Size size;
|
||||
if (!ThumbnailUriUtils::ParseThumbnailInfo(uri, id, size, path, table)) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_FAIL},
|
||||
{KEY_OPT_FILE, uri}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return E_FAIL;
|
||||
}
|
||||
#ifdef MEDIALIBRARY_COMPATIBILITY
|
||||
if (path.empty()) {
|
||||
int32_t errCode = GetPathFromDb(rdbStorePtr_, id, table, path);
|
||||
if (errCode != E_OK) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, errCode},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
MEDIA_ERR_LOG("GetPathFromDb failed, errCode = %{public}d", errCode);
|
||||
return errCode;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return GetThumbFd(path, table, id, uri, size);
|
||||
}
|
||||
|
||||
int32_t ThumbnailService::ParseThumbnailParam(const std::string &uri, string &fileId, string &networkId,
|
||||
string &tableName)
|
||||
{
|
||||
if (!CheckSizeValid()) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_THUMBNAIL_INVALID_SIZE},
|
||||
{KEY_OPT_FILE, uri}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return E_THUMBNAIL_INVALID_SIZE;
|
||||
}
|
||||
string fileId;
|
||||
string networkId;
|
||||
string tableName;
|
||||
if (!ThumbnailUriUtils::ParseFileUri(uri, fileId, networkId, tableName)) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_ERR},
|
||||
{KEY_OPT_FILE, uri}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
MEDIA_ERR_LOG("ParseThumbnailInfo faild");
|
||||
return E_ERR;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t ThumbnailService::CreateThumbnailInfo(const string &path, const string &tableName, const string &fileId,
|
||||
const string &uri, const bool &isSync)
|
||||
{
|
||||
ThumbRdbOpt opts = {
|
||||
.store = rdbStorePtr_,
|
||||
.path = path,
|
||||
@@ -200,30 +238,67 @@ int32_t ThumbnailService::CreateThumbnail(const std::string &uri, const string &
|
||||
.row = fileId,
|
||||
.screenSize = screenSize_
|
||||
};
|
||||
Size size = { DEFAULT_THUMB_SIZE, DEFAULT_THUMB_SIZE };
|
||||
|
||||
Size size = {DEFAULT_THUMB_SIZE, DEFAULT_THUMB_SIZE};
|
||||
shared_ptr<IThumbnailHelper> thumbnailHelper = ThumbnailHelperFactory::GetThumbnailHelper(size);
|
||||
if (thumbnailHelper == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_ERR},
|
||||
{KEY_OPT_FILE, uri}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
MEDIA_ERR_LOG("thumbnailHelper nullptr");
|
||||
return E_ERR;
|
||||
}
|
||||
int32_t err = thumbnailHelper->CreateThumbnail(opts, isSync);
|
||||
if (err != E_OK) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_FILE, uri}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
MEDIA_ERR_LOG("CreateThumbnail failed : %{public}d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
size = { DEFAULT_LCD_SIZE, DEFAULT_LCD_SIZE };
|
||||
size = {DEFAULT_LCD_SIZE, DEFAULT_LCD_SIZE};
|
||||
shared_ptr<IThumbnailHelper> lcdHelper = ThumbnailHelperFactory::GetThumbnailHelper(size);
|
||||
if (lcdHelper == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_ERR},
|
||||
{KEY_OPT_FILE, uri}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
MEDIA_ERR_LOG("lcdHelper nullptr");
|
||||
return E_ERR;
|
||||
}
|
||||
err = lcdHelper->CreateThumbnail(opts, isSync);
|
||||
if (err != E_OK) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_FILE, uri}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
MEDIA_ERR_LOG("CreateLcd failed : %{public}d", err);
|
||||
return err;
|
||||
}
|
||||
return err;
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t ThumbnailService::CreateThumbnail(const std::string &uri, const string &path, bool isSync)
|
||||
{
|
||||
string fileId;
|
||||
string networkId;
|
||||
string tableName;
|
||||
|
||||
int err = ParseThumbnailParam(uri, fileId, networkId, tableName);
|
||||
if (err != E_OK) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_ERR},
|
||||
{KEY_OPT_FILE, uri}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
}
|
||||
|
||||
err = CreateThumbnailInfo(path, tableName, fileId, uri, isSync);
|
||||
if (err != E_OK) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_FILE, uri}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return err;
|
||||
}
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
void ThumbnailService::InterruptBgworker()
|
||||
@@ -264,6 +339,7 @@ int32_t ThumbnailService::GenerateThumbnails()
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("CreateThumbnailBatch failed : %{public}d", err);
|
||||
}
|
||||
|
||||
if (tableName != AudioColumn::AUDIOS_TABLE) {
|
||||
err = ThumbnailGenerateHelper::CreateLcdBatch(opts);
|
||||
if (err != E_OK) {
|
||||
@@ -340,5 +416,56 @@ void ThumbnailService::InvalidateThumbnail(const std::string &id, const std::str
|
||||
ThumbnailData thumbnailData;
|
||||
ThumbnailUtils::DeleteOriginImage(opts);
|
||||
}
|
||||
|
||||
int32_t ThumbnailService::GetAgingDataSize(const int64_t &time, int &count)
|
||||
{
|
||||
int32_t err = 0;
|
||||
vector<string> tableList;
|
||||
tableList.emplace_back(PhotoColumn::PHOTOS_TABLE);
|
||||
tableList.emplace_back(AudioColumn::AUDIOS_TABLE);
|
||||
tableList.emplace_back(MEDIALIBRARY_TABLE);
|
||||
|
||||
for (const auto &tableName : tableList) {
|
||||
ThumbRdbOpt opts = {
|
||||
.store = rdbStorePtr_,
|
||||
.kvStore = kvStorePtr_,
|
||||
.table = tableName,
|
||||
};
|
||||
int tempCount = 0;
|
||||
err = ThumbnailAgingHelper::GetAgingDataCount(time, true, opts, tempCount);
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("AgingLcdBatch failed : %{public}d", err);
|
||||
return err;
|
||||
}
|
||||
count += tempCount;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t ThumbnailService::QueryNewThumbnailCount(const int64_t &time, int32_t &count)
|
||||
{
|
||||
int32_t err = 0;
|
||||
vector<string> tableList;
|
||||
tableList.emplace_back(PhotoColumn::PHOTOS_TABLE);
|
||||
tableList.emplace_back(AudioColumn::AUDIOS_TABLE);
|
||||
tableList.emplace_back(MEDIALIBRARY_TABLE);
|
||||
|
||||
for (const auto &tableName : tableList) {
|
||||
ThumbRdbOpt opts = {
|
||||
.store = rdbStorePtr_,
|
||||
.kvStore = kvStorePtr_,
|
||||
.table = tableName
|
||||
};
|
||||
int32_t tempCount = 0;
|
||||
err = ThumbnailGenerateHelper::GetNewThumbnailCount(opts, time, tempCount);
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("CreateThumbnailBatch failed : %{public}d", err);
|
||||
return err;
|
||||
}
|
||||
count += tempCount;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "distributed_kv_data_manager.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "image_packer.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "medialibrary_common_utils.h"
|
||||
#include "medialibrary_errno.h"
|
||||
#include "medialibrary_sync_operation.h"
|
||||
@@ -42,6 +43,7 @@
|
||||
#include "rdb_predicates.h"
|
||||
#include "thumbnail_const.h"
|
||||
#include "unique_fd.h"
|
||||
#include "post_event_utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS::DistributedKv;
|
||||
@@ -138,6 +140,59 @@ bool ThumbnailUtils::DeleteThumbFile(ThumbnailData &data, ThumbnailType type)
|
||||
string fileName = GetThumbnailPath(data.path, GetThumbnailSuffix(type));
|
||||
if (!MediaFileUtils::DeleteFile(fileName)) {
|
||||
MEDIA_ERR_LOG("delete file faild %{public}d", errno);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, -errno},
|
||||
{KEY_OPT_FILE, fileName}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ThumbnailUtils::LoadAudioFileInfo(shared_ptr<AVMetadataHelper> avMetadataHelper, ThumbnailData &data,
|
||||
const bool isThumbnail, const Size &desiredSize, uint32_t &errCode)
|
||||
{
|
||||
auto audioPicMemory = avMetadataHelper->FetchArtPicture();
|
||||
if (audioPicMemory == nullptr) {
|
||||
MEDIA_ERR_LOG("FetchArtPicture failed!");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_THUMBNAIL_UNKNOWN},
|
||||
{KEY_OPT_FILE, data.path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
SourceOptions opts;
|
||||
unique_ptr<ImageSource> audioImageSource = ImageSource::CreateImageSource(audioPicMemory->GetBase(),
|
||||
audioPicMemory->GetSize(), opts, errCode);
|
||||
if (audioImageSource == nullptr) {
|
||||
MEDIA_ERR_LOG("Failed to create image source! path %{private}s errCode %{public}d", data.path.c_str(), errCode);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__},
|
||||
{KEY_ERR_CODE, static_cast<int32_t>(errCode)}, {KEY_OPT_FILE, data.path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
ImageInfo imageInfo;
|
||||
errCode = audioImageSource->GetImageInfo(0, imageInfo);
|
||||
if (errCode != E_OK) {
|
||||
MEDIA_ERR_LOG("Failed to get image info, path: %{private}s err: %{public}d", data.path.c_str(), errCode);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__},
|
||||
{KEY_ERR_CODE, static_cast<int32_t>(errCode)}, {KEY_OPT_FILE, data.path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
DecodeOptions decOpts;
|
||||
decOpts.desiredSize = ConvertDecodeSize(imageInfo.size, desiredSize, isThumbnail);
|
||||
decOpts.desiredPixelFormat = PixelFormat::RGBA_8888;
|
||||
data.source = audioImageSource->CreatePixelMap(decOpts, errCode);
|
||||
if ((errCode != E_OK) || (data.source == nullptr)) {
|
||||
MEDIA_ERR_LOG("Av meta data helper fetch frame at time failed");
|
||||
if (errCode != E_OK) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__},
|
||||
{KEY_ERR_CODE, static_cast<int32_t>(errCode)}, {KEY_OPT_FILE, data.path},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -149,39 +204,18 @@ bool ThumbnailUtils::LoadAudioFile(ThumbnailData &data, const bool isThumbnail,
|
||||
string path = data.path;
|
||||
int32_t err = SetSource(avMetadataHelper, path);
|
||||
if (err != E_OK) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_FILE, path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
|
||||
MEDIA_ERR_LOG("Av meta data helper set source failed %{public}d", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto audioPicMemory = avMetadataHelper->FetchArtPicture();
|
||||
if (audioPicMemory == nullptr) {
|
||||
MEDIA_ERR_LOG("FetchArtPicture failed!");
|
||||
return false;
|
||||
}
|
||||
|
||||
SourceOptions opts;
|
||||
uint32_t errCode = 0;
|
||||
unique_ptr<ImageSource> audioImageSource = ImageSource::CreateImageSource(audioPicMemory->GetBase(),
|
||||
audioPicMemory->GetSize(), opts, errCode);
|
||||
if (audioImageSource == nullptr) {
|
||||
MEDIA_ERR_LOG("Failed to create image source! path %{private}s errCode %{public}d",
|
||||
path.c_str(), errCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
ImageInfo imageInfo;
|
||||
errCode = audioImageSource->GetImageInfo(0, imageInfo);
|
||||
if (errCode != E_OK) {
|
||||
MEDIA_ERR_LOG("Failed to get image info, path: %{private}s err: %{public}d", path.c_str(), errCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
DecodeOptions decOpts;
|
||||
decOpts.desiredSize = ConvertDecodeSize(imageInfo.size, desiredSize, isThumbnail);
|
||||
decOpts.desiredPixelFormat = PixelFormat::RGBA_8888;
|
||||
data.source = audioImageSource->CreatePixelMap(decOpts, errCode);
|
||||
if ((errCode != E_OK) || (data.source == nullptr)) {
|
||||
MEDIA_ERR_LOG("Av meta data helper fetch frame at time failed");
|
||||
if (!LoadAudioFileInfo(avMetadataHelper, data, isThumbnail, desiredSize, errCode)) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__},
|
||||
{KEY_ERR_CODE, static_cast<int32_t>(errCode)}, {KEY_OPT_FILE, path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -195,6 +229,9 @@ bool ThumbnailUtils::LoadVideoFile(ThumbnailData &data, const bool isThumbnail,
|
||||
if (err != 0) {
|
||||
MEDIA_ERR_LOG("Av meta data helper set source failed path %{private}s err %{public}d",
|
||||
path.c_str(), err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_FILE, path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
PixelMapParams param;
|
||||
@@ -202,6 +239,9 @@ bool ThumbnailUtils::LoadVideoFile(ThumbnailData &data, const bool isThumbnail,
|
||||
data.source = avMetadataHelper->FetchFrameAtTime(AV_FRAME_TIME, AVMetadataQueryOption::AV_META_QUERY_NEXT_SYNC,
|
||||
param);
|
||||
if (data.source == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_THUMBNAIL_UNKNOWN},
|
||||
{KEY_OPT_FILE, data.path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
MEDIA_ERR_LOG("Av meta data helper fetch frame at time failed");
|
||||
return false;
|
||||
}
|
||||
@@ -243,6 +283,9 @@ bool ThumbnailUtils::LoadImageFile(ThumbnailData &data, const bool isThumbnail,
|
||||
unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(path, opts, err);
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("Failed to create image source, path: %{private}s err: %{public}d", path.c_str(), err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__},
|
||||
{KEY_ERR_CODE, static_cast<int32_t>(err)}, {KEY_OPT_FILE, path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
tracer.Finish();
|
||||
@@ -252,6 +295,9 @@ bool ThumbnailUtils::LoadImageFile(ThumbnailData &data, const bool isThumbnail,
|
||||
err = imageSource->GetImageInfo(0, imageInfo);
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("Failed to get image info, path: %{private}s err: %{public}d", path.c_str(), err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, static_cast<int32_t>(err)},
|
||||
{KEY_OPT_FILE, path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -262,6 +308,11 @@ bool ThumbnailUtils::LoadImageFile(ThumbnailData &data, const bool isThumbnail,
|
||||
if ((err != E_OK) || (data.source == nullptr)) {
|
||||
MEDIA_ERR_LOG("Failed to create pixelmap path %{private}s err %{public}d",
|
||||
path.c_str(), err);
|
||||
if (err != E_OK) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__},
|
||||
{KEY_ERR_CODE, static_cast<int32_t>(err)}, {KEY_OPT_FILE, path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
tracer.Finish();
|
||||
@@ -302,8 +353,13 @@ string ThumbnailUtils::GetUdid()
|
||||
return "";
|
||||
}
|
||||
|
||||
bool ThumbnailUtils::CompressImage(shared_ptr<PixelMap> &pixelMap, vector<uint8_t> &data, bool isHigh)
|
||||
bool ThumbnailUtils::CompressImage(shared_ptr<PixelMap> &pixelMap, vector<uint8_t> &data, bool isHigh,
|
||||
shared_ptr<string> pathPtr)
|
||||
{
|
||||
string path;
|
||||
if (pathPtr != nullptr) {
|
||||
path = *pathPtr;
|
||||
}
|
||||
PackOption option = {
|
||||
.format = THUMBNAIL_FORMAT,
|
||||
.quality = isHigh ? THUMBNAIL_HIGH : THUMBNAIL_MID,
|
||||
@@ -318,6 +374,9 @@ bool ThumbnailUtils::CompressImage(shared_ptr<PixelMap> &pixelMap, vector<uint8_
|
||||
tracer.Finish();
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("Failed to StartPacking %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, static_cast<int32_t>(err)},
|
||||
{KEY_OPT_FILE, path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -326,6 +385,9 @@ bool ThumbnailUtils::CompressImage(shared_ptr<PixelMap> &pixelMap, vector<uint8_
|
||||
tracer.Finish();
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("Failed to StartPacking %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, static_cast<int32_t>(err)},
|
||||
{KEY_OPT_FILE, path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -334,6 +396,9 @@ bool ThumbnailUtils::CompressImage(shared_ptr<PixelMap> &pixelMap, vector<uint8_
|
||||
err = imagePacker.FinalizePacking(packedSize);
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("Failed to StartPacking %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, static_cast<int32_t>(err)},
|
||||
{KEY_OPT_FILE, path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -387,6 +452,9 @@ shared_ptr<ResultSet> ThumbnailUtils::QueryThumbnailInfo(ThumbRdbOpt &opts,
|
||||
|
||||
err = resultSet->GoToFirstRow();
|
||||
if (err != E_OK) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -405,6 +473,9 @@ bool ThumbnailUtils::QueryLcdCount(ThumbRdbOpt &opts, int &outLcdCount, int &err
|
||||
rdbPredicates.NotEqualTo(MEDIA_DATA_DB_MEDIA_TYPE, to_string(MEDIA_TYPE_ALBUM));
|
||||
auto resultSet = opts.store->QueryByStep(rdbPredicates, column);
|
||||
if (resultSet == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
int rowCount = 0;
|
||||
@@ -412,6 +483,50 @@ bool ThumbnailUtils::QueryLcdCount(ThumbRdbOpt &opts, int &outLcdCount, int &err
|
||||
resultSet.reset();
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("Failed to get row count %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
MEDIA_DEBUG_LOG("rowCount is %{public}d", rowCount);
|
||||
if (rowCount <= 0) {
|
||||
MEDIA_INFO_LOG("No match! %{private}s", rdbPredicates.ToString().c_str());
|
||||
rowCount = 0;
|
||||
}
|
||||
|
||||
outLcdCount = rowCount;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ThumbnailUtils::QueryLcdCountByTime(const int64_t &time, const bool &before, ThumbRdbOpt &opts, int &outLcdCount,
|
||||
int &err)
|
||||
{
|
||||
vector<string> column = {
|
||||
MEDIA_DATA_DB_ID,
|
||||
};
|
||||
RdbPredicates rdbPredicates(opts.table);
|
||||
if (before) {
|
||||
rdbPredicates.LessThanOrEqualTo(MEDIA_DATA_DB_TIME_VISIT, to_string(time));
|
||||
} else {
|
||||
rdbPredicates.GreaterThan(MEDIA_DATA_DB_TIME_VISIT, to_string(time));
|
||||
}
|
||||
rdbPredicates.NotEqualTo(MEDIA_DATA_DB_MEDIA_TYPE, to_string(MEDIA_TYPE_FILE));
|
||||
rdbPredicates.NotEqualTo(MEDIA_DATA_DB_MEDIA_TYPE, to_string(MEDIA_TYPE_ALBUM));
|
||||
auto resultSet = opts.store->QueryByStep(rdbPredicates, column);
|
||||
if (resultSet == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
int rowCount = 0;
|
||||
err = resultSet->GetRowCount(rowCount);
|
||||
resultSet.reset();
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("Failed to get row count %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
MEDIA_DEBUG_LOG("rowCount is %{public}d", rowCount);
|
||||
@@ -620,6 +735,9 @@ bool ThumbnailUtils::QueryNoLcdInfos(ThumbRdbOpt &opts, int LcdLimit, vector<Thu
|
||||
err = resultSet->GoToFirstRow();
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("Failed GoToFirstRow %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -666,6 +784,9 @@ bool ThumbnailUtils::QueryNoThumbnailInfos(ThumbRdbOpt &opts, vector<ThumbnailDa
|
||||
err = resultSet->GoToFirstRow();
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("Failed GoToFirstRow %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -679,6 +800,52 @@ bool ThumbnailUtils::QueryNoThumbnailInfos(ThumbRdbOpt &opts, vector<ThumbnailDa
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ThumbnailUtils::QueryNewThumbnailCount(ThumbRdbOpt &opts, const int64_t &time, int &count,
|
||||
int &err)
|
||||
{
|
||||
vector<string> column = {
|
||||
MEDIA_DATA_DB_ID,
|
||||
};
|
||||
RdbPredicates rdbPredicates(opts.table);
|
||||
rdbPredicates.GreaterThan(MEDIA_DATA_DB_TIME_VISIT, to_string(time));
|
||||
if (opts.table == MEDIALIBRARY_TABLE) {
|
||||
rdbPredicates.EqualTo(MEDIA_DATA_DB_IS_TRASH, "0");
|
||||
} else {
|
||||
rdbPredicates.EqualTo(MEDIA_DATA_DB_DATE_TRASHED, "0");
|
||||
}
|
||||
rdbPredicates.EqualTo(MEDIA_DATA_DB_TIME_PENDING, "0");
|
||||
rdbPredicates.NotEqualTo(MEDIA_DATA_DB_MEDIA_TYPE, to_string(MEDIA_TYPE_ALBUM));
|
||||
rdbPredicates.NotEqualTo(MEDIA_DATA_DB_MEDIA_TYPE, to_string(MEDIA_TYPE_FILE));
|
||||
|
||||
rdbPredicates.OrderByDesc(MEDIA_DATA_DB_DATE_ADDED);
|
||||
|
||||
shared_ptr<ResultSet> resultSet = opts.store->QueryByStep(rdbPredicates, column);
|
||||
if (resultSet == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
int rowCount = 0;
|
||||
err = resultSet->GetRowCount(rowCount);
|
||||
resultSet.reset();
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("Failed to get row count %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
MEDIA_DEBUG_LOG("rowCount is %{public}d", rowCount);
|
||||
if (rowCount <= 0) {
|
||||
MEDIA_INFO_LOG("No match! %{public}s", rdbPredicates.ToString().c_str());
|
||||
rowCount = 0;
|
||||
}
|
||||
|
||||
count = rowCount;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ThumbnailUtils::UpdateLcdInfo(ThumbRdbOpt &opts, ThumbnailData &data, int &err)
|
||||
{
|
||||
ValuesBucket values;
|
||||
@@ -693,6 +860,9 @@ bool ThumbnailUtils::UpdateLcdInfo(ThumbRdbOpt &opts, ThumbnailData &data, int &
|
||||
vector<string> { opts.row });
|
||||
if (err != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("RdbStore Update failed! %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -712,6 +882,9 @@ bool ThumbnailUtils::UpdateVisitTime(ThumbRdbOpt &opts, ThumbnailData &data, int
|
||||
vector<string> { opts.row });
|
||||
if (err != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("RdbStore Update failed! %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -736,6 +909,9 @@ bool ThumbnailUtils::QueryDeviceThumbnailRecords(ThumbRdbOpt &opts, vector<Thumb
|
||||
err = resultSet->GoToFirstRow();
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("Failed GoToFirstRow %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -937,6 +1113,9 @@ bool ThumbnailUtils::CleanThumbnailInfo(ThumbRdbOpt &opts, bool withThumb, bool
|
||||
vector<string> { opts.row });
|
||||
if (err != NativeRdb::E_OK) {
|
||||
MEDIA_ERR_LOG("RdbStore Update failed! %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -1021,6 +1200,9 @@ bool ThumbnailUtils::LoadSourceImage(ThumbnailData &data, const Size &desiredSiz
|
||||
ret = LoadImageFile(data, isThumbnail, desiredSize);
|
||||
}
|
||||
if (!ret || (data.source == nullptr)) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_THUMBNAIL_UNKNOWN},
|
||||
{KEY_OPT_FILE, data.path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
tracer.Finish();
|
||||
@@ -1030,6 +1212,9 @@ bool ThumbnailUtils::LoadSourceImage(ThumbnailData &data, const Size &desiredSiz
|
||||
PostProc postProc;
|
||||
if (!postProc.CenterScale(desiredSize, *data.source)) {
|
||||
MEDIA_ERR_LOG("thumbnail center crop failed [%{private}s]", data.id.c_str());
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_THUMBNAIL_UNKNOWN},
|
||||
{KEY_OPT_FILE, data.path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1076,6 +1261,39 @@ static int SaveFile(const string &fileName, uint8_t *output, int writeSize)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ThumbnailUtils::SaveFileCreateDir(const string &path, const string &suffix, string &fileName)
|
||||
{
|
||||
fileName = GetThumbnailPath(path, suffix);
|
||||
string dir = MediaFileUtils::GetParentPath(fileName);
|
||||
if (!MediaFileUtils::CreateDirectory(dir)) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, -errno},
|
||||
{KEY_OPT_FILE, dir}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return -errno;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int ThumbnailUtils::ToSaveFile(ThumbnailData &data, const ThumbnailType &type, const string &fileName,
|
||||
uint8_t *output, const int &writeSize)
|
||||
{
|
||||
int ret = SaveFile(fileName, output, writeSize);
|
||||
if (ret < 0) {
|
||||
DeleteThumbFile(data, type);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_FILE, fileName}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return ret;
|
||||
} else if (ret != writeSize) {
|
||||
DeleteThumbFile(data, type);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_NO_SPACE},
|
||||
{KEY_OPT_FILE, fileName}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return E_NO_SPACE;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int ThumbnailUtils::TrySaveFile(ThumbnailData &data, ThumbnailType type)
|
||||
{
|
||||
string suffix;
|
||||
@@ -1104,19 +1322,20 @@ int ThumbnailUtils::TrySaveFile(ThumbnailData &data, ThumbnailType type)
|
||||
if (writeSize <= 0) {
|
||||
return E_THUMBNAIL_LOCAL_CREATE_FAIL;
|
||||
}
|
||||
string fileName = GetThumbnailPath(data.path, suffix);
|
||||
string dir = MediaFileUtils::GetParentPath(fileName);
|
||||
if (!MediaFileUtils::CreateDirectory(dir)) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
int ret = SaveFile(fileName, output, writeSize);
|
||||
if (ret < 0) {
|
||||
DeleteThumbFile(data, type);
|
||||
string fileName;
|
||||
int ret = SaveFileCreateDir(data.path, suffix, fileName);
|
||||
if (ret != E_OK) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_FILE, fileName}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return ret;
|
||||
}
|
||||
ret = ToSaveFile(data, type, fileName, output, writeSize);
|
||||
if (ret < 0) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_FILE, fileName}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return ret;
|
||||
} else if (ret != writeSize) {
|
||||
DeleteThumbFile(data, type);
|
||||
return E_NO_SPACE;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
@@ -1152,12 +1371,18 @@ int32_t ThumbnailUtils::SetSource(shared_ptr<AVMetadataHelper> avMetadataHelper,
|
||||
int32_t fd = open(path.c_str(), O_RDONLY);
|
||||
if (fd < 0) {
|
||||
MEDIA_ERR_LOG("Open file failed, err %{public}d", errno);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, -errno},
|
||||
{KEY_OPT_FILE, path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return E_ERR;
|
||||
}
|
||||
|
||||
struct stat64 st;
|
||||
if (fstat64(fd, &st) != 0) {
|
||||
MEDIA_ERR_LOG("Get file state failed, err %{public}d", errno);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, -errno},
|
||||
{KEY_OPT_FILE, path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
(void)close(fd);
|
||||
return E_ERR;
|
||||
}
|
||||
@@ -1165,6 +1390,9 @@ int32_t ThumbnailUtils::SetSource(shared_ptr<AVMetadataHelper> avMetadataHelper,
|
||||
int32_t ret = avMetadataHelper->SetSource(fd, 0, length, AV_META_USAGE_PIXEL_MAP);
|
||||
if (ret != 0) {
|
||||
MEDIA_ERR_LOG("SetSource fail");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_FILE, path}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
(void)close(fd);
|
||||
return E_ERR;
|
||||
}
|
||||
@@ -1188,6 +1416,9 @@ bool ThumbnailUtils::ResizeImage(const vector<uint8_t> &data, const Size &size,
|
||||
data.size(), opts, err);
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("Failed to create image source %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, static_cast<int32_t>(err)},
|
||||
{KEY_OPT_FILE, ""}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
tracer.Finish();
|
||||
@@ -1199,6 +1430,9 @@ bool ThumbnailUtils::ResizeImage(const vector<uint8_t> &data, const Size &size,
|
||||
decodeOpts.allocatorType = AllocatorType::SHARE_MEM_ALLOC;
|
||||
pixelMap = imageSource->CreatePixelMap(decodeOpts, err);
|
||||
if (err != Media::SUCCESS) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, static_cast<int32_t>(err)},
|
||||
{KEY_OPT_FILE, ""}, {KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::FILE_OPT_ERR, map);
|
||||
MEDIA_ERR_LOG("Failed to create pixelmap %{public}d", err);
|
||||
return false;
|
||||
}
|
||||
@@ -1214,6 +1448,9 @@ int ThumbnailUtils::GetPixelMapFromResult(const shared_ptr<DataShare::DataShareR
|
||||
int ret = resultSet->GoToFirstRow();
|
||||
if (ret != DataShare::E_OK) {
|
||||
MEDIA_ERR_LOG("GoToFirstRow error %{public}d", ret);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1221,6 +1458,9 @@ int ThumbnailUtils::GetPixelMapFromResult(const shared_ptr<DataShare::DataShareR
|
||||
ret = resultSet->GetBlob(KEY_INDEX, key);
|
||||
if (ret != DataShare::E_OK) {
|
||||
MEDIA_ERR_LOG("GetBlob key error %{public}d", ret);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1228,6 +1468,9 @@ int ThumbnailUtils::GetPixelMapFromResult(const shared_ptr<DataShare::DataShareR
|
||||
ret = resultSet->GetBlob(VALUE_INDEX, image);
|
||||
if (ret != DataShare::E_OK) {
|
||||
MEDIA_ERR_LOG("GetBlob image error %{public}d", ret);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, ret},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1240,6 +1483,9 @@ int ThumbnailUtils::GetPixelMapFromResult(const shared_ptr<DataShare::DataShareR
|
||||
tracer.Start("ThumbnailUtils::ResizeImage");
|
||||
if (!ResizeImage(image, size, outPixelMap)) {
|
||||
MEDIA_ERR_LOG("ResizeImage error");
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_THUMBNAIL_UNKNOWN},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
@@ -1371,18 +1617,27 @@ int64_t ThumbnailUtils::UTCTimeMilliSeconds()
|
||||
bool ThumbnailUtils::CheckResultSetCount(const shared_ptr<ResultSet> &resultSet, int &err)
|
||||
{
|
||||
if (resultSet == nullptr) {
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, E_HAS_DB_ERROR},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
int rowCount = 0;
|
||||
err = resultSet->GetRowCount(rowCount);
|
||||
if (err != E_OK) {
|
||||
MEDIA_ERR_LOG("Failed to get row count %{public}d", err);
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rowCount <= 0) {
|
||||
MEDIA_ERR_LOG("CheckCount No match!");
|
||||
err = E_EMPTY_VALUES_BUCKET;
|
||||
VariantMap map = {{KEY_ERR_FILE, __FILE__}, {KEY_ERR_LINE, __LINE__}, {KEY_ERR_CODE, err},
|
||||
{KEY_OPT_TYPE, OptType::THUMB}};
|
||||
PostEventUtils::GetInstance().PostErrorProcess(ErrType::DB_OPT_ERR, map);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,3 +73,27 @@ ohos_static_library("permission_utils") {
|
||||
subsystem_name = "multimedia"
|
||||
part_name = "media_library"
|
||||
}
|
||||
|
||||
ohos_static_library("post_event_utils") {
|
||||
include_dirs = [
|
||||
"./include/",
|
||||
"${MEDIALIB_INTERFACES_PATH}/inner_api/media_library_helper/include",
|
||||
]
|
||||
|
||||
sources = [ "src/post_event_utils.cpp" ]
|
||||
|
||||
external_deps = [
|
||||
"hilog:libhilog",
|
||||
"hisysevent:libhisysevent",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
if (!link_opt) {
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
}
|
||||
subsystem_name = "multimedia"
|
||||
part_name = "media_library"
|
||||
}
|
||||
|
||||
@@ -104,6 +104,7 @@ constexpr int32_t E_THUMBNAIL_LOCAL_CREATE_FAIL = MEDIA_LIBRARY_ERR(E_THUMBNAIL_
|
||||
constexpr int32_t E_THUMBNAIL_REMOTE_CREATE_FAIL = MEDIA_LIBRARY_ERR(E_THUMBNAIL_OFFSET, 3);
|
||||
constexpr int32_t E_THUMBNAIL_SERVICE_NULLPTR = MEDIA_LIBRARY_ERR(E_THUMBNAIL_OFFSET, 4);
|
||||
constexpr int32_t E_THUMBNAIL_INVALID_SIZE = MEDIA_LIBRARY_ERR(E_THUMBNAIL_OFFSET, 5);
|
||||
constexpr int32_t E_THUMBNAIL_UNKNOWN = MEDIA_LIBRARY_ERR(E_THUMBNAIL_OFFSET, 6);
|
||||
|
||||
// medialibary scanner { 2400, 2499 }
|
||||
constexpr int32_t E_SCANNER_OFFSET = 2400;
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef POST_EVENT_UTILS_H
|
||||
#define POST_EVENT_UTILS_H
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
#include "singleton.h"
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
||||
const std::string KEY_OPT_TYPE = "optType";
|
||||
|
||||
const std::string KEY_ERR_FILE = "errFile";
|
||||
const std::string KEY_ERR_LINE = "errLine";
|
||||
const std::string KEY_ERR_CODE = "errCode";
|
||||
const std::string KEY_OPT_FILE = "optFile";
|
||||
|
||||
const std::string KEY_GNUMS = "gnums";
|
||||
const std::string KEY_ANUMS = "anums";
|
||||
|
||||
const std::string KEY_PRE_VERSION = "preVersion";
|
||||
const std::string KEY_AFTER_VERSION = "afterVersion";
|
||||
|
||||
const std::string KEY_COUNT = "count";
|
||||
|
||||
enum OptType {
|
||||
CREATE = 0,
|
||||
THUMB,
|
||||
SCAN,
|
||||
QUERY,
|
||||
};
|
||||
|
||||
enum ErrType {
|
||||
FILE_OPT_ERR = 0,
|
||||
DB_OPT_ERR,
|
||||
DB_UPGRADE_ERR,
|
||||
};
|
||||
|
||||
enum StatType {
|
||||
THUMBNAIL_STAT = 0,
|
||||
DB_UPGRADE_STAT,
|
||||
SYNC_STAT,
|
||||
AGING_STAT,
|
||||
};
|
||||
using VariantMap = std::map<std::string, std::variant<int32_t, std::string>>;
|
||||
|
||||
class PostEventUtils : public Singleton<PostEventUtils> {
|
||||
public:
|
||||
void PostErrorProcess(const uint32_t &errType, const VariantMap &error);
|
||||
void PostStatProcess(const uint32_t &statType, const VariantMap &stat);
|
||||
|
||||
private:
|
||||
std::string GetOptType(const uint32_t &optType);
|
||||
void PostFileOptError(const VariantMap &errMap);
|
||||
void PostDbOptError(const VariantMap &errMap);
|
||||
void PostDbUpgradeError(const VariantMap &errMap);
|
||||
void PostThumbnailStat(const VariantMap &stat);
|
||||
void PostDbUpgradeStat(const VariantMap &stat);
|
||||
void PostSyncStat();
|
||||
void PostAgingStat(const VariantMap &stat);
|
||||
|
||||
int GetIntValue(const std::string &key, const VariantMap &map);
|
||||
std::string GetStringValue(const std::string &key, const VariantMap &map);
|
||||
|
||||
uint32_t thumbnailTimes_ = 0;
|
||||
uint32_t dbUpgradeTimes_ = 0;
|
||||
uint32_t syncTimes_ = 0;
|
||||
uint32_t recycleTimes_ = 0;
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "post_event_utils.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "hisysevent.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "media_log.h"
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using namespace std;
|
||||
|
||||
const string OPT_CREATE = "CREATE";
|
||||
const string OPT_THUMB = "THUMB";
|
||||
const string OPT_SCAN = "SCAN";
|
||||
const string OPT_QUERY = "QUERY";
|
||||
static constexpr char MEDIA_LIBRARY[] = "";
|
||||
|
||||
string PostEventUtils::GetOptType(const uint32_t &optType)
|
||||
{
|
||||
string type = "";
|
||||
switch (optType) {
|
||||
case OptType::CREATE:
|
||||
type = OPT_CREATE;
|
||||
break;
|
||||
case OptType::THUMB:
|
||||
type = OPT_THUMB;
|
||||
break;
|
||||
case OptType::SCAN:
|
||||
type = OPT_SCAN;
|
||||
break;
|
||||
case OptType::QUERY:
|
||||
type = OPT_QUERY;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
int32_t PostEventUtils::GetIntValue(const string &key, const VariantMap &map)
|
||||
{
|
||||
int value = 0;
|
||||
auto iter = map.find(key);
|
||||
if (iter != map.end()) {
|
||||
if (holds_alternative<int32_t>(iter->second)) {
|
||||
return get<int32_t>(iter->second);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
string PostEventUtils::GetStringValue(const string &key, const VariantMap &map)
|
||||
{
|
||||
string value;
|
||||
auto iter = map.find(key);
|
||||
if (iter != map.end()) {
|
||||
if (holds_alternative<string>(iter->second)) {
|
||||
return get<string>(iter->second);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void PostEventUtils::PostFileOptError(const VariantMap &error)
|
||||
{
|
||||
uint32_t uid = getuid();
|
||||
int ret = HiSysEventWrite(
|
||||
MEDIA_LIBRARY,
|
||||
"MEDIALIB_FILE_OPT_ERROR",
|
||||
HiviewDFX::HiSysEvent::EventType::FAULT,
|
||||
"UID", uid,
|
||||
"ERR_FILE", GetStringValue(KEY_ERR_FILE, error),
|
||||
"LINE", GetIntValue(KEY_ERR_LINE, error),
|
||||
"ERROR_CODE", GetIntValue(KEY_ERR_CODE, error),
|
||||
"FILE", GetStringValue(KEY_OPT_FILE, error),
|
||||
"TYPE", GetOptType(GetIntValue(KEY_OPT_TYPE, error)),
|
||||
"CALLING_ID", IPCSkeleton::GetCallingUid());
|
||||
if (ret != 0) {
|
||||
MEDIA_ERR_LOG("PostFileOptError error:%{public}d", ret);
|
||||
}
|
||||
}
|
||||
|
||||
void PostEventUtils::PostDbOptError(const VariantMap &error)
|
||||
{
|
||||
uint32_t uid = getuid();
|
||||
int ret = HiSysEventWrite(
|
||||
MEDIA_LIBRARY,
|
||||
"MEDIALIB_DB_OPT_ERROR",
|
||||
HiviewDFX::HiSysEvent::EventType::FAULT,
|
||||
"UID", uid,
|
||||
"ERR_FILE", GetStringValue(KEY_ERR_FILE, error),
|
||||
"LINE", GetIntValue(KEY_ERR_LINE, error),
|
||||
"ERROR_CODE", GetIntValue(KEY_ERR_CODE, error),
|
||||
"TYPE", GetOptType(GetIntValue(KEY_OPT_TYPE, error)),
|
||||
"CALLING_ID", IPCSkeleton::GetCallingUid());
|
||||
if (ret != 0) {
|
||||
MEDIA_ERR_LOG("Failed to PostDbOptError error:%{public}d", ret);
|
||||
}
|
||||
}
|
||||
|
||||
void PostEventUtils::PostDbUpgradeError(const VariantMap &error)
|
||||
{
|
||||
int ret = HiSysEventWrite(
|
||||
MEDIA_LIBRARY,
|
||||
"MEDIALIB_DB_UPGRADE_ERROR",
|
||||
HiviewDFX::HiSysEvent::EventType::FAULT,
|
||||
"ERR_FILE", GetStringValue(KEY_ERR_FILE, error),
|
||||
"LINE", GetIntValue(KEY_ERR_LINE, error));
|
||||
if (ret != 0) {
|
||||
MEDIA_ERR_LOG("Failed to PostDbUpgradeError err:%{public}d", ret);
|
||||
}
|
||||
}
|
||||
|
||||
void PostEventUtils::PostThumbnailStat(const VariantMap &stat)
|
||||
{
|
||||
uint32_t uid = getuid();
|
||||
thumbnailTimes_++;
|
||||
int ret = HiSysEventWrite(
|
||||
MEDIA_LIBRARY,
|
||||
"MEDIALIB_THUMBNAIL_STAT",
|
||||
HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
|
||||
"UID", uid,
|
||||
"TIMES", thumbnailTimes_,
|
||||
"GNUMS", GetIntValue(KEY_GNUMS, stat),
|
||||
"ANUMS", GetIntValue(KEY_ANUMS, stat));
|
||||
if (ret != 0) {
|
||||
MEDIA_ERR_LOG("Failed to PostThumbnailStat error:%{public}d ", ret);
|
||||
}
|
||||
}
|
||||
|
||||
void PostEventUtils::PostDbUpgradeStat(const VariantMap &stat)
|
||||
{
|
||||
int32_t preVersion = GetIntValue(KEY_PRE_VERSION, stat);
|
||||
int32_t afterVersion = GetIntValue(KEY_AFTER_VERSION, stat);
|
||||
dbUpgradeTimes_++;
|
||||
int ret = HiSysEventWrite(
|
||||
MEDIA_LIBRARY,
|
||||
"MEDIALIB_DB_UPGRADE_STAT",
|
||||
HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
|
||||
"PRE_VERSION", preVersion,
|
||||
"AFTER_VERSION", afterVersion,
|
||||
"COUNT", dbUpgradeTimes_);
|
||||
if (ret != 0) {
|
||||
MEDIA_ERR_LOG("PostDbUpgradeStat preVersion:%{public}d afterVersion:%{public}d error:%{public}d",
|
||||
preVersion, afterVersion, ret);
|
||||
}
|
||||
}
|
||||
|
||||
void PostEventUtils::PostSyncStat()
|
||||
{
|
||||
syncTimes_++;
|
||||
int ret = HiSysEventWrite(
|
||||
MEDIA_LIBRARY,
|
||||
"MEDIALIB_SYNC_STAT",
|
||||
HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
|
||||
"TIMES", syncTimes_);
|
||||
if (ret != 0) {
|
||||
MEDIA_ERR_LOG("PostSyncStat ret:%{public}d", ret);
|
||||
}
|
||||
}
|
||||
|
||||
void PostEventUtils::PostAgingStat(const VariantMap &stat)
|
||||
{
|
||||
recycleTimes_++;
|
||||
int ret = HiSysEventWrite(
|
||||
MEDIA_LIBRARY,
|
||||
"MEDIALIB_AGING_STAT",
|
||||
HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
|
||||
"TIMES", recycleTimes_,
|
||||
"COUNT", GetIntValue(KEY_COUNT, stat));
|
||||
if (ret != 0) {
|
||||
MEDIA_ERR_LOG("PostAgingStat error:%{public}d", ret);
|
||||
}
|
||||
}
|
||||
|
||||
void PostEventUtils::PostErrorProcess(const uint32_t &errType, const VariantMap &error)
|
||||
{
|
||||
switch (errType) {
|
||||
case ErrType::FILE_OPT_ERR:
|
||||
PostFileOptError(error);
|
||||
break;
|
||||
case ErrType::DB_OPT_ERR:
|
||||
PostDbOptError(error);
|
||||
break;
|
||||
case ErrType::DB_UPGRADE_ERR:
|
||||
PostDbUpgradeError(error);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PostEventUtils::PostStatProcess(const uint32_t &statType, const VariantMap &stat)
|
||||
{
|
||||
switch (statType) {
|
||||
case StatType::THUMBNAIL_STAT:
|
||||
PostThumbnailStat(stat);
|
||||
break;
|
||||
case StatType::DB_UPGRADE_STAT:
|
||||
PostDbUpgradeStat(stat);
|
||||
break;
|
||||
case StatType::SYNC_STAT:
|
||||
PostSyncStat();
|
||||
break;
|
||||
case StatType::AGING_STAT:
|
||||
PostAgingStat(stat);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
+41
-28
@@ -36,37 +36,50 @@
|
||||
# DESCRIPTION contains userid,request type.
|
||||
# REASON contains errno num, and failed interface.
|
||||
|
||||
domain: MULTI_MEDIA
|
||||
domain: MEDIALIBRARY
|
||||
|
||||
MEDIALIBRARY_FILESYSTEM_ERROR:
|
||||
__BASE: { type: FAULT, level: CRITICAL, desc: filesystem error }
|
||||
UID: { type: INT32, desc: application uid}
|
||||
PACKAGE_NAME: { type: STRING, desc: application package name }
|
||||
DESCRIPTION: { type: STRING, desc: errro message }
|
||||
REASON: { type: STRING, desc: fault reason }
|
||||
MEDIALIB_FILE_OPT_ERROR:
|
||||
__BASE: { type: FAULT, level: CRITICAL, desc: create file error }
|
||||
UID: { type: INT32, desc: user id}
|
||||
ERR_FILE: { type: STRING, desc: failed file }
|
||||
LINE: { type: UINT32, desc: failed line }
|
||||
ERROR_CODE: { type: INT32, desc: error code }
|
||||
FILE: { type: STRING, desc: file name }
|
||||
TYPE: { type: STRING, desc: operation type }
|
||||
CALLING_ID: { type: INT32, desc: calling uid }
|
||||
|
||||
MEDIALIBRARY_RDB_ERROR:
|
||||
__BASE: { type: FAULT, level: CRITICAL, desc: filesystem error }
|
||||
UID: { type: INT32, desc: application uid }
|
||||
PACKAGE_NAME: { type: STRING, desc: application package name }
|
||||
DESCRIPTION: { type: STRING, desc: errro message }
|
||||
REASON: { type: STRING, desc: fault reason }
|
||||
MEDIALIB_DB_OPT_ERROR:
|
||||
__BASE: { type: FAULT, level: CRITICAL, desc: local db create file failure }
|
||||
UID: { type: INT32, desc: user id}
|
||||
ERR_FILE: { type: STRING, desc: failed file }
|
||||
LINE: { type: UINT32, desc: upgrade failed line }
|
||||
ERROR_CODE: { type: INT32, desc: error code }
|
||||
TYPE: { type: STRING, desc: operation type }
|
||||
CALLING_ID: { type: INT32, desc: calling uid }
|
||||
|
||||
MEDIALIBRARY_KVSTORE_ERROR:
|
||||
__BASE: { type: FAULT, level: CRITICAL, desc: filesystem error }
|
||||
UID: { type: INT32, desc: application uid }
|
||||
PACKAGE_NAME: { type: STRING, desc: application package name }
|
||||
DESCRIPTION: { type: STRING, desc: errro message }
|
||||
REASON: { type: STRING, desc: fault reason }
|
||||
MEDIALIB_DB_UPGRADE_ERROR:
|
||||
__BASE: { type: FAULT, level: CRITICAL, desc: local database upgrade failure }
|
||||
ERR_FILE: { type: STRING, desc: upgrade failed file }
|
||||
LINE: { type: UINT32, desc: upgrade failed line }
|
||||
|
||||
MEDIALIBRARY_DISTRIBUTE_ERROR:
|
||||
__BASE: { type: FAULT, level: CRITICAL, desc: filesystem error }
|
||||
DESCRIPTION: { type: STRING, desc: errro message }
|
||||
REASON: { type: STRING, desc: fault reason }
|
||||
|
||||
MEDIALIBRARY_THUMBNAIL_STAT:
|
||||
__BASE: { type: BEHAVIOR, level: MINOR, desc: thumbnail numbers statistic}
|
||||
TIMES: { type: UINT32, desc: generate times }
|
||||
MEDIALIB_THUMBNAIL_STAT:
|
||||
__BASE: { type: BEHAVIOR, level: MINOR, desc: thumbnail aging is triggered when the screen is off }
|
||||
UID: { type: INT32, desc: user id}
|
||||
TIMES: { type: UINT32, desc: history trigger number }
|
||||
GNUMS: { type: UINT32, desc: generate thumbnail nums }
|
||||
ANUMS: { type: UINT32, desc: aging thumbnail nums }
|
||||
ADEVICES: { type: UINT32, desc: aging devices nums }
|
||||
|
||||
MEDIALIB_DB_UPGRADE_STAT:
|
||||
__BASE: { type: BEHAVIOR, level: MINOR, desc: database upgrade }
|
||||
PRE_VERSION: { type: INT32, desc: pre upgrade version number }
|
||||
AFTER_VERSION: { type: INT32, desc: after upgrade version number }
|
||||
COUNT: { type: UINT32, desc: upgrade events count }
|
||||
|
||||
MEDIALIB_SYNC_STAT:
|
||||
__BASE: { type: BEHAVIOR, level: MINOR, desc: synchronization times between the local end and the cloud }
|
||||
TIMES: { type: UINT32, desc: sync times }
|
||||
|
||||
MEDIALIB_AGING_STAT:
|
||||
__BASE: { type: BEHAVIOR, level: MINOR, desc: aging state }
|
||||
TIMES: { type: UINT32, desc: history trigger times }
|
||||
COUNT: { type: UINT32, desc: the recycle number of aging }
|
||||
@@ -16,6 +16,7 @@
|
||||
#ifndef INTERFACES_INNERKITS_NATIVE_INCLUDE_ALBUM_ASSET_H_
|
||||
#define INTERFACES_INNERKITS_NATIVE_INCLUDE_ALBUM_ASSET_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "userfile_manager_types.h"
|
||||
@@ -54,7 +55,7 @@ public:
|
||||
string GetAlbumPath() const;
|
||||
bool GetAlbumVirtual() const;
|
||||
|
||||
bool CreateAlbumAsset();
|
||||
bool CreateAlbumAsset(std::shared_ptr<int> errCodePtr = nullptr);
|
||||
bool DeleteAlbumAsset(const std::string &albumUri);
|
||||
bool ModifyAlbumAsset(const std::string &albumUri);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user