Merge "Fix ndk native reference documentation link errors/warnings" into sc-dev
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 7ab2a8d..e2ffd02 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -2175,14 +2175,13 @@
}
/*
- * mount debugfs for non-user builds which launch with S and unmount it
- * after invoking dumpstateBoard_* methods. This is to enable debug builds
- * to not have debugfs mounted during runtime. It will also ensure that
- * debugfs is only accessed by the dumpstate HAL.
+ * mount debugfs for non-user builds with ro.product.enforce_debugfs_restrictions
+ * set to true and unmount it after invoking dumpstateBoard_* methods.
+ * This is to enable debug builds to not have debugfs mounted during runtime.
+ * It will also ensure that debugfs is only accessed by the dumpstate HAL.
*/
- auto api_level = android::base::GetIntProperty("ro.product.first_api_level", 0);
- bool mount_debugfs = !PropertiesHelper::IsUserBuild() && api_level >= 31;
-
+ auto mount_debugfs =
+ android::base::GetBoolProperty("ro.product.enforce_debugfs_restrictions", false);
if (mount_debugfs) {
RunCommand("mount debugfs", {"mount", "-t", "debugfs", "debugfs", "/sys/kernel/debug"},
AS_ROOT_20);
@@ -2290,7 +2289,10 @@
}
if (mount_debugfs) {
- RunCommand("unmount debugfs", {"umount", "/sys/kernel/debug"}, AS_ROOT_20);
+ auto keep_debugfs_mounted =
+ android::base::GetProperty("persist.dbg.keep_debugfs_mounted", "");
+ if (keep_debugfs_mounted.empty())
+ RunCommand("unmount debugfs", {"umount", "/sys/kernel/debug"}, AS_ROOT_20);
}
auto file_sizes = std::make_unique<ssize_t[]>(paths.size());
diff --git a/cmds/installd/otapreopt_chroot.cpp b/cmds/installd/otapreopt_chroot.cpp
index c04b558..3a87776 100644
--- a/cmds/installd/otapreopt_chroot.cpp
+++ b/cmds/installd/otapreopt_chroot.cpp
@@ -27,6 +27,7 @@
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/macros.h>
+#include <android-base/scopeguard.h>
#include <android-base/stringprintf.h>
#include <android-base/unique_fd.h>
#include <libdm/dm.h>
@@ -72,6 +73,15 @@
}
}
+static void DeactivateApexPackages() {
+ std::vector<std::string> apexd_cmd{"/system/bin/apexd", "--unmount-all"};
+ std::string apexd_error_msg;
+ bool exec_result = Exec(apexd_cmd, &apexd_error_msg);
+ if (!exec_result) {
+ PLOG(ERROR) << "Running /system/bin/apexd --unmount-all failed: " << apexd_error_msg;
+ }
+}
+
static void TryExtraMount(const char* name, const char* slot, const char* target) {
std::string partition_name = StringPrintf("%s%s", name, slot);
@@ -231,10 +241,30 @@
exit(205);
}
+ // Call apexd --unmount-all to free up loop and dm block devices, so that we can re-use
+ // them during the next invocation. Since otapreopt_chroot calls exit in case something goes
+ // wrong we need to register our own atexit handler.
+ // We want to register this handler before actually activating apex packages. This is mostly
+ // due to the fact that if fail to unmount apexes, then on the next run of otapreopt_chroot
+ // we will ask for new loop devices instead of re-using existing ones, and we really don't want
+ // to do that. :)
+ if (atexit(DeactivateApexPackages) != 0) {
+ LOG(ERROR) << "Failed to register atexit hander";
+ exit(206);
+ }
+
// Try to mount APEX packages in "/apex" in the chroot dir. We need at least
// the ART APEX, as it is required by otapreopt to run dex2oat.
ActivateApexPackages();
+ auto cleanup = android::base::make_scope_guard([](){
+ std::vector<std::string> apexd_cmd{"/system/bin/apexd", "--unmount-all"};
+ std::string apexd_error_msg;
+ bool exec_result = Exec(apexd_cmd, &apexd_error_msg);
+ if (!exec_result) {
+ PLOG(ERROR) << "Running /system/bin/apexd --unmount-all failed: " << apexd_error_msg;
+ }
+ });
// Check that an ART APEX has been activated; clean up and exit
// early otherwise.
static constexpr const std::string_view kRequiredApexs[] = {
diff --git a/cmds/surfacereplayer/proto/src/trace.proto b/cmds/surfacereplayer/proto/src/trace.proto
index 79aab82..06afefd 100644
--- a/cmds/surfacereplayer/proto/src/trace.proto
+++ b/cmds/surfacereplayer/proto/src/trace.proto
@@ -50,7 +50,6 @@
CornerRadiusChange corner_radius = 16;
ReparentChange reparent = 17;
RelativeParentChange relative_parent = 18;
- ReparentChildrenChange reparent_children = 19;
BackgroundBlurRadiusChange background_blur_radius = 20;
ShadowRadiusChange shadow_radius = 21;
BlurRegionsChange blur_regions = 22;
@@ -190,10 +189,6 @@
required int32 parent_id = 1;
}
-message ReparentChildrenChange {
- required int32 parent_id = 1;
-}
-
message RelativeParentChange {
required int32 relative_parent_id = 1;
required int32 z = 2;
diff --git a/cmds/surfacereplayer/replayer/Replayer.cpp b/cmds/surfacereplayer/replayer/Replayer.cpp
index bbbe6f7..a6d9a3f 100644
--- a/cmds/surfacereplayer/replayer/Replayer.cpp
+++ b/cmds/surfacereplayer/replayer/Replayer.cpp
@@ -410,9 +410,6 @@
case SurfaceChange::SurfaceChangeCase::kReparent:
setReparentChange(transaction, change.id(), change.reparent());
break;
- case SurfaceChange::SurfaceChangeCase::kReparentChildren:
- setReparentChildrenChange(transaction, change.id(), change.reparent_children());
- break;
case SurfaceChange::SurfaceChangeCase::kRelativeParent:
setRelativeParentChange(transaction, change.id(), change.relative_parent());
break;
@@ -709,15 +706,6 @@
t.setRelativeLayer(mLayers[id], mLayers[c.relative_parent_id()], c.z());
}
-void Replayer::setReparentChildrenChange(SurfaceComposerClient::Transaction& t,
- layer_id id, const ReparentChildrenChange& c) {
- if (mLayers.count(c.parent_id()) == 0 || mLayers[c.parent_id()] == nullptr) {
- ALOGE("Layer %d not found in reparent children transaction", c.parent_id());
- return;
- }
- t.reparentChildren(mLayers[id], mLayers[c.parent_id()]);
-}
-
void Replayer::setShadowRadiusChange(SurfaceComposerClient::Transaction& t,
layer_id id, const ShadowRadiusChange& c) {
t.setShadowRadius(mLayers[id], c.radius());
diff --git a/cmds/surfacereplayer/replayer/Replayer.h b/cmds/surfacereplayer/replayer/Replayer.h
index 324d591..252db2b 100644
--- a/cmds/surfacereplayer/replayer/Replayer.h
+++ b/cmds/surfacereplayer/replayer/Replayer.h
@@ -116,8 +116,6 @@
layer_id id, const ReparentChange& c);
void setRelativeParentChange(SurfaceComposerClient::Transaction& t,
layer_id id, const RelativeParentChange& c);
- void setReparentChildrenChange(SurfaceComposerClient::Transaction& t,
- layer_id id, const ReparentChildrenChange& c);
void setShadowRadiusChange(SurfaceComposerClient::Transaction& t,
layer_id id, const ShadowRadiusChange& c);
void setBlurRegionsChange(SurfaceComposerClient::Transaction& t,
diff --git a/data/etc/android.software.translation.xml b/data/etc/android.software.translation.xml
deleted file mode 100644
index 3b361e5..0000000
--- a/data/etc/android.software.translation.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2020 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.
--->
-
-<permissions>
- <feature name="android.software.translation" />
-</permissions>
diff --git a/data/etc/handheld_core_hardware.xml b/data/etc/handheld_core_hardware.xml
index c3c3a7f..41f1514 100644
--- a/data/etc/handheld_core_hardware.xml
+++ b/data/etc/handheld_core_hardware.xml
@@ -54,7 +54,6 @@
<feature name="android.software.autofill" />
<feature name="android.software.cant_save_state" />
<feature name="android.software.secure_lock_screen" />
- <feature name="android.software.translation" />
<!-- Feature to specify if the device supports adding device admins. -->
<feature name="android.software.device_admin" />
diff --git a/data/etc/tablet_core_hardware.xml b/data/etc/tablet_core_hardware.xml
index 4b565fd..8c369de 100644
--- a/data/etc/tablet_core_hardware.xml
+++ b/data/etc/tablet_core_hardware.xml
@@ -54,7 +54,6 @@
<feature name="android.software.autofill" />
<feature name="android.software.cant_save_state" />
<feature name="android.software.secure_lock_screen" />
- <feature name="android.software.translation" />
<!-- Feature to specify if the device supports adding device admins. -->
<feature name="android.software.device_admin" />
diff --git a/include/powermanager/PowerHalController.h b/include/powermanager/PowerHalController.h
index dd34c0a..71a36d0 100644
--- a/include/powermanager/PowerHalController.h
+++ b/include/powermanager/PowerHalController.h
@@ -20,6 +20,7 @@
#include <android-base/thread_annotations.h>
#include <android/hardware/power/Boost.h>
#include <android/hardware/power/IPower.h>
+#include <android/hardware/power/IPowerHintSession.h>
#include <android/hardware/power/Mode.h>
#include <powermanager/PowerHalWrapper.h>
@@ -54,8 +55,12 @@
void init();
- virtual HalResult setBoost(hardware::power::Boost boost, int32_t durationMs) override;
- virtual HalResult setMode(hardware::power::Mode mode, bool enabled) override;
+ virtual HalResult<void> setBoost(hardware::power::Boost boost, int32_t durationMs) override;
+ virtual HalResult<void> setMode(hardware::power::Mode mode, bool enabled) override;
+ virtual HalResult<sp<hardware::power::IPowerHintSession>> createHintSession(
+ int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds,
+ int64_t durationNanos) override;
+ virtual HalResult<int64_t> getHintSessionPreferredRate() override;
private:
std::mutex mConnectedHalMutex;
@@ -67,7 +72,8 @@
const std::shared_ptr<HalWrapper> mDefaultHal = std::make_shared<EmptyHalWrapper>();
std::shared_ptr<HalWrapper> initHal();
- HalResult processHalResult(HalResult result, const char* functionName);
+ template <typename T>
+ HalResult<T> processHalResult(HalResult<T> result, const char* functionName);
};
// -------------------------------------------------------------------------------------------------
diff --git a/include/powermanager/PowerHalWrapper.h b/include/powermanager/PowerHalWrapper.h
index c3e7601..2c6eacb 100644
--- a/include/powermanager/PowerHalWrapper.h
+++ b/include/powermanager/PowerHalWrapper.h
@@ -21,6 +21,7 @@
#include <android/hardware/power/1.1/IPower.h>
#include <android/hardware/power/Boost.h>
#include <android/hardware/power/IPower.h>
+#include <android/hardware/power/IPowerHintSession.h>
#include <android/hardware/power/Mode.h>
namespace android {
@@ -34,11 +35,81 @@
OFF = 2,
};
-// State of the Power HAL api call result.
-enum class HalResult {
- SUCCESSFUL = 0,
- FAILED = 1,
- UNSUPPORTED = 2,
+// Result of a call to the Power HAL wrapper, holding data if successful.
+template <typename T>
+class HalResult {
+public:
+ static HalResult<T> ok(T value) { return HalResult(value); }
+ static HalResult<T> failed(std::string msg) {
+ return HalResult(std::move(msg), /* unsupported= */ false);
+ }
+ static HalResult<T> unsupported() { return HalResult("", /* unsupported= */ true); }
+
+ static HalResult<T> fromStatus(binder::Status status, T data) {
+ if (status.exceptionCode() == binder::Status::EX_UNSUPPORTED_OPERATION) {
+ return HalResult<T>::unsupported();
+ }
+ if (status.isOk()) {
+ return HalResult<T>::ok(data);
+ }
+ return HalResult<T>::failed(std::string(status.toString8().c_str()));
+ }
+ static HalResult<T> fromStatus(hardware::power::V1_0::Status status, T data);
+
+ template <typename R>
+ static HalResult<T> fromReturn(hardware::Return<R>& ret, T data);
+
+ template <typename R>
+ static HalResult<T> fromReturn(hardware::Return<R>& ret, hardware::power::V1_0::Status status,
+ T data);
+
+ // This will throw std::bad_optional_access if this result is not ok.
+ const T& value() const { return mValue.value(); }
+ bool isOk() const { return !mUnsupported && mValue.has_value(); }
+ bool isFailed() const { return !mUnsupported && !mValue.has_value(); }
+ bool isUnsupported() const { return mUnsupported; }
+ const char* errorMessage() const { return mErrorMessage.c_str(); }
+
+private:
+ std::optional<T> mValue;
+ std::string mErrorMessage;
+ bool mUnsupported;
+
+ explicit HalResult(T value)
+ : mValue(std::make_optional(value)), mErrorMessage(), mUnsupported(false) {}
+ explicit HalResult(std::string errorMessage, bool unsupported)
+ : mValue(), mErrorMessage(std::move(errorMessage)), mUnsupported(unsupported) {}
+};
+
+// Empty result of a call to the Power HAL wrapper.
+template <>
+class HalResult<void> {
+public:
+ static HalResult<void> ok() { return HalResult(); }
+ static HalResult<void> failed(std::string msg) { return HalResult(std::move(msg)); }
+ static HalResult<void> unsupported() { return HalResult(/* unsupported= */ true); }
+
+ static HalResult<void> fromStatus(status_t status);
+ static HalResult<void> fromStatus(binder::Status status);
+ static HalResult<void> fromStatus(hardware::power::V1_0::Status status);
+
+ template <typename R>
+ static HalResult<void> fromReturn(hardware::Return<R>& ret);
+
+ bool isOk() const { return !mUnsupported && !mFailed; }
+ bool isFailed() const { return !mUnsupported && mFailed; }
+ bool isUnsupported() const { return mUnsupported; }
+ const char* errorMessage() const { return mErrorMessage.c_str(); }
+
+private:
+ std::string mErrorMessage;
+ bool mFailed;
+ bool mUnsupported;
+
+ explicit HalResult(bool unsupported = false)
+ : mErrorMessage(), mFailed(false), mUnsupported(unsupported) {}
+ explicit HalResult(std::string errorMessage)
+ : mErrorMessage(std::move(errorMessage)), mFailed(true), mUnsupported(false) {}
};
// Wrapper for Power HAL handlers.
@@ -46,8 +117,12 @@
public:
virtual ~HalWrapper() = default;
- virtual HalResult setBoost(hardware::power::Boost boost, int32_t durationMs) = 0;
- virtual HalResult setMode(hardware::power::Mode mode, bool enabled) = 0;
+ virtual HalResult<void> setBoost(hardware::power::Boost boost, int32_t durationMs) = 0;
+ virtual HalResult<void> setMode(hardware::power::Mode mode, bool enabled) = 0;
+ virtual HalResult<sp<hardware::power::IPowerHintSession>> createHintSession(
+ int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds,
+ int64_t durationNanos) = 0;
+ virtual HalResult<int64_t> getHintSessionPreferredRate() = 0;
};
// Empty Power HAL wrapper that ignores all api calls.
@@ -56,8 +131,12 @@
EmptyHalWrapper() = default;
~EmptyHalWrapper() = default;
- virtual HalResult setBoost(hardware::power::Boost boost, int32_t durationMs) override;
- virtual HalResult setMode(hardware::power::Mode mode, bool enabled) override;
+ virtual HalResult<void> setBoost(hardware::power::Boost boost, int32_t durationMs) override;
+ virtual HalResult<void> setMode(hardware::power::Mode mode, bool enabled) override;
+ virtual HalResult<sp<hardware::power::IPowerHintSession>> createHintSession(
+ int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds,
+ int64_t durationNanos) override;
+ virtual HalResult<int64_t> getHintSessionPreferredRate() override;
};
// Wrapper for the HIDL Power HAL v1.0.
@@ -67,16 +146,20 @@
: mHandleV1_0(std::move(Hal)) {}
virtual ~HidlHalWrapperV1_0() = default;
- virtual HalResult setBoost(hardware::power::Boost boost, int32_t durationMs) override;
- virtual HalResult setMode(hardware::power::Mode mode, bool enabled) override;
+ virtual HalResult<void> setBoost(hardware::power::Boost boost, int32_t durationMs) override;
+ virtual HalResult<void> setMode(hardware::power::Mode mode, bool enabled) override;
+ virtual HalResult<sp<hardware::power::IPowerHintSession>> createHintSession(
+ int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds,
+ int64_t durationNanos) override;
+ virtual HalResult<int64_t> getHintSessionPreferredRate() override;
protected:
- virtual HalResult sendPowerHint(hardware::power::V1_0::PowerHint hintId, uint32_t data);
+ virtual HalResult<void> sendPowerHint(hardware::power::V1_0::PowerHint hintId, uint32_t data);
private:
sp<hardware::power::V1_0::IPower> mHandleV1_0;
- HalResult setInteractive(bool enabled);
- HalResult setFeature(hardware::power::V1_0::Feature feature, bool enabled);
+ HalResult<void> setInteractive(bool enabled);
+ HalResult<void> setFeature(hardware::power::V1_0::Feature feature, bool enabled);
};
// Wrapper for the HIDL Power HAL v1.1.
@@ -88,8 +171,8 @@
virtual ~HidlHalWrapperV1_1() = default;
protected:
- virtual HalResult sendPowerHint(hardware::power::V1_0::PowerHint hintId,
- uint32_t data) override;
+ virtual HalResult<void> sendPowerHint(hardware::power::V1_0::PowerHint hintId,
+ uint32_t data) override;
private:
sp<hardware::power::V1_1::IPower> mHandleV1_1;
@@ -101,8 +184,12 @@
explicit AidlHalWrapper(sp<hardware::power::IPower> handle) : mHandle(std::move(handle)) {}
virtual ~AidlHalWrapper() = default;
- virtual HalResult setBoost(hardware::power::Boost boost, int32_t durationMs) override;
- virtual HalResult setMode(hardware::power::Mode mode, bool enabled) override;
+ virtual HalResult<void> setBoost(hardware::power::Boost boost, int32_t durationMs) override;
+ virtual HalResult<void> setMode(hardware::power::Mode mode, bool enabled) override;
+ virtual HalResult<sp<hardware::power::IPowerHintSession>> createHintSession(
+ int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds,
+ int64_t durationNanos) override;
+ virtual HalResult<int64_t> getHintSessionPreferredRate() override;
private:
// Control access to the boost and mode supported arrays.
diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp
index cdd8006..6da4e9e 100644
--- a/libs/binder/Android.bp
+++ b/libs/binder/Android.bp
@@ -60,16 +60,13 @@
// Currently, these are only on system android (not vendor, not host)
// TODO(b/183654927) - move these into separate libraries
libbinder_device_interface_sources = [
- "ActivityManager.cpp",
"AppOpsManager.cpp",
- "IActivityManager.cpp",
"IAppOpsCallback.cpp",
"IAppOpsService.cpp",
+
"IPermissionController.cpp",
- "IUidObserver.cpp",
"PermissionCache.cpp",
"PermissionController.cpp",
- ":activity_manager_procstate_aidl",
]
cc_library {
@@ -163,6 +160,7 @@
"-Werror",
"-Wzero-as-null-pointer-constant",
"-DANDROID_BASE_UNIQUE_FD_DISABLE_IMPLICIT_CONVERSION",
+ "-DANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION",
],
product_variables: {
binder32bit: {
@@ -294,13 +292,21 @@
],
}
-// TODO(b/183654927): initially empty lib to work around some merge conflicts
cc_library {
name: "libactivitymanager_aidl",
- srcs: [],
+ srcs: [
+ "ActivityManager.cpp",
+ "IActivityManager.cpp",
+ "IUidObserver.cpp",
+ ":activity_manager_procstate_aidl",
+ ],
+ export_include_dirs: ["include_activitymanager"],
shared_libs: [
"libbinder",
"libutils",
"liblog",
],
+ aidl: {
+ export_aidl_headers: true,
+ },
}
diff --git a/libs/binder/AppOpsManager.cpp b/libs/binder/AppOpsManager.cpp
index de42f36..baa9d75 100644
--- a/libs/binder/AppOpsManager.cpp
+++ b/libs/binder/AppOpsManager.cpp
@@ -37,7 +37,7 @@
pthread_mutex_lock(&gClientIdMutex);
if (gClientId == nullptr) {
- gClientId = new BBinder();
+ gClientId = sp<BBinder>::make();
}
pthread_mutex_unlock(&gClientIdMutex);
return gClientId;
diff --git a/libs/binder/BpBinder.cpp b/libs/binder/BpBinder.cpp
index 53b36ff..fdcf94a 100644
--- a/libs/binder/BpBinder.cpp
+++ b/libs/binder/BpBinder.cpp
@@ -107,8 +107,7 @@
// ---------------------------------------------------------------------------
-
-BpBinder* BpBinder::create(int32_t handle) {
+sp<BpBinder> BpBinder::create(int32_t handle) {
int32_t trackedUid = -1;
if (sCountByUidEnabled) {
trackedUid = IPCThreadState::self()->getCallingUid();
@@ -134,10 +133,10 @@
}
sTrackingMap[trackedUid]++;
}
- return new BpBinder(BinderHandle{handle}, trackedUid);
+ return sp<BpBinder>::make(BinderHandle{handle}, trackedUid);
}
-BpBinder* BpBinder::create(const sp<RpcConnection>& connection, const RpcAddress& address) {
+sp<BpBinder> BpBinder::create(const sp<RpcConnection>& connection, const RpcAddress& address) {
LOG_ALWAYS_FATAL_IF(connection == nullptr, "BpBinder::create null connection");
// These are not currently tracked, since there is no UID or other
@@ -145,7 +144,7 @@
// needed, connection objects keep track of all BpBinder objects on a
// per-connection basis.
- return new BpBinder(SocketHandle{connection, address});
+ return sp<BpBinder>::make(SocketHandle{connection, address});
}
BpBinder::BpBinder(Handle&& handle)
@@ -194,7 +193,7 @@
const String16& BpBinder::getInterfaceDescriptor() const
{
if (isDescriptorCached() == false) {
- sp<BpBinder> thiz = const_cast<BpBinder*>(this);
+ sp<BpBinder> thiz = sp<BpBinder>::fromExisting(const_cast<BpBinder*>(this));
Parcel data;
data.markForBinder(thiz);
@@ -226,7 +225,7 @@
status_t BpBinder::pingBinder()
{
Parcel data;
- data.markForBinder(this);
+ data.markForBinder(sp<BpBinder>::fromExisting(this));
Parcel reply;
return transact(PING_TRANSACTION, data, &reply);
}
@@ -403,7 +402,7 @@
ALOGV("Reporting death to recipient: %p\n", recipient.get());
if (recipient == nullptr) return;
- recipient->binderDied(this);
+ recipient->binderDied(wp<BpBinder>::fromExisting(this));
}
diff --git a/libs/binder/BufferedTextOutput.cpp b/libs/binder/BufferedTextOutput.cpp
index 349658e..a90bfd2 100644
--- a/libs/binder/BufferedTextOutput.cpp
+++ b/libs/binder/BufferedTextOutput.cpp
@@ -254,7 +254,7 @@
BufferState* bs = ts.states[mIndex].get();
if (bs != nullptr && bs->seq == mSeq) return bs;
- ts.states.editItemAt(mIndex) = new BufferState(mIndex);
+ ts.states.editItemAt(mIndex) = sp<BufferState>::make(mIndex);
bs = ts.states[mIndex].get();
if (bs != nullptr) return bs;
}
diff --git a/libs/binder/IAppOpsService.cpp b/libs/binder/IAppOpsService.cpp
index 44aa55e..d59f445 100644
--- a/libs/binder/IAppOpsService.cpp
+++ b/libs/binder/IAppOpsService.cpp
@@ -18,8 +18,8 @@
#include <binder/IAppOpsService.h>
-#include <utils/Log.h>
#include <binder/Parcel.h>
+#include <utils/Log.h>
#include <utils/String8.h>
#include <optional>
@@ -63,6 +63,8 @@
remote()->transact(NOTE_OPERATION_TRANSACTION, data, &reply);
// fail on exception
if (reply.readExceptionCode() != 0) return MODE_ERRORED;
+ // TODO b/184855056: extract to class
+ reply.readInt32();
reply.readByte();
return reply.readInt32();
}
@@ -85,6 +87,8 @@
remote()->transact(START_OPERATION_TRANSACTION, data, &reply);
// fail on exception
if (reply.readExceptionCode() != 0) return MODE_ERRORED;
+ // TODO b/184855056: extract to class
+ reply.readInt32();
reply.readByte();
return reply.readInt32();
}
diff --git a/libs/binder/IInterface.cpp b/libs/binder/IInterface.cpp
index b19004d..2780bd4 100644
--- a/libs/binder/IInterface.cpp
+++ b/libs/binder/IInterface.cpp
@@ -33,14 +33,14 @@
sp<IBinder> IInterface::asBinder(const IInterface* iface)
{
if (iface == nullptr) return nullptr;
- return const_cast<IInterface*>(iface)->onAsBinder();
+ return sp<IBinder>::fromExisting(const_cast<IInterface*>(iface)->onAsBinder());
}
// static
sp<IBinder> IInterface::asBinder(const sp<IInterface>& iface)
{
if (iface == nullptr) return nullptr;
- return iface->onAsBinder();
+ return sp<IBinder>::fromExisting(iface->onAsBinder());
}
diff --git a/libs/binder/IMemory.cpp b/libs/binder/IMemory.cpp
index cca8f81..bd974b0 100644
--- a/libs/binder/IMemory.cpp
+++ b/libs/binder/IMemory.cpp
@@ -68,7 +68,7 @@
// TODO: Reimplemement based on standard C++ container?
};
-static sp<HeapCache> gHeapCache = new HeapCache();
+static sp<HeapCache> gHeapCache = sp<HeapCache>::make();
/******************************************************************************/
@@ -288,7 +288,7 @@
int32_t heapId = mHeapId.load(memory_order_acquire);
if (heapId == -1) {
sp<IBinder> binder(IInterface::asBinder(const_cast<BpMemoryHeap*>(this)));
- sp<BpMemoryHeap> heap(static_cast<BpMemoryHeap*>(find_heap(binder).get()));
+ sp<BpMemoryHeap> heap = sp<BpMemoryHeap>::cast(find_heap(binder));
heap->assertReallyMapped();
if (heap->mBase != MAP_FAILED) {
Mutex::Autolock _l(mLock);
diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp
index ca067e2..61f4581 100644
--- a/libs/binder/IServiceManager.cpp
+++ b/libs/binder/IServiceManager.cpp
@@ -102,7 +102,7 @@
}
}
- gDefaultServiceManager = new ServiceManagerShim(sm);
+ gDefaultServiceManager = sp<ServiceManagerShim>::make(sm);
});
return gDefaultServiceManager;
@@ -324,7 +324,7 @@
}
if (out != nullptr) return out;
- sp<Waiter> waiter = new Waiter;
+ sp<Waiter> waiter = sp<Waiter>::make();
if (!mTheRealServiceManager->registerForNotifications(
name, waiter).isOk()) {
return nullptr;
diff --git a/libs/binder/LazyServiceRegistrar.cpp b/libs/binder/LazyServiceRegistrar.cpp
index f96b6bb..b503beb 100644
--- a/libs/binder/LazyServiceRegistrar.cpp
+++ b/libs/binder/LazyServiceRegistrar.cpp
@@ -129,7 +129,9 @@
}
if (!reRegister) {
- if(!manager->registerClientCallback(name, service, this).isOk()) {
+ if (!manager->registerClientCallback(name, service,
+ sp<android::os::IClientCallback>::fromExisting(this))
+ .isOk()) {
ALOGE("Failed to add client callback for service %s", name.c_str());
return false;
}
diff --git a/libs/binder/MemoryDealer.cpp b/libs/binder/MemoryDealer.cpp
index b46b3e8..c4475c7 100644
--- a/libs/binder/MemoryDealer.cpp
+++ b/libs/binder/MemoryDealer.cpp
@@ -228,10 +228,8 @@
// ----------------------------------------------------------------------------
MemoryDealer::MemoryDealer(size_t size, const char* name, uint32_t flags)
- : mHeap(new MemoryHeapBase(size, flags, name)),
- mAllocator(new SimpleBestFitAllocator(size))
-{
-}
+ : mHeap(sp<MemoryHeapBase>::make(size, flags, name)),
+ mAllocator(new SimpleBestFitAllocator(size)) {}
MemoryDealer::~MemoryDealer()
{
@@ -243,7 +241,7 @@
sp<IMemory> memory;
const ssize_t offset = allocator()->allocate(size);
if (offset >= 0) {
- memory = new Allocation(this, heap(), offset, size);
+ memory = sp<Allocation>::make(sp<MemoryDealer>::fromExisting(this), heap(), offset, size);
}
return memory;
}
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 0425159..a735309 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -293,7 +293,8 @@
if (flat) {
switch (flat->hdr.type) {
case BINDER_TYPE_BINDER: {
- sp<IBinder> binder = reinterpret_cast<IBinder*>(flat->cookie);
+ sp<IBinder> binder =
+ sp<IBinder>::fromExisting(reinterpret_cast<IBinder*>(flat->cookie));
return finishUnflattenBinder(binder, out);
}
case BINDER_TYPE_HANDLE: {
diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp
index abb792e..7647a8c 100644
--- a/libs/binder/ProcessState.cpp
+++ b/libs/binder/ProcessState.cpp
@@ -105,7 +105,7 @@
}
std::lock_guard<std::mutex> l(gProcessMutex);
- gProcess = new ProcessState(driver);
+ gProcess = sp<ProcessState>::make(driver);
});
if (requireDefault) {
@@ -299,8 +299,8 @@
return nullptr;
}
- b = BpBinder::create(handle);
- e->binder = b;
+ sp<BpBinder> b = BpBinder::create(handle);
+ e->binder = b.get();
if (b) e->refs = b->getWeakRefs();
result = b;
} else {
@@ -340,7 +340,7 @@
if (mThreadPoolStarted) {
String8 name = makeBinderThreadName();
ALOGV("Spawning new pooled thread, name=%s\n", name.string());
- sp<Thread> t = new PoolThread(isMain);
+ sp<Thread> t = sp<PoolThread>::make(isMain);
t->run(name.string());
}
}
diff --git a/libs/binder/RpcConnection.cpp b/libs/binder/RpcConnection.cpp
index dab3246..1bf3d88 100644
--- a/libs/binder/RpcConnection.cpp
+++ b/libs/binder/RpcConnection.cpp
@@ -54,7 +54,7 @@
}
sp<RpcConnection> RpcConnection::make() {
- return new RpcConnection;
+ return sp<RpcConnection>::make();
}
class UnixSocketAddress : public RpcConnection::SocketAddress {
@@ -120,20 +120,21 @@
#endif // __BIONIC__
sp<IBinder> RpcConnection::getRootObject() {
- ExclusiveSocket socket(this, SocketUse::CLIENT);
- return state()->getRootObject(socket.fd(), this);
+ ExclusiveSocket socket(sp<RpcConnection>::fromExisting(this), SocketUse::CLIENT);
+ return state()->getRootObject(socket.fd(), sp<RpcConnection>::fromExisting(this));
}
status_t RpcConnection::transact(const RpcAddress& address, uint32_t code, const Parcel& data,
Parcel* reply, uint32_t flags) {
- ExclusiveSocket socket(this,
+ ExclusiveSocket socket(sp<RpcConnection>::fromExisting(this),
(flags & IBinder::FLAG_ONEWAY) ? SocketUse::CLIENT_ASYNC
: SocketUse::CLIENT);
- return state()->transact(socket.fd(), address, code, data, this, reply, flags);
+ return state()->transact(socket.fd(), address, code, data,
+ sp<RpcConnection>::fromExisting(this), reply, flags);
}
status_t RpcConnection::sendDecStrong(const RpcAddress& address) {
- ExclusiveSocket socket(this, SocketUse::CLIENT_REFCOUNT);
+ ExclusiveSocket socket(sp<RpcConnection>::fromExisting(this), SocketUse::CLIENT_REFCOUNT);
return state()->sendDecStrong(socket.fd(), address);
}
@@ -157,10 +158,11 @@
// We may not use the connection we just established (two threads might
// establish connections for each other), but for now, just use one
// server/socket connection.
- ExclusiveSocket socket(this, SocketUse::SERVER);
+ ExclusiveSocket socket(sp<RpcConnection>::fromExisting(this), SocketUse::SERVER);
while (true) {
- status_t error = state()->getAndExecuteCommand(socket.fd(), this);
+ status_t error =
+ state()->getAndExecuteCommand(socket.fd(), sp<RpcConnection>::fromExisting(this));
if (error != OK) {
ALOGI("Binder socket thread closing w/ status %s", statusToString(error).c_str());
@@ -221,7 +223,7 @@
LOG_RPC_DETAIL("Socket at %s client with fd %d", addr.toString().c_str(), serverFd.get());
std::lock_guard<std::mutex> _l(mSocketMutex);
- sp<ConnectionSocket> connection = new ConnectionSocket();
+ sp<ConnectionSocket> connection = sp<ConnectionSocket>::make();
connection->fd = std::move(serverFd);
mClients.push_back(connection);
return true;
@@ -229,7 +231,7 @@
void RpcConnection::assignServerToThisThread(base::unique_fd&& fd) {
std::lock_guard<std::mutex> _l(mSocketMutex);
- sp<ConnectionSocket> connection = new ConnectionSocket();
+ sp<ConnectionSocket> connection = sp<ConnectionSocket>::make();
connection->fd = std::move(fd);
mServers.push_back(connection);
}
diff --git a/libs/binder/RpcServer.cpp b/libs/binder/RpcServer.cpp
index df07916..1fa37ba 100644
--- a/libs/binder/RpcServer.cpp
+++ b/libs/binder/RpcServer.cpp
@@ -36,7 +36,7 @@
RpcServer::~RpcServer() {}
sp<RpcServer> RpcServer::make() {
- return new RpcServer;
+ return sp<RpcServer>::make();
}
void RpcServer::iUnderstandThisCodeIsExperimentalAndIWillNotUseItInProduction() {
@@ -47,7 +47,7 @@
LOG_ALWAYS_FATAL_IF(!mAgreedExperimental, "no!");
auto connection = RpcConnection::make();
- connection->setForServer(this);
+ connection->setForServer(sp<RpcServer>::fromExisting(this));
mConnections.push_back(connection);
return connection;
}
diff --git a/libs/binder/include/binder/AppOpsManager.h b/libs/binder/include/binder/AppOpsManager.h
index be6667d..c048cbe 100644
--- a/libs/binder/include/binder/AppOpsManager.h
+++ b/libs/binder/include/binder/AppOpsManager.h
@@ -144,7 +144,9 @@
OP_MANAGE_MEDIA = 110,
OP_BLUETOOTH_CONNECT = 111,
OP_UWB_RANGING = 112,
- _NUM_OP = 113
+ OP_ACTIVITY_RECOGNITION_SOURCE = 113,
+ OP_BLUETOOTH_ADVERTISE = 114,
+ _NUM_OP = 115
};
AppOpsManager();
diff --git a/libs/binder/include/binder/Binder.h b/libs/binder/include/binder/Binder.h
index 7079544..7e9be41 100644
--- a/libs/binder/include/binder/Binder.h
+++ b/libs/binder/include/binder/Binder.h
@@ -131,8 +131,8 @@
virtual void onLastStrongRef(const void* id);
virtual bool onIncStrongAttempted(uint32_t flags, const void* id);
- inline IBinder* remote() { return mRemote; }
- inline IBinder* remote() const { return mRemote; }
+ inline IBinder* remote() const { return mRemote; }
+ inline sp<IBinder> remoteStrong() const { return sp<IBinder>::fromExisting(mRemote); }
private:
BpRefBase(const BpRefBase& o);
diff --git a/libs/binder/include/binder/BpBinder.h b/libs/binder/include/binder/BpBinder.h
index 8ab7893..ad618f9 100644
--- a/libs/binder/include/binder/BpBinder.h
+++ b/libs/binder/include/binder/BpBinder.h
@@ -40,8 +40,8 @@
class BpBinder : public IBinder
{
public:
- static BpBinder* create(int32_t handle);
- static BpBinder* create(const sp<RpcConnection>& connection, const RpcAddress& address);
+ static sp<BpBinder> create(int32_t handle);
+ static sp<BpBinder> create(const sp<RpcConnection>& connection, const RpcAddress& address);
/**
* Return value:
@@ -143,6 +143,7 @@
private:
friend PrivateAccessorForId;
+ friend class sp<BpBinder>;
struct BinderHandle {
int32_t handle;
diff --git a/libs/binder/include/binder/IInterface.h b/libs/binder/include/binder/IInterface.h
index b86fc0b..ff90b30 100644
--- a/libs/binder/include/binder/IInterface.h
+++ b/libs/binder/include/binder/IInterface.h
@@ -143,11 +143,10 @@
{ \
::android::sp<I##INTERFACE> intr; \
if (obj != nullptr) { \
- intr = static_cast<I##INTERFACE*>( \
- obj->queryLocalInterface( \
- I##INTERFACE::descriptor).get()); \
+ intr = ::android::sp<I##INTERFACE>::cast( \
+ obj->queryLocalInterface(I##INTERFACE::descriptor)); \
if (intr == nullptr) { \
- intr = new Bp##INTERFACE(obj); \
+ intr = ::android::sp<Bp##INTERFACE>::make(obj); \
} \
} \
return intr; \
diff --git a/libs/binder/include/binder/ProcessState.h b/libs/binder/include/binder/ProcessState.h
index ca29440..0919648 100644
--- a/libs/binder/include/binder/ProcessState.h
+++ b/libs/binder/include/binder/ProcessState.h
@@ -88,7 +88,8 @@
static sp<ProcessState> init(const char *defaultDriver, bool requireDefault);
friend class IPCThreadState;
-
+ friend class sp<ProcessState>;
+
explicit ProcessState(const char* driver);
~ProcessState();
diff --git a/libs/binder/include/binder/RpcServer.h b/libs/binder/include/binder/RpcServer.h
index a2c2aee..d29b651 100644
--- a/libs/binder/include/binder/RpcServer.h
+++ b/libs/binder/include/binder/RpcServer.h
@@ -72,6 +72,7 @@
~RpcServer();
private:
+ friend sp<RpcServer>;
RpcServer();
bool mAgreedExperimental = false;
diff --git a/libs/binder/include/binder/ActivityManager.h b/libs/binder/include_activitymanager/binder/ActivityManager.h
similarity index 100%
rename from libs/binder/include/binder/ActivityManager.h
rename to libs/binder/include_activitymanager/binder/ActivityManager.h
diff --git a/libs/binder/include/binder/IActivityManager.h b/libs/binder/include_activitymanager/binder/IActivityManager.h
similarity index 99%
rename from libs/binder/include/binder/IActivityManager.h
rename to libs/binder/include_activitymanager/binder/IActivityManager.h
index 2d58c46..4632b2e 100644
--- a/libs/binder/include/binder/IActivityManager.h
+++ b/libs/binder/include_activitymanager/binder/IActivityManager.h
@@ -18,8 +18,8 @@
#ifndef __ANDROID_VNDK__
-#include <binder/IInterface.h>
#include <binder/IUidObserver.h>
+#include <binder/IInterface.h>
namespace android {
diff --git a/libs/binder/include/binder/IUidObserver.h b/libs/binder/include_activitymanager/binder/IUidObserver.h
similarity index 100%
rename from libs/binder/include/binder/IUidObserver.h
rename to libs/binder/include_activitymanager/binder/IUidObserver.h
diff --git a/libs/binder/ndk/ibinder.cpp b/libs/binder/ndk/ibinder.cpp
index 3e6c39f..1dcb41b 100644
--- a/libs/binder/ndk/ibinder.cpp
+++ b/libs/binder/ndk/ibinder.cpp
@@ -363,7 +363,8 @@
}
void AIBinder_DeathRecipient::TransferDeathRecipient::binderDied(const wp<IBinder>& who) {
- CHECK(who == mWho);
+ CHECK(who == mWho) << who.unsafe_get() << "(" << who.get_refs() << ") vs " << mWho.unsafe_get()
+ << " (" << mWho.get_refs() << ")";
mOnDied(mCookie);
diff --git a/libs/gui/Android.bp b/libs/gui/Android.bp
index ff059d7..64203f7 100644
--- a/libs/gui/Android.bp
+++ b/libs/gui/Android.bp
@@ -39,12 +39,50 @@
min_sdk_version: "29",
}
+cc_library_headers {
+ name: "libgui_aidl_headers",
+ vendor_available: true,
+ static_libs: [
+ "libgui_aidl_static",
+ ],
+
+ export_static_lib_headers: [
+ "libgui_aidl_static",
+ ],
+}
+
filegroup {
name: "libgui_aidl",
srcs: ["aidl/**/*.aidl"],
path: "aidl/",
}
+cc_library_static {
+ name: "libgui_aidl_static",
+ vendor_available: true,
+ srcs: [
+ ":libgui_aidl",
+ ],
+
+ shared_libs: [
+ "libbinder",
+ "libui",
+ ],
+
+ local_include_dirs: [
+ "include",
+ ],
+
+ export_shared_lib_headers: [
+ "libbinder",
+ ],
+
+ aidl: {
+ export_aidl_headers: true
+ }
+}
+
+
cc_library_shared {
name: "libgui",
vendor_available: true,
@@ -56,10 +94,16 @@
defaults: ["libgui_bufferqueue-defaults"],
+ static_libs: [
+ "libgui_aidl_static",
+ ],
+ export_static_lib_headers: [
+ "libgui_aidl_static",
+ ],
+
srcs: [
":framework_native_aidl",
":inputconstants_aidl",
- ":libgui_aidl",
":libgui_bufferqueue_sources",
"BitTube.cpp",
@@ -115,6 +159,10 @@
"libinput",
],
+ export_header_lib_headers: [
+ "libgui_aidl_headers",
+ ],
+
// bufferhub is not used when building libgui for vendors
target: {
vendor: {
@@ -136,15 +184,16 @@
},
},
- header_libs: [
- "libdvr_headers",
- "libpdx_headers",
- ],
-
aidl: {
export_aidl_headers: true,
},
+ header_libs: [
+ "libdvr_headers",
+ "libgui_aidl_headers",
+ "libpdx_headers",
+ ],
+
pgo: {
sampling: true,
profile_file: "libgui/libgui.profdata",
@@ -175,8 +224,8 @@
srcs: [
":inputconstants_aidl",
- ":libgui_aidl",
":libgui_bufferqueue_sources",
+ ":libgui_aidl",
],
}
diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp
index 0ca4977..8094385 100644
--- a/libs/gui/LayerState.cpp
+++ b/libs/gui/LayerState.cpp
@@ -430,10 +430,6 @@
barrierSurfaceControl_legacy = other.barrierSurfaceControl_legacy;
barrierFrameNumber = other.barrierFrameNumber;
}
- if (other.what & eReparentChildren) {
- what |= eReparentChildren;
- reparentSurfaceControl = other.reparentSurfaceControl;
- }
if (other.what & eRelativeLayerChanged) {
what |= eRelativeLayerChanged;
what &= ~eLayerChanged;
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index c888312..9ce094a 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -1157,20 +1157,6 @@
return *this;
}
-SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparentChildren(
- const sp<SurfaceControl>& sc, const sp<SurfaceControl>& newParent) {
- layer_state_t* s = getLayerState(sc);
- if (!s) {
- mStatus = BAD_INDEX;
- return *this;
- }
- s->what |= layer_state_t::eReparentChildren;
- s->reparentSurfaceControl = newParent;
-
- registerSurfaceControlForCallback(sc);
- return *this;
-}
-
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparent(
const sp<SurfaceControl>& sc, const sp<SurfaceControl>& newParent) {
layer_state_t* s = getLayerState(sc);
diff --git a/libs/gui/include/gui/FrameTimelineInfo.h b/libs/gui/include/gui/FrameTimelineInfo.h
index 3b4c009..a23c202 100644
--- a/libs/gui/include/gui/FrameTimelineInfo.h
+++ b/libs/gui/include/gui/FrameTimelineInfo.h
@@ -18,7 +18,6 @@
#include <stdint.h>
-#include <android/os/IInputConstants.h>
#include <binder/Parcel.h>
namespace android {
@@ -31,7 +30,11 @@
int64_t vsyncId = INVALID_VSYNC_ID;
// The id of the input event that caused this buffer
- int32_t inputEventId = android::os::IInputConstants::INVALID_INPUT_EVENT_ID;
+ // Default is android::os::IInputConstants::INVALID_INPUT_EVENT_ID = 0
+ // We copy the value of the input event ID instead of including the header, because libgui
+ // header libraries containing FrameTimelineInfo must be available to vendors, but libinput is
+ // not directly vendor available.
+ int32_t inputEventId = 0;
status_t write(Parcel& output) const;
status_t read(const Parcel& input);
diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h
index 706a09c..41a022f 100644
--- a/libs/gui/include/gui/LayerState.h
+++ b/libs/gui/include/gui/LayerState.h
@@ -86,7 +86,6 @@
eDeferTransaction_legacy = 0x00000200,
eReleaseBufferListenerChanged = 0x00000400,
eShadowRadiusChanged = 0x00000800,
- eReparentChildren = 0x00001000,
/* was eDetachChildren, now available 0x00002000, */
eRelativeLayerChanged = 0x00004000,
eReparent = 0x00008000,
diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h
index 731af58..1590b10 100644
--- a/libs/gui/include/gui/SurfaceComposerClient.h
+++ b/libs/gui/include/gui/SurfaceComposerClient.h
@@ -461,13 +461,7 @@
Transaction& deferTransactionUntil_legacy(const sp<SurfaceControl>& sc,
const sp<SurfaceControl>& barrierSurfaceControl,
uint64_t frameNumber);
- // Reparents all children of this layer to the new parent handle.
- Transaction& reparentChildren(const sp<SurfaceControl>& sc,
- const sp<SurfaceControl>& newParent);
-
/// Reparents the current layer to the new parent handle. The new parent must not be null.
- // This can be used instead of reparentChildren if the caller wants to
- // only re-parent a specific child.
Transaction& reparent(const sp<SurfaceControl>& sc, const sp<SurfaceControl>& newParent);
Transaction& setColor(const sp<SurfaceControl>& sc, const half3& color);
diff --git a/libs/gui/tests/EndToEndNativeInputTest.cpp b/libs/gui/tests/EndToEndNativeInputTest.cpp
index 59e5c13..49c44a7 100644
--- a/libs/gui/tests/EndToEndNativeInputTest.cpp
+++ b/libs/gui/tests/EndToEndNativeInputTest.cpp
@@ -47,6 +47,8 @@
using android::os::IInputFlinger;
+using android::hardware::graphics::common::V1_1::BufferUsage;
+
namespace android::test {
using Transaction = SurfaceComposerClient::Transaction;
@@ -95,15 +97,6 @@
return std::make_unique<InputSurface>(surfaceControl, width, height);
}
- static std::unique_ptr<InputSurface> makeBlastInputSurface(const sp<SurfaceComposerClient> &scc,
- int width, int height) {
- sp<SurfaceControl> surfaceControl =
- scc->createSurface(String8("Test Buffer Surface"), width, height,
- PIXEL_FORMAT_RGBA_8888,
- ISurfaceComposerClient::eFXSurfaceBufferState);
- return std::make_unique<InputSurface>(surfaceControl, width, height);
- }
-
static std::unique_ptr<InputSurface> makeContainerInputSurface(
const sp<SurfaceComposerClient> &scc, int width, int height) {
sp<SurfaceControl> surfaceControl =
@@ -180,16 +173,19 @@
EXPECT_EQ(flags, mev->getFlags() & flags);
}
- ~InputSurface() { mInputFlinger->removeInputChannel(mClientChannel->getConnectionToken()); }
+ virtual ~InputSurface() {
+ mInputFlinger->removeInputChannel(mClientChannel->getConnectionToken());
+ }
- void doTransaction(std::function<void(SurfaceComposerClient::Transaction&,
- const sp<SurfaceControl>&)> transactionBody) {
+ virtual void doTransaction(
+ std::function<void(SurfaceComposerClient::Transaction &, const sp<SurfaceControl> &)>
+ transactionBody) {
SurfaceComposerClient::Transaction t;
transactionBody(t, mSurfaceControl);
t.apply(true);
}
- void showAt(int x, int y, Rect crop = Rect(0, 0, 100, 100)) {
+ virtual void showAt(int x, int y, Rect crop = Rect(0, 0, 100, 100)) {
SurfaceComposerClient::Transaction t;
t.show(mSurfaceControl);
t.setInputWindowInfo(mSurfaceControl, mInputInfo);
@@ -259,6 +255,57 @@
InputConsumer* mInputConsumer;
};
+class BlastInputSurface : public InputSurface {
+public:
+ BlastInputSurface(const sp<SurfaceControl> &sc, const sp<SurfaceControl> &parentSc, int width,
+ int height)
+ : InputSurface(sc, width, height) {
+ mParentSurfaceControl = parentSc;
+ }
+
+ ~BlastInputSurface() = default;
+
+ static std::unique_ptr<BlastInputSurface> makeBlastInputSurface(
+ const sp<SurfaceComposerClient> &scc, int width, int height) {
+ sp<SurfaceControl> parentSc =
+ scc->createSurface(String8("Test Parent Surface"), 0 /* bufHeight */,
+ 0 /* bufWidth */, PIXEL_FORMAT_RGBA_8888,
+ ISurfaceComposerClient::eFXSurfaceContainer);
+
+ sp<SurfaceControl> surfaceControl =
+ scc->createSurface(String8("Test Buffer Surface"), width, height,
+ PIXEL_FORMAT_RGBA_8888,
+ ISurfaceComposerClient::eFXSurfaceBufferState,
+ parentSc->getHandle());
+ return std::make_unique<BlastInputSurface>(surfaceControl, parentSc, width, height);
+ }
+
+ void doTransaction(
+ std::function<void(SurfaceComposerClient::Transaction &, const sp<SurfaceControl> &)>
+ transactionBody) override {
+ SurfaceComposerClient::Transaction t;
+ transactionBody(t, mParentSurfaceControl);
+ t.apply(true);
+ }
+
+ void showAt(int x, int y, Rect crop = Rect(0, 0, 100, 100)) override {
+ SurfaceComposerClient::Transaction t;
+ t.show(mParentSurfaceControl);
+ t.setLayer(mParentSurfaceControl, LAYER_BASE);
+ t.setPosition(mParentSurfaceControl, x, y);
+ t.setCrop(mParentSurfaceControl, crop);
+
+ t.show(mSurfaceControl);
+ t.setInputWindowInfo(mSurfaceControl, mInputInfo);
+ t.setCrop(mSurfaceControl, crop);
+ t.setAlpha(mSurfaceControl, 1);
+ t.apply(true);
+ }
+
+private:
+ sp<SurfaceControl> mParentSurfaceControl;
+};
+
class InputSurfacesTest : public ::testing::Test {
public:
InputSurfacesTest() {
@@ -289,15 +336,12 @@
return InputSurface::makeColorInputSurface(mComposerClient, width, height);
}
- void postBuffer(const sp<SurfaceControl> &layer) {
- // wait for previous transactions (such as setSize) to complete
- Transaction().apply(true);
- ANativeWindow_Buffer buffer = {};
- EXPECT_EQ(NO_ERROR, layer->getSurface()->lock(&buffer, nullptr));
- ASSERT_EQ(NO_ERROR, layer->getSurface()->unlockAndPost());
- // Request an empty transaction to get applied synchronously to ensure the buffer is
- // latched.
- Transaction().apply(true);
+ void postBuffer(const sp<SurfaceControl> &layer, int32_t w, int32_t h) {
+ int64_t usageFlags = BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
+ BufferUsage::COMPOSER_OVERLAY | BufferUsage::GPU_TEXTURE;
+ sp<GraphicBuffer> buffer =
+ new GraphicBuffer(w, h, PIXEL_FORMAT_RGBA_8888, 1, usageFlags, "test");
+ Transaction().setBuffer(layer, buffer).apply(true);
usleep(mBufferPostDelay);
}
@@ -474,8 +518,8 @@
// Original bug ref: b/120839715
TEST_F(InputSurfacesTest, input_ignores_buffer_layer_buffer) {
std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
- std::unique_ptr<InputSurface> bufferSurface =
- InputSurface::makeBufferInputSurface(mComposerClient, 100, 100);
+ std::unique_ptr<BlastInputSurface> bufferSurface =
+ BlastInputSurface::makeBlastInputSurface(mComposerClient, 100, 100);
bgSurface->showAt(10, 10);
bufferSurface->showAt(10, 10);
@@ -483,16 +527,16 @@
injectTap(11, 11);
bufferSurface->expectTap(1, 1);
- postBuffer(bufferSurface->mSurfaceControl);
+ postBuffer(bufferSurface->mSurfaceControl, 100, 100);
injectTap(11, 11);
bufferSurface->expectTap(1, 1);
}
TEST_F(InputSurfacesTest, input_ignores_buffer_layer_alpha) {
std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
- std::unique_ptr<InputSurface> bufferSurface =
- InputSurface::makeBufferInputSurface(mComposerClient, 100, 100);
- postBuffer(bufferSurface->mSurfaceControl);
+ std::unique_ptr<BlastInputSurface> bufferSurface =
+ BlastInputSurface::makeBlastInputSurface(mComposerClient, 100, 100);
+ postBuffer(bufferSurface->mSurfaceControl, 100, 100);
bgSurface->showAt(10, 10);
bufferSurface->showAt(10, 10);
@@ -720,8 +764,8 @@
TEST_F(InputSurfacesTest, touch_not_obscured_with_zero_sized_blast) {
std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
- std::unique_ptr<InputSurface> bufferSurface =
- InputSurface::makeBlastInputSurface(mComposerClient, 0, 0);
+ std::unique_ptr<BlastInputSurface> bufferSurface =
+ BlastInputSurface::makeBlastInputSurface(mComposerClient, 0, 0);
bufferSurface->mInputInfo.flags = InputWindowInfo::Flag::NOT_TOUCHABLE;
bufferSurface->mInputInfo.ownerUid = 22222;
diff --git a/libs/renderengine/skia/Cache.cpp b/libs/renderengine/skia/Cache.cpp
index 69c6a09..1db20c0 100644
--- a/libs/renderengine/skia/Cache.cpp
+++ b/libs/renderengine/skia/Cache.cpp
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
#include "Cache.h"
#include "AutoBackendTexture.h"
#include "SkiaRenderEngine.h"
@@ -28,9 +27,24 @@
namespace android::renderengine::skia {
+namespace {
// Warming shader cache, not framebuffer cache.
constexpr bool kUseFrameBufferCache = false;
+// clang-format off
+// Any non-identity matrix will do.
+const auto kScaleAndTranslate = mat4(0.7f, 0.f, 0.f, 0.f,
+ 0.f, 0.7f, 0.f, 0.f,
+ 0.f, 0.f, 1.f, 0.f,
+ 67.3f, 52.2f, 0.f, 1.f);
+// clang-format on
+// When choosing dataspaces below, whether the match the destination or not determined whether
+// a color correction effect is added to the shader. There may be other additional shader details
+// for particular color spaces.
+// TODO(b/184842383) figure out which color related shaders are necessary
+constexpr auto kDestDataSpace = ui::Dataspace::SRGB;
+} // namespace
+
static void drawShadowLayers(SkiaRenderEngine* renderengine, const DisplaySettings& display,
sp<GraphicBuffer> dstBuffer) {
// Somewhat arbitrary dimensions, but on screen and slightly shorter, based
@@ -51,23 +65,29 @@
.lightRadius = 2200.0f,
.length = 0.955342f,
},
+ // important that this matches dest so the general shadow fragment shader doesn't
+ // have color correction added, and important that it be srgb, so the *vertex* shader
+ // doesn't have color correction added.
+ .sourceDataspace = kDestDataSpace,
};
auto layers = std::vector<const LayerSettings*>{&layer};
- // The identity matrix will generate the fast shaders, and the second matrix
- // (based on one seen while going from dialer to the home screen) will
- // generate the slower (more general case) version. If we also need a
- // slow version without color correction, we should use this matrix with
- // display.outputDataspace set to SRGB.
- bool identity = true;
- for (const mat4 transform : { mat4(), mat4(0.728872f, 0.f, 0.f, 0.f,
- 0.f, 0.727627f, 0.f, 0.f,
- 0.f, 0.f, 1.f, 0.f,
- 167.355743f, 1852.257812f, 0.f, 1.f) }) {
- layer.geometry.positionTransform = transform;
+ // The identity matrix will generate the fast shader
+ renderengine->drawLayers(display, layers, dstBuffer, kUseFrameBufferCache, base::unique_fd(),
+ nullptr);
+ // This matrix, which has different scales for x and y, will
+ // generate the slower (more general case) version, which has variants for translucent
+ // casters and rounded rects.
+ // clang-format off
+ layer.geometry.positionTransform = mat4(0.7f, 0.f, 0.f, 0.f,
+ 0.f, 0.8f, 0.f, 0.f,
+ 0.f, 0.f, 1.f, 0.f,
+ 0.f, 0.f, 0.f, 1.f);
+ // clang-format on
+ for (auto translucent : {false, true}) {
+ layer.shadow.casterIsTranslucent = translucent;
renderengine->drawLayers(display, layers, dstBuffer, kUseFrameBufferCache,
base::unique_fd(), nullptr);
- identity = false;
}
}
@@ -89,33 +109,25 @@
}},
};
- // This matrix is based on actual data seen when opening the dialer.
- // translate and scale creates new shaders when combined with rounded corners
- // clang-format off
- auto scale_and_translate = mat4(.19f, .0f, .0f, .0f,
- .0f, .19f, .0f, .0f,
- .0f, .0f, 1.f, .0f,
- 169.f, 1527.f, .0f, 1.f);
- // clang-format on
+ auto threeCornerRadii = {0.0f, 0.05f, 50.f};
+ auto oneCornerRadius = {50.f};
// Test both drawRect and drawRRect
auto layers = std::vector<const LayerSettings*>{&layer};
- for (auto transform : {mat4(), scale_and_translate}) {
- layer.geometry.positionTransform = transform;
- // fractional corner radius creates a shader that is used during home button swipe
- for (float roundedCornersRadius : {0.0f, 0.05f, 500.f}) {
+ for (bool identity : {true, false}) {
+ layer.geometry.positionTransform = identity ? mat4() : kScaleAndTranslate;
+ // Corner radii less than 0.5 creates a special shader. This likely occurs in real usage
+ // due to animating corner radius.
+ // For the non-idenity matrix, only the large corner radius will create a new shader.
+ for (float roundedCornersRadius : identity ? threeCornerRadii : oneCornerRadius) {
// roundedCornersCrop is always set, but it is this radius that triggers the behavior
layer.geometry.roundedCornersRadius = roundedCornersRadius;
- // No need to check UNKNOWN, which is treated as SRGB.
- for (auto dataspace : {ui::Dataspace::SRGB, ui::Dataspace::DISPLAY_P3}) {
- layer.sourceDataspace = dataspace;
- for (bool isOpaque : {true, false}) {
- layer.source.buffer.isOpaque = isOpaque;
- for (auto alpha : {half(.23999f), half(1.0f)}) {
- layer.alpha = alpha;
- renderengine->drawLayers(display, layers, dstBuffer, kUseFrameBufferCache,
- base::unique_fd(), nullptr);
- }
+ for (bool isOpaque : {true, false}) {
+ layer.source.buffer.isOpaque = isOpaque;
+ for (auto alpha : {half(.23999f), half(1.0f)}) {
+ layer.alpha = alpha;
+ renderengine->drawLayers(display, layers, dstBuffer, kUseFrameBufferCache,
+ base::unique_fd(), nullptr);
}
}
}
@@ -139,11 +151,54 @@
};
auto layers = std::vector<const LayerSettings*>{&layer};
- renderengine->drawLayers(display, layers, dstBuffer, kUseFrameBufferCache, base::unique_fd(),
- nullptr);
+ for (auto transform : {mat4(), kScaleAndTranslate}) {
+ layer.geometry.positionTransform = transform;
+ for (float roundedCornersRadius : {0.0f, 0.05f, 50.f}) {
+ layer.geometry.roundedCornersRadius = roundedCornersRadius;
+ renderengine->drawLayers(display, layers, dstBuffer, kUseFrameBufferCache,
+ base::unique_fd(), nullptr);
+ }
+ }
}
+static void drawBlurLayers(SkiaRenderEngine* renderengine, const DisplaySettings& display,
+ sp<GraphicBuffer> dstBuffer) {
+ const Rect& displayRect = display.physicalDisplay;
+ FloatRect rect(0, 0, displayRect.width(), displayRect.height());
+ LayerSettings layer{
+ .geometry =
+ Geometry{
+ .boundaries = rect,
+ },
+ .alpha = 1,
+ };
+
+ auto layers = std::vector<const LayerSettings*>{&layer};
+ for (int radius : {9, 60}) {
+ layer.backgroundBlurRadius = radius;
+ renderengine->drawLayers(display, layers, dstBuffer, kUseFrameBufferCache,
+ base::unique_fd(), nullptr);
+ }
+}
+
+//
+// The collection of shaders cached here were found by using perfetto to record shader compiles
+// during actions that involve RenderEngine, logging the layer settings, and the shader code
+// and reproducing those settings here.
+//
+// It is helpful when debugging this to turn on
+// in SkGLRenderEngine.cpp:
+// kPrintLayerSettings = true
+// kFlushAfterEveryLayer = true
+// in external/skia/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
+// gPrintSKSL = true
+//
+// TODO(b/184631553) cache the shader involved in youtube pip return.
void Cache::primeShaderCache(SkiaRenderEngine* renderengine) {
+ const int previousCount = renderengine->reportShadersCompiled();
+ if (previousCount) {
+ ALOGD("%d Shaders already compiled before Cache::primeShaderCache ran\n", previousCount);
+ }
const nsecs_t timeBefore = systemTime();
// The dimensions should not matter, so long as we draw inside them.
const Rect displayRect(0, 0, 1080, 2340);
@@ -151,7 +206,7 @@
.physicalDisplay = displayRect,
.clip = displayRect,
.maxLuminance = 500,
- .outputDataspace = ui::Dataspace::DISPLAY_P3,
+ .outputDataspace = kDestDataSpace,
};
const int64_t usage = GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;
@@ -166,12 +221,30 @@
sp<GraphicBuffer> srcBuffer =
new GraphicBuffer(displayRect.width(), displayRect.height(), PIXEL_FORMAT_RGBA_8888, 1,
usage, "drawImageLayer_src");
+
drawSolidLayers(renderengine, display, dstBuffer);
drawShadowLayers(renderengine, display, srcBuffer);
+ drawBlurLayers(renderengine, display, dstBuffer);
+ // The majority of shaders are related to sampling images.
drawImageLayers(renderengine, display, dstBuffer, srcBuffer);
+
+ // should be the same as AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
+ const int64_t usageExternal = GRALLOC_USAGE_HW_TEXTURE;
+
+ sp<GraphicBuffer> externalBuffer =
+ new GraphicBuffer(displayRect.width(), displayRect.height(), PIXEL_FORMAT_RGBA_8888, 1,
+ usageExternal, "primeShaderCache_external");
+ // TODO(b/184665179) doubles number of image shader compilations, but only somewhere
+ // between 6 and 8 will occur in real uses.
+ drawImageLayers(renderengine, display, dstBuffer, externalBuffer);
+ renderengine->unbindExternalTextureBuffer(externalBuffer->getId());
+
+ renderengine->unbindExternalTextureBuffer(srcBuffer->getId());
+
const nsecs_t timeAfter = systemTime();
const float compileTimeMs = static_cast<float>(timeAfter - timeBefore) / 1.0E6;
- ALOGD("shader cache generated in %f ms\n", compileTimeMs);
+ const int shadersCompiled = renderengine->reportShadersCompiled();
+ ALOGD("Shader cache generated %d shaders in %f ms\n", shadersCompiled, compileTimeMs);
}
} // namespace android::renderengine::skia
diff --git a/libs/renderengine/skia/SkiaGLRenderEngine.cpp b/libs/renderengine/skia/SkiaGLRenderEngine.cpp
index 94a0dca..fb7e285 100644
--- a/libs/renderengine/skia/SkiaGLRenderEngine.cpp
+++ b/libs/renderengine/skia/SkiaGLRenderEngine.cpp
@@ -56,6 +56,12 @@
#include "skia/debug/SkiaCapture.h"
#include "system/graphics-base-v1.0.h"
+namespace {
+// Debugging settings
+static const bool kPrintLayerSettings = false;
+static const bool kFlushAfterEveryLayer = false;
+} // namespace
+
bool checkGlError(const char* op, int lineNumber);
namespace android {
@@ -285,6 +291,10 @@
numShaders, cached);
}
+int SkiaGLRenderEngine::reportShadersCompiled() {
+ return mSkSLCacheMonitor.shadersCachedSinceLastCall();
+}
+
SkiaGLRenderEngine::SkiaGLRenderEngine(const RenderEngineCreationArgs& args, EGLDisplay display,
EGLContext ctxt, EGLSurface placeholder,
EGLContext protectedContext, EGLSurface protectedPlaceholder)
@@ -735,6 +745,17 @@
for (const auto& layer : layers) {
ATRACE_NAME("DrawLayer");
+ if (kPrintLayerSettings) {
+ std::stringstream ls;
+ PrintTo(*layer, &ls);
+ auto debugs = ls.str();
+ int pos = 0;
+ while (pos < debugs.size()) {
+ ALOGD("cache_debug %s", debugs.substr(pos, 1000).c_str());
+ pos += 1000;
+ }
+ }
+
sk_sp<SkImage> blurInput;
if (blurCompositionLayer == layer) {
LOG_ALWAYS_FATAL_IF(activeSurface == dstSurface);
@@ -956,6 +977,10 @@
} else {
canvas->drawRect(bounds, paint);
}
+ if (kFlushAfterEveryLayer) {
+ ATRACE_NAME("flush surface");
+ activeSurface->flush();
+ }
}
surfaceAutoSaveRestore.restore();
mCapture->endCapture();
diff --git a/libs/renderengine/skia/SkiaGLRenderEngine.h b/libs/renderengine/skia/SkiaGLRenderEngine.h
index 25557f1..8e77c16 100644
--- a/libs/renderengine/skia/SkiaGLRenderEngine.h
+++ b/libs/renderengine/skia/SkiaGLRenderEngine.h
@@ -66,6 +66,7 @@
bool supportsBackgroundBlur() override { return mBlurFilter != nullptr; }
void assertShadersCompiled(int numShaders) override;
void onPrimaryDisplaySizeChanged(ui::Size size) override;
+ int reportShadersCompiled() override;
protected:
void dump(std::string& result) override;
diff --git a/libs/renderengine/skia/SkiaRenderEngine.h b/libs/renderengine/skia/SkiaRenderEngine.h
index 59d7e2f..51ef088 100644
--- a/libs/renderengine/skia/SkiaRenderEngine.h
+++ b/libs/renderengine/skia/SkiaRenderEngine.h
@@ -59,6 +59,7 @@
virtual bool cleanupPostRender(CleanupMode) override { return true; };
virtual int getContextPriority() override { return 0; }
virtual void assertShadersCompiled(int numShaders) {}
+ virtual int reportShadersCompiled() { return 0; }
};
} // namespace skia
diff --git a/libs/renderengine/skia/filters/BlurFilter.cpp b/libs/renderengine/skia/filters/BlurFilter.cpp
index ec710d9..6dd4161 100644
--- a/libs/renderengine/skia/filters/BlurFilter.cpp
+++ b/libs/renderengine/skia/filters/BlurFilter.cpp
@@ -34,7 +34,7 @@
BlurFilter::BlurFilter() {
SkString blurString(R"(
- in shader input;
+ uniform shader input;
uniform float2 in_blurOffset;
uniform float2 in_maxSizeXY;
@@ -60,8 +60,8 @@
mBlurEffect = std::move(blurEffect);
SkString mixString(R"(
- in shader blurredInput;
- in shader originalInput;
+ uniform shader blurredInput;
+ uniform shader originalInput;
uniform float mixFactor;
half4 main(float2 xy) {
diff --git a/libs/renderengine/skia/filters/LinearEffect.cpp b/libs/renderengine/skia/filters/LinearEffect.cpp
index 84af016..8e8e42e 100644
--- a/libs/renderengine/skia/filters/LinearEffect.cpp
+++ b/libs/renderengine/skia/filters/LinearEffect.cpp
@@ -390,7 +390,7 @@
static void generateEffectiveOOTF(bool undoPremultipliedAlpha, SkString& shader) {
shader.append(R"(
- in shader input;
+ uniform shader input;
half4 main(float2 xy) {
float4 c = float4(sample(input, xy));
)");
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 073455a..4e05847 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -2326,6 +2326,8 @@
if (dropWindow) {
vec2 local = dropWindow->getInfo()->transform.transform(x, y);
notifyDropWindowLocked(dropWindow->getToken(), local.x, local.y);
+ } else {
+ notifyDropWindowLocked(nullptr, 0, 0);
}
mDragState.reset();
}
@@ -2372,6 +2374,7 @@
} else if (maskedAction == AMOTION_EVENT_ACTION_UP) {
finishDragAndDrop(entry.displayId, x, y);
} else if (maskedAction == AMOTION_EVENT_ACTION_CANCEL) {
+ notifyDropWindowLocked(nullptr, 0, 0);
mDragState.reset();
}
}
diff --git a/services/inputflinger/reader/Android.bp b/services/inputflinger/reader/Android.bp
index 7468894..7db32e3 100644
--- a/services/inputflinger/reader/Android.bp
+++ b/services/inputflinger/reader/Android.bp
@@ -36,7 +36,7 @@
srcs: [
"EventHub.cpp",
"InputDevice.cpp",
- "controller/InputController.cpp",
+ "controller/PeripheralController.cpp",
"mapper/accumulator/CursorButtonAccumulator.cpp",
"mapper/accumulator/CursorScrollAccumulator.cpp",
"mapper/accumulator/SingleTouchMotionAccumulator.cpp",
diff --git a/services/inputflinger/reader/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp
index 045d24c..e3e6c12 100644
--- a/services/inputflinger/reader/EventHub.cpp
+++ b/services/inputflinger/reader/EventHub.cpp
@@ -363,7 +363,7 @@
virtualKeyMap(nullptr),
ffEffectPlaying(false),
ffEffectId(-1),
- miscDevice(nullptr),
+ associatedDevice(nullptr),
controllerNumber(0),
enabled(true),
isVirtual(fd < 0) {}
@@ -554,7 +554,7 @@
}
// Check the sysfs path for any input device batteries, returns true if battery found.
-bool EventHub::MiscDevice::configureBatteryLocked() {
+bool EventHub::AssociatedDevice::configureBatteryLocked() {
nextBatteryId = 0;
// Check if device has any battery.
const auto& paths = findSysfsNodes(sysfsRootPath, SysfsClass::POWER_SUPPLY);
@@ -580,7 +580,7 @@
}
// Check the sysfs path for any input device lights, returns true if lights found.
-bool EventHub::MiscDevice::configureLightsLocked() {
+bool EventHub::AssociatedDevice::configureLightsLocked() {
nextLightId = 0;
// Check if device has any lights.
const auto& paths = findSysfsNodes(sysfsRootPath, SysfsClass::LEDS);
@@ -988,14 +988,10 @@
int32_t deviceId) const {
static const std::unordered_map<int32_t, RawBatteryInfo> EMPTY_BATTERY_INFO = {};
Device* device = getDeviceLocked(deviceId);
- if (device == nullptr) {
+ if (device == nullptr || !device->associatedDevice) {
return EMPTY_BATTERY_INFO;
}
- auto it = mMiscDevices.find(device->identifier.descriptor);
- if (it == mMiscDevices.end()) {
- return EMPTY_BATTERY_INFO;
- }
- return it->second->batteryInfos;
+ return device->associatedDevice->batteryInfos;
}
const std::vector<int32_t> EventHub::getRawBatteryIds(int32_t deviceId) {
@@ -1028,14 +1024,10 @@
int32_t deviceId) const {
static const std::unordered_map<int32_t, RawLightInfo> EMPTY_LIGHT_INFO = {};
Device* device = getDeviceLocked(deviceId);
- if (device == nullptr) {
+ if (device == nullptr || !device->associatedDevice) {
return EMPTY_LIGHT_INFO;
}
- auto it = mMiscDevices.find(device->identifier.descriptor);
- if (it == mMiscDevices.end()) {
- return EMPTY_LIGHT_INFO;
- }
- return it->second->lightInfos;
+ return device->associatedDevice->lightInfos;
}
const std::vector<int32_t> EventHub::getRawLightIds(int32_t deviceId) {
@@ -1946,18 +1938,20 @@
// Check the sysfs root path
std::optional<std::filesystem::path> sysfsRootPath = getSysfsRootPath(devicePath.c_str());
if (sysfsRootPath.has_value()) {
- std::shared_ptr<MiscDevice> miscDevice;
- auto it = mMiscDevices.find(device->identifier.descriptor);
- if (it == mMiscDevices.end()) {
- miscDevice = std::make_shared<MiscDevice>(sysfsRootPath.value());
- } else {
- miscDevice = it->second;
+ std::shared_ptr<AssociatedDevice> associatedDevice;
+ for (const auto& [id, dev] : mDevices) {
+ if (device->identifier.descriptor == dev->identifier.descriptor &&
+ !dev->associatedDevice) {
+ associatedDevice = dev->associatedDevice;
+ }
}
- hasBattery = miscDevice->configureBatteryLocked();
- hasLights = miscDevice->configureLightsLocked();
+ if (!associatedDevice) {
+ associatedDevice = std::make_shared<AssociatedDevice>(sysfsRootPath.value());
+ }
+ hasBattery = associatedDevice->configureBatteryLocked();
+ hasLights = associatedDevice->configureLightsLocked();
- device->miscDevice = miscDevice;
- mMiscDevices.insert_or_assign(device->identifier.descriptor, std::move(miscDevice));
+ device->associatedDevice = associatedDevice;
}
// Figure out the kinds of events the device reports.
@@ -2329,12 +2323,6 @@
mClosingDevices.push_back(std::move(mDevices[device.id]));
mDevices.erase(device.id);
- // If all devices with the descriptor have been removed then the miscellaneous device should
- // be removed too.
- std::string descriptor = device.identifier.descriptor;
- if (getDeviceByDescriptorLocked(descriptor) == nullptr) {
- mMiscDevices.erase(descriptor);
- }
}
status_t EventHub::readNotifyLocked() {
diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp
index f935c36..8f75d22 100644
--- a/services/inputflinger/reader/InputDevice.cpp
+++ b/services/inputflinger/reader/InputDevice.cpp
@@ -23,11 +23,11 @@
#include "CursorInputMapper.h"
#include "ExternalStylusInputMapper.h"
-#include "InputController.h"
#include "InputReaderContext.h"
#include "JoystickInputMapper.h"
#include "KeyboardInputMapper.h"
#include "MultiTouchInputMapper.h"
+#include "PeripheralController.h"
#include "RotaryEncoderInputMapper.h"
#include "SensorInputMapper.h"
#include "SingleTouchInputMapper.h"
@@ -165,9 +165,9 @@
}
// Battery-like devices or light-containing devices.
- // InputController will be created with associated EventHub device.
+ // PeripheralController will be created with associated EventHub device.
if (classes.test(InputDeviceClass::BATTERY) || classes.test(InputDeviceClass::LIGHT)) {
- mController = std::make_unique<InputController>(*contextPtr);
+ mController = std::make_unique<PeripheralController>(*contextPtr);
}
// Keyboard-like devices.
@@ -504,8 +504,6 @@
for_each_mapper([when, readTime](InputMapper& mapper) { mapper.cancelTouch(when, readTime); });
}
-// TODO b/180733860 support multiple battery in API and remove this.
-constexpr int32_t DEFAULT_BATTERY_ID = 1;
std::optional<int32_t> InputDevice::getBatteryCapacity() {
return mController ? mController->getBatteryCapacity(DEFAULT_BATTERY_ID) : std::nullopt;
}
diff --git a/services/inputflinger/reader/controller/InputController.cpp b/services/inputflinger/reader/controller/PeripheralController.cpp
similarity index 90%
rename from services/inputflinger/reader/controller/InputController.cpp
rename to services/inputflinger/reader/controller/PeripheralController.cpp
index 45266fb..1a40d06 100644
--- a/services/inputflinger/reader/controller/InputController.cpp
+++ b/services/inputflinger/reader/controller/PeripheralController.cpp
@@ -19,7 +19,7 @@
#include "../Macros.h"
-#include "InputController.h"
+#include "PeripheralController.h"
#include "input/NamedEnum.h"
// Log detailed debug messages about input device lights.
@@ -52,15 +52,15 @@
* lights, getting and setting the lights brightness and color, by interacting with EventHub
* devices.
*/
-InputController::InputController(InputDeviceContext& deviceContext)
+PeripheralController::PeripheralController(InputDeviceContext& deviceContext)
: mDeviceContext(deviceContext) {
configureBattries();
configureLights();
}
-InputController::~InputController() {}
+PeripheralController::~PeripheralController() {}
-std::optional<std::int32_t> InputController::Light::getRawLightBrightness(int32_t rawLightId) {
+std::optional<std::int32_t> PeripheralController::Light::getRawLightBrightness(int32_t rawLightId) {
std::optional<RawLightInfo> rawInfoOpt = context.getRawLightInfo(rawLightId);
if (!rawInfoOpt.has_value()) {
return std::nullopt;
@@ -85,7 +85,7 @@
return brightness;
}
-void InputController::Light::setRawLightBrightness(int32_t rawLightId, int32_t brightness) {
+void PeripheralController::Light::setRawLightBrightness(int32_t rawLightId, int32_t brightness) {
std::optional<RawLightInfo> rawInfo = context.getRawLightInfo(rawLightId);
if (!rawInfo.has_value()) {
return;
@@ -104,14 +104,14 @@
context.setLightBrightness(rawLightId, brightness);
}
-bool InputController::SingleLight::setLightColor(int32_t color) {
+bool PeripheralController::SingleLight::setLightColor(int32_t color) {
int32_t brightness = getAlpha(color);
setRawLightBrightness(rawId, brightness);
return true;
}
-bool InputController::RgbLight::setLightColor(int32_t color) {
+bool PeripheralController::RgbLight::setLightColor(int32_t color) {
// Compose color value as per:
// https://developer.android.com/reference/android/graphics/Color?hl=en
// int color = (A & 0xff) << 24 | (R & 0xff) << 16 | (G & 0xff) << 8 | (B & 0xff);
@@ -137,7 +137,7 @@
return true;
}
-bool InputController::MultiColorLight::setLightColor(int32_t color) {
+bool PeripheralController::MultiColorLight::setLightColor(int32_t color) {
std::unordered_map<LightColor, int32_t> intensities;
intensities.emplace(LightColor::RED, getRed(color));
intensities.emplace(LightColor::GREEN, getGreen(color));
@@ -148,7 +148,7 @@
return true;
}
-std::optional<int32_t> InputController::SingleLight::getLightColor() {
+std::optional<int32_t> PeripheralController::SingleLight::getLightColor() {
std::optional<int32_t> brightness = getRawLightBrightness(rawId);
if (!brightness.has_value()) {
return std::nullopt;
@@ -157,7 +157,7 @@
return toArgb(brightness.value(), 0 /* red */, 0 /* green */, 0 /* blue */);
}
-std::optional<int32_t> InputController::RgbLight::getLightColor() {
+std::optional<int32_t> PeripheralController::RgbLight::getLightColor() {
// If the Alpha component is zero, then return color 0.
if (brightness == 0) {
return 0;
@@ -192,7 +192,7 @@
return toArgb(brightness, red, green, blue);
}
-std::optional<int32_t> InputController::MultiColorLight::getLightColor() {
+std::optional<int32_t> PeripheralController::MultiColorLight::getLightColor() {
auto ret = context.getLightIntensities(rawId);
if (!ret.has_value()) {
return std::nullopt;
@@ -210,7 +210,7 @@
return std::nullopt;
}
-bool InputController::PlayerIdLight::setLightPlayerId(int32_t playerId) {
+bool PeripheralController::PlayerIdLight::setLightPlayerId(int32_t playerId) {
if (rawLightIds.find(playerId) == rawLightIds.end()) {
return false;
}
@@ -224,7 +224,7 @@
return true;
}
-std::optional<int32_t> InputController::PlayerIdLight::getLightPlayerId() {
+std::optional<int32_t> PeripheralController::PlayerIdLight::getLightPlayerId() {
for (const auto& [id, rawId] : rawLightIds) {
std::optional<int32_t> brightness = getRawLightBrightness(rawId);
if (brightness.has_value() && brightness.value() > 0) {
@@ -234,11 +234,11 @@
return std::nullopt;
}
-void InputController::SingleLight::dump(std::string& dump) {
+void PeripheralController::SingleLight::dump(std::string& dump) {
dump += StringPrintf(INDENT4 "Color: 0x%x\n", getLightColor().value_or(0));
}
-void InputController::PlayerIdLight::dump(std::string& dump) {
+void PeripheralController::PlayerIdLight::dump(std::string& dump) {
dump += StringPrintf(INDENT4 "PlayerId: %d\n", getLightPlayerId().value_or(-1));
dump += StringPrintf(INDENT4 "Raw Player ID LEDs:");
for (const auto& [id, rawId] : rawLightIds) {
@@ -247,7 +247,7 @@
dump += "\n";
}
-void InputController::RgbLight::dump(std::string& dump) {
+void PeripheralController::RgbLight::dump(std::string& dump) {
dump += StringPrintf(INDENT4 "Color: 0x%x\n", getLightColor().value_or(0));
dump += StringPrintf(INDENT4 "Raw RGB LEDs: [%d, %d, %d] ", rawRgbIds.at(LightColor::RED),
rawRgbIds.at(LightColor::GREEN), rawRgbIds.at(LightColor::BLUE));
@@ -257,11 +257,11 @@
dump += "\n";
}
-void InputController::MultiColorLight::dump(std::string& dump) {
+void PeripheralController::MultiColorLight::dump(std::string& dump) {
dump += StringPrintf(INDENT4 "Color: 0x%x\n", getLightColor().value_or(0));
}
-void InputController::populateDeviceInfo(InputDeviceInfo* deviceInfo) {
+void PeripheralController::populateDeviceInfo(InputDeviceInfo* deviceInfo) {
// TODO: b/180733860 Remove this after enabling multi-battery
if (!mBatteries.empty()) {
deviceInfo->setHasBattery(true);
@@ -279,7 +279,7 @@
}
}
-void InputController::dump(std::string& dump) {
+void PeripheralController::dump(std::string& dump) {
dump += INDENT2 "Input Controller:\n";
if (!mLights.empty()) {
dump += INDENT3 "Lights:\n";
@@ -340,7 +340,7 @@
}
}
-void InputController::configureBattries() {
+void PeripheralController::configureBattries() {
// Check raw batteries
const std::vector<int32_t> rawBatteryIds = getDeviceContext().getRawBatteryIds();
@@ -355,7 +355,7 @@
}
}
-void InputController::configureLights() {
+void PeripheralController::configureLights() {
bool hasRedLed = false;
bool hasGreenLed = false;
bool hasBlueLed = false;
@@ -472,15 +472,15 @@
}
}
-std::optional<int32_t> InputController::getBatteryCapacity(int batteryId) {
+std::optional<int32_t> PeripheralController::getBatteryCapacity(int batteryId) {
return getDeviceContext().getBatteryCapacity(batteryId);
}
-std::optional<int32_t> InputController::getBatteryStatus(int batteryId) {
+std::optional<int32_t> PeripheralController::getBatteryStatus(int batteryId) {
return getDeviceContext().getBatteryStatus(batteryId);
}
-bool InputController::setLightColor(int32_t lightId, int32_t color) {
+bool PeripheralController::setLightColor(int32_t lightId, int32_t color) {
auto it = mLights.find(lightId);
if (it == mLights.end()) {
return false;
@@ -493,7 +493,7 @@
return light->setLightColor(color);
}
-std::optional<int32_t> InputController::getLightColor(int32_t lightId) {
+std::optional<int32_t> PeripheralController::getLightColor(int32_t lightId) {
auto it = mLights.find(lightId);
if (it == mLights.end()) {
return std::nullopt;
@@ -507,7 +507,7 @@
return color;
}
-bool InputController::setLightPlayerId(int32_t lightId, int32_t playerId) {
+bool PeripheralController::setLightPlayerId(int32_t lightId, int32_t playerId) {
auto it = mLights.find(lightId);
if (it == mLights.end()) {
return false;
@@ -516,7 +516,7 @@
return light->setLightPlayerId(playerId);
}
-std::optional<int32_t> InputController::getLightPlayerId(int32_t lightId) {
+std::optional<int32_t> PeripheralController::getLightPlayerId(int32_t lightId) {
auto it = mLights.find(lightId);
if (it == mLights.end()) {
return std::nullopt;
diff --git a/services/inputflinger/reader/controller/InputController.h b/services/inputflinger/reader/controller/PeripheralController.h
similarity index 96%
rename from services/inputflinger/reader/controller/InputController.h
rename to services/inputflinger/reader/controller/PeripheralController.h
index d4222e2..ff3607f 100644
--- a/services/inputflinger/reader/controller/InputController.h
+++ b/services/inputflinger/reader/controller/PeripheralController.h
@@ -17,19 +17,19 @@
#ifndef _UI_INPUTREADER_LIGHT_CONTROLLER_H
#define _UI_INPUTREADER_LIGHT_CONTROLLER_H
-#include "InputControllerInterface.h"
+#include "PeripheralControllerInterface.h"
namespace android {
-class InputController : public InputControllerInterface {
+class PeripheralController : public PeripheralControllerInterface {
// Refer to https://developer.android.com/reference/kotlin/android/graphics/Color
/* Number of colors : {red, green, blue} */
static constexpr size_t COLOR_NUM = 3;
static constexpr int32_t MAX_BRIGHTNESS = 0xff;
public:
- explicit InputController(InputDeviceContext& deviceContext);
- ~InputController() override;
+ explicit PeripheralController(InputDeviceContext& deviceContext);
+ ~PeripheralController() override;
void populateDeviceInfo(InputDeviceInfo* deviceInfo) override;
void dump(std::string& dump) override;
diff --git a/services/inputflinger/reader/controller/InputControllerInterface.h b/services/inputflinger/reader/controller/PeripheralControllerInterface.h
similarity index 87%
rename from services/inputflinger/reader/controller/InputControllerInterface.h
rename to services/inputflinger/reader/controller/PeripheralControllerInterface.h
index 504eded..7688a43 100644
--- a/services/inputflinger/reader/controller/InputControllerInterface.h
+++ b/services/inputflinger/reader/controller/PeripheralControllerInterface.h
@@ -24,14 +24,14 @@
namespace android {
-/* An input controller manages the miscellaneous devices associated with the input device,
+/* A peripheral controller manages the input device peripherals associated with the input device,
* like the sysfs based battery and light class devices.
*
*/
-class InputControllerInterface {
+class PeripheralControllerInterface {
public:
- InputControllerInterface() {}
- virtual ~InputControllerInterface() {}
+ PeripheralControllerInterface() {}
+ virtual ~PeripheralControllerInterface() {}
// Interface methods for Battery
virtual std::optional<int32_t> getBatteryCapacity(int32_t batteryId) = 0;
diff --git a/services/inputflinger/reader/include/EventHub.h b/services/inputflinger/reader/include/EventHub.h
index c970c8b..410a706 100644
--- a/services/inputflinger/reader/include/EventHub.h
+++ b/services/inputflinger/reader/include/EventHub.h
@@ -528,7 +528,7 @@
~EventHub() override;
private:
- struct MiscDevice {
+ struct AssociatedDevice {
// The device descriptor from evdev device the misc device associated with.
std::string descriptor;
// The sysfs root path of the misc device.
@@ -538,7 +538,7 @@
int32_t nextLightId;
std::unordered_map<int32_t, RawBatteryInfo> batteryInfos;
std::unordered_map<int32_t, RawLightInfo> lightInfos;
- explicit MiscDevice(std::filesystem::path sysfsRootPath)
+ explicit AssociatedDevice(std::filesystem::path sysfsRootPath)
: sysfsRootPath(sysfsRootPath), nextBatteryId(0), nextLightId(0) {}
bool configureBatteryLocked();
bool configureLightsLocked();
@@ -573,7 +573,9 @@
bool ffEffectPlaying;
int16_t ffEffectId; // initially -1
- std::shared_ptr<MiscDevice> miscDevice;
+ // A shared_ptr of a device associated with the input device.
+ // The input devices with same descriptor has the same associated device.
+ std::shared_ptr<AssociatedDevice> associatedDevice;
int32_t controllerNumber;
@@ -690,11 +692,6 @@
std::vector<std::unique_ptr<Device>> mOpeningDevices;
std::vector<std::unique_ptr<Device>> mClosingDevices;
- // Map from std::string descriptor, to a shared_ptr of a miscellaneous device associated with
- // the input device. The descriptor is the same from the EventHub device which it associates
- // with.
- std::unordered_map<std::string, std::shared_ptr<MiscDevice>> mMiscDevices;
-
bool mNeedToSendFinishedDeviceScan;
bool mNeedToReopenDevices;
bool mNeedToScanDevices;
diff --git a/services/inputflinger/reader/include/InputDevice.h b/services/inputflinger/reader/include/InputDevice.h
index 5d56f5a..b2b23e5 100644
--- a/services/inputflinger/reader/include/InputDevice.h
+++ b/services/inputflinger/reader/include/InputDevice.h
@@ -32,9 +32,11 @@
#include "InputReaderContext.h"
namespace android {
+// TODO b/180733860 support multiple battery in API and remove this.
+constexpr int32_t DEFAULT_BATTERY_ID = 1;
-class InputController;
-class InputControllerInterface;
+class PeripheralController;
+class PeripheralControllerInterface;
class InputDeviceContext;
class InputMapper;
@@ -162,7 +164,7 @@
// Map from EventHub ID to pair of device context and vector of mapper.
std::unordered_map<int32_t, DevicePair> mDevices;
// Misc devices controller for lights, battery, etc.
- std::unique_ptr<InputControllerInterface> mController;
+ std::unique_ptr<PeripheralControllerInterface> mController;
uint32_t mSources;
bool mIsExternal;
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp
index b62fce4..31d6900 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -268,7 +268,9 @@
void assertDropTargetEquals(const sp<IBinder>& targetToken) {
std::scoped_lock lock(mLock);
+ ASSERT_TRUE(mNotifyDropWindowWasCalled);
ASSERT_EQ(targetToken, mDropTargetWindowToken);
+ mNotifyDropWindowWasCalled = false;
}
private:
@@ -290,6 +292,7 @@
std::condition_variable mNotifyAnr;
sp<IBinder> mDropTargetWindowToken GUARDED_BY(mLock);
+ bool mNotifyDropWindowWasCalled GUARDED_BY(mLock) = false;
void notifyConfigurationChanged(nsecs_t when) override {
std::scoped_lock lock(mLock);
@@ -403,6 +406,7 @@
void notifyDropWindow(const sp<IBinder>& token, float x, float y) override {
std::scoped_lock lock(mLock);
+ mNotifyDropWindowWasCalled = true;
mDropTargetWindowToken = token;
}
@@ -4951,4 +4955,40 @@
mSecondWindow->assertNoEvents();
}
+TEST_F(InputDispatcherDragTests, DragAndDrop_InvalidWindow) {
+ performDrag();
+
+ // Set second window invisible.
+ mSecondWindow->setVisible(false);
+ mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mDragWindow, mWindow, mSecondWindow}}});
+
+ // 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->assertNoEvents();
+
+ // 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(nullptr);
+ mWindow->assertNoEvents();
+ mSecondWindow->assertNoEvents();
+}
+
} // namespace android::inputdispatcher
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index 3d99a6b..0e721e9 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -15,7 +15,6 @@
*/
#include <CursorInputMapper.h>
-#include <InputController.h>
#include <InputDevice.h>
#include <InputMapper.h>
#include <InputReader.h>
@@ -23,6 +22,7 @@
#include <InputReaderFactory.h>
#include <KeyboardInputMapper.h>
#include <MultiTouchInputMapper.h>
+#include <PeripheralController.h>
#include <SensorInputMapper.h>
#include <SingleTouchInputMapper.h>
#include <SwitchInputMapper.h>
@@ -2015,13 +2015,13 @@
ASSERT_EQ(mReader->getVibratorIds(deviceId).size(), 2U);
}
-// --- FakeInputController ---
+// --- FakePeripheralController ---
-class FakeInputController : public InputControllerInterface {
+class FakePeripheralController : public PeripheralControllerInterface {
public:
- FakeInputController(InputDeviceContext& deviceContext) : mDeviceContext(deviceContext) {}
+ FakePeripheralController(InputDeviceContext& deviceContext) : mDeviceContext(deviceContext) {}
- ~FakeInputController() override {}
+ ~FakePeripheralController() override {}
void populateDeviceInfo(InputDeviceInfo* deviceInfo) override {}
@@ -2064,7 +2064,8 @@
constexpr int32_t eventHubId = 1;
const char* DEVICE_LOCATION = "BLUETOOTH";
std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake", DEVICE_LOCATION);
- FakeInputController& controller = device->addController<FakeInputController>(eventHubId);
+ FakePeripheralController& controller =
+ device->addController<FakePeripheralController>(eventHubId);
mReader->pushNextDevice(device);
ASSERT_NO_FATAL_FAILURE(addDevice(eventHubId, "fake", deviceClass, nullptr));
@@ -2079,7 +2080,8 @@
constexpr int32_t eventHubId = 1;
const char* DEVICE_LOCATION = "BLUETOOTH";
std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake", DEVICE_LOCATION);
- FakeInputController& controller = device->addController<FakeInputController>(eventHubId);
+ FakePeripheralController& controller =
+ device->addController<FakePeripheralController>(eventHubId);
mReader->pushNextDevice(device);
ASSERT_NO_FATAL_FAILURE(addDevice(eventHubId, "fake", deviceClass, nullptr));
@@ -2094,7 +2096,8 @@
constexpr int32_t eventHubId = 1;
const char* DEVICE_LOCATION = "BLUETOOTH";
std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake", DEVICE_LOCATION);
- FakeInputController& controller = device->addController<FakeInputController>(eventHubId);
+ FakePeripheralController& controller =
+ device->addController<FakePeripheralController>(eventHubId);
mReader->pushNextDevice(device);
RawLightInfo info = {.id = 1,
.name = "Mono",
@@ -8598,9 +8601,9 @@
ASSERT_EQ(AINPUT_SOURCE_TOUCHPAD, mapper.getSources());
}
-// --- InputControllerTest ---
+// --- PeripheralControllerTest ---
-class InputControllerTest : public testing::Test {
+class PeripheralControllerTest : public testing::Test {
protected:
static const char* DEVICE_NAME;
static const char* DEVICE_LOCATION;
@@ -8663,41 +8666,43 @@
}
};
-const char* InputControllerTest::DEVICE_NAME = "device";
-const char* InputControllerTest::DEVICE_LOCATION = "BLUETOOTH";
-const int32_t InputControllerTest::DEVICE_ID = END_RESERVED_ID + 1000;
-const int32_t InputControllerTest::DEVICE_GENERATION = 2;
-const int32_t InputControllerTest::DEVICE_CONTROLLER_NUMBER = 0;
-const Flags<InputDeviceClass> InputControllerTest::DEVICE_CLASSES =
+const char* PeripheralControllerTest::DEVICE_NAME = "device";
+const char* PeripheralControllerTest::DEVICE_LOCATION = "BLUETOOTH";
+const int32_t PeripheralControllerTest::DEVICE_ID = END_RESERVED_ID + 1000;
+const int32_t PeripheralControllerTest::DEVICE_GENERATION = 2;
+const int32_t PeripheralControllerTest::DEVICE_CONTROLLER_NUMBER = 0;
+const Flags<InputDeviceClass> PeripheralControllerTest::DEVICE_CLASSES =
Flags<InputDeviceClass>(0); // not needed for current tests
-const int32_t InputControllerTest::EVENTHUB_ID = 1;
+const int32_t PeripheralControllerTest::EVENTHUB_ID = 1;
// --- BatteryControllerTest ---
-class BatteryControllerTest : public InputControllerTest {
+class BatteryControllerTest : public PeripheralControllerTest {
protected:
void SetUp() override {
- InputControllerTest::SetUp(DEVICE_CLASSES | InputDeviceClass::BATTERY);
+ PeripheralControllerTest::SetUp(DEVICE_CLASSES | InputDeviceClass::BATTERY);
}
};
TEST_F(BatteryControllerTest, GetBatteryCapacity) {
- InputController& controller = addControllerAndConfigure<InputController>();
+ PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
ASSERT_TRUE(controller.getBatteryCapacity(DEFAULT_BATTERY));
ASSERT_EQ(controller.getBatteryCapacity(DEFAULT_BATTERY).value_or(-1), BATTERY_CAPACITY);
}
TEST_F(BatteryControllerTest, GetBatteryStatus) {
- InputController& controller = addControllerAndConfigure<InputController>();
+ PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
ASSERT_TRUE(controller.getBatteryStatus(DEFAULT_BATTERY));
ASSERT_EQ(controller.getBatteryStatus(DEFAULT_BATTERY).value_or(-1), BATTERY_STATUS);
}
// --- LightControllerTest ---
-class LightControllerTest : public InputControllerTest {
+class LightControllerTest : public PeripheralControllerTest {
protected:
- void SetUp() override { InputControllerTest::SetUp(DEVICE_CLASSES | InputDeviceClass::LIGHT); }
+ void SetUp() override {
+ PeripheralControllerTest::SetUp(DEVICE_CLASSES | InputDeviceClass::LIGHT);
+ }
};
TEST_F(LightControllerTest, SingleLight) {
@@ -8708,7 +8713,7 @@
.path = ""};
mFakeEventHub->addRawLightInfo(infoSingle.id, std::move(infoSingle));
- InputController& controller = addControllerAndConfigure<InputController>();
+ PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
InputDeviceInfo info;
controller.populateDeviceInfo(&info);
const auto& ids = info.getLightIds();
@@ -8739,7 +8744,7 @@
mFakeEventHub->addRawLightInfo(infoGreen.id, std::move(infoGreen));
mFakeEventHub->addRawLightInfo(infoBlue.id, std::move(infoBlue));
- InputController& controller = addControllerAndConfigure<InputController>();
+ PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
InputDeviceInfo info;
controller.populateDeviceInfo(&info);
const auto& ids = info.getLightIds();
@@ -8761,7 +8766,7 @@
mFakeEventHub->addRawLightInfo(infoColor.id, std::move(infoColor));
- InputController& controller = addControllerAndConfigure<InputController>();
+ PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
InputDeviceInfo info;
controller.populateDeviceInfo(&info);
const auto& ids = info.getLightIds();
@@ -8798,7 +8803,7 @@
mFakeEventHub->addRawLightInfo(info3.id, std::move(info3));
mFakeEventHub->addRawLightInfo(info4.id, std::move(info4));
- InputController& controller = addControllerAndConfigure<InputController>();
+ PeripheralController& controller = addControllerAndConfigure<PeripheralController>();
InputDeviceInfo info;
controller.populateDeviceInfo(&info);
const auto& ids = info.getLightIds();
diff --git a/services/memtrackproxy/MemtrackProxy.cpp b/services/memtrackproxy/MemtrackProxy.cpp
index 8da6e89..4676167 100644
--- a/services/memtrackproxy/MemtrackProxy.cpp
+++ b/services/memtrackproxy/MemtrackProxy.cpp
@@ -122,11 +122,9 @@
_aidl_return->clear();
- if (memtrack_aidl_instance_ ||
- (memtrack_aidl_instance_ = MemtrackProxy::MemtrackAidlInstance())) {
+ if (memtrack_aidl_instance_) {
return memtrack_aidl_instance_->getMemory(pid, type, _aidl_return);
- } else if (memtrack_hidl_instance_ ||
- (memtrack_hidl_instance_ = MemtrackProxy::MemtrackHidlInstance())) {
+ } else if (memtrack_hidl_instance_) {
ndk::ScopedAStatus aidl_status;
Return<void> ret = memtrack_hidl_instance_->getMemory(
diff --git a/services/powermanager/Android.bp b/services/powermanager/Android.bp
index 1d3e5b5..d828aa9 100644
--- a/services/powermanager/Android.bp
+++ b/services/powermanager/Android.bp
@@ -38,7 +38,7 @@
"libutils",
"android.hardware.power@1.0",
"android.hardware.power@1.1",
- "android.hardware.power-V1-cpp",
+ "android.hardware.power-V2-cpp",
],
cflags: [
diff --git a/services/powermanager/PowerHalController.cpp b/services/powermanager/PowerHalController.cpp
index 178f545..8c225d5 100644
--- a/services/powermanager/PowerHalController.cpp
+++ b/services/powermanager/PowerHalController.cpp
@@ -18,6 +18,7 @@
#include <android/hardware/power/1.1/IPower.h>
#include <android/hardware/power/Boost.h>
#include <android/hardware/power/IPower.h>
+#include <android/hardware/power/IPowerHintSession.h>
#include <android/hardware/power/Mode.h>
#include <powermanager/PowerHalController.h>
#include <powermanager/PowerHalLoader.h>
@@ -73,9 +74,10 @@
// Check if a call to Power HAL function failed; if so, log the failure and
// invalidate the current Power HAL handle.
-HalResult PowerHalController::processHalResult(HalResult result, const char* fnName) {
- if (result == HalResult::FAILED) {
- ALOGE("%s() failed: power HAL service not available.", fnName);
+template <typename T>
+HalResult<T> PowerHalController::processHalResult(HalResult<T> result, const char* fnName) {
+ if (result.isFailed()) {
+ ALOGE("%s failed: %s", fnName, result.errorMessage());
std::lock_guard<std::mutex> lock(mConnectedHalMutex);
// Drop Power HAL handle. This will force future api calls to reconnect.
mConnectedHal = nullptr;
@@ -84,18 +86,31 @@
return result;
}
-HalResult PowerHalController::setBoost(Boost boost, int32_t durationMs) {
+HalResult<void> PowerHalController::setBoost(Boost boost, int32_t durationMs) {
std::shared_ptr<HalWrapper> handle = initHal();
auto result = handle->setBoost(boost, durationMs);
return processHalResult(result, "setBoost");
}
-HalResult PowerHalController::setMode(Mode mode, bool enabled) {
+HalResult<void> PowerHalController::setMode(Mode mode, bool enabled) {
std::shared_ptr<HalWrapper> handle = initHal();
auto result = handle->setMode(mode, enabled);
return processHalResult(result, "setMode");
}
+HalResult<sp<IPowerHintSession>> PowerHalController::createHintSession(
+ int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds, int64_t durationNanos) {
+ std::shared_ptr<HalWrapper> handle = initHal();
+ auto result = handle->createHintSession(tgid, uid, threadIds, durationNanos);
+ return processHalResult(result, "createHintSession");
+}
+
+HalResult<int64_t> PowerHalController::getHintSessionPreferredRate() {
+ std::shared_ptr<HalWrapper> handle = initHal();
+ auto result = handle->getHintSessionPreferredRate();
+ return processHalResult(result, "getHintSessionPreferredRate");
+}
+
} // namespace power
} // namespace android
diff --git a/services/powermanager/PowerHalWrapper.cpp b/services/powermanager/PowerHalWrapper.cpp
index 2f32827..d74bd23 100644
--- a/services/powermanager/PowerHalWrapper.cpp
+++ b/services/powermanager/PowerHalWrapper.cpp
@@ -16,11 +16,17 @@
#define LOG_TAG "HalWrapper"
#include <android/hardware/power/Boost.h>
+#include <android/hardware/power/IPowerHintSession.h>
#include <android/hardware/power/Mode.h>
#include <powermanager/PowerHalWrapper.h>
#include <utils/Log.h>
+#include <cinttypes>
+
using namespace android::hardware::power;
+namespace V1_0 = android::hardware::power::V1_0;
+namespace V1_1 = android::hardware::power::V1_1;
+namespace Aidl = android::hardware::power;
namespace android {
@@ -28,49 +34,88 @@
// -------------------------------------------------------------------------------------------------
-inline HalResult toHalResult(const binder::Status& result) {
+inline HalResult<void> toHalResult(const binder::Status& result) {
if (result.isOk()) {
- return HalResult::SUCCESSFUL;
+ return HalResult<void>::ok();
}
ALOGE("Power HAL request failed: %s", result.toString8().c_str());
- return HalResult::FAILED;
+ return HalResult<void>::fromStatus(result);
}
template <typename T>
-inline HalResult toHalResult(const hardware::Return<T>& result) {
- if (result.isOk()) {
- return HalResult::SUCCESSFUL;
- }
- ALOGE("Power HAL request failed: %s", result.description().c_str());
- return HalResult::FAILED;
+template <typename R>
+HalResult<T> HalResult<T>::fromReturn(hardware::Return<R>& ret, T data) {
+ return ret.isOk() ? HalResult<T>::ok(data) : HalResult<T>::failed(ret.description());
+}
+
+template <typename T>
+template <typename R>
+HalResult<T> HalResult<T>::fromReturn(hardware::Return<R>& ret, V1_0::Status status, T data) {
+ return ret.isOk() ? HalResult<T>::fromStatus(status, data)
+ : HalResult<T>::failed(ret.description());
}
// -------------------------------------------------------------------------------------------------
-HalResult EmptyHalWrapper::setBoost(Boost boost, int32_t durationMs) {
+HalResult<void> HalResult<void>::fromStatus(status_t status) {
+ if (status == android::OK) {
+ return HalResult<void>::ok();
+ }
+ return HalResult<void>::failed(statusToString(status));
+}
+
+HalResult<void> HalResult<void>::fromStatus(binder::Status status) {
+ if (status.exceptionCode() == binder::Status::EX_UNSUPPORTED_OPERATION) {
+ return HalResult<void>::unsupported();
+ }
+ if (status.isOk()) {
+ return HalResult<void>::ok();
+ }
+ return HalResult<void>::failed(std::string(status.toString8().c_str()));
+}
+
+template <typename R>
+HalResult<void> HalResult<void>::fromReturn(hardware::Return<R>& ret) {
+ return ret.isOk() ? HalResult<void>::ok() : HalResult<void>::failed(ret.description());
+}
+// -------------------------------------------------------------------------------------------------
+
+HalResult<void> EmptyHalWrapper::setBoost(Boost boost, int32_t durationMs) {
ALOGV("Skipped setBoost %s with duration %dms because Power HAL not available",
toString(boost).c_str(), durationMs);
- return HalResult::UNSUPPORTED;
+ return HalResult<void>::unsupported();
}
-HalResult EmptyHalWrapper::setMode(Mode mode, bool enabled) {
+HalResult<void> EmptyHalWrapper::setMode(Mode mode, bool enabled) {
ALOGV("Skipped setMode %s to %s because Power HAL not available", toString(mode).c_str(),
enabled ? "true" : "false");
- return HalResult::UNSUPPORTED;
+ return HalResult<void>::unsupported();
+}
+
+HalResult<sp<Aidl::IPowerHintSession>> EmptyHalWrapper::createHintSession(
+ int32_t, int32_t, const std::vector<int32_t>& threadIds, int64_t) {
+ ALOGV("Skipped createHintSession(task num=%zu) because Power HAL not available",
+ threadIds.size());
+ return HalResult<sp<Aidl::IPowerHintSession>>::unsupported();
+}
+
+HalResult<int64_t> EmptyHalWrapper::getHintSessionPreferredRate() {
+ ALOGV("Skipped getHintSessionPreferredRate because Power HAL not available");
+ return HalResult<int64_t>::unsupported();
}
// -------------------------------------------------------------------------------------------------
-HalResult HidlHalWrapperV1_0::setBoost(Boost boost, int32_t durationMs) {
+HalResult<void> HidlHalWrapperV1_0::setBoost(Boost boost, int32_t durationMs) {
if (boost == Boost::INTERACTION) {
return sendPowerHint(V1_0::PowerHint::INTERACTION, durationMs);
} else {
ALOGV("Skipped setBoost %s because Power HAL AIDL not available", toString(boost).c_str());
- return HalResult::UNSUPPORTED;
+ return HalResult<void>::unsupported();
}
}
-HalResult HidlHalWrapperV1_0::setMode(Mode mode, bool enabled) {
+HalResult<void> HidlHalWrapperV1_0::setMode(Mode mode, bool enabled) {
uint32_t data = enabled ? 1 : 0;
switch (mode) {
case Mode::LAUNCH:
@@ -88,38 +133,54 @@
default:
ALOGV("Skipped setMode %s because Power HAL AIDL not available",
toString(mode).c_str());
- return HalResult::UNSUPPORTED;
+ return HalResult<void>::unsupported();
}
}
-HalResult HidlHalWrapperV1_0::sendPowerHint(V1_0::PowerHint hintId, uint32_t data) {
- return toHalResult(mHandleV1_0->powerHint(hintId, data));
+HalResult<void> HidlHalWrapperV1_0::sendPowerHint(V1_0::PowerHint hintId, uint32_t data) {
+ auto ret = mHandleV1_0->powerHint(hintId, data);
+ return HalResult<void>::fromReturn(ret);
}
-HalResult HidlHalWrapperV1_0::setInteractive(bool enabled) {
- return toHalResult(mHandleV1_0->setInteractive(enabled));
+HalResult<void> HidlHalWrapperV1_0::setInteractive(bool enabled) {
+ auto ret = mHandleV1_0->setInteractive(enabled);
+ return HalResult<void>::fromReturn(ret);
}
-HalResult HidlHalWrapperV1_0::setFeature(V1_0::Feature feature, bool enabled) {
- return toHalResult(mHandleV1_0->setFeature(feature, enabled));
+HalResult<void> HidlHalWrapperV1_0::setFeature(V1_0::Feature feature, bool enabled) {
+ auto ret = mHandleV1_0->setFeature(feature, enabled);
+ return HalResult<void>::fromReturn(ret);
+}
+
+HalResult<sp<Aidl::IPowerHintSession>> HidlHalWrapperV1_0::createHintSession(
+ int32_t, int32_t, const std::vector<int32_t>& threadIds, int64_t) {
+ ALOGV("Skipped createHintSession(task num=%zu) because Power HAL not available",
+ threadIds.size());
+ return HalResult<sp<Aidl::IPowerHintSession>>::unsupported();
+}
+
+HalResult<int64_t> HidlHalWrapperV1_0::getHintSessionPreferredRate() {
+ ALOGV("Skipped getHintSessionPreferredRate because Power HAL not available");
+ return HalResult<int64_t>::unsupported();
}
// -------------------------------------------------------------------------------------------------
-HalResult HidlHalWrapperV1_1::sendPowerHint(V1_0::PowerHint hintId, uint32_t data) {
- return toHalResult(mHandleV1_1->powerHintAsync(hintId, data));
+HalResult<void> HidlHalWrapperV1_1::sendPowerHint(V1_0::PowerHint hintId, uint32_t data) {
+ auto ret = mHandleV1_1->powerHintAsync(hintId, data);
+ return HalResult<void>::fromReturn(ret);
}
// -------------------------------------------------------------------------------------------------
-HalResult AidlHalWrapper::setBoost(Boost boost, int32_t durationMs) {
+HalResult<void> AidlHalWrapper::setBoost(Boost boost, int32_t durationMs) {
std::unique_lock<std::mutex> lock(mBoostMutex);
size_t idx = static_cast<size_t>(boost);
// Quick return if boost is not supported by HAL
if (idx >= mBoostSupportedArray.size() || mBoostSupportedArray[idx] == HalSupport::OFF) {
ALOGV("Skipped setBoost %s because Power HAL doesn't support it", toString(boost).c_str());
- return HalResult::UNSUPPORTED;
+ return HalResult<void>::unsupported();
}
if (mBoostSupportedArray[idx] == HalSupport::UNKNOWN) {
@@ -128,14 +189,15 @@
if (!isSupportedRet.isOk()) {
ALOGE("Skipped setBoost %s because check support failed with: %s",
toString(boost).c_str(), isSupportedRet.toString8().c_str());
- return HalResult::FAILED;
+ // return HalResult::FAILED;
+ return HalResult<void>::fromStatus(isSupportedRet);
}
mBoostSupportedArray[idx] = isSupported ? HalSupport::ON : HalSupport::OFF;
if (!isSupported) {
ALOGV("Skipped setBoost %s because Power HAL doesn't support it",
toString(boost).c_str());
- return HalResult::UNSUPPORTED;
+ return HalResult<void>::unsupported();
}
}
lock.unlock();
@@ -143,30 +205,28 @@
return toHalResult(mHandle->setBoost(boost, durationMs));
}
-HalResult AidlHalWrapper::setMode(Mode mode, bool enabled) {
+HalResult<void> AidlHalWrapper::setMode(Mode mode, bool enabled) {
std::unique_lock<std::mutex> lock(mModeMutex);
size_t idx = static_cast<size_t>(mode);
// Quick return if mode is not supported by HAL
if (idx >= mModeSupportedArray.size() || mModeSupportedArray[idx] == HalSupport::OFF) {
ALOGV("Skipped setMode %s because Power HAL doesn't support it", toString(mode).c_str());
- return HalResult::UNSUPPORTED;
+ return HalResult<void>::unsupported();
}
if (mModeSupportedArray[idx] == HalSupport::UNKNOWN) {
bool isSupported = false;
auto isSupportedRet = mHandle->isModeSupported(mode, &isSupported);
if (!isSupportedRet.isOk()) {
- ALOGE("Skipped setMode %s because check support failed with: %s",
- toString(mode).c_str(), isSupportedRet.toString8().c_str());
- return HalResult::FAILED;
+ return HalResult<void>::failed(isSupportedRet.toString8().c_str());
}
mModeSupportedArray[idx] = isSupported ? HalSupport::ON : HalSupport::OFF;
if (!isSupported) {
ALOGV("Skipped setMode %s because Power HAL doesn't support it",
toString(mode).c_str());
- return HalResult::UNSUPPORTED;
+ return HalResult<void>::unsupported();
}
}
lock.unlock();
@@ -174,6 +234,20 @@
return toHalResult(mHandle->setMode(mode, enabled));
}
+HalResult<sp<Aidl::IPowerHintSession>> AidlHalWrapper::createHintSession(
+ int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds, int64_t durationNanos) {
+ sp<IPowerHintSession> appSession;
+ return HalResult<sp<Aidl::IPowerHintSession>>::
+ fromStatus(mHandle->createHintSession(tgid, uid, threadIds, durationNanos, &appSession),
+ appSession);
+}
+
+HalResult<int64_t> AidlHalWrapper::getHintSessionPreferredRate() {
+ int64_t rate = -1;
+ auto result = mHandle->getHintSessionPreferredRate(&rate);
+ return HalResult<int64_t>::fromStatus(result, rate);
+}
+
// -------------------------------------------------------------------------------------------------
} // namespace power
diff --git a/services/powermanager/benchmarks/Android.bp b/services/powermanager/benchmarks/Android.bp
index a489253..3997929 100644
--- a/services/powermanager/benchmarks/Android.bp
+++ b/services/powermanager/benchmarks/Android.bp
@@ -38,7 +38,7 @@
"libutils",
"android.hardware.power@1.0",
"android.hardware.power@1.1",
- "android.hardware.power-V1-cpp",
+ "android.hardware.power-V2-cpp",
],
static_libs: [
"libtestUtil",
diff --git a/services/powermanager/benchmarks/PowerHalAidlBenchmarks.cpp b/services/powermanager/benchmarks/PowerHalAidlBenchmarks.cpp
index 1004828..1100cad 100644
--- a/services/powermanager/benchmarks/PowerHalAidlBenchmarks.cpp
+++ b/services/powermanager/benchmarks/PowerHalAidlBenchmarks.cpp
@@ -18,7 +18,9 @@
#include <android/hardware/power/Boost.h>
#include <android/hardware/power/IPower.h>
+#include <android/hardware/power/IPowerHintSession.h>
#include <android/hardware/power/Mode.h>
+#include <android/hardware/power/WorkDuration.h>
#include <benchmark/benchmark.h>
#include <binder/IServiceManager.h>
#include <testUtil.h>
@@ -26,7 +28,9 @@
using android::hardware::power::Boost;
using android::hardware::power::IPower;
+using android::hardware::power::IPowerHintSession;
using android::hardware::power::Mode;
+using android::hardware::power::WorkDuration;
using std::chrono::microseconds;
using namespace android;
@@ -38,6 +42,21 @@
static constexpr int64_t FIRST_MODE = static_cast<int64_t>(Mode::DOUBLE_TAP_TO_WAKE);
static constexpr int64_t LAST_MODE = static_cast<int64_t>(Mode::CAMERA_STREAMING_HIGH);
+class DurationWrapper : public WorkDuration {
+public:
+ DurationWrapper(int64_t dur, int64_t time) {
+ durationNanos = dur;
+ timeStampNanos = time;
+ }
+};
+
+static const std::vector<WorkDuration> DURATIONS = {
+ DurationWrapper(1L, 1L),
+ DurationWrapper(1000L, 2L),
+ DurationWrapper(1000000L, 3L),
+ DurationWrapper(1000000000L, 4L),
+};
+
// Delay between oneway method calls to avoid overflowing the binder buffers.
static constexpr microseconds ONEWAY_API_DELAY = 100us;
@@ -68,6 +87,47 @@
}
}
+template <class R, class... Args0, class... Args1>
+static void runSessionBenchmark(benchmark::State& state, R (IPowerHintSession::*fn)(Args0...),
+ Args1&&... args1) {
+ sp<IPower> pwHal = waitForVintfService<IPower>();
+
+ if (pwHal == nullptr) {
+ ALOGI("Power HAL not available, skipping test...");
+ return;
+ }
+
+ // do not use tid from the benchmark process, use 1 for init
+ std::vector<int32_t> threadIds{1};
+ int64_t durationNanos = 16666666L;
+ sp<IPowerHintSession> hal;
+
+ auto status = pwHal->createHintSession(1, 0, threadIds, durationNanos, &hal);
+
+ if (hal == nullptr) {
+ ALOGI("Power HAL doesn't support session, skipping test...");
+ return;
+ }
+
+ binder::Status ret = (*hal.*fn)(std::forward<Args1>(args1)...);
+ if (ret.exceptionCode() == binder::Status::Exception::EX_UNSUPPORTED_OPERATION) {
+ ALOGI("Power HAL does not support this operation, skipping test...");
+ return;
+ }
+
+ while (state.KeepRunning()) {
+ ret = (*hal.*fn)(std::forward<Args1>(args1)...);
+ state.PauseTiming();
+ if (!ret.isOk()) state.SkipWithError(ret.toString8().c_str());
+ if (ONEWAY_API_DELAY > 0us) {
+ testDelaySpin(std::chrono::duration_cast<std::chrono::duration<float>>(ONEWAY_API_DELAY)
+ .count());
+ }
+ state.ResumeTiming();
+ }
+ hal->close();
+}
+
static void BM_PowerHalAidlBenchmarks_isBoostSupported(benchmark::State& state) {
bool isSupported;
Boost boost = static_cast<Boost>(state.range(0));
@@ -90,7 +150,53 @@
runBenchmark(state, ONEWAY_API_DELAY, &IPower::setMode, mode, false);
}
+static void BM_PowerHalAidlBenchmarks_createHintSession(benchmark::State& state) {
+ std::vector<int32_t> threadIds{static_cast<int32_t>(state.range(0))};
+ int64_t durationNanos = 16666666L;
+ int32_t tgid = 999;
+ int32_t uid = 1001;
+ sp<IPowerHintSession> appSession;
+ sp<IPower> hal = waitForVintfService<IPower>();
+
+ if (hal == nullptr) {
+ ALOGI("Power HAL not available, skipping test...");
+ return;
+ }
+
+ binder::Status ret = hal->createHintSession(tgid, uid, threadIds, durationNanos, &appSession);
+ if (ret.exceptionCode() == binder::Status::Exception::EX_UNSUPPORTED_OPERATION) {
+ ALOGI("Power HAL does not support this operation, skipping test...");
+ return;
+ }
+
+ while (state.KeepRunning()) {
+ ret = hal->createHintSession(tgid, uid, threadIds, durationNanos, &appSession);
+ state.PauseTiming();
+ if (!ret.isOk()) state.SkipWithError(ret.toString8().c_str());
+ appSession->close();
+ state.ResumeTiming();
+ }
+}
+
+static void BM_PowerHalAidlBenchmarks_getHintSessionPreferredRate(benchmark::State& state) {
+ int64_t rate;
+ runBenchmark(state, 0us, &IPower::getHintSessionPreferredRate, &rate);
+}
+
+static void BM_PowerHalAidlBenchmarks_updateTargetWorkDuration(benchmark::State& state) {
+ int64_t duration = 1000;
+ runSessionBenchmark(state, &IPowerHintSession::updateTargetWorkDuration, duration);
+}
+
+static void BM_PowerHalAidlBenchmarks_reportActualWorkDuration(benchmark::State& state) {
+ runSessionBenchmark(state, &IPowerHintSession::reportActualWorkDuration, DURATIONS);
+}
+
BENCHMARK(BM_PowerHalAidlBenchmarks_isBoostSupported)->DenseRange(FIRST_BOOST, LAST_BOOST, 1);
BENCHMARK(BM_PowerHalAidlBenchmarks_isModeSupported)->DenseRange(FIRST_MODE, LAST_MODE, 1);
BENCHMARK(BM_PowerHalAidlBenchmarks_setBoost)->DenseRange(FIRST_BOOST, LAST_BOOST, 1);
BENCHMARK(BM_PowerHalAidlBenchmarks_setMode)->DenseRange(FIRST_MODE, LAST_MODE, 1);
+BENCHMARK(BM_PowerHalAidlBenchmarks_createHintSession)->Arg(1);
+BENCHMARK(BM_PowerHalAidlBenchmarks_getHintSessionPreferredRate);
+BENCHMARK(BM_PowerHalAidlBenchmarks_updateTargetWorkDuration);
+BENCHMARK(BM_PowerHalAidlBenchmarks_reportActualWorkDuration);
diff --git a/services/powermanager/benchmarks/PowerHalControllerBenchmarks.cpp b/services/powermanager/benchmarks/PowerHalControllerBenchmarks.cpp
index 598080b..f8abc7a 100644
--- a/services/powermanager/benchmarks/PowerHalControllerBenchmarks.cpp
+++ b/services/powermanager/benchmarks/PowerHalControllerBenchmarks.cpp
@@ -40,29 +40,29 @@
// Delay between oneway method calls to avoid overflowing the binder buffers.
static constexpr std::chrono::microseconds ONEWAY_API_DELAY = 100us;
-template <class... Args0, class... Args1>
-static void runBenchmark(benchmark::State& state, HalResult (PowerHalController::*fn)(Args0...),
+template <typename T, class... Args0, class... Args1>
+static void runBenchmark(benchmark::State& state, HalResult<T> (PowerHalController::*fn)(Args0...),
Args1&&... args1) {
while (state.KeepRunning()) {
PowerHalController controller;
- HalResult ret = (controller.*fn)(std::forward<Args1>(args1)...);
+ HalResult<T> ret = (controller.*fn)(std::forward<Args1>(args1)...);
state.PauseTiming();
- if (ret == HalResult::FAILED) state.SkipWithError("Power HAL request failed");
+ if (ret.isFailed()) state.SkipWithError("Power HAL request failed");
state.ResumeTiming();
}
}
-template <class... Args0, class... Args1>
+template <typename T, class... Args0, class... Args1>
static void runCachedBenchmark(benchmark::State& state,
- HalResult (PowerHalController::*fn)(Args0...), Args1&&... args1) {
+ HalResult<T> (PowerHalController::*fn)(Args0...), Args1&&... args1) {
PowerHalController controller;
// First call out of test, to cache HAL service and isSupported result.
(controller.*fn)(std::forward<Args1>(args1)...);
while (state.KeepRunning()) {
- HalResult ret = (controller.*fn)(std::forward<Args1>(args1)...);
+ HalResult<T> ret = (controller.*fn)(std::forward<Args1>(args1)...);
state.PauseTiming();
- if (ret == HalResult::FAILED) {
+ if (ret.isFailed()) {
state.SkipWithError("Power HAL request failed");
}
testDelaySpin(
diff --git a/services/powermanager/tests/Android.bp b/services/powermanager/tests/Android.bp
index 69e4041..659b2d2 100644
--- a/services/powermanager/tests/Android.bp
+++ b/services/powermanager/tests/Android.bp
@@ -46,7 +46,7 @@
"libutils",
"android.hardware.power@1.0",
"android.hardware.power@1.1",
- "android.hardware.power-V1-cpp",
+ "android.hardware.power-V2-cpp",
],
static_libs: [
"libgmock",
diff --git a/services/powermanager/tests/PowerHalControllerTest.cpp b/services/powermanager/tests/PowerHalControllerTest.cpp
index 141b244..6cc7a6f 100644
--- a/services/powermanager/tests/PowerHalControllerTest.cpp
+++ b/services/powermanager/tests/PowerHalControllerTest.cpp
@@ -134,9 +134,9 @@
// Still works with EmptyPowerHalWrapper as fallback ignoring every api call
// and logging.
auto result = halController.setBoost(Boost::INTERACTION, 1000);
- ASSERT_EQ(HalResult::UNSUPPORTED, result);
+ ASSERT_TRUE(result.isUnsupported());
result = halController.setMode(Mode::LAUNCH, true);
- ASSERT_EQ(HalResult::UNSUPPORTED, result);
+ ASSERT_TRUE(result.isUnsupported());
// PowerHalConnector was called every time to attempt to reconnect with
// underlying service.
@@ -159,9 +159,9 @@
}
auto result = mHalController->setBoost(Boost::INTERACTION, 100);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
result = mHalController->setMode(Mode::LAUNCH, true);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
// PowerHalConnector was called only once and never reset.
powerHalConnectCount = mHalConnector->getConnectCount();
@@ -182,13 +182,13 @@
EXPECT_CALL(*mMockHal.get(), powerHint(_, _)).Times(Exactly(4));
auto result = mHalController->setBoost(Boost::INTERACTION, 1000);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
result = mHalController->setMode(Mode::LAUNCH, true);
- ASSERT_EQ(HalResult::FAILED, result);
+ ASSERT_TRUE(result.isFailed());
result = mHalController->setMode(Mode::VR, false);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
result = mHalController->setMode(Mode::LOW_POWER, true);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
// PowerHalConnector was called only twice: on first api call and after failed
// call.
@@ -204,9 +204,9 @@
EXPECT_EQ(powerHalConnectCount, 0);
auto result = mHalController->setBoost(Boost::CAMERA_LAUNCH, 1000);
- ASSERT_EQ(HalResult::UNSUPPORTED, result);
+ ASSERT_TRUE(result.isUnsupported());
result = mHalController->setMode(Mode::CAMERA_STREAMING_HIGH, true);
- ASSERT_EQ(HalResult::UNSUPPORTED, result);
+ ASSERT_TRUE(result.isUnsupported());
// PowerHalConnector was called only once and never reset.
powerHalConnectCount = mHalConnector->getConnectCount();
@@ -225,7 +225,7 @@
for (int i = 0; i < 10; i++) {
threads.push_back(std::thread([&]() {
auto result = mHalController->setBoost(Boost::INTERACTION, 1000);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
}));
}
std::for_each(threads.begin(), threads.end(), [](std::thread& t) { t.join(); });
@@ -253,19 +253,19 @@
for (int i = 0; i < 10; i++) {
threads.push_back(std::thread([&]() {
auto result = mHalController->setBoost(Boost::INTERACTION, 1000);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
}));
threads.push_back(std::thread([&]() {
auto result = mHalController->setMode(Mode::LAUNCH, true);
- ASSERT_EQ(HalResult::FAILED, result);
+ ASSERT_TRUE(result.isFailed());
}));
threads.push_back(std::thread([&]() {
auto result = mHalController->setMode(Mode::LOW_POWER, false);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
}));
threads.push_back(std::thread([&]() {
auto result = mHalController->setMode(Mode::VR, true);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
}));
}
std::for_each(threads.begin(), threads.end(), [](std::thread& t) { t.join(); });
diff --git a/services/powermanager/tests/PowerHalWrapperAidlTest.cpp b/services/powermanager/tests/PowerHalWrapperAidlTest.cpp
index a765659..d890f5c 100644
--- a/services/powermanager/tests/PowerHalWrapperAidlTest.cpp
+++ b/services/powermanager/tests/PowerHalWrapperAidlTest.cpp
@@ -17,6 +17,7 @@
#define LOG_TAG "PowerHalWrapperAidlTest"
#include <android/hardware/power/Boost.h>
+#include <android/hardware/power/IPowerHintSession.h>
#include <android/hardware/power/Mode.h>
#include <binder/IServiceManager.h>
#include <gmock/gmock.h>
@@ -24,11 +25,13 @@
#include <powermanager/PowerHalWrapper.h>
#include <utils/Log.h>
+#include <unistd.h>
#include <thread>
using android::binder::Status;
using android::hardware::power::Boost;
using android::hardware::power::IPower;
+using android::hardware::power::IPowerHintSession;
using android::hardware::power::Mode;
using namespace android;
@@ -44,6 +47,11 @@
MOCK_METHOD(Status, setBoost, (Boost boost, int32_t durationMs), (override));
MOCK_METHOD(Status, isModeSupported, (Mode mode, bool* ret), (override));
MOCK_METHOD(Status, setMode, (Mode mode, bool enabled), (override));
+ MOCK_METHOD(Status, createHintSession,
+ (int32_t tgid, int32_t uid, const std::vector<int32_t>& threadIds,
+ int64_t durationNanos, sp<IPowerHintSession>* session),
+ (override));
+ MOCK_METHOD(Status, getHintSessionPreferredRate, (int64_t * rate), (override));
MOCK_METHOD(int32_t, getInterfaceVersion, (), (override));
MOCK_METHOD(std::string, getInterfaceHash, (), (override));
MOCK_METHOD(IBinder*, onAsBinder, (), (override));
@@ -65,7 +73,7 @@
void PowerHalWrapperAidlTest::SetUp() {
mMockHal = new StrictMock<MockIPower>();
mWrapper = std::make_unique<AidlHalWrapper>(mMockHal);
- ASSERT_NE(mWrapper, nullptr);
+ ASSERT_NE(nullptr, mWrapper);
}
// -------------------------------------------------------------------------------------------------
@@ -81,7 +89,7 @@
}
auto result = mWrapper->setBoost(Boost::DISPLAY_UPDATE_IMMINENT, 100);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
}
TEST_F(PowerHalWrapperAidlTest, TestSetBoostFailed) {
@@ -99,9 +107,9 @@
}
auto result = mWrapper->setBoost(Boost::INTERACTION, 100);
- ASSERT_EQ(HalResult::FAILED, result);
+ ASSERT_TRUE(result.isFailed());
result = mWrapper->setBoost(Boost::DISPLAY_UPDATE_IMMINENT, 1000);
- ASSERT_EQ(HalResult::FAILED, result);
+ ASSERT_TRUE(result.isFailed());
}
TEST_F(PowerHalWrapperAidlTest, TestSetBoostUnsupported) {
@@ -110,9 +118,9 @@
.WillRepeatedly(DoAll(SetArgPointee<1>(false), Return(Status())));
auto result = mWrapper->setBoost(Boost::INTERACTION, 1000);
- ASSERT_EQ(HalResult::UNSUPPORTED, result);
+ ASSERT_TRUE(result.isUnsupported());
result = mWrapper->setBoost(Boost::CAMERA_SHOT, 10);
- ASSERT_EQ(HalResult::UNSUPPORTED, result);
+ ASSERT_TRUE(result.isUnsupported());
}
TEST_F(PowerHalWrapperAidlTest, TestSetBoostMultiThreadCheckSupportedOnlyOnce) {
@@ -128,7 +136,7 @@
for (int i = 0; i < 10; i++) {
threads.push_back(std::thread([&]() {
auto result = mWrapper->setBoost(Boost::INTERACTION, 100);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
}));
}
std::for_each(threads.begin(), threads.end(), [](std::thread& t) { t.join(); });
@@ -145,7 +153,7 @@
}
auto result = mWrapper->setMode(Mode::DISPLAY_INACTIVE, false);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
}
TEST_F(PowerHalWrapperAidlTest, TestSetModeFailed) {
@@ -163,9 +171,9 @@
}
auto result = mWrapper->setMode(Mode::LAUNCH, true);
- ASSERT_EQ(HalResult::FAILED, result);
+ ASSERT_TRUE(result.isFailed());
result = mWrapper->setMode(Mode::DISPLAY_INACTIVE, false);
- ASSERT_EQ(HalResult::FAILED, result);
+ ASSERT_TRUE(result.isFailed());
}
TEST_F(PowerHalWrapperAidlTest, TestSetModeUnsupported) {
@@ -174,9 +182,9 @@
.WillRepeatedly(DoAll(SetArgPointee<1>(false), Return(Status())));
auto result = mWrapper->setMode(Mode::LAUNCH, true);
- ASSERT_EQ(HalResult::UNSUPPORTED, result);
+ ASSERT_TRUE(result.isUnsupported());
result = mWrapper->setMode(Mode::CAMERA_STREAMING_HIGH, true);
- ASSERT_EQ(HalResult::UNSUPPORTED, result);
+ ASSERT_TRUE(result.isUnsupported());
}
TEST_F(PowerHalWrapperAidlTest, TestSetModeMultiThreadCheckSupportedOnlyOnce) {
@@ -192,8 +200,41 @@
for (int i = 0; i < 10; i++) {
threads.push_back(std::thread([&]() {
auto result = mWrapper->setMode(Mode::LAUNCH, false);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
}));
}
std::for_each(threads.begin(), threads.end(), [](std::thread& t) { t.join(); });
}
+
+TEST_F(PowerHalWrapperAidlTest, TestCreateHintSessionSuccessful) {
+ std::vector<int> threadIds{gettid()};
+ int32_t tgid = 999;
+ int32_t uid = 1001;
+ int64_t durationNanos = 16666666L;
+ EXPECT_CALL(*mMockHal.get(),
+ createHintSession(Eq(tgid), Eq(uid), Eq(threadIds), Eq(durationNanos), _))
+ .Times(Exactly(1));
+ auto result = mWrapper->createHintSession(tgid, uid, threadIds, durationNanos);
+ ASSERT_TRUE(result.isOk());
+}
+
+TEST_F(PowerHalWrapperAidlTest, TestCreateHintSessionFailed) {
+ int32_t tgid = 999;
+ int32_t uid = 1001;
+ std::vector<int> threadIds{};
+ int64_t durationNanos = 16666666L;
+ EXPECT_CALL(*mMockHal.get(),
+ createHintSession(Eq(tgid), Eq(uid), Eq(threadIds), Eq(durationNanos), _))
+ .Times(Exactly(1))
+ .WillRepeatedly(Return(Status::fromExceptionCode(Status::EX_ILLEGAL_ARGUMENT)));
+ auto result = mWrapper->createHintSession(tgid, uid, threadIds, durationNanos);
+ ASSERT_TRUE(result.isFailed());
+}
+
+TEST_F(PowerHalWrapperAidlTest, TestGetHintSessionPreferredRate) {
+ EXPECT_CALL(*mMockHal.get(), getHintSessionPreferredRate(_)).Times(Exactly(1));
+ auto result = mWrapper->getHintSessionPreferredRate();
+ ASSERT_TRUE(result.isOk());
+ int64_t rate = result.value();
+ ASSERT_GE(0, rate);
+}
diff --git a/services/powermanager/tests/PowerHalWrapperHidlV1_0Test.cpp b/services/powermanager/tests/PowerHalWrapperHidlV1_0Test.cpp
index 6693d0b..b54762c 100644
--- a/services/powermanager/tests/PowerHalWrapperHidlV1_0Test.cpp
+++ b/services/powermanager/tests/PowerHalWrapperHidlV1_0Test.cpp
@@ -72,7 +72,7 @@
EXPECT_CALL(*mMockHal.get(), powerHint(Eq(PowerHint::INTERACTION), Eq(1000))).Times(Exactly(1));
auto result = mWrapper->setBoost(Boost::INTERACTION, 1000);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
}
TEST_F(PowerHalWrapperHidlV1_0Test, TestSetBoostFailed) {
@@ -83,12 +83,12 @@
});
auto result = mWrapper->setBoost(Boost::INTERACTION, 1000);
- ASSERT_EQ(HalResult::FAILED, result);
+ ASSERT_TRUE(result.isFailed());
}
TEST_F(PowerHalWrapperHidlV1_0Test, TestSetBoostUnsupported) {
auto result = mWrapper->setBoost(Boost::CAMERA_LAUNCH, 10);
- ASSERT_EQ(HalResult::UNSUPPORTED, result);
+ ASSERT_TRUE(result.isUnsupported());
}
TEST_F(PowerHalWrapperHidlV1_0Test, TestSetModeSuccessful) {
@@ -106,17 +106,17 @@
}
auto result = mWrapper->setMode(Mode::LAUNCH, true);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
result = mWrapper->setMode(Mode::LOW_POWER, false);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
result = mWrapper->setMode(Mode::SUSTAINED_PERFORMANCE, true);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
result = mWrapper->setMode(Mode::VR, false);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
result = mWrapper->setMode(Mode::INTERACTIVE, true);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
result = mWrapper->setMode(Mode::DOUBLE_TAP_TO_WAKE, false);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
}
TEST_F(PowerHalWrapperHidlV1_0Test, TestSetModeFailed) {
@@ -127,10 +127,10 @@
});
auto result = mWrapper->setMode(Mode::LAUNCH, 1);
- ASSERT_EQ(HalResult::FAILED, result);
+ ASSERT_TRUE(result.isFailed());
}
TEST_F(PowerHalWrapperHidlV1_0Test, TestSetModeIgnored) {
auto result = mWrapper->setMode(Mode::CAMERA_STREAMING_HIGH, true);
- ASSERT_EQ(HalResult::UNSUPPORTED, result);
+ ASSERT_TRUE(result.isUnsupported());
}
diff --git a/services/powermanager/tests/PowerHalWrapperHidlV1_1Test.cpp b/services/powermanager/tests/PowerHalWrapperHidlV1_1Test.cpp
index 55bbd6d..d30e8d2 100644
--- a/services/powermanager/tests/PowerHalWrapperHidlV1_1Test.cpp
+++ b/services/powermanager/tests/PowerHalWrapperHidlV1_1Test.cpp
@@ -89,7 +89,7 @@
.Times(Exactly(1));
auto result = mWrapper->setBoost(Boost::INTERACTION, 1000);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
}
TEST_F(PowerHalWrapperHidlV1_1Test, TestSetBoostFailed) {
@@ -100,12 +100,12 @@
});
auto result = mWrapper->setBoost(Boost::INTERACTION, 1000);
- ASSERT_EQ(HalResult::FAILED, result);
+ ASSERT_TRUE(result.isFailed());
}
TEST_F(PowerHalWrapperHidlV1_1Test, TestSetBoostUnsupported) {
auto result = mWrapper->setBoost(Boost::CAMERA_LAUNCH, 10);
- ASSERT_EQ(HalResult::UNSUPPORTED, result);
+ ASSERT_TRUE(result.isUnsupported());
}
TEST_F(PowerHalWrapperHidlV1_1Test, TestSetMode) {
@@ -127,17 +127,17 @@
}
auto result = mWrapper->setMode(Mode::LAUNCH, true);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
result = mWrapper->setMode(Mode::LOW_POWER, false);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
result = mWrapper->setMode(Mode::SUSTAINED_PERFORMANCE, true);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
result = mWrapper->setMode(Mode::VR, false);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
result = mWrapper->setMode(Mode::INTERACTIVE, true);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
result = mWrapper->setMode(Mode::DOUBLE_TAP_TO_WAKE, false);
- ASSERT_EQ(HalResult::SUCCESSFUL, result);
+ ASSERT_TRUE(result.isOk());
}
TEST_F(PowerHalWrapperHidlV1_1Test, TestSetModeFailed) {
@@ -148,10 +148,10 @@
});
auto result = mWrapper->setMode(Mode::LAUNCH, 1);
- ASSERT_EQ(HalResult::FAILED, result);
+ ASSERT_TRUE(result.isFailed());
}
TEST_F(PowerHalWrapperHidlV1_1Test, TestSetModeIgnored) {
auto result = mWrapper->setMode(Mode::CAMERA_STREAMING_HIGH, true);
- ASSERT_EQ(HalResult::UNSUPPORTED, result);
+ ASSERT_TRUE(result.isUnsupported());
}
diff --git a/services/sensorservice/Android.bp b/services/sensorservice/Android.bp
index c769e97..9aecaff 100644
--- a/services/sensorservice/Android.bp
+++ b/services/sensorservice/Android.bp
@@ -49,6 +49,7 @@
"libhardware_legacy",
"libutils",
"liblog",
+ "libactivitymanager_aidl",
"libbatterystats_aidl",
"libbinder",
"libsensor",
@@ -69,8 +70,11 @@
generated_headers: ["framework-cppstream-protos"],
- // our public headers depend on libsensor and libsensorprivacy
- export_shared_lib_headers: ["libsensor", "libsensorprivacy"],
+ export_shared_lib_headers: [
+ "libactivitymanager_aidl",
+ "libsensor",
+ "libsensorprivacy",
+ ],
}
cc_binary {
diff --git a/services/surfaceflinger/Android.bp b/services/surfaceflinger/Android.bp
index b976eb5..9885352 100644
--- a/services/surfaceflinger/Android.bp
+++ b/services/surfaceflinger/Android.bp
@@ -60,7 +60,6 @@
"libnativewindow",
"libprocessgroup",
"libprotobuf-cpp-lite",
- "libstatslog",
"libsync",
"libtimestats",
"libui",
diff --git a/services/surfaceflinger/BufferStateLayer.cpp b/services/surfaceflinger/BufferStateLayer.cpp
index 09e3cd9..ed826a0 100644
--- a/services/surfaceflinger/BufferStateLayer.cpp
+++ b/services/surfaceflinger/BufferStateLayer.cpp
@@ -903,6 +903,36 @@
}
}
+/*
+ * We don't want to send the layer's transform to input, but rather the
+ * parent's transform. This is because BufferStateLayer's transform is
+ * information about how the buffer is placed on screen. The parent's
+ * transform makes more sense to send since it's information about how the
+ * layer is placed on screen. This transform is used by input to determine
+ * how to go from screen space back to window space.
+ */
+ui::Transform BufferStateLayer::getInputTransform() const {
+ sp<Layer> parent = mDrawingParent.promote();
+ if (parent == nullptr) {
+ return ui::Transform();
+ }
+
+ return parent->getTransform();
+}
+
+/**
+ * Similar to getInputTransform, we need to update the bounds to include the transform.
+ * This is because bounds for BSL doesn't include buffer transform, where the input assumes
+ * that's already included.
+ */
+Rect BufferStateLayer::getInputBounds() const {
+ Rect bufferBounds = getCroppedBufferSize(getDrawingState());
+ if (mDrawingState.transform.getType() == ui::Transform::IDENTITY || !bufferBounds.isValid()) {
+ return bufferBounds;
+ }
+ return mDrawingState.transform.transform(bufferBounds);
+}
+
} // namespace android
// TODO(b/129481165): remove the #pragma below and fix conversion issues
diff --git a/services/surfaceflinger/BufferStateLayer.h b/services/surfaceflinger/BufferStateLayer.h
index af2819e..8ce3e1f 100644
--- a/services/surfaceflinger/BufferStateLayer.h
+++ b/services/surfaceflinger/BufferStateLayer.h
@@ -118,6 +118,8 @@
void gatherBufferInfo() override;
uint64_t getHeadFrameNumber(nsecs_t expectedPresentTime) const;
void onSurfaceFrameCreated(const std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame);
+ ui::Transform getInputTransform() const override;
+ Rect getInputBounds() const override;
private:
friend class SlotGenerationTest;
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayerCompositionState.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayerCompositionState.h
index 4c065ec..48a54d6 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayerCompositionState.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputLayerCompositionState.h
@@ -115,6 +115,9 @@
// The buffer cache for this layer. This is used to lower the
// cost of sending reused buffers to the HWC.
HwcBufferCache hwcBufferCache;
+
+ // Set to true when overridden info has been sent to HW composer
+ bool stateOverridden = false;
};
// The HWC state is optional, and is only set up if there is any potential
diff --git a/services/surfaceflinger/CompositionEngine/src/Output.cpp b/services/surfaceflinger/CompositionEngine/src/Output.cpp
index aed3be9..3ac5433 100644
--- a/services/surfaceflinger/CompositionEngine/src/Output.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/Output.cpp
@@ -722,10 +722,7 @@
previousOverride = layer->getState().overrideInfo.buffer;
}
- // TODO(b/181172795): We now update geometry for all flattened layers. We should update it
- // only when the geometry actually changes
- const bool includeGeometry = refreshArgs.updatingGeometryThisFrame ||
- layer->getState().overrideInfo.buffer != nullptr || skipLayer;
+ const bool includeGeometry = refreshArgs.updatingGeometryThisFrame;
layer->writeStateToHWC(includeGeometry, skipLayer);
}
}
@@ -1104,6 +1101,7 @@
Region stubRegion;
bool disableBlurs = false;
+ sp<GraphicBuffer> previousOverrideBuffer = nullptr;
for (auto* layer : getOutputLayersOrderedByZ()) {
const auto& layerState = layer->getState();
@@ -1153,8 +1151,14 @@
std::vector<LayerFE::LayerSettings> results;
if (layer->getState().overrideInfo.buffer != nullptr) {
- results = layer->getOverrideCompositionList();
- ALOGV("Replacing [%s] with override in RE", layer->getLayerFE().getDebugName());
+ if (layer->getState().overrideInfo.buffer != previousOverrideBuffer) {
+ results = layer->getOverrideCompositionList();
+ previousOverrideBuffer = layer->getState().overrideInfo.buffer;
+ ALOGV("Replacing [%s] with override in RE", layer->getLayerFE().getDebugName());
+ } else {
+ ALOGV("Skipping redundant override buffer for [%s] in RE",
+ layer->getLayerFE().getDebugName());
+ }
} else {
results = layerFE.prepareClientCompositionList(targetSettings);
if (realContentIsVisible && !results.empty()) {
diff --git a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
index 3f36a8f..f640f85 100644
--- a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
@@ -333,7 +333,11 @@
auto requestedCompositionType = outputIndependentState->compositionType;
- if (includeGeometry) {
+ // TODO(b/181172795): We now update geometry for all flattened layers. We should update it
+ // only when the geometry actually changes
+ const bool isOverridden = state.overrideInfo.buffer != nullptr;
+ const bool prevOverridden = state.hwc->stateOverridden;
+ if (isOverridden || prevOverridden || skipLayer || includeGeometry) {
writeOutputDependentGeometryStateToHWC(hwcLayer.get(), requestedCompositionType);
writeOutputIndependentGeometryStateToHWC(hwcLayer.get(), *outputIndependentState,
skipLayer);
@@ -346,6 +350,8 @@
// Always set the layer color after setting the composition type.
writeSolidColorStateToHWC(hwcLayer.get(), *outputIndependentState);
+
+ editState().hwc->stateOverridden = isOverridden;
}
void OutputLayer::writeOutputDependentGeometryStateToHWC(
diff --git a/services/surfaceflinger/DisplayHardware/ComposerHal.cpp b/services/surfaceflinger/DisplayHardware/ComposerHal.cpp
index 1bf43da..fd70988 100644
--- a/services/surfaceflinger/DisplayHardware/ComposerHal.cpp
+++ b/services/surfaceflinger/DisplayHardware/ComposerHal.cpp
@@ -20,11 +20,7 @@
#undef LOG_TAG
#define LOG_TAG "HwcComposer"
-
-#include <log/log.h>
-
-#include <algorithm>
-#include <cinttypes>
+#define ATRACE_TAG ATRACE_TAG_GRAPHICS
#include "ComposerHal.h"
@@ -32,6 +28,11 @@
#include <gui/BufferQueue.h>
#include <hidl/HidlTransportSupport.h>
#include <hidl/HidlTransportUtils.h>
+#include <log/log.h>
+#include <utils/Trace.h>
+
+#include <algorithm>
+#include <cinttypes>
namespace android {
@@ -492,6 +493,7 @@
Error Composer::presentDisplay(Display display, int* outPresentFence)
{
+ ATRACE_NAME("HwcPresentDisplay");
mWriter.selectDisplay(display);
mWriter.presentDisplay();
@@ -586,6 +588,7 @@
Error Composer::validateDisplay(Display display, uint32_t* outNumTypes,
uint32_t* outNumRequests)
{
+ ATRACE_NAME("HwcValidateDisplay");
mWriter.selectDisplay(display);
mWriter.validateDisplay();
@@ -601,13 +604,14 @@
Error Composer::presentOrValidateDisplay(Display display, uint32_t* outNumTypes,
uint32_t* outNumRequests, int* outPresentFence, uint32_t* state) {
- mWriter.selectDisplay(display);
- mWriter.presentOrvalidateDisplay();
+ ATRACE_NAME("HwcPresentOrValidateDisplay");
+ mWriter.selectDisplay(display);
+ mWriter.presentOrvalidateDisplay();
- Error error = execute();
- if (error != Error::NONE) {
- return error;
- }
+ Error error = execute();
+ if (error != Error::NONE) {
+ return error;
+ }
mReader.takePresentOrValidateStage(display, state);
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 2fcd821..6038658 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -1949,32 +1949,6 @@
return removeResult;
}
-void Layer::reparentChildren(const sp<Layer>& newParent) {
- for (const sp<Layer>& child : mCurrentChildren) {
- newParent->addChild(child);
- }
- mCurrentChildren.clear();
- updateTreeHasFrameRateVote();
-}
-
-bool Layer::reparentChildren(const sp<IBinder>& newParentHandle) {
- sp<Handle> handle = nullptr;
- sp<Layer> newParent = nullptr;
- if (newParentHandle == nullptr) {
- return false;
- }
- handle = static_cast<Handle*>(newParentHandle.get());
- newParent = handle->owner.promote();
- if (newParent == nullptr) {
- ALOGE("Unable to promote Layer handle");
- return false;
- }
-
- reparentChildren(newParent);
-
- return true;
-}
-
void Layer::setChildrenDrawingParent(const sp<Layer>& newParent) {
for (const sp<Layer>& child : mDrawingChildren) {
child->mDrawingParent = newParent;
@@ -2535,14 +2509,22 @@
return mRemovedFromCurrentState;
}
+ui::Transform Layer::getInputTransform() const {
+ return getTransform();
+}
+
+Rect Layer::getInputBounds() const {
+ return getCroppedBufferSize(getDrawingState());
+}
+
void Layer::fillInputFrameInfo(InputWindowInfo& info, const ui::Transform& toPhysicalDisplay) {
// 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
- ? getBufferSize(getDrawingState())
+ ? getInputBounds()
: info.touchableRegion.getBounds();
if (!layerBounds.isValid()) {
- layerBounds = getCroppedBufferSize(getDrawingState());
+ layerBounds = getInputBounds();
}
if (!layerBounds.isValid()) {
@@ -2555,7 +2537,7 @@
return;
}
- ui::Transform layerToDisplay = getTransform();
+ ui::Transform layerToDisplay = getInputTransform();
// Transform that takes window coordinates to unrotated display coordinates
ui::Transform t = toPhysicalDisplay * layerToDisplay;
int32_t xSurfaceInset = info.surfaceInset;
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 4a105eb..5528a81 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -637,8 +637,6 @@
void onLayerDisplayed(const sp<Fence>& releaseFence) override;
const char* getDebugName() const override;
- bool reparentChildren(const sp<IBinder>& newParentHandle);
- void reparentChildren(const sp<Layer>& newParent);
bool setShadowRadius(float shadowRadius);
// Before color management is introduced, contents on Android have to be
@@ -1025,6 +1023,9 @@
compositionengine::OutputLayer* findOutputLayerForDisplay(const DisplayDevice*) const;
bool usingRelativeZ(LayerVector::StateSet) const;
+ virtual ui::Transform getInputTransform() const;
+ virtual Rect getInputBounds() const;
+
// SyncPoints which will be signaled when the correct frame is at the head
// of the queue and dropped after the frame has been latched. Protected by
// mLocalSyncPointMutex.
diff --git a/services/surfaceflinger/Scheduler/LayerInfo.cpp b/services/surfaceflinger/Scheduler/LayerInfo.cpp
index 3630ad8..989bf4e 100644
--- a/services/surfaceflinger/Scheduler/LayerInfo.cpp
+++ b/services/surfaceflinger/Scheduler/LayerInfo.cpp
@@ -235,6 +235,8 @@
if (!isFrequent(now)) {
ALOGV("%s is infrequent", mName.c_str());
mLastRefreshRate.animatingOrInfrequent = true;
+ // Infrequent layers vote for mininal refresh rate for
+ // battery saving purposes and also to prevent b/135718869.
return {LayerHistory::LayerVoteType::Min, Fps(0.0f)};
}
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 1b7158b..02579c6 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -1814,10 +1814,6 @@
if (frameMissed) {
mFrameMissedCount++;
mTimeStats->incrementMissedFrames();
- if (mMissedFrameJankCount == 0) {
- mMissedFrameJankStart = systemTime();
- }
- mMissedFrameJankCount++;
}
if (hwcFrameMissed) {
@@ -1849,37 +1845,6 @@
}
}
- // Our jank window is always at least 100ms since we missed a
- // frame...
- static constexpr nsecs_t kMinJankyDuration =
- std::chrono::duration_cast<std::chrono::nanoseconds>(100ms).count();
- // ...but if it's larger than 1s then we missed the trace cutoff.
- static constexpr nsecs_t kMaxJankyDuration =
- std::chrono::duration_cast<std::chrono::nanoseconds>(1s).count();
- nsecs_t jankDurationToUpload = -1;
- // If we're in a user build then don't push any atoms
- if (!mIsUserBuild && mMissedFrameJankCount > 0) {
- const auto display = ON_MAIN_THREAD(getDefaultDisplayDeviceLocked());
- // Only report jank when the display is on, as displays in DOZE
- // power mode may operate at a different frame rate than is
- // reported in their config, which causes noticeable (but less
- // severe) jank.
- if (display && display->getPowerMode() == hal::PowerMode::ON) {
- const nsecs_t currentTime = systemTime();
- const nsecs_t jankDuration = currentTime - mMissedFrameJankStart;
- if (jankDuration > kMinJankyDuration && jankDuration < kMaxJankyDuration) {
- jankDurationToUpload = jankDuration;
- }
-
- // We either reported a jank event or we missed the trace
- // window, so clear counters here.
- if (jankDuration > kMinJankyDuration) {
- mMissedFrameJankCount = 0;
- mMissedFrameJankStart = 0;
- }
- }
- }
-
if (mTracingEnabledChanged) {
mTracingEnabled = mTracing.isEnabled();
mTracingEnabledChanged = false;
@@ -1926,7 +1891,6 @@
refreshNeeded |= mRepaintEverything;
if (refreshNeeded && CC_LIKELY(mBootStage != BootStage::BOOTLOADER)) {
- mLastJankDuration = jankDurationToUpload;
// Signal a refresh if a transaction modified the window state,
// a new buffer was latched, or if HWC has requested a full
// repaint
@@ -2302,14 +2266,6 @@
const size_t appConnections = mScheduler->getEventThreadConnectionCount(mAppConnectionHandle);
mTimeStats->recordDisplayEventConnectionCount(sfConnections + appConnections);
- if (mLastJankDuration > 0) {
- ATRACE_NAME("Jank detected");
- const int32_t jankyDurationMillis = mLastJankDuration / (1000 * 1000);
- android::util::stats_write(android::util::DISPLAY_JANK_REPORTED, jankyDurationMillis,
- mMissedFrameJankCount);
- mLastJankDuration = -1;
- }
-
if (isDisplayConnected && !display->isPoweredOn()) {
return;
}
@@ -3361,8 +3317,12 @@
}
}
- if (const auto display = getDefaultDisplayDeviceLocked()) {
- lbc->updateTransformHint(display->getTransformHint());
+ if (const auto token = getInternalDisplayTokenLocked()) {
+ const ssize_t index = mCurrentState.displays.indexOfKey(token);
+ if (index >= 0) {
+ const DisplayDeviceState& state = mCurrentState.displays.valueAt(index);
+ lbc->updateTransformHint(ui::Transform::toRotationFlags(state.orientation));
+ }
}
if (outTransformHint) {
*outTransformHint = lbc->getTransformHint();
@@ -4019,11 +3979,6 @@
// We don't trigger a traversal here because if no other state is
// changed, we don't want this to cause any more work
}
- if (what & layer_state_t::eReparentChildren) {
- if (layer->reparentChildren(s.reparentSurfaceControl->getHandle())) {
- flags |= eTransactionNeeded|eTraversalNeeded;
- }
- }
if (what & layer_state_t::eTransformChanged) {
if (layer->setTransform(s.transform)) flags |= eTraversalNeeded;
}
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index c7601fa..b3da61e 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -1387,13 +1387,6 @@
// be any issues with a raw pointer referencing an invalid object.
std::unordered_set<Layer*> mOffscreenLayers;
- // Fields tracking the current jank event: when it started and how many
- // janky frames there are.
- nsecs_t mMissedFrameJankStart = 0;
- int32_t mMissedFrameJankCount = 0;
- // Positive if jank should be uploaded in postComposition
- nsecs_t mLastJankDuration = -1;
-
int mFrameRateFlexibilityTokenCount = 0;
sp<IBinder> mDebugFrameRateFlexibilityToken;
diff --git a/services/surfaceflinger/SurfaceInterceptor.cpp b/services/surfaceflinger/SurfaceInterceptor.cpp
index 8a3be9f..b49562a 100644
--- a/services/surfaceflinger/SurfaceInterceptor.cpp
+++ b/services/surfaceflinger/SurfaceInterceptor.cpp
@@ -401,13 +401,6 @@
overrideChange->set_parent_id(parentId);
}
-void SurfaceInterceptor::addReparentChildrenLocked(Transaction* transaction, int32_t layerId,
- int32_t parentId) {
- SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
- ReparentChildrenChange* overrideChange(change->mutable_reparent_children());
- overrideChange->set_parent_id(parentId);
-}
-
void SurfaceInterceptor::addRelativeParentLocked(Transaction* transaction, int32_t layerId,
int32_t parentId, int z) {
SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
@@ -486,10 +479,6 @@
: nullptr;
addReparentLocked(transaction, layerId, getLayerIdFromHandle(parentHandle));
}
- if (state.what & layer_state_t::eReparentChildren) {
- addReparentChildrenLocked(transaction, layerId,
- getLayerIdFromHandle(state.reparentSurfaceControl->getHandle()));
- }
if (state.what & layer_state_t::eRelativeLayerChanged) {
addRelativeParentLocked(transaction, layerId,
getLayerIdFromHandle(
diff --git a/services/surfaceflinger/SurfaceInterceptor.h b/services/surfaceflinger/SurfaceInterceptor.h
index 3e27e83..d2cbf40 100644
--- a/services/surfaceflinger/SurfaceInterceptor.h
+++ b/services/surfaceflinger/SurfaceInterceptor.h
@@ -176,7 +176,6 @@
uint32_t transactionFlags, int originPid, int originUid,
uint64_t transactionId);
void addReparentLocked(Transaction* transaction, int32_t layerId, int32_t parentId);
- void addReparentChildrenLocked(Transaction* transaction, int32_t layerId, int32_t parentId);
void addRelativeParentLocked(Transaction* transaction, int32_t layerId, int32_t parentId,
int z);
void addShadowRadiusLocked(Transaction* transaction, int32_t layerId, float shadowRadius);
diff --git a/services/surfaceflinger/main_surfaceflinger.cpp b/services/surfaceflinger/main_surfaceflinger.cpp
index 2b8424c..9686523 100644
--- a/services/surfaceflinger/main_surfaceflinger.cpp
+++ b/services/surfaceflinger/main_surfaceflinger.cpp
@@ -89,13 +89,47 @@
// binder threads to 4.
ProcessState::self()->setThreadPoolMaxThreadCount(4);
+ // The binder threadpool we start will inherit sched policy and priority
+ // of (this) creating thread. We want the binder thread pool to have
+ // SCHED_FIFO policy and priority 1 (lowest RT priority)
+ // Once the pool is created we reset this thread's priority back to
+ // original.
+ int newPriority = 0;
+ int origPolicy = sched_getscheduler(0);
+ struct sched_param origSchedParam;
+
+ int errorInPriorityModification = sched_getparam(0, &origSchedParam);
+ if (errorInPriorityModification == 0) {
+ int policy = SCHED_FIFO;
+ newPriority = sched_get_priority_min(policy);
+
+ struct sched_param param;
+ param.sched_priority = newPriority;
+
+ errorInPriorityModification = sched_setscheduler(0, policy, ¶m);
+ }
+
// start the thread pool
sp<ProcessState> ps(ProcessState::self());
ps->startThreadPool();
+ // Reset current thread's policy and priority
+ if (errorInPriorityModification == 0) {
+ errorInPriorityModification = sched_setscheduler(0, origPolicy, &origSchedParam);
+ } else {
+ ALOGE("Failed to set SurfaceFlinger binder threadpool priority to SCHED_FIFO");
+ }
+
// instantiate surfaceflinger
sp<SurfaceFlinger> flinger = surfaceflinger::createSurfaceFlinger();
+ // Set the minimum policy of surfaceflinger node to be SCHED_FIFO.
+ // So any thread with policy/priority lower than {SCHED_FIFO, 1}, will run
+ // at least with SCHED_FIFO policy and priority 1.
+ if (errorInPriorityModification == 0) {
+ flinger->setMinSchedulerPolicy(SCHED_FIFO, newPriority);
+ }
+
setpriority(PRIO_PROCESS, 0, PRIORITY_URGENT_DISPLAY);
set_sched_policy(0, SP_FOREGROUND);
diff --git a/services/surfaceflinger/tests/LayerUpdate_test.cpp b/services/surfaceflinger/tests/LayerUpdate_test.cpp
index e5c2ec8..39d9206 100644
--- a/services/surfaceflinger/tests/LayerUpdate_test.cpp
+++ b/services/surfaceflinger/tests/LayerUpdate_test.cpp
@@ -462,38 +462,6 @@
}
}
-TEST_F(ChildLayerTest, ReparentChildren) {
- asTransaction([&](Transaction& t) {
- t.show(mChild);
- t.setPosition(mChild, 10, 10);
- t.setPosition(mFGSurfaceControl, 64, 64);
- });
-
- {
- mCapture = screenshot();
- // Top left of foreground must now be visible
- mCapture->expectFGColor(64, 64);
- // But 10 pixels in we should see the child surface
- mCapture->expectChildColor(74, 74);
- // And 10 more pixels we should be back to the foreground surface
- mCapture->expectFGColor(84, 84);
- }
-
- asTransaction(
- [&](Transaction& t) { t.reparentChildren(mFGSurfaceControl, mBGSurfaceControl); });
-
- {
- mCapture = screenshot();
- mCapture->expectFGColor(64, 64);
- // In reparenting we should have exposed the entire foreground surface.
- mCapture->expectFGColor(74, 74);
- // And the child layer should now begin at 10, 10 (since the BG
- // layer is at (0, 0)).
- mCapture->expectBGColor(9, 9);
- mCapture->expectChildColor(10, 10);
- }
-}
-
TEST_F(ChildLayerTest, ChildrenSurviveParentDestruction) {
sp<SurfaceControl> mGrandChild =
createSurface(mClient, "Grand Child", 10, 10, PIXEL_FORMAT_RGBA_8888, 0, mChild.get());
@@ -539,7 +507,7 @@
asTransaction([&](Transaction& t) {
t.reparent(mChild, nullptr);
- t.reparentChildren(mChild, mFGSurfaceControl);
+ t.reparent(mGrandChild, mFGSurfaceControl);
});
{
diff --git a/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp b/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp
index d9cab42..09bd775 100644
--- a/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp
+++ b/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp
@@ -194,7 +194,6 @@
bool deferredTransactionUpdateFound(const SurfaceChange& change, bool foundDeferred);
bool reparentUpdateFound(const SurfaceChange& change, bool found);
bool relativeParentUpdateFound(const SurfaceChange& change, bool found);
- bool reparentChildrenUpdateFound(const SurfaceChange& change, bool found);
bool shadowRadiusUpdateFound(const SurfaceChange& change, bool found);
bool surfaceUpdateFound(const Trace& trace, SurfaceChange::SurfaceChangeCase changeCase);
@@ -231,7 +230,6 @@
void deferredTransactionUpdate(Transaction&);
void reparentUpdate(Transaction&);
void relativeParentUpdate(Transaction&);
- void reparentChildrenUpdate(Transaction&);
void shadowRadiusUpdate(Transaction&);
void surfaceCreation(Transaction&);
void displayCreation(Transaction&);
@@ -410,10 +408,6 @@
t.setRelativeLayer(mBGSurfaceControl, mFGSurfaceControl, RELATIVE_Z);
}
-void SurfaceInterceptorTest::reparentChildrenUpdate(Transaction& t) {
- t.reparentChildren(mBGSurfaceControl, mFGSurfaceControl);
-}
-
void SurfaceInterceptorTest::shadowRadiusUpdate(Transaction& t) {
t.setShadowRadius(mBGSurfaceControl, SHADOW_RADIUS_UPDATE);
}
@@ -445,7 +439,6 @@
runInTransaction(&SurfaceInterceptorTest::secureFlagUpdate);
runInTransaction(&SurfaceInterceptorTest::deferredTransactionUpdate);
runInTransaction(&SurfaceInterceptorTest::reparentUpdate);
- runInTransaction(&SurfaceInterceptorTest::reparentChildrenUpdate);
runInTransaction(&SurfaceInterceptorTest::relativeParentUpdate);
runInTransaction(&SurfaceInterceptorTest::shadowRadiusUpdate);
}
@@ -660,16 +653,6 @@
return found;
}
-bool SurfaceInterceptorTest::reparentChildrenUpdateFound(const SurfaceChange& change, bool found) {
- bool hasId(change.reparent_children().parent_id() == mFGLayerId);
- if (hasId && !found) {
- found = true;
- } else if (hasId && found) {
- []() { FAIL(); }();
- }
- return found;
-}
-
bool SurfaceInterceptorTest::shadowRadiusUpdateFound(const SurfaceChange& change,
bool foundShadowRadius) {
bool hasShadowRadius(change.shadow_radius().radius() == SHADOW_RADIUS_UPDATE);
@@ -738,9 +721,6 @@
case SurfaceChange::SurfaceChangeCase::kReparent:
foundUpdate = reparentUpdateFound(change, foundUpdate);
break;
- case SurfaceChange::SurfaceChangeCase::kReparentChildren:
- foundUpdate = reparentChildrenUpdateFound(change, foundUpdate);
- break;
case SurfaceChange::SurfaceChangeCase::kRelativeParent:
foundUpdate = relativeParentUpdateFound(change, foundUpdate);
break;
@@ -771,7 +751,6 @@
ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kSecureFlag));
ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kDeferredTransaction));
ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kReparent));
- ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kReparentChildren));
ASSERT_TRUE(surfaceUpdateFound(trace, SurfaceChange::SurfaceChangeCase::kRelativeParent));
}
@@ -937,11 +916,6 @@
SurfaceChange::SurfaceChangeCase::kReparent);
}
-TEST_F(SurfaceInterceptorTest, InterceptReparentChildrenUpdateWorks) {
- captureTest(&SurfaceInterceptorTest::reparentChildrenUpdate,
- SurfaceChange::SurfaceChangeCase::kReparentChildren);
-}
-
TEST_F(SurfaceInterceptorTest, InterceptRelativeParentUpdateWorks) {
captureTest(&SurfaceInterceptorTest::relativeParentUpdate,
SurfaceChange::SurfaceChangeCase::kRelativeParent);
diff --git a/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp b/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp
index 820f248..c081f9b 100644
--- a/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp
+++ b/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp
@@ -1766,30 +1766,6 @@
EXPECT_TRUE(framesAreSame(referenceFrame2, Base::sFakeComposer->getLatestFrame()));
}
- void Test_ReparentChildren() {
- {
- TransactionScope ts(*Base::sFakeComposer);
- ts.show(mChild);
- ts.setPosition(mChild, 10, 10);
- ts.setPosition(Base::mFGSurfaceControl, 64, 64);
- }
- auto referenceFrame = Base::mBaseFrame;
- referenceFrame[Base::FG_LAYER].mDisplayFrame = hwc_rect_t{64, 64, 64 + 64, 64 + 64};
- referenceFrame[CHILD_LAYER].mDisplayFrame =
- hwc_rect_t{64 + 10, 64 + 10, 64 + 10 + 10, 64 + 10 + 10};
- EXPECT_TRUE(framesAreSame(referenceFrame, Base::sFakeComposer->getLatestFrame()));
-
- {
- TransactionScope ts(*Base::sFakeComposer);
- ts.reparentChildren(Base::mFGSurfaceControl, Base::mBGSurfaceControl);
- }
-
- auto referenceFrame2 = referenceFrame;
- referenceFrame2[Base::FG_LAYER].mDisplayFrame = hwc_rect_t{64, 64, 64 + 64, 64 + 64};
- referenceFrame2[CHILD_LAYER].mDisplayFrame = hwc_rect_t{10, 10, 10 + 10, 10 + 10};
- EXPECT_TRUE(framesAreSame(referenceFrame2, Base::sFakeComposer->getLatestFrame()));
- }
-
// Regression test for b/37673612
void Test_ChildrenWithParentBufferTransform() {
{
@@ -1886,10 +1862,6 @@
Test_LayerAlpha();
}
-TEST_F(ChildLayerTest_2_1, DISABLED_ReparentChildren) {
- Test_ReparentChildren();
-}
-
// Regression test for b/37673612
TEST_F(ChildLayerTest_2_1, DISABLED_ChildrenWithParentBufferTransform) {
Test_ChildrenWithParentBufferTransform();
diff --git a/services/surfaceflinger/tests/unittests/SetFrameRateTest.cpp b/services/surfaceflinger/tests/unittests/SetFrameRateTest.cpp
index 7e602a2..0bb7e31 100644
--- a/services/surfaceflinger/tests/unittests/SetFrameRateTest.cpp
+++ b/services/surfaceflinger/tests/unittests/SetFrameRateTest.cpp
@@ -122,7 +122,6 @@
void addChild(sp<Layer> layer, sp<Layer> child);
void removeChild(sp<Layer> layer, sp<Layer> child);
- void reparentChildren(sp<Layer> layer, sp<Layer> child);
void commitTransaction();
TestableSurfaceFlinger mFlinger;
@@ -152,10 +151,6 @@
layer.get()->removeChild(child.get());
}
-void SetFrameRateTest::reparentChildren(sp<Layer> parent, sp<Layer> newParent) {
- parent.get()->reparentChildren(newParent);
-}
-
void SetFrameRateTest::commitTransaction() {
for (auto layer : mLayers) {
layer->pushPendingState();
@@ -433,41 +428,6 @@
EXPECT_EQ(FRAME_RATE_NO_VOTE, child2_1->getFrameRateForLayerTree());
}
-TEST_P(SetFrameRateTest, SetAndGetReparentChildren) {
- EXPECT_CALL(*mMessageQueue, invalidate()).Times(1);
-
- const auto& layerFactory = GetParam();
-
- auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
- auto parent2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
- auto child1 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
- auto child2 = mLayers.emplace_back(layerFactory->createLayer(mFlinger));
-
- addChild(parent, child1);
- addChild(child1, child2);
-
- child2->setFrameRate(FRAME_RATE_VOTE1);
- commitTransaction();
- EXPECT_EQ(FRAME_RATE_TREE, parent->getFrameRateForLayerTree());
- EXPECT_EQ(FRAME_RATE_NO_VOTE, parent2->getFrameRateForLayerTree());
- EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree());
- EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
-
- reparentChildren(parent, parent2);
- commitTransaction();
- EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
- EXPECT_EQ(FRAME_RATE_TREE, parent2->getFrameRateForLayerTree());
- EXPECT_EQ(FRAME_RATE_TREE, child1->getFrameRateForLayerTree());
- EXPECT_EQ(FRAME_RATE_VOTE1, child2->getFrameRateForLayerTree());
-
- child2->setFrameRate(FRAME_RATE_NO_VOTE);
- commitTransaction();
- EXPECT_EQ(FRAME_RATE_NO_VOTE, parent->getFrameRateForLayerTree());
- EXPECT_EQ(FRAME_RATE_NO_VOTE, parent2->getFrameRateForLayerTree());
- EXPECT_EQ(FRAME_RATE_NO_VOTE, child1->getFrameRateForLayerTree());
- EXPECT_EQ(FRAME_RATE_NO_VOTE, child2->getFrameRateForLayerTree());
-}
-
INSTANTIATE_TEST_SUITE_P(PerLayerType, SetFrameRateTest,
testing::Values(std::make_shared<BufferQueueLayerFactory>(),
std::make_shared<BufferStateLayerFactory>(),
diff --git a/services/vibratorservice/VibratorManagerHalWrapper.cpp b/services/vibratorservice/VibratorManagerHalWrapper.cpp
index a9d499d..6e660e7 100644
--- a/services/vibratorservice/VibratorManagerHalWrapper.cpp
+++ b/services/vibratorservice/VibratorManagerHalWrapper.cpp
@@ -30,7 +30,7 @@
const constexpr char* MISSING_VIBRATOR_MESSAGE_PREFIX = "No vibrator with id=";
HalResult<void> LegacyManagerHalWrapper::ping() {
- auto pingFn = [](std::shared_ptr<HalWrapper> hal) { return hal->ping(); };
+ auto pingFn = [](HalWrapper* hal) { return hal->ping(); };
return mController->doWithRetry<void>(pingFn, "ping");
}
diff --git a/services/vibratorservice/include/vibratorservice/VibratorHalController.h b/services/vibratorservice/include/vibratorservice/VibratorHalController.h
index 354e56c..6c31e2b 100644
--- a/services/vibratorservice/include/vibratorservice/VibratorHalController.h
+++ b/services/vibratorservice/include/vibratorservice/VibratorHalController.h
@@ -30,7 +30,7 @@
std::shared_ptr<HalWrapper> connectHal(std::shared_ptr<CallbackScheduler> scheduler);
template <typename T>
-using HalFunction = std::function<T(std::shared_ptr<HalWrapper>)>;
+using HalFunction = std::function<T(HalWrapper*)>;
// Controller for Vibrator HAL handle.
// This relies on a given Connector to connect to the underlying Vibrator HAL service and reconnects
@@ -64,8 +64,7 @@
*/
Info getInfo() {
static Info sDefaultInfo = InfoCache().get();
- return apply<Info>([](std::shared_ptr<HalWrapper> hal) { return hal->getInfo(); },
- sDefaultInfo, "getInfo");
+ return apply<Info>([](HalWrapper* hal) { return hal->getInfo(); }, sDefaultInfo, "getInfo");
}
/* Calls given HAL function, applying automatic retries to reconnect with the HAL when the
@@ -103,7 +102,7 @@
}
for (int i = 0; i < MAX_RETRIES; i++) {
- T result = halFn(hal);
+ T result = halFn(hal.get());
if (result.checkAndLogFailure(functionName)) {
tryReconnect();
} else {
@@ -111,7 +110,7 @@
}
}
- return halFn(hal);
+ return halFn(hal.get());
}
};
diff --git a/services/vibratorservice/test/VibratorHalControllerTest.cpp b/services/vibratorservice/test/VibratorHalControllerTest.cpp
index 279496a..8e77bc5 100644
--- a/services/vibratorservice/test/VibratorHalControllerTest.cpp
+++ b/services/vibratorservice/test/VibratorHalControllerTest.cpp
@@ -40,11 +40,9 @@
using namespace std::chrono_literals;
using namespace testing;
-static const auto ON_FN = [](std::shared_ptr<vibrator::HalWrapper> hal) {
- return hal->on(10ms, []() {});
-};
-static const auto OFF_FN = [](std::shared_ptr<vibrator::HalWrapper> hal) { return hal->off(); };
-static const auto PING_FN = [](std::shared_ptr<vibrator::HalWrapper> hal) { return hal->ping(); };
+static const auto ON_FN = [](vibrator::HalWrapper* hal) { return hal->on(10ms, []() {}); };
+static const auto OFF_FN = [](vibrator::HalWrapper* hal) { return hal->off(); };
+static const auto PING_FN = [](vibrator::HalWrapper* hal) { return hal->ping(); };
// -------------------------------------------------------------------------------------------------
@@ -233,7 +231,7 @@
std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
- auto onFn = [&](std::shared_ptr<vibrator::HalWrapper> hal) { return hal->on(10ms, callback); };
+ auto onFn = [&](vibrator::HalWrapper* hal) { return hal->on(10ms, callback); };
ASSERT_TRUE(mController->doWithRetry<void>(onFn, "on").isOk());
ASSERT_TRUE(mController->doWithRetry<void>(PING_FN, "ping").isFailed());
mMockHal.reset();
diff --git a/services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp b/services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp
index d1db82b..af0cdb8 100644
--- a/services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp
+++ b/services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp
@@ -644,7 +644,6 @@
.Times(Exactly(2))
.WillOnce(Return(Status::fromExceptionCode(Status::Exception::EX_SECURITY)))
.WillRepeatedly(DoAll(TriggerCallbackInArg1(), Return(Status())));
- ;
}
std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
diff --git a/services/vibratorservice/test/VibratorManagerHalWrapperAidlTest.cpp b/services/vibratorservice/test/VibratorManagerHalWrapperAidlTest.cpp
index 3de1576..548d028 100644
--- a/services/vibratorservice/test/VibratorManagerHalWrapperAidlTest.cpp
+++ b/services/vibratorservice/test/VibratorManagerHalWrapperAidlTest.cpp
@@ -40,7 +40,7 @@
using namespace android;
using namespace testing;
-static const auto OFF_FN = [](std::shared_ptr<vibrator::HalWrapper> hal) { return hal->off(); };
+static const auto OFF_FN = [](vibrator::HalWrapper* hal) { return hal->off(); };
class MockBinder : public BBinder {
public:
diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp
index 020b520..8d6681c 100644
--- a/vulkan/libvulkan/swapchain.cpp
+++ b/vulkan/libvulkan/swapchain.cpp
@@ -1086,7 +1086,8 @@
ALOGW_IF(err != android::OK, "native_window_api_connect failed: %s (%d)",
strerror(-err), err);
- err = window->perform(window, NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT, -1);
+ err =
+ window->perform(window, NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT, nsecs_t{-1});
if (err != android::OK) {
ALOGE("window->perform(SET_DEQUEUE_TIMEOUT) failed: %s (%d)",
strerror(-err), err);