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 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 Dump(int32_t fd, const std::vector<std::u16string>& args) override; 64 private: 65 #ifdef POWER_MANAGER_ENABLE 66 void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 67 #endif 68 bool Initialize() const; 69 int32_t ResponseDumpCommand(int32_t fd, const std::vector<std::u16string>& args); 70 71 ServiceRunningState state_; 72 73 #ifdef POWER_MANAGER_ENABLE 74 sptr<PowerMgr::IAsyncShutdownCallback> powerShutDownCallback_ = nullptr; 75 #endif 76 }; 77 } // namespace AccessToken 78 } // namespace Security 79 } // namespace OHOS 80 #endif // PRIVACY_MANAGER_SERVICE_H 81