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 Sensitives and 13 * limitations under the License. 14 */ 15 16 #ifndef MEDIALIBRARY_APP_URI_SENSITIVE_OPERATIONS 17 #define MEDIALIBRARY_APP_URI_SENSITIVE_OPERATIONS 18 19 #include <string> 20 #include <unordered_map> 21 #include "media_app_uri_sensitive_column.h" 22 #include "media_app_uri_permission_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 29 namespace OHOS { 30 namespace Media { 31 32 EXPORT const std::unordered_map<std::string, int> APP_URI_SENSITIVE_MEMBER_MAP = { 33 {AppUriSensitiveColumn::ID, MEMBER_TYPE_INT32}, 34 {AppUriSensitiveColumn::APP_ID, MEMBER_TYPE_STRING}, 35 {AppUriSensitiveColumn::FILE_ID, MEMBER_TYPE_INT32}, 36 {AppUriSensitiveColumn::URI_TYPE, MEMBER_TYPE_INT32}, 37 {AppUriSensitiveColumn::HIDE_SENSITIVE_TYPE, MEMBER_TYPE_INT32}, 38 {AppUriSensitiveColumn::DATE_MODIFIED, MEMBER_TYPE_INT64}}; 39 40 class MediaLibraryAppUriSensitiveOperations { 41 public: 42 EXPORT static const int ERROR; 43 EXPORT static const int SUCCEED; 44 EXPORT static const int ALREADY_EXIST; 45 EXPORT static const int NO_DATA; 46 47 EXPORT static int32_t HandleInsertOperation(MediaLibraryCommand &cmd); 48 EXPORT static int32_t BatchInsert(MediaLibraryCommand &cmd, 49 const std::vector<DataShare::DataShareValuesBucket> &values); 50 EXPORT static int32_t DeleteOperation(NativeRdb::RdbPredicates &predicates); 51 EXPORT static std::shared_ptr<OHOS::NativeRdb::ResultSet> QueryOperation( 52 DataShare::DataSharePredicates &predicates, std::vector<std::string> &fetchColumns); 53 private: 54 /** 55 * query newData before insert, use this method. 56 * @param resultFlag ERROR: query newData error. 57 * NO_DATA: newData not exist in database. 58 * ALREADY_EXIST: newData already exist in database. 59 */ 60 static std::shared_ptr<OHOS::NativeRdb::ResultSet> QueryNewData( 61 OHOS::NativeRdb::ValuesBucket &valueBucket, int &resultFlag); 62 /** 63 * get the value of the int type corresponding to {@code column} from {@code valueBucket}. 64 * @param result target value 65 * @return true: Successfully obtained the value. 66 * false: failed to get the value. 67 */ 68 static bool GetIntFromValuesBucket(OHOS::NativeRdb::ValuesBucket &valueBucket, 69 const std::string &column, int &result); 70 71 /** 72 * get the value of the int type corresponding to {@code column} from {@code valueBucket}. 73 * @param result target value 74 * @return true: Successfully obtained the value. 75 * false: failed to get the value. 76 */ 77 static bool GetStringFromValuesBucket(OHOS::NativeRdb::ValuesBucket &valueBucket, 78 const std::string &column, std::string &result); 79 80 /** 81 * @param resultSetDB must contain id value. 82 * @param valueBucketParam must contain SensitiveType value. 83 */ 84 static int UpdateSensitiveType(std::shared_ptr<OHOS::NativeRdb::ResultSet> &resultSetDB, 85 int &sensitiveTypeParam); 86 static bool IsValidSensitiveType(int &sensitiveType); 87 }; 88 } // namespace Media 89 } // namespace OHOS 90 91 #endif // MEDIALIBRARY_APP_URI_SENSITIVE_OPERATIONS