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