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 "distributed_extension_context.h"
17
18 #include "ability_connection.h"
19 #include "ability_manager_client.h"
20 #include "dtbschedmgr_log.h"
21
22 namespace OHOS {
23 namespace DistributedSchedule {
24 const std::string TAG = "DistributedExtensionContextJS";
25 using namespace AbilityRuntime;
26
ConnectAbility(const AAFwk::Want & want,const sptr<AbilityConnectCallback> & connectCallback) const27 bool DistributedExtensionContext::ConnectAbility(const AAFwk::Want &want,
28 const sptr<AbilityConnectCallback> &connectCallback) const
29 {
30 HILOGI("%{public}s start.", __func__);
31 ErrCode ret = ConnectionManager::GetInstance().ConnectAbility(token_, want, connectCallback);
32 HILOGI("DistributedExtensionContext::ConnectAbility ret: %{public}d", ret);
33 return ret == ERR_OK;
34 }
35
DisconnectAbility(const AAFwk::Want & want,const sptr<AbilityConnectCallback> & connectCallback) const36 ErrCode DistributedExtensionContext::DisconnectAbility(const AAFwk::Want &want,
37 const sptr<AbilityConnectCallback> &connectCallback) const
38 {
39 HILOGI("%{public}s start.", __func__);
40 ErrCode ret = ConnectionManager::GetInstance().DisconnectAbility(token_, want.GetElement(), connectCallback);
41 if (ret != ERR_OK) {
42 HILOGE("%{public}s end DisconnectAbility error, ret: %{public}d!", __func__, ret);
43 }
44 HILOGI("%{public}s end DisconnectAbility.", __func__);
45 return ret;
46 }
47 }
48 }
49