2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
28 #define LOG_TAG "APPINFO"
31 #define _SECURE_LOGI LOGI
32 #define _SECURE_LOGE LOGE
34 #define _SECURE_LOGI(...)
35 #define _SECURE_LOGE(...)
39 #define likely(x) __builtin_expect(!!(x), 1)
42 #define unlikely(x) __builtin_expect(!!(x), 0)
49 static const char INVALID_EXEC_NAME[] = "";
50 static app_info_version_e _current_api_ver = APP_INFO_VERSION_2_2;
51 static int _compat_mode = 0;
52 static int _app_info_init = 0;
55 static char** _argv = NULL;
57 #define MAX_OSP_PKGID 10
60 static char __pkgid[MAX_OSP_PKGID+1]={'\0',};
61 static char __appid[MAX_APPID]={'\0',};
62 static const char* _pkgid = NULL;
63 static const char* _appid = NULL;
64 static const char* _execname = &INVALID_EXEC_NAME;
68 * @brief Initializes the appinfo structure
70 * @param[in] appid The application id to initialize
71 * @param[in] is_invalid_appid @c 1 for invalid appid compatibility mode, @c 0 otherwise
72 * @return 0 on success, otherwise a negative error value
73 * @retval APP_INFO_ERROR_NONE Succesful
74 * @retval APP_INFO_ERROR_INVALID_ARG The appid is invalid
75 * @remarks It initialize the platform API version to APP_INFO_VERSION_3_0 and compat mode 0.
78 appinfo_init(const char* appid, int is_invalid_appid)
80 if (!appid || (appid && strlen(appid) >= sizeof(__appid)))
82 return APP_INFO_ERROR_INVALID_ARG;
85 strncpy(__appid, appid, strlen(appid));
88 // SLP-style old appid
95 if (strlen(appid) < sizeof(MAX_OSP_PKGID))
97 return APP_INFO_ERROR_INVALID_ARG;
99 // proper OSP or Web appid
100 strncpy(__pkgid, appid, MAX_OSP_PKGID);
103 _execname = __appid+(MAX_OSP_PKGID+1);
106 _current_api_ver = APP_INFO_VERSION_2_2;
110 return APP_INFO_ERROR_NONE;
114 * @brief Returns the API version
116 * @return app_info_version_e value
119 appinfo_get_api_version(void)
121 return _current_api_ver;
125 * @brief Sets the API version for the current process
127 * @param[in] ver Given API version
128 * @return 0 on success, otherwise a negative error value
129 * @retval APP_INFO_ERROR_NONE Succesful
133 appinfo_set_api_version(app_info_version_e ver)
137 return APP_INFO_ERROR_INVALID_ARG;
140 _current_api_ver = ver;
147 appinfo_set_api_version(int ver)
149 app_info_version_e temp_ver;
150 temp_ver = __get_api_version_from_str(appinfo_get_api_str_by_version(ver));
152 if ( temp_ver == APP_INFO_VERSION_INVALID)
154 return APP_INFO_ERROR_INVALID_ARG;
158 _current_api_ver = temp_ver;
159 return APP_INFO_ERROR_NONE;
165 * @brief Returns the API version string by given API version
167 * @param[in] ver Given API version
168 * @return the API version string by the given version
169 * @remakr If wrong API version, return NULL
172 appinfo_get_api_str_by_version(int ver)
175 case APP_INFO_VERSION_1_0 :
177 case APP_INFO_VERSION_1_0_2 :
179 case APP_INFO_VERSION_1_1 :
181 case APP_INFO_VERSION_1_2 :
183 case APP_INFO_VERSION_2_0 :
185 case APP_INFO_VERSION_2_1 :
187 case APP_INFO_VERSION_2_2 :
189 case APP_INFO_VERSION_3_0 :
196 app_info_version_e appinfo_get_api_version_from_str(const char * ver_str)
200 return APP_INFO_VERSION_INVALID;
203 if (!strcmp(ver_str,"3.0"))
205 return APP_INFO_VERSION_3_0;
207 else if (!strcmp(ver_str,"2.2"))
209 return APP_INFO_VERSION_2_2;
211 else if (!strcmp(ver_str,"2.1"))
213 return APP_INFO_VERSION_2_1;
215 else if (!strcmp(ver_str,"2.0"))
217 return APP_INFO_VERSION_2_0;
219 else if (!strcmp(ver_str,"1.2"))
221 return APP_INFO_VERSION_1_2;
223 else if (!strcmp(ver_str,"1.1"))
225 return APP_INFO_VERSION_1_1;
227 else if (!strcmp(ver_str,"1.0.2"))
229 return APP_INFO_VERSION_1_0_2;
231 else if (!strcmp(ver_str,"1.0"))
233 return APP_INFO_VERSION_1_0;
237 return APP_INFO_VERSION_INVALID;
242 * @brief Returns whether the application is compat mode or not
244 * @return @c 1 for compat mode, @c 0 otherwise
247 appinfo_is_compat(void)
253 * @brief Sets the application compat mode
255 * @param[in] the compatibility mode
256 * @return 0 on success, otherwise a negative error value
257 * @retval APP_INFO_ERROR_NONE Succesful
258 * @retval APP_INFO_ERROR_INVALID_ARG compat should be either @c 0 or @c 1.
261 appinfo_set_compat(int compat)
263 if (compat == 0 || compat == 1)
265 _compat_mode = compat;
266 return APP_INFO_ERROR_NONE;
268 return APP_INFO_ERROR_INVALID_ARG;
273 * @brief Returns the appid for the application
275 * @retval application ID if valid, @c NULL otherwise
278 appinfo_get_appid(void)
280 if (likely(_app_info_init))
289 * @brief Returns the exec name for the application
291 * @retval application exec name if valid, empty string otherwise
294 appinfo_get_execname(void)
301 * @brief Returns the packageid for the application
303 * @retval package ID if valid, @c NULL otherwise
306 appinfo_get_packageid(void)
308 if (likely(_app_info_init))
317 * @brief Returns whether the appinfo is initialized or not
319 * @return @c 1 if initialized, @c 0 otherwise
322 appinfo_is_initialized(void)
324 return _app_info_init;
328 appinfo_set_argv(int argc, char** argv)
330 if (argc > 0 && argv)
339 int appinfo_get_argv(int* argc, char*** argv)
341 if (_app_info_init && argc && argv)
351 #define MIN(a,b) ((a) < (b) ? (a) : (b))
353 int appinfo_update_submode_execname_and_appid(const char* execname)
355 if (execname == NULL)
360 const size_t max_len = MAX_APPID - MAX_OSP_PKGID - 1;
361 const size_t size = MIN(strlen(execname) - 1, max_len - 1);
362 strncpy(__appid + MAX_OSP_PKGID + 1, execname, size);
363 __appid[size + MAX_OSP_PKGID + 1] = '\0';