18e745fdaSopenharmony_ci/* 28e745fdaSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 38e745fdaSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48e745fdaSopenharmony_ci * you may not use this file except in compliance with the License. 58e745fdaSopenharmony_ci * You may obtain a copy of the License at 68e745fdaSopenharmony_ci * 78e745fdaSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88e745fdaSopenharmony_ci * 98e745fdaSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108e745fdaSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118e745fdaSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128e745fdaSopenharmony_ci * See the License for the specific language governing permissions and 138e745fdaSopenharmony_ci * limitations under the License. 148e745fdaSopenharmony_ci */ 158e745fdaSopenharmony_ci 168e745fdaSopenharmony_ci#ifndef NETFIREWALL_CLIENT_H 178e745fdaSopenharmony_ci#define NETFIREWALL_CLIENT_H 188e745fdaSopenharmony_ci 198e745fdaSopenharmony_ci#include <cstdint> 208e745fdaSopenharmony_ci 218e745fdaSopenharmony_ci#include "i_netfirewall_service.h" 228e745fdaSopenharmony_ci#include "netfirewall_common.h" 238e745fdaSopenharmony_ci#include "system_ability_load_callback_stub.h" 248e745fdaSopenharmony_ci 258e745fdaSopenharmony_cinamespace OHOS { 268e745fdaSopenharmony_cinamespace NetManagerStandard { 278e745fdaSopenharmony_ci// Firewall load callback 288e745fdaSopenharmony_ciclass NetFirewallLoadCallback : public SystemAbilityLoadCallbackStub { 298e745fdaSopenharmony_cipublic: 308e745fdaSopenharmony_ci void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject) override; 318e745fdaSopenharmony_ci 328e745fdaSopenharmony_ci void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; 338e745fdaSopenharmony_ci 348e745fdaSopenharmony_ci bool IsFailed(); 358e745fdaSopenharmony_ci 368e745fdaSopenharmony_ci const sptr<IRemoteObject> &GetRemoteObject() const; 378e745fdaSopenharmony_ci 388e745fdaSopenharmony_ciprivate: 398e745fdaSopenharmony_ci bool loadSAFailed_ = false; 408e745fdaSopenharmony_ci sptr<IRemoteObject> remoteObject_ = nullptr; 418e745fdaSopenharmony_ci}; 428e745fdaSopenharmony_ci 438e745fdaSopenharmony_ciclass NetFirewallClient { 448e745fdaSopenharmony_cipublic: 458e745fdaSopenharmony_ci NetFirewallClient() = default; 468e745fdaSopenharmony_ci ~NetFirewallClient() = default; 478e745fdaSopenharmony_ci NetFirewallClient(const NetFirewallClient &) = delete; 488e745fdaSopenharmony_ci NetFirewallClient &operator = (const NetFirewallClient &) = delete; 498e745fdaSopenharmony_ci 508e745fdaSopenharmony_cipublic: 518e745fdaSopenharmony_ci static NetFirewallClient &GetInstance(); 528e745fdaSopenharmony_ci 538e745fdaSopenharmony_cipublic: 548e745fdaSopenharmony_ci int32_t SetNetFirewallPolicy(const int32_t userId, const sptr<NetFirewallPolicy> &status); 558e745fdaSopenharmony_ci 568e745fdaSopenharmony_ci int32_t GetNetFirewallPolicy(const int32_t userId, sptr<NetFirewallPolicy> &status); 578e745fdaSopenharmony_ci 588e745fdaSopenharmony_ci int32_t AddNetFirewallRule(const sptr<NetFirewallRule> &rule, int32_t &result); 598e745fdaSopenharmony_ci 608e745fdaSopenharmony_ci int32_t UpdateNetFirewallRule(const sptr<NetFirewallRule> &rule); 618e745fdaSopenharmony_ci 628e745fdaSopenharmony_ci int32_t DeleteNetFirewallRule(const int32_t userId, const int32_t ruleId); 638e745fdaSopenharmony_ci 648e745fdaSopenharmony_ci int32_t GetNetFirewallRules(const int32_t userId, const sptr<RequestParam> &requestParam, 658e745fdaSopenharmony_ci sptr<FirewallRulePage> &info); 668e745fdaSopenharmony_ci 678e745fdaSopenharmony_ci int32_t GetNetFirewallRule(const int32_t userId, const int32_t ruleId, sptr<NetFirewallRule> &rule); 688e745fdaSopenharmony_ci 698e745fdaSopenharmony_ci int32_t GetInterceptRecords(const int32_t userId, const sptr<RequestParam> &requestParam, 708e745fdaSopenharmony_ci sptr<InterceptRecordPage> &info); 718e745fdaSopenharmony_ci 728e745fdaSopenharmony_ciprivate: 738e745fdaSopenharmony_ci class MonitorPcfirewallServiceDead : public IRemoteObject::DeathRecipient { 748e745fdaSopenharmony_ci public: 758e745fdaSopenharmony_ci explicit MonitorPcfirewallServiceDead(NetFirewallClient &client) : client_(client) {} 768e745fdaSopenharmony_ci ~MonitorPcfirewallServiceDead() override = default; 778e745fdaSopenharmony_ci void OnRemoteDied(const wptr<IRemoteObject> &remote) override 788e745fdaSopenharmony_ci { 798e745fdaSopenharmony_ci client_.OnRemoteDied(remote); 808e745fdaSopenharmony_ci } 818e745fdaSopenharmony_ci 828e745fdaSopenharmony_ci private: 838e745fdaSopenharmony_ci NetFirewallClient &client_; 848e745fdaSopenharmony_ci }; 858e745fdaSopenharmony_ci 868e745fdaSopenharmony_ci sptr<INetFirewallService> GetProxy(); 878e745fdaSopenharmony_ci 888e745fdaSopenharmony_ci sptr<IRemoteObject> LoadSaOnDemand(); 898e745fdaSopenharmony_ci 908e745fdaSopenharmony_ci bool RestartNetFirewallManagerSysAbility(); 918e745fdaSopenharmony_ci 928e745fdaSopenharmony_ci void OnRemoteDied(const wptr<IRemoteObject> &remote); 938e745fdaSopenharmony_ci 948e745fdaSopenharmony_ciprivate: 958e745fdaSopenharmony_ci std::mutex mutex_; 968e745fdaSopenharmony_ci sptr<INetFirewallService> netfirewallService_ = nullptr; 978e745fdaSopenharmony_ci sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr; 988e745fdaSopenharmony_ci sptr<NetFirewallLoadCallback> loadCallback_ = nullptr; 998e745fdaSopenharmony_ci}; 1008e745fdaSopenharmony_ci} // namespace NetManagerStandard 1018e745fdaSopenharmony_ci} // namespace OHOS 1028e745fdaSopenharmony_ci#endif // NETFIREWALL_CLIENT_H 103