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 
16 #include "camera_log.h"
17 #include "camera_app_manager_client.h"
18 #include "camera_util.h"
19 #include "running_process_info.h"
20 
21 
22 namespace OHOS {
23 namespace CameraStandard {
24 std::mutex CameraAppManagerClient::instanceMutex_;
25 sptr<CameraAppManagerClient> CameraAppManagerClient::cameraAppManagerClient_;
26 
CameraAppManagerClient()27 CameraAppManagerClient::CameraAppManagerClient()
28 {
29     MEDIA_DEBUG_LOG("Make shared appMgrHolder_");
30     appMgrHolder_ = std::make_shared<AppExecFwk::AppMgrClient>();
31 }
32 
~CameraAppManagerClient()33 CameraAppManagerClient::~CameraAppManagerClient()
34 {
35     appMgrHolder_ = nullptr;
36 }
37 
GetInstance()38 sptr<CameraAppManagerClient>& CameraAppManagerClient::GetInstance()
39 {
40     if (cameraAppManagerClient_ == nullptr) {
41         std::unique_lock<std::mutex> lock(instanceMutex_);
42         if (cameraAppManagerClient_ == nullptr) {
43             MEDIA_INFO_LOG("Initializing CameraWindowManagerClient instance");
44             cameraAppManagerClient_ = new CameraAppManagerClient();
45         }
46     }
47     return cameraAppManagerClient_;
48 }
49 
GetProcessState(int32_t pid)50 int32_t CameraAppManagerClient::GetProcessState(int32_t pid)
51 {
52     AppExecFwk::RunningProcessInfo runningProcessstate;
53     int ret = appMgrHolder_->GetRunningProcessInfoByPid(pid, runningProcessstate);
54     MEDIA_INFO_LOG("GetProcessStateByPid error code: %{public}d, state: %{public}d", ret, runningProcessstate.state_);
55     if (ret == CAMERA_OK) {
56         return static_cast<int32_t>(runningProcessstate.state_);
57     }
58     return -1;
59 }
60 } // namespace CameraStandard
61 } // namespace OHOS