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 explicit RetentionFileManager(); 34 virtual ~RetentionFileManager(); 35 static RetentionFileManager& GetInstance(); 36 37 int32_t AddSandboxInfo(const RetentionInfo& retentionInfo); 38 int32_t DelSandboxInfo(uint32_t tokenId); 39 bool CanUninstall(const uint32_t& tokenId); 40 int32_t UpdateSandboxInfo(const std::set<std::string>& docUriSet, RetentionInfo& info, bool isRetention); 41 int32_t RemoveRetentionState(const std::string& bundleName, const int32_t& appIndex); 42 int32_t GetRetentionSandboxList(const std::string& bundleName, 43 std::vector<RetentionSandBoxInfo>& retentionSandBoxInfoVec, bool isRetention); 44 bool HasRetentionSandboxInfo(const std::string& bundleName); 45 int32_t ClearUnreservedSandbox(); 46 int32_t UpdateReadFlag(uint32_t tokenId); 47 int32_t GetBundleNameSetByUserId(const int32_t userId, std::set<std::string>& bundleNameSet); 48 int32_t RemoveRetentionInfoByUserId(const int32_t userId, const std::set<std::string>& bundleNameSet); 49 private: 50 bool Init(); 51 int32_t UpdateFile(const int32_t& jsonRes); 52 bool hasInit; 53 std::shared_ptr<FileOperator> fileOperator_; 54 std::recursive_mutex mutex_; 55 std::shared_ptr<SandboxJsonManager> sandboxJsonManager_; 56 }; 57 } // namespace DlpPermission 58 } // namespace Security 59 } // namespace OHOS 60 #endif // RETENTION_FILE_MANAGER_H