From 8868ab97ffe9440f033beb2f09fe5f821ccb7c21 Mon Sep 17 00:00:00 2001 From: GlaryCastle Date: Tue, 5 Jul 2022 17:04:41 +0800 Subject: [PATCH 1/5] Signed-off-by: GlaryCastle Changes to be committed: modified: bundle.json modified: frameworks/inputmethod_controller/BUILD.gn modified: frameworks/inputmethod_controller/include/input_method_controller.h modified: frameworks/inputmethod_controller/src/input_method_controller.cpp new file: hisysevent.yaml modified: services/BUILD.gn new file: services/dfx/include/inputmethod_dump.h new file: services/dfx/include/inputmethod_sysevent.h new file: services/dfx/include/inputmethod_trace.h new file: services/dfx/src/inputmethod_dump.cpp new file: services/dfx/src/inputmethod_sysevent.cpp new file: services/dfx/src/inputmethod_trace.cpp modified: services/include/input_method_system_ability.h modified: services/include/peruser_session.h modified: services/src/input_method_system_ability.cpp modified: services/src/peruser_session.cpp --- bundle.json | 3 + frameworks/inputmethod_controller/BUILD.gn | 12 ++- .../include/input_method_controller.h | 2 + .../src/input_method_controller.cpp | 11 ++- hisysevent.yaml | 32 ++++++++ services/BUILD.gn | 7 ++ services/dfx/include/inputmethod_dump.h | 46 +++++++++++ services/dfx/include/inputmethod_sysevent.h | 29 +++++++ services/dfx/include/inputmethod_trace.h | 33 ++++++++ services/dfx/src/inputmethod_dump.cpp | 79 +++++++++++++++++++ services/dfx/src/inputmethod_sysevent.cpp | 54 +++++++++++++ services/dfx/src/inputmethod_trace.cpp | 40 ++++++++++ .../include/input_method_system_ability.h | 4 + services/include/peruser_session.h | 2 + services/src/input_method_system_ability.cpp | 56 ++++++++++++- services/src/peruser_session.cpp | 3 + 16 files changed, 410 insertions(+), 3 deletions(-) create mode 100644 hisysevent.yaml create mode 100644 services/dfx/include/inputmethod_dump.h create mode 100644 services/dfx/include/inputmethod_sysevent.h create mode 100644 services/dfx/include/inputmethod_trace.h create mode 100644 services/dfx/src/inputmethod_dump.cpp create mode 100644 services/dfx/src/inputmethod_sysevent.cpp create mode 100644 services/dfx/src/inputmethod_trace.cpp diff --git a/bundle.json b/bundle.json index e30bbde..9fd6140 100644 --- a/bundle.json +++ b/bundle.json @@ -17,6 +17,9 @@ ], "features": [ ], + "hisysevent_config": [ + "//base/miscservices/inputmethod/hisysevent.yaml" + ], "adapted_system_type": [ "standard" ], diff --git a/frameworks/inputmethod_controller/BUILD.gn b/frameworks/inputmethod_controller/BUILD.gn index 79139a2..df300da 100644 --- a/frameworks/inputmethod_controller/BUILD.gn +++ b/frameworks/inputmethod_controller/BUILD.gn @@ -17,6 +17,7 @@ config("inputmethod_client_native_config") { visibility = [ ":*" ] include_dirs = [ "include", + "${inputmethod_path}/services/dfx/include", "//utils/native/base/include", "${inputmethod_path}/services/include", ] @@ -29,6 +30,7 @@ config("inputmethod_client_native_public_config") { "//base/miscservices/inputmethod/frameworks/inputmethod_ability/include", "//base/miscservices/inputmethod/services/include", "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", + "${inputmethod_path}/services/dfx/include", "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", "//foundation/multimodalinput/input/interfaces/native/innerkits/event/include", "//utils/native/base/include", @@ -50,6 +52,9 @@ ohos_shared_library("inputmethod_client") { "src/input_method_controller.cpp", "src/input_method_system_ability_proxy.cpp", "src/input_method_utils.cpp", + "${inputmethod_path}/services/dfx/src/inputmethod_dump.cpp", + "${inputmethod_path}/services/dfx/src/inputmethod_trace.cpp", + "${inputmethod_path}/services/dfx/src/inputmethod_sysevent.cpp", ] deps = [ @@ -61,7 +66,12 @@ ohos_shared_library("inputmethod_client") { "//utils/native/base:utils", ] - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", + "hitrace_native:libhitrace", + ] configs = [ ":inputmethod_client_native_config" ] diff --git a/frameworks/inputmethod_controller/include/input_method_controller.h b/frameworks/inputmethod_controller/include/input_method_controller.h index c15acf5..57582a7 100644 --- a/frameworks/inputmethod_controller/include/input_method_controller.h +++ b/frameworks/inputmethod_controller/include/input_method_controller.h @@ -17,6 +17,7 @@ #ifndef FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_INPUT_METHOD_CONTROLLER_H #define FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_INPUT_METHOD_CONTROLLER_H +#include "global.h" #include #include #include "input_data_channel_stub.h" @@ -28,6 +29,7 @@ #include "iremote_object.h" #include "input_method_utils.h" #include "key_event.h" +#include "ipc_skeleton.h" namespace OHOS { namespace MiscServices { diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index 9a8ef44..aca548f 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -17,6 +17,8 @@ #include "iservice_registry.h" #include "system_ability_definition.h" #include "global.h" +#include "inputmethod_sysevent.h" +#include "inputmethod_trace.h" namespace OHOS { namespace MiscServices { @@ -82,9 +84,14 @@ using namespace MessageID; return nullptr; } + int32_t uid = IPCSkeleton::GetCallingUid(); + std::string strBundleName; + strBundleName = "com.inputmethod.default"; + auto systemAbility = systemAbilityManager->GetSystemAbility(INPUT_METHOD_SYSTEM_ABILITY_ID, ""); if (!systemAbility) { IMSA_HILOGI("InputMethodController::GetImsaProxy systemAbility is nullptr"); + FaultReporter(uid, strBundleName, ErrorCode::ERROR_NULL_POINTER); return nullptr; } @@ -198,8 +205,9 @@ using namespace MessageID; { textListener = listener; IMSA_HILOGI("InputMethodController::Attach"); - PrepareInput(0, mClient, mInputDataChannel, mAttribute); + InputmethodTrace tracer("InputMethodController Attach trace."); StartInput(mClient); + PrepareInput(0, mClient, mInputDataChannel, mAttribute); } void InputMethodController::ShowTextInput() @@ -230,6 +238,7 @@ using namespace MessageID; void InputMethodController::Close() { ReleaseInput(mClient); + InputmethodTrace tracer("InputMethodController Close trace."); textListener = nullptr; IMSA_HILOGI("InputMethodController::Close"); } diff --git a/hisysevent.yaml b/hisysevent.yaml new file mode 100644 index 0000000..276a77d --- /dev/null +++ b/hisysevent.yaml @@ -0,0 +1,32 @@ +# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +domain: INPUTMETHOD + +SERVICE_INIT_FAILED: + __BASE: {type: STATISTIC, level: MINOR, tag: PowerStatus, desc: inputmethod service init report} + USER_ID: {type: INT32, desc: the user id} + COMPONENT_ID: {type: INT32,desc: component type} + ERROR_CODE: {type: INT32, desc: error code} + +CREATE_COMPONENT_FAILED: + __BASE: {type: STATISTIC, level: MINOR, tag: PowerStatus, desc: create component failed report} + USER_ID: {type: INT32, desc: the user id} + COMPONENT_ID: {type: INT32,desc: the component type} + ERROR_CODE: {type: INT32, desc: error code} + +INPUTMETHOD_USING: + __BASE: {type: STATISTIC, level: MINOR, tag: PowerStatus, desc: inputmethod using report} + USER_ID: {type: INT32, desc: the timer id} + COMPONENT_ID: {type: INT32,desc: the component type} + ERROR_CODE: {type: INT32, desc: error code} \ No newline at end of file diff --git a/services/BUILD.gn b/services/BUILD.gn index 5068a64..3f8395c 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -17,6 +17,7 @@ config("inputmethod_services_native_config") { visibility = [ ":*" ] include_dirs = [ "include", + "dfx/include", "${inputmethod_path}/frameworks/inputmethod_ability/include", "${inputmethod_path}/frameworks/inputmethod_controller/include", "//base/notification/common_event_service/frameworks/core/include", @@ -47,6 +48,9 @@ ohos_shared_library("inputmethod_service") { "src/peruser_setting.cpp", "src/platform.cpp", "src/platform_callback_stub.cpp", + "dfx/src/inputmethod_dump.cpp", + "dfx/src/inputmethod_trace.cpp", + "dfx/src/inputmethod_sysevent.cpp", ] configs = [ ":inputmethod_services_native_config" ] @@ -79,6 +83,9 @@ ohos_shared_library("inputmethod_service") { "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", + "hitrace_native:libhitrace", "hiviewdfx_hilog_native:libhilog", ] diff --git a/services/dfx/include/inputmethod_dump.h b/services/dfx/include/inputmethod_dump.h new file mode 100644 index 0000000..466dbfa --- /dev/null +++ b/services/dfx/include/inputmethod_dump.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INPUTMETHOD_DUMP_H +#define INPUTMETHOD_DUMP_H + +#include +#include +#include +#include +#include +#include "singleton.h" + +namespace OHOS { +namespace MiscServices { +class InputmethodDump : public Singleton { +public: + using DumpNoParamFunc = std::function; + InputmethodDump() = default; + virtual ~InputmethodDump() = default; + void AddDumpAllMethod(const DumpNoParamFunc dumpAllMethod); + void AddErrorInfo(const std::string &error); + bool Dump(int fd, const std::vector &args); + +private: + void ShowHelp(int fd); + void ShowIllealInfomation(int fd); + mutable std::mutex hidumperMutex_; + std::list errorInfo_; + DumpNoParamFunc dumpAllMethod_; +}; +} // namespace MiscServices +} // namespace OHOS +#endif // INPUTMETHOD_DUMP_H \ No newline at end of file diff --git a/services/dfx/include/inputmethod_sysevent.h b/services/dfx/include/inputmethod_sysevent.h new file mode 100644 index 0000000..4a46432 --- /dev/null +++ b/services/dfx/include/inputmethod_sysevent.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INPUTMETHOD_SYSEVENT_H +#define INPUTMETHOD_SYSEVENT_H + +#include +#include "global.h" + +namespace OHOS { +namespace MiscServices { +void FaultReporter(int32_t userId, std::string bundname, int32_t errCode); +void CreateComponentFailed(int32_t userId, int32_t errCode); +void BehaviourReporter(std::string ActiveName, const std::string &inputmethodName); +} // namespace MiscServices +} // namespace OHOS +#endif // INPUTMETHOD_SYSEVENT_H diff --git a/services/dfx/include/inputmethod_trace.h b/services/dfx/include/inputmethod_trace.h new file mode 100644 index 0000000..dcab05d --- /dev/null +++ b/services/dfx/include/inputmethod_trace.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INPUTMETHOD_TRACE_H +#define INPUTMETHOD_TRACE_H + +#include + +namespace OHOS { +namespace MiscServices { + +void InitHiTrace(); +void ValueTrace(const std::string &name, int64_t count); +class InputmethodTrace { +public: + explicit InputmethodTrace(const std::string &value); + virtual ~InputmethodTrace(); +}; +} // namespace MiscServices +} // namespace OHOS +#endif // INPUTMETHOD_TRACE_H \ No newline at end of file diff --git a/services/dfx/src/inputmethod_dump.cpp b/services/dfx/src/inputmethod_dump.cpp new file mode 100644 index 0000000..6c24ec8 --- /dev/null +++ b/services/dfx/src/inputmethod_dump.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2022-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "inputmethod_dump.h" + +namespace OHOS { +namespace MiscServices { +constexpr int32_t MAX_RECORED_ERROR = 10; +constexpr int32_t SUB_CMD_NAME = 0; +constexpr int32_t CMD_ONE_PARAM = 1; +constexpr const char *CMD_HELP = "-h"; +constexpr const char *CMD_ALL_DUMP = "-a"; +static const std::string illegalInfo = "input dump parameter error,enter '-h' for usage.\n"; + +void InputmethodDump::AddDumpAllMethod(const DumpNoParamFunc dumpAllMethod) +{ + if (dumpAllMethod == nullptr) { + return; + } + dumpAllMethod_ = dumpAllMethod; +} + +void InputmethodDump::AddErrorInfo(const std::string &error) +{ + std::lock_guard lock(hidumperMutex_); + if (errorInfo_.size() + 1 > MAX_RECORED_ERROR) { + errorInfo_.pop_front(); + errorInfo_.push_back(error); + } else { + errorInfo_.push_back(error); + } +} + +bool InputmethodDump::Dump(int fd, const std::vector &args) +{ + std::string command = ""; + if (args.size() == CMD_ONE_PARAM) { + command = args.at(SUB_CMD_NAME); + } else if (command == CMD_HELP) { + ShowHelp(fd); + } else if (command == CMD_ALL_DUMP) { + if (!dumpAllMethod_) { + return false; + } + dumpAllMethod_(fd); + } else { + ShowIllealInfomation(fd); + } + return true; +} + +void InputmethodDump::ShowHelp(int fd) +{ + std::string result; + result.append("Usage:dump [options]\n") + .append("Description:\n") + .append("-h show help\n") + .append("-a dump all input methods\n"); + dprintf(fd, "%s\n", result.c_str()); +} + +void InputmethodDump::ShowIllealInfomation(int fd) +{ + dprintf(fd, "%s\n", illegalInfo.c_str()); +} +} // namespace MiscServices +} // namespace OHOS \ No newline at end of file diff --git a/services/dfx/src/inputmethod_sysevent.cpp b/services/dfx/src/inputmethod_sysevent.cpp new file mode 100644 index 0000000..29a37ee --- /dev/null +++ b/services/dfx/src/inputmethod_sysevent.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "inputmethod_sysevent.h" + +#include "hisysevent.h" + +namespace OHOS { +namespace MiscServices { +namespace { +using HiSysEventNameSpace = OHOS::HiviewDFX::HiSysEvent; +const std::string DOMAIN_STR = std::string(HiSysEventNameSpace::Domain::OTHERS); +} // namespace + +void FaultReporter(int32_t userId, std::string bundname, int32_t errCode) +{ + int ret = HiSysEventNameSpace::Write(DOMAIN_STR, "SERVICE_INIT_FAILED", HiSysEventNameSpace::EventType::FAULT, + "USER_ID", userId, "COMPONENT_ID", bundname, "ERROR_CODE", errCode); + if (ret != 0) { + IMSA_HILOGE("hisysevent FaultReporter failed! ret %{public}d,errCode %{public}d", ret, errCode); + } +} + +void CreateComponentFailed(int32_t userId, int32_t errCode) +{ + int ret = HiSysEventNameSpace::Write(DOMAIN_STR, "CREATE_COMPONENT_FAILED", HiSysEventNameSpace::EventType::FAULT, + "USER_ID", userId, "ERROR_CODE", errCode); + if (ret != 0) { + IMSA_HILOGE("hisysevent CreateComponentFailed failed! ret %{public}d,errCode %{public}d", ret, errCode); + } +} + +void BehaviourReporter(std::string ActiveName, const std::string &inputmethodName) +{ + int ret = HiSysEventNameSpace::Write(DOMAIN_STR, "INPUTMETHOD_USING", HiSysEventNameSpace::EventType::BEHAVIOR, + "ACTIVE_NAME", ActiveName, "INPUTMETHOD_NAME", inputmethodName); + if (ret != 0) { + IMSA_HILOGE("hisysevent BehaviourReporter failed! ret %{public}d", ret); + } +} +} // namespace MiscServices +} // namespace OHOS \ No newline at end of file diff --git a/services/dfx/src/inputmethod_trace.cpp b/services/dfx/src/inputmethod_trace.cpp new file mode 100644 index 0000000..0408bbb --- /dev/null +++ b/services/dfx/src/inputmethod_trace.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "inputmethod_trace.h" +#include "hitrace_meter.h" + +namespace OHOS { +namespace MiscServices { +void InitHiTrace() +{ + UpdateTraceLabel(); +} + +void ValueTrace(const std::string &name, int64_t count) +{ + CountTrace(HITRACE_TAG_MISC, name, count); +} +InputmethodTrace::InputmethodTrace(const std::string &value) +{ + StartTrace(HITRACE_TAG_MISC, value); +} + +InputmethodTrace::~InputmethodTrace() +{ + FinishTrace(HITRACE_TAG_MISC); +} +} // namespace MiscServices +} // namespace OHOS \ No newline at end of file diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index 3fc22fe..d980630 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -25,6 +25,8 @@ #include "event_handler.h" #include "bundle_mgr_proxy.h" #include "ability_manager_interface.h" +#include "inputmethod_dump.h" +#include "inputmethod_trace.h" namespace OHOS { namespace MiscServices { @@ -54,6 +56,8 @@ namespace MiscServices { int32_t listInputMethod(std::vector *properties) override; int32_t listInputMethodByUserId(int32_t userId, std::vector *properties) override; int32_t listKeyboardType(const std::u16string& imeId, std::vector *types) override; + int Dump(int fd, const std::vector &args) override; + void DumpAllMethod(int fd); protected: void OnStart() override; diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index 7d36c80..a8e9dd7 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -38,6 +38,8 @@ #include "keyboard_type.h" #include "ability_manager_interface.h" #include "ability_connect_callback_proxy.h" +#include "global.h" +#include "inputmethod_sysevent.h" namespace OHOS { namespace MiscServices { diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index a26972a..d56364c 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -120,11 +120,65 @@ namespace MiscServices { IMSA_HILOGE("Init failed. Try again 10s later"); return; } - + InitHiTrace(); + InputmethodTrace tracer("InputMethodController Attach trace."); + ValueTrace("InputMethodController", -1); + InputmethodDump::GetInstance().AddDumpAllMethod( + std::bind(&InputMethodSystemAbility::DumpAllMethod, this, std::placeholders::_1)); IMSA_HILOGI("Start ImsaService ErrorCode::NO_ERROR."); return; } + int InputMethodSystemAbility::Dump(int fd, const std::vector &args) + { + std::vector argsStr; + for (auto item : args) { + argsStr.emplace_back(Str16ToStr8(item)); + } + if (InputmethodDump::GetInstance().Dump(fd, argsStr)) { + return ERR_OK; + } + return ERR_OK; + } + + void InputMethodSystemAbility::DumpAllMethod(int fd) + { + IMSA_HILOGI("InputMethodSystemAbility::DumpAllMethod"); + // dprintf(fd, "\n - dump all method:\n"); + int32_t uid = IPCSkeleton::GetCallingUid(); + int32_t userId = getUserId(uid); + std::vector properties; + listInputMethodByUserId(userId, &properties); + if (!properties.size()) { + IMSA_HILOGI("InputMethodSystemAbility::DumpAllMethod has no ime"); + dprintf(fd, "\n - dump has no ime:\n"); + return; + } + std::string defaultIme = ParaHandle::GetDefaultIme(userId_); + std::string params = ""; + std::vector::iterator it; + for (it = properties.begin(); it < properties.end(); ++it) { + if (it == properties.begin()) { + params += "{\"imeList\":["; + } else { + params += "},"; + } + InputMethodProperty *property = (InputMethodProperty *)*it; + std::string imeId = Str16ToStr8(property->mPackageName) + "/" + Str16ToStr8(property->mAbilityName); + params += "{\"ime\": \"" + imeId + "\","; + params += "\"labelId\": \"" + std::to_string(property->labelId) + "\","; + params += "\"descriptionId\": \"" + std::to_string(property->descriptionId) + "\","; + std::string isDefaultIme = defaultIme == imeId ? "true" : "false"; + params += "\"isDefaultIme\": \"" + isDefaultIme + "\","; + params += "\"label\": \"" + Str16ToStr8(property->label) + "\","; + params += "\"description\": \"" + Str16ToStr8(property->description) + "\""; + } + params += "}]}"; + + dprintf(fd, "\n - dump all input methods:%s\n\n", params.c_str()); + IMSA_HILOGI("InputMethodSystemAbility::DumpAllMethod end."); + } + int32_t InputMethodSystemAbility::Init() { bool ret = Publish(InputMethodSystemAbility::GetInstance()); diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 72779ce..d47cc1d 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -1190,6 +1190,7 @@ namespace MiscServices { delete attribute; if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("PerUserSession::OnPrepareInput Aborted! %{public}s", ErrorCode::ToString(ret)); + CreateComponentFailed(userId_, ret); return; } SendAgentToSingleClient(client); @@ -1200,11 +1201,13 @@ namespace MiscServices { IMSA_HILOGI("PerUserSession::SendAgentToSingleClient"); if (!imsAgent) { IMSA_HILOGI("PerUserSession::SendAgentToSingleClient imsAgent is nullptr"); + CreateComponentFailed(userId_, ErrorCode::ERROR_NULL_POINTER); return; } ClientInfo *clientInfo = GetClientInfo(inputClient); if (!clientInfo) { IMSA_HILOGE("PerUserSession::SendAgentToSingleClient clientInfo is nullptr"); + CreateComponentFailed(userId_, ErrorCode::ERROR_NULL_POINTER); return; } clientInfo->client->onInputReady(imsAgent); From ccf9e23380bdff0f101f551308cebc8d8956547f Mon Sep 17 00:00:00 2001 From: GlaryCastle Date: Tue, 5 Jul 2022 17:49:28 +0800 Subject: [PATCH 2/5] Signed-off-by: GlaryCastle Changes to be committed: modified: frameworks/inputmethod_controller/BUILD.gn --- frameworks/inputmethod_controller/BUILD.gn | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frameworks/inputmethod_controller/BUILD.gn b/frameworks/inputmethod_controller/BUILD.gn index df300da..e383fe3 100644 --- a/frameworks/inputmethod_controller/BUILD.gn +++ b/frameworks/inputmethod_controller/BUILD.gn @@ -40,6 +40,9 @@ config("inputmethod_client_native_public_config") { ohos_shared_library("inputmethod_client") { sources = [ "${inputmethod_path}/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp", + "${inputmethod_path}/services/dfx/src/inputmethod_dump.cpp", + "${inputmethod_path}/services/dfx/src/inputmethod_sysevent.cpp", + "${inputmethod_path}/services/dfx/src/inputmethod_trace.cpp", "${inputmethod_path}/services/src/input_attribute.cpp", "${inputmethod_path}/services/src/input_method_property.cpp", "${inputmethod_path}/services/src/keyboard_type.cpp", @@ -52,9 +55,6 @@ ohos_shared_library("inputmethod_client") { "src/input_method_controller.cpp", "src/input_method_system_ability_proxy.cpp", "src/input_method_utils.cpp", - "${inputmethod_path}/services/dfx/src/inputmethod_dump.cpp", - "${inputmethod_path}/services/dfx/src/inputmethod_trace.cpp", - "${inputmethod_path}/services/dfx/src/inputmethod_sysevent.cpp", ] deps = [ @@ -67,10 +67,10 @@ ohos_shared_library("inputmethod_client") { ] external_deps = [ - "hiviewdfx_hilog_native:libhilog", "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", "hitrace_native:libhitrace", + "hiviewdfx_hilog_native:libhilog", ] configs = [ ":inputmethod_client_native_config" ] From 664403728bafbf4ceafcf706b1fa767cf7e3f1ad Mon Sep 17 00:00:00 2001 From: GlaryCastle Date: Tue, 5 Jul 2022 17:59:05 +0800 Subject: [PATCH 3/5] Signed-off-by: GlaryCastle Changes to be committed: modified: frameworks/inputmethod_controller/include/input_method_controller.h modified: frameworks/inputmethod_controller/src/input_method_controller.cpp modified: services/dfx/include/inputmethod_trace.h modified: services/src/input_method_system_ability.cpp --- .../include/input_method_controller.h | 17 +++++++++-------- .../src/input_method_controller.cpp | 4 +--- services/dfx/include/inputmethod_trace.h | 1 - services/src/input_method_system_ability.cpp | 1 - 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/frameworks/inputmethod_controller/include/input_method_controller.h b/frameworks/inputmethod_controller/include/input_method_controller.h index 57582a7..99af3ca 100644 --- a/frameworks/inputmethod_controller/include/input_method_controller.h +++ b/frameworks/inputmethod_controller/include/input_method_controller.h @@ -17,19 +17,20 @@ #ifndef FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_INPUT_METHOD_CONTROLLER_H #define FRAMEWORKS_INPUTMETHOD_CONTROLLER_INCLUDE_INPUT_METHOD_CONTROLLER_H -#include "global.h" #include #include -#include "input_data_channel_stub.h" -#include "input_client_stub.h" -#include "input_method_system_ability_proxy.h" -#include "input_method_agent_proxy.h" + +#include "global.h" #include "i_input_method_agent.h" -#include "message_handler.h" -#include "iremote_object.h" +#include "input_client_stub.h" +#include "input_data_channel_stub.h" +#include "input_method_agent_proxy.h" +#include "input_method_system_ability_proxy.h" #include "input_method_utils.h" -#include "key_event.h" #include "ipc_skeleton.h" +#include "iremote_object.h" +#include "key_event.h" +#include "message_handler.h" namespace OHOS { namespace MiscServices { diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index aca548f..e8f0241 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -85,9 +85,7 @@ using namespace MessageID; } int32_t uid = IPCSkeleton::GetCallingUid(); - std::string strBundleName; - strBundleName = "com.inputmethod.default"; - + std::string strBundleName = "com.inputmethod.default"; auto systemAbility = systemAbilityManager->GetSystemAbility(INPUT_METHOD_SYSTEM_ABILITY_ID, ""); if (!systemAbility) { IMSA_HILOGI("InputMethodController::GetImsaProxy systemAbility is nullptr"); diff --git a/services/dfx/include/inputmethod_trace.h b/services/dfx/include/inputmethod_trace.h index dcab05d..19f6c55 100644 --- a/services/dfx/include/inputmethod_trace.h +++ b/services/dfx/include/inputmethod_trace.h @@ -20,7 +20,6 @@ namespace OHOS { namespace MiscServices { - void InitHiTrace(); void ValueTrace(const std::string &name, int64_t count); class InputmethodTrace { diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index d56364c..b97abc7 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -144,7 +144,6 @@ namespace MiscServices { void InputMethodSystemAbility::DumpAllMethod(int fd) { IMSA_HILOGI("InputMethodSystemAbility::DumpAllMethod"); - // dprintf(fd, "\n - dump all method:\n"); int32_t uid = IPCSkeleton::GetCallingUid(); int32_t userId = getUserId(uid); std::vector properties; From dfb349cefea929fd787d6710cdfaa72936c2c7ea Mon Sep 17 00:00:00 2001 From: GlaryCastle Date: Tue, 5 Jul 2022 18:02:49 +0800 Subject: [PATCH 4/5] Signed-off-by: GlaryCastle Changes to be committed: modified: services/dfx/include/inputmethod_dump.h modified: services/dfx/src/inputmethod_dump.cpp --- services/dfx/include/inputmethod_dump.h | 2 +- services/dfx/src/inputmethod_dump.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/dfx/include/inputmethod_dump.h b/services/dfx/include/inputmethod_dump.h index 466dbfa..d65519d 100644 --- a/services/dfx/include/inputmethod_dump.h +++ b/services/dfx/include/inputmethod_dump.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2022 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/dfx/src/inputmethod_dump.cpp b/services/dfx/src/inputmethod_dump.cpp index 6c24ec8..4b68678 100644 --- a/services/dfx/src/inputmethod_dump.cpp +++ b/services/dfx/src/inputmethod_dump.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2022 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at From 7b2c533791f98ed328a023256fc0e5de223ee4b1 Mon Sep 17 00:00:00 2001 From: GlaryCastle Date: Tue, 5 Jul 2022 18:45:57 +0800 Subject: [PATCH 5/5] Signed-off-by: GlaryCastle Changes to be committed: modified: services/BUILD.gn --- services/BUILD.gn | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/BUILD.gn b/services/BUILD.gn index 3f8395c..fcd2efd 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -30,6 +30,9 @@ config("inputmethod_services_native_config") { ohos_shared_library("inputmethod_service") { sources = [ "${inputmethod_path}/frameworks/inputmethod_controller/src/input_client_proxy.cpp", + "dfx/src/inputmethod_dump.cpp", + "dfx/src/inputmethod_sysevent.cpp", + "dfx/src/inputmethod_trace.cpp", "src/global.cpp", "src/im_common_event_manager.cpp", "src/input_attribute.cpp", @@ -48,9 +51,6 @@ ohos_shared_library("inputmethod_service") { "src/peruser_setting.cpp", "src/platform.cpp", "src/platform_callback_stub.cpp", - "dfx/src/inputmethod_dump.cpp", - "dfx/src/inputmethod_trace.cpp", - "dfx/src/inputmethod_sysevent.cpp", ] configs = [ ":inputmethod_services_native_config" ]