add inputmethod

Signed-off-by: zhouyongfei <zhouyongfei@huawei.com>
This commit is contained in:
zhouyongfei
2021-09-14 20:33:47 +08:00
parent c92108aa00
commit 3e8b13bd33
90 changed files with 10984 additions and 0 deletions
+172
View File
@@ -0,0 +1,172 @@
/*
* 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.
*/
#ifndef FM_IMMS_PROJECT_GLOBAL_H
#define FM_IMMS_PROJECT_GLOBAL_H
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include "iremote_broker.h"
#include "peer_holder.h"
#include "ipc_object_stub.h"
#include "refbase.h"
#include "hilog/log.h"
namespace OHOS {
namespace MiscServices {
#define PLATFORM OHOS
using BRemoteObject = IPCObjectStub;
#define INPUTMETHOD_DEBUG 0
#define LOG_INFO(fmt, args...) \
LogTimeStamp();printf("I %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
#define LOG_ERROR(fmt, args...) \
LogTimeStamp();printf("E %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
#define LOG_WARNING(fmt, args...) \
LogTimeStamp();printf("W %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
#if DEBUG
#define LOG_DEBUG(fmt, args...) \
LogTimeStamp();printf("D %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
#else
#define LOG_DEBUG(fmt, args...)
#endif
void LogTimeStamp();
namespace CommonEvent {
//! the events handled in input method management system
enum {
COMMON_EVENT_USER_STARTED = 10001, /*!< a user is started. */
COMMON_EVENT_USER_STOPPED = 10002, /*!< a user is stopped. */
COMMON_EVENT_USER_UNLOCKED = 10003, /*!< a user is unlocked. */
COMMON_EVENT_USER_LOCKED = 10004, /*!< a user is locked. */
COMMON_EVENT_SETTING_CHANGED = 10005, /*!< input method setting data is changed. */
COMMON_EVENT_PACKAGE_ADDED = 10006, /*!< a package is installed. */
COMMON_EVENT_PACKAGE_REMOVED = 10007, /*!< a package is removed */
};
};
//! User State
namespace UserState {
/*! The states of a user in the system. */
enum {
USER_STATE_NOT_AVAILABLE = -1,
USER_STATE_STARTED = 0, /*!< a user is started. */
USER_STATE_UNLOCKED, /*!< a user is unlocked. */
};
};
//! Error Code
namespace ErrorCode {
/*! Error Code definition in the input method management system */
enum {
ERROR_STATUS_UNKNOWN_ERROR = (-2147483647 - 1), //!< unknown error
ERROR_STATUS_NO_MEMORY = -ENOMEM, //!< no memory
ERROR_STATUS_INVALID_OPERATION = -ENOSYS, //!< invalid operation
ERROR_STATUS_BAD_VALUE = -EINVAL, //!< bad value
ERROR_STATUS_BAD_TYPE = ERROR_STATUS_UNKNOWN_ERROR+1, //!< bad type
ERROR_STATUS_NAME_NOT_FOUND = -ENOENT, //!< name not found
ERROR_STATUS_PERMISSION_DENIED = -EPERM, //!< permission denied
ERROR_STATUS_NO_INIT = -ENODEV, //!< no init
ERROR_STATUS_ALREADY_EXISTS = -EEXIST, //!< already exist
ERROR_STATUS_DEAD_OBJECT = -EPIPE, //!< dead object
ERROR_STATUS_FAILED_TRANSACTION = ERROR_STATUS_UNKNOWN_ERROR+2, //!< failed transaction
ERROR_STATUS_BAD_INDEX = -EOVERFLOW, //!< bad index
ERROR_STATUS_NOT_ENOUGH_DATA = -ENODATA, //!< not enough data
ERROR_STATUS_WOULD_BLOCK = -EWOULDBLOCK, //!< would block
ERROR_STATUS_TIMED_OUT = -ETIMEDOUT, //!< time out
ERROR_STATUS_UNKNOWN_TRANSACTION = -EBADMSG, //!< unknown transaction
ERROR_STATUS_FDS_NOT_ALLOWED = ERROR_STATUS_UNKNOWN_ERROR+7, //!< fds not allowed
ERROR_STATUS_UNEXPECTED_NULL = ERROR_STATUS_UNKNOWN_ERROR+8, //!< unexpected null,
// binder exception error code from Status.h
ERROR_EX_ILLEGAL_ARGUMENT = -3, //!< illegal argument exception
ERROR_EX_NULL_POINTER = -4, //!< null pointer exception
ERROR_EX_ILLEGAL_STATE = -5, //!< illegal state exception
ERROR_EX_NETWORK_MAIN_THREAD = -6, //!< network main thread exception
ERROR_EX_UNSUPPORTED_OPERATION = -7, //!< unsupported operation exception
ERROR_EX_SERVICE_SPECIFIC = -8, //!< service specific exception
ERROR_EX_PARCELABLE = -9, //!< parcelable exception
// no error
NO_ERROR = 0, //!< no error
// system service error
ERROR_NULL_POINTER, //!< null pointer
ERROR_BAD_PARAMETERS, //!< bad parameters
ERROR_SERVICE_START_FAILED, //!< failed to start service
ERROR_USER_NOT_STARTED, //!< user is not started
ERROR_USER_ALREADY_STARTED, //!< user has already started
ERROR_USER_NOT_UNLOCKED, //!< user is not unlocked
ERROR_USER_ALREADY_UNLOCKED, //!< user has already unlocked
ERROR_USER_NOT_LOCKED, //!< user is not locked
ERROR_IME_NOT_AVAILABLE, //!< input method engine is not available
ERROR_SECURITY_IME_NOT_AVAILABLE, //!< security input method engine is not available
ERROR_TOKEN_CREATE_FAILED, //!< failed to create window token
ERROR_TOKEN_DESTROY_FAILED, //!< failed to destroy window token
ERROR_IME_BIND_FAILED, //!< failed to bind IME service
ERROR_IME_UNBIND_FAILED, //!< failed to unbind IME service
ERROR_IME_START_FAILED, //!< failed to start IME service
ERROR_IME_STOP_FAILED, //!< failed to stop IME service
ERROR_KBD_SHOW_FAILED, //!< failed to show keyboard
ERROR_KBD_HIDE_FAILED, //!< failed to hide keyboard
ERROR_IME_NOT_STARTED, //!< input method service is not started
ERROR_KBD_IS_OCCUPIED, //!< keyboard is showing by other client
ERROR_KBD_IS_NOT_SHOWING, //!< keyboard is not showing
ERROR_IME_ALREADY_STARTED, //!< input method service has already started
ERROR_NOT_IME_PACKAGE, //!< not an IME package
ERROR_IME_PACKAGE_DUPLICATED, //!< duplicated IME package
ERROR_SETTING_SAME_VALUE, //!< same setting value
ERROR_NO_NEXT_IME, //!< no next ime is available
ERROR_CLIENTWINDOW_NOT_FOCUSED, //!< the input client window is not focused
ERROR_CLIENT_NOT_WINDOW, //!< the input client is not from a valid window
// error from ime
ERROR_REMOTE_IME_DIED, //!< remote input method service died abnormally
ERROR_RESTART_IME_FAILED, //!< failed to restart input method service
// error from client
ERROR_REMOTE_CLIENT_DIED, //!< remote client died abnormally
ERROR_CLIENT_DUPLICATED, //!< duplicated client
ERROR_CLIENT_NOT_FOUND, //!< client is not found
};
const char* ToString(int errorCode);
};
static constexpr HiviewDFX::HiLogLabel g_SMALL_SERVICES_LABEL = {
LOG_CORE,
0xD001C00,
"ImsaKit"
};
#define IMSA_HILOGD(fmt, ...) (void)OHOS::HiviewDFX::HiLog::Debug(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \
"line: %d, function: %s," fmt, __LINE__, __FUNCTION__, ##__VA_ARGS__)
#define IMSA_HILOGE(fmt, ...) (void)OHOS::HiviewDFX::HiLog::Error(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \
"line: %d, function: %s," fmt, __LINE__, __FUNCTION__, ##__VA_ARGS__)
#define IMSA_HILOGF(fmt, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \
"line: %d, function: %s," fmt, __LINE__FILE__, __FUNCTION__, ##__VA_ARGS__)
#define IMSA_HILOGI(fmt, ...) (void)OHOS::HiviewDFX::HiLog::Info(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \
"line: %d, function: %s," fmt, __LINE__, __FUNCTION__, ##__VA_ARGS__)
#define IMSA_HILOGW(fmt, ...) (void)OHOS::HiviewDFX::HiLog::Warn(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \
"line: %d, function: %s," fmt, __LINE__, __FUNCTION__, ##__VA_ARGS__)
}
}
#endif // FM_IMMS_PROJECT_GLOBAL_H
@@ -0,0 +1,47 @@
/*
* 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.
*/
#ifndef FM_IMMS_PROJECT_IINPUTCONTROLCHANNEL_H
#define FM_IMMS_PROJECT_IINPUTCONTROLCHANNEL_H
#include "iremote_broker.h"
#include "input_channel.h"
#include "i_input_method_agent.h"
#include "global.h"
namespace OHOS {
namespace MiscServices {
class IInputControlChannel : public IRemoteBroker {
public:
enum {
ON_AGENT_CREATED = FIRST_CALL_TRANSACTION,
HIDE_KEYBOARD_SELF,
ADVANCE_TO_NEXT,
SET_DISPLAY_MODE,
ON_KEYBOARD_SHOWED,
};
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.InputControlChannel");
virtual void onAgentCreated(sptr<IInputMethodAgent>& agent, InputChannel* channel) = 0;
virtual void hideKeyboardSelf(int flags) = 0;
virtual bool advanceToNext(bool isCurrentIme) = 0;
virtual void setDisplayMode(int mode) = 0;
virtual void onKeyboardShowed() = 0;
};
}
}
#endif // FM_IMMS_PROJECT_IINPUTCONTROLCHANNEL_H
+38
View File
@@ -0,0 +1,38 @@
/*
* 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.
*/
#ifndef FM_IMMS_PROJECT_IINPUTMETHODAGENT_H
#define FM_IMMS_PROJECT_IINPUTMETHODAGENT_H
#include "iremote_broker.h"
#include "iremote_object.h"
#include "global.h"
namespace OHOS {
namespace MiscServices {
class IInputMethodProxy : public IRemoteBroker {
public:
enum {
DISPATCH_KEY = FIRST_CALL_TRANSACTION,
};
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IInputMethodProxy");
virtual int32_t dispatchKey(int key, int status) = 0;
};
}
}
#endif // FM_IMMS_PROJECT_IINPUTMETHODAGENT_H
@@ -0,0 +1,67 @@
/*
* 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.
*/
#ifndef FM_IMMS_PROJECT_IINPUTMETHODSYSTEMABILITY_H
#define FM_IMMS_PROJECT_IINPUTMETHODSYSTEMABILITY_H
#include <vector>
#include <errors.h>
#include "iremote_broker.h"
#include "i_input_client.h"
#include "i_input_data_channel.h"
#include "input_attribute.h"
#include "input_method_property.h"
#include "keyboard_type.h"
#include "global.h"
#include "message_parcel.h"
#include "i_input_method_core.h"
namespace OHOS {
namespace MiscServices {
class IInputMethodSystemAbility : public IRemoteBroker {
public:
enum {
PREPARE_INPUT = 0,
RELEASE_INPUT,
START_INPUT,
STOP_INPUT,
SET_INPUT_METHOD_CORE,
GET_DISPLAY_MODE,
GET_KEYBOARD_WINDOW_HEIGHT,
GET_CURRENT_KEYBOARD_TYPE,
LIST_INPUT_METHOD_ENABLED,
LIST_INPUT_METHOD,
LIST_KEYBOARD_TYPE,
};
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IInputMethodSystemAbility");
virtual void prepareInput(MessageParcel& data) = 0;
virtual void releaseInput(MessageParcel& data) = 0;
virtual void startInput(MessageParcel& data) = 0;
virtual void stopInput(MessageParcel& data) = 0;
virtual int32_t setInputMethodCore(sptr<IInputMethodCore> &core)=0;
virtual int32_t getDisplayMode(int32_t *retMode) = 0;
virtual int32_t getKeyboardWindowHeight(int32_t *retHeight) = 0;
virtual int32_t getCurrentKeyboardType(KeyboardType* retType) = 0;
virtual int32_t listInputMethodEnabled(std::vector<InputMethodProperty*> *properties) = 0;
virtual int32_t listInputMethod(std::vector<InputMethodProperty*> *properties) = 0;
virtual int32_t listKeyboardType(const std::u16string& imeId, std::vector<KeyboardType*> *types) = 0;
};
}
}
#endif // FM_IMMS_PROJECT_IINPUTMETHODSYSTEMABILITY_H
+63
View File
@@ -0,0 +1,63 @@
/*
* 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.
*/
#ifndef FM_IMMS_PROJECT_IPLATFORMAPI_H
#define FM_IMMS_PROJECT_IPLATFORMAPI_H
#include <vector>
#include <string>
#include "iremote_broker.h"
#include "ipc_types.h"
#include "i_platform_callback.h"
#include "input_method_property.h"
#include "input_method_setting.h"
#include "i_input_method_core.h"
#include "global.h"
namespace OHOS {
namespace MiscServices {
class IPlatformApi : public IRemoteBroker {
public:
enum {
REGISTER_CALLBACK = FIRST_CALL_TRANSACTION,
BIND_IMS,
UNBIND_IMS,
CREATE_WINDOW_TOKEN,
DESTROY_WINDOW_TOKEN,
LIST_INPUT_METHOD,
GET_INPUT_METHOD_PROPERTY,
GET_INPUT_METHOD_SETTING,
SET_INPUT_METHOD_SETTING,
};
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IPlatformApi");
virtual int32_t registerCallback(const sptr<IPlatformCallback>& cb) = 0;
virtual sptr<IInputMethodCore> bindInputMethodService(const std::u16string& packageName,
const std::u16string& intention, int userId) = 0;
virtual int32_t unbindInputMethodService(int userId, const std::u16string& packageName) = 0;
virtual sptr<IRemoteObject> createWindowToken(int userId, int displayId, const std::u16string& packageName) = 0;
virtual int32_t destroyWindowToken(int userId, const std::u16string& packageName) = 0;
virtual int32_t listInputMethod(int userId, std::vector<InputMethodProperty*> *inputMethodProperties) = 0;
virtual int32_t getInputMethodProperty(int userId, const std::u16string& packageName,
InputMethodProperty *inputMethodProperty) = 0;
virtual int32_t getInputMethodSetting(int userId, InputMethodSetting *inputMethodSetting) = 0;
virtual int32_t setInputMethodSetting(int userId, const InputMethodSetting& inputMethodSetting) = 0;
};
}
}
#endif // FM_IMMS_PROJECT_IPLATFORMAPI_H
+39
View File
@@ -0,0 +1,39 @@
/*
* 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.
*/
#ifndef FM_IMMS_PROJECT_IPLATFORMCALLBACK_H
#define FM_IMMS_PROJECT_IPLATFORMCALLBACK_H
#include <vector>
#include <string>
#include "iremote_broker.h"
#include "ipc_types.h"
#include "global.h"
namespace OHOS {
namespace MiscServices {
class IPlatformCallback : public IRemoteBroker {
public:
enum {
NOTIFY_EVENT = OHOS::FIRST_CALL_TRANSACTION,
};
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IPlatformCallback");
virtual void notifyEvent(int eventId, int userId, const std::vector<std::u16string>& eventContent) = 0;
};
}
}
#endif // FM_IMMS_PROJECT_IPLATFORMCALLBACK_H
+42
View File
@@ -0,0 +1,42 @@
/*
* 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.
*/
#ifndef FM_IMMS_PROJECT_INPUTATTRIBUTE_H
#define FM_IMMS_PROJECT_INPUTATTRIBUTE_H
#include "parcel.h"
namespace OHOS {
namespace MiscServices {
class InputAttribute : public Parcelable {
public:
InputAttribute();
InputAttribute(const InputAttribute& attribute);
InputAttribute& operator=(const InputAttribute& attribute);
~InputAttribute();
virtual bool Marshalling(Parcel &parcel) const override;
static InputAttribute *Unmarshalling(Parcel &parcel);
void SetInputPattern(int32_t pattern);
bool GetSecurityFlag();
static const int32_t PATTERN_TEXT = 0x00000001;
static const int32_t PATTERN_PASSWORD = 0x00000007;
private:
int32_t inputPattern;
int32_t enterKeyType;
int32_t inputOption;
};
}
}
#endif // FM_IMMS_PROJECT_INPUTATTRIBUTE_H
+39
View File
@@ -0,0 +1,39 @@
/*
* 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.
*/
#ifndef FM_IMMS_PROJECT__INPUTCHANNEL_H
#define FM_IMMS_PROJECT__INPUTCHANNEL_H
#include "parcel.h"
#include "global.h"
#include "message_parcel.h"
#include <string>
namespace OHOS {
namespace MiscServices {
class InputChannel : public Parcelable{
public:
InputChannel();
~InputChannel();
virtual bool Marshalling(Parcel &parcel) const override;
static InputChannel *Unmarshalling(Parcel &parcel);
private:
std::u16string name;
MessageParcel inputChannelParcel;
InputChannel(const InputChannel& channel);
InputChannel& operator=(const InputChannel& channel);
};
}
}
#endif // INPUTMETHODSYSTEMSERVICE_INPUTCHANNEL_H
@@ -0,0 +1,46 @@
/*
* 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.
*/
#ifndef FM_IMMS_PROJECT_INPUTCONTROLCHANNELPROXY_H
#define FM_IMMS_PROJECT_INPUTCONTROLCHANNELPROXY_H
#include "parcel.h"
#include "iremote_broker.h"
#include "message_parcel.h"
#include "message_handler.h"
#include "global.h"
#include "iremote_proxy.h"
#include "i_input_control_channel.h"
#include "i_input_method_agent.h"
namespace OHOS {
namespace MiscServices {
class InputControlChannelProxy : public IRemoteProxy<IInputControlChannel> {
public:
InputControlChannelProxy(const sptr<IRemoteObject> &impl);
~InputControlChannelProxy();
virtual void onAgentCreated(sptr<IInputMethodAgent>& agent, InputChannel* channel) override;
virtual void hideKeyboardSelf(int flags) override;
virtual bool advanceToNext(bool isCurrentIme) override;
virtual void setDisplayMode(int mode) override;
virtual void onKeyboardShowed() override;
};
}
}
#endif // FM_IMMS_PROJECT_INPUTCONTROLCHANNELPROXY_H
@@ -0,0 +1,59 @@
/*
* 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.
*/
#ifndef FM_IMMS_PROJECT_INPUTCONTROLCHANNEL_SK_H
#define FM_IMMS_PROJECT_INPUTCONTROLCHANNEL_SK_H
#include "iremote_broker.h"
#include "iremote_stub.h"
#include "i_input_method_agent.h"
#include "input_channel.h"
#include <mutex>
#include <condition_variable>
#include "message_parcel.h"
#include "i_input_control_channel.h"
namespace OHOS {
namespace MiscServices {
class InputControlChannelStub : public IRemoteStub<IInputControlChannel> {
public:
explicit InputControlChannelStub(int userId);
virtual ~InputControlChannelStub();
virtual int OnRemoteRequest(uint32_t code,
MessageParcel &data,
MessageParcel &reply,
MessageOption &option) override;
virtual void onAgentCreated(sptr<IInputMethodAgent>& agent, InputChannel* channel) override;
virtual void hideKeyboardSelf(int flags) override;
virtual bool advanceToNext(bool isCurrentIme) override;
virtual void setDisplayMode(int mode) override;
virtual void onKeyboardShowed() override;
void ResetFlag();
bool GetAgentAndChannel(sptr<IInputMethodAgent>* retAgent, InputChannel** retChannel);
bool WaitKeyboardReady();
private:
int userId_;
sptr<IInputMethodAgent> agent = nullptr;
InputChannel* channel = nullptr;
std::mutex mtx;
std::condition_variable cv;
bool agentReadyFlag = false;
bool keyboardReadyFlag = false;
};
}
}
#endif // FM_IMMS_PROJECT_INPUTCONTROLCHANNEL_SK_H
@@ -0,0 +1,46 @@
/*
* 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.
*/
#ifndef SERVICES_INPUTMETHODABILITYCONNECTIONSTUB_H
#define SERVICES_INPUTMETHODABILITYCONNECTIONSTUB_H
#include "ability_connect_callback_stub.h"
#include "want.h"
#include "element_name.h"
#include "message_handler.h"
#include "iremote_object.h"
#include "global.h"
namespace OHOS {
namespace MiscServices {
class InputMethodAbilityConnectionStub : public AAFwk::AbilityConnectionStub {
public:
enum MessageID {
MSG_ID_ABILITY_CONNECT_DONE = 1,
MSG_ID_ABILITY_DISCONNECT_DONE,
};
InputMethodAbilityConnectionStub(const int index);
~InputMethodAbilityConnectionStub();
void OnAbilityConnectDone(const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override;
void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override;
void SetHandler(MessageHandler* handler);
private:
MessageHandler* messageHandler;
int mIndex;
};
}
}
#endif // SERVICES_INPUTMETHODABILITYCONNECTIONSTUB_H
+44
View File
@@ -0,0 +1,44 @@
/*
* 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.
*/
#ifndef FM_IMMS_PROJECT_INPUTMETHODPROPERTY_H
#define FM_IMMS_PROJECT_INPUTMETHODPROPERTY_H
#include <vector>
#include "parcel.h"
#include <string>
#include "keyboard_type.h"
namespace OHOS {
namespace MiscServices {
class InputMethodProperty : public Parcelable {
public:
std::u16string mImeId;
std::u16string mPackageName;
std::u16string mAbilityName;
std::u16string mConfigurationPage;
bool isSystemIme;
int32_t mDefaultImeId;
std::vector<KeyboardType*> mTypes;
InputMethodProperty();
~InputMethodProperty();
InputMethodProperty(const InputMethodProperty& property);
InputMethodProperty& operator=(const InputMethodProperty& property);
virtual bool Marshalling(Parcel &parcel) const override;
static InputMethodProperty *Unmarshalling(Parcel &parcel);
};
}
}
#endif // FM_IMMS_PROJECT_INPUTMETHODPROPERTY_H
+73
View File
@@ -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.
*/
#ifndef FM_IMMS_PROJECT_INPUTMETHODSETTING_H
#define FM_IMMS_PROJECT_INPUTMETHODSETTING_H
#include <map>
#include <vector>
#include "global.h"
#include "parcel.h"
#include "string.h"
namespace OHOS {
namespace MiscServices {
class InputMethodSetting : public Parcelable {
public:
const static std::u16string CURRENT_INPUT_METHOD_TAG; //!< the item name of 'default IME' in the system setting
const static std::u16string ENABLED_INPUT_METHODS_TAG; //!< the item name of 'enabled IME list' in the system setting
const static std::u16string CURRENT_KEYBOARD_TYPE_TAG; //!< the item name of 'default keyboard type' in the system setting
const static std::u16string CURRENT_SYS_KEYBOARD_TYPE_TAG;
//!< the item name of 'default keyboard type for security IME in the system setting
const static std::u16string SYSTEM_LOCALE_TAG; //!< the item name of locale list supported in the system
InputMethodSetting();
~InputMethodSetting();
InputMethodSetting(const InputMethodSetting& inputMethodSetting);
InputMethodSetting& operator=(const InputMethodSetting& inputMethodSetting);
void SetValue(const std::u16string& key, const std::u16string& value);
std::u16string GetValue(const std::u16string& key) const;
std::u16string GetCurrentInputMethod() const;
void SetCurrentInputMethod(const std::u16string& imeId);
std::vector<std::u16string> GetEnabledInputMethodList();
bool AddEnabledInputMethod(const std::u16string& imeId, const std::vector<int32_t>& types);
bool RemoveEnabledInputMethod(const std::u16string& imdId);
std::vector<int32_t> GetEnabledKeyboardTypes(const std::u16string& imeId);
int32_t GetCurrentKeyboardType();
void SetCurrentKeyboardType(int32_t type);
int32_t GetCurrentSysKeyboardType();
void SetCurrentSysKeyboardType(int32_t type);
void ClearData();
bool FindKey(const std::u16string& key) const;
virtual bool Marshalling(Parcel &parcel) const override;
static InputMethodSetting *Unmarshalling(Parcel &parcel);
private:
std::map<std::u16string, std::u16string> setting;
const char16_t DELIM_IME = ':';
const char16_t DELIM_KBD_TYPE = ';';
std::vector<std::u16string> Split(const std::u16string& str, char16_t delim);
std::u16string BuildString(const std::vector<std::u16string>& vector, char16_t delim);
};
}
}
#endif // FM_IMMS_PROJECT_INPUTMETHODSETTING_H
@@ -0,0 +1,94 @@
/*
* 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.
*/
#ifndef FM_IMMS_PROJECT_INPUTMETHODSYSTEMABILITY_H
#define FM_IMMS_PROJECT_INPUTMETHODSYSTEMABILITY_H
#include <thread>
#include <map>
#include "system_ability.h"
#include "input_method_system_ability_stub.h"
#include "peruser_setting.h"
#include "peruser_session.h"
#include "event_handler.h"
#include "input_method_ability.h"
namespace OHOS {
namespace MiscServices {
enum class ServiceRunningState {
STATE_NOT_START,
STATE_RUNNING
};
class InputMethodSystemAbility : public SystemAbility, public InputMethodSystemAbilityStub {
DECLARE_SYSTEM_ABILITY(InputMethodSystemAbility);
public:
DISALLOW_COPY_AND_MOVE(InputMethodSystemAbility);
InputMethodSystemAbility(int32_t systemAbilityId, bool runOnCreate);
InputMethodSystemAbility();
~InputMethodSystemAbility();
static sptr<InputMethodSystemAbility> GetInstance();
int32_t GetUserState(int32_t userId);
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
virtual int32_t getDisplayMode(int32_t *retMode) override;
virtual int32_t getKeyboardWindowHeight(int32_t *retHeight) override;
virtual int32_t getCurrentKeyboardType(KeyboardType* retType) override;
virtual int32_t listInputMethodEnabled(std::vector<InputMethodProperty*> *properties) override;
virtual int32_t listInputMethod(std::vector<InputMethodProperty*> *properties) override;
virtual int32_t listKeyboardType(const std::u16string& imeId, std::vector<KeyboardType*> *types) override;
int32_t dump(int32_t fd, const std::vector<std::u16string>& args);
virtual int32_t setInputMethodCore(sptr<IInputMethodCore> &core) override;
protected:
void OnStart() override;
void OnStop() override;
private:
int32_t Init();
void Initialize();
std::thread workThreadHandler; /*!< thread handler of the WorkThread */
std::map<int32_t, PerUserSetting*> userSettings;
std::map<int32_t, PerUserSession*> userSessions;
std::map<int32_t, MessageHandler*> msgHandlers;
void WorkThread();
PerUserSetting* GetUserSetting(int32_t userId);
PerUserSession* GetUserSession(int32_t userId);
int32_t OnUserStarted(const Message* msg);
int32_t OnUserStopped(const Message* msg);
int32_t OnUserUnlocked(const Message* msg);
int32_t OnUserLocked(const Message* msg);
int32_t OnPrepareInput(Message* msg);
int32_t OnHandleMessage(Message* msg);
int32_t OnRemotePeerDied(const Message* msg);
int32_t OnSettingChanged(const Message* msg);
int32_t OnPackageRemoved(const Message* msg);
int32_t OnPackageAdded(const Message* msg);
int32_t OnDisableIms(const Message* msg);
int32_t OnAdvanceToNext(const Message* msg);
ServiceRunningState state_;
sptr<InputMethodAbility> inputMethodAbility_;
void InitServiceHandler();
static std::mutex instanceLock_;
static sptr<InputMethodSystemAbility> instance_;
static std::shared_ptr<AppExecFwk::EventHandler> serviceHandler_;
};
}
}
#endif // FM_IMMS_PROJECT_INPUTMETHODSYSTEMABILITY_H
@@ -0,0 +1,42 @@
/*
* 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.
*/
#ifndef FM_IMMS_PROJECT_INPUTMETHODSYSTEMABILITY_SK_H
#define FM_IMMS_PROJECT_INPUTMETHODSYSTEMABILITY_SK_H
#include <errors.h>
#include "refbase.h"
#include "i_input_method_system_ability.h"
#include "iremote_stub.h"
#include "global.h"
#include "message_parcel.h"
namespace OHOS {
namespace MiscServices {
class InputMethodSystemAbilityStub : public IRemoteStub<IInputMethodSystemAbility> {
public:
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
virtual void prepareInput(MessageParcel& data) override;
virtual void releaseInput(MessageParcel& data) override;
virtual void startInput(MessageParcel& data) override;
virtual void stopInput(MessageParcel& data) override;
void setInputMethodCoreFromHap(MessageParcel& data);
protected:
int32_t getUserId(int32_t uid);
};
}
}
#endif // FM_IMMS_PROJECT_INPUTMETHODSYSTEMABILITY_SK_H
+63
View File
@@ -0,0 +1,63 @@
/*
* 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.
*/
#ifndef FM_IMMS_PROJECT_KEYBOARDTYPE_H
#define FM_IMMS_PROJECT_KEYBOARDTYPE_H
#include <vector>
#include "parcel.h"
#include <string>
namespace OHOS {
namespace MiscServices {
class KeyboardType : public Parcelable {
public:
KeyboardType();
KeyboardType(const KeyboardType& type);
~KeyboardType();
KeyboardType& operator=(const KeyboardType& type);
virtual bool Marshalling(Parcel &parcel) const override;
static KeyboardType *Unmarshalling(Parcel &parcel);
void setId(int32_t typeId);
void setLabelId(int32_t labelId);
void setIconId(int32_t iconId);
void setAsciiCapability(bool isAsciiCapable);
void setLanguage(std::u16string language);
void setInputSource(std::u16string inputSource);
void setCustomizedValue(std::u16string keyBoardTypeCustomizedValue);
int32_t getId() const;
int32_t getLabelId() const;
int32_t getIconId() const;
int32_t getHashCode() const;
std::u16string getLanguage() const;
std::u16string getInputSource() const;
std::u16string getCustomizedValue() const;
bool supportsAscii();
private:
int32_t mId;
int32_t mHashCode;
int32_t mLabelId;
int32_t mIconId;
bool mIsAsciiCapable;
std::u16string mLanguage;
std::u16string mInputSource;
std::u16string mCustomizedValue;
const int32_t ID_NONE = 0;
};
}
}
#endif // FM_IMMS_PROJECT_KEYBOARDTYPE_H
+39
View File
@@ -0,0 +1,39 @@
/*
* 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.
*/
/*! \file MessageHandler.h */
#ifndef FM_IMMS_PROJECT_MESSAGE_H
#define FM_IMMS_PROJECT_MESSAGE_H
#include "global.h"
#include "message_parcel.h"
namespace OHOS {
namespace MiscServices {
class Message {
public:
int32_t msgId_; //!< message id
MessageParcel *msgContent_ = nullptr; //!< message content
Message(int32_t msgId, MessageParcel* msgContent);
explicit Message(const Message& msg);
Message& operator= (const Message& msg);
~Message();
private:
Message(const Message&&);
Message& operator= (const Message&&);
};
}
}
#endif // FM_IMMS_PROJECT_MESSAGE_H
+100
View File
@@ -0,0 +1,100 @@
/*
* 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.
*/
/*! \file MessageHandler.h */
#ifndef FM_IMMS_PROJECT_MESSAGEHANDLER_H
#define FM_IMMS_PROJECT_MESSAGEHANDLER_H
#include <queue>
#include <mutex>
#include <condition_variable>
#include "global.h"
#include "message_parcel.h"
#include "message.h"
namespace OHOS {
namespace MiscServices {
namespace MessageID {
enum {
// for system broadcast
MSG_ID_SYSTEM_START = 0, //!< system started
MSG_ID_SYSTEM_STOP, //!< system stopped
MSG_ID_USER_START, //!< a user started
MSG_ID_USER_STOP, //!< a user stopped
MSG_ID_USER_UNLOCK, //!< a user unlocked
MSG_ID_USER_LOCK, //!< a user locked
MSG_ID_PACKAGE_ADDED, //!< a package is installed
MSG_ID_PACKAGE_REMOVED, //!< a package is removed
MSG_ID_SETTING_CHANGED, //!< input method setting is changed
// the request from client
MSG_ID_PREPARE_INPUT, //!< prepare input
MSG_ID_START_INPUT, //!< start input
MSG_ID_STOP_INPUT, //!< stop input
MSG_ID_RELEASE_INPUT, //!< release input
MSG_ID_SET_INPUT_METHOD_CORE,
// the request to handle the condition that the remote object died
MSG_ID_CLIENT_DIED, //!< input client died
MSG_ID_IMS_DIED, //!< input method service died
MSG_ID_DISABLE_IMS, //!< disable input method service
MSG_ID_RESTART_IMS, //!< restart input method service
MSG_ID_HIDE_KEYBOARD_SELF, //!< hide the current keyboard
MSG_ID_ADVANCE_TO_NEXT, //!< switch to next
MSG_ID_SET_DISPLAY_MODE, //!< set display mode
MSG_ID_SHELL_COMMAND, //!< shell command
MSG_ID_EXIT_SERVICE, //!< exit service
//the request from IMSA to IMC
MSG_ID_INSERT_CHAR,
MSG_ID_DELETE_BACKWARD,
MSG_ID_CLOSE,
MSG_ID_ON_INPUT_READY,
// the request from IMSA to IMA
MSG_ID_SHOW_KEYBOARD, //
MSG_ID_INITIALIZE_INPUT, //
MSG_ID_HIDE_KEYBOARD, //
MSG_ID_SET_KEYBOARD_TYPE,
MSG_ID_GET_KEYBOARD_WINDOW_HEIGHT,
// the request from IMC to IMA
MSG_ID_DISPATCH_KEY,//!< dispatch key from PhysicalKbd
};
}
class MessageHandler {
public:
MessageHandler();
~MessageHandler();
void SendMessage(Message* msg);
Message* GetMessage();
static MessageHandler* Instance();
private:
std::mutex mMutex; //!< a mutex to guard message queue
std::condition_variable mCV; //!< condition variable to work with mMutex
std::queue<Message*> mQueue ;//!< Message queue, guarded by mMutex;
MessageHandler(const MessageHandler&);
MessageHandler& operator= (const MessageHandler&);
MessageHandler(const MessageHandler&&);
MessageHandler& operator= (const MessageHandler&&);
};
}
}
#endif // FM_IMMS_PROJECT_MESSAGEHANDLER_H
+196
View File
@@ -0,0 +1,196 @@
/*
* 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.
*/
#ifndef FM_IMMS_PROJECT_PERUSERSESSION_H
#define FM_IMMS_PROJECT_PERUSERSESSION_H
#include <thread>
#include <mutex>
#include <map>
#include <memory>
#include "iremote_object.h"
#include "i_input_control_channel.h"
#include "i_input_client.h"
#include "i_input_method_core.h"
#include "i_input_data_channel.h"
#include "i_input_method_agent.h"
#include "input_attribute.h"
#include "input_method_property.h"
#include "input_method_setting.h"
#include "input_control_channel_stub.h"
#include "message.h"
#include "message_handler.h"
#include "global.h"
#include "platform.h"
#include "keyboard_type.h"
#include "ability_manager_interface.h"
#include "ability_connect_callback_proxy.h"
#include "input_method_ability.h"
namespace OHOS {
namespace MiscServices {
class RemoteObjectDeathRecipient : public IRemoteObject::DeathRecipient {
public:
RemoteObjectDeathRecipient(int userId, int msgId);
~RemoteObjectDeathRecipient();
void OnRemoteDied(const wptr<IRemoteObject>& who) override;
private :
int userId_; //!< the id of the user to whom the object is linking
int msgId_; //!< the message id can be MessageID::MSG_ID_CLIENT_DIED and MessageID::MSG_ID_IMS_DIED
};
/*! \class ClientInfo
\brief The class defines the details of an input client.
*/
class ClientInfo {
public:
int pid; //!< the process id of the process in which the input client is running
int uid; //!< the uid of the process in which the input client is running
int userId; //!< the user if of the user under which the input client is running
int displayId; //!< the display id on which the input client is showing
sptr<IInputClient> client; //!< the remote object handler for the service to callback to the input client
sptr<IInputDataChannel> channel; //!< the remote object handler for input method service callback to input client
InputAttribute attribute; //!< the input attribute of the input client
ClientInfo(int pid, int uid, int userId, int displayId, const sptr<IInputClient>& client,
const sptr<IInputDataChannel>& channel, const InputAttribute& attribute)
{
this->pid = pid;
this->uid = uid;
this->userId = userId;
this->displayId = displayId;
this->client = client;
this->channel = channel;
this->attribute = attribute;
};
~ClientInfo()
{
this->client = nullptr;
this->channel = nullptr;
};
};
/*! \class PerUserSession
\brief The class provides session management in input method management service
This class manages the sessions between input clients and input method engines for each unlocked user.
*/
class PerUserSession {
enum {
DEFAULT_IME = 0, //!< index for default input method service
SECURITY_IME = 1, //!< index for security input method service
MAX_IME = 2, //!< the maximum count of ims started for a user
};
public:
explicit PerUserSession(int userId);
~PerUserSession();
void SetCurrentIme(InputMethodProperty* ime);
void SetSecurityIme(InputMethodProperty* ime);
void SetInputMethodSetting(InputMethodSetting* setting);
void ResetIme(InputMethodProperty* defaultIme, InputMethodProperty* securityIme);
void OnPackageRemoved(const std::u16string& packageName);
int GetDisplayMode();
int GetKeyboardWindowHeight(int *retHeight);
KeyboardType* GetCurrentKeyboardType();
int OnSettingChanged(const std::u16string& key, const std::u16string& value);
void Dump(int fd);
void CreateWorkThread(MessageHandler& handler);
void JoinWorkThread();
void SetInputMethodAbility(sptr<InputMethodAbility> &inputMethodAbility);
static void BindInputAbility();
private:
int userId_; //!< the id of the user to whom the object is linking
int userState; //!< the state of the user to whom the object is linking
int displayId; //!< the id of the display screen on which the user is
int currentIndex;
std::map<sptr<IRemoteObject>, ClientInfo*> mapClients; //!< a map to manage the input clients connected to the service
/*!< \n key is the remote IInputClient handler
\n value is an object of an ClientInfo */
InputMethodProperty* currentIme[MAX_IME]; //!< 0 - the default ime. 1 - security ime
/*!< \n The pointers are referred to the objects in the PerUserSetting */
InputControlChannelStub* localControlChannel[MAX_IME]; //!< inputControlChannel object used by the local process
sptr<IInputControlChannel> inputControlChannel[MAX_IME]; //!< channels between the service and input method service
sptr<IInputMethodCore> imsCore[MAX_IME]; //!< the remote handlers of input method service
sptr<IRemoteObject> inputMethodToken[MAX_IME]; //!< the window token of keyboard
int currentKbdIndex[MAX_IME]; //!< current keyboard index
int lastImeIndex; //!< The last ime which showed keyboard
InputMethodSetting* inputMethodSetting; //!< The pointer referred to the object in PerUserSetting
int currentDisplayMode; //!< the display mode of the current keyboard
sptr<IInputMethodAgent> imsAgent;
InputChannel* imsChannel; //!< the write channel created by input method service
sptr<IInputClient> currentClient; //!< the current input client
sptr<IInputClient> needReshowClient; //!< the input client for which keyboard need to re-show
sptr<RemoteObjectDeathRecipient> clientDeathRecipient; //!< remote object death monitor for input client
sptr<RemoteObjectDeathRecipient> imsDeathRecipient; //!< remote object death monitor for input method service
MessageHandler* msgHandler = nullptr; //!< message handler working with Work Thread
std::thread workThreadHandler; //!< work thread handler
std::mutex mtx; //!< mutex to lock the operations among multi work threads
sptr<AAFwk::AbilityConnectionProxy> connCallback;
sptr<InputMethodAbility> inputMethodAbility_;
PerUserSession(const PerUserSession&);
PerUserSession& operator= (const PerUserSession&);
PerUserSession(const PerUserSession&&);
PerUserSession& operator= (const PerUserSession&&);
int IncreaseOrResetImeError(bool resetFlag, int imeIndex);
KeyboardType* GetKeyboardType(int imeIndex, int typeIndex);
void ResetCurrentKeyboardType(int imeIndex);
int OnCurrentKeyboardTypeChanged(int index, const std::u16string& value);
void DumpClientInfo(int fd, const ClientInfo& clientInfo);
void DumpCurrentSession(int fd);
void CopyInputMethodService(int imeIndex);
ClientInfo* GetClientInfo(const sptr<IInputClient>& inputClient);
void WorkThread();
void OnPrepareInput(Message* msg);
void OnReleaseInput(Message* msg);
void OnStartInput(Message* msg);
void OnStopInput(Message* msg);
void OnClientDied(const wptr<IRemoteObject>& who);
void OnImsDied(const wptr<IRemoteObject>& who);
void OnHideKeyboardSelf(int flags);
void OnAdvanceToNext();
void OnSetDisplayMode(int mode);
void OnRestartIms(int index, const std::u16string& imeId);
void OnUserLocked();
int AddClient(int pid, int uid, int displayId, const sptr<IInputClient>& inputClient,
const sptr<IInputDataChannel>& channel,
const InputAttribute& attribute);
int RemoveClient(const sptr<IInputClient>& inputClient, int *retClientNum);
int StartInputMethod(int index);
int StopInputMethod(int index);
int ShowKeyboard(const sptr<IInputClient>& inputClient);
int HideKeyboard(const sptr<IInputClient>& inputClient);
void SetDisplayId(int displayId);
int GetImeIndex(const sptr<IInputClient>& inputClient);
static sptr<AAFwk::IAbilityManager> GetAbilityManagerService();
void onSetInputMethodCore(Message* msg);
};
}
}
#endif // FM_IMMS_PROJECT_PERUSERSESSION_H
+73
View File
@@ -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.
*/
#ifndef FM_IMMS_PROJECT_PERUSERSETTING_H
#define FM_IMMS_PROJECT_PERUSERSETTING_H
#include <map>
#include <string>
#include <vector>
#include "input_method_property.h"
#include "input_method_setting.h"
#include "global.h"
namespace OHOS {
namespace MiscServices {
class PerUserSetting {
public:
explicit PerUserSetting(int32_t userId);
~PerUserSetting();
void Initialize();
int32_t GetUserState();
InputMethodProperty* GetCurrentInputMethod();
InputMethodProperty* GetSecurityInputMethod();
InputMethodProperty* GetNextInputMethod();
InputMethodSetting* GetInputMethodSetting();
InputMethodProperty* GetInputMethodProperty(const std::u16string& imeId);
int32_t OnPackageAdded(std::u16string& packageName, bool* isSecurityIme = nullptr);
int32_t OnPackageRemoved(std::u16string& packageName, bool* isSecurityIme = nullptr);
int32_t OnSettingChanged(const std::u16string& key, const std::u16string& value);
void OnAdvanceToNext();
void OnUserLocked();
void Dump(int32_t fd);
int32_t ListInputMethodEnabled(std::vector<InputMethodProperty*> *properties);
int32_t ListInputMethod(std::vector<InputMethodProperty*> *properties);
int32_t ListKeyboardType(const std::u16string& imeId, std::vector<KeyboardType*> *types);
static bool CheckIfSecurityIme(const InputMethodProperty& property);
private:
int32_t userId_; //!< the id of the user to whom the object is linking
int32_t userState; //!< the state of the user to whom the object is linking
std::vector<InputMethodProperty*> inputMethodProperties; //!< a vector to save all IME installed for this user
std::u16string currentImeId; //!< the id of the default input method engine.
InputMethodSetting inputMethodSetting; //!< the object to manage the setting data for this user
PerUserSetting(const PerUserSetting&);
PerUserSetting& operator= (const PerUserSetting&);
PerUserSetting(const PerUserSetting&&);
PerUserSetting& operator= (const PerUserSetting&&);
void InitInputMethodSetting();
void ResetCurrentInputMethod();
std::u16string GetKeyboardTypeLanguage(const InputMethodProperty* property, int32_t hashCode);
std::u16string GetImeId(const std::u16string& packageName);
};
}
}
#endif // FM_IMMS_PROJECT_PERUSERSETTING_H
+66
View File
@@ -0,0 +1,66 @@
/*
* 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.
*/
#ifndef FM_IMMS_PROJECT_PLATFORMAPI_H
#define FM_IMMS_PROJECT_PLATFORMAPI_H
#include <vector>
#include <string>
#include <memory>
#include "iremote_broker.h"
#include "iremote_object.h"
#include "i_platform_api.h"
#include "i_input_method_core.h"
#include "input_method_property.h"
#include "input_method_setting.h"
namespace OHOS {
namespace MiscServices {
class Platform {
public:
static Platform* Instance();
void SetPlatform(const sptr<IPlatformApi>& platformApi);
sptr<IInputMethodCore> BindInputMethodService(int userId, const std::u16string& packageName, const std::u16string& intention);
int UnbindInputMethodService(int userId, const std::u16string& packageName);
sptr<IRemoteObject> CreateWindowToken(int userId, int displayId, const std::u16string& packageName);
int DestroyWindowToken(int userId, const std::u16string& packageName);
int ListInputMethod(int userId, std::vector<InputMethodProperty*>* inputMethodProperties);
int GetInputMethodProperty(int userId, const std::u16string& packageName, InputMethodProperty* inputMethodProperty);
int GetInputMethodSetting(int userId, InputMethodSetting* inputMethodSetting);
int SetInputMethodSetting(int userId, const InputMethodSetting& inputMethodSetting);
bool CheckPhysicalKeyboard();
bool IsValidWindow(int uid, int pid, int displayId);
bool IsWindowFocused(int uid, int pid, int displayId);
static inline sptr<IRemoteObject> RemoteBrokerToObject(const sptr<IRemoteBroker>& broker)
{
return broker->AsObject();
}
private:
sptr<IPlatformApi> platformApi;
Platform();
~Platform();
Platform(const Platform&);
Platform& operator = (const Platform&);
Platform(const Platform&&);
Platform& operator = (const Platform&&);
};
}
}
#endif // FM_IMMS_PROJECT_PLATFORMAPI_H
+39
View File
@@ -0,0 +1,39 @@
/*
* 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.
*/
#ifndef FM_IMMS_PROJECT_PLATFORMCALLBACK_SK_H
#define FM_IMMS_PROJECT_PLATFORMCALLBACK_SK_H
#include <string>
#include "iremote_stub.h"
#include "message_option.h"
#include "message_parcel.h"
#include "i_platform_callback.h"
namespace OHOS {
namespace MiscServices {
class PlatformCallbackStub : public IRemoteStub<IPlatformCallback> {
public:
PlatformCallbackStub();
~PlatformCallbackStub();
virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
virtual void notifyEvent(int eventId, int userId, const std::vector<std::u16string>& eventContent) override;
};
}
}
#endif // FM_IMMS_PROJECT_PLATFORMCALLBACK_SK_H
+40
View File
@@ -0,0 +1,40 @@
/*
* 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.
*/
/*! \file utils.h */
#ifndef FM_IMMS_PROJECT_UTILS_H
#define FM_IMMS_PROJECT_UTILS_H
#include <string>
#include <codecvt>
#include <locale>
#include <iostream>
namespace OHOS {
namespace MiscServices {
class Utils {
public:
static std::string to_utf8( std::u16string str16 ) {
return std::wstring_convert< std::codecvt_utf8_utf16<char16_t>, char16_t >{}.to_bytes(str16);
}
static std::u16string to_utf16( std::string str ) {
return std::wstring_convert< std::codecvt_utf8_utf16<char16_t>, char16_t >{}.from_bytes(str);
}
};
}
}
#endif