1 /*
2  * Copyright (c) 2021 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 "connection_manager.h"
17 #include "hilog_wrapper.h"
18 #include "js_wallpaper_extension_ability.h"
19 #include "runtime.h"
20 #include "wallpaper_extension_ability.h"
21 #include "wallpaper_extension_context.h"
22 
23 namespace OHOS {
24 namespace AbilityRuntime {
25 using namespace OHOS::AppExecFwk;
Create(const std::unique_ptr<Runtime> & runtime)26 WallpaperExtensionAbility *WallpaperExtensionAbility::Create(const std::unique_ptr<Runtime> &runtime)
27 {
28     HILOG_INFO("jws WallpaperExtensionAbility::Create runtime.");
29     if (!runtime) {
30         return new WallpaperExtensionAbility();
31     }
32     HILOG_INFO("jws WallpaperExtensionAbility::Create runtime.");
33     switch (runtime->GetLanguage()) {
34         case Runtime::Language::JS:
35             return JsWallpaperExtensionAbility::Create(runtime);
36 
37         default:
38             return new WallpaperExtensionAbility();
39     }
40 }
41 
Init(const std::shared_ptr<AbilityLocalRecord> & record,const std::shared_ptr<OHOSApplication> & application,std::shared_ptr<AbilityHandler> & handler,const sptr<IRemoteObject> & token)42 void WallpaperExtensionAbility::Init(const std::shared_ptr<AbilityLocalRecord> &record,
43     const std::shared_ptr<OHOSApplication> &application, std::shared_ptr<AbilityHandler> &handler,
44     const sptr<IRemoteObject> &token)
45 {
46     HILOG_INFO("jws WallpaperExtensionAbility begin init context.");
47     ExtensionBase<WallpaperExtensionContext>::Init(record, application, handler, token);
48 }
49 
CreateAndInitContext(const std::shared_ptr<AbilityLocalRecord> & record,const std::shared_ptr<OHOSApplication> & application,std::shared_ptr<AbilityHandler> & handler,const sptr<IRemoteObject> & token)50 std::shared_ptr<WallpaperExtensionContext> WallpaperExtensionAbility::CreateAndInitContext(
51     const std::shared_ptr<AbilityLocalRecord> &record, const std::shared_ptr<OHOSApplication> &application,
52     std::shared_ptr<AbilityHandler> &handler, const sptr<IRemoteObject> &token)
53 {
54     HILOG_INFO("jws WallpaperExtensionAbility begin init context.");
55     std::shared_ptr<WallpaperExtensionContext> context =
56         ExtensionBase<WallpaperExtensionContext>::CreateAndInitContext(record, application, handler, token);
57     if (context == nullptr) {
58         HILOG_ERROR("WallpaperExtensionAbility::CreateAndInitContext context is nullptr!");
59         return context;
60     }
61     return context;
62 }
63 } // namespace AbilityRuntime
64 } // namespace OHOS