summaryrefslogtreecommitdiff
path: root/test/uat-init.c
blob: 0b112f45f2cf113f14d4092bf652489bbe606b92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*
 * 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 <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <glib.h>
#include <gio/gio.h>

#include <user-awareness.h>
#include <user-awareness-internal.h>

#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_user_h user_handle, void *user_data)
{
	int ret = UA_ERROR_NONE;
	char *account = NULL;

	msgp("result : %s", uat_get_error_str(result));

	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_user_h user_handle, void *user_data)
{
	int ret = UA_ERROR_NONE;
	char *account = NULL;

	msgp("result : %s", uat_get_error_str(result));

	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, },
};