mirror of
https://github.com/openharmony/miscservices_inputmethod.git
synced 2026-07-22 08:25:20 -04:00
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 "input_client_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using namespace ErrorCode;
|
||||
InputClientProxy::InputClientProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IInputClient>(object)
|
||||
{
|
||||
}
|
||||
|
||||
int32_t InputClientProxy::onInputReady(int32_t retValue, const sptr<IInputMethodAgent>& agent, const InputChannel* channel)
|
||||
{
|
||||
IMSA_HILOGI("InputClientProxy::onInputReady");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
if (!data.WriteInt32(retValue)){
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
if (agent ==nullptr) {
|
||||
data.WriteInt32(0);
|
||||
} else {
|
||||
data.WriteInt32(1);
|
||||
data.WriteRemoteObject(agent->AsObject().GetRefPtr());
|
||||
}
|
||||
|
||||
if (channel == nullptr) {
|
||||
data.WriteInt32(0);
|
||||
} else {
|
||||
data.WriteInt32(1);
|
||||
data.WriteParcelable(channel);
|
||||
}
|
||||
|
||||
auto ret = Remote()->SendRequest(ON_INPUT_READY, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputClientProxy::onInputReady SendRequest failed");
|
||||
return ERROR_STATUS_FAILED_TRANSACTION;
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t InputClientProxy::onInputReleased(int32_t retValue)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
data.WriteInt32(retValue);
|
||||
auto status = Remote()->SendRequest(ON_INPUT_RELEASED, data, reply, option);
|
||||
return status;
|
||||
}
|
||||
|
||||
int32_t InputClientProxy::setDisplayMode(int32_t mode)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
data.WriteInt32(mode);
|
||||
auto status = Remote()->SendRequest(SET_DISPLAY_MODE, data, reply, option);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 "input_client_stub.h"
|
||||
#include "global.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
|
||||
InputClientStub::InputClientStub()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
InputClientStub::~InputClientStub()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int32_t InputClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
IMSA_HILOGI("InputClientStub::OnRemoteRequest. code = %{public}u", code);
|
||||
auto descriptorToken = data.ReadInterfaceToken();
|
||||
if (descriptorToken != GetDescriptor()) {
|
||||
return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
|
||||
}
|
||||
switch (code) {
|
||||
case ON_INPUT_READY: {
|
||||
if (msgHandler == nullptr) {
|
||||
break;
|
||||
}
|
||||
MessageParcel* parcel = new MessageParcel();
|
||||
parcel->WriteInt32(data.ReadInt32());
|
||||
if (data.ReadInt32() > 0) {
|
||||
parcel->WriteRemoteObject(data.ReadRemoteObject());
|
||||
}
|
||||
if (data.ReadInt32() > 0) {
|
||||
parcel->WriteParcelable(data.ReadParcelable<InputChannel>());
|
||||
}
|
||||
|
||||
Message* msg = new Message(MessageID::MSG_ID_ON_INPUT_READY, parcel);
|
||||
msgHandler->SendMessage(msg);
|
||||
break;
|
||||
}
|
||||
case ON_INPUT_RELEASED: {
|
||||
if (msgHandler == nullptr) {
|
||||
break;
|
||||
}
|
||||
MessageParcel* parcel = new MessageParcel();
|
||||
parcel->WriteInt32(data.ReadInt32());
|
||||
Message* msg = new Message(MessageID::MSG_ID_EXIT_SERVICE, parcel);
|
||||
msgHandler->SendMessage(msg);
|
||||
break;
|
||||
}
|
||||
case SET_DISPLAY_MODE: {
|
||||
if (msgHandler == nullptr) {
|
||||
break;
|
||||
}
|
||||
MessageParcel* parcel = new MessageParcel();
|
||||
parcel->WriteInt32(data.ReadInt32());
|
||||
Message* msg = new Message(MessageID::MSG_ID_SET_DISPLAY_MODE, parcel);
|
||||
msgHandler->SendMessage(msg);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t InputClientStub::onInputReady(int32_t retValue, const sptr<IInputMethodAgent>& agent, const InputChannel* channel)
|
||||
{
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t InputClientStub::onInputReleased(int32_t retValue)
|
||||
{
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t InputClientStub::setDisplayMode(int32_t mode)
|
||||
{
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
void InputClientStub::SetHandler(MessageHandler* handler)
|
||||
{
|
||||
msgHandler = handler;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 "input_data_channel_proxy.h"
|
||||
#include "message_parcel.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
|
||||
InputDataChannelProxy::InputDataChannelProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IInputDataChannel>(object)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool InputDataChannelProxy::InsertText(const std::u16string& text)
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelProxy::InsertText");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
data.WriteString16(text);
|
||||
|
||||
auto ret = Remote()->SendRequest(INSERT_TEXT, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
return false;
|
||||
}
|
||||
auto result = reply.ReadBool();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool InputDataChannelProxy::DeleteBackward(int32_t length)
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelProxy::DeleteBackward");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
data.WriteInt32(length);
|
||||
|
||||
auto ret = Remote()->SendRequest(DELETE_BACKWARD, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
return false;
|
||||
}
|
||||
auto result = reply.ReadBool();
|
||||
return result;
|
||||
}
|
||||
|
||||
void InputDataChannelProxy::Close()
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelProxy::Close");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(GetDescriptor());
|
||||
|
||||
auto ret = Remote()->SendRequest(CLOSE, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 "input_data_channel_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
InputDataChannelStub::InputDataChannelStub() : msgHandler(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
InputDataChannelStub::~InputDataChannelStub()
|
||||
{
|
||||
if (msgHandler != nullptr) {
|
||||
delete msgHandler;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t InputDataChannelStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelStub::OnRemoteRequest code = %{public}d", code);
|
||||
auto descriptorToken = data.ReadInterfaceToken();
|
||||
if (descriptorToken != GetDescriptor()) {
|
||||
return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
|
||||
}
|
||||
switch (code) {
|
||||
case INSERT_TEXT: {
|
||||
auto text = data.ReadString16();
|
||||
InsertText(text);
|
||||
break;
|
||||
}
|
||||
case DELETE_BACKWARD: {
|
||||
auto length = data.ReadInt32();
|
||||
DeleteBackward(length);
|
||||
break;
|
||||
}
|
||||
case CLOSE: {
|
||||
Close();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
bool InputDataChannelStub::InsertText(const std::u16string& text)
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelStub::InsertText");
|
||||
if (msgHandler != nullptr) {
|
||||
MessageParcel* parcel = new MessageParcel;
|
||||
parcel->WriteString16(text);
|
||||
Message* msg = new Message(MessageID::MSG_ID_INSERT_CHAR, parcel);
|
||||
msgHandler->SendMessage(msg);
|
||||
IMSA_HILOGI("InputDataChannelStub::InsertText return true");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputDataChannelStub::DeleteBackward(int32_t length)
|
||||
{
|
||||
IMSA_HILOGI("InputDataChannelStub::DeleteBackward");
|
||||
if (msgHandler != nullptr) {
|
||||
MessageParcel* parcel = new MessageParcel;
|
||||
parcel->WriteInt32(length);
|
||||
Message* msg = new Message(MessageID::MSG_ID_DELETE_BACKWARD, parcel);
|
||||
msgHandler->SendMessage(msg);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void InputDataChannelStub::Close()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void InputDataChannelStub::SetHandler(MessageHandler* handler)
|
||||
{
|
||||
msgHandler = handler;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 "input_method_controller.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "global.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using namespace MessageID;
|
||||
sptr<InputMethodController> InputMethodController::instance_;
|
||||
std::mutex InputMethodController::instanceLock_;
|
||||
|
||||
InputMethodController::InputMethodController()
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController structure");
|
||||
Initialize();
|
||||
}
|
||||
|
||||
InputMethodController::~InputMethodController()
|
||||
{
|
||||
if (msgHandler != nullptr) {
|
||||
delete msgHandler;
|
||||
}
|
||||
}
|
||||
|
||||
sptr<InputMethodController> InputMethodController::GetInstance()
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::GetInstance");
|
||||
if (instance_ == nullptr) {
|
||||
std::lock_guard<std::mutex> autoLock(instanceLock_);
|
||||
if (instance_ == nullptr) {
|
||||
IMSA_HILOGI("InputMethodController::GetInstance instance_ is nullptr");
|
||||
instance_ = new InputMethodController();
|
||||
}
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
bool InputMethodController::Initialize()
|
||||
{
|
||||
mImms = GetImsaProxy();
|
||||
|
||||
msgHandler = new MessageHandler();
|
||||
|
||||
mClient = new InputClientStub();
|
||||
mClient->SetHandler(msgHandler);
|
||||
|
||||
mInputDataChannel = new InputDataChannelStub();
|
||||
mInputDataChannel->SetHandler(msgHandler);
|
||||
|
||||
workThreadHandler = std::thread([this]{WorkThread();});
|
||||
mAttribute.SetInputPattern(InputAttribute::PATTERN_TEXT);
|
||||
return true;
|
||||
}
|
||||
|
||||
sptr<InputMethodSystemAbilityProxy> InputMethodController::GetImsaProxy()
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::GetImsaProxy");
|
||||
sptr<ISystemAbilityManager> systemAbilityManager =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (systemAbilityManager == nullptr) {
|
||||
IMSA_HILOGI("InputMethodController::GetImsaProxy systemAbilityManager is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto systemAbility = systemAbilityManager->GetSystemAbility(INPUT_METHOD_SYSTEM_ABILITY_ID, "");
|
||||
if (systemAbility == nullptr) {
|
||||
IMSA_HILOGI("InputMethodController::GetImsaProxy systemAbility is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (deathRecipient_ == nullptr) {
|
||||
deathRecipient_ = new ImsaDeathRecipient();
|
||||
}
|
||||
systemAbility->AddDeathRecipient(deathRecipient_);
|
||||
|
||||
sptr<InputMethodSystemAbilityProxy> iface = new InputMethodSystemAbilityProxy(systemAbility);
|
||||
return iface;
|
||||
}
|
||||
|
||||
void InputMethodController::WorkThread()
|
||||
{
|
||||
while(1) {
|
||||
Message* msg = msgHandler->GetMessage();
|
||||
switch(msg->msgId_) {
|
||||
case MSG_ID_INSERT_CHAR:{
|
||||
MessageParcel* data = msg->msgContent_;
|
||||
std::u16string text = data->ReadString16();
|
||||
if(textListener != nullptr){
|
||||
textListener->InsertText(text);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MSG_ID_DELETE_BACKWARD:{
|
||||
MessageParcel* data = msg->msgContent_;
|
||||
int32_t length = data->ReadInt32();
|
||||
if(textListener != nullptr){
|
||||
textListener->DeleteBackward(length);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MSG_ID_SET_DISPLAY_MODE:{
|
||||
MessageParcel* data = msg->msgContent_;
|
||||
int32_t ret = data->ReadInt32();
|
||||
IMSA_HILOGI("MSG_ID_SET_DISPLAY_MODE : %{public}d", ret);
|
||||
break;
|
||||
}
|
||||
case MSG_ID_ON_INPUT_READY:{
|
||||
MessageParcel* data = msg->msgContent_;
|
||||
int32_t ret = data->ReadInt32();
|
||||
if(ret != ErrorCode::NO_ERROR) {
|
||||
if (textListener != nullptr){
|
||||
textListener->SetKeyboardStatus(false);
|
||||
}
|
||||
mAgent=nullptr;
|
||||
break;
|
||||
}
|
||||
sptr<IRemoteObject> object = data->ReadRemoteObject();
|
||||
mAgent = new InputMethodAgentProxy(object);
|
||||
if (textListener != nullptr){
|
||||
textListener->SetKeyboardStatus(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MSG_ID_EXIT_SERVICE:{
|
||||
MessageParcel* data = msg->msgContent_;
|
||||
int32_t ret = data->ReadInt32();
|
||||
IMSA_HILOGI("MSG_ID_EXIT_SERVICE : %{public}d", ret);
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete msg;
|
||||
}
|
||||
}
|
||||
|
||||
void InputMethodController::Attach()
|
||||
{
|
||||
PrepareInput(0,mClient,mInputDataChannel,mAttribute);
|
||||
}
|
||||
|
||||
void InputMethodController::ShowTextInput(sptr<OnTextChangedListener> &listener)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::ShowTextInput");
|
||||
textListener=listener;
|
||||
StartInput(mClient);
|
||||
}
|
||||
|
||||
void InputMethodController::HideTextInput()
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::HideTextInput");
|
||||
StopInput(mClient);
|
||||
}
|
||||
|
||||
void InputMethodController::Close()
|
||||
{
|
||||
ReleaseInput(mClient);
|
||||
}
|
||||
|
||||
void InputMethodController::PrepareInput(int32_t displayId,sptr<InputClientStub> &client,sptr<InputDataChannelStub> &channel,InputAttribute &attribute)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::PrepareInput");
|
||||
if(mImms == nullptr){
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
if(!(data.WriteInterfaceToken(mImms->GetDescriptor())
|
||||
&&data.WriteInt32(displayId)
|
||||
&&data.WriteRemoteObject(client->AsObject())
|
||||
&&data.WriteRemoteObject(channel->AsObject())
|
||||
&&data.WriteParcelable(&attribute))){
|
||||
return;
|
||||
}
|
||||
mImms->prepareInput(data);
|
||||
}
|
||||
|
||||
void InputMethodController::StartInput(sptr<InputClientStub> &client)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::StartInput");
|
||||
if(mImms == nullptr){
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
if(!(data.WriteInterfaceToken(mImms->GetDescriptor())
|
||||
&&data.WriteRemoteObject(client->AsObject()))){
|
||||
return;
|
||||
}
|
||||
mImms->startInput(data);
|
||||
}
|
||||
|
||||
void InputMethodController::ReleaseInput(sptr<InputClientStub> &client)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::ReleaseInput");
|
||||
if(mImms == nullptr){
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
if(!(data.WriteInterfaceToken(mImms->GetDescriptor())
|
||||
&&data.WriteRemoteObject(client->AsObject().GetRefPtr()))) {
|
||||
return;
|
||||
}
|
||||
mImms->releaseInput(data);
|
||||
}
|
||||
|
||||
void InputMethodController::StopInput(sptr<InputClientStub> &client)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::StopInput");
|
||||
if(mImms == nullptr){
|
||||
return;
|
||||
}
|
||||
MessageParcel data;
|
||||
if(!(data.WriteInterfaceToken(mImms->GetDescriptor())
|
||||
&&data.WriteRemoteObject(client->AsObject().GetRefPtr()))) {
|
||||
return;
|
||||
}
|
||||
mImms->stopInput(data);
|
||||
}
|
||||
|
||||
void InputMethodController::OnRemoteSaDied(const wptr<IRemoteObject> &remote) {
|
||||
mImms = GetImsaProxy();
|
||||
}
|
||||
|
||||
ImsaDeathRecipient::ImsaDeathRecipient()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ImsaDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &object)
|
||||
{
|
||||
InputMethodController::GetInstance()->OnRemoteSaDied(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,410 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 "input_method_system_ability_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using namespace ErrorCode;
|
||||
|
||||
InputMethodSystemAbilityProxy::InputMethodSystemAbilityProxy(const sptr<IRemoteObject> &object)
|
||||
: IRemoteProxy<IInputMethodSystemAbility>(object)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void InputMethodSystemAbilityProxy::prepareInput(MessageParcel& data)
|
||||
{
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
auto ret = Remote()->SendRequest(PREPARE_INPUT, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::prepareInput SendRequest failed");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::prepareInput reply failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void InputMethodSystemAbilityProxy::releaseInput(MessageParcel& data)
|
||||
{
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
auto ret = Remote()->SendRequest(RELEASE_INPUT, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::releaseInput SendRequest failed");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::releaseInput reply failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void InputMethodSystemAbilityProxy::startInput(MessageParcel& data)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::startInput");
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
auto ret = Remote()->SendRequest(START_INPUT,data,reply,option);
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::startInput SendRequest failed");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::startInput reply failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void InputMethodSystemAbilityProxy::stopInput(MessageParcel& data)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::stopInput");
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
auto ret = Remote()->SendRequest(STOP_INPUT,data,reply,option);
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::stopInput SendRequest failed");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::stopInput reply failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t InputMethodSystemAbilityProxy::setInputMethodCore(sptr<IInputMethodCore> &core)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::setInputMethodCore");
|
||||
|
||||
if (core == nullptr) {
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::setInputMethodCore inputDataChannel is nullptr");
|
||||
}
|
||||
auto remote = Remote();
|
||||
if (remote == nullptr)
|
||||
return -1;
|
||||
MessageParcel data;
|
||||
if (!(data.WriteInterfaceToken(GetDescriptor())
|
||||
&& data.WriteRemoteObject(core->AsObject())))
|
||||
return -1;
|
||||
MessageParcel reply;
|
||||
MessageOption option { MessageOption::TF_SYNC };
|
||||
|
||||
int32_t status = Remote()->SendRequest(SET_INPUT_METHOD_CORE, data, reply, option);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int32_t InputMethodSystemAbilityProxy::Prepare(int32_t displayId, sptr<InputClientStub> &client, sptr<InputDataChannelStub> &channel, InputAttribute &attribute)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
if (!(data.WriteInt32(displayId)
|
||||
&& data.WriteRemoteObject(client->AsObject())
|
||||
&& data.WriteRemoteObject(channel->AsObject())
|
||||
&& data.WriteParcelable(&attribute))) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
auto ret = Remote()->SendRequest(PREPARE_INPUT, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
return ERROR_STATUS_FAILED_TRANSACTION;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t InputMethodSystemAbilityProxy::Release(sptr<InputClientStub> &client)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodSystemAbilityProxy::Release");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
if (!data.WriteRemoteObject(client->AsObject().GetRefPtr())) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
auto ret = Remote()->SendRequest(RELEASE_INPUT, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
return ERROR_STATUS_FAILED_TRANSACTION;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t InputMethodSystemAbilityProxy::Start(sptr<InputClientStub> &client)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
if (!data.WriteRemoteObject(client->AsObject().GetRefPtr())) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
auto ret = Remote()->SendRequest(START_INPUT, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
return ERROR_STATUS_FAILED_TRANSACTION;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t InputMethodSystemAbilityProxy::Stop(sptr<InputClientStub> &client)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
if (!data.WriteRemoteObject(client->AsObject().GetRefPtr())) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
auto ret = Remote()->SendRequest(STOP_INPUT, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
return ERROR_STATUS_FAILED_TRANSACTION;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t InputMethodSystemAbilityProxy::getDisplayMode(int32_t *retMode)
|
||||
{
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
auto ret = Remote()->SendRequest(GET_DISPLAY_MODE, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
return ERROR_STATUS_FAILED_TRANSACTION;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!reply.ReadInt32(*retMode)) {
|
||||
return ERROR_STATUS_BAD_VALUE;
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t InputMethodSystemAbilityProxy::getKeyboardWindowHeight(int32_t *retHeight)
|
||||
{
|
||||
if (retHeight == nullptr) {
|
||||
return ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
auto ret = Remote()->SendRequest(GET_KEYBOARD_WINDOW_HEIGHT, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
return ERROR_STATUS_FAILED_TRANSACTION;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!reply.ReadInt32(*retHeight)) {
|
||||
return ERROR_STATUS_BAD_VALUE;
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t InputMethodSystemAbilityProxy::getCurrentKeyboardType(KeyboardType* retType)
|
||||
{
|
||||
if (retType == nullptr) {
|
||||
return ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
auto ret = Remote()->SendRequest(GET_CURRENT_KEYBOARD_TYPE, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
return ERROR_STATUS_FAILED_TRANSACTION;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
KeyboardType* keyType = reply.ReadParcelable<KeyboardType>();
|
||||
*retType = *keyType;
|
||||
delete keyType;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t InputMethodSystemAbilityProxy::listInputMethodEnabled(std::vector<InputMethodProperty*> *properties)
|
||||
{
|
||||
if (properties == nullptr) {
|
||||
return ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
auto ret = Remote()->SendRequest(LIST_INPUT_METHOD_ENABLED, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
return ERROR_STATUS_FAILED_TRANSACTION;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto size = reply.ReadInt32();
|
||||
while (size > 0) {
|
||||
InputMethodProperty* imp = reply.ReadParcelable<InputMethodProperty>();
|
||||
properties->push_back(imp);
|
||||
size--;
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t InputMethodSystemAbilityProxy::listInputMethod(std::vector<InputMethodProperty*> *properties)
|
||||
{
|
||||
if (properties == nullptr) {
|
||||
return ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
auto ret = Remote()->SendRequest(LIST_INPUT_METHOD, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
return ERROR_STATUS_FAILED_TRANSACTION;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto size = reply.ReadInt32();
|
||||
|
||||
while (size > 0) {
|
||||
InputMethodProperty* imp = reply.ReadParcelable<InputMethodProperty>();
|
||||
properties->push_back(imp);
|
||||
size--;
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t InputMethodSystemAbilityProxy::listKeyboardType(const std::u16string& imeId, std::vector<KeyboardType*> *types)
|
||||
{
|
||||
if (types == nullptr) {
|
||||
return ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!(data.WriteInterfaceToken(GetDescriptor()) && data.WriteString16(imeId))) {
|
||||
return ERROR_EX_PARCELABLE;
|
||||
}
|
||||
|
||||
auto ret = Remote()->SendRequest(LIST_KEYBOARD_TYPE, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
return ERROR_STATUS_FAILED_TRANSACTION;
|
||||
}
|
||||
|
||||
ret = reply.ReadInt32();
|
||||
if (ret != NO_ERROR) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto size = reply.ReadInt32();
|
||||
while (size > 0) {
|
||||
KeyboardType* kt = reply.ReadParcelable<KeyboardType>();
|
||||
types->push_back(kt);
|
||||
size--;
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user