Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/wakelock_plus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## NEXT

* Use wrapper API.

## 2.1.5

* Update wakelock_plus to 1.8.0.
Expand Down
20 changes: 20 additions & 0 deletions packages/wakelock_plus/tizen/inc/ftpw_wakelock_plus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2026 Samsung Electronics Co., Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_TIZEN_PLUGINS_WRAPPER_WAKELOCK_PLUS_H_
#define FLUTTER_TIZEN_PLUGINS_WRAPPER_WAKELOCK_PLUS_H_

#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

int ftpw_wakelock_plus_screensaver_reset_timeout(void);
int ftpw_wakelock_plus_screensaver_override_reset(bool onoff);

#ifdef __cplusplus
}
#endif

#endif
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions packages/wakelock_plus/tizen/project_def.prop
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ USER_CPP_UNDEFS =
USER_INC_DIRS = inc src
USER_INC_FILES =
USER_CPP_INC_FILES =

# User libraries
USER_LIB_DIRS += lib/${BUILD_ARCH}
USER_LIBS += ftpw_wakelock_plus
55 changes: 10 additions & 45 deletions packages/wakelock_plus/tizen/src/wakelock_plus_tizen_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@

#include "wakelock_plus_tizen_plugin.h"

#include <dlfcn.h>
#include <flutter/method_channel.h>
#include <flutter/plugin_registrar.h>
#include <flutter/standard_method_codec.h>
#include <glib.h>
#include <tizen.h>

#include <cerrno>
#include <memory>
#include <string>
#include <variant>

#include "ftpw_wakelock_plus.h"
#include "log.h"

namespace {

typedef int (*FuncScreensaverResetTimeout)(void);
typedef int (*FuncScreensaverOverrideReset)(bool onoff);

class WakelockPlusTizenPlugin : public flutter::Plugin {
public:
static void RegisterWithRegistrar(flutter::PluginRegistrar *registrar) {
Expand All @@ -46,10 +44,6 @@ class WakelockPlusTizenPlugin : public flutter::Plugin {
g_source_remove(timer_id_);
timer_id_ = 0;
}
if (screensaver_api_handle_) {
dlclose(screensaver_api_handle_);
screensaver_api_handle_ = nullptr;
}
}

private:
Expand All @@ -58,7 +52,11 @@ class WakelockPlusTizenPlugin : public flutter::Plugin {
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
const auto &method_name = method_call.method_name();
if (!is_initialized_screensaver_api_) {
InitScreensaverApi();
int ret = ftpw_wakelock_plus_screensaver_override_reset(false);
if (ret != 0) {
LOG_ERROR("screensaver_override_reset failed: %s",
get_error_message(ret));
}
is_initialized_screensaver_api_ = true;
}

Expand All @@ -67,12 +65,12 @@ class WakelockPlusTizenPlugin : public flutter::Plugin {
if (std::holds_alternative<bool>(arguments)) {
bool enable = std::get<bool>(arguments);
if (enable) {
if (!screensaver_reset_timeout_) {
int ret = ftpw_wakelock_plus_screensaver_reset_timeout();
if (ret == -ENOSYS) {
result->Error("Not supported",
"The screensaver API is not supported.");
return;
}
int ret = screensaver_reset_timeout_();
if (ret != 0) {
result->Error(std::to_string(ret), get_error_message(ret));
return;
Expand Down Expand Up @@ -101,40 +99,9 @@ class WakelockPlusTizenPlugin : public flutter::Plugin {
}
}

void InitScreensaverApi() {
screensaver_api_handle_ = dlopen("libcapi-screensaver.so", RTLD_LAZY);
if (!screensaver_api_handle_) {
LOG_ERROR("dlopen failed: %s", dlerror());
return;
}
screensaver_reset_timeout_ = reinterpret_cast<FuncScreensaverResetTimeout>(
dlsym(screensaver_api_handle_, "screensaver_reset_timeout"));
if (!screensaver_reset_timeout_) {
LOG_ERROR("Symbol not found: %s", dlerror());
return;
}
FuncScreensaverOverrideReset screensaver_override_reset =
reinterpret_cast<FuncScreensaverOverrideReset>(
dlsym(screensaver_api_handle_, "screensaver_override_reset"));
if (!screensaver_override_reset) {
LOG_ERROR("Symbol not found: %s", dlerror());
return;
}
int ret = screensaver_override_reset(false);
if (ret != 0) {
LOG_ERROR("screensaver_override_reset failed: %s",
get_error_message(ret));
return;
}
}

static gboolean OnResetScreensaverTimeout(gpointer data) {
auto *plugin = static_cast<WakelockPlusTizenPlugin *>(data);
if (!plugin->screensaver_reset_timeout_) {
plugin->timer_id_ = 0;
return G_SOURCE_REMOVE;
}
int ret = plugin->screensaver_reset_timeout_();
int ret = ftpw_wakelock_plus_screensaver_reset_timeout();
if (ret != 0) {
LOG_ERROR("screensaver_reset_timeout failed: %s", get_error_message(ret));
plugin->timer_id_ = 0;
Expand All @@ -145,9 +112,7 @@ class WakelockPlusTizenPlugin : public flutter::Plugin {
}

bool is_initialized_screensaver_api_ = false;
void *screensaver_api_handle_ = nullptr;
guint timer_id_ = 0;
FuncScreensaverResetTimeout screensaver_reset_timeout_ = nullptr;
bool is_enabled_ = false;
};

Expand Down
Loading