1 /*
2  * Copyright (C) 2024 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 #include "uc_render_state_observer.h"
16 
17 #include "hiview_logger.h"
18 #include "process_status.h"
19 
20 namespace OHOS {
21 namespace HiviewDFX {
22 DEFINE_LOG_TAG("HiView-UnifiedCollector");
23 namespace {
24 using namespace OHOS::HiviewDFX::UCollectUtil;
25 
GetProcessState(int32_t state)26 ProcessState GetProcessState(int32_t state)
27 {
28     const std::unordered_map<int32_t, ProcessState> renderStates = {
29         {0, FOREGROUND},
30         {1, BACKGROUND},
31     };
32     if (renderStates.find(state) == renderStates.end()) {
33         HIVIEW_LOGD("invalid render state=%{public}d", state);
34         return INVALID;
35     }
36     return renderStates.at(state);
37 }
38 }
39 
OnRenderStateChanged(const AppExecFwk::RenderStateData & renderStateData)40 void UcRenderStateObserver::OnRenderStateChanged(const AppExecFwk::RenderStateData &renderStateData)
41 {
42     ProcessState procState = GetProcessState(renderStateData.state);
43     if (procState == INVALID) {
44         return;
45     }
46     ProcessStatus::GetInstance().NotifyProcessState(renderStateData.pid, procState);
47 }
48 }  // namespace HiviewDFX
49 }  // namespace OHOS
50