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);
36 case VCONFKEY_SYSMAN_EARJACK_3WIRE:
37 case VCONFKEY_SYSMAN_EARJACK_4WIRE:
38 case VCONFKEY_SYSMAN_EARJACK_TVOUT:
39 _D("Earphone is connected");
40 earphone_is_connected = 1;
43 _D("Earphone is disconnected");
44 earphone_is_connected = 0;
49 static int register_earphone_module(void *data)
53 ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_EARJACK, _volume_earphone_changed_cb, NULL);
55 _E("Failed to set earphone changed callback");
56 return VOLUME_ERROR_FAIL;
59 _volume_earphone_changed_cb(NULL, NULL);
61 return VOLUME_ERROR_OK;
64 static int deregister_earphone_module(void *data)
68 ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_EARJACK, _volume_earphone_changed_cb);
70 _E("Failed to set earphone changed callback");
71 return VOLUME_ERROR_FAIL;
74 return VOLUME_ERROR_OK;
77 void earphone_init(void)
79 _D("Initialization Earphone");
83 ret = register_earphone_module(NULL);
84 _D("Initializaion result: %d", ret);
87 void earphone_fini(void)
89 _D("Deinitialization Earphone");
92 ret = deregister_earphone_module(NULL);
93 _D("Deinitialization result: %d", ret);
96 int earphone_get_earphone_is_connected(void)
98 return earphone_is_connected;