Merge "SapImpl: log error description"
diff --git a/libril/Android.mk b/libril/Android.mk
index ca6c004..a9e30f7 100644
--- a/libril/Android.mk
+++ b/libril/Android.mk
@@ -6,7 +6,6 @@
LOCAL_SRC_FILES:= \
ril.cpp \
ril_event.cpp\
- RilSocket.cpp \
RilSapSocket.cpp \
ril_service.cpp \
sap_service.cpp
@@ -14,7 +13,6 @@
LOCAL_SHARED_LIBRARIES := \
liblog \
libutils \
- libbinder \
libcutils \
libhardware_legacy \
librilutils \
diff --git a/libril/RilSapSocket.cpp b/libril/RilSapSocket.cpp
index a9187be..20df3a2 100644
--- a/libril/RilSapSocket.cpp
+++ b/libril/RilSapSocket.cpp
@@ -181,7 +181,6 @@
}
current->next = listItem;
}
- socket->socketInit();
}
}
@@ -197,24 +196,6 @@
return false;
}
-void* RilSapSocket::processRequestsLoop(void) {
- RLOGI("UIM_SOCKET:Request loop started");
-
- while(true) {
- SapSocketRequest *req = dispatchQueue.dequeue();
-
- RLOGI("New request from the dispatch Queue");
-
- if (req != NULL) {
- dispatchRequest(req->curr);
- free(req);
- } else {
- RLOGE("Fetched null buffer from queue!");
- }
- }
- return NULL;
-}
-
RilSapSocket::RilSapSocket(const char *socketName,
RIL_SOCKET_ID socketId,
RIL_RadioFunctions *inputUimFuncs):
@@ -338,54 +319,6 @@
free(hdr);
}
-void RilSapSocket::sendResponse(MsgHeader* hdr) {
- size_t encoded_size = 0;
- uint32_t written_size;
- size_t buffer_size = 0;
- pb_ostream_t ostream;
- bool success = false;
-
- pthread_mutex_lock(&write_lock);
-
- if ((success = pb_get_encoded_size(&encoded_size, MsgHeader_fields,
- hdr)) && encoded_size <= INT32_MAX && commandFd != -1) {
- buffer_size = encoded_size + sizeof(uint32_t);
- uint8_t* buffer = (uint8_t*)malloc(buffer_size);
- if (!buffer) {
- RLOGE("sendResponse: OOM");
- pthread_mutex_unlock(&write_lock);
- return;
- }
- written_size = htonl((uint32_t) encoded_size);
- ostream = pb_ostream_from_buffer(buffer, buffer_size);
- pb_write(&ostream, (uint8_t *)&written_size, sizeof(written_size));
- success = pb_encode(&ostream, MsgHeader_fields, hdr);
-
- if (success) {
- RLOGD("Size: %zu (0x%zx) Size as written: 0x%x", encoded_size,
- encoded_size, written_size);
- log_hex("onRequestComplete", &buffer[sizeof(written_size)], encoded_size);
- RLOGI("[%d] < SAP RESPONSE type: %d. id: %d. error: %d",
- hdr->token, hdr->type, hdr->id,hdr->error );
-
- if ( 0 != blockingWrite_helper(commandFd, buffer, buffer_size)) {
- RLOGE("Error %d while writing to fd", errno);
- } else {
- RLOGD("Write successful");
- }
- } else {
- RLOGE("Error while encoding response of type %d id %d buffer_size: %zu: %s.",
- hdr->type, hdr->id, buffer_size, PB_GET_ERROR(&ostream));
- }
- free(buffer);
- } else {
- RLOGE("Not sending response type %d: encoded_size: %zu. commandFd: %d. encoded size result:\
- %d", hdr->type, encoded_size, commandFd, success);
- }
-
- pthread_mutex_unlock(&write_lock);
-}
-
void RilSapSocket::onUnsolicitedResponse(int unsolResponse, void *data, size_t datalen) {
if (data && datalen > 0) {
pb_bytes_array_t *payload = (pb_bytes_array_t *)calloc(1,
@@ -404,116 +337,4 @@
sap::processUnsolResponse(&rsp, this);
free(payload);
}
-}
-
-void RilSapSocket::pushRecord(void *p_record, size_t recordlen) {
- pb_istream_t stream = pb_istream_from_buffer((uint8_t *)p_record, recordlen);
- // MsgHeader will be deallocated in onRequestComplete()
- MsgHeader *reqHeader = (MsgHeader *)malloc(sizeof (MsgHeader));
- if (!reqHeader) {
- RLOGE("pushRecord: OOM");
- return;
- }
- memset(reqHeader, 0, sizeof(MsgHeader));
-
- log_hex("BtSapTest-Payload", (const uint8_t*)p_record, recordlen);
-
- if (!pb_decode(&stream, MsgHeader_fields, reqHeader) ) {
- RLOGE("Error decoding protobuf buffer : %s", PB_GET_ERROR(&stream));
- free(reqHeader);
- } else {
- // SapSocketRequest will be deallocated in processRequestsLoop()
- SapSocketRequest *recv = (SapSocketRequest*)malloc(sizeof(SapSocketRequest));
- if (!recv) {
- RLOGE("pushRecord: OOM");
- free(reqHeader);
- return;
- }
- recv->token = reqHeader->token;
- recv->curr = reqHeader;
- recv->socketId = id;
-
- dispatchQueue.enqueue(recv);
- }
-}
-
-void RilSapSocket::sendDisconnect() {
- size_t encoded_size = 0;
- uint32_t written_size;
- size_t buffer_size = 0;
- pb_ostream_t ostream;
- bool success = false;
-
- RIL_SIM_SAP_DISCONNECT_REQ disconnectReq;
-
- if ((success = pb_get_encoded_size(&encoded_size, RIL_SIM_SAP_DISCONNECT_REQ_fields,
- &disconnectReq)) && encoded_size <= INT32_MAX) {
- buffer_size = encoded_size + sizeof(uint32_t);
- uint8_t* buffer = (uint8_t*)malloc(buffer_size);
- if (!buffer) {
- RLOGE("sendDisconnect: OOM");
- return;
- }
- written_size = htonl((uint32_t) encoded_size);
- ostream = pb_ostream_from_buffer(buffer, buffer_size);
- pb_write(&ostream, (uint8_t *)&written_size, sizeof(written_size));
- success = pb_encode(&ostream, RIL_SIM_SAP_DISCONNECT_REQ_fields, buffer);
-
- if(success) {
- // Buffer will be deallocated in sOnRequestComplete()
- pb_bytes_array_t *payload = (pb_bytes_array_t *)calloc(1,
- sizeof(pb_bytes_array_t) + written_size);
- if (!payload) {
- RLOGE("sendDisconnect: OOM");
- return;
- }
- memcpy(payload->bytes, buffer, written_size);
- payload->size = written_size;
- // MsgHeader will be deallocated in sOnRequestComplete()
- MsgHeader *hdr = (MsgHeader *)malloc(sizeof(MsgHeader));
- if (!hdr) {
- RLOGE("sendDisconnect: OOM");
- free(payload);
- return;
- }
- hdr->payload = payload;
- hdr->type = MsgType_REQUEST;
- hdr->id = MsgId_RIL_SIM_SAP_DISCONNECT;
- hdr->error = Error_RIL_E_SUCCESS;
- dispatchDisconnect(hdr);
- }
- else {
- RLOGE("Encode failed in send disconnect!");
- }
- free(buffer);
- }
-}
-
-void RilSapSocket::dispatchDisconnect(MsgHeader *req) {
- // SapSocketRequest will be deallocated in sOnRequestComplete()
- SapSocketRequest* currRequest=(SapSocketRequest*)malloc(sizeof(SapSocketRequest));
- if (!currRequest) {
- RLOGE("dispatchDisconnect: OOM");
- // Free memory allocated in sendDisconnect
- free(req->payload);
- free(req);
- return;
- }
- currRequest->token = -1;
- currRequest->curr = req;
- currRequest->p_next = NULL;
- currRequest->socketId = (RIL_SOCKET_ID)99;
-
- RLOGD("Sending disconnect on command close!");
-
-#if defined(ANDROID_MULTI_SIM)
- uimFuncs->onRequest(req->id, req->payload->bytes, req->payload->size, currRequest, id);
-#else
- uimFuncs->onRequest(req->id, req->payload->bytes, req->payload->size, currRequest);
-#endif
-}
-
-void RilSapSocket::onCommandsSocketClosed() {
- sendDisconnect();
- RLOGE("Socket command closed");
-}
+}
\ No newline at end of file
diff --git a/libril/RilSapSocket.h b/libril/RilSapSocket.h
index 68ee4b4..1f6163e 100644
--- a/libril/RilSapSocket.h
+++ b/libril/RilSapSocket.h
@@ -99,11 +99,6 @@
static void printList();
/**
- * Clean up method to be called on command close.
- */
- void onCommandsSocketClosed(void);
-
- /**
* Dispatches the request to the lower layers.
* It calls the on request function.
*
@@ -129,16 +124,6 @@
protected:
/**
- * Process each record read from the socket and
- * push a new request created from that record to
- * the dispatch request queue.
- *
- * @param The record data.
- * @param The record length.
- */
- void pushRecord(void *record, size_t recordlen);
-
- /**
* Socket handler to be called when a request has
* been completed.
*
@@ -162,19 +147,6 @@
void *data, size_t datalen);
/**
- * Method to send response to SAP. It does an atomic write operation on the
- * socket.
- *
- * @param the response header with the payload.
- */
- void sendResponse(MsgHeader *hdr);
-
- /**
- * A loop for processing the requests in the request dispatch queue.
- */
- void *processRequestsLoop(void);
-
- /**
* Class method to add the sap socket to the list of sockets.
* Does nothing if the socket is already present in the list.
* Otherwise, calls the constructor of the parent class(To startlistening)
@@ -191,18 +163,6 @@
*/
static bool SocketExists(const char *socketName);
- /**
- * Send a clean up SAP DISCONNECT if the socket disconnects before doing a SAP
- * disconnect.
- */
- void sendDisconnect(void);
-
- /**
- * Dispatch the clean up disconnect request.
- */
- void dispatchDisconnect(MsgHeader *req);
-
-
private:
/**
* Constructor.
diff --git a/libril/RilSocket.cpp b/libril/RilSocket.cpp
deleted file mode 100644
index a77423d..0000000
--- a/libril/RilSocket.cpp
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
-* Copyright (C) 2014 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.
-*/
-
-extern "C"
-void *ril_socket_process_requests_loop(void *arg);
-
-#include "RilSocket.h"
-#include <cutils/sockets.h>
-#include <utils/Log.h>
-#include <assert.h>
-#define SOCKET_LISTEN_BACKLOG 0
-
-int RilSocket::socketInit(void) {
- int ret;
-
- listenCb = &RilSocket::sSocketListener;
- commandCb = &RilSocket::sSocketRequestsHandler;
- listenFd = android_get_control_socket(name);
-
- //Start listening
- ret = listen(listenFd, SOCKET_LISTEN_BACKLOG);
-
- if (ret < 0) {
- RLOGE("Failed to listen on %s socket '%d': %s",
- name, listenFd, strerror(errno));
- return ret;
- }
- //Add listen event to the event loop
- ril_event_set(&listenEvent, listenFd, false, listenCb, this);
- rilEventAddWakeup_helper(&listenEvent);
- return ret;
-}
-
-void RilSocket::sSocketListener(int fd, short flags, void *param) {
- RilSocket *theSocket = (RilSocket *) param;
- MySocketListenParam listenParam;
- listenParam.socket = theSocket;
- listenParam.sListenParam.type = RIL_SAP_SOCKET;
-}
-
-void RilSocket::onNewCommandConnect() {
- pthread_attr_t attr;
- PthreadPtr pptr = ril_socket_process_requests_loop;
- int result;
-
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
- //Start socket request processing loop thread
- result = pthread_create(&socketThreadId, &attr, pptr, this);
- if(result < 0) {
- RLOGE("pthread_create failed with result:%d",result);
- }
-
- RLOGE("New socket command connected and socket request thread started");
-}
-
-void RilSocket::sSocketRequestsHandler(int fd, short flags, void *param) {
- socketClient *sc = (socketClient *) param;
- RilSocket *theSocket = sc->socketPtr;
- RecordStream *rs = sc->rs;
-
- theSocket->socketRequestsHandler(fd, flags, rs);
-}
-
-void RilSocket::socketRequestsHandler(int fd, short flags, RecordStream *p_rs) {
- int ret;
- assert(fd == commandFd);
- void *p_record;
- size_t recordlen;
-
- for (;;) {
- /* loop until EAGAIN/EINTR, end of stream, or other error */
- ret = record_stream_get_next(p_rs, &p_record, &recordlen);
-
- if (ret == 0 && p_record == NULL) {
- /* end-of-stream */
- break;
- } else if (ret < 0) {
- break;
- } else if (ret == 0) {
- pushRecord(p_record, recordlen);
- }
- }
-
- if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
- /* fatal error or end-of-stream */
- if (ret != 0) {
- RLOGE("error on reading command socket errno:%d\n", errno);
- } else {
- RLOGW("EOS. Closing command socket.");
- }
-
- close(commandFd);
- commandFd = -1;
-
- ril_event_del(&callbackEvent);
-
- record_stream_free(p_rs);
-
- /* start listening for new connections again */
-
- rilEventAddWakeup_helper(&listenEvent);
-
- onCommandsSocketClosed();
- }
-}
-
-void RilSocket::setListenFd(int fd) {
- listenFd = fd;
-}
-
-void RilSocket::setCommandFd(int fd) {
- commandFd = fd;
-}
-
-int RilSocket::getListenFd(void) {
- return listenFd;
-}
-
-int RilSocket::getCommandFd(void) {
- return commandFd;
-}
-
-void RilSocket::setListenCb(ril_event_cb cb) {
- listenCb = cb;
-}
-
-void RilSocket::setCommandCb(ril_event_cb cb) {
- commandCb = cb;
-}
-
-ril_event_cb RilSocket::getListenCb(void) {
- return listenCb;
-}
-
-ril_event_cb RilSocket::getCommandCb(void) {
- return commandCb;
-}
-
-void RilSocket::setListenEvent(ril_event event) {
- listenEvent = event;
-}
-
-void RilSocket::setCallbackEvent(ril_event event) {
- callbackEvent = event;
-}
-
-ril_event* RilSocket::getListenEvent(void) {
- return &listenEvent;
-}
-
-ril_event* RilSocket::getCallbackEvent(void) {
- return &callbackEvent;
-}
-
-RIL_SOCKET_ID RilSocket::getSocketId(void) {
- return id;
-}
-
-extern "C"
-void *ril_socket_process_requests_loop(void *arg) {
- RilSocket *socket = (RilSocket *)arg;
- socket->processRequestsLoop();
- return NULL;
-}
diff --git a/libril/RilSocket.h b/libril/RilSocket.h
index 3f5de61..53b00c9 100644
--- a/libril/RilSocket.h
+++ b/libril/RilSocket.h
@@ -20,10 +20,6 @@
#include "rilSocketQueue.h"
#include <ril_event.h>
-using namespace std;
-
-extern "C" void *ril_socket_process_requests_loop(void *arg);
-
/**
* Abstract socket class representing sockets in rild.
* <p>
@@ -46,81 +42,6 @@
*/
RIL_SOCKET_ID id;
- /**
- * Listen socket file descriptor.
- */
- int listenFd = -1;
-
- /**
- * Commands socket file descriptor.
- */
- int commandFd = -1;
-
- /**
- * Socket request loop thread id.
- */
- pthread_t socketThreadId;
-
- /**
- * Listen event callack. Callback called when the other ends does accept.
- */
- ril_event_cb listenCb;
-
- /**
- * Commands event callack.Callback called when there are requests from the other side.
- */
- ril_event_cb commandCb;
-
- /**
- * Listen event to be added to eventloop after socket listen.
- */
- struct ril_event listenEvent;
-
- /**
- * Commands event to be added to eventloop after accept.
- */
- struct ril_event callbackEvent;
-
- /**
- * Static socket listen handler. Chooses the socket to call the listen callback
- * from ril.cpp.
- *
- * @param Listen fd.
- * @param flags.
- * @param Parameter for the listen handler.
- */
- static void sSocketListener(int fd, short flags, void *param);
-
- /**
- * Static socket request handler. Chooses the socket to call the request handler on.
- *
- * @param Commands fd.
- * @param flags.
- * @param Parameter for the request handler.
- */
- static void sSocketRequestsHandler(int fd, short flags, void *param);
-
- /**
- * Process record from the record stream and push the requests onto the queue.
- *
- * @param record data.
- * @param record length.
- */
- virtual void pushRecord(void *record, size_t recordlen) = 0;
-
- /**
- * Socket lock for writing data on the socket.
- */
- pthread_mutex_t write_lock = PTHREAD_MUTEX_INITIALIZER;
-
- /**
- * The loop to process the incoming requests.
- */
- virtual void *processRequestsLoop(void) = 0;
-
- private:
- friend void *::ril_socket_process_requests_loop(void *arg);
-
public:
/**
@@ -135,145 +56,15 @@
}
/**
- * Clean up function on commands socket close.
- */
- virtual void onCommandsSocketClosed(void) = 0;
-
- /**
- * Function called on new commands socket connect. Request loop thread is started here.
- */
- void onNewCommandConnect(void);
-
- /**
- * Set listen socket fd.
- *
- * @param Input fd.
- */
- void setListenFd(int listenFd);
-
- /**
- * Set commands socket fd.
- *
- * @param Input fd.
- */
- void setCommandFd(int commandFd);
-
- /**
- * Get listen socket fd.
- *
- * @return Listen fd.
- */
- int getListenFd(void);
-
- /**
- * Get commands socket fd.
- *
- * @return Commands fd.
- */
- int getCommandFd(void);
-
- /**
- * Set listen event callback.
- *
- * @param Input event callback.
- */
- void setListenCb(ril_event_cb listenCb);
-
- /**
- * Set command event callback.
- *
- * @param Input event callback.
- */
- void setCommandCb(ril_event_cb commandCb);
-
- /**
- * Get listen event callback.
- *
- * @return Listen event callback.
- */
- ril_event_cb getListenCb(void);
-
- /**
- * Gey command event callback.
- *
- * @return Command event callback.
- */
- ril_event_cb getCommandCb(void);
-
- /**
- * Set listen event.
- *
- * @param Input event.
- */
- void setListenEvent(ril_event listenEvent);
-
- /**
- * Set command callback event.
- *
- * @param Input event.
- */
- void setCallbackEvent(ril_event commandEvent);
-
- /**
- * Get listen event.
- *
- * @return Listen event.
- */
- ril_event* getListenEvent(void);
-
- /**
- * Get commands callback event.
- *
- * @return Commands callback event.
- */
- ril_event* getCallbackEvent(void);
-
- /**
* Get socket id.
*
* @return RIL_SOCKET_ID socket id.
*/
- RIL_SOCKET_ID getSocketId(void);
+ RIL_SOCKET_ID getSocketId(void) {
+ return id;
+ }
virtual ~RilSocket(){}
-
- protected:
-
- /**
- * Start listening on the socket and add the socket listen callback event.
- *
- * @return Result of the socket listen.
- */
- int socketInit(void);
-
- /**
- * Socket request handler
- *
- * @param Commands fd.
- * @param flags.
- * @param Record stream.
- */
- void socketRequestsHandler(int fd, short flags, RecordStream *rs);
};
-class socketClient {
- public:
- RilSocket *socketPtr;
- RecordStream *rs;
-
- socketClient(RilSocket *socketPtr, RecordStream *rs) {
- this->socketPtr = socketPtr;
- this->rs = rs;
- }
-};
-
-typedef struct MySocketListenParam {
- SocketListenParam sListenParam;
- RilSocket *socket;
-} MySocketListenParam;
-
-typedef void* (RilSocket::*RilSocketFuncPtr)(void);
-typedef void (RilSocket::*RilSocketEventPtr)(int fd,short flags, void *param);
-typedef void* (*PthreadPtr)(void*);
-
#endif
diff --git a/rild/rild.rc b/rild/rild.rc
index f4b7521..2aa8c63 100644
--- a/rild/rild.rc
+++ b/rild/rild.rc
@@ -1,5 +1,4 @@
service ril-daemon /vendor/bin/hw/rild
class main
- socket sap_uim_socket1 stream 660 bluetooth bluetooth
user root
group radio cache inet misc audio log readproc wakelock