Merge "Binder: Split OS to Android and Unix part, abstract GetThreadId out" into main
diff --git a/libs/binder/RpcServer.cpp b/libs/binder/RpcServer.cpp
index 354a4b3..db31737 100644
--- a/libs/binder/RpcServer.cpp
+++ b/libs/binder/RpcServer.cpp
@@ -24,7 +24,6 @@
#include <thread>
#include <vector>
-#include <android-base/hex.h>
#include <android-base/scopeguard.h>
#include <binder/Parcel.h>
#include <binder/RpcServer.h>
@@ -484,7 +483,7 @@
// don't block if there is some entropy issue
if (tries++ > 5) {
ALOGE("Cannot find new address: %s",
- base::HexString(sessionId.data(), sessionId.size()).c_str());
+ HexString(sessionId.data(), sessionId.size()).c_str());
return;
}
@@ -536,7 +535,7 @@
auto it = server->mSessions.find(sessionId);
if (it == server->mSessions.end()) {
ALOGE("Cannot add thread, no record of session with ID %s",
- base::HexString(sessionId.data(), sessionId.size()).c_str());
+ HexString(sessionId.data(), sessionId.size()).c_str());
return;
}
session = it->second;
@@ -610,15 +609,14 @@
void RpcServer::onSessionAllIncomingThreadsEnded(const sp<RpcSession>& session) {
const std::vector<uint8_t>& id = session->mId;
LOG_ALWAYS_FATAL_IF(id.empty(), "Server sessions must be initialized with ID");
- LOG_RPC_DETAIL("Dropping session with address %s",
- base::HexString(id.data(), id.size()).c_str());
+ LOG_RPC_DETAIL("Dropping session with address %s", HexString(id.data(), id.size()).c_str());
RpcMutexLockGuard _l(mLock);
auto it = mSessions.find(id);
LOG_ALWAYS_FATAL_IF(it == mSessions.end(), "Bad state, unknown session id %s",
- base::HexString(id.data(), id.size()).c_str());
+ HexString(id.data(), id.size()).c_str());
LOG_ALWAYS_FATAL_IF(it->second != session, "Bad state, session has id mismatch %s",
- base::HexString(id.data(), id.size()).c_str());
+ HexString(id.data(), id.size()).c_str());
(void)mSessions.erase(it);
}
diff --git a/libs/binder/RpcSession.cpp b/libs/binder/RpcSession.cpp
index 679b194..fa8f2b5 100644
--- a/libs/binder/RpcSession.cpp
+++ b/libs/binder/RpcSession.cpp
@@ -26,7 +26,6 @@
#include <string_view>
-#include <android-base/hex.h>
#include <android-base/macros.h>
#include <android-base/scopeguard.h>
#include <binder/BpBinder.h>
@@ -310,8 +309,7 @@
status = state()->getSessionId(connection.get(), sp<RpcSession>::fromExisting(this), &mId);
if (status != OK) return status;
- LOG_RPC_DETAIL("RpcSession %p has id %s", this,
- base::HexString(mId.data(), mId.size()).c_str());
+ LOG_RPC_DETAIL("RpcSession %p has id %s", this, HexString(mId.data(), mId.size()).c_str());
return OK;
}
@@ -709,7 +707,7 @@
std::nullopt, nullptr);
if (sendSessionIdStatus != OK) {
ALOGE("Could not write session ID ('%s') to socket: %s",
- base::HexString(sessionId.data(), sessionId.size()).c_str(),
+ HexString(sessionId.data(), sessionId.size()).c_str(),
statusToString(sendSessionIdStatus).c_str());
return sendSessionIdStatus;
}
diff --git a/libs/binder/RpcState.cpp b/libs/binder/RpcState.cpp
index bac2808..cf14bce 100644
--- a/libs/binder/RpcState.cpp
+++ b/libs/binder/RpcState.cpp
@@ -18,7 +18,6 @@
#include "RpcState.h"
-#include <android-base/hex.h>
#include <android-base/macros.h>
#include <android-base/scopeguard.h>
#include <android-base/stringprintf.h>
@@ -363,7 +362,7 @@
for (int i = 0; i < niovs; i++) {
LOG_RPC_DETAIL("Sending %s (part %d of %d) on RpcTransport %p: %s",
what, i + 1, niovs, connection->rpcTransport.get(),
- android::base::HexString(iovs[i].iov_base, iovs[i].iov_len).c_str());
+ HexString(iovs[i].iov_base, iovs[i].iov_len).c_str());
}
if (status_t status =
@@ -398,7 +397,7 @@
for (int i = 0; i < niovs; i++) {
LOG_RPC_DETAIL("Received %s (part %d of %d) on RpcTransport %p: %s",
what, i + 1, niovs, connection->rpcTransport.get(),
- android::base::HexString(iovs[i].iov_base, iovs[i].iov_len).c_str());
+ HexString(iovs[i].iov_base, iovs[i].iov_len).c_str());
}
return OK;
}
diff --git a/libs/binder/Utils.cpp b/libs/binder/Utils.cpp
index 0314b0f..47fd17d 100644
--- a/libs/binder/Utils.cpp
+++ b/libs/binder/Utils.cpp
@@ -16,6 +16,7 @@
#include "Utils.h"
+#include <android-base/logging.h>
#include <string.h>
namespace android {
@@ -24,4 +25,22 @@
memset(data, 0, size);
}
+std::string HexString(const void* bytes, size_t len) {
+ CHECK(bytes != nullptr || len == 0) << bytes << " " << len;
+
+ // b/132916539: Doing this the 'C way', std::setfill triggers ubsan implicit conversion
+ const uint8_t* bytes8 = static_cast<const uint8_t*>(bytes);
+ const char chars[] = "0123456789abcdef";
+ std::string result;
+ result.resize(len * 2);
+
+ for (size_t i = 0; i < len; i++) {
+ const auto c = bytes8[i];
+ result[2 * i] = chars[c >> 4];
+ result[2 * i + 1] = chars[c & 0xf];
+ }
+
+ return result;
+}
+
} // namespace android
diff --git a/libs/binder/Utils.h b/libs/binder/Utils.h
index e04199c..dd632c0 100644
--- a/libs/binder/Utils.h
+++ b/libs/binder/Utils.h
@@ -70,4 +70,10 @@
}
};
+// Converts binary data into a hexString.
+//
+// Hex values are printed in order, e.g. 0xDEAD will result in 'adde' because
+// Android is little-endian.
+std::string HexString(const void* bytes, size_t len);
+
} // namespace android
diff --git a/libs/binder/include/binder/Parcel.h b/libs/binder/include/binder/Parcel.h
index 45e5ace..b94267c 100644
--- a/libs/binder/include/binder/Parcel.h
+++ b/libs/binder/include/binder/Parcel.h
@@ -1289,6 +1289,7 @@
// Fields only needed when parcelling for "kernel Binder".
struct KernelFields {
+ KernelFields() {}
binder_size_t* mObjects = nullptr;
size_t mObjectsSize = 0;
size_t mObjectsCapacity = 0;
diff --git a/libs/binder/tests/binderClearBufTest.cpp b/libs/binder/tests/binderClearBufTest.cpp
index 3ea5b55..e43ee5f 100644
--- a/libs/binder/tests/binderClearBufTest.cpp
+++ b/libs/binder/tests/binderClearBufTest.cpp
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-#include <android-base/hex.h>
#include <android-base/logging.h>
#include <binder/Binder.h>
#include <binder/IBinder.h>
@@ -24,6 +23,8 @@
#include <binder/Stability.h>
#include <gtest/gtest.h>
+#include "../Utils.h"
+
#include <sys/prctl.h>
#include <thread>
@@ -68,7 +69,7 @@
lastReply = reply.data();
lastReplySize = reply.dataSize();
}
- *outBuffer = android::base::HexString(lastReply, lastReplySize);
+ *outBuffer = android::HexString(lastReply, lastReplySize);
return result;
}
};
diff --git a/libs/binder/tests/binderRpcWireProtocolTest.cpp b/libs/binder/tests/binderRpcWireProtocolTest.cpp
index 642cea4..d0ce37d 100644
--- a/libs/binder/tests/binderRpcWireProtocolTest.cpp
+++ b/libs/binder/tests/binderRpcWireProtocolTest.cpp
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-#include <android-base/hex.h>
#include <android-base/logging.h>
#include <android-base/macros.h>
#include <android-base/properties.h>
@@ -25,6 +24,7 @@
#include <gtest/gtest.h>
#include "../Debug.h"
+#include "../Utils.h"
namespace android {
@@ -176,7 +176,7 @@
setParcelForRpc(&p, version);
kFillFuns[i](&p);
- result += base::HexString(p.data(), p.dataSize());
+ result += HexString(p.data(), p.dataSize());
}
return result;
}
diff --git a/libs/binder/tests/parcel_fuzzer/binder.cpp b/libs/binder/tests/parcel_fuzzer/binder.cpp
index 46d387c..416ffad 100644
--- a/libs/binder/tests/parcel_fuzzer/binder.cpp
+++ b/libs/binder/tests/parcel_fuzzer/binder.cpp
@@ -21,14 +21,15 @@
#include "parcelables/SingleDataParcelable.h"
#include "util.h"
-#include <android-base/hex.h>
#include <android/os/IServiceManager.h>
#include <binder/ParcelableHolder.h>
#include <binder/PersistableBundle.h>
#include <binder/Status.h>
+#include "../../Utils.h"
+
using ::android::status_t;
-using ::android::base::HexString;
+using ::android::HexString;
enum ByteEnum : int8_t {};
enum IntEnum : int32_t {};
diff --git a/libs/binder/tests/parcel_fuzzer/hwbinder.cpp b/libs/binder/tests/parcel_fuzzer/hwbinder.cpp
index 438e8ae..cdc8bcc 100644
--- a/libs/binder/tests/parcel_fuzzer/hwbinder.cpp
+++ b/libs/binder/tests/parcel_fuzzer/hwbinder.cpp
@@ -18,12 +18,13 @@
#include "hwbinder.h"
#include "util.h"
-#include <android-base/hex.h>
#include <android-base/logging.h>
#include <hwbinder/Parcel.h>
+#include "../../Utils.h"
+
using ::android::status_t;
-using ::android::base::HexString;
+using ::android::HexString;
// TODO: support scatter-gather types
diff --git a/libs/binder/tests/parcel_fuzzer/include_random_parcel_seeds/fuzzseeds/random_parcel_seeds.h b/libs/binder/tests/parcel_fuzzer/include_random_parcel_seeds/fuzzseeds/random_parcel_seeds.h
index 5755239..071250d 100644
--- a/libs/binder/tests/parcel_fuzzer/include_random_parcel_seeds/fuzzseeds/random_parcel_seeds.h
+++ b/libs/binder/tests/parcel_fuzzer/include_random_parcel_seeds/fuzzseeds/random_parcel_seeds.h
@@ -15,7 +15,6 @@
*/
#include <android-base/file.h>
-#include <android-base/hex.h>
#include <android-base/logging.h>
#include <binder/Binder.h>
@@ -27,7 +26,6 @@
#include <vector>
using android::Parcel;
-using android::base::HexString;
using std::vector;
namespace android {
diff --git a/libs/binder/tests/parcel_fuzzer/main.cpp b/libs/binder/tests/parcel_fuzzer/main.cpp
index bef4ab6..5b1e9ea 100644
--- a/libs/binder/tests/parcel_fuzzer/main.cpp
+++ b/libs/binder/tests/parcel_fuzzer/main.cpp
@@ -22,7 +22,6 @@
#include <iostream>
-#include <android-base/hex.h>
#include <android-base/logging.h>
#include <android/binder_auto_utils.h>
#include <android/binder_libbinder.h>
@@ -34,10 +33,12 @@
#include <sys/resource.h>
#include <sys/time.h>
+#include "../../Utils.h"
+
using android::fillRandomParcel;
using android::RandomParcelOptions;
using android::sp;
-using android::base::HexString;
+using android::HexString;
void fillRandomParcel(::android::hardware::Parcel* p, FuzzedDataProvider&& provider,
RandomParcelOptions* options) {
diff --git a/libs/binder/trusty/kernel/rules.mk b/libs/binder/trusty/kernel/rules.mk
index ab7a50d..f6e894c 100644
--- a/libs/binder/trusty/kernel/rules.mk
+++ b/libs/binder/trusty/kernel/rules.mk
@@ -37,22 +37,15 @@
$(LIBBINDER_DIR)/Utils.cpp \
$(LIBBASE_DIR)/hex.cpp \
$(LIBBASE_DIR)/stringprintf.cpp \
- $(LIBUTILS_DIR)/Errors.cpp \
+ $(LIBUTILS_DIR)/binder/Errors.cpp \
+ $(LIBUTILS_DIR)/binder/RefBase.cpp \
+ $(LIBUTILS_DIR)/binder/SharedBuffer.cpp \
+ $(LIBUTILS_DIR)/binder/String16.cpp \
+ $(LIBUTILS_DIR)/binder/String8.cpp \
+ $(LIBUTILS_DIR)/binder/StrongPointer.cpp \
+ $(LIBUTILS_DIR)/binder/Unicode.cpp \
+ $(LIBUTILS_DIR)/binder/VectorImpl.cpp \
$(LIBUTILS_DIR)/misc.cpp \
- $(LIBUTILS_DIR)/RefBase.cpp \
- $(LIBUTILS_DIR)/StrongPointer.cpp \
- $(LIBUTILS_DIR)/Unicode.cpp \
-
-# TODO: remove the following when libbinder supports std::string
-# instead of String16 and String8 for Status and descriptors
-MODULE_SRCS += \
- $(LIBUTILS_DIR)/SharedBuffer.cpp \
- $(LIBUTILS_DIR)/String16.cpp \
- $(LIBUTILS_DIR)/String8.cpp \
-
-# TODO: disable dump() transactions to get rid of Vector
-MODULE_SRCS += \
- $(LIBUTILS_DIR)/VectorImpl.cpp \
MODULE_DEFINES += \
LK_DEBUGLEVEL_NO_ALIASES=1 \
diff --git a/libs/binder/trusty/rules.mk b/libs/binder/trusty/rules.mk
index c916670..2e56cbd 100644
--- a/libs/binder/trusty/rules.mk
+++ b/libs/binder/trusty/rules.mk
@@ -46,22 +46,15 @@
$(LIBBINDER_DIR)/Utils.cpp \
$(LIBBASE_DIR)/hex.cpp \
$(LIBBASE_DIR)/stringprintf.cpp \
- $(LIBUTILS_DIR)/Errors.cpp \
+ $(LIBUTILS_DIR)/binder/Errors.cpp \
+ $(LIBUTILS_DIR)/binder/RefBase.cpp \
+ $(LIBUTILS_DIR)/binder/SharedBuffer.cpp \
+ $(LIBUTILS_DIR)/binder/String16.cpp \
+ $(LIBUTILS_DIR)/binder/String8.cpp \
+ $(LIBUTILS_DIR)/binder/StrongPointer.cpp \
+ $(LIBUTILS_DIR)/binder/Unicode.cpp \
+ $(LIBUTILS_DIR)/binder/VectorImpl.cpp \
$(LIBUTILS_DIR)/misc.cpp \
- $(LIBUTILS_DIR)/RefBase.cpp \
- $(LIBUTILS_DIR)/StrongPointer.cpp \
- $(LIBUTILS_DIR)/Unicode.cpp \
-
-# TODO: remove the following when libbinder supports std::string
-# instead of String16 and String8 for Status and descriptors
-MODULE_SRCS += \
- $(LIBUTILS_DIR)/SharedBuffer.cpp \
- $(LIBUTILS_DIR)/String16.cpp \
- $(LIBUTILS_DIR)/String8.cpp \
-
-# TODO: disable dump() transactions to get rid of Vector
-MODULE_SRCS += \
- $(LIBUTILS_DIR)/VectorImpl.cpp \
MODULE_EXPORT_INCLUDES += \
$(LOCAL_DIR)/include \
diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp
index 16315ed..1a638c1 100644
--- a/libs/graphicsenv/GraphicsEnv.cpp
+++ b/libs/graphicsenv/GraphicsEnv.cpp
@@ -160,8 +160,8 @@
return appDebuggable || platformDebuggable;
}
-void GraphicsEnv::setDriverPathAndSphalLibraries(const std::string path,
- const std::string sphalLibraries) {
+void GraphicsEnv::setDriverPathAndSphalLibraries(const std::string& path,
+ const std::string& sphalLibraries) {
if (!mDriverPath.empty() || !mSphalLibraries.empty()) {
ALOGV("ignoring attempt to change driver path from '%s' to '%s' or change sphal libraries "
"from '%s' to '%s'",
@@ -410,55 +410,24 @@
return true;
}
-void* GraphicsEnv::loadLibrary(std::string name) {
- const android_dlextinfo dlextinfo = {
- .flags = ANDROID_DLEXT_USE_NAMESPACE,
- .library_namespace = getAngleNamespace(),
- };
-
- std::string libName = std::string("lib") + name + "_angle.so";
-
- void* so = android_dlopen_ext(libName.c_str(), RTLD_LOCAL | RTLD_NOW, &dlextinfo);
-
- if (so) {
- ALOGD("dlopen_ext from APK (%s) success at %p", libName.c_str(), so);
- return so;
- } else {
- ALOGE("dlopen_ext(\"%s\") failed: %s", libName.c_str(), dlerror());
- }
-
- return nullptr;
-}
-
-bool GraphicsEnv::shouldUseAngle(std::string appName) {
- if (appName != mAngleAppName) {
- // Make sure we are checking the app we were init'ed for
- ALOGE("App name does not match: expected '%s', got '%s'", mAngleAppName.c_str(),
- appName.c_str());
- return false;
- }
-
- return shouldUseAngle();
-}
-
bool GraphicsEnv::shouldUseAngle() {
// Make sure we are init'ed
- if (mAngleAppName.empty()) {
- ALOGV("App name is empty. setAngleInfo() has not been called to enable ANGLE.");
+ if (mPackageName.empty()) {
+ ALOGV("Package name is empty. setAngleInfo() has not been called to enable ANGLE.");
return false;
}
- return (mUseAngle == YES) ? true : false;
+ return (mShouldUseAngle == YES) ? true : false;
}
-void GraphicsEnv::updateUseAngle() {
+void GraphicsEnv::updateShouldUseAngle() {
const char* ANGLE_PREFER_ANGLE = "angle";
const char* ANGLE_PREFER_NATIVE = "native";
- mUseAngle = NO;
+ mShouldUseAngle = NO;
if (mAngleDeveloperOptIn == ANGLE_PREFER_ANGLE) {
ALOGV("User set \"Developer Options\" to force the use of ANGLE");
- mUseAngle = YES;
+ mShouldUseAngle = YES;
} else if (mAngleDeveloperOptIn == ANGLE_PREFER_NATIVE) {
ALOGV("User set \"Developer Options\" to force the use of Native");
} else {
@@ -466,13 +435,13 @@
}
}
-void GraphicsEnv::setAngleInfo(const std::string path, const std::string appName,
- const std::string developerOptIn,
+void GraphicsEnv::setAngleInfo(const std::string& path, const std::string& packageName,
+ const std::string& developerOptIn,
const std::vector<std::string> eglFeatures) {
- if (mUseAngle != UNKNOWN) {
+ if (mShouldUseAngle != UNKNOWN) {
// We've already figured out an answer for this app, so just return.
- ALOGV("Already evaluated the rules file for '%s': use ANGLE = %s", appName.c_str(),
- (mUseAngle == YES) ? "true" : "false");
+ ALOGV("Already evaluated the rules file for '%s': use ANGLE = %s", packageName.c_str(),
+ (mShouldUseAngle == YES) ? "true" : "false");
return;
}
@@ -480,16 +449,17 @@
ALOGV("setting ANGLE path to '%s'", path.c_str());
mAnglePath = path;
- ALOGV("setting ANGLE app name to '%s'", appName.c_str());
- mAngleAppName = appName;
+ ALOGV("setting app package name to '%s'", packageName.c_str());
+ mPackageName = packageName;
ALOGV("setting ANGLE application opt-in to '%s'", developerOptIn.c_str());
mAngleDeveloperOptIn = developerOptIn;
// Update the current status of whether we should use ANGLE or not
- updateUseAngle();
+ updateShouldUseAngle();
}
-void GraphicsEnv::setLayerPaths(NativeLoaderNamespace* appNamespace, const std::string layerPaths) {
+void GraphicsEnv::setLayerPaths(NativeLoaderNamespace* appNamespace,
+ const std::string& layerPaths) {
if (mLayerPaths.empty()) {
mLayerPaths = layerPaths;
mAppNamespace = appNamespace;
@@ -503,8 +473,8 @@
return mAppNamespace;
}
-std::string& GraphicsEnv::getAngleAppName() {
- return mAngleAppName;
+std::string& GraphicsEnv::getPackageName() {
+ return mPackageName;
}
const std::vector<std::string>& GraphicsEnv::getAngleEglFeatures() {
@@ -523,11 +493,11 @@
return mDebugLayersGLES;
}
-void GraphicsEnv::setDebugLayers(const std::string layers) {
+void GraphicsEnv::setDebugLayers(const std::string& layers) {
mDebugLayers = layers;
}
-void GraphicsEnv::setDebugLayersGLES(const std::string layers) {
+void GraphicsEnv::setDebugLayersGLES(const std::string& layers) {
mDebugLayersGLES = layers;
}
diff --git a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h
index f9b234a..a1b5e50 100644
--- a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h
+++ b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h
@@ -55,7 +55,7 @@
// Also set additional required sphal libraries to the linker for loading
// graphics drivers. The string is a list of libraries separated by ':',
// which is required by android_link_namespaces.
- void setDriverPathAndSphalLibraries(const std::string path, const std::string sphalLibraries);
+ void setDriverPathAndSphalLibraries(const std::string& path, const std::string& sphalLibraries);
// Get the updatable driver namespace.
android_namespace_t* getDriverNamespace();
std::string getDriverPath() const;
@@ -96,8 +96,6 @@
/*
* Apis for ANGLE
*/
- // Check if the requested app should use ANGLE.
- bool shouldUseAngle(std::string appName);
// Check if this app process should use ANGLE.
bool shouldUseAngle();
// Set a search path for loading ANGLE libraries. The path is a list of
@@ -105,42 +103,39 @@
// (libraries must be stored uncompressed and page aligned); such elements
// in the search path must have a '!' after the zip filename, e.g.
// /system/app/ANGLEPrebuilt/ANGLEPrebuilt.apk!/lib/arm64-v8a
- void setAngleInfo(const std::string path, const std::string appName, std::string devOptIn,
- const std::vector<std::string> eglFeatures);
+ void setAngleInfo(const std::string& path, const std::string& packageName,
+ const std::string& devOptIn, const std::vector<std::string> eglFeatures);
// Get the ANGLE driver namespace.
android_namespace_t* getAngleNamespace();
- // Get the app name for ANGLE debug message.
- std::string& getAngleAppName();
-
+ // Get the app package name.
+ std::string& getPackageName();
const std::vector<std::string>& getAngleEglFeatures();
+ // Set the persist.graphics.egl system property value.
+ void nativeToggleAngleAsSystemDriver(bool enabled);
/*
* Apis for debug layer
*/
// Set additional layer search paths.
- void setLayerPaths(NativeLoaderNamespace* appNamespace, const std::string layerPaths);
+ void setLayerPaths(NativeLoaderNamespace* appNamespace, const std::string& layerPaths);
// Get the app namespace for loading layers.
NativeLoaderNamespace* getAppNamespace();
// Get additional layer search paths.
const std::string& getLayerPaths();
// Set the Vulkan debug layers.
- void setDebugLayers(const std::string layers);
+ void setDebugLayers(const std::string& layers);
// Set the GL debug layers.
- void setDebugLayersGLES(const std::string layers);
+ void setDebugLayersGLES(const std::string& layers);
// Get the debug layers to load.
const std::string& getDebugLayers();
// Get the debug layers to load.
const std::string& getDebugLayersGLES();
- // Set the persist.graphics.egl system property value.
- void nativeToggleAngleAsSystemDriver(bool enabled);
private:
enum UseAngle { UNKNOWN, YES, NO };
- // Load requested ANGLE library.
- void* loadLibrary(std::string name);
// Update whether ANGLE should be used.
- void updateUseAngle();
+ void updateShouldUseAngle();
// Link updatable driver namespace with llndk and vndk-sp libs.
bool linkDriverNamespaceLocked(android_namespace_t* vndkNamespace);
// Check whether this process is ready to send stats.
@@ -149,39 +144,56 @@
void sendGpuStatsLocked(GpuStatsInfo::Api api, bool isDriverLoaded, int64_t driverLoadingTime);
GraphicsEnv() = default;
+
+ // This mutex protects the namespace creation.
+ std::mutex mNamespaceMutex;
+
+ /**
+ * Updatable driver variables.
+ */
// Path to updatable driver libs.
std::string mDriverPath;
// Path to additional sphal libs linked to updatable driver namespace.
std::string mSphalLibraries;
+ // Updatable driver namespace.
+ android_namespace_t* mDriverNamespace = nullptr;
+
+ /**
+ * ANGLE variables.
+ */
+ // Path to ANGLE libs.
+ std::string mAnglePath;
+ // App's package name.
+ std::string mPackageName;
+ // ANGLE developer opt in status.
+ std::string mAngleDeveloperOptIn;
+ // ANGLE EGL features;
+ std::vector<std::string> mAngleEglFeatures;
+ // Use ANGLE flag.
+ UseAngle mShouldUseAngle = UNKNOWN;
+ // ANGLE namespace.
+ android_namespace_t* mAngleNamespace = nullptr;
+
+ /**
+ * GPU metrics.
+ */
// This mutex protects mGpuStats and get gpuservice call.
std::mutex mStatsLock;
// Cache the activity launch info
bool mActivityLaunched = false;
// Information bookkept for GpuStats.
GpuStatsInfo mGpuStats;
- // Path to ANGLE libs.
- std::string mAnglePath;
- // This App's name.
- std::string mAngleAppName;
- // ANGLE developer opt in status.
- std::string mAngleDeveloperOptIn;
- // ANGLE EGL features;
- std::vector<std::string> mAngleEglFeatures;
- // Use ANGLE flag.
- UseAngle mUseAngle = UNKNOWN;
+
+ /**
+ * Debug layers.
+ */
// Vulkan debug layers libs.
std::string mDebugLayers;
// GL debug layers libs.
std::string mDebugLayersGLES;
// Additional debug layers search path.
std::string mLayerPaths;
- // This mutex protects the namespace creation.
- std::mutex mNamespaceMutex;
- // Updatable driver namespace.
- android_namespace_t* mDriverNamespace = nullptr;
- // ANGLE namespace.
- android_namespace_t* mAngleNamespace = nullptr;
- // This App's namespace.
+ // This App's namespace to open native libraries.
NativeLoaderNamespace* mAppNamespace = nullptr;
};
diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp
index bb3b43a..b4fc5f0 100644
--- a/opengl/libs/EGL/Loader.cpp
+++ b/opengl/libs/EGL/Loader.cpp
@@ -147,13 +147,18 @@
RO_BOARD_PLATFORM_PROPERTY,
};
+// Check whether the loaded system drivers should be unloaded in order to
+// load ANGLE or the updatable graphics drivers.
+// If ANGLE namespace is set, it means the application is identified to run on top of ANGLE.
+// If updatable graphics driver namespace is set, it means the application is identified to
+// run on top of updatable graphics drivers.
static bool should_unload_system_driver(egl_connection_t* cnx) {
// Return false if the system driver has been unloaded once.
if (cnx->systemDriverUnloaded) {
return false;
}
- // Return true if Angle namespace is set.
+ // Return true if ANGLE namespace is set.
android_namespace_t* ns = android::GraphicsEnv::getInstance().getAngleNamespace();
if (ns) {
return true;
@@ -279,10 +284,10 @@
false, systemTime() - openTime);
} else {
// init_angle_backend will check if loaded driver is ANGLE or not,
- // will set cnx->useAngle appropriately.
+ // will set cnx->angleLoaded appropriately.
// Do this here so that we use ANGLE path when driver is ANGLE (e.g. loaded as native),
// not just loading ANGLE as option.
- init_angle_backend(hnd->dso[2], cnx);
+ attempt_to_init_angle_backend(hnd->dso[2], cnx);
}
LOG_ALWAYS_FATAL_IF(!hnd,
@@ -324,7 +329,7 @@
delete hnd;
cnx->dso = nullptr;
- cnx->useAngle = false;
+ cnx->angleLoaded = false;
}
void Loader::init_api(void* dso,
@@ -565,14 +570,14 @@
return hnd;
}
-void Loader::init_angle_backend(void* dso, egl_connection_t* cnx) {
+void Loader::attempt_to_init_angle_backend(void* dso, egl_connection_t* cnx) {
void* pANGLEGetDisplayPlatform = dlsym(dso, "ANGLEGetDisplayPlatform");
if (pANGLEGetDisplayPlatform) {
- ALOGV("ANGLE GLES library in use");
- cnx->useAngle = true;
+ ALOGV("ANGLE GLES library loaded");
+ cnx->angleLoaded = true;
} else {
- ALOGV("Native GLES library in use");
- cnx->useAngle = false;
+ ALOGV("Native GLES library loaded");
+ cnx->angleLoaded = false;
}
}
diff --git a/opengl/libs/EGL/Loader.h b/opengl/libs/EGL/Loader.h
index 81742ab..cadbd46 100644
--- a/opengl/libs/EGL/Loader.h
+++ b/opengl/libs/EGL/Loader.h
@@ -57,7 +57,7 @@
driver_t* attempt_to_load_system_driver(egl_connection_t* cnx, const char* suffix, const bool exact);
void unload_system_driver(egl_connection_t* cnx);
void initialize_api(void* dso, egl_connection_t* cnx, uint32_t mask);
- void init_angle_backend(void* dso, egl_connection_t* cnx);
+ void attempt_to_init_angle_backend(void* dso, egl_connection_t* cnx);
static __attribute__((noinline)) void init_api(void* dso, const char* const* api,
const char* const* ref_api,
diff --git a/opengl/libs/EGL/egl_display.cpp b/opengl/libs/EGL/egl_display.cpp
index 525fed1..3317347 100644
--- a/opengl/libs/EGL/egl_display.cpp
+++ b/opengl/libs/EGL/egl_display.cpp
@@ -191,7 +191,7 @@
if (cnx->dso) {
EGLDisplay dpy = EGL_NO_DISPLAY;
- if (cnx->useAngle) {
+ if (cnx->angleLoaded) {
EGLint error;
dpy = getPlatformDisplayAngle(display, cnx, attrib_list, &error);
if (error != EGL_NONE) {
@@ -324,7 +324,7 @@
// b/269060366 Conditionally enabled EGL_ANDROID_get_frame_timestamps extension if the
// device's present timestamps are reliable (which may not be the case on emulators).
- if (cnx->useAngle) {
+ if (cnx->angleLoaded) {
if (android::base::GetBoolProperty("service.sf.present_timestamp", false)) {
mExtensionString.append("EGL_ANDROID_get_frame_timestamps ");
}
@@ -432,7 +432,7 @@
egl_connection_t* const cnx = &gEGLImpl;
if (cnx->dso && disp.state == egl_display_t::INITIALIZED) {
// If we're using ANGLE reset any custom DisplayPlatform
- if (cnx->useAngle) {
+ if (cnx->angleLoaded) {
angle::resetAnglePlatform(disp.dpy);
}
if (cnx->egl.eglTerminate(disp.dpy) == EGL_FALSE) {
diff --git a/opengl/libs/EGL/egl_object.cpp b/opengl/libs/EGL/egl_object.cpp
index efbe613..33a77c4 100644
--- a/opengl/libs/EGL/egl_object.cpp
+++ b/opengl/libs/EGL/egl_object.cpp
@@ -84,7 +84,7 @@
if (win != nullptr && connected) {
// NOTE: When using Vulkan backend, the Vulkan runtime makes all the
// native_window_* calls, so don't do them here.
- if (!cnx->useAngle) {
+ if (!cnx->angleLoaded) {
native_window_set_buffers_format(win, 0);
if (native_window_api_disconnect(win, NATIVE_WINDOW_API_EGL)) {
ALOGW("EGLNativeWindowType %p disconnect failed", win);
diff --git a/opengl/libs/EGL/egl_platform_entries.cpp b/opengl/libs/EGL/egl_platform_entries.cpp
index aefa1f0..440eb17 100644
--- a/opengl/libs/EGL/egl_platform_entries.cpp
+++ b/opengl/libs/EGL/egl_platform_entries.cpp
@@ -685,7 +685,7 @@
// NOTE: When using Vulkan backend, the Vulkan runtime makes all the
// native_window_* calls, so don't do them here.
- if (!cnx->useAngle) {
+ if (!cnx->angleLoaded) {
int result = native_window_api_connect(window, NATIVE_WINDOW_API_EGL);
if (result < 0) {
ALOGE("eglCreateWindowSurface: native_window_api_connect (win=%p) "
@@ -704,14 +704,14 @@
std::vector<AttrType> strippedAttribList;
if (!processAttributes<AttrType>(dp, window, attrib_list, &colorSpace, &strippedAttribList)) {
ALOGE("error invalid colorspace: %d", colorSpace);
- if (!cnx->useAngle) {
+ if (!cnx->angleLoaded) {
native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
}
return EGL_NO_SURFACE;
}
attrib_list = strippedAttribList.data();
- if (!cnx->useAngle) {
+ if (!cnx->angleLoaded) {
int err = native_window_set_buffers_format(window, static_cast<int>(format));
if (err != 0) {
ALOGE("error setting native window pixel format: %s (%d)", strerror(-err), err);
@@ -743,7 +743,7 @@
}
// EGLSurface creation failed
- if (!cnx->useAngle) {
+ if (!cnx->angleLoaded) {
native_window_set_buffers_format(window, 0);
native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
}
@@ -1354,7 +1354,7 @@
}
}
- if (!s->cnx->useAngle) {
+ if (!s->cnx->angleLoaded) {
if (!sendSurfaceMetadata(s)) {
native_window_api_disconnect(s->getNativeWindow(), NATIVE_WINDOW_API_EGL);
return setError(EGL_BAD_NATIVE_WINDOW, (EGLBoolean)EGL_FALSE);
@@ -1379,7 +1379,7 @@
androidRect.bottom = y;
androidRects.push_back(androidRect);
}
- if (!s->cnx->useAngle) {
+ if (!s->cnx->angleLoaded) {
native_window_set_surface_damage(s->getNativeWindow(), androidRects.data(),
androidRects.size());
}
@@ -1470,7 +1470,7 @@
int err = native_window_set_auto_refresh(s->getNativeWindow(), value != 0);
if (err != 0) {
return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
- } else if (!s->cnx->useAngle) {
+ } else if (!s->cnx->angleLoaded) {
return EGL_TRUE;
} // else if ANGLE, fall through to the call to the driver (i.e. ANGLE) below
}
@@ -1484,7 +1484,7 @@
int err = native_window_enable_frame_timestamps(s->getNativeWindow(), value != 0);
if (err != 0) {
return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);
- } else if (!s->cnx->useAngle) {
+ } else if (!s->cnx->angleLoaded) {
return EGL_TRUE;
} // else if ANGLE, fall through to the call to the driver (i.e. ANGLE) below
}
diff --git a/opengl/libs/EGL/egldefs.h b/opengl/libs/EGL/egldefs.h
index fcc11f1..3bd37cb 100644
--- a/opengl/libs/EGL/egldefs.h
+++ b/opengl/libs/EGL/egldefs.h
@@ -41,7 +41,8 @@
libEgl(nullptr),
libGles1(nullptr),
libGles2(nullptr),
- systemDriverUnloaded(false) {
+ systemDriverUnloaded(false),
+ angleLoaded(false) {
const char* const* entries = platform_names;
EGLFuncPointer* curr = reinterpret_cast<EGLFuncPointer*>(&platform);
while (*entries) {
@@ -73,7 +74,7 @@
void* libGles2;
bool systemDriverUnloaded;
- bool useAngle; // Was ANGLE successfully loaded
+ bool angleLoaded; // Was ANGLE successfully loaded
};
extern gl_hooks_t gHooks[2];