Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5414a167 authored by Ashish Sharma's avatar Ashish Sharma Committed by Android (Google) Code Review
Browse files

Merge "Network traffic accounting for chromium stack support in mediaserver."

parents 7ad291a5 d5a20d8d
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -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 {
+15 −4
Original line number Diff line number Diff line
@@ -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
+6 −0
Original line number Diff line number Diff line
@@ -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);
}

+40 −0
Original line number Diff line number Diff line
@@ -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");
+5 −0
Original line number Diff line number Diff line
@@ -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);

Loading