1 /*
2 * Copyright (c) 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 #include "app_uninstall_observer.h"
17 #include "dlp_permission.h"
18 #include "dlp_permission_log.h"
19 #include "retention_file_manager.h"
20
21 namespace OHOS {
22 namespace Security {
23 namespace DlpPermission {
24 namespace {
25 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, SECURITY_DOMAIN_DLP_PERMISSION, "AppUninstallObserver" };
26 }
27
AppUninstallObserver(const EventFwk::CommonEventSubscribeInfo & subscribeInfo)28 AppUninstallObserver::AppUninstallObserver(const EventFwk::CommonEventSubscribeInfo& subscribeInfo)
29 : CommonEventSubscriber(subscribeInfo)
30 {}
31
OnReceiveEvent(const EventFwk::CommonEventData & data)32 void AppUninstallObserver::OnReceiveEvent(const EventFwk::CommonEventData& data)
33 {
34 std::string action = data.GetWant().GetAction();
35 std::string bundleName = data.GetWant().GetBundle();
36 DLP_LOG_DEBUG(LABEL, "action %{public}s %{public}s is uninstall", action.c_str(), bundleName.c_str());
37 if (action != EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED &&
38 action != EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_FULLY_REMOVED) {
39 return;
40 }
41 if (RetentionFileManager::GetInstance().HasRetentionSandboxInfo(bundleName)) {
42 RetentionFileManager::GetInstance().RemoveRetentionState(bundleName, -1);
43 }
44 }
45
DlpEventSubSubscriber()46 DlpEventSubSubscriber::DlpEventSubSubscriber()
47 {
48 EventFwk::MatchingSkills matchingSkills;
49 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED);
50 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_FULLY_REMOVED);
51 EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills);
52 auto appUninstallObserver = std::make_shared<AppUninstallObserver>(subscribeInfo);
53 EventFwk::CommonEventManager::SubscribeCommonEvent(appUninstallObserver);
54 }
55 } // namespace DlpPermission
56 } // namespace Security
57 } // namespace OHOS
58