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.
20 #define TRACE_TAG TRACE_SDB
24 #include "sdbd_plugin.h"
25 #include "default_plugin.h"
27 int get_lock_state ( parameters* in, parameters* out )
29 if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL
30 || in->array_of_parameter[0].type != type_int32 ) {
31 D ( "Invalid argument\n" );
32 return PLUGIN_CMD_FAIL;
36 D ( "Invalid argument\n" );
37 return PLUGIN_CMD_FAIL;
40 D ( "lock type: %d\n", in->array_of_parameter[0].v_int32);
42 out->number_of_parameter = 1;
43 out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
44 out->array_of_parameter[0].type = type_int32;
45 out->array_of_parameter[0].v_int32 = ( plugin_pwlocked() == 1 ) ? PLUGIN_RET_ON : PLUGIN_RET_OFF;
47 return PLUGIN_CMD_SUCCESS;
50 int plugin_pwlocked ( void )
52 int pwlock_status = 0;
55 if ( vconf_get_int ( VCONFKEY_IDLE_LOCK_STATE, &pwlock_status ) ) {
57 PLUGIN_LOG ( "failed to get pw lock status\n" );
60 PLUGIN_LOG ( "wearable lock applied\n" );
61 // for wearable which uses different VCONF key (lock type)
62 if ( vconf_get_int ( VCONFKEY_SETAPPL_PRIVACY_LOCK_TYPE_INT, &pwlock_type ) ) {
64 PLUGIN_LOG ( "failed to get pw lock type\n" );
66 if ( ( pwlock_status == VCONFKEY_IDLE_LOCK ) && ( pwlock_type != SETTING_PRIVACY_LOCK_TYPE_NONE ) ) {
67 PLUGIN_LOG ( "device has been locked\n" );
71 PLUGIN_LOG ( "mobile lock applied\n" );
73 if ( vconf_get_int ( VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &pwlock_type ) ) {
75 PLUGIN_LOG ( "failed to get pw lock type\n" );
77 if ( pwlock_status == VCONFKEY_IDLE_LOCK && ( ( pwlock_type != SETTING_SCREEN_LOCK_TYPE_NONE ) && ( pwlock_type != SETTING_SCREEN_LOCK_TYPE_SWIPE ) ) ) {
78 PLUGIN_LOG ( "device has been locked\n" );
82 return 0; // unlocked!
85 static void pwlock_cb ( keynode_t *key, void* data )
87 PLUGIN_LOG ( "pwlock callback is issued\n" );
88 int pwlocked = plugin_pwlocked();
90 parameters* out = ( parameters* ) malloc ( sizeof ( parameters ) );
91 out->number_of_parameter = 1;
92 out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
93 out->array_of_parameter[0].type = type_int32;
94 out->array_of_parameter[0].v_int32 = ( pwlocked == 1 ) ? PLUGIN_RET_ON : PLUGIN_RET_OFF;
96 event_handler ( PLUGIN_EVENT_PWLOCK, out );
99 static void register_pwlock_cb()
101 int ret = vconf_notify_key_changed ( VCONFKEY_IDLE_LOCK_STATE, pwlock_cb, NULL );
103 PLUGIN_LOG ( "cannot register vconf callback.\n" );
106 PLUGIN_LOG ( "registered vconf callback\n" );
109 static void unregister_pwlock_cb()
111 int ret = vconf_ignore_key_changed ( VCONFKEY_IDLE_LOCK_STATE, pwlock_cb );
113 PLUGIN_LOG ( "cannot unregister vconf callback.\n" );
116 PLUGIN_LOG ( "unregistered vconf callback\n" );
119 static void *pwlock_thread ( void *x )
122 loop = g_main_loop_new ( NULL, FALSE );
123 register_pwlock_cb();
124 g_main_loop_run ( loop );
125 g_main_loop_unref ( loop );
126 unregister_pwlock_cb();
130 void create_pwlock_thread()
133 if ( sdb_thread_create ( &t, pwlock_thread, NULL ) ) {
134 PLUGIN_LOG ( "cannot create_pwlock_thread.\n" );
137 PLUGIN_LOG ( "created pwlock_thread\n" );