Network traffic accounting for chromium stack support in mediaserver.
- Atribute network activity to uid calling the mediaplayer
- Enables logging of chromium network stack in logcat
Change-Id: I2d28c8392248a056b3cee305dd4d4475ebba4337
This commit is contained in:
@@ -255,8 +255,8 @@ sp<IMediaPlayer> MediaPlayerService::create(
|
||||
this, pid, connId, client, audioSessionId,
|
||||
IPCThreadState::self()->getCallingUid());
|
||||
|
||||
LOGV("Create new client(%d) from pid %d, url=%s, connId=%d, audioSessionId=%d",
|
||||
connId, pid, url, connId, audioSessionId);
|
||||
LOGV("Create new client(%d) from pid %d, uid %d, url=%s, connId=%d, audioSessionId=%d",
|
||||
connId, pid, IPCThreadState::self()->getCallingUid(), url, connId, audioSessionId);
|
||||
if (NO_ERROR != c->setDataSource(url, headers))
|
||||
{
|
||||
c.clear();
|
||||
@@ -277,8 +277,9 @@ sp<IMediaPlayer> MediaPlayerService::create(pid_t pid, const sp<IMediaPlayerClie
|
||||
this, pid, connId, client, audioSessionId,
|
||||
IPCThreadState::self()->getCallingUid());
|
||||
|
||||
LOGV("Create new client(%d) from pid %d, fd=%d, offset=%lld, length=%lld, audioSessionId=%d",
|
||||
connId, pid, fd, offset, length, audioSessionId);
|
||||
LOGV("Create new client(%d) from pid %d, uid %d, fd=%d, offset=%lld, "
|
||||
"length=%lld, audioSessionId=%d", connId, pid,
|
||||
IPCThreadState::self()->getCallingUid(), fd, offset, length, audioSessionId);
|
||||
if (NO_ERROR != c->setDataSource(fd, offset, length)) {
|
||||
c.clear();
|
||||
} else {
|
||||
|
||||
@@ -39,7 +39,8 @@ HTTPBase::HTTPBase()
|
||||
mPrevBandwidthMeasureTimeUs(0),
|
||||
mPrevEstimatedBandWidthKbps(0),
|
||||
mBandWidthCollectFreqMs(5000),
|
||||
mUIDValid(false) {
|
||||
mUIDValid(false),
|
||||
mUID(0) {
|
||||
}
|
||||
|
||||
// static
|
||||
@@ -135,9 +136,19 @@ bool HTTPBase::getUID(uid_t *uid) const {
|
||||
}
|
||||
|
||||
// static
|
||||
void HTTPBase::RegisterSocketUser(int s, uid_t uid) {
|
||||
static const uint32_t kTag = 0xdeadbeef;
|
||||
set_qtaguid(s, kTag, uid);
|
||||
void HTTPBase::RegisterSocketUserTag(int sockfd, uid_t uid, uint32_t kTag) {
|
||||
int res = qtaguid_tagSocket(sockfd, kTag, uid);
|
||||
if (res != 0) {
|
||||
LOGE("Failed tagging socket %d for uid %d (My UID=%d)", sockfd, uid, geteuid());
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
void HTTPBase::UnRegisterSocketUserTag(int sockfd) {
|
||||
int res = qtaguid_untagSocket(sockfd);
|
||||
if (res != 0) {
|
||||
LOGE("Failed untagging socket %d (My UID=%d)", sockfd, geteuid());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
|
||||
@@ -61,6 +61,12 @@ status_t ChromiumHTTPDataSource::connect(
|
||||
off64_t offset) {
|
||||
Mutex::Autolock autoLock(mLock);
|
||||
|
||||
uid_t uid;
|
||||
if (getUID(&uid)) {
|
||||
mDelegate->setUID(uid);
|
||||
}
|
||||
LOG_PRI(ANDROID_LOG_VERBOSE, LOG_TAG, "connect on behalf of uid %d", uid);
|
||||
|
||||
return connect_l(uri, headers, offset);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "support.h"
|
||||
|
||||
#include "android/net/android_network_library_impl.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/threading/thread.h"
|
||||
#include "net/base/cert_verifier.h"
|
||||
#include "net/base/cookie_monster.h"
|
||||
@@ -34,8 +35,10 @@
|
||||
|
||||
#include "include/ChromiumHTTPDataSource.h"
|
||||
|
||||
#include <cutils/log.h>
|
||||
#include <cutils/properties.h>
|
||||
#include <media/stagefright/MediaErrors.h>
|
||||
#include <string>
|
||||
|
||||
namespace android {
|
||||
|
||||
@@ -44,6 +47,34 @@ static base::Thread *gNetworkThread = NULL;
|
||||
static scoped_refptr<net::URLRequestContext> gReqContext;
|
||||
static scoped_ptr<net::NetworkChangeNotifier> gNetworkChangeNotifier;
|
||||
|
||||
bool logMessageHandler(
|
||||
int severity,
|
||||
const char* file,
|
||||
int line,
|
||||
size_t message_start,
|
||||
const std::string& str) {
|
||||
int androidSeverity = ANDROID_LOG_VERBOSE;
|
||||
switch(severity) {
|
||||
case logging::LOG_FATAL:
|
||||
androidSeverity = ANDROID_LOG_FATAL;
|
||||
break;
|
||||
case logging::LOG_ERROR_REPORT:
|
||||
case logging::LOG_ERROR:
|
||||
androidSeverity = ANDROID_LOG_ERROR;
|
||||
break;
|
||||
case logging::LOG_WARNING:
|
||||
androidSeverity = ANDROID_LOG_WARN;
|
||||
break;
|
||||
default:
|
||||
androidSeverity = ANDROID_LOG_VERBOSE;
|
||||
break;
|
||||
}
|
||||
android_printLog(androidSeverity, "chromium-libstagefright",
|
||||
"%s:%d: %s", file, line, str.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static void InitializeNetworkThreadIfNecessary() {
|
||||
Mutex::Autolock autoLock(gNetworkThreadLock);
|
||||
if (gNetworkThread == NULL) {
|
||||
@@ -58,6 +89,7 @@ static void InitializeNetworkThreadIfNecessary() {
|
||||
|
||||
net::AndroidNetworkLibrary::RegisterSharedInstance(
|
||||
new SfNetworkLibrary);
|
||||
logging::SetLogMessageHandler(logMessageHandler);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,6 +213,14 @@ void SfDelegate::setOwner(ChromiumHTTPDataSource *owner) {
|
||||
mOwner = owner;
|
||||
}
|
||||
|
||||
void SfDelegate::setUID(uid_t uid) {
|
||||
gReqContext->setUID(uid);
|
||||
}
|
||||
|
||||
bool SfDelegate::getUID(uid_t *uid) const {
|
||||
return gReqContext->getUID(uid);
|
||||
}
|
||||
|
||||
void SfDelegate::OnReceivedRedirect(
|
||||
net::URLRequest *request, const GURL &new_url, bool *defer_redirect) {
|
||||
MY_LOGV("OnReceivedRedirect");
|
||||
|
||||
@@ -91,6 +91,11 @@ struct SfDelegate : public net::URLRequest::Delegate {
|
||||
|
||||
void setOwner(ChromiumHTTPDataSource *mOwner);
|
||||
|
||||
// Gets the UID of the calling process
|
||||
bool getUID(uid_t *uid) const;
|
||||
|
||||
void setUID(uid_t uid);
|
||||
|
||||
virtual void OnReceivedRedirect(
|
||||
net::URLRequest *request, const GURL &new_url, bool *defer_redirect);
|
||||
|
||||
|
||||
@@ -53,7 +53,8 @@ struct HTTPBase : public DataSource {
|
||||
|
||||
static sp<HTTPBase> Create(uint32_t flags = 0);
|
||||
|
||||
static void RegisterSocketUser(int s, uid_t uid);
|
||||
static void RegisterSocketUserTag(int sockfd, uid_t uid, uint32_t kTag);
|
||||
static void UnRegisterSocketUserTag(int sockfd);
|
||||
|
||||
protected:
|
||||
void addBandwidthMeasurement(size_t numBytes, int64_t delayUs);
|
||||
|
||||
@@ -56,6 +56,9 @@ ARTSPConnection::ARTSPConnection(bool uidValid, uid_t uid)
|
||||
ARTSPConnection::~ARTSPConnection() {
|
||||
if (mSocket >= 0) {
|
||||
LOGE("Connection is still open, closing the socket.");
|
||||
if (mUIDValid) {
|
||||
HTTPBase::UnRegisterSocketUserTag(mSocket);
|
||||
}
|
||||
close(mSocket);
|
||||
mSocket = -1;
|
||||
}
|
||||
@@ -202,6 +205,9 @@ void ARTSPConnection::onConnect(const sp<AMessage> &msg) {
|
||||
++mConnectionID;
|
||||
|
||||
if (mState != DISCONNECTED) {
|
||||
if (mUIDValid) {
|
||||
HTTPBase::UnRegisterSocketUserTag(mSocket);
|
||||
}
|
||||
close(mSocket);
|
||||
mSocket = -1;
|
||||
|
||||
@@ -251,7 +257,8 @@ void ARTSPConnection::onConnect(const sp<AMessage> &msg) {
|
||||
mSocket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
if (mUIDValid) {
|
||||
HTTPBase::RegisterSocketUser(mSocket, mUID);
|
||||
HTTPBase::RegisterSocketUserTag(mSocket, mUID,
|
||||
(uint32_t)*(uint32_t*) "RTSP");
|
||||
}
|
||||
|
||||
MakeSocketBlocking(mSocket, false);
|
||||
@@ -279,6 +286,9 @@ void ARTSPConnection::onConnect(const sp<AMessage> &msg) {
|
||||
reply->setInt32("result", -errno);
|
||||
mState = DISCONNECTED;
|
||||
|
||||
if (mUIDValid) {
|
||||
HTTPBase::UnRegisterSocketUserTag(mSocket);
|
||||
}
|
||||
close(mSocket);
|
||||
mSocket = -1;
|
||||
} else {
|
||||
@@ -294,6 +304,9 @@ void ARTSPConnection::onConnect(const sp<AMessage> &msg) {
|
||||
|
||||
void ARTSPConnection::onDisconnect(const sp<AMessage> &msg) {
|
||||
if (mState == CONNECTED || mState == CONNECTING) {
|
||||
if (mUIDValid) {
|
||||
HTTPBase::UnRegisterSocketUserTag(mSocket);
|
||||
}
|
||||
close(mSocket);
|
||||
mSocket = -1;
|
||||
|
||||
@@ -358,6 +371,9 @@ void ARTSPConnection::onCompleteConnection(const sp<AMessage> &msg) {
|
||||
reply->setInt32("result", -err);
|
||||
|
||||
mState = DISCONNECTED;
|
||||
if (mUIDValid) {
|
||||
HTTPBase::UnRegisterSocketUserTag(mSocket);
|
||||
}
|
||||
close(mSocket);
|
||||
mSocket = -1;
|
||||
} else {
|
||||
|
||||
@@ -545,6 +545,12 @@ struct MyHandler : public AHandler {
|
||||
if (result != OK) {
|
||||
if (track) {
|
||||
if (!track->mUsingInterleavedTCP) {
|
||||
// Clear the tag
|
||||
if (mUIDValid) {
|
||||
HTTPBase::UnRegisterSocketUserTag(track->mRTPSocket);
|
||||
HTTPBase::UnRegisterSocketUserTag(track->mRTCPSocket);
|
||||
}
|
||||
|
||||
close(track->mRTPSocket);
|
||||
close(track->mRTCPSocket);
|
||||
}
|
||||
@@ -618,6 +624,12 @@ struct MyHandler : public AHandler {
|
||||
if (!info->mUsingInterleavedTCP) {
|
||||
mRTPConn->removeStream(info->mRTPSocket, info->mRTCPSocket);
|
||||
|
||||
// Clear the tag
|
||||
if (mUIDValid) {
|
||||
HTTPBase::UnRegisterSocketUserTag(info->mRTPSocket);
|
||||
HTTPBase::UnRegisterSocketUserTag(info->mRTCPSocket);
|
||||
}
|
||||
|
||||
close(info->mRTPSocket);
|
||||
close(info->mRTCPSocket);
|
||||
}
|
||||
@@ -1181,8 +1193,10 @@ private:
|
||||
&info->mRTPSocket, &info->mRTCPSocket, &rtpPort);
|
||||
|
||||
if (mUIDValid) {
|
||||
HTTPBase::RegisterSocketUser(info->mRTPSocket, mUID);
|
||||
HTTPBase::RegisterSocketUser(info->mRTCPSocket, mUID);
|
||||
HTTPBase::RegisterSocketUserTag(info->mRTPSocket, mUID,
|
||||
(uint32_t)*(uint32_t*) "RTP_");
|
||||
HTTPBase::RegisterSocketUserTag(info->mRTCPSocket, mUID,
|
||||
(uint32_t)*(uint32_t*) "RTP_");
|
||||
}
|
||||
|
||||
request.append("Transport: RTP/AVP/UDP;unicast;client_port=");
|
||||
|
||||
Reference in New Issue
Block a user