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 "form_render_service_extension.h"
17 
18 #include "ability_info.h"
19 #include "context_impl.h"
20 #include "fms_log_wrapper.h"
21 #include "form_render_impl.h"
22 #include "hitrace_meter.h"
23 #include "service_extension_context.h"
24 
25 namespace OHOS {
26 namespace AbilityRuntime {
27 using namespace OHOS::AppExecFwk::FormRender;
28 
Create(const std::unique_ptr<Runtime> & runtime)29 FormRenderServiceExtension* FormRenderServiceExtension::Create(const std::unique_ptr<Runtime>& runtime)
30 {
31     return new (std::nothrow) FormRenderServiceExtension(static_cast<Runtime&>(*runtime));
32 }
33 
FormRenderServiceExtension(Runtime & runtime)34 FormRenderServiceExtension::FormRenderServiceExtension(Runtime& runtime) : runtime_(runtime) {}
35 FormRenderServiceExtension::~FormRenderServiceExtension() = default;
36 
Init(const std::shared_ptr<AbilityLocalRecord> & record,const std::shared_ptr<OHOSApplication> & application,std::shared_ptr<AbilityHandler> & handler,const sptr<IRemoteObject> & token)37 void FormRenderServiceExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
38     const std::shared_ptr<OHOSApplication> &application, std::shared_ptr<AbilityHandler> &handler,
39     const sptr<IRemoteObject> &token)
40 {
41     ServiceExtension::Init(record, application, handler, token);
42 }
43 
OnStart(const AAFwk::Want & want)44 void FormRenderServiceExtension::OnStart(const AAFwk::Want &want)
45 {
46     Extension::OnStart(want);
47     auto context = GetContext();
48     if (context) {
49         OHOS::DelayedSingleton<FormRenderImpl>::GetInstance()->SetConfiguration(context->GetConfiguration());
50     }
51 
52     HILOG_INFO("FormRenderServiceExtension OnStart begin");
53 }
54 
OnStop()55 void FormRenderServiceExtension::OnStop()
56 {
57     ServiceExtension::OnStop();
58     HILOG_INFO("FormRenderServiceExtension OnStop begin");
59 }
60 
OnConnect(const AAFwk::Want & want)61 sptr<IRemoteObject> FormRenderServiceExtension::OnConnect(const AAFwk::Want &want)
62 {
63     HILOG_INFO("begin");
64     return OHOS::DelayedSingleton<FormRenderImpl>::GetInstance()->AsObject();
65 }
66 
OnConnect(const AAFwk::Want & want,AppExecFwk::AbilityTransactionCallbackInfo<sptr<IRemoteObject>> * callbackInfo,bool & isAsyncCallback)67 sptr<IRemoteObject> FormRenderServiceExtension::OnConnect(const AAFwk::Want &want,
68     AppExecFwk::AbilityTransactionCallbackInfo<sptr<IRemoteObject>> *callbackInfo, bool &isAsyncCallback)
69 {
70     HILOG_INFO("begin multiParams");
71     return OHOS::DelayedSingleton<FormRenderImpl>::GetInstance()->AsObject();
72 }
73 
OnDisconnect(const AAFwk::Want & want)74 void FormRenderServiceExtension::OnDisconnect(const AAFwk::Want &want)
75 {
76     HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
77     Extension::OnDisconnect(want);
78     HILOG_DEBUG("begin");
79 }
80 
OnDisconnect(const AAFwk::Want & want,AppExecFwk::AbilityTransactionCallbackInfo<> * callbackInfo,bool & isAsyncCallback)81 void FormRenderServiceExtension::OnDisconnect(const AAFwk::Want &want,
82     AppExecFwk::AbilityTransactionCallbackInfo<> *callbackInfo, bool &isAsyncCallback)
83 {
84     HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
85     Extension::OnDisconnect(want);
86     HILOG_DEBUG("begin");
87 }
88 
OnCommand(const AAFwk::Want & want,bool restart,int startId)89 void FormRenderServiceExtension::OnCommand(const AAFwk::Want &want, bool restart, int startId)
90 {
91     Extension::OnCommand(want, restart, startId);
92     HILOG_INFO("begin restart=%{public}s,startId=%{public}d",
93         restart ? "true" : "false",
94         startId);
95 }
96 
OnConfigurationUpdated(const AppExecFwk::Configuration & configuration)97 void FormRenderServiceExtension::OnConfigurationUpdated(const AppExecFwk::Configuration& configuration)
98 {
99     Extension::OnConfigurationUpdated(configuration);
100     HILOG_INFO("call");
101     auto config = std::make_shared<AppExecFwk::Configuration>(configuration);
102     OHOS::DelayedSingleton<FormRenderImpl>::GetInstance()->OnConfigurationUpdated(config);
103 }
104 }
105 }
106