2 * Copyright (c) 2009-2015 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.
18 #include <vconf-keys.h>
21 #include "_util_log.h"
23 int earphone_is_connected;
25 static void _volume_earphone_changed_cb(keynode_t *node, void *data)
30 ret = vconf_get_int(VCONFKEY_SYSMAN_EARJACK, &status);
35 case VCONFKEY_SYSMAN_EARJACK_3WIRE:
36 case VCONFKEY_SYSMAN_EARJACK_4WIRE:
37 case VCONFKEY_SYSMAN_EARJACK_TVOUT:
38 _D("Earphone is connected");
39 earphone_is_connected = 1;
42 _D("Earphone is disconnected");
43 earphone_is_connected = 0;
48 static int register_earphone_module(void *data)
52 ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_EARJACK, _volume_earphone_changed_cb, NULL);
54 _E("Failed to set earphone changed callback");
55 return VOLUME_ERROR_FAIL;
58 _volume_earphone_changed_cb(NULL, NULL);
60 return VOLUME_ERROR_OK;
63 static int deregister_earphone_module(void *data)
67 ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_EARJACK, _volume_earphone_changed_cb);
69 _E("Failed to set earphone changed callback");
70 return VOLUME_ERROR_FAIL;
73 return VOLUME_ERROR_OK;
76 void earphone_init(void)
78 _D("Initialization Earphone");
82 ret = register_earphone_module(NULL);
83 _D("Initializaion result: %d", ret);
86 void earphone_fini(void)
88 _D("Deinitialization Earphone");
91 ret = deregister_earphone_module(NULL);
92 _D("Deinitialization result: %d", ret);
95 int earphone_get_earphone_is_connected(void)
97 return earphone_is_connected;