1 /* 2 * Copyright (c) 2023 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 RETENTION_FILE_MANAGER_H 17 #define RETENTION_FILE_MANAGER_H 18 19 #include <mutex> 20 #include <map> 21 22 #include "file_operator.h" 23 #include "nlohmann/json.hpp" 24 #include "sandbox_json_manager.h" 25 26 namespace OHOS { 27 namespace Security { 28 namespace DlpPermission { 29 using Json = nlohmann::json; 30 31 class RetentionFileManager { 32 public: 33 virtual ~RetentionFileManager(); 34 static RetentionFileManager& GetInstance(); 35 36 int32_t AddSandboxInfo(const RetentionInfo& retentionInfo); 37 int32_t DelSandboxInfo(uint32_t tokenId); 38 bool CanUninstall(const uint32_t& tokenId); 39 int32_t UpdateSandboxInfo(const std::set<std::string>& docUriSet, RetentionInfo& info, bool isRetention); 40 int32_t RemoveRetentionState(const std::string& bundleName, const int32_t& appIndex); 41 int32_t GetRetentionSandboxList(const std::string& bundleName, 42 std::vector<RetentionSandBoxInfo>& retentionSandBoxInfoVec, bool isRetention); 43 bool HasRetentionSandboxInfo(const std::string& bundleName); 44 int32_t ClearUnreservedSandbox(); 45 int32_t UpdateReadFlag(uint32_t tokenId); 46 int32_t GetBundleNameSetByUserId(const int32_t userId, std::set<std::string>& bundleNameSet); 47 int32_t RemoveRetentionInfoByUserId(const int32_t userId, const std::set<std::string>& bundleNameSet); 48 private: 49 RetentionFileManager(); 50 DISALLOW_COPY_AND_MOVE(RetentionFileManager); 51 bool Init(); 52 int32_t UpdateFile(const int32_t& jsonRes); 53 bool hasInit_; 54 std::shared_ptr<FileOperator> fileOperator_; 55 std::recursive_mutex mutex_; 56 std::shared_ptr<SandboxJsonManager> sandboxJsonManager_; 57 }; 58 } // namespace DlpPermission 59 } // namespace Security 60 } // namespace OHOS 61 #endif // RETENTION_FILE_MANAGER_H