Merge changes from topic "presubmit-am-12394aafba3f4f85823b8d6d9815f908"
* changes:
[automerged blank] Obviate libbinder_ndk_host_user. 2p: 5c4dd9ffb3
Obviate libbinder_ndk_host_user.
diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp
index b6f42ad..c796da6 100644
--- a/cmds/installd/dexopt.cpp
+++ b/cmds/installd/dexopt.cpp
@@ -244,7 +244,7 @@
// The location is the profile name for primary apks or the dex path for secondary dex files.
bool clear_primary_current_profiles(const std::string& package_name, const std::string& location) {
bool success = true;
- // For secondary dex files, we don't really need the user but we use it for sanity checks.
+ // For secondary dex files, we don't really need the user but we use it for validity checks.
std::vector<userid_t> users = get_known_users(/*volume_uuid*/ nullptr);
for (auto user : users) {
success &= clear_current_profile(package_name, location, user, /*is_secondary_dex*/false);
@@ -468,7 +468,7 @@
*reference_profile_fd = open_reference_profile(uid, package_name, location,
/*read_write*/ true, is_secondary_dex);
- // For secondary dex files, we don't really need the user but we use it for sanity checks.
+ // For secondary dex files, we don't really need the user but we use it for validity checks.
// Note: the user owning the dex file should be the current user.
std::vector<userid_t> users;
if (is_secondary_dex){
diff --git a/cmds/installd/utils.cpp b/cmds/installd/utils.cpp
index c4ecd07..0f8a732 100644
--- a/cmds/installd/utils.cpp
+++ b/cmds/installd/utils.cpp
@@ -829,7 +829,7 @@
* to top level directories (i.e. have "..").
*/
static int validate_path(const std::string& dir, const std::string& path, int maxSubdirs) {
- // Argument sanity checking
+ // Argument check
if (dir.find('/') != 0 || dir.rfind('/') != dir.size() - 1
|| dir.find("..") != std::string::npos) {
LOG(ERROR) << "Invalid directory " << dir;
diff --git a/cmds/service/service.cpp b/cmds/service/service.cpp
index fe417a3..d5ca725 100644
--- a/cmds/service/service.cpp
+++ b/cmds/service/service.cpp
@@ -21,6 +21,7 @@
#include <cutils/ashmem.h>
#include <getopt.h>
+#include <libgen.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
diff --git a/include/android/bitmap.h b/include/android/bitmap.h
index 6704a1d..35f87f9 100644
--- a/include/android/bitmap.h
+++ b/include/android/bitmap.h
@@ -68,6 +68,8 @@
ANDROID_BITMAP_FORMAT_A_8 = 8,
/** Each component is stored as a half float. **/
ANDROID_BITMAP_FORMAT_RGBA_F16 = 9,
+ /** Red: 10 bits, Green: 10 bits, Blue: 10 bits, Alpha: 2 bits. **/
+ ANDROID_BITMAP_FORMAT_RGBA_1010102 = 10,
};
/** Bitmap alpha format */
diff --git a/include/android/performance_hint.h b/include/android/performance_hint.h
new file mode 100644
index 0000000..5fa47f6
--- /dev/null
+++ b/include/android/performance_hint.h
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_NATIVE_PERFORMANCE_HINT_H
+#define ANDROID_NATIVE_PERFORMANCE_HINT_H
+
+#include <sys/cdefs.h>
+
+/******************************************************************
+ *
+ * IMPORTANT NOTICE:
+ *
+ * This file is part of Android's set of stable system headers
+ * exposed by the Android NDK (Native Development Kit).
+ *
+ * Third-party source AND binary code relies on the definitions
+ * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
+ *
+ * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
+ * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
+ * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
+ * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
+ */
+
+#include <android/api-level.h>
+#include <stdint.h>
+
+__BEGIN_DECLS
+
+struct APerformanceHintManager;
+struct APerformanceHintSession;
+
+/**
+ * An opaque type representing a handle to a performance hint manager.
+ * It must be released after use.
+ *
+ * <p>To use:<ul>
+ * <li>Obtain the performance hint manager instance by calling
+ * {@link APerformanceHint_getManager} function.</li>
+ * <li>Create an {@link APerformanceHintSession} with
+ * {@link APerformanceHint_createSession}.</li>
+ * <li>Get the preferred update rate in nanoseconds with
+ * {@link APerformanceHint_getPreferredUpdateRateNanos}.</li>
+ */
+typedef struct APerformanceHintManager APerformanceHintManager;
+
+/**
+ * An opaque type representing a handle to a performance hint session.
+ * A session can only be acquired from a {@link APerformanceHintManager}
+ * with {@link APerformanceHint_getPreferredUpdateRateNanos}. It must be
+ * freed with {@link APerformanceHint_closeSession} after use.
+ *
+ * A Session represents a group of threads with an inter-related workload such that hints for
+ * their performance should be considered as a unit. The threads in a given session should be
+ * long-life and not created or destroyed dynamically.
+ *
+ * <p>Each session is expected to have a periodic workload with a target duration for each
+ * cycle. The cycle duration is likely greater than the target work duration to allow other
+ * parts of the pipeline to run within the available budget. For example, a renderer thread may
+ * work at 60hz in order to produce frames at the display's frame but have a target work
+ * duration of only 6ms.</p>
+ *
+ * <p>After each cycle of work, the client is expected to use
+ * {@link APerformanceHint_reportActualWorkDuration} to report the actual time taken to
+ * complete.</p>
+ *
+ * <p>To use:<ul>
+ * <li>Update a sessions target duration for each cycle of work
+ * with {@link APerformanceHint_updateTargetWorkDuration}.</li>
+ * <li>Report the actual duration for the last cycle of work with
+ * {@link APerformanceHint_reportActualWorkDuration}.</li>
+ * <li>Release the session instance with
+ * {@link APerformanceHint_closeSession}.</li></ul></p>
+ */
+typedef struct APerformanceHintSession APerformanceHintSession;
+
+/**
+ * Acquire an instance of the performance hint manager.
+ *
+ * @return manager instance on success, nullptr on failure.
+ */
+APerformanceHintManager* APerformanceHint_getManager() __INTRODUCED_IN(__ANDROID_API_T__);
+
+/**
+ * Creates a session for the given set of threads and sets their initial target work
+ * duration.
+ * @param manager The performance hint manager instance.
+ * @param threadIds The list of threads to be associated with this session. They must be part of
+ * this app's thread group.
+ * @param size the size of threadIds.
+ * @param initialTargetWorkDurationNanos The desired duration in nanoseconds for the new session.
+ * This must be positive.
+ * @return manager instance on success, nullptr on failure.
+ */
+APerformanceHintSession* APerformanceHint_createSession(
+ APerformanceHintManager* manager,
+ const int32_t* threadIds, size_t size,
+ int64_t initialTargetWorkDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__);
+
+/**
+ * Get preferred update rate information for this device.
+ *
+ * @param manager The performance hint manager instance.
+ * @return the preferred update rate supported by device software.
+ */
+int64_t APerformanceHint_getPreferredUpdateRateNanos(
+ APerformanceHintManager* manager) __INTRODUCED_IN(__ANDROID_API_T__);
+
+/**
+ * Updates this session's target duration for each cycle of work.
+ *
+ * @param session The performance hint session instance to update.
+ * @param targetDurationNanos the new desired duration in nanoseconds. This must be positive.
+ * @return 0 on success
+ * EINVAL if targetDurationNanos is not positive.
+ * EPIPE if communication with the system service has failed.
+ */
+int APerformanceHint_updateTargetWorkDuration(
+ APerformanceHintSession* session,
+ int64_t targetDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__);
+
+/**
+ * Reports the actual duration for the last cycle of work.
+ *
+ * <p>The system will attempt to adjust the core placement of the threads within the thread
+ * group and/or the frequency of the core on which they are run to bring the actual duration
+ * close to the target duration.</p>
+ *
+ * @param session The performance hint session instance to update.
+ * @param actualDurationNanos how long the thread group took to complete its last task in
+ * nanoseconds. This must be positive.
+ * @return 0 on success
+ * EINVAL if actualDurationNanos is not positive.
+ * EPIPE if communication with the system service has failed.
+ */
+int APerformanceHint_reportActualWorkDuration(
+ APerformanceHintSession* session,
+ int64_t actualDurationNanos) __INTRODUCED_IN(__ANDROID_API_T__);
+
+/**
+ * Release the performance hint manager pointer acquired via
+ * {@link APerformanceHint_createSession}.
+ *
+ * @param session The performance hint session instance to release.
+ */
+void APerformanceHint_closeSession(
+ APerformanceHintSession* session) __INTRODUCED_IN(__ANDROID_API_T__);
+
+__END_DECLS
+
+#endif // ANDROID_NATIVE_PERFORMANCE_HINT_H
diff --git a/include/private/performance_hint_private.h b/include/private/performance_hint_private.h
index 5832bf4..f27f5f1 100644
--- a/include/private/performance_hint_private.h
+++ b/include/private/performance_hint_private.h
@@ -17,124 +17,8 @@
#ifndef ANDROID_PRIVATE_NATIVE_PERFORMANCE_HINT_PRIVATE_H
#define ANDROID_PRIVATE_NATIVE_PERFORMANCE_HINT_PRIVATE_H
-#include <stdint.h>
-
__BEGIN_DECLS
-struct APerformanceHintManager;
-struct APerformanceHintSession;
-
-/**
- * An opaque type representing a handle to a performance hint manager.
- * It must be released after use.
- *
- * <p>To use:<ul>
- * <li>Obtain the performance hint manager instance by calling
- * {@link APerformanceHint_getManager} function.</li>
- * <li>Create an {@link APerformanceHintSession} with
- * {@link APerformanceHint_createSession}.</li>
- * <li>Get the preferred update rate in nanoseconds with
- * {@link APerformanceHint_getPreferredUpdateRateNanos}.</li>
- */
-typedef struct APerformanceHintManager APerformanceHintManager;
-
-/**
- * An opaque type representing a handle to a performance hint session.
- * A session can only be acquired from a {@link APerformanceHintManager}
- * with {@link APerformanceHint_getPreferredUpdateRateNanos}. It must be
- * freed with {@link APerformanceHint_closeSession} after use.
- *
- * A Session represents a group of threads with an inter-related workload such that hints for
- * their performance should be considered as a unit. The threads in a given session should be
- * long-life and not created or destroyed dynamically.
- *
- * <p>Each session is expected to have a periodic workload with a target duration for each
- * cycle. The cycle duration is likely greater than the target work duration to allow other
- * parts of the pipeline to run within the available budget. For example, a renderer thread may
- * work at 60hz in order to produce frames at the display's frame but have a target work
- * duration of only 6ms.</p>
- *
- * <p>After each cycle of work, the client is expected to use
- * {@link APerformanceHint_reportActualWorkDuration} to report the actual time taken to
- * complete.</p>
- *
- * <p>To use:<ul>
- * <li>Update a sessions target duration for each cycle of work
- * with {@link APerformanceHint_updateTargetWorkDuration}.</li>
- * <li>Report the actual duration for the last cycle of work with
- * {@link APerformanceHint_reportActualWorkDuration}.</li>
- * <li>Release the session instance with
- * {@link APerformanceHint_closeSession}.</li></ul></p>
- */
-typedef struct APerformanceHintSession APerformanceHintSession;
-
-/**
- * Acquire an instance of the performance hint manager.
- *
- * @return manager instance on success, nullptr on failure.
- */
-APerformanceHintManager* APerformanceHint_getManager();
-
-/**
- * Creates a session for the given set of threads and sets their initial target work
- * duration.
- * @param manager The performance hint manager instance.
- * @param threadIds The list of threads to be associated with this session. They must be part of
- * this app's thread group.
- * @param size the size of threadIds.
- * @param initialTargetWorkDurationNanos The desired duration in nanoseconds for the new session.
- * This must be positive.
- * @return manager instance on success, nullptr on failure.
- */
-APerformanceHintSession* APerformanceHint_createSession(APerformanceHintManager* manager,
- const int32_t* threadIds, size_t size,
- int64_t initialTargetWorkDurationNanos);
-
-/**
- * Get preferred update rate information for this device.
- *
- * @param manager The performance hint manager instance.
- * @return the preferred update rate supported by device software.
- */
-int64_t APerformanceHint_getPreferredUpdateRateNanos(APerformanceHintManager* manager);
-
-/**
- * Updates this session's target duration for each cycle of work.
- *
- * @param session The performance hint session instance to update.
- * @param targetDurationNanos the new desired duration in nanoseconds. This must be positive.
- * @return 0 on success
- * EINVAL if targetDurationNanos is not positive.
- * EPIPE if communication with the system service has failed.
- */
-int APerformanceHint_updateTargetWorkDuration(APerformanceHintSession* session,
- int64_t targetDurationNanos);
-
-/**
- * Reports the actual duration for the last cycle of work.
- *
- * <p>The system will attempt to adjust the core placement of the threads within the thread
- * group and/or the frequency of the core on which they are run to bring the actual duration
- * close to the target duration.</p>
- *
- * @param session The performance hint session instance to update.
- * @param actualDurationNanos how long the thread group took to complete its last task in
- * nanoseconds. This must be positive.
- * @return 0 on success
- * EINVAL if actualDurationNanos is not positive.
- * EPIPE if communication with the system service has failed.
- */
-int APerformanceHint_reportActualWorkDuration(APerformanceHintSession* session,
- int64_t actualDurationNanos);
-
-/**
- * Release the performance hint manager pointer acquired via
- * {@link APerformanceHint_createSession}.
- *
- * @param session The performance hint session instance to release.
- */
-void APerformanceHint_closeSession(APerformanceHintSession* session);
-
/**
* For testing only.
*/
diff --git a/libs/binder/RpcState.cpp b/libs/binder/RpcState.cpp
index 6286c9c..4ddbce7 100644
--- a/libs/binder/RpcState.cpp
+++ b/libs/binder/RpcState.cpp
@@ -310,9 +310,9 @@
}
status_t RpcState::rpcSend(const sp<RpcSession::RpcConnection>& connection,
- const sp<RpcSession>& session, const char* what, iovec* iovs,
- size_t niovs, const std::function<status_t()>& altPoll) {
- for (size_t i = 0; i < niovs; i++) {
+ const sp<RpcSession>& session, const char* what, iovec* iovs, int niovs,
+ const std::function<status_t()>& altPoll) {
+ for (int i = 0; i < niovs; i++) {
LOG_RPC_DETAIL("Sending %s on RpcTransport %p: %s", what, connection->rpcTransport.get(),
android::base::HexString(iovs[i].iov_base, iovs[i].iov_len).c_str());
}
@@ -321,7 +321,7 @@
connection->rpcTransport->interruptableWriteFully(session->mShutdownTrigger.get(),
iovs, niovs, altPoll);
status != OK) {
- LOG_RPC_DETAIL("Failed to write %s (%zu iovs) on RpcTransport %p, error: %s", what, niovs,
+ LOG_RPC_DETAIL("Failed to write %s (%d iovs) on RpcTransport %p, error: %s", what, niovs,
connection->rpcTransport.get(), statusToString(status).c_str());
(void)session->shutdownAndWait(false);
return status;
@@ -331,19 +331,18 @@
}
status_t RpcState::rpcRec(const sp<RpcSession::RpcConnection>& connection,
- const sp<RpcSession>& session, const char* what, iovec* iovs,
- size_t niovs) {
+ const sp<RpcSession>& session, const char* what, iovec* iovs, int niovs) {
if (status_t status =
connection->rpcTransport->interruptableReadFully(session->mShutdownTrigger.get(),
iovs, niovs, {});
status != OK) {
- LOG_RPC_DETAIL("Failed to read %s (%zu iovs) on RpcTransport %p, error: %s", what, niovs,
+ LOG_RPC_DETAIL("Failed to read %s (%d iovs) on RpcTransport %p, error: %s", what, niovs,
connection->rpcTransport.get(), statusToString(status).c_str());
(void)session->shutdownAndWait(false);
return status;
}
- for (size_t i = 0; i < niovs; i++) {
+ for (int i = 0; i < niovs; i++) {
LOG_RPC_DETAIL("Received %s on RpcTransport %p: %s", what, connection->rpcTransport.get(),
android::base::HexString(iovs[i].iov_base, iovs[i].iov_len).c_str());
}
diff --git a/libs/binder/RpcState.h b/libs/binder/RpcState.h
index 5cad394..f4a0894 100644
--- a/libs/binder/RpcState.h
+++ b/libs/binder/RpcState.h
@@ -180,11 +180,10 @@
[[nodiscard]] status_t rpcSend(const sp<RpcSession::RpcConnection>& connection,
const sp<RpcSession>& session, const char* what, iovec* iovs,
- size_t niovs,
- const std::function<status_t()>& altPoll = nullptr);
+ int niovs, const std::function<status_t()>& altPoll = nullptr);
[[nodiscard]] status_t rpcRec(const sp<RpcSession::RpcConnection>& connection,
const sp<RpcSession>& session, const char* what, iovec* iovs,
- size_t niovs);
+ int niovs);
[[nodiscard]] status_t waitForReply(const sp<RpcSession::RpcConnection>& connection,
const sp<RpcSession>& session, Parcel* reply);
diff --git a/libs/binder/RpcTransportRaw.cpp b/libs/binder/RpcTransportRaw.cpp
index 2182e18..636e5d0 100644
--- a/libs/binder/RpcTransportRaw.cpp
+++ b/libs/binder/RpcTransportRaw.cpp
@@ -44,11 +44,15 @@
}
template <typename SendOrReceive>
- status_t interruptableReadOrWrite(FdTrigger* fdTrigger, iovec* iovs, size_t niovs,
+ status_t interruptableReadOrWrite(FdTrigger* fdTrigger, iovec* iovs, int niovs,
SendOrReceive sendOrReceiveFun, const char* funName,
int16_t event, const std::function<status_t()>& altPoll) {
MAYBE_WAIT_IN_FLAKE_MODE;
+ if (niovs < 0) {
+ return BAD_VALUE;
+ }
+
// Since we didn't poll, we need to manually check to see if it was triggered. Otherwise, we
// may never know we should be shutting down.
if (fdTrigger->isTriggered()) {
@@ -74,7 +78,9 @@
while (true) {
msghdr msg{
.msg_iov = iovs,
- .msg_iovlen = niovs,
+ // posix uses int, glibc uses size_t. niovs is a
+ // non-negative int and can be cast to either.
+ .msg_iovlen = static_cast<decltype(msg.msg_iovlen)>(niovs),
};
ssize_t processSize =
TEMP_FAILURE_RETRY(sendOrReceiveFun(mSocket.get(), &msg, MSG_NOSIGNAL));
@@ -128,13 +134,13 @@
}
}
- status_t interruptableWriteFully(FdTrigger* fdTrigger, iovec* iovs, size_t niovs,
+ status_t interruptableWriteFully(FdTrigger* fdTrigger, iovec* iovs, int niovs,
const std::function<status_t()>& altPoll) override {
return interruptableReadOrWrite(fdTrigger, iovs, niovs, sendmsg, "sendmsg", POLLOUT,
altPoll);
}
- status_t interruptableReadFully(FdTrigger* fdTrigger, iovec* iovs, size_t niovs,
+ status_t interruptableReadFully(FdTrigger* fdTrigger, iovec* iovs, int niovs,
const std::function<status_t()>& altPoll) override {
return interruptableReadOrWrite(fdTrigger, iovs, niovs, recvmsg, "recvmsg", POLLIN,
altPoll);
diff --git a/libs/binder/RpcTransportTls.cpp b/libs/binder/RpcTransportTls.cpp
index c05ea15..3936204 100644
--- a/libs/binder/RpcTransportTls.cpp
+++ b/libs/binder/RpcTransportTls.cpp
@@ -275,9 +275,9 @@
RpcTransportTls(android::base::unique_fd socket, Ssl ssl)
: mSocket(std::move(socket)), mSsl(std::move(ssl)) {}
Result<size_t> peek(void* buf, size_t size) override;
- status_t interruptableWriteFully(FdTrigger* fdTrigger, iovec* iovs, size_t niovs,
+ status_t interruptableWriteFully(FdTrigger* fdTrigger, iovec* iovs, int niovs,
const std::function<status_t()>& altPoll) override;
- status_t interruptableReadFully(FdTrigger* fdTrigger, iovec* iovs, size_t niovs,
+ status_t interruptableReadFully(FdTrigger* fdTrigger, iovec* iovs, int niovs,
const std::function<status_t()>& altPoll) override;
private:
@@ -303,16 +303,18 @@
return ret;
}
-status_t RpcTransportTls::interruptableWriteFully(FdTrigger* fdTrigger, iovec* iovs, size_t niovs,
+status_t RpcTransportTls::interruptableWriteFully(FdTrigger* fdTrigger, iovec* iovs, int niovs,
const std::function<status_t()>& altPoll) {
MAYBE_WAIT_IN_FLAKE_MODE;
+ if (niovs < 0) return BAD_VALUE;
+
// Before doing any I/O, check trigger once. This ensures the trigger is checked at least
// once. The trigger is also checked via triggerablePoll() after every SSL_write().
if (fdTrigger->isTriggered()) return DEAD_OBJECT;
size_t size = 0;
- for (size_t i = 0; i < niovs; i++) {
+ for (int i = 0; i < niovs; i++) {
const iovec& iov = iovs[i];
if (iov.iov_len == 0) {
continue;
@@ -343,16 +345,18 @@
return OK;
}
-status_t RpcTransportTls::interruptableReadFully(FdTrigger* fdTrigger, iovec* iovs, size_t niovs,
+status_t RpcTransportTls::interruptableReadFully(FdTrigger* fdTrigger, iovec* iovs, int niovs,
const std::function<status_t()>& altPoll) {
MAYBE_WAIT_IN_FLAKE_MODE;
+ if (niovs < 0) return BAD_VALUE;
+
// Before doing any I/O, check trigger once. This ensures the trigger is checked at least
// once. The trigger is also checked via triggerablePoll() after every SSL_write().
if (fdTrigger->isTriggered()) return DEAD_OBJECT;
size_t size = 0;
- for (size_t i = 0; i < niovs; i++) {
+ for (int i = 0; i < niovs; i++) {
const iovec& iov = iovs[i];
if (iov.iov_len == 0) {
continue;
diff --git a/libs/binder/include/binder/RpcTransport.h b/libs/binder/include/binder/RpcTransport.h
index 348bfeb..ade2d94 100644
--- a/libs/binder/include/binder/RpcTransport.h
+++ b/libs/binder/include/binder/RpcTransport.h
@@ -58,10 +58,10 @@
* error - interrupted (failure or trigger)
*/
[[nodiscard]] virtual status_t interruptableWriteFully(
- FdTrigger *fdTrigger, iovec *iovs, size_t niovs,
+ FdTrigger *fdTrigger, iovec *iovs, int niovs,
const std::function<status_t()> &altPoll) = 0;
[[nodiscard]] virtual status_t interruptableReadFully(
- FdTrigger *fdTrigger, iovec *iovs, size_t niovs,
+ FdTrigger *fdTrigger, iovec *iovs, int niovs,
const std::function<status_t()> &altPoll) = 0;
protected:
diff --git a/libs/binder/rust/Android.bp b/libs/binder/rust/Android.bp
index 90cbf9d..355b3b4 100644
--- a/libs/binder/rust/Android.bp
+++ b/libs/binder/rust/Android.bp
@@ -44,6 +44,7 @@
"libtokio",
],
host_supported: true,
+ vendor_available: true,
target: {
darwin: {
enabled: false,
@@ -52,8 +53,10 @@
apex_available: [
"//apex_available:platform",
"com.android.compos",
+ "com.android.uwb",
"com.android.virt",
],
+ min_sdk_version: "Tiramisu",
}
rust_library {
diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp
index b7594df..fb9ed22 100644
--- a/libs/gui/ISurfaceComposer.cpp
+++ b/libs/gui/ISurfaceComposer.cpp
@@ -495,27 +495,6 @@
return result;
}
- status_t getPreferredBootDisplayMode(const sp<IBinder>& display,
- ui::DisplayModeId* displayModeId) override {
- Parcel data, reply;
- status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
- if (result != NO_ERROR) {
- ALOGE("getPreferredBootDisplayMode failed to writeInterfaceToken: %d", result);
- return result;
- }
- result = data.writeStrongBinder(display);
- if (result != NO_ERROR) {
- ALOGE("getPreferredBootDisplayMode failed to writeStrongBinder: %d", result);
- return result;
- }
- result = remote()->transact(BnSurfaceComposer::GET_PREFERRED_BOOT_DISPLAY_MODE, data,
- &reply);
- if (result == NO_ERROR) {
- reply.writeInt32(*displayModeId);
- }
- return result;
- }
-
void setAutoLowLatencyMode(const sp<IBinder>& display, bool on) override {
Parcel data, reply;
status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
@@ -1659,21 +1638,6 @@
}
return clearBootDisplayMode(display);
}
- case GET_PREFERRED_BOOT_DISPLAY_MODE: {
- CHECK_INTERFACE(ISurfaceComposer, data, reply);
- sp<IBinder> display = nullptr;
- status_t result = data.readStrongBinder(&display);
- if (result != NO_ERROR) {
- ALOGE("getPreferredBootDisplayMode failed to readStrongBinder: %d", result);
- return result;
- }
- ui::DisplayModeId displayModeId;
- result = getPreferredBootDisplayMode(display, &displayModeId);
- if (result == NO_ERROR) {
- reply->writeInt32(displayModeId);
- }
- return result;
- }
case SET_AUTO_LOW_LATENCY_MODE: {
CHECK_INTERFACE(ISurfaceComposer, data, reply);
sp<IBinder> display = nullptr;
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index a7b2bcd..91b2fb1 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -2094,12 +2094,6 @@
return ComposerService::getComposerService()->clearBootDisplayMode(display);
}
-status_t SurfaceComposerClient::getPreferredBootDisplayMode(const sp<IBinder>& display,
- ui::DisplayModeId* displayModeId) {
- return ComposerService::getComposerService()->getPreferredBootDisplayMode(display,
- displayModeId);
-}
-
status_t SurfaceComposerClient::setOverrideFrameRate(uid_t uid, float frameRate) {
return ComposerService::getComposerService()->setOverrideFrameRate(uid, frameRate);
}
diff --git a/libs/gui/WindowInfo.cpp b/libs/gui/WindowInfo.cpp
index 8d356aa..1c7b270 100644
--- a/libs/gui/WindowInfo.cpp
+++ b/libs/gui/WindowInfo.cpp
@@ -52,7 +52,8 @@
}
bool WindowInfo::overlaps(const WindowInfo* other) const {
- return frameLeft < other->frameRight && frameRight > other->frameLeft &&
+ const bool nonEmpty = (frameRight - frameLeft > 0) || (frameBottom - frameTop > 0);
+ return nonEmpty && frameLeft < other->frameRight && frameRight > other->frameLeft &&
frameTop < other->frameBottom && frameBottom > other->frameTop;
}
diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h
index fb4fb7e..4b5cee2 100644
--- a/libs/gui/include/gui/ISurfaceComposer.h
+++ b/libs/gui/include/gui/ISurfaceComposer.h
@@ -235,12 +235,6 @@
virtual status_t clearBootDisplayMode(const sp<IBinder>& display) = 0;
/**
- * Gets the display mode in which the device boots if there is no user-preferred display mode.
- */
- virtual status_t getPreferredBootDisplayMode(const sp<IBinder>& display,
- ui::DisplayModeId*) = 0;
-
- /**
* Gets whether boot time display mode operations are supported on the device.
*
* outSupport
@@ -684,7 +678,6 @@
GET_BOOT_DISPLAY_MODE_SUPPORT,
SET_BOOT_DISPLAY_MODE,
CLEAR_BOOT_DISPLAY_MODE,
- GET_PREFERRED_BOOT_DISPLAY_MODE,
SET_OVERRIDE_FRAME_RATE,
// Always append new enum to the end.
};
diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h
index 366577d..61eeab3 100644
--- a/libs/gui/include/gui/SurfaceComposerClient.h
+++ b/libs/gui/include/gui/SurfaceComposerClient.h
@@ -174,8 +174,7 @@
static status_t setBootDisplayMode(const sp<IBinder>& display, ui::DisplayModeId);
// Clears the user-preferred display mode
static status_t clearBootDisplayMode(const sp<IBinder>& display);
- // Gets the display mode in which the device boots if there is no user-preferred display mode
- static status_t getPreferredBootDisplayMode(const sp<IBinder>& display, ui::DisplayModeId*);
+
// Sets the frame rate of a particular app (uid). This is currently called
// by GameManager.
static status_t setOverrideFrameRate(uid_t uid, float frameRate);
diff --git a/libs/gui/tests/EndToEndNativeInputTest.cpp b/libs/gui/tests/EndToEndNativeInputTest.cpp
index 6f1263b..06a0aca 100644
--- a/libs/gui/tests/EndToEndNativeInputTest.cpp
+++ b/libs/gui/tests/EndToEndNativeInputTest.cpp
@@ -546,7 +546,10 @@
}
TEST_F(InputSurfacesTest, input_respects_scaled_surface_insets_overflow) {
+ std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100);
+ bgSurface->showAt(100, 100);
+
// In case we pass the very big inset without any checking.
fgSurface->mInputInfo.surfaceInset = INT32_MAX;
fgSurface->showAt(100, 100);
@@ -554,8 +557,8 @@
fgSurface->doTransaction([&](auto &t, auto &sc) { t.setMatrix(sc, 2.0, 0, 0, 2.0); });
// expect no crash for overflow, and inset size to be clamped to surface size
- injectTap(202, 202);
- fgSurface->expectTap(1, 1);
+ injectTap(112, 124);
+ bgSurface->expectTap(12, 24);
}
// Ensure we ignore transparent region when getting screen bounds when positioning input frame.
@@ -987,6 +990,107 @@
EXPECT_EQ(surface->consumeEvent(100), nullptr);
}
+TEST_F(InputSurfacesTest, layer_with_empty_crop_cannot_be_focused) {
+ std::unique_ptr<InputSurface> bufferSurface =
+ InputSurface::makeBufferInputSurface(mComposerClient, 100, 100);
+
+ bufferSurface->showAt(50, 50, Rect::EMPTY_RECT);
+
+ bufferSurface->requestFocus();
+ EXPECT_EQ(bufferSurface->consumeEvent(100), nullptr);
+
+ bufferSurface->showAt(50, 50, Rect::INVALID_RECT);
+
+ bufferSurface->requestFocus();
+ EXPECT_EQ(bufferSurface->consumeEvent(100), nullptr);
+}
+
+TEST_F(InputSurfacesTest, layer_with_valid_crop_can_be_focused) {
+ std::unique_ptr<InputSurface> bufferSurface =
+ InputSurface::makeBufferInputSurface(mComposerClient, 100, 100);
+
+ bufferSurface->showAt(50, 50, Rect{0, 0, 100, 100});
+
+ bufferSurface->requestFocus();
+ bufferSurface->assertFocusChange(true);
+}
+
+/**
+ * If a cropped layer's touchable region is replaced with a null crop, it should receive input in
+ * its own crop.
+ */
+TEST_F(InputSurfacesTest, cropped_container_replaces_touchable_region_with_null_crop) {
+ std::unique_ptr<InputSurface> parentContainer =
+ InputSurface::makeContainerInputSurface(mComposerClient, 0, 0);
+ std::unique_ptr<InputSurface> containerSurface =
+ InputSurface::makeContainerInputSurface(mComposerClient, 100, 100);
+ containerSurface->doTransaction(
+ [&](auto &t, auto &sc) { t.reparent(sc, parentContainer->mSurfaceControl); });
+ containerSurface->mInputInfo.replaceTouchableRegionWithCrop = true;
+ containerSurface->mInputInfo.touchableRegionCropHandle = nullptr;
+ parentContainer->showAt(10, 10, Rect(0, 0, 20, 20));
+ containerSurface->showAt(10, 10, Rect(0, 0, 5, 5));
+
+ // Receives events inside its own crop
+ injectTap(21, 21);
+ containerSurface->expectTap(1, 1); // Event is in layer space
+
+ // Does not receive events outside its crop
+ injectTap(26, 26);
+ EXPECT_EQ(containerSurface->consumeEvent(100), nullptr);
+}
+
+/**
+ * If an un-cropped layer's touchable region is replaced with a null crop, it should receive input
+ * in its parent's touchable region. The input events should be in the layer's coordinate space.
+ */
+TEST_F(InputSurfacesTest, uncropped_container_replaces_touchable_region_with_null_crop) {
+ std::unique_ptr<InputSurface> parentContainer =
+ InputSurface::makeContainerInputSurface(mComposerClient, 0, 0);
+ std::unique_ptr<InputSurface> containerSurface =
+ InputSurface::makeContainerInputSurface(mComposerClient, 100, 100);
+ containerSurface->doTransaction(
+ [&](auto &t, auto &sc) { t.reparent(sc, parentContainer->mSurfaceControl); });
+ containerSurface->mInputInfo.replaceTouchableRegionWithCrop = true;
+ containerSurface->mInputInfo.touchableRegionCropHandle = nullptr;
+ parentContainer->showAt(10, 10, Rect(0, 0, 20, 20));
+ containerSurface->showAt(10, 10, Rect::INVALID_RECT);
+
+ // Receives events inside parent bounds
+ injectTap(21, 21);
+ containerSurface->expectTap(1, 1); // Event is in layer space
+
+ // Does not receive events outside parent bounds
+ injectTap(31, 31);
+ EXPECT_EQ(containerSurface->consumeEvent(100), nullptr);
+}
+
+/**
+ * If a layer's touchable region is replaced with a layer crop, it should receive input in the crop
+ * layer's bounds. The input events should be in the layer's coordinate space.
+ */
+TEST_F(InputSurfacesTest, replace_touchable_region_with_crop) {
+ std::unique_ptr<InputSurface> cropLayer =
+ InputSurface::makeContainerInputSurface(mComposerClient, 0, 0);
+ cropLayer->showAt(50, 50, Rect(0, 0, 20, 20));
+
+ std::unique_ptr<InputSurface> containerSurface =
+ InputSurface::makeContainerInputSurface(mComposerClient, 100, 100);
+ containerSurface->mInputInfo.replaceTouchableRegionWithCrop = true;
+ containerSurface->mInputInfo.touchableRegionCropHandle =
+ cropLayer->mSurfaceControl->getHandle();
+ containerSurface->showAt(10, 10, Rect::INVALID_RECT);
+
+ // Receives events inside crop layer bounds
+ injectTap(51, 51);
+ containerSurface->expectTap(41, 41); // Event is in layer space
+
+ // Does not receive events outside crop layer bounds
+ injectTap(21, 21);
+ injectTap(71, 71);
+ EXPECT_EQ(containerSurface->consumeEvent(100), nullptr);
+}
+
class MultiDisplayTests : public InputSurfacesTest {
public:
MultiDisplayTests() : InputSurfacesTest() { ProcessState::self()->startThreadPool(); }
diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp
index 0ebd11c..120ed48 100644
--- a/libs/gui/tests/Surface_test.cpp
+++ b/libs/gui/tests/Surface_test.cpp
@@ -762,10 +762,6 @@
return NO_ERROR;
}
status_t clearBootDisplayMode(const sp<IBinder>& /*display*/) override { return NO_ERROR; }
- status_t getPreferredBootDisplayMode(const sp<IBinder>& /*display*/,
- ui::DisplayModeId* /*id*/) override {
- return NO_ERROR;
- }
void setAutoLowLatencyMode(const sp<IBinder>& /*display*/, bool /*on*/) override {}
void setGameContentType(const sp<IBinder>& /*display*/, bool /*on*/) override {}
diff --git a/libs/input/Android.bp b/libs/input/Android.bp
index e73c3b8..930d819 100644
--- a/libs/input/Android.bp
+++ b/libs/input/Android.bp
@@ -35,6 +35,7 @@
cc_library {
name: "libinput",
+ cpp_std: "c++20",
host_supported: true,
cflags: [
"-Wall",
diff --git a/libs/nativewindow/AHardwareBuffer.cpp b/libs/nativewindow/AHardwareBuffer.cpp
index cb3361b..2578ee8 100644
--- a/libs/nativewindow/AHardwareBuffer.cpp
+++ b/libs/nativewindow/AHardwareBuffer.cpp
@@ -509,10 +509,6 @@
ALOGE_IF(log, "AHARDWAREBUFFER_USAGE_SENSOR_DIRECT_DATA requires AHARDWAREBUFFER_FORMAT_BLOB");
return false;
}
- if (desc->usage & AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER) {
- ALOGE_IF(log, "AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER requires AHARDWAREBUFFER_FORMAT_BLOB");
- return false;
- }
}
if ((desc->usage & (AHARDWAREBUFFER_USAGE_CPU_READ_MASK | AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK)) &&
diff --git a/libs/ui/DynamicDisplayInfo.cpp b/libs/ui/DynamicDisplayInfo.cpp
index d5c4ef0..78ba996 100644
--- a/libs/ui/DynamicDisplayInfo.cpp
+++ b/libs/ui/DynamicDisplayInfo.cpp
@@ -41,7 +41,8 @@
FlattenableHelpers::getFlattenedSize(activeColorMode) +
FlattenableHelpers::getFlattenedSize(hdrCapabilities) +
FlattenableHelpers::getFlattenedSize(autoLowLatencyModeSupported) +
- FlattenableHelpers::getFlattenedSize(gameContentTypeSupported);
+ FlattenableHelpers::getFlattenedSize(gameContentTypeSupported) +
+ FlattenableHelpers::getFlattenedSize(preferredBootDisplayMode);
}
status_t DynamicDisplayInfo::flatten(void* buffer, size_t size) const {
@@ -55,6 +56,7 @@
RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, hdrCapabilities));
RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, autoLowLatencyModeSupported));
RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, gameContentTypeSupported));
+ RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, preferredBootDisplayMode));
return OK;
}
@@ -66,6 +68,7 @@
RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &hdrCapabilities));
RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &autoLowLatencyModeSupported));
RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &gameContentTypeSupported));
+ RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &preferredBootDisplayMode));
return OK;
}
diff --git a/libs/ui/Gralloc2.cpp b/libs/ui/Gralloc2.cpp
index 040a62b..f23f10a 100644
--- a/libs/ui/Gralloc2.cpp
+++ b/libs/ui/Gralloc2.cpp
@@ -110,6 +110,15 @@
descriptorInfo->usage & ~validUsageBits);
return BAD_VALUE;
}
+
+ // Gralloc2 implementations never understand non-BLOB with GPU_DATA_BUFFER
+ // and do not reliably reject it.
+ if (descriptorInfo->usage & BufferUsage::GPU_DATA_BUFFER &&
+ descriptorInfo->format != hardware::graphics::common::V1_1::PixelFormat::BLOB) {
+ ALOGE("gralloc2 does not support non-BLOB pixel formats with GPU_DATA_BUFFER usage");
+ return BAD_VALUE;
+ }
+
return NO_ERROR;
}
diff --git a/libs/ui/Gralloc3.cpp b/libs/ui/Gralloc3.cpp
index 882674f..15c60bc 100644
--- a/libs/ui/Gralloc3.cpp
+++ b/libs/ui/Gralloc3.cpp
@@ -101,6 +101,15 @@
descriptorInfo->usage & ~validUsageBits);
return BAD_VALUE;
}
+
+ // Gralloc3 implementations never understand non-BLOB with GPU_DATA_BUFFER
+ // and do not reliably reject it.
+ if (descriptorInfo->usage & BufferUsage::GPU_DATA_BUFFER &&
+ descriptorInfo->format != hardware::graphics::common::V1_2::PixelFormat::BLOB) {
+ ALOGE("gralloc3 does not support non-BLOB pixel formats with GPU_DATA_BUFFER usage");
+ return BAD_VALUE;
+ }
+
return NO_ERROR;
}
diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp
index 1f8a2f0..c97cc94 100644
--- a/libs/ui/Gralloc4.cpp
+++ b/libs/ui/Gralloc4.cpp
@@ -41,6 +41,7 @@
using android::hardware::hidl_vec;
using android::hardware::graphics::allocator::V4_0::IAllocator;
using android::hardware::graphics::common::V1_2::BufferUsage;
+using android::hardware::graphics::common::V1_2::PixelFormat;
using android::hardware::graphics::mapper::V4_0::BufferDescriptor;
using android::hardware::graphics::mapper::V4_0::Error;
using android::hardware::graphics::mapper::V4_0::IMapper;
@@ -92,9 +93,48 @@
outRect.height = rect.height();
return outRect;
}
-static inline void sBufferDescriptorInfo(std::string name, uint32_t width, uint32_t height,
- PixelFormat format, uint32_t layerCount, uint64_t usage,
- IMapper::BufferDescriptorInfo* outDescriptorInfo) {
+
+// See if gralloc "4.1" is available.
+static bool hasIAllocatorAidl() {
+ // Avoid re-querying repeatedly for this information;
+ static bool sHasIAllocatorAidl = []() -> bool {
+ if (__builtin_available(android 31, *)) {
+ return AServiceManager_isDeclared(kAidlAllocatorServiceName.c_str());
+ }
+ return false;
+ }();
+ return sHasIAllocatorAidl;
+}
+
+// Determines whether the passed info is compatible with the mapper.
+static status_t validateBufferDescriptorInfo(IMapper::BufferDescriptorInfo* descriptorInfo) {
+ uint64_t validUsageBits = getValidUsageBits();
+ if (hasIAllocatorAidl()) {
+ validUsageBits |= getValidUsageBits41();
+ }
+
+ if (descriptorInfo->usage & ~validUsageBits) {
+ ALOGE("buffer descriptor contains invalid usage bits 0x%" PRIx64,
+ descriptorInfo->usage & ~validUsageBits);
+ return BAD_VALUE;
+ }
+
+ // Combinations that are only allowed with gralloc 4.1.
+ // Previous grallocs must be protected from this.
+ if (!hasIAllocatorAidl() &&
+ descriptorInfo->format != hardware::graphics::common::V1_2::PixelFormat::BLOB &&
+ descriptorInfo->usage & BufferUsage::GPU_DATA_BUFFER) {
+ ALOGE("non-BLOB pixel format with GPU_DATA_BUFFER usage is not supported prior to gralloc 4.1");
+ return BAD_VALUE;
+ }
+
+ return NO_ERROR;
+}
+
+static inline status_t sBufferDescriptorInfo(std::string name, uint32_t width, uint32_t height,
+ PixelFormat format, uint32_t layerCount,
+ uint64_t usage,
+ IMapper::BufferDescriptorInfo* outDescriptorInfo) {
outDescriptorInfo->name = name;
outDescriptorInfo->width = width;
outDescriptorInfo->height = height;
@@ -102,21 +142,8 @@
outDescriptorInfo->format = static_cast<hardware::graphics::common::V1_2::PixelFormat>(format);
outDescriptorInfo->usage = usage;
outDescriptorInfo->reservedSize = 0;
-}
-// See if gralloc "4.1" is available.
-static bool hasIAllocatorAidl() {
- // Avoid re-querying repeatedly for this information;
- static bool sHasIAllocatorAidl = []() -> bool {
- // TODO: Enable after landing sepolicy changes
- if constexpr ((true)) return false;
-
- if (__builtin_available(android 31, *)) {
- return AServiceManager_isDeclared(kAidlAllocatorServiceName.c_str());
- }
- return false;
- }();
- return sHasIAllocatorAidl;
+ return validateBufferDescriptorInfo(outDescriptorInfo);
}
} // anonymous namespace
@@ -140,21 +167,6 @@
return mMapper != nullptr;
}
-status_t Gralloc4Mapper::validateBufferDescriptorInfo(
- IMapper::BufferDescriptorInfo* descriptorInfo) const {
- uint64_t validUsageBits = getValidUsageBits();
- if (hasIAllocatorAidl()) {
- validUsageBits |= getValidUsageBits41();
- }
-
- if (descriptorInfo->usage & ~validUsageBits) {
- ALOGE("buffer descriptor contains invalid usage bits 0x%" PRIx64,
- descriptorInfo->usage & ~validUsageBits);
- return BAD_VALUE;
- }
- return NO_ERROR;
-}
-
status_t Gralloc4Mapper::createDescriptor(void* bufferDescriptorInfo,
void* outBufferDescriptor) const {
IMapper::BufferDescriptorInfo* descriptorInfo =
@@ -207,8 +219,10 @@
uint32_t layerCount, uint64_t usage,
uint32_t stride) const {
IMapper::BufferDescriptorInfo descriptorInfo;
- sBufferDescriptorInfo("validateBufferSize", width, height, format, layerCount, usage,
- &descriptorInfo);
+ if (auto error = sBufferDescriptorInfo("validateBufferSize", width, height, format, layerCount,
+ usage, &descriptorInfo) != OK) {
+ return error;
+ }
auto buffer = const_cast<native_handle_t*>(bufferHandle);
auto ret = mMapper->validateBufferSize(buffer, descriptorInfo, stride);
@@ -427,7 +441,7 @@
if (fd >= 0) {
releaseFence = fd;
} else {
- ALOGD("failed to dup unlock release fence");
+ ALOGW("failed to dup unlock release fence");
sync_wait(fenceHandle->data[0], -1);
}
}
@@ -448,7 +462,12 @@
uint32_t layerCount, uint64_t usage,
bool* outSupported) const {
IMapper::BufferDescriptorInfo descriptorInfo;
- sBufferDescriptorInfo("isSupported", width, height, format, layerCount, usage, &descriptorInfo);
+ if (auto error = sBufferDescriptorInfo("isSupported", width, height, format, layerCount, usage,
+ &descriptorInfo) != OK) {
+ // Usage isn't known to the HAL or otherwise failed validation.
+ *outSupported = false;
+ return OK;
+ }
Error error;
auto ret = mMapper->isSupported(descriptorInfo,
@@ -691,7 +710,10 @@
}
IMapper::BufferDescriptorInfo descriptorInfo;
- sBufferDescriptorInfo("getDefault", width, height, format, layerCount, usage, &descriptorInfo);
+ if (auto error = sBufferDescriptorInfo("getDefault", width, height, format, layerCount, usage,
+ &descriptorInfo) != OK) {
+ return error;
+ }
hidl_vec<uint8_t> vec;
Error error;
@@ -1133,7 +1155,10 @@
uint64_t usage, uint32_t bufferCount, uint32_t* outStride,
buffer_handle_t* outBufferHandles, bool importBuffers) const {
IMapper::BufferDescriptorInfo descriptorInfo;
- sBufferDescriptorInfo(requestorName, width, height, format, layerCount, usage, &descriptorInfo);
+ if (auto error = sBufferDescriptorInfo(requestorName, width, height, format, layerCount, usage,
+ &descriptorInfo) != OK) {
+ return error;
+ }
BufferDescriptor descriptor;
status_t error = mMapper.createDescriptor(static_cast<void*>(&descriptorInfo),
diff --git a/libs/ui/include/ui/DynamicDisplayInfo.h b/libs/ui/include/ui/DynamicDisplayInfo.h
index a4c2f71..ce75a65 100644
--- a/libs/ui/include/ui/DynamicDisplayInfo.h
+++ b/libs/ui/include/ui/DynamicDisplayInfo.h
@@ -35,7 +35,7 @@
// This struct is going to be serialized over binder, so
// we can't use size_t because it may have different width
// in the client process.
- int32_t activeDisplayModeId;
+ ui::DisplayModeId activeDisplayModeId;
std::vector<ui::ColorMode> supportedColorModes;
ui::ColorMode activeColorMode;
@@ -49,6 +49,9 @@
// For more information, see the HDMI 1.4 specification.
bool gameContentTypeSupported;
+ // The boot display mode preferred by the implementation.
+ ui::DisplayModeId preferredBootDisplayMode;
+
std::optional<ui::DisplayMode> getActiveDisplayMode() const;
bool isFixedSize() const { return false; }
diff --git a/libs/ui/include/ui/Gralloc4.h b/libs/ui/include/ui/Gralloc4.h
index 6bafcd6..fe38709 100644
--- a/libs/ui/include/ui/Gralloc4.h
+++ b/libs/ui/include/ui/Gralloc4.h
@@ -155,10 +155,6 @@
private:
friend class GraphicBufferAllocator;
- // Determines whether the passed info is compatible with the mapper.
- status_t validateBufferDescriptorInfo(
- hardware::graphics::mapper::V4_0::IMapper::BufferDescriptorInfo* descriptorInfo) const;
-
template <class T>
using DecodeFunction = status_t (*)(const hardware::hidl_vec<uint8_t>& input, T* output);
diff --git a/services/inputflinger/TEST_MAPPING b/services/inputflinger/TEST_MAPPING
index 3d85bef..9b72ff4 100644
--- a/services/inputflinger/TEST_MAPPING
+++ b/services/inputflinger/TEST_MAPPING
@@ -15,6 +15,9 @@
"name": "inputflinger_tests"
},
{
+ "name": "libpalmrejection_test"
+ },
+ {
"name": "InputTests"
},
{
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 7a3d6c5..d1982fc 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -120,7 +120,8 @@
// Amount of time to allow for an event to be dispatched (measured since its eventTime)
// before considering it stale and dropping it.
-constexpr nsecs_t STALE_EVENT_TIMEOUT = 10000 * 1000000LL; // 10sec
+const nsecs_t STALE_EVENT_TIMEOUT = 10000 * 1000000LL // 10sec
+ * HwTimeoutMultiplier();
// Log a warning when an event takes longer than this to process, even if an ANR does not occur.
constexpr nsecs_t SLOW_EVENT_PROCESSING_WARNING_TIMEOUT = 2000 * 1000000LL; // 2sec
diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp
index 3e95fa9..a050963 100644
--- a/services/inputflinger/reader/InputDevice.cpp
+++ b/services/inputflinger/reader/InputDevice.cpp
@@ -309,15 +309,15 @@
const auto& displayPort = ports.find(inputPort);
if (displayPort != ports.end()) {
mAssociatedDisplayPort = std::make_optional(displayPort->second);
+ } else {
+ const std::unordered_map<std::string, std::string>& displayUniqueIds =
+ config->uniqueIdAssociations;
+ const auto& displayUniqueId = displayUniqueIds.find(inputPort);
+ if (displayUniqueId != displayUniqueIds.end()) {
+ mAssociatedDisplayUniqueId = displayUniqueId->second;
+ }
}
}
- const std::string& inputDeviceName = mIdentifier.name;
- const std::unordered_map<std::string, std::string>& names =
- config->uniqueIdAssociations;
- const auto& displayUniqueId = names.find(inputDeviceName);
- if (displayUniqueId != names.end()) {
- mAssociatedDisplayUniqueId = displayUniqueId->second;
- }
// If the device was explicitly disabled by the user, it would be present in the
// "disabledDevices" list. If it is associated with a specific display, and it was not
@@ -338,7 +338,7 @@
if (!mAssociatedViewport) {
ALOGW("Input device %s should be associated with display %s but the "
"corresponding viewport cannot be found",
- inputDeviceName.c_str(), mAssociatedDisplayUniqueId->c_str());
+ getName().c_str(), mAssociatedDisplayUniqueId->c_str());
enabled = false;
}
}
diff --git a/services/inputflinger/reader/include/InputDevice.h b/services/inputflinger/reader/include/InputDevice.h
index 11c074a..694daa9 100644
--- a/services/inputflinger/reader/include/InputDevice.h
+++ b/services/inputflinger/reader/include/InputDevice.h
@@ -61,6 +61,9 @@
inline std::optional<uint8_t> getAssociatedDisplayPort() const {
return mAssociatedDisplayPort;
}
+ inline std::optional<std::string> getAssociatedDisplayUniqueId() const {
+ return mAssociatedDisplayUniqueId;
+ }
inline std::optional<DisplayViewport> getAssociatedViewport() const {
return mAssociatedViewport;
}
@@ -386,6 +389,9 @@
inline std::optional<uint8_t> getAssociatedDisplayPort() const {
return mDevice.getAssociatedDisplayPort();
}
+ inline std::optional<std::string> getAssociatedDisplayUniqueId() const {
+ return mDevice.getAssociatedDisplayUniqueId();
+ }
inline std::optional<DisplayViewport> getAssociatedViewport() const {
return mDevice.getAssociatedViewport();
}
diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp
index 4772beb..f729ba9 100644
--- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp
@@ -565,6 +565,12 @@
return getDeviceContext().getAssociatedViewport();
}
+ const std::optional<std::string> associatedDisplayUniqueId =
+ getDeviceContext().getAssociatedDisplayUniqueId();
+ if (associatedDisplayUniqueId) {
+ return getDeviceContext().getAssociatedViewport();
+ }
+
if (mDeviceMode == DeviceMode::POINTER) {
std::optional<DisplayViewport> viewport =
mConfig.getDisplayViewportById(mConfig.defaultPointerDisplayId);
diff --git a/services/inputflinger/tests/Android.bp b/services/inputflinger/tests/Android.bp
index e686924..d19dbaf 100644
--- a/services/inputflinger/tests/Android.bp
+++ b/services/inputflinger/tests/Android.bp
@@ -57,7 +57,8 @@
],
},
static_libs: [
- "libc++fs"
+ "libc++fs",
+ "libinput",
],
require_root: true,
test_suites: ["device-tests"],
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index e2596f0..54cf15d 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -2862,7 +2862,7 @@
// Device should be disabled because it is associated with a specific display, but the
// corresponding display is not found.
const std::string DISPLAY_UNIQUE_ID = "displayUniqueId";
- mFakePolicy->addInputUniqueIdAssociation(DEVICE_NAME, DISPLAY_UNIQUE_ID);
+ mFakePolicy->addInputUniqueIdAssociation(DEVICE_LOCATION, DISPLAY_UNIQUE_ID);
mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
InputReaderConfiguration::CHANGE_DISPLAY_INFO);
ASSERT_FALSE(mDevice->isEnabled());
@@ -2887,6 +2887,21 @@
ASSERT_FALSE(mDevice->isEnabled());
}
+TEST_F(InputDeviceTest, Configure_UniqueId_CorrectlyMatches) {
+ mFakePolicy->clearViewports();
+ mDevice->addMapper<FakeInputMapper>(EVENTHUB_ID, AINPUT_SOURCE_KEYBOARD);
+ mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), 0);
+
+ const std::string DISPLAY_UNIQUE_ID = "displayUniqueId";
+ mFakePolicy->addInputUniqueIdAssociation(DEVICE_LOCATION, DISPLAY_UNIQUE_ID);
+ mFakePolicy->addDisplayViewport(SECONDARY_DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT,
+ DISPLAY_ORIENTATION_0, /* isActive= */ true, DISPLAY_UNIQUE_ID,
+ NO_PORT, ViewportType::INTERNAL);
+ mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
+ InputReaderConfiguration::CHANGE_DISPLAY_INFO);
+ ASSERT_EQ(DISPLAY_UNIQUE_ID, mDevice->getAssociatedDisplayUniqueId());
+}
+
// --- InputMapperTest ---
class InputMapperTest : public testing::Test {
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/Display.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/Display.h
index 16cb41b..47aacc9 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/Display.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/Display.h
@@ -56,6 +56,9 @@
// similar requests if needed.
virtual void createClientCompositionCache(uint32_t cacheSize) = 0;
+ // Returns the boot display mode preferred by HWC.
+ virtual int32_t getPreferredBootModeId() const = 0;
+
protected:
~Display() = default;
};
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h
index b777241..ebe112b 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h
@@ -62,6 +62,7 @@
bool isSecure() const override;
bool isVirtual() const override;
void disconnect() override;
+ int32_t getPreferredBootModeId() const override;
void createDisplayColorProfile(
const compositionengine::DisplayColorProfileCreationArgs&) override;
void createRenderSurface(const compositionengine::RenderSurfaceCreationArgs&) override;
@@ -87,6 +88,7 @@
DisplayId mId;
bool mIsDisconnected = false;
Hwc2::PowerAdvisor* mPowerAdvisor = nullptr;
+ int32_t mPreferredBootDisplayModeId = -1;
};
// This template factory function standardizes the implementation details of the
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayerCompositionState.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayerCompositionState.h
index 49cb912..08cfaa6 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayerCompositionState.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayerCompositionState.h
@@ -90,6 +90,10 @@
// The dataspace for this layer
ui::Dataspace dataspace{ui::Dataspace::UNKNOWN};
+ // A hint to the HWC that this region is transparent and may be skipped in
+ // order to save power.
+ Region outputSpaceBlockingRegionHint;
+
// Overrides the buffer, acquire fence, and display frame stored in LayerFECompositionState
struct {
std::shared_ptr<renderengine::ExternalTexture> buffer = nullptr;
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Display.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Display.h
index 6fb3e08..84afb59 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Display.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Display.h
@@ -34,6 +34,7 @@
MOCK_CONST_METHOD0(getId, DisplayId());
MOCK_CONST_METHOD0(isSecure, bool());
MOCK_CONST_METHOD0(isVirtual, bool());
+ MOCK_CONST_METHOD0(getPreferredBootModeId, int32_t());
MOCK_METHOD0(disconnect, void());
diff --git a/services/surfaceflinger/CompositionEngine/src/Display.cpp b/services/surfaceflinger/CompositionEngine/src/Display.cpp
index 186e191..1ea13a7 100644
--- a/services/surfaceflinger/CompositionEngine/src/Display.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/Display.cpp
@@ -57,6 +57,12 @@
editState().isSecure = args.isSecure;
editState().displaySpace.setBounds(args.pixels);
setName(args.name);
+ bool isBootModeSupported = getCompositionEngine().getHwComposer().getBootDisplayModeSupport();
+ const auto physicalId = PhysicalDisplayId::tryCast(mId);
+ if (physicalId && isBootModeSupported) {
+ mPreferredBootDisplayModeId = static_cast<int32_t>(
+ getCompositionEngine().getHwComposer().getPreferredBootDisplayMode(*physicalId));
+ }
}
bool Display::isValid() const {
@@ -79,6 +85,10 @@
return mId;
}
+int32_t Display::getPreferredBootModeId() const {
+ return mPreferredBootDisplayModeId;
+}
+
void Display::disconnect() {
if (mIsDisconnected) {
return;
diff --git a/services/surfaceflinger/CompositionEngine/src/Output.cpp b/services/surfaceflinger/CompositionEngine/src/Output.cpp
index 162d84e..65f9731 100644
--- a/services/surfaceflinger/CompositionEngine/src/Output.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/Output.cpp
@@ -50,6 +50,8 @@
#include "TracedOrdinal.h"
+using aidl::android::hardware::graphics::composer3::Composition;
+
namespace android::compositionengine {
Output::~Output() = default;
@@ -529,11 +531,18 @@
/*
* transparentRegion: area of a surface that is hinted to be completely
- * transparent. This is only used to tell when the layer has no visible non-
- * transparent regions and can be removed from the layer list. It does not
- * affect the visibleRegion of this layer or any layers beneath it. The hint
- * may not be correct if apps don't respect the SurfaceView restrictions
- * (which, sadly, some don't).
+ * transparent.
+ * This is used to tell when the layer has no visible non-transparent
+ * regions and can be removed from the layer list. It does not affect the
+ * visibleRegion of this layer or any layers beneath it. The hint may not
+ * be correct if apps don't respect the SurfaceView restrictions (which,
+ * sadly, some don't).
+ *
+ * In addition, it is used on DISPLAY_DECORATION layers to specify the
+ * blockingRegion, allowing the DPU to skip it to save power. Once we have
+ * hardware that supports a blockingRegion on frames with AFBC, it may be
+ * useful to use this for other layers, too, so long as we can prevent
+ * regressions on b/7179570.
*/
Region transparentRegion;
@@ -674,6 +683,9 @@
outputLayerState.outputSpaceVisibleRegion = outputState.transform.transform(
visibleNonShadowRegion.intersect(outputState.layerStackSpace.getContent()));
outputLayerState.shadowRegion = shadowRegion;
+ outputLayerState.outputSpaceBlockingRegionHint =
+ layerFEState->compositionType == Composition::DISPLAY_DECORATION ? transparentRegion
+ : Region();
}
void Output::setReleasedLayers(const compositionengine::CompositionRefreshArgs&) {
diff --git a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
index 95cc5a8..4ccf11f 100644
--- a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
@@ -484,6 +484,14 @@
visibleRegion.dump(LOG_TAG);
}
+ if (auto error =
+ hwcLayer->setBlockingRegion(outputDependentState.outputSpaceBlockingRegionHint);
+ error != hal::Error::NONE) {
+ ALOGE("[%s] Failed to set blocking region: %s (%d)", getLayerFE().getDebugName(),
+ to_string(error).c_str(), static_cast<int32_t>(error));
+ outputDependentState.outputSpaceBlockingRegionHint.dump(LOG_TAG);
+ }
+
const auto dataspace = outputDependentState.overrideInfo.buffer
? outputDependentState.overrideInfo.dataspace
: outputDependentState.dataspace;
diff --git a/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp b/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp
index 7dd4c21..03c6f8d 100644
--- a/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp
+++ b/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp
@@ -164,6 +164,7 @@
EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
+ EXPECT_CALL(mHwComposer, getBootDisplayModeSupport()).WillRepeatedly(Return(false));
}
DisplayCreationArgs getDisplayCreationArgsForPhysicalDisplay() {
@@ -971,7 +972,8 @@
DisplayFunctionalTest() {
EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
-
+ mDisplay = createDisplay();
+ mRenderSurface = createRenderSurface();
mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
}
@@ -980,24 +982,29 @@
NiceMock<mock::CompositionEngine> mCompositionEngine;
sp<mock::NativeWindow> mNativeWindow = new NiceMock<mock::NativeWindow>();
sp<mock::DisplaySurface> mDisplaySurface = new NiceMock<mock::DisplaySurface>();
+ std::shared_ptr<Display> mDisplay;
+ impl::RenderSurface* mRenderSurface;
- std::shared_ptr<Display> mDisplay = impl::createDisplayTemplated<
- Display>(mCompositionEngine,
- DisplayCreationArgsBuilder()
- .setId(DEFAULT_DISPLAY_ID)
- .setPixels(DEFAULT_RESOLUTION)
- .setIsSecure(true)
- .setPowerAdvisor(&mPowerAdvisor)
- .build());
+ std::shared_ptr<Display> createDisplay() {
+ return impl::createDisplayTemplated<Display>(mCompositionEngine,
+ DisplayCreationArgsBuilder()
+ .setId(DEFAULT_DISPLAY_ID)
+ .setPixels(DEFAULT_RESOLUTION)
+ .setIsSecure(true)
+ .setPowerAdvisor(&mPowerAdvisor)
+ .build());
+ ;
+ }
- impl::RenderSurface* mRenderSurface =
- new impl::RenderSurface{mCompositionEngine, *mDisplay,
- RenderSurfaceCreationArgsBuilder()
- .setDisplayWidth(DEFAULT_RESOLUTION.width)
- .setDisplayHeight(DEFAULT_RESOLUTION.height)
- .setNativeWindow(mNativeWindow)
- .setDisplaySurface(mDisplaySurface)
- .build()};
+ impl::RenderSurface* createRenderSurface() {
+ return new impl::RenderSurface{mCompositionEngine, *mDisplay,
+ RenderSurfaceCreationArgsBuilder()
+ .setDisplayWidth(DEFAULT_RESOLUTION.width)
+ .setDisplayHeight(DEFAULT_RESOLUTION.height)
+ .setNativeWindow(mNativeWindow)
+ .setDisplaySurface(mDisplaySurface)
+ .build()};
+ }
};
TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) {
diff --git a/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h b/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h
index 6443c2b..bcd4dc2 100644
--- a/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h
+++ b/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h
@@ -109,6 +109,7 @@
MOCK_METHOD2(setBootDisplayMode, status_t(PhysicalDisplayId, hal::HWConfigId));
MOCK_METHOD1(clearBootDisplayMode, status_t(PhysicalDisplayId));
MOCK_METHOD1(getPreferredBootDisplayMode, hal::HWConfigId(PhysicalDisplayId));
+ MOCK_METHOD0(getBootDisplayModeSupport, bool());
MOCK_METHOD2(setAutoLowLatencyMode, status_t(PhysicalDisplayId, bool));
MOCK_METHOD2(getSupportedContentTypes,
status_t(PhysicalDisplayId, std::vector<hal::ContentType>*));
@@ -127,7 +128,6 @@
(const, override));
MOCK_METHOD(std::optional<hal::HWDisplayId>, fromPhysicalDisplayId, (PhysicalDisplayId),
(const, override));
- MOCK_METHOD(bool, getBootDisplayModeSupport, (), (override));
};
} // namespace mock
diff --git a/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp b/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp
index 132ac02..0b123b1 100644
--- a/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp
+++ b/services/surfaceflinger/CompositionEngine/tests/OutputLayerTest.cpp
@@ -846,7 +846,8 @@
ui::Dataspace dataspace = kDataspace,
const Region& visibleRegion = kOutputSpaceVisibleRegion,
const Region& surfaceDamage = kSurfaceDamage,
- float whitePointNits = kWhitePointNits) {
+ float whitePointNits = kWhitePointNits,
+ const Region& blockingRegion = Region()) {
EXPECT_CALL(*mHwcLayer, setVisibleRegion(RegionEq(visibleRegion))).WillOnce(Return(kError));
EXPECT_CALL(*mHwcLayer, setDataspace(dataspace)).WillOnce(Return(kError));
EXPECT_CALL(*mHwcLayer, setWhitePointNits(whitePointNits)).WillOnce(Return(kError));
@@ -855,6 +856,8 @@
? hal::Error::UNSUPPORTED
: hal::Error::NONE));
EXPECT_CALL(*mHwcLayer, setSurfaceDamage(RegionEq(surfaceDamage))).WillOnce(Return(kError));
+ EXPECT_CALL(*mHwcLayer, setBlockingRegion(RegionEq(blockingRegion)))
+ .WillOnce(Return(kError));
}
void expectSetCompositionTypeCall(Composition compositionType) {
@@ -1278,6 +1281,23 @@
EXPECT_EQ(Composition::DEVICE, mOutputLayer.getState().hwc->hwcCompositionType);
}
+TEST_F(OutputLayerWriteStateToHWCTest, setBlockingRegion) {
+ mLayerFEState.compositionType = Composition::DISPLAY_DECORATION;
+ const auto blockingRegion = Region(Rect(0, 0, 1000, 1000));
+ mOutputLayer.editState().outputSpaceBlockingRegionHint = blockingRegion;
+
+ expectGeometryCommonCalls();
+ expectPerFrameCommonCalls(SimulateUnsupported::None, kDataspace, kOutputSpaceVisibleRegion,
+ kSurfaceDamage, kWhitePointNits, blockingRegion);
+ expectSetHdrMetadataAndBufferCalls();
+ EXPECT_CALL(*mLayerFE, hasRoundedCorners()).WillRepeatedly(Return(false));
+ expectSetCompositionTypeCall(Composition::DISPLAY_DECORATION);
+
+ mOutputLayer.writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, 0,
+ /*zIsOverridden*/ false, /*isPeekingThrough*/
+ false);
+}
+
/*
* OutputLayer::writeCursorPositionToHWC()
*/
diff --git a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp
index 655db4b..f7d5991 100644
--- a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp
+++ b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp
@@ -1291,7 +1291,7 @@
mLayer.layerFEState.contentDirty = true;
mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200};
mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
- mLayer.layerFEState.transparentRegionHint = Region(Rect(0, 0, 100, 100));
+ mLayer.layerFEState.transparentRegionHint = kTransparentRegionHint;
mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 50, 200));
mLayer.outputLayerState.coveredRegion = Region(Rect(50, 0, 100, 200));
@@ -1309,6 +1309,7 @@
static const Region kRightHalfBoundsNoRotation;
static const Region kLowerHalfBoundsNoRotation;
static const Region kFullBounds90Rotation;
+ static const Region kTransparentRegionHint;
StrictMock<OutputPartialMock> mOutput;
LayerFESet mGeomSnapshots;
@@ -1326,6 +1327,8 @@
Region(Rect(50, 0, 100, 200));
const Region OutputEnsureOutputLayerIfVisibleTest::kFullBounds90Rotation =
Region(Rect(0, 0, 200, 100));
+const Region OutputEnsureOutputLayerIfVisibleTest::kTransparentRegionHint =
+ Region(Rect(0, 0, 100, 100));
TEST_F(OutputEnsureOutputLayerIfVisibleTest, performsGeomLatchBeforeCheckingIfLayerIncluded) {
EXPECT_CALL(mOutput, includesLayer(sp<LayerFE>(mLayer.layerFE))).WillOnce(Return(false));
@@ -1749,6 +1752,33 @@
ensureOutputLayerIfVisible();
}
+TEST_F(OutputEnsureOutputLayerIfVisibleTest, displayDecorSetsBlockingFromTransparentRegion) {
+ mLayer.layerFEState.isOpaque = false;
+ mLayer.layerFEState.contentDirty = true;
+ mLayer.layerFEState.compositionType =
+ aidl::android::hardware::graphics::composer3::Composition::DISPLAY_DECORATION;
+
+ EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
+ EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
+ .WillOnce(Return(&mLayer.outputLayer));
+ ensureOutputLayerIfVisible();
+
+ EXPECT_THAT(mLayer.outputLayerState.outputSpaceBlockingRegionHint,
+ RegionEq(kTransparentRegionHint));
+}
+
+TEST_F(OutputEnsureOutputLayerIfVisibleTest, normalLayersDoNotSetBlockingRegion) {
+ mLayer.layerFEState.isOpaque = false;
+ mLayer.layerFEState.contentDirty = true;
+
+ EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
+ EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
+ .WillOnce(Return(&mLayer.outputLayer));
+ ensureOutputLayerIfVisible();
+
+ EXPECT_THAT(mLayer.outputLayerState.outputSpaceBlockingRegionHint, RegionEq(Region()));
+}
+
/*
* Output::present()
*/
diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp
index a36ea72..f542161 100644
--- a/services/surfaceflinger/DisplayDevice.cpp
+++ b/services/surfaceflinger/DisplayDevice.cpp
@@ -92,10 +92,12 @@
}
mCompositionDisplay->createDisplayColorProfile(
- compositionengine::DisplayColorProfileCreationArgs{args.hasWideColorGamut,
- std::move(args.hdrCapabilities),
- args.supportedPerFrameMetadata,
- args.hwcColorModes});
+ compositionengine::DisplayColorProfileCreationArgsBuilder()
+ .setHasWideColorGamut(args.hasWideColorGamut)
+ .setHdrCapabilities(std::move(args.hdrCapabilities))
+ .setSupportedPerFrameMetadata(args.supportedPerFrameMetadata)
+ .setHwcColorModes(std::move(args.hwcColorModes))
+ .Build());
if (!mCompositionDisplay->isValid()) {
ALOGE("Composition Display did not validate!");
@@ -454,6 +456,10 @@
capabilities.getDesiredMinLuminance());
}
+ui::DisplayModeId DisplayDevice::getPreferredBootModeId() const {
+ return mCompositionDisplay->getPreferredBootModeId();
+}
+
void DisplayDevice::enableRefreshRateOverlay(bool enable, bool showSpinnner) {
if (!enable) {
mRefreshRateOverlay.reset();
diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h
index 0c9063d..3cae30f 100644
--- a/services/surfaceflinger/DisplayDevice.h
+++ b/services/surfaceflinger/DisplayDevice.h
@@ -157,6 +157,9 @@
// respectively if hardware composer doesn't return meaningful values.
HdrCapabilities getHdrCapabilities() const;
+ // Returns the boot display mode preferred by the implementation.
+ ui::DisplayModeId getPreferredBootModeId() const;
+
// Return true if intent is supported by the display.
bool hasRenderIntent(ui::RenderIntent intent) const;
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 7af1237..645d4d1 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -2160,101 +2160,71 @@
return getCroppedBufferSize(getDrawingState());
}
-void Layer::fillInputFrameInfo(WindowInfo& info, const ui::Transform& displayTransform) {
- // Transform layer size to screen space and inset it by surface insets.
- // If this is a portal window, set the touchableRegion to the layerBounds.
- Rect layerBounds = info.portalToDisplayId == ADISPLAY_ID_NONE
- ? getInputBounds()
- : info.touchableRegion.getBounds();
- if (!layerBounds.isValid()) {
- layerBounds = getInputBounds();
- }
-
- if (!layerBounds.isValid()) {
- // If the layer bounds is empty, set the frame to empty and clear the transform
- info.frameLeft = 0;
- info.frameTop = 0;
- info.frameRight = 0;
- info.frameBottom = 0;
- info.transform.reset();
- info.touchableRegion = Region();
+void Layer::fillInputFrameInfo(WindowInfo& info, const ui::Transform& screenToDisplay) {
+ Rect tmpBounds = getInputBounds();
+ if (!tmpBounds.isValid()) {
info.flags = WindowInfo::Flag::NOT_TOUCH_MODAL | WindowInfo::Flag::NOT_FOCUSABLE;
- return;
+ info.focusable = false;
+ info.touchableRegion.clear();
+ // A layer could have invalid input bounds and still expect to receive touch input if it has
+ // replaceTouchableRegionWithCrop. For that case, the input transform needs to be calculated
+ // correctly to determine the coordinate space for input events. Use an empty rect so that
+ // the layer will receive input in its own layer space.
+ tmpBounds = Rect::EMPTY_RECT;
}
- const ui::Transform layerTransform = getInputTransform();
- // Transform that takes window coordinates to non-rotated display coordinates
- ui::Transform t = displayTransform * layerTransform;
- int32_t xSurfaceInset = info.surfaceInset;
- int32_t ySurfaceInset = info.surfaceInset;
- // Bring screenBounds into non-unrotated space
- Rect screenBounds = displayTransform.transform(Rect{mScreenBounds});
+ // InputDispatcher works in the display device's coordinate space. Here, we calculate the
+ // frame and transform used for the layer, which determines the bounds and the coordinate space
+ // within which the layer will receive input.
+ //
+ // The coordinate space within which each of the bounds are specified is explicitly documented
+ // in the variable name. For example "inputBoundsInLayer" is specified in layer space. A
+ // Transform converts one coordinate space to another, which is apparent in its naming. For
+ // example, "layerToDisplay" transforms layer space to display space.
+ //
+ // Coordinate space definitions:
+ // - display: The display device's coordinate space. Correlates to pixels on the display.
+ // - screen: The post-rotation coordinate space for the display, a.k.a. logical display space.
+ // - layer: The coordinate space of this layer.
+ // - input: The coordinate space in which this layer will receive input events. This could be
+ // different than layer space if a surfaceInset is used, which changes the origin
+ // of the input space.
+ const FloatRect inputBoundsInLayer = tmpBounds.toFloatRect();
- const float xScale = t.getScaleX();
- const float yScale = t.getScaleY();
- if (xScale != 1.0f || yScale != 1.0f) {
- xSurfaceInset = std::round(xSurfaceInset * xScale);
- ySurfaceInset = std::round(ySurfaceInset * yScale);
- }
+ // Clamp surface inset to the input bounds.
+ const auto surfaceInset = static_cast<float>(info.surfaceInset);
+ const float xSurfaceInset =
+ std::max(0.f, std::min(surfaceInset, inputBoundsInLayer.getWidth() / 2.f));
+ const float ySurfaceInset =
+ std::max(0.f, std::min(surfaceInset, inputBoundsInLayer.getHeight() / 2.f));
- // Transform the layer bounds from layer coordinate space to display coordinate space.
- Rect transformedLayerBounds = t.transform(layerBounds);
+ // Apply the insets to the input bounds.
+ const FloatRect insetBoundsInLayer(inputBoundsInLayer.left + xSurfaceInset,
+ inputBoundsInLayer.top + ySurfaceInset,
+ inputBoundsInLayer.right - xSurfaceInset,
+ inputBoundsInLayer.bottom - ySurfaceInset);
- // clamp inset to layer bounds
- xSurfaceInset = (xSurfaceInset >= 0)
- ? std::min(xSurfaceInset, transformedLayerBounds.getWidth() / 2)
- : 0;
- ySurfaceInset = (ySurfaceInset >= 0)
- ? std::min(ySurfaceInset, transformedLayerBounds.getHeight() / 2)
- : 0;
+ // Crop the input bounds to ensure it is within the parent's bounds.
+ const FloatRect croppedInsetBoundsInLayer = mBounds.intersect(insetBoundsInLayer);
- // inset while protecting from overflow TODO(b/161235021): What is going wrong
- // in the overflow scenario?
- {
- int32_t tmp;
- if (!__builtin_add_overflow(transformedLayerBounds.left, xSurfaceInset, &tmp))
- transformedLayerBounds.left = tmp;
- if (!__builtin_sub_overflow(transformedLayerBounds.right, xSurfaceInset, &tmp))
- transformedLayerBounds.right = tmp;
- if (!__builtin_add_overflow(transformedLayerBounds.top, ySurfaceInset, &tmp))
- transformedLayerBounds.top = tmp;
- if (!__builtin_sub_overflow(transformedLayerBounds.bottom, ySurfaceInset, &tmp))
- transformedLayerBounds.bottom = tmp;
- }
+ const ui::Transform layerToScreen = getInputTransform();
+ const ui::Transform layerToDisplay = screenToDisplay * layerToScreen;
- // Compute the correct transform to send to input. This will allow it to transform the
- // input coordinates from display space into window space. Therefore, it needs to use the
- // final layer frame to create the inverse transform. Since surface insets are added later,
- // along with the overflow, the best way to ensure we get the correct transform is to use
- // the final frame calculated.
- // 1. Take the original transform set on the window and get the inverse transform. This is
- // used to get the final bounds in display space (ignorning the transform). Apply the
- // inverse transform on the layerBounds to get the untransformed frame (in layer space)
- // 2. Take the top and left of the untransformed frame to get the real position on screen.
- // Apply the layer transform on top/left so it includes any scale or rotation. These will
- // be the new translation values for the transform.
- // 3. Update the translation of the original transform to the new translation values.
- // 4. Send the inverse transform to input so the coordinates can be transformed back into
- // window space.
- ui::Transform inverseTransform = t.inverse();
- Rect nonTransformedBounds = inverseTransform.transform(transformedLayerBounds);
- vec2 translation = t.transform(nonTransformedBounds.left, nonTransformedBounds.top);
- ui::Transform inputTransform(t);
- inputTransform.set(translation.x, translation.y);
- info.transform = inputTransform.inverse();
+ const Rect roundedFrameInDisplay{layerToDisplay.transform(croppedInsetBoundsInLayer)};
+ info.frameLeft = roundedFrameInDisplay.left;
+ info.frameTop = roundedFrameInDisplay.top;
+ info.frameRight = roundedFrameInDisplay.right;
+ info.frameBottom = roundedFrameInDisplay.bottom;
- // We need to send the layer bounds cropped to the screenbounds since the layer can be cropped.
- // The frame should be the area the user sees on screen since it's used for occlusion
- // detection.
- transformedLayerBounds.intersect(screenBounds, &transformedLayerBounds);
- info.frameLeft = transformedLayerBounds.left;
- info.frameTop = transformedLayerBounds.top;
- info.frameRight = transformedLayerBounds.right;
- info.frameBottom = transformedLayerBounds.bottom;
+ ui::Transform inputToLayer;
+ inputToLayer.set(insetBoundsInLayer.left, insetBoundsInLayer.top);
+ const ui::Transform inputToDisplay = layerToDisplay * inputToLayer;
- // Position the touchable region relative to frame screen location and restrict it to frame
- // bounds.
- info.touchableRegion = inputTransform.transform(info.touchableRegion);
+ // InputDispatcher expects a display-to-input transform.
+ info.transform = inputToDisplay.inverse();
+
+ // The touchable region is specified in the input coordinate space. Change it to display space.
+ info.touchableRegion = inputToDisplay.transform(info.touchableRegion);
}
void Layer::fillTouchOcclusionMode(WindowInfo& info) {
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 991256b..605a27e 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -959,6 +959,19 @@
bool usingRelativeZ(LayerVector::StateSet) const;
virtual ui::Transform getInputTransform() const;
+ /**
+ * Get the bounds in layer space within which this layer can receive input.
+ *
+ * These bounds are used to:
+ * - Determine the input frame for the layer to be used for occlusion detection; and
+ * - Determine the coordinate space within which the layer will receive input. The top-left of
+ * this rect will be the origin of the coordinate space that the input events sent to the
+ * layer will be in (prior to accounting for surface insets).
+ *
+ * The layer can still receive touch input if these bounds are invalid if
+ * "replaceTouchableRegionWithCrop" is specified. In this case, the layer will receive input
+ * in this layer's space, regardless of the specified crop layer.
+ */
virtual Rect getInputBounds() const;
// constant
@@ -1080,7 +1093,7 @@
void fillTouchOcclusionMode(gui::WindowInfo& info);
// Fills in the frame and transform info for the gui::WindowInfo.
- void fillInputFrameInfo(gui::WindowInfo&, const ui::Transform& displayTransform);
+ void fillInputFrameInfo(gui::WindowInfo&, const ui::Transform& screenToDisplay);
// Cached properties computed from drawing state
// Effective transform taking into account parent transforms and any parent scaling, which is
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 73a5f58..61da45d 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -1109,6 +1109,8 @@
return type == hal::ContentType::GAME;
});
+ info->preferredBootDisplayMode = display->getPreferredBootModeId();
+
return NO_ERROR;
}
@@ -1454,20 +1456,6 @@
return future.get();
}
-status_t SurfaceFlinger::getPreferredBootDisplayMode(const sp<IBinder>& displayToken,
- ui::DisplayModeId* id) {
- auto future = mScheduler->schedule([=]() MAIN_THREAD mutable -> status_t {
- if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) {
- *id = getHwComposer().getPreferredBootDisplayMode(*displayId);
- return NO_ERROR;
- } else {
- ALOGE("%s: Invalid display token %p", __FUNCTION__, displayToken.get());
- return BAD_VALUE;
- }
- });
- return future.get();
-}
-
void SurfaceFlinger::setAutoLowLatencyMode(const sp<IBinder>& displayToken, bool on) {
const char* const whence = __func__;
static_cast<void>(mScheduler->schedule([=]() MAIN_THREAD {
@@ -5407,7 +5395,6 @@
case GET_BOOT_DISPLAY_MODE_SUPPORT:
case SET_BOOT_DISPLAY_MODE:
case CLEAR_BOOT_DISPLAY_MODE:
- case GET_PREFERRED_BOOT_DISPLAY_MODE:
case GET_AUTO_LOW_LATENCY_MODE_SUPPORT:
case SET_AUTO_LOW_LATENCY_MODE:
case GET_GAME_CONTENT_TYPE_SUPPORT:
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 0c990d8..c6a4d85 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -537,8 +537,6 @@
status_t getBootDisplayModeSupport(bool* outSupport) const override;
status_t setBootDisplayMode(const sp<IBinder>& displayToken, ui::DisplayModeId id) override;
status_t clearBootDisplayMode(const sp<IBinder>& displayToken) override;
- status_t getPreferredBootDisplayMode(const sp<IBinder>& displayToken,
- ui::DisplayModeId* id) override;
void setAutoLowLatencyMode(const sp<IBinder>& displayToken, bool on) override;
void setGameContentType(const sp<IBinder>& displayToken, bool on) override;
void setPowerMode(const sp<IBinder>& displayToken, int mode) override;
diff --git a/services/surfaceflinger/fuzzer/Android.bp b/services/surfaceflinger/fuzzer/Android.bp
new file mode 100644
index 0000000..7eebd9b
--- /dev/null
+++ b/services/surfaceflinger/fuzzer/Android.bp
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+cc_defaults {
+ name: "surfaceflinger_fuzz_defaults",
+ include_dirs: [
+ "frameworks/native/services/surfaceflinger/tests/unittests",
+ ],
+ static_libs: [
+ "android.hardware.graphics.composer@2.1-resources",
+ "libgmock",
+ "libgui_mocks",
+ "libgmock_ndk",
+ "libgmock_main",
+ "libgtest_ndk_c++",
+ "libgmock_main_ndk",
+ "librenderengine_mocks",
+ "perfetto_trace_protos",
+ "libcompositionengine_mocks",
+ "perfetto_trace_protos",
+ ],
+ shared_libs: [
+ "libprotoutil",
+ "libstatssocket",
+ "libstatspull",
+ "libtimestats",
+ "libtimestats_proto",
+ "libprotobuf-cpp-full",
+ "android.hardware.graphics.mapper@2.0",
+ "android.hardware.graphics.mapper@3.0",
+ "android.hardware.graphics.mapper@4.0",
+ ],
+ srcs: [
+ ":libsurfaceflinger_sources",
+ ":libsurfaceflinger_mock_sources",
+ ],
+ defaults: [
+ "libsurfaceflinger_defaults",
+ ],
+ header_libs: [
+ "libui_fuzzableDataspaces_headers",
+ "libsurfaceflinger_headers",
+ "libui_headers",
+ ],
+ cflags: [
+ "-Wno-unused-result",
+ "-Wno-conversion",
+ "-Wno-sign-compare",
+ ],
+ fuzz_config: {
+ cc: [
+ "android-media-fuzzing-reports@google.com",
+ ],
+ componentid: 155276,
+ },
+}
+
+cc_fuzz {
+ name: "surfaceflinger_fuzzer",
+ defaults: [
+ "surfaceflinger_fuzz_defaults",
+ ],
+ srcs: [
+ "surfaceflinger_fuzzer.cpp",
+ ],
+}
diff --git a/services/surfaceflinger/fuzzer/README.md b/services/surfaceflinger/fuzzer/README.md
new file mode 100644
index 0000000..7b244fc
--- /dev/null
+++ b/services/surfaceflinger/fuzzer/README.md
@@ -0,0 +1,24 @@
+# Fuzzers for SurfaceFlinger
+## Table of contents
++ [SurfaceFlinger](#SurfaceFlinger)
+
+# <a name="SurfaceFlinger"></a> Fuzzer for SurfaceFlinger
+
+SurfaceFlinger supports the following data sources:
+1. Pixel Formats (parameter name: `defaultCompositionPixelFormat`)
+2. Data Spaces (parameter name: `defaultCompositionDataspace`)
+3. Rotations (parameter name: `internalDisplayOrientation`)
+3. Surface composer tags (parameter name: `onTransact`)
+
+You can find the possible values in the fuzzer's source code.
+
+#### Steps to run
+1. Build the fuzzer
+```
+ $ mm -j$(nproc) surfaceflinger_fuzzer
+```
+2. To run on device
+```
+ $ adb sync data
+ $ adb shell /data/fuzz/arm64/surfaceflinger_fuzzer/surfaceflinger_fuzzer
+```
diff --git a/services/surfaceflinger/fuzzer/surfaceflinger_fuzzer.cpp b/services/surfaceflinger/fuzzer/surfaceflinger_fuzzer.cpp
new file mode 100644
index 0000000..4f89cd9
--- /dev/null
+++ b/services/surfaceflinger/fuzzer/surfaceflinger_fuzzer.cpp
@@ -0,0 +1,294 @@
+/*
+ * Copyright 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <FuzzableDataspaces.h>
+#include <binder/IServiceManager.h>
+#include <fuzzer/FuzzedDataProvider.h>
+#include <ui/DisplayStatInfo.h>
+#include "surfaceflinger_fuzzers_utils.h"
+
+namespace android::fuzz {
+
+static constexpr LatchUnsignaledConfig kLatchUnsignaledConfig[] = {
+ LatchUnsignaledConfig::Always,
+ LatchUnsignaledConfig::Auto,
+ LatchUnsignaledConfig::Disabled,
+};
+
+static constexpr ui::PixelFormat kPixelFormats[] = {ui::PixelFormat::RGBA_8888,
+ ui::PixelFormat::RGBX_8888,
+ ui::PixelFormat::RGB_888,
+ ui::PixelFormat::RGB_565,
+ ui::PixelFormat::BGRA_8888,
+ ui::PixelFormat::YCBCR_422_SP,
+ ui::PixelFormat::YCRCB_420_SP,
+ ui::PixelFormat::YCBCR_422_I,
+ ui::PixelFormat::RGBA_FP16,
+ ui::PixelFormat::RAW16,
+ ui::PixelFormat::BLOB,
+ ui::PixelFormat::IMPLEMENTATION_DEFINED,
+ ui::PixelFormat::YCBCR_420_888,
+ ui::PixelFormat::RAW_OPAQUE,
+ ui::PixelFormat::RAW10,
+ ui::PixelFormat::RAW12,
+ ui::PixelFormat::RGBA_1010102,
+ ui::PixelFormat::Y8,
+ ui::PixelFormat::Y16,
+ ui::PixelFormat::YV12,
+ ui::PixelFormat::DEPTH_16,
+ ui::PixelFormat::DEPTH_24,
+ ui::PixelFormat::DEPTH_24_STENCIL_8,
+ ui::PixelFormat::DEPTH_32F,
+ ui::PixelFormat::DEPTH_32F_STENCIL_8,
+ ui::PixelFormat::STENCIL_8,
+ ui::PixelFormat::YCBCR_P010,
+ ui::PixelFormat::HSV_888};
+
+static constexpr ui::Rotation kRotations[] = {ui::Rotation::Rotation0, ui::Rotation::Rotation90,
+ ui::Rotation::Rotation180, ui::Rotation::Rotation270};
+
+static constexpr BnSurfaceComposer::ISurfaceComposerTag kSurfaceComposerTags[]{
+ BnSurfaceComposer::BOOT_FINISHED,
+ BnSurfaceComposer::CREATE_CONNECTION,
+ BnSurfaceComposer::GET_STATIC_DISPLAY_INFO,
+ BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
+ BnSurfaceComposer::CREATE_DISPLAY,
+ BnSurfaceComposer::DESTROY_DISPLAY,
+ BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN,
+ BnSurfaceComposer::SET_TRANSACTION_STATE,
+ BnSurfaceComposer::AUTHENTICATE_SURFACE,
+ BnSurfaceComposer::GET_SUPPORTED_FRAME_TIMESTAMPS,
+ BnSurfaceComposer::GET_DISPLAY_MODES,
+ BnSurfaceComposer::GET_ACTIVE_DISPLAY_MODE,
+ BnSurfaceComposer::GET_DISPLAY_STATE,
+ BnSurfaceComposer::CAPTURE_DISPLAY,
+ BnSurfaceComposer::CAPTURE_LAYERS,
+ BnSurfaceComposer::CLEAR_ANIMATION_FRAME_STATS,
+ BnSurfaceComposer::GET_ANIMATION_FRAME_STATS,
+ BnSurfaceComposer::SET_POWER_MODE,
+ BnSurfaceComposer::GET_DISPLAY_STATS,
+ BnSurfaceComposer::GET_HDR_CAPABILITIES,
+ BnSurfaceComposer::GET_DISPLAY_COLOR_MODES,
+ BnSurfaceComposer::GET_ACTIVE_COLOR_MODE,
+ BnSurfaceComposer::SET_ACTIVE_COLOR_MODE,
+ BnSurfaceComposer::ENABLE_VSYNC_INJECTIONS,
+ BnSurfaceComposer::INJECT_VSYNC,
+ BnSurfaceComposer::GET_LAYER_DEBUG_INFO,
+ BnSurfaceComposer::GET_COMPOSITION_PREFERENCE,
+ BnSurfaceComposer::GET_COLOR_MANAGEMENT,
+ BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES,
+ BnSurfaceComposer::SET_DISPLAY_CONTENT_SAMPLING_ENABLED,
+ BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE,
+ BnSurfaceComposer::GET_PROTECTED_CONTENT_SUPPORT,
+ BnSurfaceComposer::IS_WIDE_COLOR_DISPLAY,
+ BnSurfaceComposer::GET_DISPLAY_NATIVE_PRIMARIES,
+ BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS,
+ BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER,
+ BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER,
+ BnSurfaceComposer::SET_DESIRED_DISPLAY_MODE_SPECS,
+ BnSurfaceComposer::GET_DESIRED_DISPLAY_MODE_SPECS,
+ BnSurfaceComposer::GET_DISPLAY_BRIGHTNESS_SUPPORT,
+ BnSurfaceComposer::SET_DISPLAY_BRIGHTNESS,
+ BnSurfaceComposer::CAPTURE_DISPLAY_BY_ID,
+ BnSurfaceComposer::NOTIFY_POWER_BOOST,
+ BnSurfaceComposer::SET_GLOBAL_SHADOW_SETTINGS,
+ BnSurfaceComposer::GET_AUTO_LOW_LATENCY_MODE_SUPPORT,
+ BnSurfaceComposer::SET_AUTO_LOW_LATENCY_MODE,
+ BnSurfaceComposer::GET_GAME_CONTENT_TYPE_SUPPORT,
+ BnSurfaceComposer::SET_GAME_CONTENT_TYPE,
+ BnSurfaceComposer::SET_FRAME_RATE,
+ BnSurfaceComposer::ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN,
+ BnSurfaceComposer::SET_FRAME_TIMELINE_INFO,
+ BnSurfaceComposer::ADD_TRANSACTION_TRACE_LISTENER,
+ BnSurfaceComposer::GET_GPU_CONTEXT_PRIORITY,
+ BnSurfaceComposer::GET_MAX_ACQUIRED_BUFFER_COUNT,
+ BnSurfaceComposer::GET_DYNAMIC_DISPLAY_INFO,
+ BnSurfaceComposer::ADD_FPS_LISTENER,
+ BnSurfaceComposer::REMOVE_FPS_LISTENER,
+ BnSurfaceComposer::OVERRIDE_HDR_TYPES,
+ BnSurfaceComposer::ADD_HDR_LAYER_INFO_LISTENER,
+ BnSurfaceComposer::REMOVE_HDR_LAYER_INFO_LISTENER,
+ BnSurfaceComposer::ON_PULL_ATOM,
+ BnSurfaceComposer::ADD_TUNNEL_MODE_ENABLED_LISTENER,
+ BnSurfaceComposer::REMOVE_TUNNEL_MODE_ENABLED_LISTENER,
+ BnSurfaceComposer::ADD_WINDOW_INFOS_LISTENER,
+ BnSurfaceComposer::REMOVE_WINDOW_INFOS_LISTENER,
+};
+
+static constexpr uint32_t kMinCode = 1000;
+static constexpr uint32_t kMaxCode = 1050;
+
+class SurfaceFlingerFuzzer {
+public:
+ SurfaceFlingerFuzzer(const uint8_t *data, size_t size) : mFdp(data, size) {
+ mFlinger = mTestableFlinger.flinger();
+ };
+ void process(const uint8_t *data, size_t size);
+
+private:
+ void setUp();
+ void invokeFlinger();
+ void setTransactionState();
+ void setInternalDisplayPrimaries();
+ void setDisplayStateLocked();
+ void onTransact(const uint8_t *data, size_t size);
+
+ FuzzedDataProvider mFdp;
+ TestableSurfaceFlinger mTestableFlinger;
+ sp<SurfaceFlinger> mFlinger = nullptr;
+};
+
+void SurfaceFlingerFuzzer::invokeFlinger() {
+ mFlinger->setSchedFifo(mFdp.ConsumeBool());
+ mFlinger->setSchedAttr(mFdp.ConsumeBool());
+ mFlinger->getServiceName();
+ mFlinger->hasSyncFramework = mFdp.ConsumeBool();
+ mFlinger->dispSyncPresentTimeOffset = mFdp.ConsumeIntegral<int64_t>();
+ mFlinger->useHwcForRgbToYuv = mFdp.ConsumeBool();
+ mFlinger->maxFrameBufferAcquiredBuffers = mFdp.ConsumeIntegral<int64_t>();
+ mFlinger->maxGraphicsWidth = mFdp.ConsumeIntegral<uint32_t>();
+ mFlinger->maxGraphicsHeight = mFdp.ConsumeIntegral<uint32_t>();
+ mFlinger->hasWideColorDisplay = mFdp.ConsumeBool();
+ mFlinger->internalDisplayOrientation = mFdp.PickValueInArray(kRotations);
+ mFlinger->useContextPriority = mFdp.ConsumeBool();
+
+ mFlinger->defaultCompositionDataspace = mFdp.PickValueInArray(kDataspaces);
+ mFlinger->defaultCompositionPixelFormat = mFdp.PickValueInArray(kPixelFormats);
+ mFlinger->wideColorGamutCompositionDataspace = mFdp.PickValueInArray(kDataspaces);
+ mFlinger->wideColorGamutCompositionPixelFormat = mFdp.PickValueInArray(kPixelFormats);
+
+ mFlinger->enableLatchUnsignaledConfig = mFdp.PickValueInArray(kLatchUnsignaledConfig);
+
+ mFlinger->scheduleComposite(mFdp.ConsumeBool()
+ ? scheduler::ISchedulerCallback::FrameHint::kActive
+ : scheduler::ISchedulerCallback::FrameHint::kNone);
+
+ mFlinger->scheduleRepaint();
+ mFlinger->scheduleSample();
+
+ uint32_t texture = mFlinger->getNewTexture();
+ mFlinger->deleteTextureAsync(texture);
+
+ sp<IBinder> handle = defaultServiceManager()->checkService(
+ String16(mFdp.ConsumeRandomLengthString().c_str()));
+ mFlinger->fromHandle(handle);
+ mFlinger->windowInfosReported();
+ mFlinger->disableExpensiveRendering();
+}
+
+void SurfaceFlingerFuzzer::setInternalDisplayPrimaries() {
+ ui::DisplayPrimaries primaries;
+ primaries.red.X = mFdp.ConsumeFloatingPoint<float>();
+ primaries.red.Y = mFdp.ConsumeFloatingPoint<float>();
+ primaries.red.Z = mFdp.ConsumeFloatingPoint<float>();
+ primaries.green.X = mFdp.ConsumeFloatingPoint<float>();
+ primaries.green.Y = mFdp.ConsumeFloatingPoint<float>();
+ primaries.green.Z = mFdp.ConsumeFloatingPoint<float>();
+ primaries.blue.X = mFdp.ConsumeFloatingPoint<float>();
+ primaries.blue.Y = mFdp.ConsumeFloatingPoint<float>();
+ primaries.blue.Z = mFdp.ConsumeFloatingPoint<float>();
+ primaries.white.X = mFdp.ConsumeFloatingPoint<float>();
+ primaries.white.Y = mFdp.ConsumeFloatingPoint<float>();
+ primaries.white.Z = mFdp.ConsumeFloatingPoint<float>();
+ mTestableFlinger.setInternalDisplayPrimaries(primaries);
+}
+
+void SurfaceFlingerFuzzer::setTransactionState() {
+ Vector<ComposerState> states;
+ Vector<DisplayState> displays;
+ ComposerState composerState;
+ composerState.state.what = layer_state_t::eLayerChanged;
+ composerState.state.surface = nullptr;
+ states.add(composerState);
+ uint32_t flags = mFdp.ConsumeIntegral<uint32_t>();
+ const sp<IBinder> applyToken = nullptr;
+ int64_t desiredPresentTime = mFdp.ConsumeIntegral<int64_t>();
+ bool isAutoTimestamp = mFdp.ConsumeBool();
+ bool hasListenerCallbacks = mFdp.ConsumeBool();
+ std::vector<ListenerCallbacks> listenerCallbacks{};
+ uint64_t transactionId = mFdp.ConsumeIntegral<uint64_t>();
+
+ mTestableFlinger.setTransactionState(FrameTimelineInfo{}, states, displays, flags, applyToken,
+ InputWindowCommands{}, desiredPresentTime, isAutoTimestamp,
+ {}, hasListenerCallbacks, listenerCallbacks,
+ transactionId);
+}
+
+void SurfaceFlingerFuzzer::setDisplayStateLocked() {
+ DisplayState state{};
+ mTestableFlinger.setDisplayStateLocked(state);
+}
+
+void SurfaceFlingerFuzzer::onTransact(const uint8_t *data, size_t size) {
+ Parcel fuzzedData, reply;
+ fuzzedData.writeInterfaceToken(String16("android.ui.ISurfaceComposer"));
+ fuzzedData.setData(data, size);
+ fuzzedData.setDataPosition(0);
+ uint32_t code = mFdp.ConsumeBool() ? mFdp.PickValueInArray(kSurfaceComposerTags)
+ : mFdp.ConsumeIntegralInRange<uint32_t>(kMinCode, kMaxCode);
+ mTestableFlinger.onTransact(code, fuzzedData, &reply, 0);
+}
+
+void SurfaceFlingerFuzzer::setUp() {
+ mTestableFlinger.setupScheduler(std::make_unique<android::mock::VsyncController>(),
+ std::make_unique<android::mock::VSyncTracker>(),
+ std::make_unique<android::mock::EventThread>(),
+ std::make_unique<android::mock::EventThread>());
+
+ mTestableFlinger.setupTimeStats(std::make_unique<android::mock::TimeStats>());
+
+ std::unique_ptr<android::renderengine::RenderEngine> renderEngine =
+ std::make_unique<android::renderengine::mock::RenderEngine>();
+ mTestableFlinger.setupRenderEngine(std::move(renderEngine));
+ mTestableFlinger.setupComposer(std::make_unique<android::Hwc2::mock::Composer>());
+}
+
+void SurfaceFlingerFuzzer::process(const uint8_t *data, size_t size) {
+ setUp();
+
+ invokeFlinger();
+
+ mTestableFlinger.fuzzSurfaceFlinger(data, size);
+
+ mTestableFlinger.setCreateBufferQueueFunction(
+ surfaceflinger::test::Factory::CreateBufferQueueFunction());
+ mTestableFlinger.setCreateNativeWindowSurface(
+ surfaceflinger::test::Factory::CreateNativeWindowSurfaceFunction());
+
+ setInternalDisplayPrimaries();
+
+ mTestableFlinger.enableHalVirtualDisplays(mFdp.ConsumeBool());
+
+ mTestableFlinger.commitTransactionsLocked(mFdp.ConsumeIntegral<uint32_t>());
+
+ mTestableFlinger.notifyPowerBoost(mFdp.ConsumeIntegral<int32_t>());
+
+ setDisplayStateLocked();
+
+ setTransactionState();
+ mTestableFlinger.flushTransactionQueues();
+
+ onTransact(data, size);
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ android::fuzz::SurfaceFlingerFuzzer surfaceFlingerFuzzer(data, size);
+ surfaceFlingerFuzzer.process(data, size);
+ return 0;
+}
+
+} // namespace android::fuzz
diff --git a/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h b/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h
new file mode 100644
index 0000000..0a458c2
--- /dev/null
+++ b/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h
@@ -0,0 +1,803 @@
+/*
+ * Copyright 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <compositionengine/Display.h>
+#include <compositionengine/LayerFECompositionState.h>
+#include <compositionengine/OutputLayer.h>
+#include <compositionengine/impl/CompositionEngine.h>
+#include <compositionengine/impl/Display.h>
+#include <compositionengine/impl/OutputLayerCompositionState.h>
+#include <gui/LayerDebugInfo.h>
+#include <gui/ScreenCaptureResults.h>
+#include <gui/SurfaceComposerClient.h>
+#include <gui/mock/GraphicBufferProducer.h>
+#include <ui/DisplayStatInfo.h>
+#include <ui/DynamicDisplayInfo.h>
+
+#include "BufferQueueLayer.h"
+#include "BufferStateLayer.h"
+#include "ContainerLayer.h"
+#include "DisplayDevice.h"
+#include "DisplayHardware/ComposerHal.h"
+#include "EffectLayer.h"
+#include "FrameTimeline/FrameTimeline.h"
+#include "FrameTracer/FrameTracer.h"
+#include "Layer.h"
+#include "NativeWindowSurface.h"
+#include "Scheduler/EventThread.h"
+#include "Scheduler/MessageQueue.h"
+#include "Scheduler/RefreshRateConfigs.h"
+#include "Scheduler/VSyncTracker.h"
+#include "Scheduler/VsyncConfiguration.h"
+#include "Scheduler/VsyncController.h"
+#include "Scheduler/VsyncModulator.h"
+#include "StartPropertySetThread.h"
+#include "SurfaceFlinger.h"
+#include "SurfaceFlingerDefaultFactory.h"
+#include "SurfaceInterceptor.h"
+#include "TimeStats/TimeStats.h"
+
+#include "renderengine/mock/RenderEngine.h"
+#include "scheduler/TimeKeeper.h"
+#include "tests/unittests/mock/DisplayHardware/MockComposer.h"
+#include "tests/unittests/mock/DisplayHardware/MockHWC2.h"
+#include "tests/unittests/mock/DisplayHardware/MockPowerAdvisor.h"
+#include "tests/unittests/mock/MockEventThread.h"
+#include "tests/unittests/mock/MockFrameTimeline.h"
+#include "tests/unittests/mock/MockFrameTracer.h"
+#include "tests/unittests/mock/MockNativeWindowSurface.h"
+#include "tests/unittests/mock/MockSurfaceInterceptor.h"
+#include "tests/unittests/mock/MockTimeStats.h"
+#include "tests/unittests/mock/MockVSyncTracker.h"
+#include "tests/unittests/mock/MockVsyncController.h"
+
+namespace android {
+namespace Hwc2 {
+
+class Composer;
+
+namespace types = hardware::graphics::common;
+
+namespace V2_1 = hardware::graphics::composer::V2_1;
+namespace V2_2 = hardware::graphics::composer::V2_2;
+namespace V2_3 = hardware::graphics::composer::V2_3;
+namespace V2_4 = hardware::graphics::composer::V2_4;
+
+using types::V1_0::ColorTransform;
+using types::V1_0::Transform;
+using types::V1_1::RenderIntent;
+using types::V1_2::ColorMode;
+using types::V1_2::Dataspace;
+using types::V1_2::Hdr;
+using types::V1_2::PixelFormat;
+
+using V2_1::Config;
+using V2_1::Display;
+using V2_1::Error;
+using V2_1::Layer;
+using V2_4::CommandReaderBase;
+using V2_4::CommandWriterBase;
+using V2_4::IComposer;
+using V2_4::IComposerCallback;
+using V2_4::IComposerClient;
+using V2_4::VsyncPeriodChangeTimeline;
+using V2_4::VsyncPeriodNanos;
+using DisplayCapability = IComposerClient::DisplayCapability;
+using PerFrameMetadata = IComposerClient::PerFrameMetadata;
+using PerFrameMetadataKey = IComposerClient::PerFrameMetadataKey;
+using PerFrameMetadataBlob = IComposerClient::PerFrameMetadataBlob;
+}; // namespace Hwc2
+
+static constexpr hal::HWDisplayId kHwDisplayId = 1000;
+
+static constexpr ui::Hdr kHdrTypes[] = {ui::Hdr::DOLBY_VISION, ui::Hdr::HDR10, ui::Hdr::HLG,
+ ui::Hdr::HDR10_PLUS};
+
+static constexpr ui::ColorMode kColormodes[] = {ui::ColorMode::NATIVE,
+ ui::ColorMode::STANDARD_BT601_625,
+ ui::ColorMode::STANDARD_BT601_625_UNADJUSTED,
+ ui::ColorMode::STANDARD_BT601_525,
+ ui::ColorMode::STANDARD_BT601_525_UNADJUSTED,
+ ui::ColorMode::STANDARD_BT709,
+ ui::ColorMode::DCI_P3,
+ ui::ColorMode::SRGB,
+ ui::ColorMode::ADOBE_RGB,
+ ui::ColorMode::DISPLAY_P3,
+ ui::ColorMode::BT2020,
+ ui::ColorMode::BT2100_PQ,
+ ui::ColorMode::BT2100_HLG,
+ ui::ColorMode::DISPLAY_BT2020};
+
+FloatRect getFuzzedFloatRect(FuzzedDataProvider *fdp) {
+ return FloatRect(fdp->ConsumeFloatingPoint<float>() /*left*/,
+ fdp->ConsumeFloatingPoint<float>() /*right*/,
+ fdp->ConsumeFloatingPoint<float>() /*top*/,
+ fdp->ConsumeFloatingPoint<float>() /*bottom*/);
+}
+
+HdrMetadata getFuzzedHdrMetadata(FuzzedDataProvider *fdp) {
+ HdrMetadata hdrMetadata;
+ if (fdp->ConsumeBool()) {
+ hdrMetadata.cta8613.maxContentLightLevel = fdp->ConsumeFloatingPoint<float>();
+ hdrMetadata.cta8613.maxFrameAverageLightLevel = fdp->ConsumeFloatingPoint<float>();
+
+ hdrMetadata.validTypes |= HdrMetadata::CTA861_3;
+ } else {
+ hdrMetadata.smpte2086.displayPrimaryRed.x = fdp->ConsumeFloatingPoint<float>();
+ hdrMetadata.smpte2086.displayPrimaryRed.y = fdp->ConsumeFloatingPoint<float>();
+ hdrMetadata.smpte2086.displayPrimaryGreen.x = fdp->ConsumeFloatingPoint<float>();
+ hdrMetadata.smpte2086.displayPrimaryGreen.y = fdp->ConsumeFloatingPoint<float>();
+ hdrMetadata.smpte2086.displayPrimaryBlue.x = fdp->ConsumeFloatingPoint<float>();
+ hdrMetadata.smpte2086.displayPrimaryBlue.y = fdp->ConsumeFloatingPoint<float>();
+ hdrMetadata.smpte2086.whitePoint.x = fdp->ConsumeFloatingPoint<float>();
+ hdrMetadata.smpte2086.whitePoint.y = fdp->ConsumeFloatingPoint<float>();
+ hdrMetadata.smpte2086.minLuminance = fdp->ConsumeFloatingPoint<float>();
+ hdrMetadata.smpte2086.maxLuminance = fdp->ConsumeFloatingPoint<float>();
+
+ hdrMetadata.validTypes |= HdrMetadata::SMPTE2086;
+ }
+ return hdrMetadata;
+}
+
+class EventThread;
+
+namespace hal = android::hardware::graphics::composer::hal;
+
+struct FakePhaseOffsets : scheduler::VsyncConfiguration {
+ static constexpr nsecs_t FAKE_PHASE_OFFSET_NS = 0;
+ static constexpr auto FAKE_DURATION_OFFSET_NS = std::chrono::nanoseconds(0);
+
+ VsyncConfigSet getConfigsForRefreshRate(Fps) const override { return getCurrentConfigs(); }
+
+ VsyncConfigSet getCurrentConfigs() const override {
+ return {{FAKE_PHASE_OFFSET_NS, FAKE_PHASE_OFFSET_NS, FAKE_DURATION_OFFSET_NS,
+ FAKE_DURATION_OFFSET_NS},
+ {FAKE_PHASE_OFFSET_NS, FAKE_PHASE_OFFSET_NS, FAKE_DURATION_OFFSET_NS,
+ FAKE_DURATION_OFFSET_NS},
+ {FAKE_PHASE_OFFSET_NS, FAKE_PHASE_OFFSET_NS, FAKE_DURATION_OFFSET_NS,
+ FAKE_DURATION_OFFSET_NS},
+ FAKE_DURATION_OFFSET_NS};
+ }
+
+ void reset() override {}
+ void setRefreshRateFps(Fps) override {}
+ void dump(std::string &) const override {}
+};
+namespace scheduler {
+class TestableScheduler : public Scheduler, private ICompositor {
+public:
+ TestableScheduler(const std::shared_ptr<scheduler::RefreshRateConfigs> &refreshRateConfigs,
+ ISchedulerCallback &callback)
+ : TestableScheduler(std::make_unique<android::mock::VsyncController>(),
+ std::make_unique<android::mock::VSyncTracker>(), refreshRateConfigs,
+ callback) {}
+
+ void scheduleFrame(){};
+ void postMessage(sp<MessageHandler> &&){};
+
+ TestableScheduler(std::unique_ptr<VsyncController> controller,
+ std::unique_ptr<VSyncTracker> tracker,
+ std::shared_ptr<RefreshRateConfigs> configs, ISchedulerCallback &callback)
+ : Scheduler(*this, callback, Feature::kContentDetection) {
+ mVsyncSchedule.emplace(VsyncSchedule(std::move(tracker), nullptr, std::move(controller)));
+ setRefreshRateConfigs(std::move(configs));
+ }
+
+ ConnectionHandle createConnection(std::unique_ptr<EventThread> eventThread) {
+ return Scheduler::createConnection(std::move(eventThread));
+ }
+
+ auto &mutablePrimaryHWVsyncEnabled() { return mPrimaryHWVsyncEnabled; }
+ auto &mutableHWVsyncAvailable() { return mHWVsyncAvailable; }
+
+ auto &mutableLayerHistory() { return mLayerHistory; }
+
+ auto refreshRateConfigs() { return holdRefreshRateConfigs(); }
+
+ void replaceTouchTimer(int64_t millis) {
+ if (mTouchTimer) {
+ mTouchTimer.reset();
+ }
+ mTouchTimer.emplace(
+ "Testable Touch timer", std::chrono::milliseconds(millis),
+ [this] { touchTimerCallback(TimerState::Reset); },
+ [this] { touchTimerCallback(TimerState::Expired); });
+ mTouchTimer->start();
+ }
+
+ bool isTouchActive() {
+ std::lock_guard<std::mutex> lock(mPolicyLock);
+ return mPolicy.touch == Scheduler::TouchState::Active;
+ }
+
+ void dispatchCachedReportedMode() {
+ std::lock_guard<std::mutex> lock(mPolicyLock);
+ return Scheduler::dispatchCachedReportedMode();
+ }
+
+ void clearCachedReportedMode() {
+ std::lock_guard<std::mutex> lock(mPolicyLock);
+ mPolicy.cachedModeChangedParams.reset();
+ }
+
+ void onNonPrimaryDisplayModeChanged(ConnectionHandle handle, DisplayModePtr mode) {
+ return Scheduler::onNonPrimaryDisplayModeChanged(handle, mode);
+ }
+
+private:
+ // ICompositor overrides:
+ bool commit(nsecs_t, int64_t, nsecs_t) override { return false; }
+ void composite(nsecs_t) override {}
+ void sample() override {}
+};
+}; // namespace scheduler
+
+namespace surfaceflinger::test {
+
+class Factory final : public surfaceflinger::Factory {
+public:
+ ~Factory() = default;
+
+ std::unique_ptr<HWComposer> createHWComposer(const std::string &) override { return nullptr; }
+
+ std::unique_ptr<MessageQueue> createMessageQueue(ICompositor &compositor) {
+ return std::make_unique<android::impl::MessageQueue>(compositor);
+ }
+
+ std::unique_ptr<scheduler::VsyncConfiguration> createVsyncConfiguration(
+ Fps /*currentRefreshRate*/) override {
+ return std::make_unique<FakePhaseOffsets>();
+ }
+
+ std::unique_ptr<scheduler::Scheduler> createScheduler(
+ const std::shared_ptr<scheduler::RefreshRateConfigs> &,
+ scheduler::ISchedulerCallback &) {
+ return nullptr;
+ }
+
+ sp<SurfaceInterceptor> createSurfaceInterceptor() override {
+ return new android::impl::SurfaceInterceptor();
+ }
+
+ sp<StartPropertySetThread> createStartPropertySetThread(bool timestampPropertyValue) override {
+ return new StartPropertySetThread(timestampPropertyValue);
+ }
+
+ sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs &creationArgs) override {
+ return new DisplayDevice(creationArgs);
+ }
+
+ sp<GraphicBuffer> createGraphicBuffer(uint32_t width, uint32_t height, PixelFormat format,
+ uint32_t layerCount, uint64_t usage,
+ std::string requestorName) override {
+ return new GraphicBuffer(width, height, format, layerCount, usage, requestorName);
+ }
+
+ void createBufferQueue(sp<IGraphicBufferProducer> *outProducer,
+ sp<IGraphicBufferConsumer> *outConsumer,
+ bool consumerIsSurfaceFlinger) override {
+ if (!mCreateBufferQueue) {
+ BufferQueue::createBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger);
+ return;
+ }
+ mCreateBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger);
+ }
+
+ sp<IGraphicBufferProducer> createMonitoredProducer(const sp<IGraphicBufferProducer> &producer,
+ const sp<SurfaceFlinger> &flinger,
+ const wp<Layer> &layer) override {
+ return new MonitoredProducer(producer, flinger, layer);
+ }
+
+ sp<BufferLayerConsumer> createBufferLayerConsumer(const sp<IGraphicBufferConsumer> &consumer,
+ renderengine::RenderEngine &renderEngine,
+ uint32_t textureName, Layer *layer) override {
+ return new BufferLayerConsumer(consumer, renderEngine, textureName, layer);
+ }
+
+ std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface(
+ const sp<IGraphicBufferProducer> &producer) override {
+ if (!mCreateNativeWindowSurface) return nullptr;
+ return mCreateNativeWindowSurface(producer);
+ }
+
+ std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() override {
+ return compositionengine::impl::createCompositionEngine();
+ }
+
+ sp<BufferQueueLayer> createBufferQueueLayer(const LayerCreationArgs &) override {
+ return nullptr;
+ }
+
+ sp<BufferStateLayer> createBufferStateLayer(const LayerCreationArgs &) override {
+ return nullptr;
+ }
+
+ sp<EffectLayer> createEffectLayer(const LayerCreationArgs &args) override {
+ return new EffectLayer(args);
+ }
+
+ sp<ContainerLayer> createContainerLayer(const LayerCreationArgs &args) override {
+ return new ContainerLayer(args);
+ }
+
+ std::unique_ptr<FrameTracer> createFrameTracer() override {
+ return std::make_unique<android::mock::FrameTracer>();
+ }
+
+ std::unique_ptr<frametimeline::FrameTimeline> createFrameTimeline(
+ std::shared_ptr<TimeStats> timeStats, pid_t surfaceFlingerPid = 0) override {
+ return std::make_unique<android::mock::FrameTimeline>(timeStats, surfaceFlingerPid);
+ }
+
+ using CreateBufferQueueFunction =
+ std::function<void(sp<IGraphicBufferProducer> * /* outProducer */,
+ sp<IGraphicBufferConsumer> * /* outConsumer */,
+ bool /* consumerIsSurfaceFlinger */)>;
+ CreateBufferQueueFunction mCreateBufferQueue;
+
+ using CreateNativeWindowSurfaceFunction =
+ std::function<std::unique_ptr<surfaceflinger::NativeWindowSurface>(
+ const sp<IGraphicBufferProducer> &)>;
+ CreateNativeWindowSurfaceFunction mCreateNativeWindowSurface;
+
+ using CreateCompositionEngineFunction =
+ std::function<std::unique_ptr<compositionengine::CompositionEngine>()>;
+ CreateCompositionEngineFunction mCreateCompositionEngine;
+};
+
+} // namespace surfaceflinger::test
+
+// TODO(b/189053744) : Create a common test/mock library for surfaceflinger
+class TestableSurfaceFlinger final : private scheduler::ISchedulerCallback {
+public:
+ using HotplugEvent = SurfaceFlinger::HotplugEvent;
+
+ SurfaceFlinger *flinger() { return mFlinger.get(); }
+ scheduler::TestableScheduler *scheduler() { return mScheduler; }
+
+ // Allow reading display state without locking, as if called on the SF main thread.
+ auto onInitializeDisplays() NO_THREAD_SAFETY_ANALYSIS {
+ return mFlinger->onInitializeDisplays();
+ }
+
+ void scheduleComposite(FrameHint){};
+
+ void setGlobalShadowSettings(FuzzedDataProvider *fdp) {
+ const half4 ambientColor{fdp->ConsumeFloatingPoint<float>(),
+ fdp->ConsumeFloatingPoint<float>(),
+ fdp->ConsumeFloatingPoint<float>(),
+ fdp->ConsumeFloatingPoint<float>()};
+ const half4 spotColor{fdp->ConsumeFloatingPoint<float>(),
+ fdp->ConsumeFloatingPoint<float>(),
+ fdp->ConsumeFloatingPoint<float>(),
+ fdp->ConsumeFloatingPoint<float>()};
+ float lightPosY = fdp->ConsumeFloatingPoint<float>();
+ float lightPosZ = fdp->ConsumeFloatingPoint<float>();
+ float lightRadius = fdp->ConsumeFloatingPoint<float>();
+ mFlinger->setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ,
+ lightRadius);
+ }
+
+ void onPullAtom(FuzzedDataProvider *fdp) {
+ const int32_t atomId = fdp->ConsumeIntegral<uint8_t>();
+ std::string pulledData = fdp->ConsumeRandomLengthString().c_str();
+ bool success = fdp->ConsumeBool();
+ mFlinger->onPullAtom(atomId, &pulledData, &success);
+ }
+
+ void fuzzDumpsysAndDebug(FuzzedDataProvider *fdp) {
+ std::string result = fdp->ConsumeRandomLengthString().c_str();
+ mFlinger->appendSfConfigString(result);
+ result = fdp->ConsumeRandomLengthString().c_str();
+ mFlinger->listLayersLocked(result);
+
+ using DumpArgs = Vector<String16>;
+ DumpArgs dumpArgs;
+ dumpArgs.push_back(String16(fdp->ConsumeRandomLengthString().c_str()));
+ mFlinger->clearStatsLocked(dumpArgs, result);
+
+ mFlinger->dumpTimeStats(dumpArgs, fdp->ConsumeBool(), result);
+ mFlinger->logFrameStats();
+
+ result = fdp->ConsumeRandomLengthString().c_str();
+ mFlinger->dumpFrameTimeline(dumpArgs, result);
+
+ result = fdp->ConsumeRandomLengthString().c_str();
+ mFlinger->dumpStaticScreenStats(result);
+
+ result = fdp->ConsumeRandomLengthString().c_str();
+ mFlinger->dumpFrameEventsLocked(result);
+
+ result = fdp->ConsumeRandomLengthString().c_str();
+ mFlinger->dumpRawDisplayIdentificationData(dumpArgs, result);
+
+ LayersProto layersProto = mFlinger->dumpDrawingStateProto(fdp->ConsumeIntegral<uint32_t>());
+ mFlinger->dumpOffscreenLayersProto(layersProto);
+ LayersTraceProto layersTraceProto{};
+ mFlinger->dumpDisplayProto(layersTraceProto);
+
+ result = fdp->ConsumeRandomLengthString().c_str();
+ mFlinger->dumpHwc(result);
+
+ mFlinger->calculateColorMatrix(fdp->ConsumeFloatingPoint<float>());
+ mFlinger->updateColorMatrixLocked();
+ mFlinger->CheckTransactCodeCredentials(fdp->ConsumeIntegral<uint32_t>());
+
+ const CountDownLatch transactionCommittedSignal(fdp->ConsumeIntegral<uint32_t>());
+ mFlinger->waitForSynchronousTransaction(transactionCommittedSignal);
+ mFlinger->signalSynchronousTransactions(fdp->ConsumeIntegral<uint32_t>());
+ }
+
+ void getCompositionPreference() {
+ ui::Dataspace outDataspace;
+ ui::PixelFormat outPixelFormat;
+ ui::Dataspace outWideColorGamutDataspace;
+ ui::PixelFormat outWideColorGamutPixelFormat;
+ mFlinger->getCompositionPreference(&outDataspace, &outPixelFormat,
+ &outWideColorGamutDataspace,
+ &outWideColorGamutPixelFormat);
+ }
+
+ void overrideHdrTypes(sp<IBinder> &display, FuzzedDataProvider *fdp) {
+ std::vector<ui::Hdr> hdrTypes;
+ hdrTypes.push_back(fdp->PickValueInArray(kHdrTypes));
+ mFlinger->overrideHdrTypes(display, hdrTypes);
+ }
+
+ void getDisplayedContentSample(sp<IBinder> &display, FuzzedDataProvider *fdp) {
+ DisplayedFrameStats outDisplayedFrameStats;
+ mFlinger->getDisplayedContentSample(display, fdp->ConsumeIntegral<uint64_t>(),
+ fdp->ConsumeIntegral<uint64_t>(),
+ &outDisplayedFrameStats);
+ }
+
+ void getDisplayStats(sp<IBinder> &display) {
+ android::DisplayStatInfo stats;
+ mFlinger->getDisplayStats(display, &stats);
+ }
+
+ void getDisplayState(sp<IBinder> &display) {
+ ui::DisplayState displayState;
+ mFlinger->getDisplayState(display, &displayState);
+ }
+
+ void getStaticDisplayInfo(sp<IBinder> &display) {
+ ui::StaticDisplayInfo staticDisplayInfo;
+ mFlinger->getStaticDisplayInfo(display, &staticDisplayInfo);
+ }
+
+ void getDynamicDisplayInfo(sp<IBinder> &display) {
+ android::ui::DynamicDisplayInfo dynamicDisplayInfo;
+ mFlinger->getDynamicDisplayInfo(display, &dynamicDisplayInfo);
+ }
+ void getDisplayNativePrimaries(sp<IBinder> &display) {
+ android::ui::DisplayPrimaries displayPrimaries;
+ mFlinger->getDisplayNativePrimaries(display, displayPrimaries);
+ }
+
+ void getDesiredDisplayModeSpecs(sp<IBinder> &display) {
+ ui::DisplayModeId outDefaultMode;
+ bool outAllowGroupSwitching;
+ float outPrimaryRefreshRateMin;
+ float outPrimaryRefreshRateMax;
+ float outAppRequestRefreshRateMin;
+ float outAppRequestRefreshRateMax;
+ mFlinger->getDesiredDisplayModeSpecs(display, &outDefaultMode, &outAllowGroupSwitching,
+ &outPrimaryRefreshRateMin, &outPrimaryRefreshRateMax,
+ &outAppRequestRefreshRateMin,
+ &outAppRequestRefreshRateMax);
+ }
+
+ void setVsyncConfig(FuzzedDataProvider *fdp) {
+ const scheduler::VsyncModulator::VsyncConfig vsyncConfig{};
+ mFlinger->setVsyncConfig(vsyncConfig, fdp->ConsumeIntegral<nsecs_t>());
+ }
+
+ void updateCompositorTiming(FuzzedDataProvider *fdp) {
+ std::shared_ptr<FenceTime> presentFenceTime = FenceTime::NO_FENCE;
+ mFlinger->updateCompositorTiming({}, fdp->ConsumeIntegral<nsecs_t>(), presentFenceTime);
+ }
+
+ void getCompositorTiming() {
+ CompositorTiming compositorTiming;
+ mFlinger->getCompositorTiming(&compositorTiming);
+ }
+
+ sp<IBinder> fuzzBoot(FuzzedDataProvider *fdp) {
+ mFlinger->callingThreadHasUnscopedSurfaceFlingerAccess(fdp->ConsumeBool());
+ mFlinger->createConnection();
+
+ DisplayIdGenerator<HalVirtualDisplayId> kGenerator;
+ HalVirtualDisplayId halVirtualDisplayId = kGenerator.generateId().value();
+
+ ui::Size uiSize{fdp->ConsumeIntegral<int32_t>(), fdp->ConsumeIntegral<int32_t>()};
+ ui::PixelFormat pixelFormat{};
+ mFlinger->getHwComposer().allocateVirtualDisplay(halVirtualDisplayId, uiSize, &pixelFormat);
+
+ PhysicalDisplayId physicalDisplayId = SurfaceComposerClient::getInternalDisplayId().value();
+ mFlinger->getHwComposer().allocatePhysicalDisplay(kHwDisplayId, physicalDisplayId);
+
+ sp<IBinder> display =
+ mFlinger->createDisplay(String8(fdp->ConsumeRandomLengthString().c_str()),
+ fdp->ConsumeBool());
+
+ onInitializeDisplays();
+ mFlinger->getPhysicalDisplayToken(physicalDisplayId);
+
+ mFlinger->mStartPropertySetThread =
+ mFlinger->getFactory().createStartPropertySetThread(fdp->ConsumeBool());
+
+ mFlinger->bootFinished();
+
+ return display;
+ }
+
+ void fuzzSurfaceFlinger(const uint8_t *data, size_t size) {
+ FuzzedDataProvider mFdp(data, size);
+
+ sp<IBinder> display = fuzzBoot(&mFdp);
+
+ sp<IGraphicBufferProducer> bufferProducer = sp<mock::GraphicBufferProducer>::make();
+ mFlinger->authenticateSurfaceTexture(bufferProducer.get());
+
+ mFlinger->createDisplayEventConnection();
+
+ getDisplayStats(display);
+ getDisplayState(display);
+ getStaticDisplayInfo(display);
+ getDynamicDisplayInfo(display);
+ getDisplayNativePrimaries(display);
+
+ mFlinger->setAutoLowLatencyMode(display, mFdp.ConsumeBool());
+ mFlinger->setGameContentType(display, mFdp.ConsumeBool());
+ mFlinger->setPowerMode(display, mFdp.ConsumeIntegral<int>());
+ mFlinger->clearAnimationFrameStats();
+
+ overrideHdrTypes(display, &mFdp);
+
+ onPullAtom(&mFdp);
+
+ mFlinger->injectVSync(mFdp.ConsumeIntegral<nsecs_t>());
+
+ getCompositionPreference();
+ getDisplayedContentSample(display, &mFdp);
+ getDesiredDisplayModeSpecs(display);
+
+ bool outSupport;
+ mFlinger->getDisplayBrightnessSupport(display, &outSupport);
+
+ mFlinger->notifyPowerBoost(mFdp.ConsumeIntegral<int32_t>());
+
+ setGlobalShadowSettings(&mFdp);
+
+ mFlinger->binderDied(display);
+ mFlinger->onFirstRef();
+
+ mFlinger->commitTransactions();
+ mFlinger->updateInputFlinger();
+ mFlinger->updateCursorAsync();
+
+ setVsyncConfig(&mFdp);
+
+ mFlinger->flushTransactionQueues(0);
+
+ mFlinger->setTransactionFlags(mFdp.ConsumeIntegral<uint32_t>());
+ mFlinger->clearTransactionFlags(mFdp.ConsumeIntegral<uint32_t>());
+ mFlinger->commitOffscreenLayers();
+
+ mFlinger->frameIsEarly(mFdp.ConsumeIntegral<nsecs_t>(), mFdp.ConsumeIntegral<int64_t>());
+ mFlinger->computeLayerBounds();
+ mFlinger->startBootAnim();
+
+ mFlinger->readPersistentProperties();
+
+ mFlinger->exceedsMaxRenderTargetSize(mFdp.ConsumeIntegral<uint32_t>(),
+ mFdp.ConsumeIntegral<uint32_t>());
+
+ mFlinger->getMaxAcquiredBufferCountForCurrentRefreshRate(mFdp.ConsumeIntegral<uid_t>());
+
+ mFlinger->postComposition();
+
+ getCompositorTiming();
+
+ updateCompositorTiming(&mFdp);
+
+ mFlinger->setCompositorTimingSnapped({}, mFdp.ConsumeIntegral<nsecs_t>());
+ mFlinger->postFrame();
+ mFlinger->calculateExpectedPresentTime({});
+
+ mFlinger->enableHalVirtualDisplays(mFdp.ConsumeBool());
+
+ fuzzDumpsysAndDebug(&mFdp);
+
+ mFlinger->destroyDisplay(display);
+ }
+
+ void setupRenderEngine(std::unique_ptr<renderengine::RenderEngine> renderEngine) {
+ mFlinger->mCompositionEngine->setRenderEngine(std::move(renderEngine));
+ }
+
+ void setupComposer(std::unique_ptr<Hwc2::Composer> composer) {
+ mFlinger->mCompositionEngine->setHwComposer(
+ std::make_unique<impl::HWComposer>(std::move(composer)));
+ }
+
+ void setupTimeStats(const std::shared_ptr<TimeStats> &timeStats) {
+ mFlinger->mCompositionEngine->setTimeStats(timeStats);
+ }
+
+ // The ISchedulerCallback argument can be nullptr for a no-op implementation.
+ void setupScheduler(std::unique_ptr<scheduler::VsyncController> vsyncController,
+ std::unique_ptr<scheduler::VSyncTracker> vsyncTracker,
+ std::unique_ptr<EventThread> appEventThread,
+ std::unique_ptr<EventThread> sfEventThread,
+ scheduler::ISchedulerCallback *callback = nullptr,
+ bool hasMultipleModes = false) {
+ DisplayModes modes{DisplayMode::Builder(0)
+ .setId(DisplayModeId(0))
+ .setPhysicalDisplayId(PhysicalDisplayId::fromPort(0))
+ .setVsyncPeriod(16'666'667)
+ .setGroup(0)
+ .build()};
+
+ if (hasMultipleModes) {
+ modes.emplace_back(DisplayMode::Builder(1)
+ .setId(DisplayModeId(1))
+ .setPhysicalDisplayId(PhysicalDisplayId::fromPort(0))
+ .setVsyncPeriod(11'111'111)
+ .setGroup(0)
+ .build());
+ }
+
+ const auto currMode = DisplayModeId(0);
+ mRefreshRateConfigs = std::make_shared<scheduler::RefreshRateConfigs>(modes, currMode);
+ const auto currFps = mRefreshRateConfigs->getCurrentRefreshRate().getFps();
+ mFlinger->mVsyncConfiguration = mFactory.createVsyncConfiguration(currFps);
+ mFlinger->mVsyncModulator = sp<scheduler::VsyncModulator>::make(
+ mFlinger->mVsyncConfiguration->getCurrentConfigs());
+ mFlinger->mRefreshRateStats =
+ std::make_unique<scheduler::RefreshRateStats>(*mFlinger->mTimeStats, currFps,
+ /*powerMode=*/hal::PowerMode::OFF);
+
+ mScheduler = new scheduler::TestableScheduler(std::move(vsyncController),
+ std::move(vsyncTracker), mRefreshRateConfigs,
+ *(callback ?: this));
+
+ mFlinger->mAppConnectionHandle = mScheduler->createConnection(std::move(appEventThread));
+ mFlinger->mSfConnectionHandle = mScheduler->createConnection(std::move(sfEventThread));
+ resetScheduler(mScheduler);
+ }
+
+ void resetScheduler(scheduler::Scheduler *scheduler) { mFlinger->mScheduler.reset(scheduler); }
+
+ scheduler::TestableScheduler &mutableScheduler() const { return *mScheduler; }
+
+ using CreateBufferQueueFunction = surfaceflinger::test::Factory::CreateBufferQueueFunction;
+ void setCreateBufferQueueFunction(CreateBufferQueueFunction f) {
+ mFactory.mCreateBufferQueue = f;
+ }
+
+ using CreateNativeWindowSurfaceFunction =
+ surfaceflinger::test::Factory::CreateNativeWindowSurfaceFunction;
+ void setCreateNativeWindowSurface(CreateNativeWindowSurfaceFunction f) {
+ mFactory.mCreateNativeWindowSurface = f;
+ }
+
+ void setInternalDisplayPrimaries(const ui::DisplayPrimaries &primaries) {
+ memcpy(&mFlinger->mInternalDisplayPrimaries, &primaries, sizeof(ui::DisplayPrimaries));
+ }
+
+ static auto &mutableLayerDrawingState(const sp<Layer> &layer) { return layer->mDrawingState; }
+
+ auto &mutableStateLock() { return mFlinger->mStateLock; }
+
+ static auto findOutputLayerForDisplay(const sp<Layer> &layer,
+ const sp<const DisplayDevice> &display) {
+ return layer->findOutputLayerForDisplay(display.get());
+ }
+
+ /* ------------------------------------------------------------------------
+ * Forwarding for functions being tested
+ */
+
+ void enableHalVirtualDisplays(bool enable) { mFlinger->enableHalVirtualDisplays(enable); }
+
+ auto commitTransactionsLocked(uint32_t transactionFlags) {
+ Mutex::Autolock lock(mFlinger->mStateLock);
+ return mFlinger->commitTransactionsLocked(transactionFlags);
+ }
+
+ auto setDisplayStateLocked(const DisplayState &s) {
+ Mutex::Autolock lock(mFlinger->mStateLock);
+ return mFlinger->setDisplayStateLocked(s);
+ }
+
+ auto notifyPowerBoost(int32_t boostId) { return mFlinger->notifyPowerBoost(boostId); }
+
+ // Allow reading display state without locking, as if called on the SF main thread.
+ auto setPowerModeInternal(const sp<DisplayDevice> &display,
+ hal::PowerMode mode) NO_THREAD_SAFETY_ANALYSIS {
+ return mFlinger->setPowerModeInternal(display, mode);
+ }
+
+ auto onMessageReceived(int32_t /*what*/) { return 0; }
+
+ auto &getTransactionQueue() { return mFlinger->mTransactionQueue; }
+ auto &getPendingTransactionQueue() { return mFlinger->mPendingTransactionQueues; }
+
+ auto setTransactionState(
+ const FrameTimelineInfo &frameTimelineInfo, const Vector<ComposerState> &states,
+ const Vector<DisplayState> &displays, uint32_t flags, const sp<IBinder> &applyToken,
+ const InputWindowCommands &inputWindowCommands, int64_t desiredPresentTime,
+ bool isAutoTimestamp, const client_cache_t &uncacheBuffer, bool hasListenerCallbacks,
+ std::vector<ListenerCallbacks> &listenerCallbacks, uint64_t transactionId) {
+ return mFlinger->setTransactionState(frameTimelineInfo, states, displays, flags, applyToken,
+ inputWindowCommands, desiredPresentTime,
+ isAutoTimestamp, uncacheBuffer, hasListenerCallbacks,
+ listenerCallbacks, transactionId);
+ }
+
+ auto flushTransactionQueues() { return mFlinger->flushTransactionQueues(0); };
+
+ auto onTransact(uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
+ return mFlinger->onTransact(code, data, reply, flags);
+ }
+
+ auto getGPUContextPriority() { return mFlinger->getGPUContextPriority(); }
+
+ auto calculateMaxAcquiredBufferCount(Fps refreshRate,
+ std::chrono::nanoseconds presentLatency) const {
+ return SurfaceFlinger::calculateMaxAcquiredBufferCount(refreshRate, presentLatency);
+ }
+
+ /* Read-write access to private data to set up preconditions and assert
+ * post-conditions.
+ */
+
+ auto &mutableCurrentState() { return mFlinger->mCurrentState; }
+ auto &mutableDisplays() { return mFlinger->mDisplays; }
+ auto &mutableDrawingState() { return mFlinger->mDrawingState; }
+ auto &mutableInterceptor() { return mFlinger->mInterceptor; }
+
+ auto fromHandle(const sp<IBinder> &handle) { return mFlinger->fromHandle(handle); }
+
+ ~TestableSurfaceFlinger() {
+ mutableDisplays().clear();
+ mutableCurrentState().displays.clear();
+ mutableDrawingState().displays.clear();
+ mutableInterceptor().clear();
+ mFlinger->mScheduler.reset();
+ mFlinger->mCompositionEngine->setHwComposer(std::unique_ptr<HWComposer>());
+ mFlinger->mCompositionEngine->setRenderEngine(
+ std::unique_ptr<renderengine::RenderEngine>());
+ }
+
+private:
+ void scheduleRefresh(FrameHint) {}
+ void setVsyncEnabled(bool) override {}
+ void changeRefreshRate(const RefreshRate &, DisplayModeEvent) override {}
+ void kernelTimerChanged(bool) override {}
+ void triggerOnFrameRateOverridesChanged() {}
+
+ surfaceflinger::test::Factory mFactory;
+ sp<SurfaceFlinger> mFlinger = new SurfaceFlinger(mFactory, SurfaceFlinger::SkipInitialization);
+ scheduler::TestableScheduler *mScheduler = nullptr;
+ std::shared_ptr<scheduler::RefreshRateConfigs> mRefreshRateConfigs;
+};
+} // namespace android
diff --git a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h
index 261e106..0765d5b 100644
--- a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h
+++ b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h
@@ -136,7 +136,6 @@
V2_4::Error(Display, Config, const IComposerClient::VsyncPeriodChangeConstraints&,
VsyncPeriodChangeTimeline*));
MOCK_METHOD2(setAutoLowLatencyMode, V2_4::Error(Display, bool));
- MOCK_METHOD2(getBootDisplayConfigSupport, Error(Display, bool*));
MOCK_METHOD2(setBootDisplayConfig, Error(Display, Config));
MOCK_METHOD1(clearBootDisplayConfig, Error(Display));
MOCK_METHOD2(getPreferredBootDisplayConfig, Error(Display, Config*));