• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 DLP_PERMISSION_CLIENT_H
17 #define DLP_PERMISSION_CLIENT_H
18 
19 #include <condition_variable>
20 #include <mutex>
21 #include <string>
22 #include <vector>
23 
24 #include "dlp_permission_death_recipient.h"
25 #include "dlp_permission.h"
26 #include "idlp_permission_service.h"
27 #include "dlp_permission_callback.h"
28 #include "dlp_sandbox_change_callback_customize.h"
29 #include "dlp_sandbox_change_callback.h"
30 #include "open_dlp_file_callback_customize.h"
31 #include "open_dlp_file_callback.h"
32 #include "nocopyable.h"
33 
34 namespace OHOS {
35 namespace Security {
36 namespace DlpPermission {
37 class DlpPermissionClient final {
38 public:
39     static DlpPermissionClient& GetInstance();
40 
41     int32_t GenerateDlpCertificate(
42         const PermissionPolicy& policy, std::shared_ptr<GenerateDlpCertificateCallback> callback);
43     int32_t ParseDlpCertificate(sptr<CertParcel>& certParcel, std::shared_ptr<ParseDlpCertificateCallback> callback,
44         const std::string& appId, bool offlineAccess);
45     int32_t InstallDlpSandbox(const std::string& bundleName, DLPFileAccess dlpFileAccess, int32_t userId,
46         SandboxInfo& sandboxInfo, const std::string& uri);
47     int32_t UninstallDlpSandbox(const std::string& bundleName, int32_t appIndex, int32_t userId);
48     int32_t GetSandboxExternalAuthorization(int sandboxUid, const AAFwk::Want& want,
49         SandBoxExternalAuthorType& authType);
50     int32_t QueryDlpFileCopyableByTokenId(bool& copyable, uint32_t tokenId);
51     int32_t QueryDlpFileAccess(DLPPermissionInfo& permInfo);
52     int32_t IsInDlpSandbox(bool& inSandbox);
53     int32_t GetDlpSupportFileType(std::vector<std::string>& supportFileType);
54     int32_t RegisterDlpSandboxChangeCallback(const std::shared_ptr<DlpSandboxChangeCallbackCustomize>& customizedCb);
55     int32_t UnregisterDlpSandboxChangeCallback(bool& result);
56     int32_t RegisterOpenDlpFileCallback(const std::shared_ptr<OpenDlpFileCallbackCustomize>& callback);
57     int32_t UnRegisterOpenDlpFileCallback(const std::shared_ptr<OpenDlpFileCallbackCustomize>& callback);
58     int32_t GetDlpGatheringPolicy(bool& isGathering);
59     int32_t SetRetentionState(const std::vector<std::string>& docUriVec);
60     int32_t CancelRetentionState(const std::vector<std::string>& docUriVec);
61     int32_t GetRetentionSandboxList(const std::string& bundleName,
62         std::vector<RetentionSandBoxInfo>& retentionSandBoxInfoVec);
63     int32_t ClearUnreservedSandbox();
64     int32_t GetDLPFileVisitRecord(std::vector<VisitedDLPFileInfo>& infoVec);
65     int32_t SetMDMPolicy(const std::vector<std::string>& appIdList);
66     int32_t GetMDMPolicy(std::vector<std::string>& appIdList);
67     int32_t RemoveMDMPolicy();
68     int32_t SetSandboxAppConfig(const std::string& configInfo);
69     int32_t CleanSandboxAppConfig();
70     int32_t GetSandboxAppConfig(std::string& configInfo);
71     int32_t IsDLPFeatureProvided(bool& isProvideDLPFeature);
72     int32_t SetReadFlag(uint32_t uid);
73     void OnRemoteDiedHandle();
74     void CleanUpResource();
75     int32_t SetDlpFeature(uint32_t dlpFeatureInfo, bool& statusSetInfo);
76 
77 private:
78     DlpPermissionClient();
79     virtual ~DlpPermissionClient();
80     DISALLOW_COPY_AND_MOVE(DlpPermissionClient);
81     int32_t CreateDlpSandboxChangeCallback(const std::shared_ptr<DlpSandboxChangeCallbackCustomize> &customizedCb,
82         sptr<DlpSandboxChangeCallback> &callback);
83     int32_t CreateOpenDlpFileCallback(
84         const std::shared_ptr<OpenDlpFileCallbackCustomize>& customizedCb, sptr<OpenDlpFileCallback>& callback);
85     void GetDlpPermissionSa();
86     void LoadDlpPermissionSa();
87 
88     sptr<IDlpPermissionService> GetProxy(bool doLoadSa);
89     void GetProxyFromRemoteObject(const sptr<IRemoteObject>& remoteObject);
90 
91     std::mutex proxyMutex_;
92     sptr<IDlpPermissionService> proxy_ = nullptr;
93     sptr<DlpPermissionDeathRecipient> serviceDeathObserver_ = nullptr;
94     std::mutex callbackMutex_;
95     std::map<std::shared_ptr<OpenDlpFileCallbackCustomize>, sptr<OpenDlpFileCallback>> callbackMap_;
96 };
97 }  // namespace DlpPermission
98 }  // namespace Security
99 }  // namespace OHOS
100 #endif  // DLP_PERMISSION_CLIENT_H
101