1 /* 2 * Copyright (c) 2025 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 17 #include "common_event_manager.h" 18 #include "common_event_support.h" 19 #include "comm_log.h" 20 #include "softbus_error_code.h" 21 #include "br_proxy_server_manager.h" 22 #include "trans_log.h" 23 24 using namespace OHOS::AppExecFwk; 25 using namespace OHOS::EventFwk; 26 class HapUninstallObserver : public CommonEventSubscriber { 27 public: HapUninstallObserver(const CommonEventSubscribeInfo & sp)28 explicit HapUninstallObserver(const CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) {} 29 OnReceiveEvent(const CommonEventData & data)30 void OnReceiveEvent(const CommonEventData &data) override 31 { 32 auto &want = data.GetWant(); 33 std::string wantAction = want.GetAction(); 34 TRANS_LOGI(TRANS_SVC, "[br_proxy] wantAction %{public}s", wantAction.c_str()); 35 if (wantAction == CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED || 36 wantAction == CommonEventSupport::COMMON_EVENT_BUNDLE_REMOVED || 37 wantAction == CommonEventSupport::COMMON_EVENT_PACKAGE_FULLY_REMOVED) { 38 std::string bundleName = want.GetBundle(); 39 if (IsBrProxy(bundleName.c_str())) { 40 CloseAllConnect(); 41 } 42 } 43 } 44 }; 45 RegisterHapUninstallEvent(void)46extern "C" int32_t RegisterHapUninstallEvent(void) 47 { 48 MatchingSkills matchingSkills; 49 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); 50 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_BUNDLE_REMOVED); 51 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_PACKAGE_FULLY_REMOVED); 52 53 CommonEventSubscribeInfo subscriberInfo(matchingSkills); 54 std::shared_ptr<HapUninstallObserver> subscriber = std::make_shared<HapUninstallObserver>(subscriberInfo); 55 56 CommonEventManager::SubscribeCommonEvent(subscriber); 57 58 return SOFTBUS_OK; 59 }