2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include "sdbd_plugin.h"
22 #include "default_plugin.h"
24 #include <system_info.h>
27 TIZEN_PROFILE_UNKNOWN = 0,
28 TIZEN_PROFILE_MOBILE = 0x1,
29 TIZEN_PROFILE_WEARABLE = 0x2,
30 TIZEN_PROFILE_TV = 0x4,
31 TIZEN_PROFILE_IVI = 0x8,
32 TIZEN_PROFILE_COMMON = 0x10,
34 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
35 static tizen_profile_t _get_tizen_profile()
38 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
39 switch (*profileName) {
42 profile = TIZEN_PROFILE_MOBILE;
46 profile = TIZEN_PROFILE_WEARABLE;
50 profile = TIZEN_PROFILE_TV;
54 profile = TIZEN_PROFILE_IVI;
56 default: // common or unknown ==> ALL ARE COMMON.
57 profile = TIZEN_PROFILE_COMMON;
63 static inline tizen_profile_t get_tizen_profile()
65 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
68 return _get_tizen_profile();
71 int plugin_pwlocked ( void )
73 int pwlock_status = 0;
76 if ( vconf_get_int ( VCONFKEY_IDLE_LOCK_STATE, &pwlock_status ) ) {
78 PLUGIN_LOG ( "failed to get pw lock status\n" );
80 if (get_tizen_profile() == TIZEN_PROFILE_WEARABLE) {
81 PLUGIN_LOG ( "wearable lock applied\n" );
82 // for wearable which uses different VCONF key (lock type)
83 if ( vconf_get_int ( VCONFKEY_SETAPPL_PRIVACY_LOCK_TYPE_INT, &pwlock_type ) ) {
85 PLUGIN_LOG ( "failed to get pw lock type\n" );
87 if ( ( pwlock_status == VCONFKEY_IDLE_LOCK ) && ( pwlock_type != SETTING_PRIVACY_LOCK_TYPE_NONE ) ) {
88 PLUGIN_LOG ( "device has been locked\n" );
92 PLUGIN_LOG ( "mobile lock applied\n" );
94 if ( vconf_get_int ( VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &pwlock_type ) ) {
96 PLUGIN_LOG ( "failed to get pw lock type\n" );
98 if ( pwlock_status == VCONFKEY_IDLE_LOCK && ( ( pwlock_type != SETTING_SCREEN_LOCK_TYPE_NONE ) && ( pwlock_type != SETTING_SCREEN_LOCK_TYPE_SWIPE ) ) ) {
99 PLUGIN_LOG ( "device has been locked\n" );
103 return 0; // unlocked!
106 int get_lock_state ( parameters* in, parameters* out )
108 if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
109 || in->array_of_parameter[0].type != type_int32 ) {
110 PLUGIN_LOG ( "Invalid argument\n" );
111 return PLUGIN_CMD_FAIL;
115 PLUGIN_LOG ( "Invalid argument\n" );
116 return PLUGIN_CMD_FAIL;
119 PLUGIN_LOG ( "lock type: %d\n", in->array_of_parameter[0].v_int32);
121 out->number_of_parameter = 1;
122 out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
123 out->array_of_parameter[0].type = type_int32;
124 out->array_of_parameter[0].v_int32 = ( plugin_pwlocked() == 1 ) ? PLUGIN_RET_ON : PLUGIN_RET_OFF;
126 return PLUGIN_CMD_SUCCESS;
129 static void pwlock_cb ( keynode_t *key, void* data )
131 PLUGIN_LOG ( "pwlock callback is issued\n" );
132 int pwlocked = plugin_pwlocked();
134 parameters* out = ( parameters* ) malloc ( sizeof ( parameters ) );
135 out->number_of_parameter = 1;
136 out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
137 out->array_of_parameter[0].type = type_int32;
138 out->array_of_parameter[0].v_int32 = ( pwlocked == 1 ) ? PLUGIN_RET_ON : PLUGIN_RET_OFF;
140 event_handler ( PLUGIN_EVENT_PWLOCK, out );
143 static void register_pwlock_cb()
145 int ret = vconf_notify_key_changed ( VCONFKEY_IDLE_LOCK_STATE, pwlock_cb, NULL );
147 PLUGIN_LOG ( "cannot register vconf callback.\n" );
150 PLUGIN_LOG ( "registered vconf callback\n" );
153 static void unregister_pwlock_cb()
155 int ret = vconf_ignore_key_changed ( VCONFKEY_IDLE_LOCK_STATE, pwlock_cb );
157 PLUGIN_LOG ( "cannot unregister vconf callback.\n" );
160 PLUGIN_LOG ( "unregistered vconf callback\n" );
163 static void *pwlock_thread ( void *x )
166 loop = g_main_loop_new ( NULL, FALSE );
167 register_pwlock_cb();
168 g_main_loop_run ( loop );
169 g_main_loop_unref ( loop );
170 unregister_pwlock_cb();
174 void create_pwlock_thread()
177 if ( sdb_thread_create ( &t, pwlock_thread, NULL ) ) {
178 PLUGIN_LOG ( "default plugin : cannot create_pwlock_thread.\n" );
181 PLUGIN_LOG ( "default plugin : created pwlock_thread\n" );