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 #include "privacy_manager_stub.h" 22 #include "iremote_object.h" 23 #include "nocopyable.h" 24 #ifdef POWER_MANAGER_ENABLE 25 #include "shutdown/iasync_shutdown_callback.h" 26 #endif 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(AccessTokenID tokenId, const std::string& permissionName, 43 int32_t successCount, int32_t failCount, bool asyncMode = false) override; 44 int32_t StartUsingPermission(AccessTokenID tokenId, const std::string& permissionName) override; 45 int32_t StartUsingPermission(AccessTokenID tokenId, const std::string& permissionName, 46 const sptr<IRemoteObject>& callback) override; 47 int32_t StopUsingPermission(AccessTokenID tokenId, const std::string& permissionName) override; 48 int32_t RemovePermissionUsedRecords(AccessTokenID tokenId, const std::string& deviceID) override; 49 int32_t GetPermissionUsedRecords( 50 const PermissionUsedRequestParcel& request, PermissionUsedResultParcel& result) override; 51 int32_t GetPermissionUsedRecords( 52 const PermissionUsedRequestParcel& request, const sptr<OnPermissionUsedRecordCallback>& callback) override; 53 int32_t RegisterPermActiveStatusCallback( 54 std::vector<std::string>& permList, const sptr<IRemoteObject>& callback) override; 55 int32_t UnRegisterPermActiveStatusCallback(const sptr<IRemoteObject>& callback) override; 56 #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE 57 int32_t RegisterSecCompEnhance(const SecCompEnhanceDataParcel& enhanceParcel) override; 58 int32_t DepositSecCompEnhance(const std::vector<SecCompEnhanceDataParcel>& enhanceParcelList) override; 59 int32_t RecoverSecCompEnhance(std::vector<SecCompEnhanceDataParcel>& enhanceParcelList) override; 60 #endif 61 bool IsAllowedUsingPermission(AccessTokenID tokenId, const std::string& permissionName) override; 62 int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override; 63 private: 64 #ifdef POWER_MANAGER_ENABLE 65 void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 66 #endif 67 bool Initialize() const; 68 int32_t ResponseDumpCommand(int32_t fd, const std::vector<std::u16string>& args); 69 70 ServiceRunningState state_; 71 72 #ifdef POWER_MANAGER_ENABLE 73 sptr<PowerMgr::IAsyncShutdownCallback> powerShutDownCallback_ = nullptr; 74 #endif 75 }; 76 } // namespace AccessToken 77 } // namespace Security 78 } // namespace OHOS 79 #endif // PRIVACY_MANAGER_SERVICE_H 80