• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 PRIVACY_MANAGER_CLIENT_H
17 #define PRIVACY_MANAGER_CLIENT_H
18 
19 #include <map>
20 #include <mutex>
21 #include <string>
22 #include <vector>
23 
24 #include "i_privacy_manager.h"
25 #include "perm_active_status_change_callback.h"
26 #include "perm_active_status_customized_cbk.h"
27 #include "privacy_death_recipient.h"
28 #include "state_change_callback.h"
29 #include "state_customized_cbk.h"
30 
31 namespace OHOS {
32 namespace Security {
33 namespace AccessToken {
34 class PrivacyManagerClient final {
35 public:
36     static PrivacyManagerClient& GetInstance();
37 
38     virtual ~PrivacyManagerClient();
39 
40     int32_t AddPermissionUsedRecord(AccessTokenID tokenID, const std::string& permissionName,
41         int32_t successCount, int32_t failCount, bool asyncMode = false);
42     int32_t StartUsingPermission(AccessTokenID tokenID, const std::string& permissionName);
43     int32_t CreateStateChangeCbk(const std::shared_ptr<StateCustomizedCbk>& callback,
44         sptr<StateChangeCallback>& callbackWrap);
45     int32_t StartUsingPermission(AccessTokenID tokenId, const std::string& permissionName,
46         const std::shared_ptr<StateCustomizedCbk>& callback);
47     int32_t StopUsingPermission(AccessTokenID tokenID, const std::string& permissionName);
48     int32_t RemovePermissionUsedRecords(AccessTokenID tokenID, const std::string& deviceID);
49     int32_t GetPermissionUsedRecords(const PermissionUsedRequest& request, PermissionUsedResult& result);
50     int32_t GetPermissionUsedRecords(
51         const PermissionUsedRequest& request, const sptr<OnPermissionUsedRecordCallback>& callback);
52     int32_t RegisterPermActiveStatusCallback(const std::shared_ptr<PermActiveStatusCustomizedCbk>& callback);
53     int32_t UnRegisterPermActiveStatusCallback(const std::shared_ptr<PermActiveStatusCustomizedCbk>& callback);
54     int32_t CreateActiveStatusChangeCbk(
55         const std::shared_ptr<PermActiveStatusCustomizedCbk>& callback,
56         sptr<PermActiveStatusChangeCallback>& callbackWrap);
57     bool IsAllowedUsingPermission(AccessTokenID tokenID, const std::string& permissionName);
58     void OnRemoteDiedHandle();
59 #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE
60     int32_t RegisterSecCompEnhance(const SecCompEnhanceData& enhance);
61     int32_t GetSecCompEnhance(int32_t pid, SecCompEnhanceData& enhance);
62     int32_t GetSpecialSecCompEnhance(const std::string& bundleName,
63         std::vector<SecCompEnhanceData>& enhanceList);
64 #endif
65 
66 private:
67     PrivacyManagerClient();
68 
69     DISALLOW_COPY_AND_MOVE(PrivacyManagerClient);
70     std::mutex proxyMutex_;
71     sptr<IPrivacyManager> proxy_ = nullptr;
72     sptr<PrivacyDeathRecipient> serviceDeathObserver_ = nullptr;
73     void InitProxy();
74     sptr<IPrivacyManager> GetProxy();
75 
76 private:
77     std::mutex activeCbkMutex_;
78     std::map<std::shared_ptr<PermActiveStatusCustomizedCbk>, sptr<PermActiveStatusChangeCallback>> activeCbkMap_;
79     std::mutex stateCbkMutex_;
80     sptr<StateChangeCallback> stateChangeCallback_ = nullptr;
81 };
82 } // namespace AccessToken
83 } // namespace Security
84 } // namespace OHOS
85 #endif // PRIVACY_MANAGER_CLIENT_H
86