Skip to content

Commit cbfc9dd

Browse files
committed
Improve error handling in tcore clipboard and IMF context
Fail gracefully when the tizen-core-wl display cannot be obtained in TizenClipboard, validate the fd and handle partial write() results when sending clipboard data, and check the tizen_core_imf_init() result so that tizen_core_imf_shutdown() is only called when the library was actually initialized.
1 parent 14ed60c commit cbfc9dd

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

flutter/shell/platform/tizen/tizen_clipboard.cc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ TizenClipboard::TizenClipboard(TizenViewBase* view) {
3636
tizen_core_wl_get_connected_display(nullptr, &display_);
3737
}
3838

39+
if (!display_) {
40+
FT_LOG(Error) << "Failed to obtain a tizen-core-wl display.";
41+
return;
42+
}
43+
3944
tizen_core_wl_display_get_event(display_, &tcore_wl_event_);
4045

4146
tizen_core_wl_event_add_listener(
@@ -104,7 +109,22 @@ void TizenClipboard::SendData(void* event) {
104109
return;
105110
}
106111

107-
write(fd, data_.c_str(), data_.length());
112+
if (fd < 0) {
113+
FT_LOG(Error) << "Invalid fd.";
114+
return;
115+
}
116+
117+
const char* buffer = data_.c_str();
118+
size_t remaining = data_.length();
119+
while (remaining > 0) {
120+
ssize_t written = write(fd, buffer, remaining);
121+
if (written < 0) {
122+
FT_LOG(Error) << "Failed to write clipboard data.";
123+
break;
124+
}
125+
buffer += written;
126+
remaining -= written;
127+
}
108128
close(fd);
109129
}
110130

flutter/shell/platform/tizen/tizen_input_method_context_tcore.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ tizen_core_imf_event_key_h CreateImfKeyEventFromTcoreWlEvent(void* event) {
134134
namespace flutter {
135135

136136
TizenInputMethodContext::TizenInputMethodContext(uintptr_t window_id) {
137-
tizen_core_imf_init();
137+
if (tizen_core_imf_init() != TIZEN_CORE_IMF_ERROR_NONE) {
138+
FT_LOG(Error) << "Failed to initialize tizen_core_imf.";
139+
return;
140+
}
141+
imf_initialized_ = true;
138142

139143
if (tizen_core_imf_context_create(&imf_context_) !=
140144
TIZEN_CORE_IMF_ERROR_NONE) {
@@ -157,7 +161,9 @@ TizenInputMethodContext::~TizenInputMethodContext() {
157161
tizen_core_imf_context_destroy(imf_context_);
158162
}
159163

160-
tizen_core_imf_shutdown();
164+
if (imf_initialized_) {
165+
tizen_core_imf_shutdown();
166+
}
161167
}
162168

163169
bool TizenInputMethodContext::HandleTcoreWlEventKey(void* event, bool is_down) {

flutter/shell/platform/tizen/tizen_input_method_context_tcore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class TizenInputMethodContext {
8888
void SetContextOptions();
8989
void SetInputPanelOptions();
9090

91+
bool imf_initialized_ = false;
9192
tizen_core_imf_context_h imf_context_ = nullptr;
9293
OnCommit on_commit_;
9394
OnPreeditChanged on_preedit_changed_;

0 commit comments

Comments
 (0)