• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 "iprivacy_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 "proxy_death_callback.h"
29 #include "state_change_callback.h"
30 #include "state_customized_cbk.h"
31 
32 namespace OHOS {
33 namespace Security {
34 namespace AccessToken {
35 class PrivacyManagerClient final {
36 public:
37     static PrivacyManagerClient& GetInstance();
38 
39     virtual ~PrivacyManagerClient();
40 
41     int32_t AddPermissionUsedRecord(const AddPermParamInfo& info, bool asyncMode = false);
42     int32_t SetPermissionUsedRecordToggleStatus(int32_t userID, bool status);
43     int32_t GetPermissionUsedRecordToggleStatus(int32_t userID, bool& status);
44     int32_t StartUsingPermission(AccessTokenID tokenID, int32_t pid, const std::string& permissionName,
45         PermissionUsedType type);
46     int32_t CreateStateChangeCbk(uint64_t id, const std::shared_ptr<StateCustomizedCbk>& callback,
47         sptr<StateChangeCallback>& callbackWrap);
48     int32_t StartUsingPermission(AccessTokenID tokenId, int32_t pid, const std::string& permissionName,
49         const std::shared_ptr<StateCustomizedCbk>& callback, PermissionUsedType type);
50     int32_t StopUsingPermission(AccessTokenID tokenID, int32_t pid, const std::string& permissionName);
51     int32_t RemovePermissionUsedRecords(AccessTokenID tokenID);
52     int32_t GetPermissionUsedRecords(const PermissionUsedRequest& request, PermissionUsedResult& result);
53     int32_t GetPermissionUsedRecords(
54         const PermissionUsedRequest& request, const sptr<OnPermissionUsedRecordCallback>& callback);
55     int32_t RegisterPermActiveStatusCallback(const std::shared_ptr<PermActiveStatusCustomizedCbk>& callback);
56     int32_t UnRegisterPermActiveStatusCallback(const std::shared_ptr<PermActiveStatusCustomizedCbk>& callback);
57     int32_t CreateActiveStatusChangeCbk(
58         const std::shared_ptr<PermActiveStatusCustomizedCbk>& callback,
59         sptr<PermActiveStatusChangeCallback>& callbackWrap);
60     bool IsAllowedUsingPermission(AccessTokenID tokenID, const std::string& permissionName, int32_t pid);
61     void OnRemoteDiedHandle();
62     int32_t GetPermissionUsedTypeInfos(const AccessTokenID tokenId, const std::string& permissionName,
63         std::vector<PermissionUsedTypeInfo>& results);
64     int32_t SetMutePolicy(uint32_t policyType, uint32_t callerType, bool isMute, AccessTokenID tokenID);
65     int32_t SetHapWithFGReminder(uint32_t tokenId, bool isAllowed);
66 
67 private:
68     PrivacyManagerClient();
69 
70     DISALLOW_COPY_AND_MOVE(PrivacyManagerClient);
71     std::mutex proxyMutex_;
72     sptr<IPrivacyManager> proxy_ = nullptr;
73     sptr<PrivacyDeathRecipient> serviceDeathObserver_ = nullptr;
74     void InitProxy();
75     sptr<IPrivacyManager> GetProxy();
76     void ReleaseProxy();
77     uint64_t GetUniqueId(uint32_t tokenId, int32_t pid) const;
78     sptr<ProxyDeathCallBack> GetAnonyStub();
79 
80 private:
81     std::mutex activeCbkMutex_;
82     std::map<std::shared_ptr<PermActiveStatusCustomizedCbk>, sptr<PermActiveStatusChangeCallback>> activeCbkMap_;
83     std::mutex stateCbkMutex_;
84     std::map<uint64_t, sptr<StateChangeCallback>> stateChangeCallbackMap_;
85     std::mutex stubMutex_;
86     sptr<ProxyDeathCallBack> anonyStub_ = nullptr;
87 };
88 } // namespace AccessToken
89 } // namespace Security
90 } // namespace OHOS
91 #endif // PRIVACY_MANAGER_CLIENT_H
92