Merge "SurfaceFlinger: remove SurfaceControl level vsyncId setting" into sc-dev
diff --git a/cmds/atrace/atrace.cpp b/cmds/atrace/atrace.cpp
index 3184843..cedff0b 100644
--- a/cmds/atrace/atrace.cpp
+++ b/cmds/atrace/atrace.cpp
@@ -62,7 +62,7 @@
using std::string;
-#define MAX_SYS_FILES 11
+#define MAX_SYS_FILES 12
const char* k_traceTagsProperty = "debug.atrace.tags.enableflags";
const char* k_userInitiatedTraceProperty = "debug.atrace.user_initiated";
@@ -177,6 +177,7 @@
{ OPT, "events/power/suspend_resume/enable" },
{ OPT, "events/cpuhp/cpuhp_enter/enable" },
{ OPT, "events/cpuhp/cpuhp_exit/enable" },
+ { OPT, "events/cpuhp/cpuhp_pause/enable" },
} },
{ "membus", "Memory Bus Utilization", 0, {
{ REQ, "events/memory_bus/enable" },
diff --git a/cmds/atrace/atrace.rc b/cmds/atrace/atrace.rc
index 006e532..37fc9a9 100644
--- a/cmds/atrace/atrace.rc
+++ b/cmds/atrace/atrace.rc
@@ -57,6 +57,8 @@
chmod 0666 /sys/kernel/tracing/events/cpuhp/cpuhp_enter/enable
chmod 0666 /sys/kernel/debug/tracing/events/cpuhp/cpuhp_exit/enable
chmod 0666 /sys/kernel/tracing/events/cpuhp/cpuhp_exit/enable
+ chmod 0666 /sys/kernel/debug/tracing/events/cpuhp/cpuhp_pause/enable
+ chmod 0666 /sys/kernel/tracing/events/cpuhp/cpuhp_pause/enable
chmod 0666 /sys/kernel/debug/tracing/events/power/gpu_frequency/enable
chmod 0666 /sys/kernel/tracing/events/power/gpu_frequency/enable
chmod 0666 /sys/kernel/debug/tracing/events/power/suspend_resume/enable
diff --git a/cmds/dumpstate/DumpPool.cpp b/cmds/dumpstate/DumpPool.cpp
index e15ac3f..c2c8a72 100644
--- a/cmds/dumpstate/DumpPool.cpp
+++ b/cmds/dumpstate/DumpPool.cpp
@@ -64,8 +64,8 @@
if (shutdown_ || threads_.empty()) {
return;
}
- while (!tasks_.empty()) tasks_.pop();
futures_map_.clear();
+ while (!tasks_.empty()) tasks_.pop();
shutdown_ = true;
condition_variable_.notify_all();
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index a999c9f..7ab2a8d 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -3027,11 +3027,14 @@
}
void Dumpstate::MaybeSnapshotWinTrace() {
- RunCommand(
- // Empty name because it's not intended to be classified as a bugreport section.
- // Actual tracing files can be found in "/data/misc/wmtrace/" in the bugreport.
- "", {"cmd", "window", "tracing", "save-for-bugreport"},
- CommandOptions::WithTimeout(10).Always().DropRoot().RedirectStderr().Build());
+ // Currently WindowManagerService and InputMethodManagerSerivice support WinScope protocol.
+ for (const auto& service : {"window", "input_method"}) {
+ RunCommand(
+ // Empty name because it's not intended to be classified as a bugreport section.
+ // Actual tracing files can be found in "/data/misc/wmtrace/" in the bugreport.
+ "", {"cmd", service, "tracing", "save-for-bugreport"},
+ CommandOptions::WithTimeout(10).Always().DropRoot().RedirectStderr().Build());
+ }
}
void Dumpstate::onUiIntensiveBugreportDumpsFinished(int32_t calling_uid) {
diff --git a/cmds/dumpstate/tests/dumpstate_test.cpp b/cmds/dumpstate/tests/dumpstate_test.cpp
index b2518ad..2c573e4 100644
--- a/cmds/dumpstate/tests/dumpstate_test.cpp
+++ b/cmds/dumpstate/tests/dumpstate_test.cpp
@@ -1762,6 +1762,27 @@
EXPECT_THAT(getTempFileCounts(kTestDataPath), Eq(0));
}
+TEST_F(DumpPoolTest, Shutdown_withoutCrash) {
+ bool run_1 = false;
+ auto dump_func_1 = [&]() {
+ run_1 = true;
+ };
+ auto dump_func = []() {
+ sleep(1);
+ };
+
+ dump_pool_->start(/* thread_counts = */1);
+ dump_pool_->enqueueTask(/* task_name = */"1", dump_func_1);
+ dump_pool_->enqueueTask(/* task_name = */"2", dump_func);
+ dump_pool_->enqueueTask(/* task_name = */"3", dump_func);
+ dump_pool_->enqueueTask(/* task_name = */"4", dump_func);
+ dump_pool_->waitForTask("1", "", out_fd_.get());
+ dump_pool_->shutdown();
+
+ EXPECT_TRUE(run_1);
+ EXPECT_THAT(getTempFileCounts(kTestDataPath), Eq(0));
+}
+
class TaskQueueTest : public DumpstateBaseTest {
public:
void SetUp() {
diff --git a/headers/media_plugin/media/openmax/OMX_Core.h b/headers/media_plugin/media/openmax/OMX_Core.h
index 9ff934e..4b69130 100644
--- a/headers/media_plugin/media/openmax/OMX_Core.h
+++ b/headers/media_plugin/media/openmax/OMX_Core.h
@@ -556,6 +556,12 @@
*/
OMX_EventConfigUpdate,
+ /**
+ * Event fired by a tunneled decoder when the first frame is decoded and
+ * ready to be rendered.
+ */
+ OMX_EventOnFirstTunnelFrameReady,
+
OMX_EventMax = 0x7FFFFFFF
} OMX_EVENTTYPE;
diff --git a/headers/media_plugin/media/openmax/OMX_IndexExt.h b/headers/media_plugin/media/openmax/OMX_IndexExt.h
index a427db7..07bd749 100644
--- a/headers/media_plugin/media/openmax/OMX_IndexExt.h
+++ b/headers/media_plugin/media/openmax/OMX_IndexExt.h
@@ -103,6 +103,7 @@
OMX_IndexParamConsumerUsageBits, /**< reference: OMX_PARAM_U32TYPE */
OMX_IndexConfigLatency, /**< reference: OMX_PARAM_U32TYPE */
OMX_IndexConfigLowLatency, /**< reference: OMX_CONFIG_BOOLEANTYPE */
+ OMX_IndexConfigAndroidTunnelPeek, /**< reference: OMX_CONFIG_BOOLEANTYPE */
OMX_IndexExtOtherEndUnused,
/* Time configurations */
diff --git a/include/android/multinetwork.h b/include/android/multinetwork.h
index 424299d..fa77593 100644
--- a/include/android/multinetwork.h
+++ b/include/android/multinetwork.h
@@ -83,7 +83,7 @@
*
* To clear a previous process binding, invoke with NETWORK_UNSPECIFIED.
*
- * This is the equivalent of: [android.net.ConnectivityManager#setProcessDefaultNetwork()](https://developer.android.com/reference/android/net/ConnectivityManager.html#setProcessDefaultNetwork(android.net.Network))
+ * This is the equivalent of: [android.net.ConnectivityManager#bindProcessToNetwork()](https://developer.android.com/reference/android/net/ConnectivityManager.html#bindProcessToNetwork(android.net.Network))
*
* Available since API level 23.
*/
@@ -91,6 +91,19 @@
/**
+ * Gets the |network| bound to the current process, as per android_setprocnetwork.
+ *
+ * This is the equivalent of: [android.net.ConnectivityManager#getBoundNetworkForProcess()](https://developer.android.com/reference/android/net/ConnectivityManager.html#getBoundNetworkForProcess(android.net.Network))
+ * Returns 0 on success, or -1 setting errno to EINVAL if a null pointer is
+ * passed in.
+ *
+ *
+ * Available since API level 31.
+ */
+int android_getprocnetwork(net_handle_t *network) __INTRODUCED_IN(31);
+
+
+/**
* Perform hostname resolution via the DNS servers associated with |network|.
*
* All arguments (apart from |network|) are used identically as those passed
diff --git a/libs/binder/include/binder/AppOpsManager.h b/libs/binder/include/binder/AppOpsManager.h
index 0386d66..eac1bb2 100644
--- a/libs/binder/include/binder/AppOpsManager.h
+++ b/libs/binder/include/binder/AppOpsManager.h
@@ -142,7 +142,8 @@
OP_FINE_LOCATION_SOURCE = 108,
OP_COARSE_LOCATION_SOURCE = 109,
OP_MANAGE_MEDIA = 110,
- _NUM_OP = 111
+ OP_BLUETOOTH_CONNECT = 111,
+ _NUM_OP = 112
};
AppOpsManager();
diff --git a/libs/binder/rust/src/binder.rs b/libs/binder/rust/src/binder.rs
index d53a88f..3899d47 100644
--- a/libs/binder/rust/src/binder.rs
+++ b/libs/binder/rust/src/binder.rs
@@ -33,13 +33,13 @@
/// Binder action to perform.
///
-/// This must be a number between [`IBinder::FIRST_CALL_TRANSACTION`] and
-/// [`IBinder::LAST_CALL_TRANSACTION`].
+/// This must be a number between [`FIRST_CALL_TRANSACTION`] and
+/// [`LAST_CALL_TRANSACTION`].
pub type TransactionCode = u32;
/// Additional operation flags.
///
-/// `IBinder::FLAG_*` values.
+/// `FLAG_*` values.
pub type TransactionFlags = u32;
/// Super-trait for Binder interfaces.
@@ -85,20 +85,22 @@
fn get_class() -> InterfaceClass;
}
-/// Interface of binder local or remote objects.
+/// First transaction code available for user commands (inclusive)
+pub const FIRST_CALL_TRANSACTION: TransactionCode = sys::FIRST_CALL_TRANSACTION;
+/// Last transaction code available for user commands (inclusive)
+pub const LAST_CALL_TRANSACTION: TransactionCode = sys::LAST_CALL_TRANSACTION;
+
+/// Corresponds to TF_ONE_WAY -- an asynchronous call.
+pub const FLAG_ONEWAY: TransactionFlags = sys::FLAG_ONEWAY;
+/// Corresponds to TF_CLEAR_BUF -- clear transaction buffers after call is made.
+pub const FLAG_CLEAR_BUF: TransactionFlags = sys::FLAG_CLEAR_BUF;
+
+/// Internal interface of binder local or remote objects for making
+/// transactions.
///
-/// This trait corresponds to the interface of the C++ `IBinder` class.
-pub trait IBinder {
- /// First transaction code available for user commands (inclusive)
- const FIRST_CALL_TRANSACTION: TransactionCode = sys::FIRST_CALL_TRANSACTION;
- /// Last transaction code available for user commands (inclusive)
- const LAST_CALL_TRANSACTION: TransactionCode = sys::LAST_CALL_TRANSACTION;
-
- /// Corresponds to TF_ONE_WAY -- an asynchronous call.
- const FLAG_ONEWAY: TransactionFlags = sys::FLAG_ONEWAY;
- /// Corresponds to TF_CLEAR_BUF -- clear transaction buffers after call is made.
- const FLAG_CLEAR_BUF: TransactionFlags = sys::FLAG_CLEAR_BUF;
-
+/// This trait corresponds to the parts of the interface of the C++ `IBinder`
+/// class which are internal implementation details.
+pub trait IBinderInternal: IBinder {
/// Is this object still alive?
fn is_binder_alive(&self) -> bool;
@@ -122,19 +124,24 @@
/// * `data` - [`Parcel`] with input data
/// * `reply` - Optional [`Parcel`] for reply data
/// * `flags` - Transaction flags, e.g. marking the transaction as
- /// asynchronous ([`FLAG_ONEWAY`](IBinder::FLAG_ONEWAY))
+ /// asynchronous ([`FLAG_ONEWAY`](FLAG_ONEWAY))
fn transact<F: FnOnce(&mut Parcel) -> Result<()>>(
&self,
code: TransactionCode,
flags: TransactionFlags,
input_callback: F,
) -> Result<Parcel>;
+}
+/// Interface of binder local or remote objects.
+///
+/// This trait corresponds to the parts of the interface of the C++ `IBinder`
+/// class which are public.
+pub trait IBinder {
/// Register the recipient for a notification if this binder
/// goes away. If this binder object unexpectedly goes away
/// (typically because its hosting process has been killed),
- /// then DeathRecipient::binder_died() will be called with a reference
- /// to this.
+ /// then the `DeathRecipient`'s callback will be called.
///
/// You will only receive death notifications for remote binders,
/// as local binders by definition can't die without you dying as well.
@@ -142,11 +149,6 @@
/// INVALID_OPERATION code being returned and nothing happening.
///
/// This link always holds a weak reference to its recipient.
- ///
- /// You will only receive a weak reference to the dead
- /// binder. You should not try to promote this to a strong reference.
- /// (Nor should you need to, as there is nothing useful you can
- /// directly do with it now that it has passed on.)
fn link_to_death(&mut self, recipient: &mut DeathRecipient) -> Result<()>;
/// Remove a previously registered death notification.
@@ -222,7 +224,8 @@
// the number of u16 elements before the null terminator.
let raw_descriptor: *const c_char = sys::AIBinder_Class_getDescriptor(self.0);
- CStr::from_ptr(raw_descriptor).to_str()
+ CStr::from_ptr(raw_descriptor)
+ .to_str()
.expect("Expected valid UTF-8 string from AIBinder_Class_getDescriptor")
.into()
}
diff --git a/libs/binder/rust/src/lib.rs b/libs/binder/rust/src/lib.rs
index 43a237a..5bbd2a3 100644
--- a/libs/binder/rust/src/lib.rs
+++ b/libs/binder/rust/src/lib.rs
@@ -107,8 +107,9 @@
pub mod parcel;
pub use crate::binder::{
- FromIBinder, IBinder, Interface, InterfaceClass, Remotable, Strong, TransactionCode,
- TransactionFlags, Weak,
+ FromIBinder, IBinder, IBinderInternal, Interface, InterfaceClass, Remotable, Strong,
+ TransactionCode, TransactionFlags, Weak, FIRST_CALL_TRANSACTION, FLAG_CLEAR_BUF, FLAG_ONEWAY,
+ LAST_CALL_TRANSACTION,
};
pub use error::{status_t, ExceptionCode, Result, Status, StatusCode};
pub use native::add_service;
@@ -123,8 +124,8 @@
pub use super::parcel::ParcelFileDescriptor;
pub use super::{add_service, get_interface};
pub use super::{
- ExceptionCode, Interface, ProcessState, SpIBinder, Status, StatusCode, Strong, ThreadState,
- Weak, WpIBinder,
+ DeathRecipient, ExceptionCode, IBinder, Interface, ProcessState, SpIBinder, Status,
+ StatusCode, Strong, ThreadState, Weak, WpIBinder,
};
/// Binder result containing a [`Status`] on error.
diff --git a/libs/binder/rust/src/proxy.rs b/libs/binder/rust/src/proxy.rs
index 132e075..52036f5 100644
--- a/libs/binder/rust/src/proxy.rs
+++ b/libs/binder/rust/src/proxy.rs
@@ -17,7 +17,8 @@
//! Rust API for interacting with a remote binder service.
use crate::binder::{
- AsNative, FromIBinder, IBinder, Interface, InterfaceClass, Strong, TransactionCode, TransactionFlags,
+ AsNative, FromIBinder, IBinder, IBinderInternal, Interface, InterfaceClass, Strong,
+ TransactionCode, TransactionFlags,
};
use crate::error::{status_result, Result, StatusCode};
use crate::parcel::{
@@ -26,8 +27,8 @@
};
use crate::sys;
-use std::convert::TryInto;
use std::cmp::Ordering;
+use std::convert::TryInto;
use std::ffi::{c_void, CString};
use std::fmt;
use std::os::unix::io::AsRawFd;
@@ -211,7 +212,7 @@
}
}
-impl<T: AsNative<sys::AIBinder>> IBinder for T {
+impl<T: AsNative<sys::AIBinder>> IBinderInternal for T {
/// Perform a binder transaction
fn transact<F: FnOnce(&mut Parcel) -> Result<()>>(
&self,
@@ -300,9 +301,7 @@
}
fn set_requesting_sid(&mut self, enable: bool) {
- unsafe {
- sys::AIBinder_setRequestingSid(self.as_native_mut(), enable)
- };
+ unsafe { sys::AIBinder_setRequestingSid(self.as_native_mut(), enable) };
}
fn dump<F: AsRawFd>(&mut self, fp: &F, args: &[&str]) -> Result<()> {
@@ -351,7 +350,9 @@
status_result(status)?;
Ok(ibinder)
}
+}
+impl<T: AsNative<sys::AIBinder>> IBinder for T {
fn link_to_death(&mut self, recipient: &mut DeathRecipient) -> Result<()> {
status_result(unsafe {
// Safety: `SpIBinder` guarantees that `self` always contains a
@@ -472,7 +473,10 @@
// WpIBinder object from it.
sys::AIBinder_Weak_clone(self.0)
};
- assert!(!ptr.is_null(), "Unexpected null pointer from AIBinder_Weak_clone");
+ assert!(
+ !ptr.is_null(),
+ "Unexpected null pointer from AIBinder_Weak_clone"
+ );
Self(ptr)
}
}
diff --git a/libs/binder/rust/tests/integration.rs b/libs/binder/rust/tests/integration.rs
index 719229c..60e3502 100644
--- a/libs/binder/rust/tests/integration.rs
+++ b/libs/binder/rust/tests/integration.rs
@@ -18,7 +18,10 @@
use binder::declare_binder_interface;
use binder::parcel::Parcel;
-use binder::{Binder, IBinder, Interface, SpIBinder, StatusCode, ThreadState, TransactionCode};
+use binder::{
+ Binder, IBinderInternal, Interface, StatusCode, ThreadState, TransactionCode,
+ FIRST_CALL_TRANSACTION,
+};
use std::convert::{TryFrom, TryInto};
/// Name of service runner.
@@ -83,7 +86,7 @@
#[repr(u32)]
enum TestTransactionCode {
- Test = SpIBinder::FIRST_CALL_TRANSACTION,
+ Test = FIRST_CALL_TRANSACTION,
GetSelinuxContext,
}
@@ -196,7 +199,6 @@
impl ITestSameDescriptor for Binder<BnTestSameDescriptor> {}
-
#[cfg(test)]
mod tests {
use selinux_bindgen as selinux_sys;
@@ -209,9 +211,12 @@
use std::thread;
use std::time::Duration;
- use binder::{Binder, DeathRecipient, FromIBinder, IBinder, Interface, SpIBinder, StatusCode, Strong};
+ use binder::{
+ Binder, DeathRecipient, FromIBinder, IBinder, IBinderInternal, Interface, SpIBinder,
+ StatusCode, Strong,
+ };
- use super::{BnTest, ITest, ITestSameDescriptor, RUST_SERVICE_BINARY, TestService};
+ use super::{BnTest, ITest, ITestSameDescriptor, TestService, RUST_SERVICE_BINARY};
pub struct ScopedServiceProcess(Child);
@@ -290,7 +295,9 @@
};
assert_eq!(
test_client.get_selinux_context().unwrap(),
- expected_context.to_str().expect("context was invalid UTF-8"),
+ expected_context
+ .to_str()
+ .expect("context was invalid UTF-8"),
);
}
@@ -479,18 +486,22 @@
// This should succeed although we will have to treat the service as
// remote.
- let _interface: Strong<dyn ITestSameDescriptor> = FromIBinder::try_from(service.as_binder())
- .expect("Could not re-interpret service as the ITestSameDescriptor interface");
+ let _interface: Strong<dyn ITestSameDescriptor> =
+ FromIBinder::try_from(service.as_binder())
+ .expect("Could not re-interpret service as the ITestSameDescriptor interface");
}
/// Test that we can round-trip a rust service through a generic IBinder
#[test]
fn reassociate_rust_binder() {
let service_name = "testing_service";
- let service_ibinder = BnTest::new_binder(TestService { s: service_name.to_string() })
- .as_binder();
+ let service_ibinder = BnTest::new_binder(TestService {
+ s: service_name.to_string(),
+ })
+ .as_binder();
- let service: Strong<dyn ITest> = service_ibinder.into_interface()
+ let service: Strong<dyn ITest> = service_ibinder
+ .into_interface()
.expect("Could not reassociate the generic ibinder");
assert_eq!(service.test().unwrap(), service_name);
@@ -499,7 +510,9 @@
#[test]
fn weak_binder_upgrade() {
let service_name = "testing_service";
- let service = BnTest::new_binder(TestService { s: service_name.to_string() });
+ let service = BnTest::new_binder(TestService {
+ s: service_name.to_string(),
+ });
let weak = Strong::downgrade(&service);
@@ -512,7 +525,9 @@
fn weak_binder_upgrade_dead() {
let service_name = "testing_service";
let weak = {
- let service = BnTest::new_binder(TestService { s: service_name.to_string() });
+ let service = BnTest::new_binder(TestService {
+ s: service_name.to_string(),
+ });
Strong::downgrade(&service)
};
@@ -523,7 +538,9 @@
#[test]
fn weak_binder_clone() {
let service_name = "testing_service";
- let service = BnTest::new_binder(TestService { s: service_name.to_string() });
+ let service = BnTest::new_binder(TestService {
+ s: service_name.to_string(),
+ });
let weak = Strong::downgrade(&service);
let cloned = weak.clone();
@@ -539,8 +556,12 @@
#[test]
#[allow(clippy::eq_op)]
fn binder_ord() {
- let service1 = BnTest::new_binder(TestService { s: "testing_service1".to_string() });
- let service2 = BnTest::new_binder(TestService { s: "testing_service2".to_string() });
+ let service1 = BnTest::new_binder(TestService {
+ s: "testing_service1".to_string(),
+ });
+ let service2 = BnTest::new_binder(TestService {
+ s: "testing_service2".to_string(),
+ });
assert!(!(service1 < service1));
assert!(!(service1 > service1));
diff --git a/libs/gui/BLASTBufferQueue.cpp b/libs/gui/BLASTBufferQueue.cpp
index 5b1b975..8da97bb 100644
--- a/libs/gui/BLASTBufferQueue.cpp
+++ b/libs/gui/BLASTBufferQueue.cpp
@@ -130,8 +130,7 @@
}
BLASTBufferQueue::BLASTBufferQueue(const std::string& name, const sp<SurfaceControl>& surface,
- int width, int height, int32_t format,
- bool enableTripleBuffering)
+ int width, int height, int32_t format)
: mName(name),
mSurfaceControl(surface),
mSize(width, height),
@@ -143,9 +142,8 @@
// explicitly so that dequeueBuffer will block
mProducer->setDequeueTimeout(std::numeric_limits<int64_t>::max());
- if (enableTripleBuffering) {
- mProducer->setMaxDequeuedBufferCount(2);
- }
+ // safe default, most producers are expected to override this
+ mProducer->setMaxDequeuedBufferCount(2);
mBufferItemConsumer = new BLASTBufferItemConsumer(mConsumer,
GraphicBuffer::USAGE_HW_COMPOSER |
GraphicBuffer::USAGE_HW_TEXTURE,
diff --git a/libs/gui/FrameTimelineInfo.cpp b/libs/gui/FrameTimelineInfo.cpp
index f400774..9231a57 100644
--- a/libs/gui/FrameTimelineInfo.cpp
+++ b/libs/gui/FrameTimelineInfo.cpp
@@ -21,6 +21,7 @@
#include <android/os/IInputConstants.h>
#include <gui/FrameTimelineInfo.h>
#include <gui/LayerState.h>
+#include <private/gui/ParcelUtils.h>
#include <utils/Errors.h>
#include <cmath>
diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp
index bb8124b..ceab6ec 100644
--- a/libs/gui/ISurfaceComposer.cpp
+++ b/libs/gui/ISurfaceComposer.cpp
@@ -28,6 +28,7 @@
#include <gui/ISurfaceComposerClient.h>
#include <gui/LayerDebugInfo.h>
#include <gui/LayerState.h>
+#include <private/gui/ParcelUtils.h>
#include <stdint.h>
#include <sys/types.h>
#include <system/graphics.h>
diff --git a/libs/gui/ITransactionCompletedListener.cpp b/libs/gui/ITransactionCompletedListener.cpp
index 9b5be1f..b42793b 100644
--- a/libs/gui/ITransactionCompletedListener.cpp
+++ b/libs/gui/ITransactionCompletedListener.cpp
@@ -17,9 +17,10 @@
#define LOG_TAG "ITransactionCompletedListener"
//#define LOG_NDEBUG 0
-#include <gui/LayerState.h>
#include <gui/ISurfaceComposer.h>
#include <gui/ITransactionCompletedListener.h>
+#include <gui/LayerState.h>
+#include <private/gui/ParcelUtils.h>
namespace android {
diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp
index a84e741..d653ae7 100644
--- a/libs/gui/LayerState.cpp
+++ b/libs/gui/LayerState.cpp
@@ -23,6 +23,7 @@
#include <gui/IGraphicBufferProducer.h>
#include <gui/ISurfaceComposerClient.h>
#include <gui/LayerState.h>
+#include <private/gui/ParcelUtils.h>
#include <utils/Errors.h>
#include <cmath>
diff --git a/libs/gui/ScreenCaptureResults.cpp b/libs/gui/ScreenCaptureResults.cpp
index f3849bc..e91f74f 100644
--- a/libs/gui/ScreenCaptureResults.cpp
+++ b/libs/gui/ScreenCaptureResults.cpp
@@ -16,6 +16,8 @@
#include <gui/ScreenCaptureResults.h>
+#include <private/gui/ParcelUtils.h>
+
namespace android::gui {
status_t ScreenCaptureResults::writeToParcel(android::Parcel* parcel) const {
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index eaccc5b..d7b2c2e 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -39,6 +39,7 @@
#include <gui/LayerState.h>
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>
+#include <private/gui/ParcelUtils.h>
#include <ui/DisplayMode.h>
#include <ui/DynamicDisplayInfo.h>
@@ -291,8 +292,11 @@
// callback and a release buffer callback happening at the same time to avoid an
// additional ipc call from the server.
if (surfaceStats.previousBufferId) {
- ReleaseBufferCallback callback =
- popReleaseBufferCallbackLocked(surfaceStats.previousBufferId);
+ ReleaseBufferCallback callback;
+ {
+ std::scoped_lock<std::mutex> lock(mMutex);
+ callback = popReleaseBufferCallbackLocked(surfaceStats.previousBufferId);
+ }
if (callback) {
callback(surfaceStats.previousBufferId,
surfaceStats.previousReleaseFence
@@ -470,9 +474,8 @@
mForceSynchronous(other.mForceSynchronous),
mTransactionNestCount(other.mTransactionNestCount),
mAnimation(other.mAnimation),
- mEarlyWakeup(other.mEarlyWakeup),
- mExplicitEarlyWakeupStart(other.mExplicitEarlyWakeupStart),
- mExplicitEarlyWakeupEnd(other.mExplicitEarlyWakeupEnd),
+ mEarlyWakeupStart(other.mEarlyWakeupStart),
+ mEarlyWakeupEnd(other.mEarlyWakeupEnd),
mContainsBuffer(other.mContainsBuffer),
mDesiredPresentTime(other.mDesiredPresentTime),
mIsAutoTimestamp(other.mIsAutoTimestamp),
@@ -501,9 +504,8 @@
const uint32_t forceSynchronous = parcel->readUint32();
const uint32_t transactionNestCount = parcel->readUint32();
const bool animation = parcel->readBool();
- const bool earlyWakeup = parcel->readBool();
- const bool explicitEarlyWakeupStart = parcel->readBool();
- const bool explicitEarlyWakeupEnd = parcel->readBool();
+ const bool earlyWakeupStart = parcel->readBool();
+ const bool earlyWakeupEnd = parcel->readBool();
const bool containsBuffer = parcel->readBool();
const int64_t desiredPresentTime = parcel->readInt64();
const bool isAutoTimestamp = parcel->readBool();
@@ -578,9 +580,8 @@
mForceSynchronous = forceSynchronous;
mTransactionNestCount = transactionNestCount;
mAnimation = animation;
- mEarlyWakeup = earlyWakeup;
- mExplicitEarlyWakeupStart = explicitEarlyWakeupStart;
- mExplicitEarlyWakeupEnd = explicitEarlyWakeupEnd;
+ mEarlyWakeupStart = earlyWakeupStart;
+ mEarlyWakeupEnd = earlyWakeupEnd;
mContainsBuffer = containsBuffer;
mDesiredPresentTime = desiredPresentTime;
mIsAutoTimestamp = isAutoTimestamp;
@@ -610,9 +611,8 @@
parcel->writeUint32(mForceSynchronous);
parcel->writeUint32(mTransactionNestCount);
parcel->writeBool(mAnimation);
- parcel->writeBool(mEarlyWakeup);
- parcel->writeBool(mExplicitEarlyWakeupStart);
- parcel->writeBool(mExplicitEarlyWakeupEnd);
+ parcel->writeBool(mEarlyWakeupStart);
+ parcel->writeBool(mEarlyWakeupEnd);
parcel->writeBool(mContainsBuffer);
parcel->writeInt64(mDesiredPresentTime);
parcel->writeBool(mIsAutoTimestamp);
@@ -690,9 +690,8 @@
mInputWindowCommands.merge(other.mInputWindowCommands);
mContainsBuffer |= other.mContainsBuffer;
- mEarlyWakeup = mEarlyWakeup || other.mEarlyWakeup;
- mExplicitEarlyWakeupStart = mExplicitEarlyWakeupStart || other.mExplicitEarlyWakeupStart;
- mExplicitEarlyWakeupEnd = mExplicitEarlyWakeupEnd || other.mExplicitEarlyWakeupEnd;
+ mEarlyWakeupStart = mEarlyWakeupStart || other.mEarlyWakeupStart;
+ mEarlyWakeupEnd = mEarlyWakeupEnd || other.mEarlyWakeupEnd;
mApplyToken = other.mApplyToken;
mFrameTimelineInfo.merge(other.mFrameTimelineInfo);
@@ -710,9 +709,8 @@
mForceSynchronous = 0;
mTransactionNestCount = 0;
mAnimation = false;
- mEarlyWakeup = false;
- mExplicitEarlyWakeupStart = false;
- mExplicitEarlyWakeupEnd = false;
+ mEarlyWakeupStart = false;
+ mEarlyWakeupEnd = false;
mDesiredPresentTime = 0;
mIsAutoTimestamp = true;
mFrameTimelineInfo.clear();
@@ -831,17 +829,14 @@
if (mAnimation) {
flags |= ISurfaceComposer::eAnimation;
}
- if (mEarlyWakeup) {
- flags |= ISurfaceComposer::eEarlyWakeup;
- }
- // If both mExplicitEarlyWakeupStart and mExplicitEarlyWakeupEnd are set
+ // If both mEarlyWakeupStart and mEarlyWakeupEnd are set
// it is equivalent for none
- if (mExplicitEarlyWakeupStart && !mExplicitEarlyWakeupEnd) {
- flags |= ISurfaceComposer::eExplicitEarlyWakeupStart;
+ if (mEarlyWakeupStart && !mEarlyWakeupEnd) {
+ flags |= ISurfaceComposer::eEarlyWakeupStart;
}
- if (mExplicitEarlyWakeupEnd && !mExplicitEarlyWakeupStart) {
- flags |= ISurfaceComposer::eExplicitEarlyWakeupEnd;
+ if (mEarlyWakeupEnd && !mEarlyWakeupStart) {
+ flags |= ISurfaceComposer::eEarlyWakeupEnd;
}
sp<IBinder> applyToken = mApplyToken
@@ -892,16 +887,12 @@
mAnimation = true;
}
-void SurfaceComposerClient::Transaction::setEarlyWakeup() {
- mEarlyWakeup = true;
+void SurfaceComposerClient::Transaction::setEarlyWakeupStart() {
+ mEarlyWakeupStart = true;
}
-void SurfaceComposerClient::Transaction::setExplicitEarlyWakeupStart() {
- mExplicitEarlyWakeupStart = true;
-}
-
-void SurfaceComposerClient::Transaction::setExplicitEarlyWakeupEnd() {
- mExplicitEarlyWakeupEnd = true;
+void SurfaceComposerClient::Transaction::setEarlyWakeupEnd() {
+ mEarlyWakeupEnd = true;
}
layer_state_t* SurfaceComposerClient::Transaction::getLayerState(const sp<SurfaceControl>& sc) {
diff --git a/libs/gui/SurfaceControl.cpp b/libs/gui/SurfaceControl.cpp
index 1dcfe2e..7e2f8f9 100644
--- a/libs/gui/SurfaceControl.cpp
+++ b/libs/gui/SurfaceControl.cpp
@@ -39,6 +39,7 @@
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>
#include <gui/SurfaceControl.h>
+#include <private/gui/ParcelUtils.h>
namespace android {
diff --git a/libs/gui/include/gui/BLASTBufferQueue.h b/libs/gui/include/gui/BLASTBufferQueue.h
index 0173ffd..fbd16f4 100644
--- a/libs/gui/include/gui/BLASTBufferQueue.h
+++ b/libs/gui/include/gui/BLASTBufferQueue.h
@@ -74,7 +74,7 @@
{
public:
BLASTBufferQueue(const std::string& name, const sp<SurfaceControl>& surface, int width,
- int height, int32_t format, bool enableTripleBuffering = true);
+ int height, int32_t format);
sp<IGraphicBufferProducer> getIGraphicBufferProducer() const {
return mProducer;
diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h
index 2a9e3f7..35990d1 100644
--- a/libs/gui/include/gui/ISurfaceComposer.h
+++ b/libs/gui/include/gui/ISurfaceComposer.h
@@ -90,18 +90,15 @@
eSynchronous = 0x01,
eAnimation = 0x02,
- // DEPRECATED - use eExplicitEarlyWakeup[Start|End]
- eEarlyWakeup = 0x04,
-
// Explicit indication that this transaction and others to follow will likely result in a
// lot of layers being composed, and thus, SurfaceFlinger should wake-up earlier to avoid
// missing frame deadlines. In this case SurfaceFlinger will wake up at
// (sf vsync offset - debug.sf.early_phase_offset_ns). SurfaceFlinger will continue to be
- // in the early configuration until it receives eExplicitEarlyWakeupEnd. These flags are
+ // in the early configuration until it receives eEarlyWakeupEnd. These flags are
// expected to be used by WindowManager only and are guarded by
// android.permission.ACCESS_SURFACE_FLINGER
- eExplicitEarlyWakeupStart = 0x08,
- eExplicitEarlyWakeupEnd = 0x10,
+ eEarlyWakeupStart = 0x08,
+ eEarlyWakeupEnd = 0x10,
};
enum VsyncSource {
diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h
index 4a52168..9274777 100644
--- a/libs/gui/include/gui/LayerState.h
+++ b/libs/gui/include/gui/LayerState.h
@@ -16,23 +16,7 @@
#ifndef ANDROID_SF_LAYER_STATE_H
#define ANDROID_SF_LAYER_STATE_H
-#define SAFE_PARCEL(FUNC, ...) \
- { \
- status_t error = FUNC(__VA_ARGS__); \
- if (error) { \
- ALOGE("ERROR(%d). Failed to call parcel %s(%s)", error, #FUNC, #__VA_ARGS__); \
- return error; \
- } \
- }
-#define SAFE_PARCEL_READ_SIZE(FUNC, COUNT, SIZE) \
- { \
- SAFE_PARCEL(FUNC, COUNT); \
- if (static_cast<unsigned int>(*COUNT) > SIZE) { \
- ALOGE("ERROR(BAD_VALUE). %s was greater than dataSize", #COUNT); \
- return BAD_VALUE; \
- } \
- }
#include <stdint.h>
#include <sys/types.h>
diff --git a/libs/gui/include/gui/ScreenCaptureResults.h b/libs/gui/include/gui/ScreenCaptureResults.h
index 0ccc6e8..99c35c1 100644
--- a/libs/gui/include/gui/ScreenCaptureResults.h
+++ b/libs/gui/include/gui/ScreenCaptureResults.h
@@ -16,15 +16,6 @@
#pragma once
-#define SAFE_PARCEL(FUNC, ...) \
- { \
- status_t error = FUNC(__VA_ARGS__); \
- if (error) { \
- ALOGE("ERROR(%d). Failed to call parcel %s(%s)", error, #FUNC, #__VA_ARGS__); \
- return error; \
- } \
- }
-
#include <binder/Parcel.h>
#include <binder/Parcelable.h>
#include <ui/Fence.h>
diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h
index ae7170e..a643e9e 100644
--- a/libs/gui/include/gui/SurfaceComposerClient.h
+++ b/libs/gui/include/gui/SurfaceComposerClient.h
@@ -353,9 +353,8 @@
uint32_t mForceSynchronous = 0;
uint32_t mTransactionNestCount = 0;
bool mAnimation = false;
- bool mEarlyWakeup = false;
- bool mExplicitEarlyWakeupStart = false;
- bool mExplicitEarlyWakeupEnd = false;
+ bool mEarlyWakeupStart = false;
+ bool mEarlyWakeupEnd = false;
// Indicates that the Transaction contains a buffer that should be cached
bool mContainsBuffer = false;
@@ -564,9 +563,8 @@
const Rect& layerStackRect, const Rect& displayRect);
void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
void setAnimationTransaction();
- void setEarlyWakeup();
- void setExplicitEarlyWakeupStart();
- void setExplicitEarlyWakeupEnd();
+ void setEarlyWakeupStart();
+ void setEarlyWakeupEnd();
};
status_t clearLayerFrameStats(const sp<IBinder>& token) const;
diff --git a/libs/gui/include/private/gui/ParcelUtils.h b/libs/gui/include/private/gui/ParcelUtils.h
new file mode 100644
index 0000000..1cdd07e
--- /dev/null
+++ b/libs/gui/include/private/gui/ParcelUtils.h
@@ -0,0 +1,38 @@
+/*
+ * 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 <cstring>
+
+#define SAFE_PARCEL(FUNC, ...) \
+ { \
+ status_t error = FUNC(__VA_ARGS__); \
+ if (error) { \
+ ALOGE("ERROR(%s, %d). Failed to call parcel %s(%s)", strerror(-error), error, #FUNC, \
+ #__VA_ARGS__); \
+ return error; \
+ } \
+ }
+
+#define SAFE_PARCEL_READ_SIZE(FUNC, COUNT, SIZE) \
+ { \
+ SAFE_PARCEL(FUNC, COUNT); \
+ if (static_cast<unsigned int>(*COUNT) > SIZE) { \
+ ALOGE("ERROR(BAD_VALUE). %s was greater than dataSize", #COUNT); \
+ return BAD_VALUE; \
+ } \
+ }
\ No newline at end of file
diff --git a/libs/renderengine/skia/SkiaGLRenderEngine.cpp b/libs/renderengine/skia/SkiaGLRenderEngine.cpp
index f76bfa2..afdcd76 100644
--- a/libs/renderengine/skia/SkiaGLRenderEngine.cpp
+++ b/libs/renderengine/skia/SkiaGLRenderEngine.cpp
@@ -298,11 +298,9 @@
}
SkiaGLRenderEngine::~SkiaGLRenderEngine() {
- std::lock_guard<std::mutex> lock(mRenderingMutex);
- mRuntimeEffects.clear();
- mProtectedTextureCache.clear();
- mTextureCache.clear();
+ cleanFramebufferCache();
+ std::lock_guard<std::mutex> lock(mRenderingMutex);
if (mBlurFilter) {
delete mBlurFilter;
}
@@ -797,6 +795,8 @@
const auto rect = layer->geometry.roundedCornersRadius > 0
? getSkRect(layer->geometry.roundedCornersCrop)
: bounds;
+ // This would require a new parameter/flag to SkShadowUtils::DrawShadow
+ LOG_ALWAYS_FATAL_IF(layer->disableBlending, "Cannot disableBlending with a shadow");
drawShadow(canvas, rect, layer->geometry.roundedCornersRadius, layer->shadow);
continue;
}
@@ -806,7 +806,7 @@
needsToneMapping(layer->sourceDataspace, display.outputDataspace));
// quick abort from drawing the remaining portion of the layer
- if (layer->alpha == 0 && !requiresLinearEffect &&
+ if (layer->alpha == 0 && !requiresLinearEffect && !layer->disableBlending &&
(!displayColorTransform || displayColorTransform->isAlphaUnchanged())) {
continue;
}
@@ -912,6 +912,10 @@
requiresLinearEffect));
}
+ if (layer->disableBlending) {
+ paint.setBlendMode(SkBlendMode::kSrc);
+ }
+
paint.setColorFilter(displayColorTransform);
if (layer->geometry.roundedCornersRadius > 0) {
@@ -1137,7 +1141,14 @@
return eglCreatePbufferSurface(display, placeholderConfig, attributes.data());
}
-void SkiaGLRenderEngine::cleanFramebufferCache() {}
+void SkiaGLRenderEngine::cleanFramebufferCache() {
+ // TODO(b/180767535) Remove this method and use b/180767535 instead, which would allow
+ // SF to control texture lifecycle more tightly rather than through custom hooks into RE.
+ std::lock_guard<std::mutex> lock(mRenderingMutex);
+ mRuntimeEffects.clear();
+ mProtectedTextureCache.clear();
+ mTextureCache.clear();
+}
int SkiaGLRenderEngine::getContextPriority() {
int value;
diff --git a/libs/renderengine/tests/RenderEngineTest.cpp b/libs/renderengine/tests/RenderEngineTest.cpp
index 500a90b..7846156 100644
--- a/libs/renderengine/tests/RenderEngineTest.cpp
+++ b/libs/renderengine/tests/RenderEngineTest.cpp
@@ -1920,6 +1920,83 @@
0, 255, 0, 255);
}
+TEST_P(RenderEngineTest, testClear) {
+ initializeRenderEngine();
+
+ const auto rect = fullscreenRect();
+ const renderengine::DisplaySettings display{
+ .physicalDisplay = rect,
+ .clip = rect,
+ };
+
+ const renderengine::LayerSettings redLayer{
+ .geometry.boundaries = rect.toFloatRect(),
+ .source.solidColor = half3(1.0f, 0.0f, 0.0f),
+ .alpha = 1.0f,
+ };
+
+ // This mimics prepareClearClientComposition. This layer should overwrite
+ // the redLayer, so that the buffer is transparent, rather than red.
+ const renderengine::LayerSettings clearLayer{
+ .geometry.boundaries = rect.toFloatRect(),
+ .source.solidColor = half3(0.0f, 0.0f, 0.0f),
+ .alpha = 0.0f,
+ .disableBlending = true,
+ };
+
+ std::vector<const renderengine::LayerSettings*> layers{&redLayer, &clearLayer};
+ invokeDraw(display, layers);
+ expectBufferColor(rect, 0, 0, 0, 0);
+}
+
+TEST_P(RenderEngineTest, testDisableBlendingBuffer) {
+ initializeRenderEngine();
+
+ const auto rect = Rect(0, 0, 1, 1);
+ const renderengine::DisplaySettings display{
+ .physicalDisplay = rect,
+ .clip = rect,
+ };
+
+ const renderengine::LayerSettings redLayer{
+ .geometry.boundaries = rect.toFloatRect(),
+ .source.solidColor = half3(1.0f, 0.0f, 0.0f),
+ .alpha = 1.0f,
+ };
+
+ // The next layer will overwrite redLayer with a GraphicBuffer that is green
+ // applied with a translucent alpha.
+ auto buf = allocateSourceBuffer(1, 1);
+ {
+ uint8_t* pixels;
+ buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
+ reinterpret_cast<void**>(&pixels));
+ pixels[0] = 0;
+ pixels[1] = 255;
+ pixels[2] = 0;
+ pixels[3] = 255;
+ buf->unlock();
+ }
+
+ const renderengine::LayerSettings greenLayer{
+ .geometry.boundaries = rect.toFloatRect(),
+ .source =
+ renderengine::PixelSource{
+ .buffer =
+ renderengine::Buffer{
+ .buffer = buf,
+ .usePremultipliedAlpha = true,
+ },
+ },
+ .alpha = 0.5f,
+ .disableBlending = true,
+ };
+
+ std::vector<const renderengine::LayerSettings*> layers{&redLayer, &greenLayer};
+ invokeDraw(display, layers);
+ expectBufferColor(rect, 0, 128, 0, 128);
+}
+
} // namespace android
// TODO(b/129481165): remove the #pragma below and fix conversion issues
diff --git a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp
index b2ddb42..7bd0c6b 100644
--- a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp
+++ b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp
@@ -113,6 +113,8 @@
void setPointerCapture(bool enabled) override {}
+ void notifyDropWindow(const sp<IBinder>&, float x, float y) override {}
+
InputDispatcherConfiguration mConfig;
};
diff --git a/services/inputflinger/dispatcher/Entry.h b/services/inputflinger/dispatcher/Entry.h
index e5fb26c..f3ef64b 100644
--- a/services/inputflinger/dispatcher/Entry.h
+++ b/services/inputflinger/dispatcher/Entry.h
@@ -287,6 +287,8 @@
int32_t pid;
nsecs_t consumeTime; // time when the event was consumed by InputConsumer
int32_t displayId;
+ float x;
+ float y;
};
} // namespace android::inputdispatcher
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index fe46d17..397a9d7 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -2345,6 +2345,10 @@
}
} else if (maskedAction == AMOTION_EVENT_ACTION_UP ||
maskedAction == AMOTION_EVENT_ACTION_CANCEL) {
+ if (state.dragHoverWindowHandle && maskedAction == AMOTION_EVENT_ACTION_UP) {
+ vec2 local = state.dragHoverWindowHandle->getInfo()->transform.transform(x, y);
+ notifyDropWindowLocked(state.dragHoverWindowHandle->getToken(), local.x, local.y);
+ }
state.dragWindow = nullptr;
state.dragHoverWindowHandle = nullptr;
}
@@ -5302,6 +5306,15 @@
postCommandLocked(std::move(commandEntry));
}
+void InputDispatcher::notifyDropWindowLocked(const sp<IBinder>& token, float x, float y) {
+ std::unique_ptr<CommandEntry> commandEntry =
+ std::make_unique<CommandEntry>(&InputDispatcher::doNotifyDropWindowLockedInterruptible);
+ commandEntry->newToken = token;
+ commandEntry->x = x;
+ commandEntry->y = y;
+ postCommandLocked(std::move(commandEntry));
+}
+
void InputDispatcher::onAnrLocked(const sp<Connection>& connection) {
if (connection == nullptr) {
LOG_ALWAYS_FATAL("Caller must check for nullness");
@@ -5411,6 +5424,13 @@
mLock.lock();
}
+void InputDispatcher::doNotifyDropWindowLockedInterruptible(CommandEntry* commandEntry) {
+ sp<IBinder> newToken = commandEntry->newToken;
+ mLock.unlock();
+ mPolicy->notifyDropWindow(newToken, commandEntry->x, commandEntry->y);
+ mLock.lock();
+}
+
void InputDispatcher::doNotifyNoFocusedWindowAnrLockedInterruptible(CommandEntry* commandEntry) {
mLock.unlock();
diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h
index b2f3625..593ec23 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.h
+++ b/services/inputflinger/dispatcher/InputDispatcher.h
@@ -592,6 +592,7 @@
void onFocusChangedLocked(const FocusResolver::FocusChanges& changes) REQUIRES(mLock);
void notifyFocusChangedLocked(const sp<IBinder>& oldFocus, const sp<IBinder>& newFocus)
REQUIRES(mLock);
+ void notifyDropWindowLocked(const sp<IBinder>& token, float x, float y) REQUIRES(mLock);
void onAnrLocked(const sp<Connection>& connection) REQUIRES(mLock);
void onAnrLocked(std::shared_ptr<InputApplicationHandle> application) REQUIRES(mLock);
void onUntrustedTouchLocked(const std::string& obscuringPackage) REQUIRES(mLock);
@@ -607,6 +608,8 @@
REQUIRES(mLock);
void doNotifyInputChannelBrokenLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
void doNotifyFocusChangedLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
+ void doNotifyDropWindowLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
+
// ANR-related callbacks - start
void doNotifyNoFocusedWindowAnrLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
void doNotifyWindowUnresponsiveLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock);
diff --git a/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h b/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h
index 439d85e..219f45a 100644
--- a/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h
+++ b/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h
@@ -157,6 +157,9 @@
* InputDispatcher is solely responsible for updating the Pointer Capture state.
*/
virtual void setPointerCapture(bool enabled) = 0;
+
+ /* Notifies the policy that the drag window has moved over to another window */
+ virtual void notifyDropWindow(const sp<IBinder>& token, float x, float y) = 0;
};
} // namespace android
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp
index 32f9b69..cedda6e 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -266,6 +266,11 @@
mPointerCaptureEnabled.reset();
}
+ void assertDropTargetEquals(const sp<IBinder>& targetToken) {
+ std::scoped_lock lock(mLock);
+ ASSERT_EQ(targetToken, mDropTargetWindowToken);
+ }
+
private:
std::mutex mLock;
std::unique_ptr<InputEvent> mFilteredEvent GUARDED_BY(mLock);
@@ -284,6 +289,8 @@
std::queue<int32_t> mResponsiveMonitorPids GUARDED_BY(mLock);
std::condition_variable mNotifyAnr;
+ sp<IBinder> mDropTargetWindowToken GUARDED_BY(mLock);
+
void notifyConfigurationChanged(nsecs_t when) override {
std::scoped_lock lock(mLock);
mConfigurationChangedTime = when;
@@ -392,6 +399,11 @@
mPointerCaptureChangedCondition.notify_all();
}
+ void notifyDropWindow(const sp<IBinder>& token, float x, float y) override {
+ std::scoped_lock lock(mLock);
+ mDropTargetWindowToken = token;
+ }
+
void assertFilterInputEventWasCalled(int type, nsecs_t eventTime, int32_t action,
int32_t displayId) {
std::scoped_lock lock(mLock);
@@ -4789,4 +4801,36 @@
mSecondWindow->assertNoEvents();
}
+TEST_F(InputDispatcherDragTests, DragAndDrop) {
+ performDrag();
+
+ // Move on window.
+ ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ injectMotionEvent(mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, {50, 50}))
+ << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT);
+ mWindow->consumeDragEvent(false, 50, 50);
+ mSecondWindow->assertNoEvents();
+
+ // Move to another window.
+ ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ injectMotionEvent(mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, {150, 50}))
+ << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT);
+ mWindow->consumeDragEvent(true, 150, 50);
+ mSecondWindow->consumeDragEvent(false, 50, 50);
+
+ // drop to another window.
+ ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
+ injectMotionUp(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {150, 50}))
+ << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
+ mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT);
+ mFakePolicy->assertDropTargetEquals(mSecondWindow->getToken());
+ mWindow->assertNoEvents();
+ mSecondWindow->assertNoEvents();
+}
+
} // namespace android::inputdispatcher
diff --git a/services/sensorservice/SensorEventConnection.cpp b/services/sensorservice/SensorEventConnection.cpp
index 5225dd7..9ce8d9b 100644
--- a/services/sensorservice/SensorEventConnection.cpp
+++ b/services/sensorservice/SensorEventConnection.cpp
@@ -287,29 +287,6 @@
}
}
-// TODO(b/179649922): A better algorithm to guarantee that capped connections will get a sampling
-// rate close to 200 Hz. With the current algorithm, apps might be punished unfairly: E.g.,two apps
-// make requests to the sensor service at the same time, one is not capped and uses 250 Hz, and one
-//is capped, the capped connection will only get 125 Hz.
-void SensorService::SensorEventConnection::addSensorEventsToBuffer(bool shouldResample,
- const sensors_event_t& sensorEvent, sensors_event_t* buffer, int* index) {
- if (!shouldResample || !mService->isSensorInCappedSet(sensorEvent.type)) {
- buffer[(*index)++] = sensorEvent;
- } else {
- int64_t lastTimestamp = -1;
- auto entry = mSensorLastTimestamp.find(sensorEvent.sensor);
- if (entry != mSensorLastTimestamp.end()) {
- lastTimestamp = entry->second;
- }
- // Allow 10% headroom here because the clocks are not perfect.
- if (lastTimestamp == -1 || sensorEvent.timestamp - lastTimestamp
- >= 0.9 * SENSOR_SERVICE_CAPPED_SAMPLING_PERIOD_NS) {
- mSensorLastTimestamp[sensorEvent.sensor] = sensorEvent.timestamp;
- buffer[(*index)++] = sensorEvent;
- }
- }
-}
-
status_t SensorService::SensorEventConnection::sendEvents(
sensors_event_t const* buffer, size_t numEvents,
sensors_event_t* scratch,
@@ -318,8 +295,6 @@
std::unique_ptr<sensors_event_t[]> sanitizedBuffer;
- bool shouldResample = mService->isMicSensorPrivacyEnabledForUid(mUid) ||
- mIsRateCappedBasedOnPermission;
int count = 0;
Mutex::Autolock _l(mConnectionLock);
if (scratch) {
@@ -373,7 +348,7 @@
// Regular sensor event, just copy it to the scratch buffer after checking
// the AppOp.
if (hasSensorAccess() && noteOpIfRequired(buffer[i])) {
- addSensorEventsToBuffer(shouldResample, buffer[i], scratch, &count);
+ scratch[count++] = buffer[i];
}
}
i++;
@@ -383,13 +358,12 @@
buffer[i].meta_data.sensor == sensor_handle)));
}
} else {
- sanitizedBuffer.reset(new sensors_event_t[numEvents]);
- scratch = sanitizedBuffer.get();
if (hasSensorAccess()) {
- for (size_t i = 0; i < numEvents; i++) {
- addSensorEventsToBuffer(shouldResample, buffer[i], scratch, &count);
- }
+ scratch = const_cast<sensors_event_t *>(buffer);
+ count = numEvents;
} else {
+ sanitizedBuffer.reset(new sensors_event_t[numEvents]);
+ scratch = sanitizedBuffer.get();
for (size_t i = 0; i < numEvents; i++) {
if (buffer[i].type == SENSOR_TYPE_META_DATA) {
scratch[count++] = buffer[i++];
diff --git a/services/sensorservice/SensorEventConnection.h b/services/sensorservice/SensorEventConnection.h
index 4e3f120..909053b 100644
--- a/services/sensorservice/SensorEventConnection.h
+++ b/services/sensorservice/SensorEventConnection.h
@@ -145,16 +145,10 @@
void capRates();
// Recover sensor connection previously capped by capRates().
void uncapRates();
-
- // Add sensorEvent to buffer at position index if the sensorEvent satisfies throttling rules.
- void addSensorEventsToBuffer(bool shouldResample, const sensors_event_t& sensorEvent,
- sensors_event_t* buffer, int* index);
sp<SensorService> const mService;
sp<BitTube> mChannel;
uid_t mUid;
std::atomic_bool mIsRateCappedBasedOnPermission;
- // Store a mapping of sensor to the timestamp of their last sensor event.
- std::unordered_map<int, int64_t> mSensorLastTimestamp;
mutable Mutex mConnectionLock;
// Number of events from wake up sensors which are still pending and haven't been delivered to
// the corresponding application. It is incremented by one unit for each write to the socket.
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp
index 942b7ae..9955cdb 100644
--- a/services/sensorservice/SensorService.cpp
+++ b/services/sensorservice/SensorService.cpp
@@ -2129,12 +2129,14 @@
}
void SensorService::SensorPrivacyPolicy::registerSelf() {
+ AutoCallerClear acc;
SensorPrivacyManager spm;
mSensorPrivacyEnabled = spm.isSensorPrivacyEnabled();
spm.addSensorPrivacyListener(this);
}
void SensorService::SensorPrivacyPolicy::unregisterSelf() {
+ AutoCallerClear acc;
SensorPrivacyManager spm;
spm.removeSensorPrivacyListener(this);
}
@@ -2167,7 +2169,7 @@
status_t SensorService::SensorPrivacyPolicy::registerSelfForIndividual(int userId) {
Mutex::Autolock _l(mSensorPrivacyLock);
-
+ AutoCallerClear acc;
SensorPrivacyManager spm;
status_t err = spm.addIndividualSensorPrivacyListener(userId,
SensorPrivacyManager::INDIVIDUAL_SENSOR_MICROPHONE, this);
diff --git a/services/sensorservice/SensorService.h b/services/sensorservice/SensorService.h
index 9c5060a..a563a60 100644
--- a/services/sensorservice/SensorService.h
+++ b/services/sensorservice/SensorService.h
@@ -242,6 +242,22 @@
userid_t mUserId;
};
+ // A class automatically clearing and restoring binder caller identity inside
+ // a code block (scoped variable).
+ // Declare one systematically before calling SensorPrivacyManager methods so that they are
+ // executed with the same level of privilege as the SensorService process.
+ class AutoCallerClear {
+ public:
+ AutoCallerClear() :
+ mToken(IPCThreadState::self()->clearCallingIdentity()) {}
+ ~AutoCallerClear() {
+ IPCThreadState::self()->restoreCallingIdentity(mToken);
+ }
+
+ private:
+ const int64_t mToken;
+ };
+
enum Mode {
// The regular operating mode where any application can register/unregister/call flush on
// sensors.
diff --git a/services/surfaceflinger/BufferQueueLayer.cpp b/services/surfaceflinger/BufferQueueLayer.cpp
index 51e85c4..e7f373f 100644
--- a/services/surfaceflinger/BufferQueueLayer.cpp
+++ b/services/surfaceflinger/BufferQueueLayer.cpp
@@ -506,10 +506,7 @@
mConsumer->setContentsChangedListener(mContentsChangedListener);
mConsumer->setName(String8(mName.data(), mName.size()));
- // BufferQueueCore::mMaxDequeuedBufferCount is default to 1
- if (!mFlinger->isLayerTripleBufferingDisabled()) {
- mProducer->setMaxDequeuedBufferCount(2);
- }
+ mProducer->setMaxDequeuedBufferCount(2);
}
status_t BufferQueueLayer::setDefaultBufferProperties(uint32_t w, uint32_t h, PixelFormat format) {
diff --git a/services/surfaceflinger/BufferStateLayer.cpp b/services/surfaceflinger/BufferStateLayer.cpp
index 00a6d66..4cd9400 100644
--- a/services/surfaceflinger/BufferStateLayer.cpp
+++ b/services/surfaceflinger/BufferStateLayer.cpp
@@ -404,7 +404,16 @@
mCurrentState.desiredPresentTime = desiredPresentTime;
mCurrentState.isAutoTimestamp = isAutoTimestamp;
- mFlinger->mScheduler->recordLayerHistory(this, isAutoTimestamp ? 0 : desiredPresentTime,
+ const nsecs_t presentTime = [&] {
+ if (!isAutoTimestamp) return desiredPresentTime;
+
+ const auto prediction =
+ mFlinger->mFrameTimeline->getTokenManager()->getPredictionsForToken(info.vsyncId);
+ if (prediction.has_value()) return prediction->presentTime;
+
+ return static_cast<nsecs_t>(0);
+ }();
+ mFlinger->mScheduler->recordLayerHistory(this, presentTime,
LayerHistory::LayerUpdateType::Buffer);
addFrameEvent(acquireFence, postTime, isAutoTimestamp ? 0 : desiredPresentTime);
diff --git a/services/surfaceflinger/Scheduler/VsyncModulator.cpp b/services/surfaceflinger/Scheduler/VsyncModulator.cpp
index 1f821be..194d808 100644
--- a/services/surfaceflinger/Scheduler/VsyncModulator.cpp
+++ b/services/surfaceflinger/Scheduler/VsyncModulator.cpp
@@ -50,24 +50,23 @@
TransactionSchedule schedule) {
switch (schedule) {
case Schedule::EarlyStart:
- ALOGW_IF(mExplicitEarlyWakeup, "%s: Duplicate EarlyStart", __FUNCTION__);
- mExplicitEarlyWakeup = true;
+ ALOGW_IF(mEarlyWakeup, "%s: Duplicate EarlyStart", __FUNCTION__);
+ mEarlyWakeup = true;
break;
case Schedule::EarlyEnd:
- ALOGW_IF(!mExplicitEarlyWakeup, "%s: Unexpected EarlyEnd", __FUNCTION__);
- mExplicitEarlyWakeup = false;
+ ALOGW_IF(!mEarlyWakeup, "%s: Unexpected EarlyEnd", __FUNCTION__);
+ mEarlyWakeup = false;
break;
- case Schedule::Early:
case Schedule::Late:
- // No change to mExplicitEarlyWakeup for non-explicit states.
+ // No change to mEarlyWakeup for non-explicit states.
break;
}
if (mTraceDetailedInfo) {
- ATRACE_INT("mExplicitEarlyWakeup", mExplicitEarlyWakeup);
+ ATRACE_INT("mEarlyWakeup", mEarlyWakeup);
}
- if (!mExplicitEarlyWakeup && (schedule == Schedule::Early || schedule == Schedule::EarlyEnd)) {
+ if (!mEarlyWakeup && schedule == Schedule::EarlyEnd) {
mEarlyTransactionFrames = MIN_EARLY_TRANSACTION_FRAMES;
mEarlyTransactionStartTime = mNow();
}
@@ -129,8 +128,8 @@
const VsyncModulator::VsyncConfig& VsyncModulator::getNextVsyncConfig() const {
// Early offsets are used if we're in the middle of a refresh rate
// change, or if we recently begin a transaction.
- if (mExplicitEarlyWakeup || mTransactionSchedule == Schedule::EarlyEnd ||
- mEarlyTransactionFrames > 0 || mRefreshRateChangePending) {
+ if (mEarlyWakeup || mTransactionSchedule == Schedule::EarlyEnd || mEarlyTransactionFrames > 0 ||
+ mRefreshRateChangePending) {
return mVsyncConfigSet.early;
} else if (mEarlyGpuFrames > 0) {
return mVsyncConfigSet.earlyGpu;
diff --git a/services/surfaceflinger/Scheduler/VsyncModulator.h b/services/surfaceflinger/Scheduler/VsyncModulator.h
index 355a14a..fcde279 100644
--- a/services/surfaceflinger/Scheduler/VsyncModulator.h
+++ b/services/surfaceflinger/Scheduler/VsyncModulator.h
@@ -30,7 +30,6 @@
// fixed number of frames, respectively.
enum class TransactionSchedule {
Late, // Default.
- Early, // Deprecated.
EarlyStart,
EarlyEnd
};
@@ -114,7 +113,7 @@
using Schedule = TransactionSchedule;
std::atomic<Schedule> mTransactionSchedule = Schedule::Late;
- std::atomic<bool> mExplicitEarlyWakeup = false;
+ std::atomic<bool> mEarlyWakeup = false;
std::atomic<bool> mRefreshRateChangePending = false;
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index e580a97..31097aa 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -23,6 +23,7 @@
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
#include "SurfaceFlinger.h"
+#include "TraceUtils.h"
#include <android-base/properties.h>
#include <android/configuration.h>
@@ -79,7 +80,6 @@
#include <utils/String16.h>
#include <utils/String8.h>
#include <utils/Timers.h>
-#include <utils/Trace.h>
#include <utils/misc.h>
#include <algorithm>
@@ -441,10 +441,6 @@
mUseHwcVirtualDisplays = atoi(value);
ALOGI_IF(mUseHwcVirtualDisplays, "Enabling HWC virtual displays");
- property_get("ro.sf.disable_triple_buffer", value, "0");
- mLayerTripleBufferingDisabled = atoi(value);
- ALOGI_IF(mLayerTripleBufferingDisabled, "Disabling Triple Buffering");
-
property_get("ro.surface_flinger.supports_background_blur", value, "0");
bool supportsBlurs = atoi(value);
mSupportsBlur = supportsBlurs;
@@ -1689,7 +1685,12 @@
}
void SurfaceFlinger::onMessageReceived(int32_t what, int64_t vsyncId, nsecs_t expectedVSyncTime) {
- ATRACE_CALL();
+ const auto vsyncIn = [&] {
+ if (!ATRACE_ENABLED()) return 0.f;
+ return (expectedVSyncTime - systemTime()) / 1e6f;
+ }();
+
+ ATRACE_FORMAT("onMessageReceived %" PRId64 " vsyncIn %.2fms", vsyncId, vsyncIn);
switch (what) {
case MessageQueue::INVALIDATE: {
onMessageInvalidate(vsyncId, expectedVSyncTime);
@@ -2975,7 +2976,7 @@
mRefreshRateConfigs = std::make_unique<
scheduler::RefreshRateConfigs>(displayState.physical->supportedModes,
displayState.physical->activeMode->getId(),
- android::sysprop::enable_frame_rate_override(true));
+ android::sysprop::enable_frame_rate_override(false));
const auto currRefreshRate = displayState.physical->activeMode->getFps();
mRefreshRateStats = std::make_unique<scheduler::RefreshRateStats>(*mTimeStats, currRefreshRate,
hal::PowerMode::OFF);
@@ -3493,9 +3494,8 @@
ATRACE_INT("TransactionQueue", mTransactionQueue.size());
const auto schedule = [](uint32_t flags) {
- if (flags & eEarlyWakeup) return TransactionSchedule::Early;
- if (flags & eExplicitEarlyWakeupEnd) return TransactionSchedule::EarlyEnd;
- if (flags & eExplicitEarlyWakeupStart) return TransactionSchedule::EarlyStart;
+ if (flags & eEarlyWakeupEnd) return TransactionSchedule::EarlyEnd;
+ if (flags & eEarlyWakeupStart) return TransactionSchedule::EarlyStart;
return TransactionSchedule::Late;
}(state.flags);
@@ -3547,15 +3547,10 @@
permissions |= Permission::ROTATE_SURFACE_FLINGER;
}
- // TODO(b/159125966): Remove eEarlyWakeup completely as no client should use this flag
- if (flags & eEarlyWakeup) {
- ALOGW("eEarlyWakeup is deprecated. Use eExplicitEarlyWakeup[Start|End]");
- }
-
if (!(permissions & Permission::ACCESS_SURFACE_FLINGER) &&
- (flags & (eExplicitEarlyWakeupStart | eExplicitEarlyWakeupEnd))) {
- ALOGE("Only WindowManager is allowed to use eExplicitEarlyWakeup[Start|End] flags");
- flags &= ~(eExplicitEarlyWakeupStart | eExplicitEarlyWakeupEnd);
+ (flags & (eEarlyWakeupStart | eEarlyWakeupEnd))) {
+ ALOGE("Only WindowManager is allowed to use eEarlyWakeup[Start|End] flags");
+ flags &= ~(eEarlyWakeupStart | eEarlyWakeupEnd);
}
const int64_t postTime = systemTime();
@@ -4568,9 +4563,6 @@
void SurfaceFlinger::appendSfConfigString(std::string& result) const {
result.append(" [sf");
- if (isLayerTripleBufferingDisabled())
- result.append(" DISABLE_TRIPLE_BUFFERING");
-
StringAppendF(&result, " PRESENT_TIME_OFFSET=%" PRId64, dispSyncPresentTimeOffset);
StringAppendF(&result, " FORCE_HWC_FOR_RBG_TO_YUV=%d", useHwcForRgbToYuv);
StringAppendF(&result, " MAX_VIRT_DISPLAY_DIM=%" PRIu64, maxVirtualDisplaySize);
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index a7cdcd1..8d2f66d 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -1095,10 +1095,6 @@
void dumpOffscreenLayers(std::string& result) EXCLUDES(mStateLock);
void dumpPlannerInfo(const DumpArgs& args, std::string& result) const REQUIRES(mStateLock);
- bool isLayerTripleBufferingDisabled() const {
- return this->mLayerTripleBufferingDisabled;
- }
-
status_t doDump(int fd, const DumpArgs& args, bool asProto);
status_t dumpCritical(int fd, const DumpArgs&, bool asProto);
@@ -1252,9 +1248,6 @@
TransactionCallbackInvoker mTransactionCallbackInvoker;
- // Restrict layers to use two buffers in their bufferqueues.
- bool mLayerTripleBufferingDisabled = false;
-
// these are thread safe
std::unique_ptr<MessageQueue> mEventQueue;
FrameTracker mAnimFrameTracker;
diff --git a/services/surfaceflinger/TraceUtils.h b/services/surfaceflinger/TraceUtils.h
new file mode 100644
index 0000000..90a34a5
--- /dev/null
+++ b/services/surfaceflinger/TraceUtils.h
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+// TODO(b/183120308): This file is a copy of f/b/libs/hwui/utils/TraceUtils.h
+// It should be migrated to a common place where both SF and hwui could use it.
+
+#pragma once
+
+#include <cutils/trace.h>
+#include <utils/Trace.h>
+
+#define ATRACE_FORMAT(fmt, ...) \
+ TraceUtils::TraceEnder __traceEnder = \
+ (TraceUtils::atraceFormatBegin(fmt, ##__VA_ARGS__), TraceUtils::TraceEnder())
+
+#define ATRACE_FORMAT_BEGIN(fmt, ...) TraceUtils::atraceFormatBegin(fmt, ##__VA_ARGS__)
+
+namespace android {
+
+class TraceUtils {
+public:
+ class TraceEnder {
+ public:
+ ~TraceEnder() { ATRACE_END(); }
+ };
+
+ static void atraceFormatBegin(const char* fmt, ...) {
+ if (CC_LIKELY(!ATRACE_ENABLED())) return;
+
+ const int BUFFER_SIZE = 256;
+ va_list ap;
+ char buf[BUFFER_SIZE];
+
+ va_start(ap, fmt);
+ vsnprintf(buf, BUFFER_SIZE, fmt, ap);
+ va_end(ap);
+
+ ATRACE_BEGIN(buf);
+ }
+
+}; // class TraceUtils
+
+} /* namespace android */
diff --git a/services/surfaceflinger/tests/unittests/VsyncModulatorTest.cpp b/services/surfaceflinger/tests/unittests/VsyncModulatorTest.cpp
index 106da81..17648d5 100644
--- a/services/surfaceflinger/tests/unittests/VsyncModulatorTest.cpp
+++ b/services/surfaceflinger/tests/unittests/VsyncModulatorTest.cpp
@@ -101,24 +101,6 @@
CHECK_REFRESH(1, kLate, kLate);
}
-TEST_F(VsyncModulatorTest, EarlyStartWithEarly) {
- EXPECT_EQ(kEarly, mVsyncModulator.setTransactionSchedule(Schedule::EarlyStart));
-
- CHECK_COMMIT(kEarly, kEarly);
- CHECK_REFRESH(5 * MIN_EARLY_TRANSACTION_FRAMES, std::nullopt, kEarly);
-
- EXPECT_EQ(kEarly, mVsyncModulator.setTransactionSchedule(Schedule::Early));
-
- CHECK_COMMIT(kEarly, kEarly);
- CHECK_REFRESH(5 * MIN_EARLY_TRANSACTION_FRAMES, std::nullopt, kEarly);
-
- EXPECT_EQ(kEarly, mVsyncModulator.setTransactionSchedule(Schedule::EarlyEnd));
-
- CHECK_COMMIT(kEarly, kEarly);
- CHECK_REFRESH(MIN_EARLY_TRANSACTION_FRAMES - 1, kEarly, kEarly);
- CHECK_REFRESH(1, kLate, kLate);
-}
-
TEST_F(VsyncModulatorTest, EarlyStartWithMoreTransactions) {
EXPECT_EQ(kEarly, mVsyncModulator.setTransactionSchedule(Schedule::EarlyStart));
diff --git a/services/vibratorservice/VibratorHalController.cpp b/services/vibratorservice/VibratorHalController.cpp
index 2de2e0e..70f9876 100644
--- a/services/vibratorservice/VibratorHalController.cpp
+++ b/services/vibratorservice/VibratorHalController.cpp
@@ -161,7 +161,7 @@
return apply(offFn, "off");
}
-HalResult<void> HalController::setAmplitude(int32_t amplitude) {
+HalResult<void> HalController::setAmplitude(float amplitude) {
hal_fn<void> setAmplitudeFn = [&](std::shared_ptr<HalWrapper> hal) {
return hal->setAmplitude(amplitude);
};
diff --git a/services/vibratorservice/VibratorHalWrapper.cpp b/services/vibratorservice/VibratorHalWrapper.cpp
index 3d20fa1..baee74f 100644
--- a/services/vibratorservice/VibratorHalWrapper.cpp
+++ b/services/vibratorservice/VibratorHalWrapper.cpp
@@ -168,9 +168,8 @@
return HalResult<void>::fromStatus(getHal()->off());
}
-HalResult<void> AidlHalWrapper::setAmplitude(int32_t amplitude) {
- float convertedAmplitude = static_cast<float>(amplitude) / std::numeric_limits<uint8_t>::max();
- return HalResult<void>::fromStatus(getHal()->setAmplitude(convertedAmplitude));
+HalResult<void> AidlHalWrapper::setAmplitude(float amplitude) {
+ return HalResult<void>::fromStatus(getHal()->setAmplitude(amplitude));
}
HalResult<void> AidlHalWrapper::setExternalControl(bool enabled) {
@@ -346,8 +345,9 @@
}
template <typename I>
-HalResult<void> HidlHalWrapper<I>::setAmplitude(int32_t amplitude) {
- auto result = getHal()->setAmplitude(static_cast<uint8_t>(amplitude));
+HalResult<void> HidlHalWrapper<I>::setAmplitude(float amplitude) {
+ uint8_t amp = static_cast<uint8_t>(amplitude * std::numeric_limits<uint8_t>::max());
+ auto result = getHal()->setAmplitude(amp);
return HalResult<void>::fromStatus(result.withDefault(V1_0::Status::UNKNOWN_ERROR));
}
diff --git a/services/vibratorservice/benchmarks/VibratorHalControllerBenchmarks.cpp b/services/vibratorservice/benchmarks/VibratorHalControllerBenchmarks.cpp
index 0acff06..f40980c 100644
--- a/services/vibratorservice/benchmarks/VibratorHalControllerBenchmarks.cpp
+++ b/services/vibratorservice/benchmarks/VibratorHalControllerBenchmarks.cpp
@@ -142,7 +142,7 @@
auto duration = 60s;
auto callback = []() {};
- auto amplitude = UINT8_MAX;
+ auto amplitude = 1.0f;
for (auto _ : state) {
state.PauseTiming();
@@ -169,7 +169,7 @@
auto duration = 6000s;
auto callback = []() {};
- auto amplitude = UINT8_MAX;
+ auto amplitude = 1.0f;
checkHalResult(mController.on(duration, callback), state);
@@ -224,7 +224,7 @@
return;
}
- auto amplitude = UINT8_MAX;
+ auto amplitude = 1.0f;
checkHalResult(mController.setExternalControl(true), state);
diff --git a/services/vibratorservice/include/vibratorservice/VibratorHalController.h b/services/vibratorservice/include/vibratorservice/VibratorHalController.h
index 14ec7b2..f884ff0 100644
--- a/services/vibratorservice/include/vibratorservice/VibratorHalController.h
+++ b/services/vibratorservice/include/vibratorservice/VibratorHalController.h
@@ -61,7 +61,7 @@
const std::function<void()>& completionCallback) final override;
HalResult<void> off() final override;
- HalResult<void> setAmplitude(int32_t amplitude) final override;
+ HalResult<void> setAmplitude(float amplitude) final override;
HalResult<void> setExternalControl(bool enabled) final override;
HalResult<void> alwaysOnEnable(int32_t id, hardware::vibrator::Effect effect,
diff --git a/services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h b/services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h
index 039a2d9..667702d 100644
--- a/services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h
+++ b/services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h
@@ -173,7 +173,7 @@
const std::function<void()>& completionCallback) = 0;
virtual HalResult<void> off() = 0;
- virtual HalResult<void> setAmplitude(int32_t amplitude) = 0;
+ virtual HalResult<void> setAmplitude(float amplitude) = 0;
virtual HalResult<void> setExternalControl(bool enabled) = 0;
virtual HalResult<void> alwaysOnEnable(int32_t id, hardware::vibrator::Effect effect,
@@ -223,7 +223,7 @@
const std::function<void()>& completionCallback) override final;
HalResult<void> off() override final;
- HalResult<void> setAmplitude(int32_t amplitude) override final;
+ HalResult<void> setAmplitude(float amplitude) override final;
HalResult<void> setExternalControl(bool enabled) override final;
HalResult<void> alwaysOnEnable(int32_t id, hardware::vibrator::Effect effect,
@@ -295,7 +295,7 @@
const std::function<void()>& completionCallback) override final;
HalResult<void> off() override final;
- HalResult<void> setAmplitude(int32_t amplitude) override final;
+ HalResult<void> setAmplitude(float amplitude) override final;
virtual HalResult<void> setExternalControl(bool enabled) override;
HalResult<void> alwaysOnEnable(int32_t id, hardware::vibrator::Effect effect,
diff --git a/services/vibratorservice/test/VibratorHalControllerTest.cpp b/services/vibratorservice/test/VibratorHalControllerTest.cpp
index 0c39247..e438d78 100644
--- a/services/vibratorservice/test/VibratorHalControllerTest.cpp
+++ b/services/vibratorservice/test/VibratorHalControllerTest.cpp
@@ -58,7 +58,7 @@
(milliseconds timeout, const std::function<void()>& completionCallback),
(override));
MOCK_METHOD(vibrator::HalResult<void>, off, (), (override));
- MOCK_METHOD(vibrator::HalResult<void>, setAmplitude, (int32_t amplitude), (override));
+ MOCK_METHOD(vibrator::HalResult<void>, setAmplitude, (float amplitude), (override));
MOCK_METHOD(vibrator::HalResult<void>, setExternalControl, (bool enabled), (override));
MOCK_METHOD(vibrator::HalResult<void>, alwaysOnEnable,
(int32_t id, Effect effect, EffectStrength strength), (override));
@@ -122,7 +122,7 @@
EXPECT_CALL(*mMockHal.get(), off())
.Times(Exactly(cardinality))
.WillRepeatedly(Return(voidResult));
- EXPECT_CALL(*mMockHal.get(), setAmplitude(Eq(255)))
+ EXPECT_CALL(*mMockHal.get(), setAmplitude(Eq(1.0f)))
.Times(Exactly(cardinality))
.WillRepeatedly(Return(voidResult));
EXPECT_CALL(*mMockHal.get(), setExternalControl(Eq(true)))
@@ -196,7 +196,7 @@
ASSERT_TRUE(mController->ping().isOk());
ASSERT_TRUE(mController->on(10ms, []() {}).isOk());
ASSERT_TRUE(mController->off().isOk());
- ASSERT_TRUE(mController->setAmplitude(255).isOk());
+ ASSERT_TRUE(mController->setAmplitude(1.0f).isOk());
ASSERT_TRUE(mController->setExternalControl(true).isOk());
ASSERT_TRUE(mController->alwaysOnEnable(1, Effect::CLICK, EffectStrength::LIGHT).isOk());
ASSERT_TRUE(mController->alwaysOnDisable(1).isOk());
@@ -249,7 +249,7 @@
ASSERT_TRUE(mController->ping().isUnsupported());
ASSERT_TRUE(mController->on(10ms, []() {}).isUnsupported());
ASSERT_TRUE(mController->off().isUnsupported());
- ASSERT_TRUE(mController->setAmplitude(255).isUnsupported());
+ ASSERT_TRUE(mController->setAmplitude(1.0f).isUnsupported());
ASSERT_TRUE(mController->setExternalControl(true).isUnsupported());
ASSERT_TRUE(
mController->alwaysOnEnable(1, Effect::CLICK, EffectStrength::LIGHT).isUnsupported());
@@ -282,7 +282,7 @@
ASSERT_TRUE(mController->ping().isFailed());
ASSERT_TRUE(mController->on(10ms, []() {}).isFailed());
ASSERT_TRUE(mController->off().isFailed());
- ASSERT_TRUE(mController->setAmplitude(255).isFailed());
+ ASSERT_TRUE(mController->setAmplitude(1.0f).isFailed());
ASSERT_TRUE(mController->setExternalControl(true).isFailed());
ASSERT_TRUE(mController->alwaysOnEnable(1, Effect::CLICK, EffectStrength::LIGHT).isFailed());
ASSERT_TRUE(mController->alwaysOnDisable(1).isFailed());
@@ -345,7 +345,7 @@
ASSERT_TRUE(mController->ping().isUnsupported());
ASSERT_TRUE(mController->on(10ms, []() {}).isUnsupported());
ASSERT_TRUE(mController->off().isUnsupported());
- ASSERT_TRUE(mController->setAmplitude(255).isUnsupported());
+ ASSERT_TRUE(mController->setAmplitude(1.0f).isUnsupported());
ASSERT_TRUE(mController->setExternalControl(true).isUnsupported());
ASSERT_TRUE(
mController->alwaysOnEnable(1, Effect::CLICK, EffectStrength::LIGHT).isUnsupported());
diff --git a/services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp b/services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp
index 5d77595..99f592f 100644
--- a/services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp
+++ b/services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp
@@ -215,19 +215,19 @@
TEST_F(VibratorHalWrapperAidlTest, TestSetAmplitude) {
{
InSequence seq;
- EXPECT_CALL(*mMockHal.get(), setAmplitude(FloatNear(0.1, 1e-2))).Times(Exactly(1));
- EXPECT_CALL(*mMockHal.get(), setAmplitude(FloatNear(0.2, 1e-2)))
+ EXPECT_CALL(*mMockHal.get(), setAmplitude(Eq(0.1f))).Times(Exactly(1));
+ EXPECT_CALL(*mMockHal.get(), setAmplitude(Eq(0.2f)))
.Times(Exactly(1))
.WillRepeatedly(Return(
Status::fromExceptionCode(Status::Exception::EX_UNSUPPORTED_OPERATION)));
- EXPECT_CALL(*mMockHal.get(), setAmplitude(FloatNear(0.5, 1e-2)))
+ EXPECT_CALL(*mMockHal.get(), setAmplitude(Eq(0.5f)))
.Times(Exactly(1))
.WillRepeatedly(Return(Status::fromExceptionCode(Status::Exception::EX_SECURITY)));
}
- ASSERT_TRUE(mWrapper->setAmplitude(std::numeric_limits<uint8_t>::max() / 10).isOk());
- ASSERT_TRUE(mWrapper->setAmplitude(std::numeric_limits<uint8_t>::max() / 5).isUnsupported());
- ASSERT_TRUE(mWrapper->setAmplitude(std::numeric_limits<uint8_t>::max() / 2).isFailed());
+ ASSERT_TRUE(mWrapper->setAmplitude(0.1f).isOk());
+ ASSERT_TRUE(mWrapper->setAmplitude(0.2f).isUnsupported());
+ ASSERT_TRUE(mWrapper->setAmplitude(0.5f).isFailed());
}
TEST_F(VibratorHalWrapperAidlTest, TestSetExternalControl) {
diff --git a/services/vibratorservice/test/VibratorHalWrapperHidlV1_0Test.cpp b/services/vibratorservice/test/VibratorHalWrapperHidlV1_0Test.cpp
index 06aa36f..33c47cf 100644
--- a/services/vibratorservice/test/VibratorHalWrapperHidlV1_0Test.cpp
+++ b/services/vibratorservice/test/VibratorHalWrapperHidlV1_0Test.cpp
@@ -147,7 +147,7 @@
TEST_F(VibratorHalWrapperHidlV1_0Test, TestSetAmplitude) {
{
InSequence seq;
- EXPECT_CALL(*mMockHal.get(), setAmplitude(static_cast<uint8_t>(1)))
+ EXPECT_CALL(*mMockHal.get(), setAmplitude(Eq(static_cast<uint8_t>(1))))
.Times(Exactly(1))
.WillRepeatedly(
[](uint8_t) { return hardware::Return<V1_0::Status>(V1_0::Status::OK); });
@@ -168,10 +168,11 @@
});
}
- ASSERT_TRUE(mWrapper->setAmplitude(1).isOk());
- ASSERT_TRUE(mWrapper->setAmplitude(2).isUnsupported());
- ASSERT_TRUE(mWrapper->setAmplitude(3).isFailed());
- ASSERT_TRUE(mWrapper->setAmplitude(4).isFailed());
+ auto maxAmplitude = std::numeric_limits<uint8_t>::max();
+ ASSERT_TRUE(mWrapper->setAmplitude(1.0f / maxAmplitude).isOk());
+ ASSERT_TRUE(mWrapper->setAmplitude(2.0f / maxAmplitude).isUnsupported());
+ ASSERT_TRUE(mWrapper->setAmplitude(3.0f / maxAmplitude).isFailed());
+ ASSERT_TRUE(mWrapper->setAmplitude(4.0f / maxAmplitude).isFailed());
}
TEST_F(VibratorHalWrapperHidlV1_0Test, TestSetExternalControlUnsupported) {