1 /*
2 * Copyright (C) 2025 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_dialog_manager.h"
17 #include "extension_manager_client.h"
18 #include "ipc_skeleton.h"
19 #include "ipc_types.h"
20
21 namespace OHOS {
22 namespace CameraStandard {
23 constexpr int32_t DEFAULT_USER_ID = -1;
24
25 std::shared_ptr<NoFrontCameraDialog> NoFrontCameraDialog::instance_ = nullptr;
26 std::mutex NoFrontCameraDialog::mutex_;
27
GetInstance()28 std::shared_ptr<NoFrontCameraDialog> NoFrontCameraDialog::GetInstance()
29 {
30 if (instance_ == nullptr) {
31 std::lock_guard<std::mutex> lock(mutex_);
32 if (instance_ == nullptr) {
33 instance_ = std::make_shared<NoFrontCameraDialog>();
34 }
35 }
36 return instance_;
37 }
38
ShowCameraDialog()39 void NoFrontCameraDialog::ShowCameraDialog()
40 {
41 MEDIA_INFO_LOG("HCameraDevice::ShowCameraDialog start");
42 AAFwk::Want want;
43 std::string bundleName = "com.ohos.sceneboard";
44 std::string abilityName = "com.ohos.sceneboard.systemdialog";
45 want.SetElementName(bundleName, abilityName);
46
47 std::string commandStr = "";
48 sptr<NoFrontCameraAbilityConnection> connection =
49 sptr<NoFrontCameraAbilityConnection>(new (std::nothrow) NoFrontCameraAbilityConnection(commandStr));
50 CHECK_RETURN_ELOG(connection == nullptr, "connection is nullptr");
51 NoFrontCameraDialog::GetInstance()->SetConnection(connection);
52 std::string identity = IPCSkeleton::ResetCallingIdentity();
53 auto connectResult = AAFwk::ExtensionManagerClient::GetInstance().ConnectServiceExtensionAbility(want,
54 connection, nullptr, DEFAULT_USER_ID);
55 IPCSkeleton::SetCallingIdentity(identity);
56 CHECK_RETURN_ELOG(connectResult != 0, "ConnectServiceExtensionAbility Failed!");
57 MEDIA_INFO_LOG("HCameraDevice::ShowCameraDialog end");
58 }
59
DisconnectAbilityForDialog()60 void NoFrontCameraDialog::DisconnectAbilityForDialog()
61 {
62 std::lock_guard<std::mutex> lock(connectMutex_);
63 if (connection_ != nullptr) {
64 MEDIA_INFO_LOG("connection_ is not null, begin DisconnectAbility");
65 AAFwk::ExtensionManagerClient::GetInstance().DisconnectAbility(connection_);
66 connection_ = nullptr;
67 }
68 }
69
SetConnection(sptr<NoFrontCameraAbilityConnection> connection)70 void NoFrontCameraDialog::SetConnection(sptr<NoFrontCameraAbilityConnection> connection)
71 {
72 std::lock_guard<std::mutex> lock(connectMutex_);
73 connection_ = connection;
74 }
75
76 } // namespace CameraStandard
77 } // namespace OHOS