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
GetInstance()35 sptr<CameraAppManagerClient>& CameraAppManagerClient::GetInstance()
36 {
37 if (cameraAppManagerClient_ == nullptr) {
38 std::unique_lock<std::mutex> lock(instanceMutex_);
39 if (cameraAppManagerClient_ == nullptr) {
40 MEDIA_INFO_LOG("Initializing CameraWindowManagerClient instance");
41 cameraAppManagerClient_ = new CameraAppManagerClient();
42 }
43 }
44 return cameraAppManagerClient_;
45 }
46
GetProcessState(int32_t pid)47 int32_t CameraAppManagerClient::GetProcessState(int32_t pid)
48 {
49 AppExecFwk::RunningProcessInfo runningProcessstate;
50 int ret = appMgrHolder_->GetRunningProcessInfoByPid(pid, runningProcessstate);
51 MEDIA_INFO_LOG("GetProcessStateByPid error code: %{public}d, state: %{public}d", ret, runningProcessstate.state_);
52 CHECK_RETURN_RET(ret == CAMERA_OK, static_cast<int32_t>(runningProcessstate.state_));
53 return -1;
54 }
55 } // namespace CameraStandard
56 } // namespace OHOS