change usb control process name to usb-server
[framework/system/system-server.git] / sys_device_noti / sys_device_noti.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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
18 #include <stdio.h>
19 #include <svi.h>
20 #include <pmapi.h>
21 #include <notification.h>
22 #include "ss_log.h"
23 #include "sys_device_noti.h"
24
25 #define BATTERY_FULL_ICON_PATH                  "/usr/share/system-server/sys_device_noti/batt_full_icon.png"
26 static int battery_full_noti(int bNoti)
27 {
28         int charge_full = bNoti;
29         notification_h noti = NULL;
30         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
31
32         if (charge_full == 1) {
33                 noti_err = notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NOTI);
34                 PRT_TRACE("[BAT_FULL_NOTI] add notification for battery full\n");
35                 noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
36                 if (noti == NULL) {
37                         PRT_TRACE("[BAT_FULL_NOTI] Errot noti == NULL\n");
38                         return -1;
39                 }
40
41                 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Battery fully charged", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
42                 if (noti_err != NOTIFICATION_ERROR_NONE) {
43                         PRT_TRACE("[BAT_FULL_NOTI] Error notification_set_title : %d\n", noti_err);
44                         noti_err = notification_free(noti);
45                         if (noti_err != NOTIFICATION_ERROR_NONE) {
46                                 PRT_TRACE("[BAT_FULL_NOTI] Error notification_free : %d\n", noti_err);
47                                 return -1;
48                         }
49                         return -1;
50                 }
51
52                 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "Unplug charger", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
53                 if (noti_err != NOTIFICATION_ERROR_NONE) {
54                         PRT_TRACE("[BAT_FULL_NOTI] Error notification_set_content : %d\n", noti_err);
55                         noti_err = notification_free(noti);
56                         if (noti_err != NOTIFICATION_ERROR_NONE) {
57                                 PRT_TRACE("[BAT_FULL_NOTI] Error notification_free : %d\n", noti_err);
58                                 return -1;
59                         }
60                         return -1;
61                 }
62
63                 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Unplug charger", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
64                 if (noti_err != NOTIFICATION_ERROR_NONE) {
65                         PRT_TRACE("[BAT_FULL_NOTI] Error notification_set_content : %d\n", noti_err);
66                         noti_err = notification_free(noti);
67                         if (noti_err != NOTIFICATION_ERROR_NONE) {
68                                 PRT_TRACE("[BAT_FULL_NOTI] Error notification_free : %d\n", noti_err);
69                                 return -1;
70                         }
71                         return -1;
72                 }
73
74                 noti_err = notification_set_time(noti, time(NULL));
75                 if (noti_err != NOTIFICATION_ERROR_NONE) {
76                         PRT_TRACE("[BAT_FULL_NOTI] Error notification_set_time : %d\n", noti_err);
77                         noti_err = notification_free(noti);
78                         if (noti_err != NOTIFICATION_ERROR_NONE) {
79                                 PRT_TRACE("[BAT_FULL_NOTI] Error notification_free : %d\n", noti_err);
80                                 return -1;
81                         }
82                         return -1;
83                 }
84
85                 noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, BATTERY_FULL_ICON_PATH);
86                 if (noti_err != NOTIFICATION_ERROR_NONE) {
87                         PRT_TRACE("[BAT_FULL_NOTI] Error notification_set_image : %d\n", noti_err);
88                         noti_err = notification_free(noti);
89                         if (noti_err != NOTIFICATION_ERROR_NONE) {
90                                 PRT_TRACE("[BAT_FULL_NOTI] Error notification_free : %d\n", noti_err);
91                                 return -1;
92                         }
93                         return -1;
94                 }
95
96                 noti_err = notification_set_property(noti, NOTIFICATION_PROP_DISABLE_APP_LAUNCH | NOTIFICATION_PROP_DISABLE_TICKERNOTI | NOTIFICATION_PROP_VOLATILE_DISPLAY);
97                 if (noti_err != NOTIFICATION_ERROR_NONE) {
98                         PRT_TRACE("[BAT_FULL_NOTI] Error notification_set_property : %d\n", noti_err);
99                         noti_err = notification_free(noti);
100                         if (noti_err != NOTIFICATION_ERROR_NONE) {
101                                 PRT_TRACE("[BAT_FULL_NOTI] Error notification_free : %d\n", noti_err);
102                                 return -1;
103                         }
104                         return -1;
105                 }
106
107                 noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
108                 if (noti_err != NOTIFICATION_ERROR_NONE) {
109                         PRT_TRACE("[BAT_FULL_NOTI] Error notification_set_display_applist : %d\n", noti_err);
110                         noti_err = notification_free(noti);
111                         if (noti_err != NOTIFICATION_ERROR_NONE) {
112                                 PRT_TRACE("[BAT_FULL_NOTI] Error notification_free : %d\n", noti_err);
113                                 return -1;
114                         }
115                         return -1;
116                 }
117
118                 noti_err = notification_insert(noti, NULL);
119                 if (noti_err != NOTIFICATION_ERROR_NONE) {
120                         PRT_TRACE("[BAT_FULL_NOTI] Error notification_insert : %d\n", noti_err);
121                         noti_err = notification_free(noti);
122                         if (noti_err != NOTIFICATION_ERROR_NONE) {
123                                 PRT_TRACE("[BAT_FULL_NOTI] Error notification_free : %d\n", noti_err);
124                                 return -1;
125                         }
126                         return -1;
127                 }
128
129                 noti_err = notification_free(noti);
130                 if (noti_err != NOTIFICATION_ERROR_NONE) {
131                         PRT_TRACE("[BAT_FULL_NOTI] Error notification_free : %d\n", noti_err);
132                         return -1;
133                 }
134                 pm_change_state(LCD_NORMAL);
135         } else {
136                 noti_err = notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NOTI);
137                 PRT_TRACE("[BAT_FULL_NOTI] Leave battery full status\n");
138         }
139
140         return 0;
141 }
142 int main(int argc, char *argv[])
143 {
144         int r = 0;
145         int handle = 0;
146         int bNoti = -1;
147         sound_type snd = -1;
148         vibration_type vib = -1;
149         cb_noti_type cb_type = -1;
150
151         if (argc == 3)
152                 bNoti = atoi(argv[2]);
153         cb_type = (cb_noti_type)atoi(argv[1]);
154         switch (cb_type) {
155                 case CB_NOTI_BATT_CHARGE:
156                         vib = SVI_VIB_OPERATION_CHARGERCONN;
157                         snd = SVI_SND_OPERATION_CHARGERCONN;
158                         break;
159                 case CB_NOTI_BATT_FULL:
160                         battery_full_noti(bNoti);
161                         if (1==bNoti) {
162                                 vib = SVI_VIB_OPERATION_FULLCHARGED;
163                                 snd = SVI_SND_OPERATION_FULLCHARGED;
164                                 break;
165                         } else
166                         return 0;
167                 default:
168                         PRT_TRACE("sys_device_noti cb_type error(%d)",cb_type);
169                         break;
170         }
171
172         r = svi_init(&handle); /* Initialize SVI */
173
174         if (r != SVI_SUCCESS) {
175                 PRT_TRACE("Cannot initialize SVI.\n");
176         } else {
177                 r = svi_play(handle, vib, snd);
178                 if (r != SVI_SUCCESS)
179                         PRT_TRACE("Cannot play sound or vibration.\n");
180                 r = svi_fini(handle); /* Finalize SVI */
181                 if (r != SVI_SUCCESS)
182                         PRT_TRACE("Cannot close SVI.\n");
183         }
184         return 0;
185 }