Remove trivial unnecessary build dependency
[apps/core/preloaded/lockscreen.git] / src / camera.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "camera.h"
18 #include "log.h"
19
20 #include <app_control.h>
21 #include <Ecore.h>
22 #define KEY_DISPLAY_OVER_LOCKSCREEN "http://tizen.org/lock/window/above"
23
24 static bool camera_enabled;
25 static int init_count;
26
27 int LOCKSCREEN_EVENT_CAMERA_STATUS_CHANGED;
28
29 static void _app_control_reply_cb(app_control_h request, app_control_h reply, app_control_result_e result, void *user_data)
30 {
31         switch (result) {
32                 case APP_CONTROL_RESULT_APP_STARTED:
33                 case APP_CONTROL_RESULT_SUCCEEDED:
34                         DBG("Camera application launch succcessed.");
35                         break;
36                 case APP_CONTROL_RESULT_FAILED:
37                 case APP_CONTROL_RESULT_CANCELED:
38                         DBG("Camera application launch failed.");
39                         break;
40         }
41 }
42
43 int lockscreen_camera_activate()
44 {
45         app_control_h app_ctr;
46
47         int err = app_control_create(&app_ctr);
48         if (err != APP_CONTROL_ERROR_NONE) {
49                 ERR("app_control_create failed: %s", get_error_message(err));
50                 return 1;
51         }
52
53         err = app_control_set_launch_mode(app_ctr, APP_CONTROL_LAUNCH_MODE_GROUP);
54         if (err != APP_CONTROL_ERROR_NONE) {
55                 ERR("app_control_set_launch_mode failed: %s", get_error_message(err));
56                 app_control_destroy(app_ctr);
57                 return 1;
58         }
59
60         /* Send a hint to camera-app to display itself over lockscreen */
61         err = app_control_add_extra_data(app_ctr, KEY_DISPLAY_OVER_LOCKSCREEN, "on");
62         if (err != APP_CONTROL_ERROR_NONE) {
63                 ERR("app_control_add_extra_data failed: %s", get_error_message(err));
64                 app_control_destroy(app_ctr);
65                 return 1;
66         }
67
68         /* Send a hint to camera-app to display itself in secure mode*/
69         err = app_control_add_extra_data(app_ctr, "secure_mode", "true");
70         if (err != APP_CONTROL_ERROR_NONE) {
71                 ERR("app_control_add_extra_data failed: %s", get_error_message(err));
72                 app_control_destroy(app_ctr);
73                 return 1;
74         }
75
76         err = app_control_set_app_id(app_ctr, "org.tizen.camera-app");
77         if (err != APP_CONTROL_ERROR_NONE) {
78                 ERR("app_control_set_app_id failed: %s", get_error_message(err));
79                 app_control_destroy(app_ctr);
80                 return 1;
81         }
82
83         err = app_control_send_launch_request(app_ctr, _app_control_reply_cb, NULL);
84         if (err != APP_CONTROL_ERROR_NONE) {
85                 ERR("app_control_send_launch_request failed: %s", get_error_message(err));
86                 app_control_destroy(app_ctr);
87                 return 1;
88         }
89
90         DBG("Launch request send for %s", APP_CONTROL_OPERATION_CREATE_CONTENT);
91         app_control_destroy(app_ctr);
92
93         return 0;
94 }
95
96 int lockscreen_camera_init(void)
97 {
98         if (!init_count) {
99                 //FIXME load this from settings
100                 camera_enabled = true;
101                 LOCKSCREEN_EVENT_CAMERA_STATUS_CHANGED = ecore_event_type_new();
102         }
103
104         init_count++;
105         return 0;
106 }
107
108 void lockscreen_camera_shutdown(void)
109 {
110         if (init_count) {
111                 init_count--;
112         }
113 }
114
115 bool lockscreen_camera_is_on(void)
116 {
117         return camera_enabled;
118 }