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