Signed-off-by: GlaryCastle <yangpeng190@huawei.com>

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
This commit is contained in:
GlaryCastle
2022-07-05 17:04:41 +08:00
parent 670dcecc71
commit 14290656c6
16 changed files with 410 additions and 3 deletions
+3
View File
@@ -17,6 +17,9 @@
],
"features": [
],
"hisysevent_config": [
"//base/miscservices/inputmethod/hisysevent.yaml"
],
"adapted_system_type": [
"standard"
],
+11 -1
View File
@@ -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" ]
@@ -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 <mutex>
#include <thread>
#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 {
@@ -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");
}
+32
View File
@@ -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}
+7
View File
@@ -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",
]
+46
View File
@@ -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 <stdlib.h>
#include <functional>
#include <list>
#include <string>
#include <vector>
#include "singleton.h"
namespace OHOS {
namespace MiscServices {
class InputmethodDump : public Singleton<InputmethodDump> {
public:
using DumpNoParamFunc = std::function<void(int)>;
InputmethodDump() = default;
virtual ~InputmethodDump() = default;
void AddDumpAllMethod(const DumpNoParamFunc dumpAllMethod);
void AddErrorInfo(const std::string &error);
bool Dump(int fd, const std::vector<std::string> &args);
private:
void ShowHelp(int fd);
void ShowIllealInfomation(int fd);
mutable std::mutex hidumperMutex_;
std::list<std::string> errorInfo_;
DumpNoParamFunc dumpAllMethod_;
};
} // namespace MiscServices
} // namespace OHOS
#endif // INPUTMETHOD_DUMP_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 <string>
#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
+33
View File
@@ -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 <string>
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
+79
View File
@@ -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<std::mutex> 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<std::string> &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 <command> [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
+54
View File
@@ -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
+40
View File
@@ -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
@@ -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<InputMethodProperty*> *properties) override;
int32_t listInputMethodByUserId(int32_t userId, std::vector<InputMethodProperty*> *properties) override;
int32_t listKeyboardType(const std::u16string& imeId, std::vector<KeyboardType*> *types) override;
int Dump(int fd, const std::vector<std::u16string> &args) override;
void DumpAllMethod(int fd);
protected:
void OnStart() override;
+2
View File
@@ -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 {
+55 -1
View File
@@ -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<std::u16string> &args)
{
std::vector<std::string> 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<InputMethodProperty *> 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<InputMethodProperty *>::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());
+3
View File
@@ -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);