1 /*
2 * Copyright (c) 2023-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 #ifdef MMI_ENABLE
17 #include "mmi_observer.h"
18
19 #include "nlohmann/json.hpp"
20 #include "res_common_util.h"
21 #include "res_sched_log.h"
22 #include "res_sched_mgr.h"
23 #include "res_type.h"
24
25 namespace OHOS {
26 namespace ResourceSchedule {
27 namespace {
28 static constexpr int32_t MMI_STATE = 0;
29 }
SyncBundleName(int32_t pid,int32_t uid,std::string bundleName,int32_t syncStatus)30 void MmiObserver::SyncBundleName(int32_t pid, int32_t uid, std::string bundleName, int32_t syncStatus)
31 {
32 if (!ResCommonUtil::CheckBundleName(bundleName)) {
33 RESSCHED_LOGE("mmi sync bundleName error! bundleName:%{public}s", bundleName.c_str());
34 return;
35 }
36 // mmi status, value -1: unsubscribe, value 0: nap status, value 1: subscribe, value 2: send a event.
37 RESSCHED_LOGI("mmi sync bundleName, pid:%{public}d, uid:%{public}d, bundleName:%{public}s, status:%{public}d",
38 pid, uid, bundleName.c_str(), syncStatus);
39 nlohmann::json payload;
40 payload["pid"] = std::to_string(pid);
41 payload["uid"] = std::to_string(uid);
42 payload["bundleName"] = bundleName;
43 payload["syncStatus"] = std::to_string(syncStatus);
44 ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_MMI_INPUT_STATE, MMI_STATE, payload);
45 }
46 } // namespace ResourceSchedule
47 } // namespace OHOS
48 #endif
49