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 "work_scheduler_extension_context.h"
17 #include "ability_manager_client.h"
18 #include "work_sched_hilog.h"
19 
20 namespace OHOS {
21 namespace WorkScheduler {
WorkSchedulerExtensionContext()22 WorkSchedulerExtensionContext::WorkSchedulerExtensionContext() {}
23 
~WorkSchedulerExtensionContext()24 WorkSchedulerExtensionContext::~WorkSchedulerExtensionContext() {}
StartServiceExtensionAbility(const AAFwk::Want & want,int32_t accountId) const25 ErrCode WorkSchedulerExtensionContext::StartServiceExtensionAbility(const AAFwk::Want &want, int32_t accountId) const
26 {
27     WS_HILOGI("begin");
28     ErrCode err = OHOS::AAFwk::AbilityManagerClient::GetInstance()->StartExtensionAbility(
29         want, token_, accountId, AppExecFwk::ExtensionAbilityType::SERVICE);
30     if (err != ERR_OK) {
31         WS_HILOGE("StartServiceExtensionAbility is failed %{public}d", err);
32     }
33     return err;
34 }
35 
StopServiceExtensionAbility(const AAFwk::Want & want,int32_t accountId) const36 ErrCode WorkSchedulerExtensionContext::StopServiceExtensionAbility(const AAFwk::Want& want, int32_t accountId) const
37 {
38     WS_HILOGI("begin");
39     ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StopExtensionAbility(
40         want, token_, accountId, AppExecFwk::ExtensionAbilityType::SERVICE);
41     if (err != ERR_OK) {
42         WS_HILOGE("StopServiceExtensionAbility is failed %{public}d", err);
43     }
44     return err;
45 }
46 }  // namespace WorkScheduler
47 }  // namespace OHOS