Suppress the logging of URLs when in incognito mode.

Change-Id: Ib951b495eae15669e160ef54686eab0eeb9b366a
related-to-bug: 3336575
diff --git a/media/libmediaplayerservice/StagefrightPlayer.cpp b/media/libmediaplayerservice/StagefrightPlayer.cpp
index da564dc..01e8a68 100644
--- a/media/libmediaplayerservice/StagefrightPlayer.cpp
+++ b/media/libmediaplayerservice/StagefrightPlayer.cpp
@@ -33,7 +33,6 @@
 
 status_t StagefrightPlayer::setDataSource(
         const char *url, const KeyedVector<String8, String8> *headers) {
-    LOGI("setDataSource('%s')", url);
     return mPlayer->setDataSource(url, headers);
 }
 
diff --git a/media/libmediaplayerservice/nuplayer/HTTPLiveSource.cpp b/media/libmediaplayerservice/nuplayer/HTTPLiveSource.cpp
index 6bf6dd3..b3314be 100644
--- a/media/libmediaplayerservice/nuplayer/HTTPLiveSource.cpp
+++ b/media/libmediaplayerservice/nuplayer/HTTPLiveSource.cpp
@@ -33,8 +33,9 @@
 
 namespace android {
 
-NuPlayer::HTTPLiveSource::HTTPLiveSource(const char *url)
+NuPlayer::HTTPLiveSource::HTTPLiveSource(const char *url, uint32_t flags)
     : mURL(url),
+      mFlags(flags),
       mEOS(false),
       mOffset(0) {
 }
@@ -49,7 +50,9 @@
     mLiveLooper->setName("http live");
     mLiveLooper->start();
 
-    mLiveSession = new LiveSession;
+    mLiveSession = new LiveSession(
+            (mFlags & kFlagIncognito) ? LiveSession::kFlagIncognito : 0);
+
     mLiveLooper->registerHandler(mLiveSession);
 
     mLiveSession->connect(mURL.c_str());
diff --git a/media/libmediaplayerservice/nuplayer/HTTPLiveSource.h b/media/libmediaplayerservice/nuplayer/HTTPLiveSource.h
index f3f539a..a8ce7f4 100644
--- a/media/libmediaplayerservice/nuplayer/HTTPLiveSource.h
+++ b/media/libmediaplayerservice/nuplayer/HTTPLiveSource.h
@@ -27,7 +27,11 @@
 struct LiveSession;
 
 struct NuPlayer::HTTPLiveSource : public NuPlayer::Source {
-    HTTPLiveSource(const char *url);
+    enum Flags {
+        // Don't log any URLs.
+        kFlagIncognito = 1,
+    };
+    HTTPLiveSource(const char *url, uint32_t flags = 0);
 
     virtual void start();
 
@@ -46,6 +50,7 @@
 
 private:
     AString mURL;
+    uint32_t mFlags;
     bool mEOS;
     off64_t mOffset;
     sp<ALooper> mLiveLooper;
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
index 1fcf92b..fb87d82 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
@@ -71,7 +71,17 @@
         const char *url, const KeyedVector<String8, String8> *headers) {
     sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
 
-    msg->setObject("source", new HTTPLiveSource(url));
+    uint32_t flags = 0;
+
+    if (headers) {
+        ssize_t index = headers->indexOfKey(String8("x-hide-urls-from-log"));
+
+        if (index >= 0) {
+            flags |= HTTPLiveSource::kFlagIncognito;
+        }
+    }
+
+    msg->setObject("source", new HTTPLiveSource(url, flags));
     msg->post();
 }
 
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 1b63ab2..45be459 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -245,6 +245,22 @@
 
     if (headers) {
         mUriHeaders = *headers;
+
+        ssize_t index = mUriHeaders.indexOfKey(String8("x-hide-urls-from-log"));
+        if (index >= 0) {
+            // Browser is in "incognito" mode, suppress logging URLs.
+
+            // This isn't something that should be passed to the server.
+            mUriHeaders.removeItemsAt(index);
+
+            mFlags |= INCOGNITO;
+        }
+    }
+
+    if (!(mFlags & INCOGNITO)) {
+        LOGI("setDataSource_l('%s')", mUri.string());
+    } else {
+        LOGI("setDataSource_l(URL suppressed)");
     }
 
     // The actual work will be done during preparation in the call to
@@ -1525,7 +1541,8 @@
 
     if (!strncasecmp("http://", mUri.string(), 7)
             || !strncasecmp("https://", mUri.string(), 8)) {
-        mConnectingDataSource = new NuHTTPDataSource;
+        mConnectingDataSource = new NuHTTPDataSource(
+                (mFlags & INCOGNITO) ? NuHTTPDataSource::kFlagIncognito : 0);
 
         mLock.unlock();
         status_t err = mConnectingDataSource->connect(mUri, &mUriHeaders);
diff --git a/media/libstagefright/NuHTTPDataSource.cpp b/media/libstagefright/NuHTTPDataSource.cpp
index e39fab3..dbbf3b4 100644
--- a/media/libstagefright/NuHTTPDataSource.cpp
+++ b/media/libstagefright/NuHTTPDataSource.cpp
@@ -71,8 +71,9 @@
     return true;
 }
 
-NuHTTPDataSource::NuHTTPDataSource()
-    : mState(DISCONNECTED),
+NuHTTPDataSource::NuHTTPDataSource(uint32_t flags)
+    : mFlags(flags),
+      mState(DISCONNECTED),
       mPort(0),
       mHTTPS(false),
       mOffset(0),
@@ -138,7 +139,11 @@
         bool https,
         const String8 &headers,
         off64_t offset) {
-    LOGI("connect to %s:%u%s @%lld", host, port, path, offset);
+    if (!(mFlags & kFlagIncognito)) {
+        LOGI("connect to %s:%u%s @%lld", host, port, path, offset);
+    } else {
+        LOGI("connect to <URL suppressed> @%lld", offset);
+    }
 
     bool needsToReconnect = true;
 
diff --git a/media/libstagefright/httplive/LiveSession.cpp b/media/libstagefright/httplive/LiveSession.cpp
index ee845a3..f0cd6a0 100644
--- a/media/libstagefright/httplive/LiveSession.cpp
+++ b/media/libstagefright/httplive/LiveSession.cpp
@@ -41,9 +41,14 @@
 
 const int64_t LiveSession::kMaxPlaylistAgeUs = 15000000ll;
 
-LiveSession::LiveSession()
-    : mDataSource(new LiveDataSource),
-      mHTTPDataSource(new NuHTTPDataSource),
+LiveSession::LiveSession(uint32_t flags)
+    : mFlags(flags),
+      mDataSource(new LiveDataSource),
+      mHTTPDataSource(
+              new NuHTTPDataSource(
+                  (mFlags & kFlagIncognito)
+                    ? NuHTTPDataSource::kFlagIncognito
+                    : 0)),
       mPrevBandwidthIndex(-1),
       mLastPlaylistFetchTimeUs(-1),
       mSeqNumber(-1),
@@ -139,7 +144,11 @@
     AString url;
     CHECK(msg->findString("url", &url));
 
-    LOGI("onConnect '%s'", url.c_str());
+    if (!(mFlags & kFlagIncognito)) {
+        LOGI("onConnect '%s'", url.c_str());
+    } else {
+        LOGI("onConnect <URL suppressed>");
+    }
 
     mMasterURL = url;
 
diff --git a/media/libstagefright/include/AwesomePlayer.h b/media/libstagefright/include/AwesomePlayer.h
index 1497732..ab2327c 100644
--- a/media/libstagefright/include/AwesomePlayer.h
+++ b/media/libstagefright/include/AwesomePlayer.h
@@ -122,6 +122,8 @@
 
         AUDIO_RUNNING       = 8192,
         AUDIOPLAYER_STARTED = 16384,
+
+        INCOGNITO           = 32768,
     };
 
     mutable Mutex mLock;
diff --git a/media/libstagefright/include/LiveSession.h b/media/libstagefright/include/LiveSession.h
index f1188c4..3fe5d4e 100644
--- a/media/libstagefright/include/LiveSession.h
+++ b/media/libstagefright/include/LiveSession.h
@@ -29,7 +29,11 @@
 struct NuHTTPDataSource;
 
 struct LiveSession : public AHandler {
-    LiveSession();
+    enum Flags {
+        // Don't log any URLs.
+        kFlagIncognito = 1,
+    };
+    LiveSession(uint32_t flags = 0);
 
     sp<DataSource> getDataSource();
 
@@ -67,6 +71,8 @@
         unsigned long mBandwidth;
     };
 
+    uint32_t mFlags;
+
     sp<LiveDataSource> mDataSource;
 
     sp<NuHTTPDataSource> mHTTPDataSource;
diff --git a/media/libstagefright/include/NuHTTPDataSource.h b/media/libstagefright/include/NuHTTPDataSource.h
index 3918434..082b589 100644
--- a/media/libstagefright/include/NuHTTPDataSource.h
+++ b/media/libstagefright/include/NuHTTPDataSource.h
@@ -12,7 +12,11 @@
 namespace android {
 
 struct NuHTTPDataSource : public DataSource {
-    NuHTTPDataSource();
+    enum Flags {
+        // Don't log any URLs.
+        kFlagIncognito = 1
+    };
+    NuHTTPDataSource(uint32_t flags = 0);
 
     status_t connect(
             const char *uri,
@@ -52,6 +56,8 @@
 
     Mutex mLock;
 
+    uint32_t mFlags;
+
     State mState;
 
     String8 mHost;