Remove dependency on libandroidglue from https
Bug: 141887532
Test: build
Change-Id: I086262dc4bf086042165ecf859321e3e29e5c863
diff --git a/host/frontend/gcastv2/https/Android.bp b/host/frontend/gcastv2/https/Android.bp
index 47b3783..e410f77 100644
--- a/host/frontend/gcastv2/https/Android.bp
+++ b/host/frontend/gcastv2/https/Android.bp
@@ -16,13 +16,14 @@
"Support.cpp",
],
defaults: ["cuttlefish_host_only"],
- static_libs: [
- "libandroidglue",
+ header_libs: [
+ "cuttlefish_glog",
],
shared_libs: [
"libbase",
"libcrypto",
"libssl",
+ "liblog",
],
local_include_dirs: ["include"],
export_include_dirs: ["include"],
diff --git a/host/frontend/gcastv2/https/BaseConnection.cpp b/host/frontend/gcastv2/https/BaseConnection.cpp
index be13213..610fb5f 100644
--- a/host/frontend/gcastv2/https/BaseConnection.cpp
+++ b/host/frontend/gcastv2/https/BaseConnection.cpp
@@ -3,9 +3,6 @@
#include <https/SafeCallbackable.h>
#include <https/PlainSocket.h>
-#include <media/stagefright/foundation/ADebug.h>
-#include <media/stagefright/foundation/hexdump.h>
-
BaseConnection::BaseConnection(std::shared_ptr<RunLoop> runLoop, int sock)
: mRunLoop(runLoop),
mSocket(std::make_unique<PlainSocket>(mRunLoop, sock)),
diff --git a/host/frontend/gcastv2/https/BufferedSocket.cpp b/host/frontend/gcastv2/https/BufferedSocket.cpp
index 6257bd6..117fc35 100644
--- a/host/frontend/gcastv2/https/BufferedSocket.cpp
+++ b/host/frontend/gcastv2/https/BufferedSocket.cpp
@@ -1,7 +1,6 @@
#include <https/BufferedSocket.h>
#include <cassert>
-#include <sys/socket.h>
#include <unistd.h>
BufferedSocket::BufferedSocket(std::shared_ptr<RunLoop> rl, int sock)
diff --git a/host/frontend/gcastv2/https/ClientSocket.cpp b/host/frontend/gcastv2/https/ClientSocket.cpp
index 9e095a5..3b6623d 100644
--- a/host/frontend/gcastv2/https/ClientSocket.cpp
+++ b/host/frontend/gcastv2/https/ClientSocket.cpp
@@ -5,7 +5,7 @@
#include <https/SafeCallbackable.h>
#include <https/ServerSocket.h>
-#include <media/stagefright/foundation/ADebug.h>
+#include <glog/logging.h>
#include <cstdlib>
diff --git a/host/frontend/gcastv2/https/HTTPClientConnection.cpp b/host/frontend/gcastv2/https/HTTPClientConnection.cpp
index 9b3a68a..d589734 100644
--- a/host/frontend/gcastv2/https/HTTPClientConnection.cpp
+++ b/host/frontend/gcastv2/https/HTTPClientConnection.cpp
@@ -8,8 +8,7 @@
#include <https/Support.h>
-#include <media/stagefright/foundation/ADebug.h>
-#include <media/stagefright/foundation/JSONObject.h>
+#include <glog/logging.h>
#include <arpa/inet.h>
#include <cerrno>
@@ -207,12 +206,7 @@
queueOutputData(data, size);
});
- using android::sp;
- using android::JSONObject;
- sp<JSONObject> jsonRequest = new JSONObject;
- jsonRequest->setString("message", "Hello, world!");
-
- const std::string msg = jsonRequest->toString();
+ const std::string msg = "\"message\":\"Hellow, world!\"";
mWebSocketHandler->sendMessage(msg.c_str(), msg.size());
return false;
diff --git a/host/frontend/gcastv2/https/HTTPServer.cpp b/host/frontend/gcastv2/https/HTTPServer.cpp
index 4dd2e98..6c59d18 100644
--- a/host/frontend/gcastv2/https/HTTPServer.cpp
+++ b/host/frontend/gcastv2/https/HTTPServer.cpp
@@ -4,7 +4,7 @@
#include <https/HTTPRequestResponse.h>
#include <https/Support.h>
-#include <media/stagefright/foundation/base64.h>
+#include <glog/logging.h>
#include <iostream>
#include <map>
@@ -282,7 +282,7 @@
CHECK_EQ(res, 1);
std::string acceptKey;
- android::encodeBase64(digest, sizeof(digest), &acceptKey);
+ encodeBase64(digest, sizeof(digest), &acceptKey);
(*responseHeaders)["Sec-WebSocket-Accept"] = acceptKey;
diff --git a/host/frontend/gcastv2/https/RunLoop.cpp b/host/frontend/gcastv2/https/RunLoop.cpp
index 4b4cbe6..aec8275 100644
--- a/host/frontend/gcastv2/https/RunLoop.cpp
+++ b/host/frontend/gcastv2/https/RunLoop.cpp
@@ -2,7 +2,7 @@
#include <https/Support.h>
-#include <media/stagefright/foundation/ADebug.h>
+#include <glog/logging.h>
#include <cstring>
#include <fcntl.h>
diff --git a/host/frontend/gcastv2/https/SSLSocket.cpp b/host/frontend/gcastv2/https/SSLSocket.cpp
index 49e4193..99c6070 100644
--- a/host/frontend/gcastv2/https/SSLSocket.cpp
+++ b/host/frontend/gcastv2/https/SSLSocket.cpp
@@ -2,10 +2,11 @@
#include <https/SafeCallbackable.h>
#include <https/Support.h>
-#include <media/stagefright/foundation/ADebug.h>
+#include <glog/logging.h>
#include <sstream>
#include <sys/socket.h>
-#include <utils/KeyStore.h>
+
+#define TRESPASS() LOG(FATAL) << "Should not be here."
// static
void SSLSocket::Init() {
diff --git a/host/frontend/gcastv2/https/ServerSocket.cpp b/host/frontend/gcastv2/https/ServerSocket.cpp
index 039e651..08774b0 100644
--- a/host/frontend/gcastv2/https/ServerSocket.cpp
+++ b/host/frontend/gcastv2/https/ServerSocket.cpp
@@ -5,7 +5,7 @@
#include <https/SafeCallbackable.h>
#include <https/Support.h>
-#include <media/stagefright/foundation/ADebug.h>
+#include <glog/logging.h>
#include <arpa/inet.h>
#include <fcntl.h>
diff --git a/host/frontend/gcastv2/https/Support.cpp b/host/frontend/gcastv2/https/Support.cpp
index 72fd098..994ae81 100644
--- a/host/frontend/gcastv2/https/Support.cpp
+++ b/host/frontend/gcastv2/https/Support.cpp
@@ -48,3 +48,50 @@
offset += 16;
}
}
+
+static char encode6Bit(unsigned x) {
+ static char base64[] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+ return base64[x & 63];
+}
+
+void encodeBase64(const void *_data, size_t size, std::string *out) {
+ out->clear();
+ out->reserve(((size+2)/3)*4);
+
+ const uint8_t *data = (const uint8_t *)_data;
+
+ size_t i;
+ for (i = 0; i < (size / 3) * 3; i += 3) {
+ uint8_t x1 = data[i];
+ uint8_t x2 = data[i + 1];
+ uint8_t x3 = data[i + 2];
+
+ out->append(1, encode6Bit(x1 >> 2));
+ out->append(1, encode6Bit((x1 << 4 | x2 >> 4) & 0x3f));
+ out->append(1, encode6Bit((x2 << 2 | x3 >> 6) & 0x3f));
+ out->append(1, encode6Bit(x3 & 0x3f));
+ }
+ switch (size % 3) {
+ case 0:
+ break;
+ case 2:
+ {
+ uint8_t x1 = data[i];
+ uint8_t x2 = data[i + 1];
+ out->append(1, encode6Bit(x1 >> 2));
+ out->append(1, encode6Bit((x1 << 4 | x2 >> 4) & 0x3f));
+ out->append(1, encode6Bit((x2 << 2) & 0x3f));
+ out->append(1, '=');
+ break;
+ }
+ default:
+ {
+ uint8_t x1 = data[i];
+ out->append(1, encode6Bit(x1 >> 2));
+ out->append(1, encode6Bit((x1 << 4) & 0x3f));
+ out->append("==");
+ break;
+ }
+ }
+}
diff --git a/host/frontend/gcastv2/https/WebSocketHandler.cpp b/host/frontend/gcastv2/https/WebSocketHandler.cpp
index 8fe13f3..91ed207 100644
--- a/host/frontend/gcastv2/https/WebSocketHandler.cpp
+++ b/host/frontend/gcastv2/https/WebSocketHandler.cpp
@@ -4,9 +4,21 @@
#include <https/Support.h>
#include <iostream>
-#include <media/stagefright/Utils.h>
#include <sstream>
+// TODO (jemoreira): this is duplicated from libandroid, fix!!!
+static uint16_t U16_AT(const uint8_t *ptr) {
+ return ptr[0] << 8 | ptr[1];
+}
+
+static uint32_t U32_AT(const uint8_t *ptr) {
+ return ptr[0] << 24 | ptr[1] << 16 | ptr[2] << 8 | ptr[3];
+}
+
+static uint64_t U64_AT(const uint8_t *ptr) {
+ return ((uint64_t)U32_AT(ptr)) << 32 | U32_AT(ptr + 4);
+}
+
ssize_t WebSocketHandler::handleRequest(
uint8_t *data, size_t size, bool isEOS) {
(void)isEOS;
@@ -28,14 +40,14 @@
break;
}
- payloadLen = android::U16_AT(&packet[packetOffset]);
+ payloadLen = U16_AT(&packet[packetOffset]);
packetOffset += 2;
} else if (payloadLen == 127) {
if (packetOffset + 7 >= avail) {
break;
}
- payloadLen = android::U64_AT(&packet[packetOffset]);
+ payloadLen = U64_AT(&packet[packetOffset]);
packetOffset += 8;
}
@@ -45,7 +57,7 @@
break;
}
- mask = android::U32_AT(&packet[packetOffset]);
+ mask = U32_AT(&packet[packetOffset]);
packetOffset += 4;
}
diff --git a/host/frontend/gcastv2/https/include/https/Support.h b/host/frontend/gcastv2/https/include/https/Support.h
index 54892a6..16712cd 100644
--- a/host/frontend/gcastv2/https/include/https/Support.h
+++ b/host/frontend/gcastv2/https/include/https/Support.h
@@ -2,6 +2,8 @@
#include <sys/types.h>
+#include <string>
+
#ifdef NDEBUG
#define DEBUG_ONLY(x)
#else
@@ -11,3 +13,4 @@
void makeFdNonblocking(int fd);
void hexdump(const void *_data, size_t size);
+void encodeBase64(const void *_data, size_t size, std::string *out);