1 /*
2  * Copyright (c) 2023 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 "adsservice_extension.h"
17 #include "js_adsservice_extension.h"
18 #include "ability_local_record.h"
19 #include "ad_hilog_wreapper.h"
20 
21 namespace OHOS {
22 namespace AdsExtension {
Init(const std::shared_ptr<AbilityRuntime::AbilityLocalRecord> &record, const std::shared_ptr<AbilityRuntime::OHOSApplication> &application, std::shared_ptr<AbilityRuntime::AbilityHandler> &handler, const sptr<IRemoteObject> &token)23 void AdsServiceExtension::Init(const std::shared_ptr<AbilityRuntime::AbilityLocalRecord> &record,
24     const std::shared_ptr<AbilityRuntime::OHOSApplication> &application,
25     std::shared_ptr<AbilityRuntime::AbilityHandler> &handler,
26     const sptr<IRemoteObject> &token)
27 {
28     ExtensionBase<AdsServiceExtensionContext>::Init(record, application, handler, token);
29     ADS_HILOGI(OHOS::Cloud::ADS_MODULE_JS_NAPI, "AdsServiceExtension begin init context");
30 }
31 
CreateAndInitContext( const std::shared_ptr<AbilityRuntime::AbilityLocalRecord> &record, const std::shared_ptr<AbilityRuntime::OHOSApplication> &application, std::shared_ptr<AbilityRuntime::AbilityHandler> &handler, const sptr<IRemoteObject> &token)32 std::shared_ptr<AdsServiceExtensionContext> AdsServiceExtension::CreateAndInitContext(
33     const std::shared_ptr<AbilityRuntime::AbilityLocalRecord> &record,
34     const std::shared_ptr<AbilityRuntime::OHOSApplication> &application,
35     std::shared_ptr<AbilityRuntime::AbilityHandler> &handler,
36     const sptr<IRemoteObject> &token)
37 {
38     std::shared_ptr<AdsServiceExtensionContext> context =
39         ExtensionBase<AdsServiceExtensionContext>::CreateAndInitContext(record, application, handler, token);
40     if (!context) {
41         ADS_HILOGE(OHOS::Cloud::ADS_MODULE_JS_NAPI, "AdsServiceExtension::CreateAndInitContext context is nullptr");
42     }
43     return context;
44 }
45 
Create(const std::unique_ptr<AbilityRuntime::Runtime>& runtime)46 AdsServiceExtension* AdsServiceExtension::Create(const std::unique_ptr<AbilityRuntime::Runtime>& runtime)
47 {
48     if (!runtime) {
49         return new AdsServiceExtension();
50     }
51     ADS_HILOGI(OHOS::Cloud::ADS_MODULE_JS_NAPI, "create AdsServiceExtension");
52     switch (runtime->GetLanguage()) {
53         case AbilityRuntime::Runtime::Language::JS: {
54             ADS_HILOGI(OHOS::Cloud::ADS_MODULE_JS_NAPI, "create js AdsServiceExtension");
55             return JsAdsServiceExtension::Create(runtime);
56         }
57         default: {
58             return new AdsServiceExtension();
59         }
60     }
61     return nullptr;
62 }
63 } // namespace AdsExtension
64 } // namespace OHOS