4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
27 #include <pkgmgr_installer.h>
31 #include "native_installer_util.h"
33 #define VCONF_LOCATION "db"
34 #define VCONF_NATIVE_INSTALLER VCONF_LOCATION"/nativeinstaller"
36 #define VCONF_NATIVE_INSTALLER_BACKEND_STATE \
37 VCONF_NATIVE_INSTALLER"/state"
38 #define VCONF_NATIVE_INSTALLER_BACKEND_STATEINFO \
39 VCONF_NATIVE_INSTALLER"/stateinfo"
41 #define VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_COMMAND \
42 VCONF_NATIVE_INSTALLER"/requestinfo/command"
43 #define VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_PKGNAME \
44 VCONF_NATIVE_INSTALLER"/requestinfo/pkgname"
45 #define VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_OPTIONS \
46 VCONF_NATIVE_INSTALLER"/requestinfo/options"
47 #define VCONF_NATIVE_INSTALLER_APPSETTING "db/app-settings"
49 extern char *gptrpkgname;
50 extern pkgmgr_installer *pi;
52 int _set_event_notification(int value)
56 char buff[256] = { 0, };
57 char strval[8] = { 0, };
59 snprintf(buff, sizeof(buff) - 1,
60 VCONF_NATIVE_INSTALLER_APPSETTING "/noti-enabled/%s",
63 d_msg_backend(DEBUG_ERR,
64 "_set_event_notification: snprintf FAIL\n");
68 ret = snprintf(strval, sizeof(strval) - 1, "%d", value);
70 d_msg_backend(DEBUG_ERR,
71 "_set_event_notification: snprintf FAIL\n");
75 if ((pid = fork()) < 0) {
77 } else if (pid == 0) {
78 execl("/usr/bin/vconftool", "vconftool", "-g", "6514", "set",
79 "-t", "int", buff, strval, (char *)0);
80 exit(127); /* execl error */
82 while (waitpid(pid, &ret, 0) < 0) {
84 ret = -1; /* error other than EINTR
92 d_msg_backend(DEBUG_ERR,
93 "_set_event_notification: vconf_set_int FAIL\n");
96 return NATIVEINSTALLER_SUCCESS;
99 int _unset_event_notification()
103 char buff[256] = { 0, };
104 ret = snprintf(buff, sizeof(buff) - 1,
105 VCONF_NATIVE_INSTALLER_APPSETTING "/noti-enabled/%s",
108 d_msg_backend(DEBUG_ERR,
109 "_unset_event_notification: snprintf FAIL\n");
113 if ((pid = fork()) < 0) {
115 } else if (pid == 0) {
116 execl("/usr/bin/vconftool", "vconftool", "unset", buff,
118 exit(127); /* execl error */
120 while (waitpid(pid, &ret, 0) < 0) {
121 if (errno != EINTR) {
122 ret = -1; /* error other than EINTR
130 d_msg_backend(DEBUG_ERR,
131 "_unset_event_notification: vconf_unset FAIL\n");
134 return NATIVEINSTALLER_SUCCESS;
138 int _get_backend_state()
142 ret = vconf_get_int(VCONF_NATIVE_INSTALLER_BACKEND_STATE, &state);
144 d_msg_backend(DEBUG_ERR,
145 "_get_backend_state: vconf_get_int FAIL\n");
152 int _set_backend_state(int state)
157 vconf_unset_recursive(VCONF_NATIVE_INSTALLER);
160 ret = vconf_set_int(VCONF_NATIVE_INSTALLER_BACKEND_STATE, state);
162 d_msg_backend(DEBUG_ERR,
163 "_set_backend_state: vconf_set_int FAIL\n");
169 int _get_backend_state_info()
173 ret = vconf_get_int(VCONF_NATIVE_INSTALLER_BACKEND_STATEINFO, &state);
175 d_msg_backend(DEBUG_ERR,
176 "_get_backend_state_info: vconf_get_int FAIL\n");
183 int _set_backend_state_info(int state)
186 ret = vconf_set_int(VCONF_NATIVE_INSTALLER_BACKEND_STATEINFO, state);
188 d_msg_backend(DEBUG_ERR,
189 "_set_backend_state_info: vconf_set_int FAIL\n");
194 int _get_last_input_info(char **pkgname, int *preqcommand, int *poptions)
197 if (!pkgname || !preqcommand || !poptions)
199 ret = vconf_get_int(VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_COMMAND,
202 d_msg_backend(DEBUG_ERR,
203 "_get_last_input_info: VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_COMMAND: vconf_get_int FAIL\n");
205 ret = vconf_get_int(VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_OPTIONS,
208 d_msg_backend(DEBUG_ERR,
209 "_get_last_input_info: VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_OPTIONS: vconf_get_int FAIL\n");
212 vconf_get_str(VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_PKGNAME);
216 void _save_last_input_info(char *pkgname, int reqcommand, int options)
218 keylist_t *kl = NULL;
219 kl = vconf_keylist_new();
221 vconf_keylist_add_int(kl,
222 VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_COMMAND,
224 vconf_keylist_add_str(kl,
225 VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_PKGNAME,
227 vconf_keylist_add_int(kl,
228 VCONF_NATIVE_INSTALLER_LAST_REQUESTINFO_OPTIONS,
232 d_msg_backend(DEBUG_ERR,
233 "_save_last_input_info: Failure in writing vconf\n");
235 vconf_keylist_free(kl);
240 void _broadcast_status_notification(char *pkgname, char *key, char *val)
242 char *ppkgname = NULL;
244 if (gptrpkgname != NULL)
245 ppkgname = gptrpkgname;
249 d_msg_backend(DEBUG_INFO, "pkgname = %s, key = %s, val = %s\n",
254 pkgmgr_installer_send_signal(pi, PKGTYPE, ppkgname, key, val);
256 d_msg_backend(DEBUG_ERR,
257 "Failure in sending broadcast message\n");