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.h"
17 
18 #include "js_work_scheduler_extension.h"
19 
20 namespace OHOS {
21 namespace WorkScheduler {
Create(const std::unique_ptr<AbilityRuntime::Runtime> & runtime)22 WorkSchedulerExtension* WorkSchedulerExtension::Create(const std::unique_ptr<AbilityRuntime::Runtime>& runtime)
23 {
24     if (!runtime) {
25         return (new (std::nothrow) WorkSchedulerExtension());
26     }
27     switch (runtime->GetLanguage()) {
28         case AbilityRuntime::Runtime::Language::JS:
29             return JsWorkSchedulerExtension::Create(runtime);
30         default:
31             return (new (std::nothrow) WorkSchedulerExtension());
32     }
33 }
34 
Init(const std::shared_ptr<AppExecFwk::AbilityLocalRecord> & record,const std::shared_ptr<AppExecFwk::OHOSApplication> & application,std::shared_ptr<AppExecFwk::AbilityHandler> & handler,const sptr<IRemoteObject> & token)35 void WorkSchedulerExtension::Init(const std::shared_ptr<AppExecFwk::AbilityLocalRecord>& record,
36     const std::shared_ptr<AppExecFwk::OHOSApplication>& application,
37     std::shared_ptr<AppExecFwk::AbilityHandler>& handler,
38     const sptr<IRemoteObject>& token)
39 {
40     ExtensionBase<WorkSchedulerExtensionContext>::Init(record, application, handler, token);
41 }
42 
CreateAndInitContext(const std::shared_ptr<AppExecFwk::AbilityLocalRecord> & record,const std::shared_ptr<AppExecFwk::OHOSApplication> & application,std::shared_ptr<AppExecFwk::AbilityHandler> & handler,const sptr<IRemoteObject> & token)43 std::shared_ptr<WorkSchedulerExtensionContext> WorkSchedulerExtension::CreateAndInitContext(
44     const std::shared_ptr<AppExecFwk::AbilityLocalRecord>& record,
45     const std::shared_ptr<AppExecFwk::OHOSApplication>& application,
46     std::shared_ptr<AppExecFwk::AbilityHandler>& handler,
47     const sptr<IRemoteObject>& token)
48 {
49     std::shared_ptr<WorkSchedulerExtensionContext> context =
50         ExtensionBase<WorkSchedulerExtensionContext>::CreateAndInitContext(record, application, handler, token);
51     if (record == nullptr) {
52         return context;
53     }
54     return context;
55 }
56 
OnWorkStart(WorkInfo & workInfo)57 void WorkSchedulerExtension::OnWorkStart(WorkInfo& workInfo) {
58 }
59 
OnWorkStop(WorkInfo & workInfo)60 void WorkSchedulerExtension::OnWorkStop(WorkInfo& workInfo) {
61 }
62 } // namespace WorkScheduler
63 } // namespace OHOS