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 "app_debug_listener.h"
17 
18 #include "mmi_log.h"
19 
20 #undef MMI_LOG_DOMAIN
21 #define MMI_LOG_DOMAIN MMI_LOG_SERVER
22 #undef MMI_LOG_TAG
23 #define MMI_LOG_TAG "AppDebugListener"
24 
25 namespace OHOS {
26 namespace MMI {
27 AppDebugListener *AppDebugListener::instance_ = new (std::nothrow) AppDebugListener();
GetInstance()28 AppDebugListener *AppDebugListener::GetInstance()
29 {
30     return instance_;
31 }
32 
OnAppDebugStarted(const std::vector<AppExecFwk::AppDebugInfo> & debugInfos)33 void AppDebugListener::OnAppDebugStarted(const std::vector<AppExecFwk::AppDebugInfo> &debugInfos)
34 {
35     CALL_DEBUG_ENTER;
36     for (const auto &debugInfo : debugInfos) {
37         appDebugPid_ = debugInfo.pid;
38         MMI_HILOGD("appDebugPid_:%{public}d", appDebugPid_);
39     }
40 }
41 
OnAppDebugStoped(const std::vector<AppExecFwk::AppDebugInfo> & debugInfos)42 void AppDebugListener::OnAppDebugStoped(const std::vector<AppExecFwk::AppDebugInfo> &debugInfos)
43 {
44     CALL_DEBUG_ENTER;
45     for (const auto &debugInfo : debugInfos) {
46         if (appDebugPid_ == debugInfo.pid) {
47             appDebugPid_ = -1;
48         }
49     }
50 }
51 
GetAppDebugPid()52 int32_t AppDebugListener::GetAppDebugPid()
53 {
54     MMI_HILOGD("appDebugPid_:%{public}d", appDebugPid_);
55     return appDebugPid_;
56 }
57 } // namespace MMI
58 } // namespace OHOS
59