1 /* 2 * Copyright (c) 2023-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 permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef INTERFACES_INNER_API_DLP_PERMISSION_KIT_H 17 #define INTERFACES_INNER_API_DLP_PERMISSION_KIT_H 18 19 #include <condition_variable> 20 #include <mutex> 21 #include <string> 22 #include <vector> 23 #include "cert_parcel.h" 24 #include "dlp_permission_callback.h" 25 #include "dlp_sandbox_change_callback_customize.h" 26 #include "open_dlp_file_callback_customize.h" 27 #include "parcel.h" 28 #include "permission_policy.h" 29 #include "retention_sandbox_info.h" 30 #include "visited_dlp_file_info.h" 31 #include "want.h" 32 33 namespace OHOS { 34 namespace Security { 35 namespace DlpPermission { 36 class ClientGenerateDlpCertificateCallback : public GenerateDlpCertificateCallback { 37 public: 38 ClientGenerateDlpCertificateCallback() = default; 39 virtual ~ClientGenerateDlpCertificateCallback() = default; 40 41 void OnGenerateDlpCertificate(int32_t result, const std::vector<uint8_t>& cert) override; 42 43 int32_t result_ = -1; 44 std::vector<uint8_t> cert_; 45 bool isCallBack_ = false; 46 std::mutex generateMtx_; 47 std::condition_variable generateCv_; 48 }; 49 50 class ClientParseDlpCertificateCallback : public ParseDlpCertificateCallback { 51 public: 52 ClientParseDlpCertificateCallback() = default; 53 virtual ~ClientParseDlpCertificateCallback() = default; 54 55 void OnParseDlpCertificate(int32_t result, const PermissionPolicy& policy, 56 const std::vector<uint8_t>& cert) override; 57 58 int32_t result_ = -1; 59 PermissionPolicy policy_; 60 std::vector<uint8_t> offlineCert_; 61 bool isCallBack_ = false; 62 std::mutex parseMtx_; 63 std::condition_variable parseCv_; 64 }; 65 66 class DlpPermissionKit { 67 public: 68 static int32_t GenerateDlpCertificate(const PermissionPolicy& policy, std::vector<uint8_t>& cert); 69 static int32_t ParseDlpCertificate(sptr<CertParcel>& certParcel, PermissionPolicy& policy, 70 const std::string& appId, bool offlineAccess); 71 static int32_t InstallDlpSandbox(const std::string& bundleName, DLPFileAccess access, int32_t userId, 72 SandboxInfo& sandboxInfo, const std::string& uri); 73 static int32_t UninstallDlpSandbox(const std::string& bundleName, int32_t appIndex, int32_t userId); 74 static int32_t GetSandboxExternalAuthorization(int sandboxUid, const AAFwk::Want& want, 75 SandBoxExternalAuthorType& authType); 76 static int32_t QueryDlpFileCopyableByTokenId(bool& copyable, uint32_t tokenId); 77 static int32_t QueryDlpFileAccess(DLPPermissionInfo& permInfo); 78 static int32_t IsInDlpSandbox(bool& inSandbox); 79 static int32_t GetDlpSupportFileType(std::vector<std::string>& supportFileType); 80 static int32_t RegisterDlpSandboxChangeCallback(const std::shared_ptr<DlpSandboxChangeCallbackCustomize>& callback); 81 static int32_t UnregisterDlpSandboxChangeCallback(bool& result); 82 static int32_t RegisterOpenDlpFileCallback(const std::shared_ptr<OpenDlpFileCallbackCustomize>& callback); 83 static int32_t UnRegisterOpenDlpFileCallback(const std::shared_ptr<OpenDlpFileCallbackCustomize>& callback); 84 static int32_t GetDlpGatheringPolicy(bool& isGathering); 85 static int32_t SetRetentionState(const std::vector<std::string>& docUriVec); 86 static int32_t CancelRetentionState(const std::vector<std::string>& docUriVec); 87 static int32_t GetRetentionSandboxList(const std::string& bundleName, 88 std::vector<RetentionSandBoxInfo>& retentionSandBoxInfoVec); 89 static int32_t ClearUnreservedSandbox(); 90 static int32_t GetDLPFileVisitRecord(std::vector<VisitedDLPFileInfo>& infoVec); 91 static int32_t SetMDMPolicy(const std::vector<std::string>& appIdList); 92 static int32_t GetMDMPolicy(std::vector<std::string>& appIdList); 93 static int32_t RemoveMDMPolicy(); 94 static int32_t SetSandboxAppConfig(const std::string& configInfo); 95 static int32_t CleanSandboxAppConfig(); 96 static int32_t GetSandboxAppConfig(std::string& configInfo); 97 static int32_t IsDLPFeatureProvided(bool& isProvideDLPFeature); 98 static int32_t SetReadFlag(uint32_t uid); 99 static int32_t SetDlpFeature(uint32_t dlpFeatureInfo, bool& statusSetInfo); 100 }; 101 } // namespace DlpPermission 102 } // namespace Security 103 } // namespace OHOS 104 #endif // INTERFACES_INNER_API_DLP_PERMISSION_KIT_H 105