1 /*
2 * Copyright (c) 2022 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 "form_bundle_event_callback.h"
17
18 namespace OHOS {
19 namespace AppExecFwk {
20 namespace {
21 const std::string BMS_EVENT_ADDITIONAL_INFO_CHANGED = "bms.event.ADDITIONAL_INFO_CHANGED";
22 } // namespace
23
OnReceiveEvent(const EventFwk::CommonEventData eventData)24 void FormBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData eventData)
25 {
26 const AAFwk::Want& want = eventData.GetWant();
27 // action contains the change type of haps.
28 std::string action = want.GetAction();
29 std::string bundleName = want.GetElement().GetBundleName();
30 int userId = want.GetIntParam(KEY_USER_ID, 0);
31 // verify data
32 if (action.empty() || bundleName.empty()) {
33 HILOG_ERROR("%{public}s failed, empty action/bundleName", __func__);
34 return;
35 }
36 HILOG_INFO("%{public}s, action:%{public}s.", __func__, action.c_str());
37
38 wptr<FormBundleEventCallback> weakThis = this;
39 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED ||
40 action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED) {
41 // install or update
42 HILOG_INFO("%{public}s, bundle changed, bundleName: %{public}s", __func__, bundleName.c_str());
43 formEventHelper_.HandleBundleFormInfoChanged(bundleName, userId);
44 formEventHelper_.HandleProviderUpdated(bundleName, userId);
45 } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED) {
46 // uninstall module/bundle
47 HILOG_INFO("%{public}s, bundle removed, bundleName: %{public}s", __func__, bundleName.c_str());
48 formEventHelper_.HandleBundleFormInfoRemoved(bundleName, userId);
49 formEventHelper_.HandleProviderRemoved(bundleName, userId);
50 } else if (action == BMS_EVENT_ADDITIONAL_INFO_CHANGED) {
51 // additional info changed
52 HILOG_INFO("Additional info changed, bundleName: %{public}s", bundleName.c_str());
53 formEventHelper_.HandleAdditionalInfoChanged(bundleName);
54 }
55 }
56
57 } // namespace AppExecFwk
58 } // namespace OHOS