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(const AddPermParamInfo& info, bool asyncMode = false); 41 int32_t StartUsingPermission(AccessTokenID tokenID, int32_t pid, const std::string& permissionName); 42 int32_t CreateStateChangeCbk(uint64_t id, const std::shared_ptr<StateCustomizedCbk>& callback, 43 sptr<StateChangeCallback>& callbackWrap); 44 int32_t StartUsingPermission(AccessTokenID tokenId, int32_t pid, const std::string& permissionName, 45 const std::shared_ptr<StateCustomizedCbk>& callback); 46 int32_t StopUsingPermission(AccessTokenID tokenID, int32_t pid, const std::string& permissionName); 47 int32_t RemovePermissionUsedRecords(AccessTokenID tokenID, const std::string& deviceID); 48 int32_t GetPermissionUsedRecords(const PermissionUsedRequest& request, PermissionUsedResult& result); 49 int32_t GetPermissionUsedRecords( 50 const PermissionUsedRequest& request, const sptr<OnPermissionUsedRecordCallback>& callback); 51 int32_t RegisterPermActiveStatusCallback(const std::shared_ptr<PermActiveStatusCustomizedCbk>& callback); 52 int32_t UnRegisterPermActiveStatusCallback(const std::shared_ptr<PermActiveStatusCustomizedCbk>& callback); 53 int32_t CreateActiveStatusChangeCbk( 54 const std::shared_ptr<PermActiveStatusCustomizedCbk>& callback, 55 sptr<PermActiveStatusChangeCallback>& callbackWrap); 56 bool IsAllowedUsingPermission(AccessTokenID tokenID, const std::string& permissionName); 57 void OnRemoteDiedHandle(); 58 #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE 59 int32_t RegisterSecCompEnhance(const SecCompEnhanceData& enhance); 60 int32_t UpdateSecCompEnhance(int32_t pid, uint32_t seqNum); 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 int32_t GetPermissionUsedTypeInfos(const AccessTokenID tokenId, const std::string& permissionName, 66 std::vector<PermissionUsedTypeInfo>& results); 67 int32_t SetMutePolicy(uint32_t policyType, uint32_t callerType, bool isMute); 68 int32_t SetHapWithFGReminder(uint32_t tokenId, bool isAllowed); 69 70 private: 71 PrivacyManagerClient(); 72 73 DISALLOW_COPY_AND_MOVE(PrivacyManagerClient); 74 std::mutex proxyMutex_; 75 sptr<IPrivacyManager> proxy_ = nullptr; 76 sptr<PrivacyDeathRecipient> serviceDeathObserver_ = nullptr; 77 void InitProxy(); 78 sptr<IPrivacyManager> GetProxy(); 79 void ReleaseProxy(); 80 uint64_t GetUniqueId(uint32_t tokenId, int32_t pid) const; 81 82 private: 83 std::mutex activeCbkMutex_; 84 std::map<std::shared_ptr<PermActiveStatusCustomizedCbk>, sptr<PermActiveStatusChangeCallback>> activeCbkMap_; 85 std::mutex stateCbkMutex_; 86 std::map<uint64_t, sptr<StateChangeCallback>> stateChangeCallbackMap_; 87 }; 88 } // namespace AccessToken 89 } // namespace Security 90 } // namespace OHOS 91 #endif // PRIVACY_MANAGER_CLIENT_H 92