blob: 8c8c9493b983762f9ac1409a6106140578cf55f1 [file] [log] [blame]
#include "BnHiccupd.hpp"
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <binder/IPCThreadState.h>
#include "glob.h"
using namespace android;
#define PLOG aout
namespace hiccup {
status_t BnHiccupd::onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
ALOGD("%s(%i) %i", __func__, code, flags);
data.checkInterface(this);
data.print(PLOG); endl(PLOG);
status_t ret = BAD_VALUE;
Vector<LogFile> *v =NULL;
String16 bootreason;
switch(code) {
case GET_LOGS:
v = getLogs();
if (v != NULL) {
ret = sendLogFiles(v, reply);
delete v;
}
return ret;
case GET_LAST_KMESG:
v = getLastKmsg();
if (v != NULL) {
ret = sendLogFiles(v, reply);
delete v;
}
return ret;
case CLEAN_LOGS:
return cleanLogs();
case START_LOGGING:
return startLogging();
case STOP_LOGGING:
return stopLogging();
case GET_BOOTREASON:
bootreason= getBootReason();
ret = reply->writeString16(bootreason);
return ret;
case GET_POWERONREASON:
bootreason= getPowerOnReason();
ret = reply->writeString16(bootreason);
return ret;
case GET_POWEROFFREASON:
bootreason= getPowerOffReason();
ret = reply->writeString16(bootreason);
return ret;
case GET_API_VERSION:
ret = reply->writeInt32(getApiVersion());
return ret;
default:
return BBinder::onTransact(code, data, reply, flags);
}
}
status_t BnHiccupd::sendLogFiles(const Vector<LogFile> *v, Parcel *parcel) {
status_t ret = OK;
if ( (ret = parcel->writeInt32(v->size())) != OK) {
return ret;
}
for (Vector<LogFile>::const_iterator it = v->begin() ; it != v->end(); ++it) {
ALOGD("sending fd...");
String8 pathLeaf = String8(it->fileName).getPathLeaf();
printf("<(%s))))><\n",pathLeaf.string());
if ( (ret = parcel->writeString16(String16(pathLeaf))) != OK) {
return ret;
}
ret = parcel->writeFileDescriptor(it->fd,true); /* binder will close our fds */
if (ret != OK) {
ALOGD("Writing Filedescriptor failed: %d", ret);
return ret;
}
}
return ret;
}
} /* namespace hiccup */