/* * Copyright (c) 2018 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 #include #include #include #include #include #include #include "uat-menu.h" #include "uat-common.h" extern ua_monitor_h ua_mon; extern char sensor_list_str[MENU_DATA_SIZE + 1]; extern unsigned short sensor_list; static char app_id[MENU_DATA_SIZE + 1] = {0,}; static char uid[MENU_DATA_SIZE + 1] = {0,}; static void __absence_detected_all_cb(int result, ua_monitor_h monitor, ua_sensor_e sensor, ua_user_h user_handle, void *user_data) { int ret = UA_ERROR_NONE; char *account = NULL; msgp("result : %s", uat_get_error_str(result)); msgp("sensor %s ABSENCE detected", uat_get_sensor_bitmask_str(sensor)); if (user_handle) { ret = ua_user_get_account(user_handle, &account); if (UA_ERROR_NONE == ret) { msgp("User account info %s", account); free(account); } } } static void __presence_detected_all_cb(int result, ua_monitor_h monitor, ua_sensor_e sensor, ua_user_h user_handle, void *user_data) { int ret = UA_ERROR_NONE; char *account = NULL; msgp("result : %s", uat_get_error_str(result)); msgp("sensor %s PRESENCE detected", uat_get_sensor_bitmask_str(sensor)); if (user_handle) { ret = ua_user_get_account(user_handle, &account); if (UA_ERROR_NONE == ret) { msgp("User account info %s", account); free(account); } } } static void __sensor_state_changed_cb(bool ready, ua_sensor_e sensor, ua_monitor_h monitor, void *user_data) { msgb("sensor: %s is %s", uat_get_sensor_bitmask_str(sensor), (ready ? "Ready" : "Not Ready")); } static int run_ua_monitor_create(MManager *mm, struct menu_data *menu) { const char *buf = NULL; int ret = UA_ERROR_NONE; bool is_available = false; msg("ua_monitor_create"); if (ua_mon) ua_monitor_destroy(ua_mon); ret = ua_monitor_create(&ua_mon); msg(" - ua_monitor_create() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); if (UA_ERROR_NONE != ret) return RET_SUCCESS; memset(sensor_list_str, 0, MENU_DATA_SIZE + 1); for (int i = UA_SENSOR_BT ; i < UA_SENSOR_MAX; i <<= 1) { ret = ua_monitor_is_sensor_available(i, &is_available); if (UA_ERROR_NONE == ret && is_available) { /* If sensor plugins are loaded, enable them */ ua_monitor_add_sensor(ua_mon, i); /* Save loaded sensor */ sensor_list |= i; buf = uat_get_sensor_bitmask_str(i); strncat(sensor_list_str, buf, strnlen(buf, MENU_DATA_SIZE)); strncat(sensor_list_str, " ", 2); } is_available = false; } return RET_SUCCESS; } static int run_ua_monitor_destroy(MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; msg("ua_monitor_destroy"); if (ua_mon) ret = ua_monitor_destroy(ua_mon); msg(" - ua_monitor_destroy() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); return RET_SUCCESS; } static int run_ua_monitor_set_user_absence_detected_cb( MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; msg("ua_monitor_set_absence_detected_cb"); ret = ua_monitor_set_user_absence_detected_cb(ua_mon, __absence_detected_all_cb, ua_mon); msg(" - ua_monitor_set_absence_detected_cb() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); return RET_SUCCESS; } static int run_ua_monitor_set_user_presence_detected_cb( MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; msg("ua_monitor_set_presence_detected_cb"); ret = ua_monitor_set_user_presence_detected_cb(ua_mon, __presence_detected_all_cb, ua_mon); msg(" - ua_monitor_set_presence_detected_cb() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); return RET_SUCCESS; } static int run_ua_monitor_set_sensor_state_cb( MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; msg("ua_monitor_set_sensor_state_cb"); ret = ua_monitor_set_sensor_state_cb(ua_mon, __sensor_state_changed_cb, ua_mon); msg(" - ua_monitor_set_sensor_state_cb() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); return RET_SUCCESS; } static int run_ua_monitor_unset_user_absence_detected_cb( MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; msg("ua_monitor_unset_absence_detected_cb"); ret = ua_monitor_unset_user_absence_detected_cb(ua_mon); msg(" - ua_monitor_unset_absence_detected_cb() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); return RET_SUCCESS; } static int run_ua_monitor_unset_user_presence_detected_cb( MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; msg("ua_monitor_unset_presence_detected_cb"); ret = ua_monitor_unset_user_presence_detected_cb(ua_mon); msg(" - ua_monitor_unset_presence_detected_cb() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); return RET_SUCCESS; } static int run_ua_monitor_unset_sensor_state_cb( MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; msg("ua_monitor_unset_sensor_state_cb"); ret = ua_monitor_unset_sensor_state_cb(ua_mon); msg(" - ua_monitor_unset_sensor_state_cb() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); return RET_SUCCESS; } static int run_ua_enable_low_power_mode( MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; msg("ua_enable_low_power_mode"); ret = ua_enable_low_power_mode(); msg(" - ua_enable_low_power_mode() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); return RET_SUCCESS; } static int run_ua_disable_low_power_mode( MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; msg("ua_disable_low_power_mode"); ret = ua_enable_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_register_app_resume(MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; unsigned short uid_value = 0; msg("ua_register_app_resume"); if (strlen(uid)) uid_value = (unsigned short)strtol(uid, NULL, 10); ret = ua_register_app_resume(app_id, uid_value); msg(" - ua_register_app_resume() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); return RET_SUCCESS; } static int run_ua_unregister_app_resume(MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; unsigned short uid_value = 0; msg("ua_unregister_app_resume"); if (strlen(uid)) uid_value = (unsigned short)strtol(uid, NULL, 10); ret = ua_unregister_app_resume(app_id, uid_value); msg(" - ua_unregister_app_resume() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); return RET_SUCCESS; } static struct menu_data menu_ua_register_app_resume[] = { { "1", "app_id (e.g. 'org.tizen.factory')", NULL, NULL, app_id }, { "2", "uid (Uid found using 'ps -eo uid,gid,args | grep TheApp')", NULL, NULL, uid }, { "3", "run", NULL, run_ua_register_app_resume, NULL }, { NULL, NULL, }, }; static struct menu_data menu_ua_unregister_app_resume[] = { { "1", "app_id (e.g. 'org.tizen.factory')", NULL, NULL, app_id }, { "2", "uid (Uid found using 'ps -eo uid,gid,args | grep TheApp')", NULL, NULL, uid }, { "3", "run", NULL, run_ua_unregister_app_resume, NULL }, { NULL, NULL, }, }; struct menu_data menu_ua_init[] = { { "1", "ua_monitor_create", NULL, run_ua_monitor_create, NULL }, { "2", "ua_monitor_destroy", NULL, run_ua_monitor_destroy, NULL }, { "3", "ua_monitor_set_user_sensor_state_cb", NULL, run_ua_monitor_set_sensor_state_cb, NULL }, { "4", "ua_monitor_unset_user_sensor_state_cb", NULL, run_ua_monitor_unset_sensor_state_cb, NULL }, { "5", "ua_monitor_set_user_absence_detected_cb", NULL, run_ua_monitor_set_user_absence_detected_cb, NULL }, { "6", "ua_monitor_unset_absence_detected_cb", NULL, run_ua_monitor_unset_user_absence_detected_cb, NULL }, { "7", "ua_monitor_set_user_presence_detected_cb", NULL, run_ua_monitor_set_user_presence_detected_cb, NULL }, { "8", "ua_monitor_unset_presence_detected_cb", NULL, run_ua_monitor_unset_user_presence_detected_cb, NULL }, { "9", "ua_enable_low_power_mode", NULL, run_ua_enable_low_power_mode, NULL }, { "10", "ua_disable_low_power_mode", NULL, run_ua_disable_low_power_mode, NULL }, { "11", "ua_register_app_resume", menu_ua_register_app_resume, NULL, NULL}, { "12", "ua_unregister_app_resume", menu_ua_unregister_app_resume, NULL, NULL}, { NULL, NULL, }, };