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 "inputmethod_extension.h"
17
18 #include "ability_loader.h"
19 #include "connection_manager.h"
20 #include "configuration_utils.h"
21 #include "global.h"
22 #include "inputmethod_extension_context.h"
23 #include "js_inputmethod_extension.h"
24 #include "runtime.h"
25
26 namespace OHOS {
27 namespace AbilityRuntime {
28 using namespace OHOS::AppExecFwk;
Create(const std::unique_ptr<Runtime> & runtime)29 InputMethodExtension *InputMethodExtension::Create(const std::unique_ptr<Runtime> &runtime)
30 {
31 IMSA_HILOGI("InputMethodExtension::Create runtime.");
32 if (runtime == nullptr) {
33 return new InputMethodExtension();
34 }
35 switch (runtime->GetLanguage()) {
36 case Runtime::Language::JS:
37 return JsInputMethodExtension::Create(runtime);
38 default:
39 return new InputMethodExtension();
40 }
41 }
42
Init(const std::shared_ptr<AbilityLocalRecord> & record,const std::shared_ptr<OHOSApplication> & application,std::shared_ptr<AbilityHandler> & handler,const sptr<IRemoteObject> & token)43 void InputMethodExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
44 const std::shared_ptr<OHOSApplication> &application, std::shared_ptr<AbilityHandler> &handler,
45 const sptr<IRemoteObject> &token)
46 {
47 IMSA_HILOGI("InputMethodExtension::Init start.");
48 ExtensionBase<InputMethodExtensionContext>::Init(record, application, handler, token);
49 }
50
CreateAndInitContext(const std::shared_ptr<AbilityLocalRecord> & record,const std::shared_ptr<OHOSApplication> & application,std::shared_ptr<AbilityHandler> & handler,const sptr<IRemoteObject> & token)51 std::shared_ptr<InputMethodExtensionContext> InputMethodExtension::CreateAndInitContext(
52 const std::shared_ptr<AbilityLocalRecord> &record, const std::shared_ptr<OHOSApplication> &application,
53 std::shared_ptr<AbilityHandler> &handler, const sptr<IRemoteObject> &token)
54 {
55 IMSA_HILOGI("InputMethodExtension::CreateAndInitContext create and init context.");
56 std::shared_ptr<InputMethodExtensionContext> context =
57 ExtensionBase<InputMethodExtensionContext>::CreateAndInitContext(record, application, handler, token);
58 if (context == nullptr) {
59 IMSA_HILOGE("InputMethodExtension::CreateAndInitContext context is nullptr!");
60 return context;
61 }
62 return context;
63 }
64
OnConfigurationUpdated(const AppExecFwk::Configuration & config)65 void InputMethodExtension::OnConfigurationUpdated(const AppExecFwk::Configuration &config)
66 {
67 Extension::OnConfigurationUpdated(config);
68 auto context = GetContext();
69 if (context == nullptr) {
70 IMSA_HILOGE("context is nullptr!");
71 return;
72 }
73
74 auto configUtils = std::make_shared<ConfigurationUtils>();
75 configUtils->UpdateGlobalConfig(config, context->GetResourceManager());
76 }
77 } // namespace AbilityRuntime
78 } // namespace OHOS