shouldNotThrow("tizen.power.request('SCREEN', 'SCREEN_BRIGHT')");
shouldThrow("tizen.power.release(1)", "new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR)");
shouldThrow("tizen.power.release('MOUSE')", "new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR)");
-// FIXME : For now deactivate the test of turning off the screen as it will lead to the lock screen but afer unlocking Xwalk is
-// not in foreground so you can't check the results. When #313 is fixed we can turn it on.
-//shouldNotThrow("tizen.power.release('CPU')");
+shouldNotThrow("tizen.power.release('CPU')");
shouldNotThrow("tizen.power.release('SCREEN')");
var screenBrightness = tizen.power.getScreenBrightness();
shouldThrow("tizen.power.setScreenBrightness('1')", "new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR)");
shouldThrow("tizen.power.setScreenBrightness(2)", "new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR)");
tizen.power.setScreenBrightness(0.5);
-// FIXME : Getter needs sync and uses vconf which can't be called from the extensions thread. When the extensions are
-// in their own process we can enable the test and fix the getter to work.
-//shouldBe("tizen.power.getScreenBrightness()", "0.5");
tizen.power.restoreScreenBrightness();
shouldBeTrue("tizen.power.getScreenBrightness() == screenBrightness");
tizen.power.unsetScreenStateChangeListener(ScreenStateChangeListener);
tizen.power.restoreScreenBrightness();
shouldBeTrue("tizen.power.isScreenOn()");
- // FIXME : For now deactivate the test of turning off the screen as it will lead to the lock screen but afer unlocking Xwalk is
- // not in foreground so you can't check the results. When #313 is fixed we can turn it on.
- //shouldNotThrow("tizen.power.turnScreenOff()");
- //setTimeout(waitForScreenOff, 100);
+ shouldNotThrow("tizen.power.turnScreenOff()");
+ setTimeout(waitForScreenOff, 100);
}
function waitForScreenOff() {
// FIXME: Check return value and throw exception if needed.
}
-// FIXME : This callback can be removed when extensions are moved to
-// their own process. For now it is needed for vconf to function correctly.
-// This callback actually make sure that the code is run in the main thread.
-static gboolean set_brightness_callback(gpointer data) {
- double* brightness = static_cast<double*>(data);
- if (*brightness < 0) {
+void PowerContext::HandleSetScreenBrightness(const picojson::value& msg) {
+ double brightness = msg.get("value").get<double>();
+ if (brightness < 0)
// Resource brightness.
device_set_brightness_from_settings(0);
- delete brightness;
- return false;
- }
int maxBrightness;
power_wakeup(false);
int ret = device_get_max_brightness(0, &maxBrightness);
if (ret != 0) {
fprintf(stderr, "Can't get the max brightness from the platform. \n");
- device_set_brightness(0, static_cast<int>(*brightness * 100.0));
+ device_set_brightness(0, static_cast<int>(brightness * 100.0));
} else {
- device_set_brightness(0, static_cast<int>(*brightness * maxBrightness));
+ device_set_brightness(0, static_cast<int>(brightness * maxBrightness));
}
- delete brightness;
- return false;
-}
-
-void PowerContext::HandleSetScreenBrightness(const picojson::value& msg) {
- double* requested_brightness = new double[1];
- *requested_brightness = msg.get("value").get<double>();
- g_timeout_add(0, set_brightness_callback,
- static_cast<gpointer>(requested_brightness));
}
void PowerContext::HandleGetScreenState() {
}
void PowerContext::HandleGetScreenBrightness() {
- // FIXME : This need to be called from the main thread, when extensions are
- // moved to their own process the code should work.
int platformBrightness;
- vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &platformBrightness);
+ int ret = device_get_brightness(0, &platformBrightness);
+ if (ret != 0)
+ fprintf(stderr, "Can't get the brightness from the platform. \n");
+
double brightness = platformBrightness / 100.0;
char brightnessAsString[32];
snprintf(brightnessAsString, sizeof(brightnessAsString), "%g", brightness);