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