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_SERVICE_H 17 #define PRIVACY_MANAGER_SERVICE_H 18 19 #include <string> 20 21 #ifdef EVENTHANDLER_ENABLE 22 #include "access_event_handler.h" 23 #endif 24 #include "privacy_manager_stub.h" 25 #include "iremote_object.h" 26 #include "nocopyable.h" 27 #include "proxy_death_handler.h" 28 #include "singleton.h" 29 #include "system_ability.h" 30 31 namespace OHOS { 32 namespace Security { 33 namespace AccessToken { 34 enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; 35 class PrivacyManagerService final : public SystemAbility, public PrivacyManagerStub { 36 DECLARE_DELAYED_SINGLETON(PrivacyManagerService); 37 DECLEAR_SYSTEM_ABILITY(PrivacyManagerService); 38 39 public: 40 void OnStart() override; 41 void OnStop() override; 42 43 int32_t AddPermissionUsedRecord(const AddPermParamInfoParcel& infoParcel, bool asyncMode = false) override; 44 int32_t StartUsingPermission(const PermissionUsedTypeInfoParcel &infoParcel, 45 const sptr<IRemoteObject>& anonyStub) override; 46 int32_t StartUsingPermission(const PermissionUsedTypeInfoParcel &infoParcel, 47 const sptr<IRemoteObject>& callback, const sptr<IRemoteObject>& anonyStub) override; 48 int32_t SetPermissionUsedRecordToggleStatus(int32_t userID, bool status) override; 49 int32_t GetPermissionUsedRecordToggleStatus(int32_t userID, bool& status) override; 50 int32_t StopUsingPermission(AccessTokenID tokenId, int32_t pid, const std::string& permissionName) override; 51 int32_t RemovePermissionUsedRecords(AccessTokenID tokenId) override; 52 int32_t GetPermissionUsedRecords( 53 const PermissionUsedRequestParcel& request, PermissionUsedResultParcel& result) override; 54 int32_t GetPermissionUsedRecords( 55 const PermissionUsedRequestParcel& request, const sptr<OnPermissionUsedRecordCallback>& callback) override; 56 int32_t RegisterPermActiveStatusCallback( 57 std::vector<std::string>& permList, const sptr<IRemoteObject>& callback) override; 58 int32_t UnRegisterPermActiveStatusCallback(const sptr<IRemoteObject>& callback) override; 59 #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE 60 int32_t RegisterSecCompEnhance(const SecCompEnhanceDataParcel& enhanceParcel) override; 61 int32_t UpdateSecCompEnhance(int32_t pid, uint32_t seqNum) override; 62 int32_t GetSecCompEnhance(int32_t pid, SecCompEnhanceDataParcel& enhanceParcel) override; 63 int32_t GetSpecialSecCompEnhance(const std::string& bundleName, 64 std::vector<SecCompEnhanceDataParcel>& enhanceParcelList) override; 65 #endif 66 bool IsAllowedUsingPermission(AccessTokenID tokenId, const std::string& permissionName, int32_t pid) override; 67 int32_t GetPermissionUsedTypeInfos(const AccessTokenID tokenId, const std::string& permissionName, 68 std::vector<PermissionUsedTypeInfoParcel>& resultsParcel) override; 69 int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override; 70 int32_t SetMutePolicy(uint32_t policyType, uint32_t callerType, bool isMute, AccessTokenID tokenID) override; 71 int32_t SetHapWithFGReminder(uint32_t tokenId, bool isAllowed) override; 72 private: 73 void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 74 bool Initialize(); 75 int32_t ResponseDumpCommand(int32_t fd, const std::vector<std::u16string>& args); 76 std::shared_ptr<ProxyDeathHandler> GetProxyDeathHandler(); 77 void ProcessProxyDeathStub(const sptr<IRemoteObject>& anonyStub, int32_t callerPid); 78 void ReleaseDeathStub(int32_t callerPid); 79 80 ServiceRunningState state_; 81 82 #ifdef EVENTHANDLER_ENABLE 83 std::shared_ptr<AppExecFwk::EventRunner> eventRunner_; 84 std::shared_ptr<AccessEventHandler> eventHandler_; 85 #endif 86 std::mutex deathHandlerMutex_; 87 std::shared_ptr<ProxyDeathHandler> proxyDeathHandler_; 88 }; 89 } // namespace AccessToken 90 } // namespace Security 91 } // namespace OHOS 92 #endif // PRIVACY_MANAGER_SERVICE_H 93