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