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