Add new API to set low power mode accepted/tizen_5.5_unified_mobile_hotfix tizen_5.5_mobile_hotfix accepted/tizen/5.5/unified/20191031.031318 accepted/tizen/5.5/unified/mobile/hotfix/20201027.065752 accepted/tizen/unified/20191018.052938 submit/tizen/20191018.005538 submit/tizen_5.5/20191031.000002 submit/tizen_5.5_mobile_hotfix/20201026.185102 tizen_5.5.m2_release
authorsaerome.kim <saerome.kim@samsung.com>
Thu, 17 Oct 2019 09:26:52 +0000 (18:26 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 17 Oct 2019 10:18:35 +0000 (19:18 +0900)
- Problem: it is needed that new API that can set low power mode
- Cause: without adding new API, build break occurs.
- Solution: add new API to set low power mode.

Change-Id: I2e9269003238973f29424a017c0b9f56c18b4b6d
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
include/user-awareness-internal.h
include/user-awareness.h
src/user-awareness-monitors.c
test/uat-detections.c

index 3af7f572cdd2ec443d6a1dcb3f18a87af32a9018..951037909b969e474f912920d4137837f1a7b7f7 100644 (file)
@@ -58,7 +58,7 @@ int ua_monitor_set_brightness_threshold(ua_monitor_h handle,
  * @return 0 on success, otherwise a negative error value
  * @retval #UA_ERROR_NONE Successful
  */
-int ua_enable_low_power_mode(unsigned int sensors);
+int ua_enable_low_power_mode(void);
 
 /**
  * @internal
@@ -69,7 +69,21 @@ int ua_enable_low_power_mode(unsigned int sensors);
  * @return 0 on success, otherwise a negative error value
  * @retval #UA_ERROR_NONE Successful
  */
-int ua_disable_low_power_mode(unsigned int sensors);
+int ua_disable_low_power_mode(void);
+
+/**
+ * @internal
+ * @ingroup CAPI_NETWORK_UA_MODULE
+ * @brief Sets low power mode for each sensor.
+ * @since_tizen 5.5
+ *
+ * @param[in] bitmask The sensor bitmask
+ * @param[in] on_off Low power mode enable or not
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #UA_ERROR_NONE Successful
+ */
+int ua_set_low_power_mode(unsigned int bitmask, bool on_off);
 
 /**
  * @internal
index a71dd6e3694608fa75ae0e47f3c11d5bdade187a..8ee579aa6105f5ab7af5a2c5d8c8c0fe5d5ba22a 100644 (file)
@@ -166,13 +166,14 @@ typedef enum {
  * @since_tizen 5.5
  */
 typedef enum {
-       UA_SENSOR_BT = 0x0001, /**< BT Sensor */
-       UA_SENSOR_BLE = 0x0002, /**< BLE Sensor */
-       UA_SENSOR_WIFI = 0x0004, /**< Wi-Fi Sensor */
-       UA_SENSOR_MOTION = 0x0008, /**< Motion Sensor */
-       UA_SENSOR_LIGHT = 0x0010, /**< Light Sensor */
-       UA_SENSOR_AUDIO = 0x0020, /**< Audio Sensor */
-       UA_SENSOR_MAX /**< Sensor Max. */
+       UA_SENSOR_BT = 0x00000001, /**< BT Sensor */
+       UA_SENSOR_BLE = 0x00000002, /**< BLE Sensor */
+       UA_SENSOR_WIFI = 0x00000004, /**< Wi-Fi Sensor */
+       UA_SENSOR_MOTION = 0x00000008, /**< Motion Sensor */
+       UA_SENSOR_LIGHT = 0x00000010, /**< Light Sensor */
+       UA_SENSOR_AUDIO = 0x00000020, /**< Audio Sensor */
+       UA_SENSOR_MAX, /**< Sensor Max. */
+       UA_SENSOR_ALL = 0xFFFFFFFF /**< All sensors */
 } ua_sensor_e;
 
 /**
index f707cdb198df52ae4335de9691e2cd7bd9648347..debbc0b2908d0fd07deaa718f9876d316755f15a 100644 (file)
@@ -21,6 +21,7 @@
 #include <user-awareness.h>
 #include <user-awareness-log.h>
 #include <user-awareness-private.h>
+#include <user-awareness-internal.h>
 #include <user-awareness-util.h>
 
 #define UA_MONITORING_TIME 60 /* Default: 60 seconds for scanning for device */
@@ -128,6 +129,9 @@ static unsigned int __ua_sensor_type_to_bitmask(ua_sensor_e sensor_type)
        case UA_SENSOR_AUDIO:
                bitmask = UAM_SENSOR_BITMASK_AUDIO;
                break;
+       case UA_SENSOR_ALL:
+               bitmask = UAM_SENSOR_ALL;
+               break;
        default:
                UA_WARN("Unsupported sensor [%d]", sensor_type);
                bitmask = 0x00;
@@ -1761,31 +1765,51 @@ int ua_monitor_set_brightness_threshold(ua_monitor_h handle,
        return UA_ERROR_NONE;
 }
 
-int ua_enable_low_power_mode(unsigned int sensors)
+int ua_enable_low_power_mode(void)
 {
        FUNC_ENTRY;
        int ret;
 
-       ret = _ua_get_error_code(_uam_enable_low_power_mode(sensors));
+       ret = _ua_get_error_code(_uam_set_low_power_mode(UA_SENSOR_ALL, true));
        if (UA_ERROR_NONE != ret) {
-               UA_ERR("_uam_enable_low_power_mode failed");
+               /* LCOV_EXCL_START */
+               UA_ERR("_uam_set_low_power_mode failed");
                return ret;
+               /* LCOV_EXCL_STOP */
        }
 
        FUNC_EXIT;
        return UA_ERROR_NONE;
 }
 
+int ua_disable_low_power_mode(void)
+{
+       FUNC_ENTRY;
+       int ret;
+
+       ret = _ua_get_error_code(_uam_set_low_power_mode(UA_SENSOR_ALL, false));
+       if (UA_ERROR_NONE != ret) {
+               /* LCOV_EXCL_START */
+               UA_ERR("_uam_set_low_power_mode failed");
+               return ret;
+               /* LCOV_EXCL_STOP */
+       }
+
+       FUNC_EXIT;
+       return UA_ERROR_NONE;
+}
 
-int ua_disable_low_power_mode(unsigned int sensors)
+int ua_set_low_power_mode(unsigned int bitmask, bool on_off)
 {
        FUNC_ENTRY;
        int ret;
 
-       ret = _ua_get_error_code(_uam_disable_low_power_mode(sensors));
+       ret = _ua_get_error_code(_uam_set_low_power_mode(bitmask, on_off));
        if (UA_ERROR_NONE != ret) {
-               UA_ERR("_uam_disable_low_power_mode failed");
+               /* LCOV_EXCL_START */
+               UA_ERR("_uam_set_low_power_mode failed");
                return ret;
+               /* LCOV_EXCL_STOP */
        }
 
        FUNC_EXIT;
index 4ee49b8c59165e0b5554689dc4a763f94b6c1190..ce0476c3186579016e9c4517105cc4c0745e6c83 100644 (file)
@@ -43,13 +43,14 @@ static char g_presence_conjunction_op[MENU_DATA_SIZE + 1] = {"1",}; /**< logical
 static char g_absence_and_cond[MENU_DATA_SIZE + 1] = {"6",}; /**< ABSENCE AND condition */
 static char g_absence_or_cond[MENU_DATA_SIZE + 1] = {"16",}; /**< ABSENCE OR condition */
 static char g_absence_conjunction_op[MENU_DATA_SIZE + 1] = {"0",}; /**< logical conjunction operation */
-static char g_lpm_enable_sensors[MENU_DATA_SIZE + 1] = {"30",}; /**< Low Power Mode enable sensors */
-static char g_lpm_disable_sensors[MENU_DATA_SIZE + 1] = {"30",}; /**< Low Power Mode disable sensors */
 
 static char g_presence_type[MENU_DATA_SIZE + 1] = "2"; /**< Selected PRESENCE type */
 static char g_absence_type[MENU_DATA_SIZE + 1] = "2"; /**< Selected ABSENCE type */
 static char g_scan_time_multiplier[MENU_DATA_SIZE + 1] = {0,}; /**< 10ms * what number */
 
+static char g_lpm_sensor[MENU_DATA_SIZE + 1] = "2"; /**<  Sensor to set LPM */
+static char g_lpm_onoff[MENU_DATA_SIZE + 1] = "1"; /**<  LPM mode on/off */
+
 static void __sensor_presence_detected_device(ua_device_h device_handle)
 {
        int ret;
@@ -577,13 +578,10 @@ static int run_ua_enable_low_power_mode(
                MManager *mm, struct menu_data *menu)
 {
        int ret = UA_ERROR_NONE;
-       unsigned int lpm_enable_sensors = 0;
 
-       if (strlen(g_lpm_enable_sensors))
-               lpm_enable_sensors = (unsigned int)strtol(g_lpm_enable_sensors, NULL, 10);
        msg("ua_enable_low_power_mode");
 
-       ret = ua_enable_low_power_mode(lpm_enable_sensors);
+       ret = ua_enable_low_power_mode();
 
        msg(" - ua_enable_low_power_mode() ret: [0x%X] [%s]",
                        ret, uat_get_error_str(ret));
@@ -595,20 +593,40 @@ static int run_ua_disable_low_power_mode(
                MManager *mm, struct menu_data *menu)
 {
        int ret = UA_ERROR_NONE;
-       unsigned int lpm_disable_sensors = 0;
-
-       if (strlen(g_lpm_disable_sensors))
-               lpm_disable_sensors = (unsigned int)strtol(g_lpm_disable_sensors, NULL, 10);
 
        msg("ua_disable_low_power_mode");
 
-       ret = ua_disable_low_power_mode(lpm_disable_sensors);
+       ret = ua_disable_low_power_mode();
 
        msg(" - ua_disable_low_power_mode() ret: [0x%X] [%s]",
                        ret, uat_get_error_str(ret));
 
        return RET_SUCCESS;
 }
+
+static int run_ua_set_low_power_mode(
+               MManager *mm, struct menu_data *menu)
+{
+       int ret = UA_ERROR_NONE;
+       ua_sensor_e sensor = UA_SENSOR_ALL;
+       int onoff = 0;
+
+       if (strlen(g_lpm_sensor))
+               sensor = (unsigned char)strtol((g_lpm_sensor), NULL, 10);
+
+       if (strlen(g_lpm_onoff))
+               onoff = (unsigned char)strtol((g_lpm_onoff), NULL, 10);
+
+       msg("run_ua_set_low_power_mode bitmask [%x]", sensor);
+
+       ret =ua_set_low_power_mode(sensor, onoff == 1 ? true : false);
+
+       msg(" - run_ua_set_low_power_mode() ret: [0x%X] [%s]",
+                       ret, uat_get_error_str(ret));
+
+       return RET_SUCCESS;
+}
+
 #ifdef SUSPEND_RESUME_TEST
 static int run_device_power_request_poweroff(
                MManager *mm, struct menu_data *menu)
@@ -669,22 +687,6 @@ static struct menu_data menu_ua_set_detection_window[] = {
        { NULL, NULL, },
 };
 
-static struct menu_data menu_ua_enable_low_power_mode[] = {
-       { "1", "Bitmask (1:BT 2:BLE 4:Wi-Fi 8:Motion 16:Light 32:Audio)",
-               NULL, NULL, g_lpm_enable_sensors },
-       { "2", "run", NULL,
-               run_ua_enable_low_power_mode, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_ua_disable_low_power_mode[] = {
-       { "1", "Bitmask (1:BT 2:BLE 4:Wi-Fi 8:Motion 16:Light 32:Audio)",
-               NULL, NULL, g_lpm_disable_sensors },
-       { "2", "run", NULL,
-               run_ua_disable_low_power_mode, NULL },
-       { NULL, NULL, },
-};
-
 static struct menu_data menu_ua_set_presence_condition[] = {
        { "1", "AND Bitmask (1:BT 2:BLE 4:Wi-Fi 8:Motion 16:Light 32:Audio)",
                NULL, NULL, g_presence_and_cond },
@@ -763,6 +765,16 @@ static struct menu_data menu_start_absence_presence[] = {
        { NULL, NULL, },
 };
 
+static struct menu_data menu_set_low_power_mode[] = {
+       { "1", "(1 BT 2:BLE 4:Wi-Fi 8:Motion 16:Light 32:Audio)",
+               NULL, NULL, g_lpm_sensor },
+       { "2", "(0:OFF 1:ON)",
+               NULL, NULL, g_lpm_onoff },
+       { "3", "ua_set_low_power_mode",
+               NULL, run_ua_set_low_power_mode, NULL },
+       { NULL, NULL, },
+};
+
 struct menu_data menu_ua_detections[] = {
        { "1", "ua_set_detection_cycle",
                menu_ua_set_detection_cycle, NULL, NULL},
@@ -791,11 +803,13 @@ struct menu_data menu_ua_detections[] = {
                NULL, run_ua_monitor_cancel_scan_devices, NULL },
 
        { "12", "ua_enable_low_power_mode",
-               menu_ua_enable_low_power_mode, NULL, NULL },
+               NULL, run_ua_enable_low_power_mode, NULL },
        { "13", "ua_disable_low_power_mode",
-               menu_ua_disable_low_power_mode, NULL, NULL },
+               NULL, run_ua_disable_low_power_mode, NULL },
+       { "14", "ua_set_low_power_mode",
+               menu_set_low_power_mode, NULL, NULL },
 #ifdef SUSPEND_RESUME_TEST
-       { "14", "request_power_off",
+       { "15", "request_power_off",
                NULL, run_device_power_request_poweroff, NULL },
 #endif
        { NULL, NULL, },