Return an empty optional in HardwareBuffer::GetSystemUniqueID if the underlying NDK API is unavailable (flutter/engine#51839)
This commit is contained in:
@@ -50,6 +50,8 @@ source_set("unittests_lib") {
|
||||
":unittests_fixtures",
|
||||
"//flutter/testing",
|
||||
]
|
||||
|
||||
defines = [ "TESTING" ]
|
||||
}
|
||||
|
||||
executable("unittests") {
|
||||
|
||||
@@ -108,7 +108,7 @@ std::optional<uint64_t> HardwareBuffer::GetSystemUniqueID() const {
|
||||
std::optional<uint64_t> HardwareBuffer::GetSystemUniqueID(
|
||||
AHardwareBuffer* buffer) {
|
||||
if (!GetProcTable().AHardwareBuffer_getId) {
|
||||
return false;
|
||||
return std::nullopt;
|
||||
}
|
||||
uint64_t out_id = 0u;
|
||||
if (GetProcTable().AHardwareBuffer_getId(buffer, &out_id) != 0) {
|
||||
|
||||
@@ -14,6 +14,11 @@ const ProcTable& GetProcTable() {
|
||||
return gProcTable;
|
||||
}
|
||||
|
||||
// Only used by tests.
|
||||
ProcTable& GetMutableProcTable() {
|
||||
return const_cast<ProcTable&>(GetProcTable());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void ResolveAndroidProc(
|
||||
AndroidProc<T>& proc,
|
||||
|
||||
@@ -124,6 +124,10 @@ struct ProcTable {
|
||||
|
||||
const ProcTable& GetProcTable();
|
||||
|
||||
#ifdef TESTING
|
||||
ProcTable& GetMutableProcTable();
|
||||
#endif
|
||||
|
||||
} // namespace impeller::android
|
||||
|
||||
#endif // FLUTTER_IMPELLER_TOOLKIT_ANDROID_PROC_TABLE_H_
|
||||
|
||||
@@ -12,6 +12,18 @@
|
||||
|
||||
namespace impeller::android::testing {
|
||||
|
||||
#define DISABLE_ANDROID_PROC(name) \
|
||||
struct Disable##name { \
|
||||
Disable##name() { \
|
||||
real_proc = GetMutableProcTable().name.proc; \
|
||||
GetMutableProcTable().name.proc = nullptr; \
|
||||
} \
|
||||
~Disable##name() { \
|
||||
GetMutableProcTable().name.proc = real_proc; \
|
||||
} \
|
||||
decltype(name)* real_proc; \
|
||||
} disable##name;
|
||||
|
||||
TEST(ToolkitAndroidTest, CanCreateProcTable) {
|
||||
ProcTable proc_table;
|
||||
ASSERT_TRUE(proc_table.IsValid());
|
||||
@@ -49,6 +61,11 @@ TEST(ToolkitAndroidTest, CanGetHardwareBufferIDs) {
|
||||
ASSERT_TRUE(buffer.GetSystemUniqueID().has_value());
|
||||
}
|
||||
|
||||
TEST(ToolkitAndroidTest, HardwareBufferNullIDIfAPIUnavailable) {
|
||||
DISABLE_ANDROID_PROC(AHardwareBuffer_getId);
|
||||
ASSERT_FALSE(HardwareBuffer::GetSystemUniqueID(nullptr).has_value());
|
||||
}
|
||||
|
||||
TEST(ToolkitAndroidTest, CanDescribeHardwareBufferHandles) {
|
||||
if (!HardwareBuffer::IsAvailableOnPlatform()) {
|
||||
GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
|
||||
|
||||
Reference in New Issue
Block a user