1 /* 2 * Copyright (C) 2024 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 #ifndef MEDIALIBRARY_APP_URI_PERMISSION_OPERATIONS 17 #define MEDIALIBRARY_APP_URI_PERMISSION_OPERATIONS 18 19 #include <string> 20 #include <unordered_map> 21 #include "media_app_uri_permission_column.h" 22 #include "media_app_uri_sensitive_column.h" 23 #include "file_asset.h" 24 #include "medialibrary_command.h" 25 #include "rdb_predicates.h" 26 #include "result_set.h" 27 #include "datashare_values_bucket.h" 28 #include "medialibrary_rdb_transaction.h" 29 30 namespace OHOS { 31 namespace Media { 32 #define EXPORT __attribute__ ((visibility ("default"))) 33 34 EXPORT const std::unordered_map<std::string, int> APP_URI_PERMISSION_MEMBER_MAP = { 35 {AppUriPermissionColumn::ID, MEMBER_TYPE_INT32}, 36 {AppUriPermissionColumn::APP_ID, MEMBER_TYPE_STRING}, 37 {AppUriPermissionColumn::FILE_ID, MEMBER_TYPE_INT32}, 38 {AppUriPermissionColumn::URI_TYPE, MEMBER_TYPE_INT32}, 39 {AppUriPermissionColumn::PERMISSION_TYPE, MEMBER_TYPE_INT32}, 40 {AppUriPermissionColumn::DATE_MODIFIED, MEMBER_TYPE_INT64}, 41 {AppUriPermissionColumn::SOURCE_TOKENID, MEMBER_TYPE_INT64}, 42 {AppUriPermissionColumn::TARGET_TOKENID, MEMBER_TYPE_INT64}}; 43 44 class MediaLibraryAppUriPermissionOperations { 45 public: 46 EXPORT static const int ERROR; 47 EXPORT static const int SUCCEED; 48 EXPORT static const int ALREADY_EXIST; 49 EXPORT static const int NO_DATA_EXIST; 50 51 EXPORT static int32_t HandleInsertOperation(MediaLibraryCommand &cmd); 52 EXPORT static int32_t BatchInsert(MediaLibraryCommand &cmd, 53 const std::vector<DataShare::DataShareValuesBucket> &values); 54 EXPORT static int32_t BatchInsertInner(MediaLibraryCommand &cmd, 55 const std::vector<DataShare::DataShareValuesBucket> &values, 56 std::shared_ptr<TransactionOperations> trans); 57 EXPORT static int32_t DeleteOperation(NativeRdb::RdbPredicates &predicates); 58 EXPORT static std::shared_ptr<OHOS::NativeRdb::ResultSet> QueryOperation( 59 DataShare::DataSharePredicates &predicates, std::vector<std::string> &fetchColumns); 60 private: 61 /** 62 * query newData before insert, use this method. 63 * @param resultFlag ERROR: query newData error. 64 * NO_DATA: newData not exist in database. 65 * ALREADY_EXIST: newData already exist in database. 66 */ 67 static std::shared_ptr<OHOS::NativeRdb::ResultSet> QueryNewData( 68 OHOS::NativeRdb::ValuesBucket &valueBucket, int &resultFlag); 69 /** 70 * get the value of the int type corresponding to {@code column} from {@code valueBucket}. 71 * @param result target value 72 * @return true: Successfully obtained the value. 73 * false: failed to get the value. 74 */ 75 static bool GetIntFromValuesBucket(OHOS::NativeRdb::ValuesBucket &valueBucket, 76 const std::string &column, int &result); 77 /** 78 * @param resultSetDB must contain id value. 79 * @param valueBucketParam must contain permissionType value. 80 */ 81 static int UpdatePermissionType(std::shared_ptr<OHOS::NativeRdb::ResultSet> &resultSetDB, 82 int &permissionTypeParam, std::shared_ptr<TransactionOperations> trans = nullptr); 83 static bool IsValidPermissionType(int &permissionType); 84 static bool CanOverride(int &permissionTypeParam, int &permissionTypeDB); 85 static bool IsPhotoExist(int &photoFileId); 86 static bool IsPhotosAllExist(const std::vector<DataShare::DataShareValuesBucket> &values); 87 }; 88 } // namespace Media 89 } // namespace OHOS 90 91 #endif // MEDIALIBRARY_APP_URI_PERMISSION_OPERATIONS