summaryrefslogtreecommitdiffstats
path: root/audio/ril_interface.c
blob: b20d42bdfd2cc004dc4872cbde9b63e5bc6bfbdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <dlfcn.h>

#include <utils/Log.h>

#include "ril_interface.h"

int ril_open(void **ril_handle, void **ril_client)
{
    void *handle;
    void *client;

    handle = dlopen(RIL_CLIENT_LIBPATH, RTLD_NOW);

    if (!handle) {
        LOGE("Cannot open '%s'", RIL_CLIENT_LIBPATH);
        return -1;
    }

    ril_open_client = dlsym(handle, "OpenClient_RILD");
    ril_close_client = dlsym(handle, "CloseClient_RILD");
    ril_connect = dlsym(handle, "Connect_RILD");
    ril_is_connected = dlsym(handle, "isConnected_RILD");
    ril_disconnect = dlsym(handle, "Disconnect_RILD");
    ril_set_call_volume = dlsym(handle, "SetCallVolume");
    ril_set_call_audio_path = dlsym(handle, "SetCallAudioPath");
    ril_set_call_clock_sync = dlsym(handle, "SetCallClockSync");

    if (!ril_open_client || !ril_close_client || !ril_connect ||
        !ril_is_connected || !ril_disconnect || !ril_set_call_volume ||
        !ril_set_call_audio_path || !ril_set_call_clock_sync) {
        LOGE("Cannot get symbols from '%s'", RIL_CLIENT_LIBPATH);
        dlclose(handle);
        return -1;
    }

    client = ril_open_client();
    if (!client) {
        LOGE("ril_open_client() failed");
        dlclose(handle);
        return -1;
    }

    if (ril_connect(client) != RIL_CLIENT_ERR_SUCCESS ||
        !ril_is_connected(client)) {
        LOGE("ril_connect() failed");
        ril_close_client(client);
        dlclose(handle);
        return -1;
    }

    *ril_handle = handle;
    *ril_client = client;
    return 0;
}

int ril_close(void *ril_handle, void *ril_client)
{
    if (!ril_handle)
        return -1;

    if ((ril_disconnect(ril_client) != RIL_CLIENT_ERR_SUCCESS) ||
        (ril_close_client(ril_client) != RIL_CLIENT_ERR_SUCCESS)) {
        LOGE("ril_disconnect() or ril_close_client() failed");
        return -1;
    }

    dlclose(ril_handle);
    return 0;
}