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::IS_FORCE_SENSITIVE, MEMBER_TYPE_INT32}, 39 {AppUriSensitiveColumn::DATE_MODIFIED, MEMBER_TYPE_INT64}, 40 {AppUriSensitiveColumn::SOURCE_TOKENID, MEMBER_TYPE_INT64}, 41 {AppUriSensitiveColumn::TARGET_TOKENID, MEMBER_TYPE_INT64}}; 42 43 class MediaLibraryAppUriSensitiveOperations { 44 public: 45 EXPORT static const int ERROR; 46 EXPORT static const int SUCCEED; 47 EXPORT static const int ALREADY_EXIST; 48 EXPORT static const int NO_DATA_EXIST; 49 50 EXPORT static int32_t HandleInsertOperation(MediaLibraryCommand &cmd); 51 EXPORT static int32_t BatchInsert(MediaLibraryCommand &cmd, 52 const std::vector<DataShare::DataShareValuesBucket> &values); 53 EXPORT static int32_t DeleteOperation(NativeRdb::RdbPredicates &predicates); 54 EXPORT static std::shared_ptr<OHOS::NativeRdb::ResultSet> QueryOperation( 55 DataShare::DataSharePredicates &predicates, std::vector<std::string> &fetchColumns); 56 EXPORT static bool BeForceSensitive(MediaLibraryCommand &cmd, 57 const std::vector<DataShare::DataShareValuesBucket> &values); 58 private: 59 /** 60 * query newData before insert, use this method. 61 * @param resultFlag ERROR: query newData error. 62 * NO_DATA_EXIST: newData not exist in database. 63 * ALREADY_EXIST: newData already exist in database. 64 */ 65 static std::shared_ptr<OHOS::NativeRdb::ResultSet> QueryNewData( 66 OHOS::NativeRdb::ValuesBucket &valueBucket, int &resultFlag); 67 /** 68 * get the value of the int type corresponding to {@code column} from {@code valueBucket}. 69 * @param result target value 70 * @return true: Successfully obtained the value. 71 * false: failed to get the value. 72 */ 73 static bool GetIntFromValuesBucket(OHOS::NativeRdb::ValuesBucket &valueBucket, 74 const std::string &column, int &result); 75 76 /** 77 * get the value of the int type corresponding to {@code column} from {@code valueBucket}. 78 * @param result target value 79 * @return true: Successfully obtained the value. 80 * false: failed to get the value. 81 */ 82 static bool GetStringFromValuesBucket(OHOS::NativeRdb::ValuesBucket &valueBucket, 83 const std::string &column, std::string &result); 84 85 /** 86 * @param resultSetDB must contain id value. 87 * @param valueBucketParam must contain SensitiveType value. 88 */ 89 static int UpdateSensitiveType(std::shared_ptr<OHOS::NativeRdb::ResultSet> &resultSetDB, 90 int &sensitiveTypeParam); 91 92 static int UpdateSensitiveTypeAndForceHideSensitive(std::shared_ptr<OHOS::NativeRdb::ResultSet> &resultSetDB, 93 int &sensitiveTypeParam, OHOS::NativeRdb::ValuesBucket &valueBucket); 94 static bool IsValidSensitiveType(int &sensitiveType); 95 }; 96 } // namespace Media 97 } // namespace OHOS 98 99 #endif // MEDIALIBRARY_APP_URI_SENSITIVE_OPERATIONS