• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "medialibrary_data_ability_utils.h"
17 #include <regex>
18 
19 using namespace std;
20 using namespace OHOS::NativeRdb;
21 
22 namespace OHOS {
23 namespace Media {
24 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "MediaLibraryDataAbilityUtils"};
GetFileName(const string & path)25 string MediaLibraryDataAbilityUtils::GetFileName(const string &path)
26 {
27     string name;
28     size_t slashIndex = path.rfind("/");
29     if (slashIndex != string::npos) {
30         name = path.substr(slashIndex + 1);
31     }
32     return name;
33 }
34 
GetParentPath(const string & path)35 string MediaLibraryDataAbilityUtils::GetParentPath(const string &path)
36 {
37     string name;
38     size_t slashIndex = path.rfind("/");
39     if (slashIndex != string::npos) {
40         name = path.substr(0, slashIndex);
41     }
42 
43     return name;
44 }
45 
GetParentIdFromDb(const string & path,const shared_ptr<RdbStore> & rdbStore)46 int32_t MediaLibraryDataAbilityUtils::GetParentIdFromDb(const string &path, const shared_ptr<RdbStore> &rdbStore)
47 {
48     int32_t parentId = 0;
49     int32_t columnIndex(0);
50 
51     if (rdbStore != nullptr && !path.empty()) {
52         AbsRdbPredicates absPredicates(MEDIALIBRARY_TABLE);
53         absPredicates.EqualTo(MEDIA_DATA_DB_FILE_PATH, path);
54 
55         vector<string> columns;
56         columns.push_back(MEDIA_DATA_DB_ID);
57 
58         unique_ptr<ResultSet> queryResultSet = rdbStore->Query(absPredicates, columns);
59         CHECK_AND_RETURN_RET_LOG(queryResultSet != nullptr, parentId, "Failed to obtain parentId from database");
60 
61         auto ret = queryResultSet->GoToFirstRow();
62         CHECK_AND_RETURN_RET_LOG(ret == 0, parentId, "Failed to shift at first row");
63 
64         ret = queryResultSet->GetColumnIndex(MEDIA_DATA_DB_ID, columnIndex);
65         CHECK_AND_RETURN_RET_LOG(ret == 0, parentId, "Failed to obtain column index");
66 
67         ret = queryResultSet->GetInt(columnIndex, parentId);
68         CHECK_AND_RETURN_RET_LOG(ret == 0, parentId, "Failed to obtain parent id");
69     }
70 
71     return parentId;
72 }
GetParentDisplayNameFromDb(const int & id,const shared_ptr<RdbStore> & rdbStore)73 string MediaLibraryDataAbilityUtils::GetParentDisplayNameFromDb(const int &id, const shared_ptr<RdbStore> &rdbStore)
74 {
75     string parentName;
76     int32_t columnIndex(0);
77     if (rdbStore != nullptr) {
78         AbsRdbPredicates absPredicates(MEDIALIBRARY_TABLE);
79         absPredicates.EqualTo(MEDIA_DATA_DB_ID, std::to_string(id));
80         vector<string> columns;
81         columns.push_back(MEDIA_DATA_DB_NAME);
82         unique_ptr<ResultSet> queryResultSet = rdbStore->Query(absPredicates, columns);
83         auto ret = queryResultSet->GoToFirstRow();
84         ret = queryResultSet->GetColumnIndex(MEDIA_DATA_DB_NAME, columnIndex);
85         ret = queryResultSet->GetString(columnIndex, parentName);
86     }
87     return parentName;
88 }
89 
IsNumber(const string & str)90 bool MediaLibraryDataAbilityUtils::IsNumber(const string &str)
91 {
92     if (str.length() == 0) {
93         MEDIA_ERR_LOG("IsNumber input is empty ");
94         return false;
95     }
96 
97     for (char const &c : str) {
98         if (isdigit(c) == 0) {
99             MEDIA_ERR_LOG("Index is not a number");
100             return false;
101         }
102     }
103 
104     return true;
105 }
CreateDirectorys(const string relativePath,const std::shared_ptr<NativeRdb::RdbStore> & rdbStore,vector<int32_t> & outIds)106 NativeAlbumAsset MediaLibraryDataAbilityUtils::CreateDirectorys(const string relativePath,
107                                                                 const std::shared_ptr<NativeRdb::RdbStore> &rdbStore,
108                                                                 vector<int32_t> &outIds)
109 {
110     NativeAlbumAsset albumAsset;
111     if (!relativePath.empty()) {
112         string path = relativePath;
113         ValuesBucket values;
114         values.PutString(MEDIA_DATA_DB_FILE_PATH, ROOT_MEDIA_DIR + path);
115         MediaLibraryAlbumOperations albumOprn;
116         int32_t errorcode = albumOprn.HandleAlbumOperations(MEDIA_ALBUMOPRN_CREATEALBUM, values, rdbStore, outIds);
117         albumAsset.SetAlbumId(errorcode);
118         albumAsset.SetAlbumName(albumOprn.GetNativeAlbumAsset()->GetAlbumName());
119     }
120     return albumAsset;
121 }
DeleteDirectorys(vector<int32_t> & outIds,const std::shared_ptr<NativeRdb::RdbStore> & rdbStore)122 int32_t MediaLibraryDataAbilityUtils::DeleteDirectorys(vector<int32_t> &outIds,
123                                                        const std::shared_ptr<NativeRdb::RdbStore> &rdbStore)
124 {
125     int32_t errorCode = -1;
126     if (!outIds.empty()) {
127         MediaLibraryAlbumOperations albumOprn;
128         for (vector<int32_t>::reverse_iterator it = outIds.rbegin(); it != outIds.rend(); ++it) {
129             ValuesBucket values;
130             int32_t id = *it;
131             values.PutInt(MEDIA_DATA_DB_ID, id);
132             errorCode = albumOprn.HandleAlbumOperations(MEDIA_ALBUMOPRN_DELETEALBUM, values, rdbStore, outIds);
133         }
134     }
135     return errorCode;
136 }
GetAlbumAsset(const std::string & id,const std::shared_ptr<NativeRdb::RdbStore> & rdbStore)137 NativeAlbumAsset MediaLibraryDataAbilityUtils::GetAlbumAsset(const std::string &id,
138                                                              const std::shared_ptr<NativeRdb::RdbStore> &rdbStore)
139 {
140     NativeAlbumAsset albumAsset;
141     vector<string> columns;
142     AbsRdbPredicates absPredicates(MEDIALIBRARY_TABLE);
143     absPredicates.EqualTo(MEDIA_DATA_DB_ID, id);
144     unique_ptr<ResultSet> queryResultSet = rdbStore->Query(absPredicates, columns);
145     if (queryResultSet->GoToNextRow() == NativeRdb::E_OK) {
146         int32_t columnIndexId;
147         int32_t idVal;
148         int32_t columnIndexName;
149         string nameVal;
150         queryResultSet->GetColumnIndex(MEDIA_DATA_DB_ID, columnIndexId);
151         queryResultSet->GetInt(columnIndexId, idVal);
152         queryResultSet->GetColumnIndex(MEDIA_DATA_DB_TITLE, columnIndexName);
153         queryResultSet->GetString(columnIndexName, nameVal);
154         albumAsset.SetAlbumId(idVal);
155         albumAsset.SetAlbumName(nameVal);
156     }
157     return albumAsset;
158 }
GetFileTitle(const std::string & displayName)159 std::string MediaLibraryDataAbilityUtils::GetFileTitle(const std::string& displayName)
160 {
161     std::string title = "";
162     if (!displayName.empty()) {
163         std::string::size_type pos = displayName.find_first_of('.');
164         if (pos == displayName.length()) {
165             return displayName;
166         }
167         title = displayName.substr(0, pos);
168         HiviewDFX::HiLog::Debug(LABEL, "title substr = %{public}s", title.c_str());
169     }
170     HiviewDFX::HiLog::Debug(LABEL, "title = %{public}s", title.c_str());
171     return title;
172 }
GetLastAlbumExistInDb(const std::string & relativePath,const std::shared_ptr<NativeRdb::RdbStore> & rdbStore)173 NativeAlbumAsset MediaLibraryDataAbilityUtils::GetLastAlbumExistInDb(const std::string &relativePath,
174     const std::shared_ptr<NativeRdb::RdbStore> &rdbStore)
175 {
176     NativeAlbumAsset nativeAlbumAsset;
177     int32_t idVal = 0;
178     int32_t columnIndexId;
179     int32_t maxColumnIndexPath;
180     string maxVal = ROOT_MEDIA_DIR;
181     string::size_type max = maxVal.length();
182     string maxPath = ROOT_MEDIA_DIR;
183     int32_t maxId = 0;
184     string::size_type idx;
185     string sql = "SELECT " + MEDIA_DATA_DB_RELATIVE_PATH + ","
186     + MEDIA_DATA_DB_FILE_PATH + "," + MEDIA_DATA_DB_ID + " FROM " + MEDIALIBRARY_TABLE;
187     unique_ptr<ResultSet> queryResultSet = rdbStore->QuerySql(sql);
188     while (queryResultSet->GoToNextRow() == NativeRdb::E_OK) {
189         queryResultSet->GetColumnIndex(MEDIA_DATA_DB_FILE_PATH, maxColumnIndexPath);
190         queryResultSet->GetString(maxColumnIndexPath, maxPath);
191         queryResultSet->GetColumnIndex(MEDIA_DATA_DB_ID, columnIndexId);
192         queryResultSet->GetInt(columnIndexId, idVal);
193         idx = relativePath.find(maxPath);
194         if (idx != string::npos && max < maxPath.length()) {
195             max = maxPath.length();
196             maxVal = maxPath;
197             maxId = idVal;
198         }
199     }
200     nativeAlbumAsset.SetAlbumId(maxId);
201     nativeAlbumAsset.SetAlbumPath(maxVal);
202     return nativeAlbumAsset;
203 }
isAlbumExistInDb(const std::string & relativePath,const std::shared_ptr<NativeRdb::RdbStore> & rdbStore,int32_t & outRow)204 bool MediaLibraryDataAbilityUtils::isAlbumExistInDb(const std::string &relativePath,
205     const std::shared_ptr<NativeRdb::RdbStore> &rdbStore,
206     int32_t &outRow)
207 {
208     vector<string> columns;
209     AbsRdbPredicates absPredicates(MEDIALIBRARY_TABLE);
210     absPredicates.EqualTo(MEDIA_DATA_DB_FILE_PATH, relativePath);
211     unique_ptr<ResultSet> queryResultSet = rdbStore->Query(absPredicates, columns);
212     if (queryResultSet != nullptr) {
213         if (queryResultSet->GoToNextRow() == NativeRdb::E_OK) {
214             int32_t columnIndexId;
215             int32_t idVal;
216             queryResultSet->GetColumnIndex(MEDIA_DATA_DB_ID, columnIndexId);
217             queryResultSet->GetInt(columnIndexId, idVal);
218             OHOS::HiviewDFX::HiLog::Error(LABEL, "id = %{public}d", idVal);
219             outRow = idVal;
220             return true;
221         }
222 }
223     return false;
224 }
GetAlbumDateModified(const string & albumPath)225 int64_t MediaLibraryDataAbilityUtils::GetAlbumDateModified(const string &albumPath)
226 {
227     struct stat statInfo {};
228     if (!albumPath.empty() && stat(albumPath.c_str(), &statInfo) == 0) {
229         return (statInfo.st_mtime);
230     }
231 
232     return 0;
233 }
234 
GetOperationType(const string & uri)235 string MediaLibraryDataAbilityUtils::GetOperationType(const string &uri)
236 {
237     string oprn("");
238     size_t found = uri.rfind('/');
239     if (found != string::npos) {
240         oprn = uri.substr(found + 1);
241     }
242 
243     return oprn;
244 }
245 
isFileExistInDb(const string & path,const shared_ptr<RdbStore> & rdbStore)246 bool MediaLibraryDataAbilityUtils::isFileExistInDb(const string &path, const shared_ptr<RdbStore> &rdbStore)
247 {
248     int32_t count = 0;
249     vector<string> selectionArgs = {};
250     if ((path.empty()) || (rdbStore == nullptr)) {
251         MEDIA_ERR_LOG("path is incorrect or rdbStore is null");
252         return false;
253     }
254     string strQueryCondition = MEDIA_DATA_DB_FILE_PATH + " = '" + path + "'";
255     AbsRdbPredicates absPredicates(MEDIALIBRARY_TABLE);
256     absPredicates.SetWhereClause(strQueryCondition);
257     absPredicates.SetWhereArgs(selectionArgs);
258     vector<string> columns;
259     columns.push_back(MEDIA_DATA_DB_FILE_PATH);
260     unique_ptr<ResultSet> queryResultSet = rdbStore->Query(absPredicates, columns);
261     if (queryResultSet != nullptr) {
262         queryResultSet->GetRowCount(count);
263         MEDIA_INFO_LOG("count is %{public}d", count);
264         if (count > 0) {
265             return true;
266         }
267     }
268 
269     return false;
270 }
271 
GetPathFromDb(const string & id,const shared_ptr<RdbStore> & rdbStore)272 string MediaLibraryDataAbilityUtils::GetPathFromDb(const string &id, const shared_ptr<RdbStore> &rdbStore)
273 {
274     string filePath("");
275     vector<string> selectionArgs = {};
276     int32_t columnIndex(0);
277 
278     if ((id.empty()) || (!IsNumber(id)) || (stoi(id) == -1) || (rdbStore == nullptr)) {
279         MEDIA_ERR_LOG("Id for the path is incorrect or rdbStore is null");
280         return filePath;
281     }
282 
283     string strQueryCondition = MEDIA_DATA_DB_ID + " = " + id;
284 
285     AbsRdbPredicates absPredicates(MEDIALIBRARY_TABLE);
286     absPredicates.SetWhereClause(strQueryCondition);
287     absPredicates.SetWhereArgs(selectionArgs);
288 
289     vector<string> columns;
290     columns.push_back(MEDIA_DATA_DB_FILE_PATH);
291 
292     unique_ptr<ResultSet> queryResultSet = rdbStore->Query(absPredicates, columns);
293     CHECK_AND_RETURN_RET_LOG(queryResultSet != nullptr, filePath, "Failed to obtain path from database");
294 
295     auto ret = queryResultSet->GoToFirstRow();
296     CHECK_AND_RETURN_RET_LOG(ret == 0, filePath, "Failed to shift at first row");
297 
298     ret = queryResultSet->GetColumnIndex(MEDIA_DATA_DB_FILE_PATH, columnIndex);
299     CHECK_AND_RETURN_RET_LOG(ret == 0, filePath, "Failed to obtain column index");
300 
301     ret = queryResultSet->GetString(columnIndex, filePath);
302     CHECK_AND_RETURN_RET_LOG(ret == 0, filePath, "Failed to obtain file path");
303 
304     return filePath;
305 }
306 
GetFileAssetFromDb(const string & uriStr,const shared_ptr<RdbStore> & rdbStore)307 shared_ptr<FileAsset> MediaLibraryDataAbilityUtils::GetFileAssetFromDb(const string &uriStr,
308     const shared_ptr<RdbStore> &rdbStore)
309 {
310     string id = MediaLibraryDataAbilityUtils::GetIdFromUri(uriStr);
311     string networkId = MediaLibraryDataAbilityUtils::GetNetworkIdFromUri(uriStr);
312     vector<string> selectionArgs = {};
313 
314     if ((id.empty()) || (!IsNumber(id)) || (stoi(id) == -1) || (rdbStore == nullptr)) {
315         MEDIA_ERR_LOG("Id for the path is incorrect or rdbStore is null");
316         return nullptr;
317     }
318 
319     string strQueryCondition = MEDIA_DATA_DB_ID + " = " + id;
320     string tableName = MEDIALIBRARY_TABLE;
321     if (!networkId.empty()) {
322         tableName = rdbStore->ObtainDistributedTableName(networkId, MEDIALIBRARY_TABLE);
323         MEDIA_INFO_LOG("tableName is %{public}s", tableName.c_str());
324     }
325 
326     if (tableName.empty()) {
327         MEDIA_ERR_LOG("Get tableName fail, networkId is %{public}s", networkId.c_str());
328         return nullptr;
329     }
330     AbsRdbPredicates absPredicates(tableName);
331     absPredicates.SetWhereClause(strQueryCondition);
332     absPredicates.SetWhereArgs(selectionArgs);
333 
334     vector<string> columns;
335 
336     shared_ptr<AbsSharedResultSet> resultSet = rdbStore->Query(absPredicates, columns);
337     CHECK_AND_RETURN_RET_LOG(resultSet != nullptr, nullptr, "Failed to obtain path from database");
338 
339     shared_ptr<FetchResult> fetchFileResult = make_shared<FetchResult>(resultSet);
340     if (fetchFileResult == nullptr) {
341         MEDIA_ERR_LOG("Failed to obtain fetch file result");
342         return nullptr;
343     }
344     fetchFileResult->networkId_ = networkId;
345     return fetchFileResult->GetFirstObject();
346 }
347 
checkFilePending(const shared_ptr<FileAsset> fileAsset)348 bool MediaLibraryDataAbilityUtils::checkFilePending(const shared_ptr<FileAsset> fileAsset)
349 {
350     MEDIA_INFO_LOG("checkFilePending in");
351     if (fileAsset->IsPending()) {
352         MEDIA_INFO_LOG("checkFilePending IsPending true");
353         return true;
354     } else if (fileAsset->GetTimePending() > 0 &&
355         (UTCTimeSeconds() - fileAsset->GetTimePending()) > TIMEPENDING_MIN) {
356         return true;
357     }
358     MEDIA_INFO_LOG("checkFilePending IsPending false");
359     return false;
360 }
361 
checkOpenMode(const string & mode)362 bool MediaLibraryDataAbilityUtils::checkOpenMode(const string &mode)
363 {
364     MEDIA_INFO_LOG("checkOpenMode in mode %{public}s", mode.c_str());
365 
366     std::string lowModeStr = mode;
367     std::transform(lowModeStr.begin(), lowModeStr.end(), lowModeStr.begin(), [](unsigned char c) {
368         return std::tolower(c);
369     });
370 
371     size_t wIndex = lowModeStr.rfind('w');
372     if (wIndex != string::npos) {
373         return true;
374     }
375     return false;
376 }
377 
setFilePending(string & uriStr,bool isPending,const shared_ptr<RdbStore> & rdbStore)378 int32_t MediaLibraryDataAbilityUtils::setFilePending(string &uriStr,
379     bool isPending, const shared_ptr<RdbStore> &rdbStore)
380 {
381     string id = MediaLibraryDataAbilityUtils::GetIdFromUri(uriStr);
382     string networkId = MediaLibraryDataAbilityUtils::GetNetworkIdFromUri(uriStr);
383     MEDIA_INFO_LOG("setFilePending id = %{public}s, networkId = %{public}s, isPending = %{public}d",
384         id.c_str(), networkId.c_str(), isPending);
385     vector<string> selectionArgs = {};
386     string strUpdateCondition = MEDIA_DATA_DB_ID + " = " + id;
387 
388     ValuesBucket values;
389     values.PutBool(MEDIA_DATA_DB_IS_PENDING, isPending);
390     int64_t timeNow = UTCTimeSeconds();
391     if (isPending) {
392         values.PutLong(MEDIA_DATA_DB_TIME_PENDING, timeNow);
393     } else {
394         values.PutLong(MEDIA_DATA_DB_TIME_PENDING, 0);
395     }
396 
397     values.PutLong(MEDIA_DATA_DB_DATE_MODIFIED, timeNow);
398 
399     int32_t changedRows = DATA_ABILITY_FAIL;
400     string tableName = MEDIALIBRARY_TABLE;
401     if (!networkId.empty()) {
402         tableName = rdbStore->ObtainDistributedTableName(networkId, MEDIALIBRARY_TABLE);
403         MEDIA_INFO_LOG("tableName is %{public}s", tableName.c_str());
404     }
405 
406     if (tableName.empty()) {
407         MEDIA_ERR_LOG("Get tableName fail, networkId is %{public}s", networkId.c_str());
408         return DATA_ABILITY_FAIL;
409     }
410     (void)rdbStore->Update(changedRows, tableName, values, strUpdateCondition, selectionArgs);
411     MEDIA_INFO_LOG("setFilePending out");
412     return changedRows;
413 }
414 
GetIdFromUri(const string & uri)415 string MediaLibraryDataAbilityUtils::GetIdFromUri(const string &uri)
416 {
417     string rowNum = "-1";
418 
419     size_t pos = uri.rfind('/');
420     if (pos != std::string::npos) {
421         rowNum = uri.substr(pos + 1);
422     }
423 
424     return rowNum;
425 }
426 
GetMediaTypeUri(MediaType mediaType)427 string MediaLibraryDataAbilityUtils::GetMediaTypeUri(MediaType mediaType)
428 {
429     switch (mediaType) {
430         case MEDIA_TYPE_AUDIO:
431             return MEDIALIBRARY_AUDIO_URI;
432             break;
433         case MEDIA_TYPE_VIDEO:
434             return MEDIALIBRARY_VIDEO_URI;
435             break;
436         case MEDIA_TYPE_IMAGE:
437             return MEDIALIBRARY_IMAGE_URI;
438             break;
439         case MEDIA_TYPE_SMARTALBUM:
440             return MEDIALIBRARY_SMARTALBUM_CHANGE_URI;
441             break;
442         case MEDIA_TYPE_DEVICE:
443             return MEDIALIBRARY_DEVICE_URI;
444             break;
445         case MEDIA_TYPE_FILE:
446         default:
447             return MEDIALIBRARY_FILE_URI;
448             break;
449     }
450 }
451 
UTCTimeSeconds()452 int64_t MediaLibraryDataAbilityUtils::UTCTimeSeconds()
453 {
454     struct timespec t;
455     t.tv_sec = 0;
456     t.tv_nsec = 0;
457     clock_gettime(CLOCK_REALTIME, &t);
458     return (int64_t)(t.tv_sec);
459 }
460 
CheckDisplayName(std::string displayName)461 bool MediaLibraryDataAbilityUtils::CheckDisplayName(std::string displayName)
462 {
463     int size = displayName.length();
464     if (size <= 0 || size > DISPLAYNAME_MAX) {
465         return false;
466     }
467     std::regex express("[\\.\\\\/:*?\"<>|{}\\[\\]]");
468     bool bValid = std::regex_search(displayName, express);
469     if (bValid) {
470         MEDIA_ERR_LOG("CheckDisplayName fail %{public}s", displayName.c_str());
471     }
472     return !bValid;
473 }
474 
QueryFiles(const string & strQueryCondition,const shared_ptr<RdbStore> & rdbStore)475 unique_ptr<AbsSharedResultSet> MediaLibraryDataAbilityUtils::QueryFiles(const string &strQueryCondition,
476     const shared_ptr<RdbStore> &rdbStore)
477 {
478     vector<string> selectionArgs = {};
479 
480     if ((strQueryCondition.empty()) || (rdbStore == nullptr)) {
481         MEDIA_ERR_LOG("QueryFiles params is incorrect or rdbStore is null");
482         return nullptr;
483     }
484 
485     AbsRdbPredicates absPredicates(MEDIALIBRARY_TABLE);
486     absPredicates.SetWhereClause(strQueryCondition);
487     absPredicates.SetWhereArgs(selectionArgs);
488 
489     vector<string> columns;
490 
491     unique_ptr<AbsSharedResultSet> resultSet = rdbStore->Query(absPredicates, columns);
492 
493     return resultSet;
494 }
495 
QueryFavFiles(const shared_ptr<RdbStore> & rdbStore)496 unique_ptr<AbsSharedResultSet> MediaLibraryDataAbilityUtils::QueryFavFiles(const shared_ptr<RdbStore> &rdbStore)
497 {
498     string strQueryCondition = MEDIA_DATA_DB_IS_FAV + " = 1 AND " + MEDIA_DATA_DB_MEDIA_TYPE + " <> 8";
499     return QueryFiles(strQueryCondition, rdbStore);
500 }
501 
QueryTrashFiles(const shared_ptr<RdbStore> & rdbStore)502 unique_ptr<AbsSharedResultSet> MediaLibraryDataAbilityUtils::QueryTrashFiles(const shared_ptr<RdbStore> &rdbStore)
503 {
504     string strQueryCondition = MEDIA_DATA_DB_DATE_TRASHED + " > 0 AND " + MEDIA_DATA_DB_MEDIA_TYPE + " <> 8";
505     return QueryFiles(strQueryCondition, rdbStore);
506 }
507 
GetNetworkIdFromUri(const string & uri)508 string MediaLibraryDataAbilityUtils::GetNetworkIdFromUri(const string &uri)
509 {
510     string deviceId;
511     if (uri.empty()) {
512         return deviceId;
513     }
514     size_t pos = uri.find(MEDIALIBRARY_DATA_ABILITY_PREFIX);
515     if (pos == string::npos) {
516         return deviceId;
517     }
518 
519     string tempUri = uri.substr(MEDIALIBRARY_DATA_ABILITY_PREFIX.length());
520     if (tempUri.empty()) {
521         return deviceId;
522     }
523     MEDIA_INFO_LOG("MediaLibraryDataAbilityUtils::GetNetworkIdFromUri tempUri = %{public}s", tempUri.c_str());
524     pos = tempUri.find_first_of('/');
525     if (pos == 0 || pos == string::npos) {
526         return deviceId;
527     }
528     deviceId = tempUri.substr(0, pos);
529 
530     return deviceId;
531 }
GetDistributedAlbumSql(const string & strQueryCondition,const string & tableName)532 string MediaLibraryDataAbilityUtils::GetDistributedAlbumSql(const string &strQueryCondition, const string &tableName)
533 {
534     string distributedAlbumSql;
535     if (!strQueryCondition.empty()) {
536         distributedAlbumSql = "SELECT * FROM ( " + DISTRIBUTED_ABLUM_COLUMNS + " FROM " +
537         tableName + " " + FILE_TABLE + ", " + tableName + " " + ABLUM_TABLE +
538         DISTRIBUTED_ABLUM_WHERE_AND_GROUPBY + " )" +
539         " WHERE " + strQueryCondition;
540     } else {
541         distributedAlbumSql = "SELECT * FROM ( " + DISTRIBUTED_ABLUM_COLUMNS + " FROM " +
542         tableName + " " + FILE_TABLE + ", " + tableName + " " + ABLUM_TABLE +
543         DISTRIBUTED_ABLUM_WHERE_AND_GROUPBY + " )";
544     }
545     MEDIA_INFO_LOG("GetDistributedAlbumSql distributedAlbumSql = %{public}s", distributedAlbumSql.c_str());
546     return distributedAlbumSql;
547 }
548 } // namespace Media
549 } // namespace OHOS
550