1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"){return 0;} 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 #ifndef OHOS_MEDIALIBRARY_PERMISSION_HEADER_REQ_H 16 #define OHOS_MEDIALIBRARY_PERMISSION_HEADER_REQ_H 17 18 #include <stdint.h> 19 #include <string> 20 #include <unordered_map> 21 #include "media_permission_policy_type.h" 22 23 namespace OHOS::Media { 24 #define EXPORT __attribute__ ((visibility ("default"))) 25 class PermissionHeaderReq { 26 private: 27 // Three groups of header authentication parameters 28 // accross account check 29 int32_t userId_ = -1; 30 // db permission check 31 std::string fileId_ = ""; 32 int32_t uriType_ = -1; 33 //openfile api header check 34 std::string openUri_ = ""; 35 std::string openMode_ = ""; 36 37 std::vector<std::vector<PermissionType>> permissionPolicy_; 38 bool isDBBypass_ = false; 39 40 std::unordered_map<std::string, std::string> headerReq_; 41 void setUserId(int32_t userId); 42 void setPermissionPolicy(std::vector<std::vector<PermissionType>>& permissionPolicy); 43 void setDBBypass(bool isDBBypass); 44 public: 45 PermissionHeaderReq() = default; PermissionHeaderReq(int32_t userId)46 PermissionHeaderReq(int32_t userId) : userId_(userId) {} 47 PermissionHeaderReq(const std::string& fileId, int32_t uriType); 48 PermissionHeaderReq(const std::string& openUri, const std::string& openMode); 49 PermissionHeaderReq(const std::string& fileId, int32_t uriType, 50 const std::string& openUri, const std::string& openMode); 51 EXPORT static PermissionHeaderReq convertToPermissionHeaderReq(const std::unordered_map<std::string, 52 std::string>& req, int32_t userId, std::vector<std::vector<PermissionType>>& permissionPolicy, bool isDBBypass); 53 std::string getFileId() const; 54 int32_t getUriType() const; 55 std::string getOpenUri() const; 56 std::string getOpenMode() const; 57 int32_t getUserId() const; 58 std::vector<std::vector<PermissionType>> getPermissionPolicy() const; 59 bool getIsDBBypass() const; 60 EXPORT static const std::string FILE_ID_KEY; 61 EXPORT static const std::string URI_TYPE_KEY; 62 EXPORT static const std::string OPEN_URI_KEY; 63 EXPORT static const std::string OPEN_MODE_KEY; 64 }; 65 } // namespace OHOS::Media 66 #endif // OHOS_MEDIALIBRARY_PERMISSION_HEADER_REQ_H