1 /*
2 * Copyright (C) 2022 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 "call_connect_ability.h"
17 #include "call_ability_connect_callback.h"
18 #include "ability_manager_client.h"
19 #include "want.h"
20 #include "string_wrapper.h"
21 #include "int_wrapper.h"
22 #include "telephony_log_wrapper.h"
23
24 namespace OHOS {
25 namespace Telephony {
~CallConnectAbility()26 CallConnectAbility::~CallConnectAbility() {}
27
CallConnectAbility()28 CallConnectAbility::CallConnectAbility() {}
29
ConnectAbility(const CallAttributeInfo & info)30 void CallConnectAbility::ConnectAbility(const CallAttributeInfo &info)
31 {
32 if (isConnected_) {
33 TELEPHONY_LOGE("callui has already connected");
34 return;
35 }
36 TELEPHONY_LOGI("Connect callui ability");
37 AAFwk::Want want;
38 AppExecFwk::ElementName element("", "com.ohos.callui", "com.ohos.callui.ServiceAbility");
39 want.SetElement(element);
40 AAFwk::WantParams wantParams;
41 wantParams.SetParam("accountNumber", AAFwk::String::Box(std::string(info.accountNumber)));
42 wantParams.SetParam("videoState", AAFwk::Integer::Box(static_cast<int32_t>(info.videoState)));
43 wantParams.SetParam("callType", AAFwk::Integer::Box(static_cast<int32_t>(info.callType)));
44 wantParams.SetParam("callState", AAFwk::Integer::Box(static_cast<int32_t>(info.callState)));
45 wantParams.SetParam("callId", AAFwk::Integer::Box(static_cast<int32_t>(info.callId)));
46 wantParams.SetParam("startTime", AAFwk::Integer::Box(static_cast<int32_t>(info.startTime)));
47 wantParams.SetParam("accountId", AAFwk::Integer::Box(static_cast<int32_t>(info.accountId)));
48 wantParams.SetParam("isEcc", AAFwk::Integer::Box(static_cast<bool>(info.isEcc)));
49 wantParams.SetParam("conferenceState", AAFwk::Integer::Box(static_cast<int32_t>(info.conferenceState)));
50 want.SetParams(wantParams);
51 if (connectCallback_ == nullptr) {
52 connectCallback_ = new CallAbilityConnectCallback();
53 }
54 int32_t userId = 0;
55 AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, connectCallback_, userId);
56 }
57
DisconnectAbility()58 void CallConnectAbility::DisconnectAbility()
59 {
60 if (!isConnected_) {
61 TELEPHONY_LOGE("callui is not connected, no need to disconnect ability");
62 return;
63 }
64 if (connectCallback_ != nullptr) {
65 TELEPHONY_LOGI("Disconnect callui ability");
66 AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(connectCallback_);
67 connectCallback_ = nullptr;
68 }
69 }
70
SetConnectFlag(bool isConnected)71 void CallConnectAbility::SetConnectFlag(bool isConnected)
72 {
73 isConnected_ = isConnected;
74 }
75 } // namespace Telephony
76 } // namespace OHOS
77