--- /dev/null
+/*
+ * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 "DisplayAutoBrightness.h"
+#include <sstream>
+#include <string>
+#include <vconf.h>
+#include <modes_errors.h>
+#include "plugin-log.h"
+
+MODES_NAMESPACE_USE;
+
+const std::string DisplayAutoBrightness::NAME = "autoBrightness";
+const char* const DisplayAutoBrightness::key = VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT;
+
+DisplayAutoBrightness::DisplayAutoBrightness()
+ :DisplayAction(NAME), oldVal(-1)
+{
+}
+
+DisplayAutoBrightness::~DisplayAutoBrightness()
+{
+}
+
+int DisplayAutoBrightness::set(int val)
+{
+ int ret = vconf_get_int(key, &oldVal);
+ if (0 != ret) {
+ ERR("vconf_get_int(%s) Fail(%d)", key, ret);
+ return MODES_ERROR_SYSTEM;
+ }
+
+ if (oldVal == val) {
+ INFO("Auto brightness already set(%d)", val);
+ return MODES_ERROR_NONE;
+ }
+
+ ret = vconf_set_int(key, val);
+ if (0 != ret) {
+ ERR("vconf_set_int(%s, %d) Fail(%d)", key, val, ret);
+ return MODES_ERROR_SYSTEM;
+ }
+
+ return MODES_ERROR_NONE;
+}
+
+void DisplayAutoBrightness::undo()
+{
+ RET_IF(-1 == oldVal);
+
+ int ret = vconf_set_int(key, oldVal);
+ if (0 != ret)
+ ERR("vconf_set_int(%s, %d) Fail(%d)", key, oldVal, ret);
+}
+
+std::string DisplayAutoBrightness::serialize()
+{
+ std::ostringstream ostr;
+
+ ostr << oldVal;
+ return ostr.str();
+}
+
+int DisplayAutoBrightness::parse(const std::string &archive)
+{
+ std::istringstream iss(archive);
+ iss >> oldVal;
+
+ return MODES_ERROR_NONE;
+}
+
+int DisplayAutoBrightness::setChangedCallback(valueChangedCB callback, void *userData)
+{
+ cbData = userData;
+ cb = callback;
+ int ret = vconf_notify_key_changed(key, autoBrightnessChangedCB, this);
+ if (0 != ret) {
+ ERR("vconf_notify_key_changed(%s) Fail(%d)", key, ret);
+ return MODES_ERROR_SYSTEM;
+ }
+ return MODES_ERROR_NONE;
+}
+
+void DisplayAutoBrightness::unSetChangedCallback(valueChangedCB callback, void *userData)
+{
+ int ret = vconf_ignore_key_changed(key, autoBrightnessChangedCB);
+ if (0 != ret)
+ ERR("vconf_ignore_key_changed(%s) Fail(%d)", key, ret);
+
+ cbData = NULL;
+ cb = NULL;
+}
+
+void DisplayAutoBrightness::autoBrightnessChangedCB(keynode_t *node, void *userData)
+{
+ DisplayAutoBrightness *action = (DisplayAutoBrightness*)userData;
+
+ RET_IF(NULL == userData);
+
+ int val = 0;
+ int ret = vconf_get_int(key, &val);
+ if (0 != ret) {
+ ERR("vconf_get_int(%s) Fail(%d)", key, ret);
+ return;
+ }
+
+ if (action->cb && (val != action->autoBrightness))
+ action->cb(action->cbData);
+}
--- /dev/null
+/*
+ * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.
+ */
+#pragma once
+
+#include <string>
+#include <vconf.h>
+#include "plugin-def.h"
+#include "DisplayAction.h"
+
+MODES_NAMESPACE_BEGIN
+
+class DisplayAutoBrightness : public DisplayAction {
+public:
+ DisplayAutoBrightness();
+ ~DisplayAutoBrightness();
+
+ int set(int val) override;
+ void undo() override;
+ std::string serialize() override;
+ int parse(const std::string &archive) override;
+
+ int setChangedCallback(valueChangedCB callback, void *userData) override;
+ void unSetChangedCallback(valueChangedCB callback, void *userData) override;
+
+ static const std::string NAME;
+
+private:
+ static void autoBrightnessChangedCB(keynode_t *node, void *userData);
+
+ static const char* const key;
+ int oldVal;
+ int autoBrightness;
+ valueChangedCB cb;
+ void *cbData;
+};
+
+MODES_NAMESPACE_END
#include <device/power.h>
#include "plugin-log.h"
#include "DisplayBrightness.h"
+#include "DisplayAutoBrightness.h"
#include "DisplayTimeout.h"
#include "DisplayAllowPalmTouch.h"
DisplayFactory::DisplayFactory()
{
actionMap[DisplayBrightness::NAME] = BRIGHTNESS;
+ actionMap[DisplayAutoBrightness::NAME] = AUTO_BRIGHTNESS;
actionMap[DisplayTimeout::NAME] = TIMEOUT;
actionMap[DisplayAllowPalmTouch::NAME] = ALLOW_PALM_TOUCH;
}
case BRIGHTNESS:
action = new DisplayBrightness();
break;
+ case AUTO_BRIGHTNESS:
+ action = new DisplayAutoBrightness();
+ break;
case TIMEOUT:
action = new DisplayTimeout();
break;
private:
enum actionKey{
BRIGHTNESS,
+ AUTO_BRIGHTNESS,
TIMEOUT,
ALLOW_PALM_TOUCH,
};
MODES_NAMESPACE_USE;
-const std::string DisplayTimeout::NAME = "Timeout";
+const std::string DisplayTimeout::NAME = "timeout";
DisplayTimeout::DisplayTimeout()
:DisplayAction(NAME), key(VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL), oldDisplayTimeout(-1)
{
<desc>Display brightness</desc>
<domain>System</domain>
</rule>
- <rule name="display.Timeout" type="int" since="6.0" plugin="display">
+ <rule name="display.autoBrightness" type="int" since="6.0" plugin="display">
+ <alias name="off">0</alias>
+ <alias name="on">1</alias>
+ <alias name="pause">2</alias>
+ <desc>Display auto brightness</desc>
+ <domain>System</domain>
+ </rule>
+ <rule name="display.timeout" type="int" since="6.0" plugin="display">
<alias name="ALWAYS_ON">0</alias>
<desc>Display Timeout</desc>
<domain>System</domain>
static gboolean displayPluginAlwaysOnIdler(gpointer data)
{
PluginAction *action;
- result = plugin->set("Timeout", 0, &action);
+ result = plugin->set("timeout", 0, &action);
EXPECT_EQ(MODES_ERROR_NONE, result);
plugin->undo(action);
return G_SOURCE_REMOVE;
}
+
+ static gboolean displayPluginAutoBrightnessIdler(gpointer data)
+ {
+ PluginAction *action;
+ result = plugin->set("autoBrightness", 1, &action);
+ EXPECT_EQ(MODES_ERROR_NONE, result);
+
+ plugin->undo(action);
+
+ result = plugin->set("autoBrightness", 2, &action);
+ EXPECT_EQ(MODES_ERROR_NONE, result);
+
+ g_main_loop_quit(loop);
+
+ return G_SOURCE_REMOVE;
+ }
static int result;
static GMainLoop *loop;
static Plugin *plugin;
g_main_loop_run(loop);
}
+TEST_F(displayPluginTest, setAutoBrightness)
+{
+ g_idle_add(displayPluginAutoBrightnessIdler, plugin);
+ g_main_loop_run(loop);
+}
+
TEST_F(displayPluginTest, setAlwaysOn)
{
g_idle_add(displayPluginAlwaysOnIdler, plugin);
<?xml version="1.0" encoding="utf-8"?>
<tizenModes xmlns="http://www.tizen.org" version="6.0">
<mode name="displayBlock" type="exclusive">
- <action rule="display.Timeout">ALWAYS_ON</action>
+ <action rule="display.timeout">ALWAYS_ON</action>
<action rule="display.allowPalmTouch">off</action>
</mode>
</tizenModes>