1 /* 2 * Copyright (C) 2024 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 #include "net_policy_listener.h" 17 18 #include "net_manager_constants.h" 19 #include "net_mgr_log_wrapper.h" 20 #include "netmanager_base_common_utils.h" 21 22 namespace OHOS { 23 namespace NetManagerStandard { 24 namespace { 25 using namespace OHOS::EventFwk; 26 constexpr const char* UID = "uid"; 27 }; 28 NetPolicyListener(const EventFwk::CommonEventSubscribeInfo & sp,std::shared_ptr<NetPolicyService> NetPolicy)29NetPolicyListener::NetPolicyListener(const EventFwk::CommonEventSubscribeInfo &sp, 30 std::shared_ptr<NetPolicyService> NetPolicy) 31 : CommonEventSubscriber(sp) 32 { 33 netPolicyService_ = NetPolicy; 34 } 35 OnReceiveEvent(const CommonEventData & data)36void NetPolicyListener::OnReceiveEvent(const CommonEventData &data) 37 { 38 auto &want = data.GetWant(); 39 std::string wantAction = want.GetAction(); 40 if (wantAction == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED) { 41 uint32_t uid = want.GetIntParam(UID, 0); 42 netPolicyService_->GetNetAccessPolicyDBHandler().DeleteByUid(uid); 43 netPolicyService_->DeleteNetworkAccessPolicy(uid); 44 NETMGR_LOG_I("packet remove uid:[%{public}d]", uid); 45 } 46 } 47 } // namespace NetManagerStandard 48 } // namespace OHOS 49