Merge "Improve logging of evdev events by using labels for recognized values" into udc-dev
diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp
index 24642d2..6a354b4 100644
--- a/libs/binder/Android.bp
+++ b/libs/binder/Android.bp
@@ -74,9 +74,6 @@
name: "libbinder_common_defaults",
host_supported: true,
- // for vndbinder and binderRpcTest
- vendor_available: true,
-
srcs: [
"Binder.cpp",
"BpBinder.cpp",
@@ -200,7 +197,6 @@
cc_library_headers {
name: "trusty_mock_headers",
- vendor_available: true,
host_supported: true,
export_include_dirs: [
@@ -215,7 +211,6 @@
cc_defaults {
name: "trusty_mock_defaults",
- vendor_available: true,
host_supported: true,
header_libs: [
@@ -309,6 +304,8 @@
version_script: "libbinder.map",
+ // for vndbinder
+ vendor_available: true,
vndk: {
enabled: true,
},
@@ -467,7 +464,6 @@
cc_library_static {
name: "libbinder_tls_static",
defaults: ["libbinder_tls_defaults"],
- vendor_available: true,
visibility: [
":__subpackages__",
],
@@ -550,6 +546,7 @@
"//packages/modules/Virtualization/javalib/jni",
"//packages/modules/Virtualization/vm_payload",
"//device/google/cuttlefish/shared/minidroid:__subpackages__",
+ "//system/software_defined_vehicle:__subpackages__",
],
}
diff --git a/libs/binder/ndk/include_platform/android/binder_manager.h b/libs/binder/ndk/include_platform/android/binder_manager.h
index 86d5ed2..43159d8 100644
--- a/libs/binder/ndk/include_platform/android/binder_manager.h
+++ b/libs/binder/ndk/include_platform/android/binder_manager.h
@@ -22,6 +22,16 @@
__BEGIN_DECLS
+enum AServiceManager_AddServiceFlag : uint32_t {
+ /**
+ * This allows processes with AID_ISOLATED to get the binder of the service added.
+ *
+ * Services with methods that perform file IO, web socket creation or ways to egress data must
+ * not be added with this flag for privacy concerns.
+ */
+ ADD_SERVICE_ALLOW_ISOLATED = 1,
+};
+
/**
* This registers the service with the default service manager under this instance name. This does
* not take ownership of binder.
@@ -46,12 +56,13 @@
*
* \param binder object to register globally with the service manager.
* \param instance identifier of the service. This will be used to lookup the service.
- * \param allowIsolated allows if this service can be isolated.
+ * \param flag an AServiceManager_AddServiceFlag enum to denote how the service should be added.
*
* \return EX_NONE on success.
*/
-__attribute__((warn_unused_result)) binder_exception_t AServiceManager_addServiceWithAllowIsolated(
- AIBinder* binder, const char* instance, bool allowIsolated) __INTRODUCED_IN(34);
+__attribute__((warn_unused_result)) binder_exception_t AServiceManager_addServiceWithFlag(
+ AIBinder* binder, const char* instance, const AServiceManager_AddServiceFlag flag)
+ __INTRODUCED_IN(34);
/**
* Gets a binder object with this specific instance name. Will return nullptr immediately if the
diff --git a/libs/binder/ndk/libbinder_ndk.map.txt b/libs/binder/ndk/libbinder_ndk.map.txt
index 5f2f617..1078fb2 100644
--- a/libs/binder/ndk/libbinder_ndk.map.txt
+++ b/libs/binder/ndk/libbinder_ndk.map.txt
@@ -158,12 +158,12 @@
AServiceManager_getUpdatableApexName; # systemapi
AServiceManager_registerForServiceNotifications; # systemapi llndk
AServiceManager_NotificationRegistration_delete; # systemapi llndk
+ AServiceManager_addServiceWithFlag; # systemapi llndk
};
LIBBINDER_NDK_PLATFORM {
global:
AParcel_getAllowFds;
- AServiceManager_addServiceWithAllowIsolated;
extern "C++" {
AIBinder_fromPlatformBinder*;
AIBinder_toPlatformBinder*;
diff --git a/libs/binder/ndk/service_manager.cpp b/libs/binder/ndk/service_manager.cpp
index 2763ddb..84da459 100644
--- a/libs/binder/ndk/service_manager.cpp
+++ b/libs/binder/ndk/service_manager.cpp
@@ -42,14 +42,15 @@
return PruneException(exception);
}
-binder_exception_t AServiceManager_addServiceWithAllowIsolated(AIBinder* binder,
- const char* instance,
- bool allowIsolated) {
+binder_exception_t AServiceManager_addServiceWithFlag(AIBinder* binder, const char* instance,
+ const AServiceManager_AddServiceFlag flag) {
if (binder == nullptr || instance == nullptr) {
return EX_ILLEGAL_ARGUMENT;
}
sp<IServiceManager> sm = defaultServiceManager();
+
+ bool allowIsolated = flag & AServiceManager_AddServiceFlag::ADD_SERVICE_ALLOW_ISOLATED;
status_t exception = sm->addService(String16(instance), binder->getBinder(), allowIsolated);
return PruneException(exception);
}
diff --git a/libs/binder/rust/rpcbinder/Android.bp b/libs/binder/rust/rpcbinder/Android.bp
index da9797b..0067a20 100644
--- a/libs/binder/rust/rpcbinder/Android.bp
+++ b/libs/binder/rust/rpcbinder/Android.bp
@@ -26,6 +26,7 @@
visibility: [
"//device/google/cuttlefish/shared/minidroid/sample",
"//packages/modules/Virtualization:__subpackages__",
+ "//system/software_defined_vehicle:__subpackages__",
],
apex_available: [
"//apex_available:platform",
diff --git a/libs/binder/tests/Android.bp b/libs/binder/tests/Android.bp
index 2a4fc48..0f0d64a 100644
--- a/libs/binder/tests/Android.bp
+++ b/libs/binder/tests/Android.bp
@@ -138,7 +138,6 @@
aidl_interface {
name: "binderRpcTestIface",
- vendor_available: true,
host_supported: true,
unstable: true,
srcs: [
@@ -159,7 +158,6 @@
cc_library_static {
name: "libbinder_tls_test_utils",
- vendor_available: true,
host_supported: true,
target: {
darwin: {
@@ -213,7 +211,6 @@
defaults: [
"binderRpcTest_common_defaults",
],
- vendor_available: true,
gtest: false,
auto_gen_config: false,
srcs: [
@@ -224,18 +221,10 @@
cc_defaults {
name: "binderRpcTest_defaults",
- vendor_available: true,
target: {
android: {
test_suites: ["vts"],
},
-
- vendor: {
- shared_libs: [
- "libbinder_trusty",
- "libtrusty",
- ],
- },
},
defaults: [
"binderRpcTest_common_defaults",
@@ -397,11 +386,6 @@
cc_test {
name: "binderRpcTest",
- // TODO(b/269799024)
- test_options: {
- unit_test: false,
- },
-
defaults: [
"binderRpcTest_defaults",
"binderRpcTest_shared_defaults",
diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp
index 7459466..c3af996 100644
--- a/libs/ui/Gralloc4.cpp
+++ b/libs/ui/Gralloc4.cpp
@@ -22,6 +22,8 @@
#include <aidlcommonsupport/NativeHandle.h>
#include <android/binder_enums.h>
#include <android/binder_manager.h>
+#include <cutils/android_filesystem_config.h>
+#include <cutils/multiuser.h>
#include <gralloctypes/Gralloc4.h>
#include <hidl/ServiceManagement.h>
#include <hwbinder/IPCThreadState.h>
@@ -1195,8 +1197,15 @@
mAllocator = IAllocator::getService();
if (__builtin_available(android 31, *)) {
if (hasIAllocatorAidl()) {
- mAidlAllocator = AidlIAllocator::fromBinder(ndk::SpAIBinder(
- AServiceManager_waitForService(kAidlAllocatorServiceName.c_str())));
+ // TODO(b/269517338): Perform the isolated checking for this in service manager instead.
+ uid_t aid = multiuser_get_app_id(getuid());
+ if (aid >= AID_ISOLATED_START && aid <= AID_ISOLATED_END) {
+ mAidlAllocator = AidlIAllocator::fromBinder(ndk::SpAIBinder(
+ AServiceManager_getService(kAidlAllocatorServiceName.c_str())));
+ } else {
+ mAidlAllocator = AidlIAllocator::fromBinder(ndk::SpAIBinder(
+ AServiceManager_waitForService(kAidlAllocatorServiceName.c_str())));
+ }
ALOGE_IF(!mAidlAllocator, "AIDL IAllocator declared but failed to get service");
}
}
diff --git a/opengl/libs/EGL/BlobCache.cpp b/opengl/libs/EGL/BlobCache.cpp
index 86c788d..aecfc6b 100644
--- a/opengl/libs/EGL/BlobCache.cpp
+++ b/opengl/libs/EGL/BlobCache.cpp
@@ -231,7 +231,7 @@
int BlobCache::unflatten(void const* buffer, size_t size) {
// All errors should result in the BlobCache being in an empty state.
- mCacheEntries.clear();
+ clear();
// Read the cache header
if (size < sizeof(Header)) {
@@ -258,7 +258,7 @@
size_t numEntries = header->mNumEntries;
for (size_t i = 0; i < numEntries; i++) {
if (byteOffset + sizeof(EntryHeader) > size) {
- mCacheEntries.clear();
+ clear();
ALOGE("unflatten: not enough room for cache entry headers");
return -EINVAL;
}
@@ -270,7 +270,7 @@
size_t totalSize = align4(entrySize);
if (byteOffset + totalSize > size) {
- mCacheEntries.clear();
+ clear();
ALOGE("unflatten: not enough room for cache entry headers");
return -EINVAL;
}
diff --git a/opengl/libs/EGL/BlobCache.h b/opengl/libs/EGL/BlobCache.h
index ff03d30..52078ff 100644
--- a/opengl/libs/EGL/BlobCache.h
+++ b/opengl/libs/EGL/BlobCache.h
@@ -117,7 +117,10 @@
// clear flushes out all contents of the cache then the BlobCache, leaving
// it in an empty state.
- void clear() { mCacheEntries.clear(); }
+ void clear() {
+ mCacheEntries.clear();
+ mTotalSize = 0;
+ }
protected:
// mMaxTotalSize is the maximum size that all cache entries can occupy. This
diff --git a/opengl/libs/EGL/BlobCache_test.cpp b/opengl/libs/EGL/BlobCache_test.cpp
index ceea0fb..450c128 100644
--- a/opengl/libs/EGL/BlobCache_test.cpp
+++ b/opengl/libs/EGL/BlobCache_test.cpp
@@ -466,4 +466,31 @@
ASSERT_EQ(size_t(0), mBC2->get("abcd", 4, buf, 4));
}
+// Test for a divide by zero bug (b/239862516). Before the fix, unflatten() would not reset
+// mTotalSize when it encountered an error, which would trigger division by 0 in clean() in the
+// right conditions.
+TEST_F(BlobCacheFlattenTest, SetAfterFailedUnflatten) {
+ // isCleanable() must be true, so mTotalSize must be > mMaxTotalSize / 2 after unflattening
+ // after one entry is lost. To make this the case, MaxTotalSize is 30 and three 10 sized
+ // entries are used. One of those entries is lost, resulting in mTotalSize=20
+ const size_t kMaxKeySize = 10;
+ const size_t kMaxValueSize = 10;
+ const size_t kMaxTotalSize = 30;
+ mBC.reset(new BlobCache(kMaxKeySize, kMaxValueSize, kMaxTotalSize));
+ mBC2.reset(new BlobCache(kMaxKeySize, kMaxValueSize, kMaxTotalSize));
+ mBC->set("aaaaa", 5, "aaaaa", 5);
+ mBC->set("bbbbb", 5, "bbbbb", 5);
+ mBC->set("ccccc", 5, "ccccc", 5);
+
+ size_t size = mBC->getFlattenedSize();
+ uint8_t* flat = new uint8_t[size];
+ ASSERT_EQ(OK, mBC->flatten(flat, size));
+
+ ASSERT_EQ(BAD_VALUE, mBC2->unflatten(flat, size - 10));
+ delete[] flat;
+
+ // This line will trigger clean() which caused a crash.
+ mBC2->set("dddddddddd", 10, "dddddddddd", 10);
+}
+
} // namespace android
diff --git a/services/batteryservice/include/batteryservice/BatteryService.h b/services/batteryservice/include/batteryservice/BatteryService.h
index a2e4115..bf6189d 100644
--- a/services/batteryservice/include/batteryservice/BatteryService.h
+++ b/services/batteryservice/include/batteryservice/BatteryService.h
@@ -37,6 +37,7 @@
BATTERY_PROP_CHARGING_POLICY = 7, // equals BATTERY_PROPERTY_CHARGING_POLICY
BATTERY_PROP_MANUFACTURING_DATE = 8, // equals BATTERY_PROPERTY_MANUFACTURING_DATE
BATTERY_PROP_FIRST_USAGE_DATE = 9, // equals BATTERY_PROPERTY_FIRST_USAGE_DATE
+ BATTERY_PROP_STATE_OF_HEALTH = 10, // equals BATTERY_PROPERTY_STATE_OF_HEALTH
};
struct BatteryProperties {
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index c91ad49..06ece93 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2031,15 +2031,9 @@
void SurfaceFlinger::onComposerHalVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp,
std::optional<hal::VsyncPeriodNanos> vsyncPeriod) {
- const std::string tracePeriod = [vsyncPeriod]() {
- if (ATRACE_ENABLED() && vsyncPeriod) {
- std::stringstream ss;
- ss << "(" << *vsyncPeriod << ")";
- return ss.str();
- }
- return std::string();
- }();
- ATRACE_FORMAT("onComposerHalVsync%s", tracePeriod.c_str());
+ ATRACE_NAME(vsyncPeriod
+ ? ftl::Concat(__func__, ' ', hwcDisplayId, ' ', *vsyncPeriod, "ns").c_str()
+ : ftl::Concat(__func__, ' ', hwcDisplayId).c_str());
Mutex::Autolock lock(mStateLock);
@@ -3576,6 +3570,10 @@
});
}
+ if (transactionFlags & eInputInfoUpdateNeeded) {
+ mUpdateInputInfo = true;
+ }
+
doCommitTransactions();
}
@@ -7567,8 +7565,9 @@
}
status_t SurfaceFlinger::addWindowInfosListener(
- const sp<IWindowInfosListener>& windowInfosListener) const {
+ const sp<IWindowInfosListener>& windowInfosListener) {
mWindowInfosListenerInvoker->addWindowInfosListener(windowInfosListener);
+ setTransactionFlags(eInputInfoUpdateNeeded);
return NO_ERROR;
}
@@ -8560,8 +8559,12 @@
binder::Status SurfaceComposerAIDL::addWindowInfosListener(
const sp<gui::IWindowInfosListener>& windowInfosListener) {
status_t status;
+ const int pid = IPCThreadState::self()->getCallingPid();
const int uid = IPCThreadState::self()->getCallingUid();
- if (uid == AID_SYSTEM || uid == AID_GRAPHICS) {
+ // TODO(b/270566761) update permissions check so that only system_server and shell can add
+ // WindowInfosListeners
+ if (uid == AID_SYSTEM || uid == AID_GRAPHICS ||
+ checkPermission(sAccessSurfaceFlinger, pid, uid)) {
status = mFlinger->addWindowInfosListener(windowInfosListener);
} else {
status = PERMISSION_DENIED;
@@ -8572,8 +8575,10 @@
binder::Status SurfaceComposerAIDL::removeWindowInfosListener(
const sp<gui::IWindowInfosListener>& windowInfosListener) {
status_t status;
+ const int pid = IPCThreadState::self()->getCallingPid();
const int uid = IPCThreadState::self()->getCallingUid();
- if (uid == AID_SYSTEM || uid == AID_GRAPHICS) {
+ if (uid == AID_SYSTEM || uid == AID_GRAPHICS ||
+ checkPermission(sAccessSurfaceFlinger, pid, uid)) {
status = mFlinger->removeWindowInfosListener(windowInfosListener);
} else {
status = PERMISSION_DENIED;
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index b41f414..03c31bb 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -162,7 +162,8 @@
eDisplayTransactionNeeded = 0x04,
eTransformHintUpdateNeeded = 0x08,
eTransactionFlushNeeded = 0x10,
- eTransactionMask = 0x1f,
+ eInputInfoUpdateNeeded = 0x20,
+ eTransactionMask = 0x3f,
};
// Latch Unsignaled buffer behaviours
@@ -618,7 +619,7 @@
status_t getMaxAcquiredBufferCount(int* buffers) const;
- status_t addWindowInfosListener(const sp<gui::IWindowInfosListener>& windowInfosListener) const;
+ status_t addWindowInfosListener(const sp<gui::IWindowInfosListener>& windowInfosListener);
status_t removeWindowInfosListener(
const sp<gui::IWindowInfosListener>& windowInfosListener) const;
diff --git a/services/surfaceflinger/Tracing/TransactionProtoParser.cpp b/services/surfaceflinger/Tracing/TransactionProtoParser.cpp
index 2f46487..475c76b 100644
--- a/services/surfaceflinger/Tracing/TransactionProtoParser.cpp
+++ b/services/surfaceflinger/Tracing/TransactionProtoParser.cpp
@@ -15,6 +15,7 @@
*/
#include <gui/SurfaceComposerClient.h>
+#include <renderengine/mock/FakeExternalTexture.h>
#include <ui/Fence.h>
#include <ui/Rect.h>
@@ -313,6 +314,14 @@
ResolvedComposerState s;
s.state.what = 0;
fromProto(proto.layer_changes(i), s.state);
+ if (s.state.bufferData) {
+ s.externalTexture = std::make_shared<
+ renderengine::mock::FakeExternalTexture>(s.state.bufferData->getWidth(),
+ s.state.bufferData->getHeight(),
+ s.state.bufferData->getId(),
+ s.state.bufferData->getPixelFormat(),
+ s.state.bufferData->getUsage());
+ }
t.states.emplace_back(s);
}
diff --git a/services/surfaceflinger/Tracing/tools/run.sh b/services/surfaceflinger/Tracing/tools/run.sh
index baa93f1..307a4d8 100644
--- a/services/surfaceflinger/Tracing/tools/run.sh
+++ b/services/surfaceflinger/Tracing/tools/run.sh
@@ -5,7 +5,15 @@
# Build, push and run layertracegenerator
$ANDROID_BUILD_TOP/build/soong/soong_ui.bash --make-mode layertracegenerator
adb wait-for-device && adb push $OUT/system/bin/layertracegenerator /data/layertracegenerator
-echo "Writing transaction trace to file"
-adb shell service call SurfaceFlinger 1041 i32 0
-adb shell /data/layertracegenerator
+
+if [ -z "$1" ]
+ then
+ echo "Writing transaction trace to file"
+ adb shell service call SurfaceFlinger 1041 i32 0
+ adb shell /data/layertracegenerator
+ else
+ echo "Pushing transaction trace to device"
+ adb push $1 /data/transaction_trace.winscope
+ adb shell /data/layertracegenerator /data/transaction_trace.winscope
+fi
adb pull /data/misc/wmtrace/layers_trace.winscope
\ No newline at end of file
diff --git a/services/surfaceflinger/WindowInfosListenerInvoker.cpp b/services/surfaceflinger/WindowInfosListenerInvoker.cpp
index a1313e3..292083b 100644
--- a/services/surfaceflinger/WindowInfosListenerInvoker.cpp
+++ b/services/surfaceflinger/WindowInfosListenerInvoker.cpp
@@ -17,7 +17,6 @@
#include <ftl/small_vector.h>
#include <gui/ISurfaceComposer.h>
-#include "SurfaceFlinger.h"
#include "WindowInfosListenerInvoker.h"
namespace android {
diff --git a/services/surfaceflinger/WindowInfosListenerInvoker.h b/services/surfaceflinger/WindowInfosListenerInvoker.h
index a1d66a1..d60a9c4 100644
--- a/services/surfaceflinger/WindowInfosListenerInvoker.h
+++ b/services/surfaceflinger/WindowInfosListenerInvoker.h
@@ -16,6 +16,8 @@
#pragma once
+#include <unordered_set>
+
#include <android/gui/BnWindowInfosReportedListener.h>
#include <android/gui/IWindowInfosListener.h>
#include <android/gui/IWindowInfosReportedListener.h>
@@ -49,8 +51,6 @@
static constexpr size_t kStaticCapacity = 3;
ftl::SmallMap<wp<IBinder>, const sp<gui::IWindowInfosListener>, kStaticCapacity>
mWindowInfosListeners GUARDED_BY(mListenersMutex);
-
- sp<gui::IWindowInfosReportedListener> mWindowInfosReportedListener;
};
} // namespace android
diff --git a/services/surfaceflinger/tests/WindowInfosListener_test.cpp b/services/surfaceflinger/tests/WindowInfosListener_test.cpp
index 53c3c39..d71486f 100644
--- a/services/surfaceflinger/tests/WindowInfosListener_test.cpp
+++ b/services/surfaceflinger/tests/WindowInfosListener_test.cpp
@@ -18,61 +18,61 @@
#include <gui/SurfaceComposerClient.h>
#include <private/android_filesystem_config.h>
#include <future>
-#include "utils/TransactionUtils.h"
namespace android {
using Transaction = SurfaceComposerClient::Transaction;
using gui::DisplayInfo;
using gui::WindowInfo;
+using WindowInfosPredicate = std::function<bool(const std::vector<WindowInfo>&)>;
+
class WindowInfosListenerTest : public ::testing::Test {
protected:
void SetUp() override {
seteuid(AID_SYSTEM);
mClient = sp<SurfaceComposerClient>::make();
- mWindowInfosListener = sp<SyncWindowInfosListener>::make();
- mClient->addWindowInfosListener(mWindowInfosListener);
}
- void TearDown() override {
- mClient->removeWindowInfosListener(mWindowInfosListener);
- seteuid(AID_ROOT);
- }
+ void TearDown() override { seteuid(AID_ROOT); }
- struct SyncWindowInfosListener : public gui::WindowInfosListener {
+ struct WindowInfosListener : public gui::WindowInfosListener {
public:
+ WindowInfosListener(WindowInfosPredicate predicate, std::promise<void>& promise)
+ : mPredicate(std::move(predicate)), mPromise(promise) {}
+
void onWindowInfosChanged(const std::vector<WindowInfo>& windowInfos,
const std::vector<DisplayInfo>&) override {
- windowInfosPromise.set_value(windowInfos);
- }
-
- std::vector<WindowInfo> waitForWindowInfos() {
- std::future<std::vector<WindowInfo>> windowInfosFuture =
- windowInfosPromise.get_future();
- std::vector<WindowInfo> windowInfos = windowInfosFuture.get();
- windowInfosPromise = std::promise<std::vector<WindowInfo>>();
- return windowInfos;
+ if (mPredicate(windowInfos)) {
+ mPromise.set_value();
+ }
}
private:
- std::promise<std::vector<WindowInfo>> windowInfosPromise;
+ WindowInfosPredicate mPredicate;
+ std::promise<void>& mPromise;
};
sp<SurfaceComposerClient> mClient;
- sp<SyncWindowInfosListener> mWindowInfosListener;
+
+ bool waitForWindowInfosPredicate(WindowInfosPredicate predicate) {
+ std::promise<void> promise;
+ auto listener = sp<WindowInfosListener>::make(std::move(predicate), promise);
+ mClient->addWindowInfosListener(listener);
+ auto future = promise.get_future();
+ bool satisfied = future.wait_for(std::chrono::seconds{1}) == std::future_status::ready;
+ mClient->removeWindowInfosListener(listener);
+ return satisfied;
+ }
};
std::optional<WindowInfo> findMatchingWindowInfo(WindowInfo targetWindowInfo,
std::vector<WindowInfo> windowInfos) {
- std::optional<WindowInfo> foundWindowInfo = std::nullopt;
for (WindowInfo windowInfo : windowInfos) {
if (windowInfo.token == targetWindowInfo.token) {
- foundWindowInfo = std::make_optional<>(windowInfo);
- break;
+ return windowInfo;
}
}
-
- return foundWindowInfo;
+ return std::nullopt;
}
TEST_F(WindowInfosListenerTest, WindowInfoAddedAndRemoved) {
@@ -92,15 +92,17 @@
.setInputWindowInfo(surfaceControl, windowInfo)
.apply();
- std::vector<WindowInfo> windowInfos = mWindowInfosListener->waitForWindowInfos();
- std::optional<WindowInfo> foundWindowInfo = findMatchingWindowInfo(windowInfo, windowInfos);
- ASSERT_NE(std::nullopt, foundWindowInfo);
+ auto windowPresent = [&](const std::vector<WindowInfo>& windowInfos) {
+ return findMatchingWindowInfo(windowInfo, windowInfos).has_value();
+ };
+ ASSERT_TRUE(waitForWindowInfosPredicate(windowPresent));
Transaction().reparent(surfaceControl, nullptr).apply();
- windowInfos = mWindowInfosListener->waitForWindowInfos();
- foundWindowInfo = findMatchingWindowInfo(windowInfo, windowInfos);
- ASSERT_EQ(std::nullopt, foundWindowInfo);
+ auto windowNotPresent = [&](const std::vector<WindowInfo>& windowInfos) {
+ return !findMatchingWindowInfo(windowInfo, windowInfos).has_value();
+ };
+ ASSERT_TRUE(waitForWindowInfosPredicate(windowNotPresent));
}
TEST_F(WindowInfosListenerTest, WindowInfoChanged) {
@@ -121,19 +123,28 @@
.setInputWindowInfo(surfaceControl, windowInfo)
.apply();
- std::vector<WindowInfo> windowInfos = mWindowInfosListener->waitForWindowInfos();
- std::optional<WindowInfo> foundWindowInfo = findMatchingWindowInfo(windowInfo, windowInfos);
- ASSERT_NE(std::nullopt, foundWindowInfo);
- ASSERT_TRUE(foundWindowInfo->touchableRegion.isEmpty());
+ auto windowIsPresentAndTouchableRegionEmpty = [&](const std::vector<WindowInfo>& windowInfos) {
+ auto foundWindowInfo = findMatchingWindowInfo(windowInfo, windowInfos);
+ if (!foundWindowInfo) {
+ return false;
+ }
+ return foundWindowInfo->touchableRegion.isEmpty();
+ };
+ ASSERT_TRUE(waitForWindowInfosPredicate(windowIsPresentAndTouchableRegionEmpty));
Rect touchableRegions(0, 0, 50, 50);
windowInfo.addTouchableRegion(Rect(0, 0, 50, 50));
Transaction().setInputWindowInfo(surfaceControl, windowInfo).apply();
- windowInfos = mWindowInfosListener->waitForWindowInfos();
- foundWindowInfo = findMatchingWindowInfo(windowInfo, windowInfos);
- ASSERT_NE(std::nullopt, foundWindowInfo);
- ASSERT_TRUE(foundWindowInfo->touchableRegion.hasSameRects(windowInfo.touchableRegion));
+ auto windowIsPresentAndTouchableRegionMatches =
+ [&](const std::vector<WindowInfo>& windowInfos) {
+ auto foundWindowInfo = findMatchingWindowInfo(windowInfo, windowInfos);
+ if (!foundWindowInfo) {
+ return false;
+ }
+ return foundWindowInfo->touchableRegion.hasSameRects(windowInfo.touchableRegion);
+ };
+ ASSERT_TRUE(waitForWindowInfosPredicate(windowIsPresentAndTouchableRegionMatches));
}
} // namespace android
diff --git a/services/surfaceflinger/tests/tracing/TransactionTraceTestSuite.cpp b/services/surfaceflinger/tests/tracing/TransactionTraceTestSuite.cpp
index 0e214af..5f9214c 100644
--- a/services/surfaceflinger/tests/tracing/TransactionTraceTestSuite.cpp
+++ b/services/surfaceflinger/tests/tracing/TransactionTraceTestSuite.cpp
@@ -91,6 +91,8 @@
uint64_t curr_frame;
float x;
float y;
+ uint32_t bufferWidth;
+ uint32_t bufferHeight;
};
bool operator==(const LayerInfo& lh, const LayerInfo& rh) {
@@ -105,7 +107,8 @@
inline void PrintTo(const LayerInfo& info, ::std::ostream* os) {
*os << "Layer [" << info.id << "] name=" << info.name << " parent=" << info.parent
<< " z=" << info.z << " curr_frame=" << info.curr_frame << " x=" << info.x
- << " y=" << info.y;
+ << " y=" << info.y << " bufferWidth=" << info.bufferWidth
+ << " bufferHeight=" << info.bufferHeight;
}
struct find_id : std::unary_function<LayerInfo, bool> {
@@ -114,6 +117,18 @@
bool operator()(LayerInfo const& m) const { return m.id == id; }
};
+static LayerInfo getLayerInfoFromProto(::android::surfaceflinger::LayerProto& proto) {
+ return {proto.id(),
+ proto.name(),
+ proto.parent(),
+ proto.z(),
+ proto.curr_frame(),
+ proto.has_position() ? proto.position().x() : -1,
+ proto.has_position() ? proto.position().y() : -1,
+ proto.has_active_buffer() ? proto.active_buffer().width() : 0,
+ proto.has_active_buffer() ? proto.active_buffer().height() : 0};
+}
+
TEST_P(TransactionTraceTestSuite, validateEndState) {
ASSERT_GT(mActualLayersTraceProto.entry_size(), 0);
ASSERT_GT(mExpectedLayersTraceProto.entry_size(), 0);
@@ -128,10 +143,7 @@
expectedLayers.reserve(static_cast<size_t>(expectedLastEntry.layers().layers_size()));
for (int i = 0; i < expectedLastEntry.layers().layers_size(); i++) {
auto layer = expectedLastEntry.layers().layers(i);
- expectedLayers.push_back({layer.id(), layer.name(), layer.parent(), layer.z(),
- layer.curr_frame(),
- layer.has_position() ? layer.position().x() : -1,
- layer.has_position() ? layer.position().y() : -1});
+ expectedLayers.push_back(getLayerInfoFromProto(layer));
}
std::sort(expectedLayers.begin(), expectedLayers.end(), compareById);
@@ -139,10 +151,7 @@
actualLayers.reserve(static_cast<size_t>(actualLastEntry.layers().layers_size()));
for (int i = 0; i < actualLastEntry.layers().layers_size(); i++) {
auto layer = actualLastEntry.layers().layers(i);
- actualLayers.push_back({layer.id(), layer.name(), layer.parent(), layer.z(),
- layer.curr_frame(),
- layer.has_position() ? layer.position().x() : -1,
- layer.has_position() ? layer.position().y() : -1});
+ actualLayers.push_back(getLayerInfoFromProto(layer));
}
std::sort(actualLayers.begin(), actualLayers.end(), compareById);
diff --git a/services/surfaceflinger/tests/unittests/CompositionTest.cpp b/services/surfaceflinger/tests/unittests/CompositionTest.cpp
index 17ef6ff..19a93e1 100644
--- a/services/surfaceflinger/tests/unittests/CompositionTest.cpp
+++ b/services/surfaceflinger/tests/unittests/CompositionTest.cpp
@@ -284,13 +284,16 @@
constexpr auto kDisplayConnectionType = ui::DisplayConnectionType::Internal;
constexpr bool kIsPrimary = true;
- test->mDisplay = FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
- kDisplayConnectionType, HWC_DISPLAY, kIsPrimary)
- .setDisplaySurface(test->mDisplaySurface)
- .setNativeWindow(test->mNativeWindow)
- .setSecure(Derived::IS_SECURE)
- .setPowerMode(Derived::INIT_POWER_MODE)
- .inject();
+ test->mDisplay =
+ FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay,
+ kDisplayConnectionType, HWC_DISPLAY, kIsPrimary)
+ .setDisplaySurface(test->mDisplaySurface)
+ .setNativeWindow(test->mNativeWindow)
+ .setSecure(Derived::IS_SECURE)
+ .setPowerMode(Derived::INIT_POWER_MODE)
+ .setRefreshRateSelector(test->mFlinger.scheduler()->refreshRateSelector())
+ .skipRegisterDisplay()
+ .inject();
Mock::VerifyAndClear(test->mNativeWindow.get());
constexpr bool kIsInternal = kDisplayConnectionType == ui::DisplayConnectionType::Internal;
diff --git a/services/surfaceflinger/tests/unittests/SurfaceFlinger_PowerHintTest.cpp b/services/surfaceflinger/tests/unittests/SurfaceFlinger_PowerHintTest.cpp
index 9699fc2..7839ef0 100644
--- a/services/surfaceflinger/tests/unittests/SurfaceFlinger_PowerHintTest.cpp
+++ b/services/surfaceflinger/tests/unittests/SurfaceFlinger_PowerHintTest.cpp
@@ -92,6 +92,8 @@
.setDisplaySurface(mDisplaySurface)
.setNativeWindow(mNativeWindow)
.setPowerMode(hal::PowerMode::ON)
+ .setRefreshRateSelector(mFlinger.scheduler()->refreshRateSelector())
+ .skipRegisterDisplay()
.inject();
}
diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
index 4488038..0649333 100644
--- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
+++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
@@ -855,6 +855,11 @@
return *this;
}
+ auto& skipRegisterDisplay() {
+ mRegisterDisplay = false;
+ return *this;
+ }
+
sp<DisplayDevice> inject() NO_THREAD_SAFETY_ANALYSIS {
const auto displayId = mCreationArgs.compositionDisplay->getDisplayId();
@@ -918,7 +923,7 @@
ui::ColorModes(),
std::nullopt);
- if (mFlinger.scheduler()) {
+ if (mFlinger.scheduler() && mRegisterDisplay) {
mFlinger.scheduler()->registerDisplay(physicalId,
display->holdRefreshRateSelector());
}
@@ -937,6 +942,7 @@
sp<BBinder> mDisplayToken = sp<BBinder>::make();
DisplayDeviceCreationArgs mCreationArgs;
DisplayModes mDisplayModes;
+ bool mRegisterDisplay = true;
const std::optional<ui::DisplayConnectionType> mConnectionType;
const std::optional<hal::HWDisplayId> mHwcDisplayId;
};