Merge "Vulkan: correctly expose Vulkan entry points"
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 369c3de..b87582e 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -253,7 +253,7 @@
MYLOGE("Failed to retrieve module metadata package name: %s", status.toString8().c_str());
return 0L;
}
- MYLOGD("Module metadata package name: %s", package_name.c_str());
+ MYLOGD("Module metadata package name: %s\n", package_name.c_str());
int64_t version_code;
status = package_service->getVersionCodeForPackage(android::String16(package_name.c_str()),
&version_code);
@@ -876,6 +876,17 @@
CommandOptions::WithTimeoutInMs(timeout_ms).Build());
}
+static void DoSystemLogcat(time_t since) {
+ char since_str[80];
+ strftime(since_str, sizeof(since_str), "%Y-%m-%d %H:%M:%S.000", localtime(&since));
+
+ unsigned long timeout_ms = logcat_timeout({"main", "system", "crash"});
+ RunCommand("SYSTEM LOG",
+ {"logcat", "-v", "threadtime", "-v", "printable", "-v", "uid", "-d", "*:v", "-T",
+ since_str},
+ CommandOptions::WithTimeoutInMs(timeout_ms).Build());
+}
+
static void DoLogcat() {
unsigned long timeout_ms;
// DumpFile("EVENT LOG TAGS", "/etc/event-log-tags");
@@ -1071,7 +1082,7 @@
std::string path(title);
path.append(" - ").append(String8(service).c_str());
size_t bytes_written = 0;
- status_t status = dumpsys.startDumpThread(service, args);
+ status_t status = dumpsys.startDumpThread(Dumpsys::Type::DUMP, service, args);
if (status == OK) {
dumpsys.writeDumpHeader(STDOUT_FILENO, service, priority);
std::chrono::duration<double> elapsed_seconds;
@@ -1143,7 +1154,7 @@
path.append("_HIGH");
}
path.append(kProtoExt);
- status_t status = dumpsys.startDumpThread(service, args);
+ status_t status = dumpsys.startDumpThread(Dumpsys::Type::DUMP, service, args);
if (status == OK) {
status = ds.AddZipEntryFromFd(path, dumpsys.getDumpFd(), service_timeout);
bool dumpTerminated = (status == OK);
@@ -1365,8 +1376,6 @@
ds.TakeScreenshot();
}
- DoLogcat();
-
AddAnrTraceFiles();
// NOTE: tombstones are always added as separate entries in the zip archive
@@ -1523,6 +1532,12 @@
// keep the system stats as close to its initial state as possible.
RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(RunDumpsysCritical);
+ // Capture first logcat early on; useful to take a snapshot before dumpstate logs take over the
+ // buffer.
+ DoLogcat();
+ // Capture timestamp after first logcat to use in next logcat
+ time_t logcat_ts = time(nullptr);
+
/* collect stack traces from Dalvik and native processes (needs root) */
RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(ds.DumpTraces, &dump_traces_path);
@@ -1569,7 +1584,10 @@
}
RETURN_IF_USER_DENIED_CONSENT();
- return dumpstate();
+ Dumpstate::RunStatus status = dumpstate();
+ // Capture logcat since the last time we did it.
+ DoSystemLogcat(logcat_ts);
+ return status;
}
// This method collects common dumpsys for telephony and wifi
@@ -2508,6 +2526,8 @@
return RunStatus::OK;
}
+ MYLOGD("dumpstate calling_uid = %d ; calling package = %s \n",
+ calling_uid, calling_package.c_str());
if (options_->bugreport_fd.get() != -1) {
// If the output needs to be copied over to the caller's fd, get user consent.
android::String16 package(calling_package.c_str());
@@ -2685,10 +2705,10 @@
FinalizeFile();
}
- // Share the final file with the caller if the user has consented.
+ // Share the final file with the caller if the user has consented or Shell is the caller.
Dumpstate::RunStatus status = Dumpstate::RunStatus::OK;
if (options_->bugreport_fd.get() != -1) {
- status = CopyBugreportIfUserConsented();
+ status = CopyBugreportIfUserConsented(calling_uid);
if (status != Dumpstate::RunStatus::OK &&
status != Dumpstate::RunStatus::USER_CONSENT_TIMED_OUT) {
// Do an early return if there were errors. We make an exception for consent
@@ -2758,6 +2778,9 @@
}
void Dumpstate::CheckUserConsent(int32_t calling_uid, const android::String16& calling_package) {
+ if (calling_uid == AID_SHELL) {
+ return;
+ }
consent_callback_ = new ConsentCallback();
const String16 incidentcompanion("incidentcompanion");
sp<android::IBinder> ics(defaultServiceManager()->getService(incidentcompanion));
@@ -2792,10 +2815,15 @@
return USER_CONSENT_DENIED;
}
-Dumpstate::RunStatus Dumpstate::CopyBugreportIfUserConsented() {
+Dumpstate::RunStatus Dumpstate::CopyBugreportIfUserConsented(int32_t calling_uid) {
// If the caller has asked to copy the bugreport over to their directory, we need explicit
- // user consent.
- UserConsentResult consent_result = consent_callback_->getResult();
+ // user consent (unless the caller is Shell).
+ UserConsentResult consent_result;
+ if (calling_uid == AID_SHELL) {
+ consent_result = UserConsentResult::APPROVED;
+ } else {
+ consent_result = consent_callback_->getResult();
+ }
if (consent_result == UserConsentResult::UNAVAILABLE) {
// User has not responded yet.
uint64_t elapsed_ms = consent_callback_->getElapsedTimeMs();
diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h
index 5ba84ca..430936e 100644
--- a/cmds/dumpstate/dumpstate.h
+++ b/cmds/dumpstate/dumpstate.h
@@ -498,8 +498,9 @@
RunStatus HandleUserConsentDenied();
- // Copies bugreport artifacts over to the caller's directories provided there is user consent.
- RunStatus CopyBugreportIfUserConsented();
+ // Copies bugreport artifacts over to the caller's directories provided there is user consent or
+ // called by Shell.
+ RunStatus CopyBugreportIfUserConsented(int32_t calling_uid);
// Used by GetInstance() only.
explicit Dumpstate(const std::string& version = VERSION_CURRENT);
diff --git a/cmds/dumpsys/dumpsys.cpp b/cmds/dumpsys/dumpsys.cpp
index 9f65425..abdf168 100644
--- a/cmds/dumpsys/dumpsys.cpp
+++ b/cmds/dumpsys/dumpsys.cpp
@@ -59,12 +59,13 @@
"usage: dumpsys\n"
" To dump all services.\n"
"or:\n"
- " dumpsys [-t TIMEOUT] [--priority LEVEL] [--help | -l | --skip SERVICES | "
- "SERVICE [ARGS]]\n"
+ " dumpsys [-t TIMEOUT] [--priority LEVEL] [--pid] [--help | -l | --skip SERVICES "
+ "| SERVICE [ARGS]]\n"
" --help: shows this help\n"
" -l: only list services, do not dump them\n"
" -t TIMEOUT_SEC: TIMEOUT to use in seconds instead of default 10 seconds\n"
" -T TIMEOUT_MS: TIMEOUT to use in milliseconds instead of default 10 seconds\n"
+ " --pid: dump PID instead of usual dump\n"
" --proto: filter services that support dumping data in proto format. Dumps\n"
" will be in proto format.\n"
" --priority LEVEL: filter services based on specified priority\n"
@@ -120,9 +121,11 @@
bool showListOnly = false;
bool skipServices = false;
bool asProto = false;
+ Type type = Type::DUMP;
int timeoutArgMs = 10000;
int priorityFlags = IServiceManager::DUMP_FLAG_PRIORITY_ALL;
- static struct option longOptions[] = {{"priority", required_argument, 0, 0},
+ static struct option longOptions[] = {{"pid", no_argument, 0, 0},
+ {"priority", required_argument, 0, 0},
{"proto", no_argument, 0, 0},
{"skip", no_argument, 0, 0},
{"help", no_argument, 0, 0},
@@ -157,6 +160,8 @@
usage();
return -1;
}
+ } else if (!strcmp(longOptions[optionIndex].name, "pid")) {
+ type = Type::PID;
}
break;
@@ -246,7 +251,7 @@
const String16& serviceName = services[i];
if (IsSkipped(skippedServices, serviceName)) continue;
- if (startDumpThread(serviceName, args) == OK) {
+ if (startDumpThread(type, serviceName, args) == OK) {
bool addSeparator = (N > 1);
if (addSeparator) {
writeDumpHeader(STDOUT_FILENO, serviceName, priorityFlags);
@@ -313,7 +318,18 @@
}
}
-status_t Dumpsys::startDumpThread(const String16& serviceName, const Vector<String16>& args) {
+static status_t dumpPidToFd(const sp<IBinder>& service, const unique_fd& fd) {
+ pid_t pid;
+ status_t status = service->getDebugPid(&pid);
+ if (status != OK) {
+ return status;
+ }
+ WriteStringToFd(std::to_string(pid) + "\n", fd.get());
+ return OK;
+}
+
+status_t Dumpsys::startDumpThread(Type type, const String16& serviceName,
+ const Vector<String16>& args) {
sp<IBinder> service = sm_->checkService(serviceName);
if (service == nullptr) {
aerr << "Can't find service: " << serviceName << endl;
@@ -333,16 +349,22 @@
// dump blocks until completion, so spawn a thread..
activeThread_ = std::thread([=, remote_end{std::move(remote_end)}]() mutable {
- int err = service->dump(remote_end.get(), args);
+ status_t err = 0;
- // It'd be nice to be able to close the remote end of the socketpair before the dump
- // call returns, to terminate our reads if the other end closes their copy of the
- // file descriptor, but then hangs for some reason. There doesn't seem to be a good
- // way to do this, though.
- remote_end.reset();
+ switch (type) {
+ case Type::DUMP:
+ err = service->dump(remote_end.get(), args);
+ break;
+ case Type::PID:
+ err = dumpPidToFd(service, remote_end);
+ break;
+ default:
+ aerr << "Unknown dump type" << static_cast<int>(type) << endl;
+ return;
+ }
- if (err != 0) {
- aerr << "Error dumping service info: (" << strerror(err) << ") "
+ if (err != OK) {
+ aerr << "Error dumping service info status_t: (" << err << ") "
<< serviceName << endl;
}
});
diff --git a/cmds/dumpsys/dumpsys.h b/cmds/dumpsys/dumpsys.h
index c48a1e9..929c55c 100644
--- a/cmds/dumpsys/dumpsys.h
+++ b/cmds/dumpsys/dumpsys.h
@@ -51,6 +51,11 @@
*/
static void setServiceArgs(Vector<String16>& args, bool asProto, int priorityFlags);
+ enum class Type {
+ DUMP, // dump using `dump` function
+ PID, // dump pid of server only
+ };
+
/**
* Starts a thread to connect to a service and get its dump output. The thread redirects
* the output to a pipe. Thread must be stopped by a subsequent callto {@code
@@ -61,7 +66,8 @@
* {@code NAME_NOT_FOUND} service could not be found.
* {@code != OK} error
*/
- status_t startDumpThread(const String16& serviceName, const Vector<String16>& args);
+ status_t startDumpThread(Type type, const String16& serviceName,
+ const Vector<String16>& args);
/**
* Writes a section header to a file descriptor.
diff --git a/cmds/dumpsys/tests/dumpsys_test.cpp b/cmds/dumpsys/tests/dumpsys_test.cpp
index cbac839..cf4e0b5 100644
--- a/cmds/dumpsys/tests/dumpsys_test.cpp
+++ b/cmds/dumpsys/tests/dumpsys_test.cpp
@@ -194,7 +194,7 @@
CaptureStdout();
CaptureStderr();
dump_.setServiceArgs(args, supportsProto, priorityFlags);
- status_t status = dump_.startDumpThread(serviceName, args);
+ status_t status = dump_.startDumpThread(Dumpsys::Type::DUMP, serviceName, args);
EXPECT_THAT(status, Eq(0));
status = dump_.writeDump(STDOUT_FILENO, serviceName, std::chrono::milliseconds(500), false,
elapsedDuration, bytesWritten);
@@ -539,6 +539,27 @@
AssertDumpedWithPriority("runninghigh2", "dump2", PriorityDumper::PRIORITY_ARG_HIGH);
}
+// Tests 'dumpsys --pid'
+TEST_F(DumpsysTest, ListAllServicesWithPid) {
+ ExpectListServices({"Locksmith", "Valet"});
+ ExpectCheckService("Locksmith");
+ ExpectCheckService("Valet");
+
+ CallMain({"--pid"});
+
+ AssertRunningServices({"Locksmith", "Valet"});
+ AssertOutputContains(std::to_string(getpid()));
+}
+
+// Tests 'dumpsys --pid service_name'
+TEST_F(DumpsysTest, ListServiceWithPid) {
+ ExpectCheckService("Locksmith");
+
+ CallMain({"--pid", "Locksmith"});
+
+ AssertOutput(std::to_string(getpid()) + "\n");
+}
+
TEST_F(DumpsysTest, GetBytesWritten) {
const char* serviceName = "service2";
const char* dumpContents = "dump1";
@@ -563,4 +584,4 @@
dump_.writeDump(STDOUT_FILENO, String16("service"), std::chrono::milliseconds(500),
/* as_proto = */ false, elapsedDuration, bytesWritten);
EXPECT_THAT(status, Eq(INVALID_OPERATION));
-}
\ No newline at end of file
+}
diff --git a/headers/media_plugin/media/openmax/OMX_VideoExt.h b/headers/media_plugin/media/openmax/OMX_VideoExt.h
index 435fcc8..dc37bbd 100644
--- a/headers/media_plugin/media/openmax/OMX_VideoExt.h
+++ b/headers/media_plugin/media/openmax/OMX_VideoExt.h
@@ -291,18 +291,19 @@
/** Dolby Vision Profile enum type */
typedef enum OMX_VIDEO_DOLBYVISIONPROFILETYPE {
- OMX_VIDEO_DolbyVisionProfileUnknown = 0x0,
- OMX_VIDEO_DolbyVisionProfileDvavPer = 0x1,
- OMX_VIDEO_DolbyVisionProfileDvavPen = 0x2,
- OMX_VIDEO_DolbyVisionProfileDvheDer = 0x4,
- OMX_VIDEO_DolbyVisionProfileDvheDen = 0x8,
- OMX_VIDEO_DolbyVisionProfileDvheDtr = 0x10,
- OMX_VIDEO_DolbyVisionProfileDvheStn = 0x20,
- OMX_VIDEO_DolbyVisionProfileDvheDth = 0x40,
- OMX_VIDEO_DolbyVisionProfileDvheDtb = 0x80,
- OMX_VIDEO_DolbyVisionProfileDvheSt = 0x100,
- OMX_VIDEO_DolbyVisionProfileDvavSe = 0x200,
- OMX_VIDEO_DolbyVisionProfileMax = 0x7FFFFFFF
+ OMX_VIDEO_DolbyVisionProfileUnknown = 0x0,
+ OMX_VIDEO_DolbyVisionProfileDvavPer = 0x1,
+ OMX_VIDEO_DolbyVisionProfileDvavPen = 0x2,
+ OMX_VIDEO_DolbyVisionProfileDvheDer = 0x4,
+ OMX_VIDEO_DolbyVisionProfileDvheDen = 0x8,
+ OMX_VIDEO_DolbyVisionProfileDvheDtr = 0x10,
+ OMX_VIDEO_DolbyVisionProfileDvheStn = 0x20,
+ OMX_VIDEO_DolbyVisionProfileDvheDth = 0x40,
+ OMX_VIDEO_DolbyVisionProfileDvheDtb = 0x80,
+ OMX_VIDEO_DolbyVisionProfileDvheSt = 0x100,
+ OMX_VIDEO_DolbyVisionProfileDvavSe = 0x200,
+ OMX_VIDEO_DolbyVisionProfileDvav110 = 0x400,
+ OMX_VIDEO_DolbyVisionProfileMax = 0x7FFFFFFF
} OMX_VIDEO_DOLBYVISIONPROFILETYPE;
/** Dolby Vision Level enum type */
diff --git a/libs/android_runtime_lazy/Android.bp b/libs/android_runtime_lazy/Android.bp
index 2d6292c..09a5f39 100644
--- a/libs/android_runtime_lazy/Android.bp
+++ b/libs/android_runtime_lazy/Android.bp
@@ -52,10 +52,6 @@
"libutils",
],
- required: [
- "libandroid_runtime",
- ],
-
export_include_dirs: [
"include",
],
diff --git a/libs/binder/AppOpsManager.cpp b/libs/binder/AppOpsManager.cpp
index 9da9c13..60f047f 100644
--- a/libs/binder/AppOpsManager.cpp
+++ b/libs/binder/AppOpsManager.cpp
@@ -115,18 +115,23 @@
}
int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage) {
- return noteOp(op, uid, callingPackage, String16("noteOp from native code"));
+ return noteOp(op, uid, callingPackage, String16(), String16());
}
int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage,
- const String16& message) {
+ const String16& featureId, const String16& message) {
sp<IAppOpsService> service = getService();
int32_t mode = service != nullptr
? service->noteOperation(op, uid, callingPackage)
: APP_OPS_MANAGER_UNAVAILABLE_MODE;
if (mode == AppOpsManager::MODE_ALLOWED) {
- markAppOpNoted(uid, callingPackage, op, message);
+ if (message.size() == 0) {
+ markAppOpNoted(uid, callingPackage, op, featureId,
+ String16("noteOp from native code"));
+ } else {
+ markAppOpNoted(uid, callingPackage, op, featureId, message);
+ }
}
return mode;
@@ -134,19 +139,23 @@
int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage,
bool startIfModeDefault) {
- return startOpNoThrow(op, uid, callingPackage, startIfModeDefault,
- String16("startOpNoThrow from native code"));
+ return startOpNoThrow(op, uid, callingPackage, startIfModeDefault, String16(), String16());
}
int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage,
- bool startIfModeDefault, const String16& message) {
+ bool startIfModeDefault, const String16& featureId, const String16& message) {
sp<IAppOpsService> service = getService();
int32_t mode = service != nullptr
? service->startOperation(getToken(service), op, uid, callingPackage,
startIfModeDefault) : APP_OPS_MANAGER_UNAVAILABLE_MODE;
if (mode == AppOpsManager::MODE_ALLOWED) {
- markAppOpNoted(uid, callingPackage, op, message);
+ if (message.size() == 0) {
+ markAppOpNoted(uid, callingPackage, op, featureId,
+ String16("startOp from native code"));
+ } else {
+ markAppOpNoted(uid, callingPackage, op, featureId, message);
+ }
}
return mode;
@@ -198,7 +207,7 @@
}
void AppOpsManager::markAppOpNoted(int32_t uid, const String16& packageName, int32_t opCode,
- const String16& message) {
+ const String16& featureId, const String16& message) {
// check it the appops needs to be collected and cache result
if (appOpsToNote[opCode] == 0) {
if (shouldCollectNotes(opCode)) {
@@ -212,14 +221,16 @@
return;
}
- noteAsyncOp(String16(), uid, packageName, opCode, message);
+ noteAsyncOp(String16(), uid, packageName, opCode, featureId, message);
}
void AppOpsManager::noteAsyncOp(const String16& callingPackageName, int32_t uid,
- const String16& packageName, int32_t opCode, const String16& message) {
+ const String16& packageName, int32_t opCode, const String16& featureId,
+ const String16& message) {
sp<IAppOpsService> service = getService();
if (service != nullptr) {
- return service->noteAsyncOp(callingPackageName, uid, packageName, opCode, message);
+ return service->noteAsyncOp(callingPackageName, uid, packageName, opCode, featureId,
+ message);
}
}
diff --git a/libs/binder/BpBinder.cpp b/libs/binder/BpBinder.cpp
index 50c7053..238c9dc 100644
--- a/libs/binder/BpBinder.cpp
+++ b/libs/binder/BpBinder.cpp
@@ -214,16 +214,21 @@
{
// Once a binder has died, it will never come back to life.
if (mAlive) {
+ bool privateVendor = flags & FLAG_PRIVATE_VENDOR;
+ // don't send userspace flags to the kernel
+ flags = flags & ~FLAG_PRIVATE_VENDOR;
+
// user transactions require a given stability level
if (code >= FIRST_CALL_TRANSACTION && code <= LAST_CALL_TRANSACTION) {
using android::internal::Stability;
auto stability = Stability::get(this);
+ auto required = privateVendor ? Stability::VENDOR : Stability::kLocalStability;
- if (CC_UNLIKELY(!Stability::check(stability, Stability::kLocalStability))) {
+ if (CC_UNLIKELY(!Stability::check(stability, required))) {
ALOGE("Cannot do a user transaction on a %s binder in a %s context.",
Stability::stabilityString(stability).c_str(),
- Stability::stabilityString(Stability::kLocalStability).c_str());
+ Stability::stabilityString(required).c_str());
return BAD_TYPE;
}
}
diff --git a/libs/binder/IAppOpsService.cpp b/libs/binder/IAppOpsService.cpp
index 6c16c2d..9760e13 100644
--- a/libs/binder/IAppOpsService.cpp
+++ b/libs/binder/IAppOpsService.cpp
@@ -145,7 +145,8 @@
}
virtual void noteAsyncOp(const String16& callingPackageName, int32_t uid,
- const String16& packageName, int32_t opCode, const String16& message) {
+ const String16& packageName, int32_t opCode, const String16& featureId,
+ const String16& message) {
Parcel data, reply;
data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
@@ -166,6 +167,14 @@
}
data.writeInt32(opCode);
+
+ // Convert empty featureId into null string
+ if (featureId.size() != 0) {
+ data.writeString16(featureId);
+ } else {
+ data.writeString16(nullptr, 0);
+ }
+
data.writeString16(message);
remote()->transact(NOTE_ASYNC_OP_TRANSACTION, data, &reply);
}
@@ -291,8 +300,9 @@
int32_t uid = data.readInt32();
String16 packageName = data.readString16();
int32_t opCode = data.readInt32();
+ String16 featureId = data.readString16();
String16 message = data.readString16();
- noteAsyncOp(callingPackageName, uid, packageName, opCode, message);
+ noteAsyncOp(callingPackageName, uid, packageName, opCode, featureId, message);
reply->writeNoException();
return NO_ERROR;
} break;
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 573a038..323e079 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -50,10 +50,6 @@
#include <private/binder/binder_module.h>
#include "Static.h"
-#ifndef INT32_MAX
-#define INT32_MAX ((int32_t)(2147483647))
-#endif
-
#define LOG_REFS(...)
//#define LOG_REFS(...) ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOG_ALLOC(...)
@@ -750,61 +746,37 @@
return writeUtf8AsUtf16(*str);
}
-namespace {
-
-template<typename T>
-status_t writeByteVectorInternal(Parcel* parcel, const std::vector<T>& val)
-{
- status_t status;
- if (val.size() > std::numeric_limits<int32_t>::max()) {
- status = BAD_VALUE;
- return status;
+status_t Parcel::writeByteVectorInternal(const int8_t* data, size_t size) {
+ if (size > std::numeric_limits<int32_t>::max()) {
+ return BAD_VALUE;
}
- status = parcel->writeInt32(val.size());
+ status_t status = writeInt32(size);
if (status != OK) {
return status;
}
- void* data = parcel->writeInplace(val.size());
- if (!data) {
- status = BAD_VALUE;
- return status;
- }
-
- memcpy(data, val.data(), val.size());
- return status;
+ return write(data, size);
}
-template<typename T>
-status_t writeByteVectorInternalPtr(Parcel* parcel,
- const std::unique_ptr<std::vector<T>>& val)
-{
- if (!val) {
- return parcel->writeInt32(-1);
- }
-
- return writeByteVectorInternal(parcel, *val);
-}
-
-} // namespace
-
status_t Parcel::writeByteVector(const std::vector<int8_t>& val) {
- return writeByteVectorInternal(this, val);
+ return writeByteVectorInternal(val.data(), val.size());
}
status_t Parcel::writeByteVector(const std::unique_ptr<std::vector<int8_t>>& val)
{
- return writeByteVectorInternalPtr(this, val);
+ if (!val) return writeInt32(-1);
+ return writeByteVectorInternal(val->data(), val->size());
}
status_t Parcel::writeByteVector(const std::vector<uint8_t>& val) {
- return writeByteVectorInternal(this, val);
+ return writeByteVectorInternal(reinterpret_cast<const int8_t*>(val.data()), val.size());
}
status_t Parcel::writeByteVector(const std::unique_ptr<std::vector<uint8_t>>& val)
{
- return writeByteVectorInternalPtr(this, val);
+ if (!val) return writeInt32(-1);
+ return writeByteVectorInternal(reinterpret_cast<const int8_t*>(val->data()), val->size());
}
status_t Parcel::writeInt32Vector(const std::vector<int32_t>& val)
@@ -1477,81 +1449,41 @@
return err;
}
-namespace {
-
-template<typename T>
-status_t readByteVectorInternal(const Parcel* parcel,
- std::vector<T>* val) {
- val->clear();
-
- int32_t size;
- status_t status = parcel->readInt32(&size);
-
- if (status != OK) {
- return status;
+status_t Parcel::readByteVectorInternal(int8_t* data, size_t size) const {
+ if (size_t(size) > dataAvail()) {
+ return BAD_VALUE;
}
-
- if (size < 0) {
- status = UNEXPECTED_NULL;
- return status;
- }
- if (size_t(size) > parcel->dataAvail()) {
- status = BAD_VALUE;
- return status;
- }
-
- T* data = const_cast<T*>(reinterpret_cast<const T*>(parcel->readInplace(size)));
- if (!data) {
- status = BAD_VALUE;
- return status;
- }
- val->reserve(size);
- val->insert(val->end(), data, data + size);
-
- return status;
+ return read(data, size);
}
-template<typename T>
-status_t readByteVectorInternalPtr(
- const Parcel* parcel,
- std::unique_ptr<std::vector<T>>* val) {
- const int32_t start = parcel->dataPosition();
- int32_t size;
- status_t status = parcel->readInt32(&size);
- val->reset();
-
- if (status != OK || size < 0) {
- return status;
- }
-
- parcel->setDataPosition(start);
- val->reset(new (std::nothrow) std::vector<T>());
-
- status = readByteVectorInternal(parcel, val->get());
-
- if (status != OK) {
- val->reset();
- }
-
- return status;
-}
-
-} // namespace
-
status_t Parcel::readByteVector(std::vector<int8_t>* val) const {
- return readByteVectorInternal(this, val);
+ if (status_t status = resizeOutVector(val); status != OK) return status;
+ return readByteVectorInternal(val->data(), val->size());
}
status_t Parcel::readByteVector(std::vector<uint8_t>* val) const {
- return readByteVectorInternal(this, val);
+ if (status_t status = resizeOutVector(val); status != OK) return status;
+ return readByteVectorInternal(reinterpret_cast<int8_t*>(val->data()), val->size());
}
status_t Parcel::readByteVector(std::unique_ptr<std::vector<int8_t>>* val) const {
- return readByteVectorInternalPtr(this, val);
+ if (status_t status = resizeOutVector(val); status != OK) return status;
+ if (val->get() == nullptr) {
+ // resizeOutVector does not create the out vector if size is < 0.
+ // This occurs when writing a null byte vector.
+ return OK;
+ }
+ return readByteVectorInternal((*val)->data(), (*val)->size());
}
status_t Parcel::readByteVector(std::unique_ptr<std::vector<uint8_t>>* val) const {
- return readByteVectorInternalPtr(this, val);
+ if (status_t status = resizeOutVector(val); status != OK) return status;
+ if (val->get() == nullptr) {
+ // resizeOutVector does not create the out vector if size is < 0.
+ // This occurs when writing a null byte vector.
+ return OK;
+ }
+ return readByteVectorInternal(reinterpret_cast<int8_t*>((*val)->data()), (*val)->size());
}
status_t Parcel::readInt32Vector(std::unique_ptr<std::vector<int32_t>>* val) const {
@@ -2630,11 +2562,13 @@
if (objectsSize == 0) {
free(mObjects);
mObjects = nullptr;
+ mObjectsCapacity = 0;
} else {
binder_size_t* objects =
(binder_size_t*)realloc(mObjects, objectsSize*sizeof(binder_size_t));
if (objects) {
mObjects = objects;
+ mObjectsCapacity = objectsSize;
}
}
mObjectsSize = objectsSize;
diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp
index 0336d3e..6971c72 100644
--- a/libs/binder/ProcessState.cpp
+++ b/libs/binder/ProcessState.cpp
@@ -373,7 +373,9 @@
}
}
+#ifdef __ANDROID__
LOG_ALWAYS_FATAL_IF(mDriverFD < 0, "Binder driver '%s' could not be opened. Terminating.", driver);
+#endif
}
ProcessState::~ProcessState()
diff --git a/libs/binder/TEST_MAPPING b/libs/binder/TEST_MAPPING
index 136bdb0..b3afd81 100644
--- a/libs/binder/TEST_MAPPING
+++ b/libs/binder/TEST_MAPPING
@@ -4,6 +4,9 @@
"name": "binderSafeInterfaceTest"
},
{
+ "name": "binderVendorDoubleLoadTest"
+ },
+ {
"name": "binderDriverInterfaceTest"
},
{
@@ -14,6 +17,9 @@
},
{
"name": "binderStabilityTest"
+ },
+ {
+ "name": "CtsNdkBinderTestCases"
}
]
}
diff --git a/libs/binder/fuzzer/Android.bp b/libs/binder/fuzzer/Android.bp
index d2f0d37..a9d2b75 100644
--- a/libs/binder/fuzzer/Android.bp
+++ b/libs/binder/fuzzer/Android.bp
@@ -36,4 +36,8 @@
],
},
},
+ // This flag enables verbose output in the fuzz target, and is very useful
+ // for debugging a failure. If you are trying to diagnose how a crash was
+ // produced, you may find uncommenting the below line very useful.
+ // cflags: ["-DENABLE_LOG_FUZZ"],
}
diff --git a/libs/binder/fuzzer/binder.cpp b/libs/binder/fuzzer/binder.cpp
index 86264db..52c730c 100644
--- a/libs/binder/fuzzer/binder.cpp
+++ b/libs/binder/fuzzer/binder.cpp
@@ -22,6 +22,10 @@
using ::android::status_t;
+enum ByteEnum : int8_t {};
+enum IntEnum : int32_t {};
+enum LongEnum : int64_t {};
+
class ExampleParcelable : public android::Parcelable {
public:
status_t writeToParcel(android::Parcel* /*parcel*/) const override {
@@ -80,6 +84,7 @@
PARCEL_READ_WITH_STATUS(T, FUN), \
PARCEL_READ_NO_STATUS(T, FUN)
+// clang-format off
std::vector<ParcelRead<::android::Parcel>> BINDER_PARCEL_READ_FUNCTIONS {
PARCEL_READ_NO_STATUS(size_t, dataSize),
PARCEL_READ_NO_STATUS(size_t, dataAvail),
@@ -93,26 +98,16 @@
PARCEL_READ_NO_STATUS(size_t, allowFds),
PARCEL_READ_NO_STATUS(size_t, hasFileDescriptors),
[] (const ::android::Parcel& p, uint8_t len) {
-#ifdef __ANDROID__
std::string interface(len, 'a');
FUZZ_LOG() << "about to enforceInterface: " << interface;
bool b = p.enforceInterface(::android::String16(interface.c_str()));
FUZZ_LOG() << "enforced interface: " << b;
-#else
- FUZZ_LOG() << "skipping enforceInterface";
- (void)p;
- (void)len;
-#endif // __ANDROID__
},
[] (const ::android::Parcel& p, uint8_t /*len*/) {
-#ifdef __ANDROID__
FUZZ_LOG() << "about to checkInterface";
- bool b = p.checkInterface(new android::BBinder());
+ android::sp<android::IBinder> aBinder = new android::BBinder();
+ bool b = p.checkInterface(aBinder.get());
FUZZ_LOG() << "checked interface: " << b;
-#else
- FUZZ_LOG() << "skipping checkInterface";
- (void)p;
-#endif // __ANDROID__
},
PARCEL_READ_NO_STATUS(size_t, objectsCount),
PARCEL_READ_NO_STATUS(status_t, errorCheck),
@@ -158,6 +153,14 @@
PARCEL_READ_WITH_STATUS(android::sp<android::IBinder>, readStrongBinder),
PARCEL_READ_WITH_STATUS(android::sp<android::IBinder>, readNullableStrongBinder),
+ // TODO(b/131868573): can force read of arbitrarily sized vector
+ // PARCEL_READ_WITH_STATUS(std::vector<ByteEnum>, readEnumVector),
+ // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<ByteEnum>>, readEnumVector),
+ // PARCEL_READ_WITH_STATUS(std::vector<IntEnum>, readEnumVector),
+ // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<IntEnum>>, readEnumVector),
+ // PARCEL_READ_WITH_STATUS(std::vector<LongEnum>, readEnumVector),
+ // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<LongEnum>>, readEnumVector),
+
// only reading one parcelable type for now
// TODO(b/131868573): can force read of arbitrarily sized vector
// PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<std::unique_ptr<ExampleParcelable>>>, readParcelableVector),
@@ -249,3 +252,4 @@
PARCEL_READ_NO_STATUS(size_t, getBlobAshmemSize),
PARCEL_READ_NO_STATUS(size_t, getOpenAshmemSize),
};
+// clang-format on
diff --git a/libs/binder/fuzzer/hwbinder.cpp b/libs/binder/fuzzer/hwbinder.cpp
index b8cce72..0fec393 100644
--- a/libs/binder/fuzzer/hwbinder.cpp
+++ b/libs/binder/fuzzer/hwbinder.cpp
@@ -30,6 +30,9 @@
return os;
}
+#define PARCEL_READ_OPT_STATUS(T, FUN) \
+ PARCEL_READ_NO_STATUS(T, FUN), PARCEL_READ_WITH_STATUS(T, FUN)
+
#define PARCEL_READ_NO_STATUS(T, FUN) \
[] (const ::android::hardware::Parcel& p, uint8_t /*data*/) {\
FUZZ_LOG() << "about to read " #T " using " #FUN " with no status";\
@@ -45,6 +48,7 @@
FUZZ_LOG() << #T " status: " << status << " value: " << t;\
}
+// clang-format off
std::vector<ParcelRead<::android::hardware::Parcel>> HWBINDER_PARCEL_READ_FUNCTIONS {
PARCEL_READ_NO_STATUS(size_t, dataSize),
PARCEL_READ_NO_STATUS(size_t, dataAvail),
@@ -62,30 +66,44 @@
FUZZ_LOG() << "enforceInterface status: " << okay;
},
PARCEL_READ_NO_STATUS(size_t, objectsCount),
+ [] (const ::android::hardware::Parcel& p, uint8_t length) {
+ FUZZ_LOG() << "about to read";
+ std::vector<uint8_t> data (length);
+ status_t status = p.read(data.data(), length);
+ FUZZ_LOG() << "read status: " << status << " data: " << hexString(data.data(), data.size());
+ },
+ [] (const ::android::hardware::Parcel& p, uint8_t length) {
+ FUZZ_LOG() << "about to read";
+ std::vector<uint8_t> data (length);
+ const void* inplace = p.readInplace(length);
+ FUZZ_LOG() << "read status: " << hexString(inplace, length);
+ },
PARCEL_READ_WITH_STATUS(int8_t, readInt8),
PARCEL_READ_WITH_STATUS(uint8_t, readUint8),
PARCEL_READ_WITH_STATUS(int16_t, readInt16),
PARCEL_READ_WITH_STATUS(uint16_t, readUint16),
- PARCEL_READ_WITH_STATUS(int32_t, readInt32),
- PARCEL_READ_WITH_STATUS(uint32_t, readUint32),
- PARCEL_READ_WITH_STATUS(int64_t, readInt64),
- PARCEL_READ_WITH_STATUS(uint64_t, readUint64),
- PARCEL_READ_WITH_STATUS(float, readFloat),
- PARCEL_READ_WITH_STATUS(double, readDouble),
- PARCEL_READ_WITH_STATUS(bool, readBool),
- PARCEL_READ_WITH_STATUS(::android::String16, readString16),
- PARCEL_READ_WITH_STATUS(::android::sp<::android::hardware::IBinder>, readStrongBinder),
- PARCEL_READ_WITH_STATUS(::android::sp<::android::hardware::IBinder>, readNullableStrongBinder),
- [] (const ::android::hardware::Parcel& p, uint8_t amount) {
- FUZZ_LOG() << "about to readInPlace " << amount;
- const uint8_t* data = (const uint8_t*)p.readInplace(amount);
- if (data) {
- std::vector<uint8_t> vdata(data, data + amount);
- FUZZ_LOG() << "readInPlace " << amount << " data: " << hexString(vdata);
- } else {
- FUZZ_LOG() << "readInPlace " << amount << " no data";
- }
+ PARCEL_READ_OPT_STATUS(int32_t, readInt32),
+ PARCEL_READ_OPT_STATUS(uint32_t, readUint32),
+ PARCEL_READ_OPT_STATUS(int64_t, readInt64),
+ PARCEL_READ_OPT_STATUS(uint64_t, readUint64),
+ PARCEL_READ_OPT_STATUS(float, readFloat),
+ PARCEL_READ_OPT_STATUS(double, readDouble),
+ PARCEL_READ_OPT_STATUS(bool, readBool),
+ [] (const ::android::hardware::Parcel& p, uint8_t /*data*/) {
+ FUZZ_LOG() << "about to readCString";
+ const char* str = p.readCString();
+ FUZZ_LOG() << "readCString " << (str ? str : "<null>");
},
+ PARCEL_READ_OPT_STATUS(::android::String16, readString16),
+ PARCEL_READ_WITH_STATUS(std::unique_ptr<::android::String16>, readString16),
+ [] (const ::android::hardware::Parcel& p, uint8_t /*data*/) {
+ FUZZ_LOG() << "about to readString16Inplace";
+ size_t outSize = 0;
+ const char16_t* str = p.readString16Inplace(&outSize);
+ FUZZ_LOG() << "readString16Inplace: " << hexString(str, sizeof(char16_t) * outSize);
+ },
+ PARCEL_READ_OPT_STATUS(::android::sp<::android::hardware::IBinder>, readStrongBinder),
+ PARCEL_READ_WITH_STATUS(::android::sp<::android::hardware::IBinder>, readNullableStrongBinder),
[] (const ::android::hardware::Parcel& p, uint8_t size) {
FUZZ_LOG() << "about to readBuffer";
size_t handle = 0;
@@ -130,6 +148,28 @@
// should be null since we don't create any IPC objects
CHECK(data == nullptr) << data;
},
+ [] (const ::android::hardware::Parcel& p, uint8_t size) {
+ FUZZ_LOG() << "about to readEmbeddedNativeHandle";
+ size_t parent_buffer_handle = size & 0xf;
+ size_t parent_offset = size >> 4;
+ const native_handle_t* handle = nullptr;
+ status_t status = p.readEmbeddedNativeHandle(parent_buffer_handle, parent_offset, &handle);
+ FUZZ_LOG() << "readEmbeddedNativeHandle status: " << status << " handle: " << handle << " handle: " << handle;
+
+ // should be null since we don't create any IPC objects
+ CHECK(handle == nullptr) << handle;
+ },
+ [] (const ::android::hardware::Parcel& p, uint8_t size) {
+ FUZZ_LOG() << "about to readNullableEmbeddedNativeHandle";
+ size_t parent_buffer_handle = size & 0xf;
+ size_t parent_offset = size >> 4;
+ const native_handle_t* handle = nullptr;
+ status_t status = p.readNullableEmbeddedNativeHandle(parent_buffer_handle, parent_offset, &handle);
+ FUZZ_LOG() << "readNullableEmbeddedNativeHandle status: " << status << " handle: " << handle << " handle: " << handle;
+
+ // should be null since we don't create any IPC objects
+ CHECK(handle == nullptr) << handle;
+ },
[] (const ::android::hardware::Parcel& p, uint8_t /*data*/) {
FUZZ_LOG() << "about to readNativeHandleNoDup";
const native_handle_t* handle = nullptr;
@@ -150,3 +190,4 @@
CHECK(handle == nullptr) << handle;
},
};
+// clang-format on
diff --git a/libs/binder/fuzzer/main.cpp b/libs/binder/fuzzer/main.cpp
index 369aa34..6657edb 100644
--- a/libs/binder/fuzzer/main.cpp
+++ b/libs/binder/fuzzer/main.cpp
@@ -34,28 +34,53 @@
P p;
p.setData(input.data(), input.size());
+ // since we are only using a byte to index
+ CHECK(reads.size() <= 255) << reads.size();
+
for (size_t i = 0; i < instructions.size() - 1; i += 2) {
uint8_t a = instructions[i];
+ uint8_t readIdx = a % reads.size();
+
uint8_t b = instructions[i + 1];
- FUZZ_LOG() << "size: " << p.dataSize() << " avail: " << p.dataAvail()
- << " pos: " << p.dataPosition() << " cap: " << p.dataCapacity();
+ FUZZ_LOG() << "Instruction: " << (i / 2) + 1 << "/" << instructions.size() / 2
+ << " cmd: " << static_cast<size_t>(a) << " (" << static_cast<size_t>(readIdx)
+ << ") arg: " << static_cast<size_t>(b) << " size: " << p.dataSize()
+ << " avail: " << p.dataAvail() << " pos: " << p.dataPosition()
+ << " cap: " << p.dataCapacity();
- reads[a % reads.size()](p, b);
+ reads[readIdx](p, b);
}
}
void fuzz(uint8_t options, const std::vector<uint8_t>& input, const std::vector<uint8_t>& instructions) {
- (void) options;
+ uint8_t parcelType = options & 0x3;
- // although they will do completely different things, might as well fuzz both
- doFuzz<::android::hardware::Parcel>(HWBINDER_PARCEL_READ_FUNCTIONS, input, instructions);
- doFuzz<::android::Parcel>(BINDER_PARCEL_READ_FUNCTIONS, input, instructions);
- doFuzz<NdkParcelAdapter>(BINDER_NDK_PARCEL_READ_FUNCTIONS, input, instructions);
+ switch (parcelType) {
+ case 0x0:
+ doFuzz<::android::hardware::Parcel>(HWBINDER_PARCEL_READ_FUNCTIONS, input,
+ instructions);
+ break;
+ case 0x1:
+ doFuzz<::android::Parcel>(BINDER_PARCEL_READ_FUNCTIONS, input, instructions);
+ break;
+ case 0x2:
+ doFuzz<NdkParcelAdapter>(BINDER_NDK_PARCEL_READ_FUNCTIONS, input, instructions);
+ break;
+ case 0x3:
+ /*reserved for future use*/
+ break;
+ default:
+ LOG_ALWAYS_FATAL("unknown parcel type %d", static_cast<int>(parcelType));
+ }
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (size <= 1) return 0; // no use
+
+ // avoid timeouts, see b/142617274, b/142473153
+ if (size > 50000) return 0;
+
uint8_t options = *data;
data++;
size--;
diff --git a/libs/binder/fuzzer/util.cpp b/libs/binder/fuzzer/util.cpp
index b1213e9..479f406 100644
--- a/libs/binder/fuzzer/util.cpp
+++ b/libs/binder/fuzzer/util.cpp
@@ -24,13 +24,17 @@
std::string hexString(const void* bytes, size_t len) {
if (bytes == nullptr) return "<null>";
- std::ostringstream s;
- s << std::hex << std::setfill('0');
+ const uint8_t* bytes8 = static_cast<const uint8_t*>(bytes);
+ char chars[] = "0123456789abcdef";
+ std::string result;
+ result.resize(len * 2);
+
for (size_t i = 0; i < len; i++) {
- s << std::setw(2) << static_cast<int>(
- static_cast<const uint8_t*>(bytes)[i]);
+ result[2 * i] = chars[bytes8[i] >> 4];
+ result[2 * i + 1] = chars[bytes8[i] & 0xf];
}
- return s.str();
+
+ return result;
}
std::string hexString(const std::vector<uint8_t>& bytes) {
return hexString(bytes.data(), bytes.size());
diff --git a/libs/binder/fuzzer/util.h b/libs/binder/fuzzer/util.h
index 416c3a7..aa504d2 100644
--- a/libs/binder/fuzzer/util.h
+++ b/libs/binder/fuzzer/util.h
@@ -23,27 +23,31 @@
#error "Must define FUZZ_LOG_TAG"
#endif
-#define ENABLE_LOG_FUZZ 1
-#define FUZZ_LOG() FuzzLog(FUZZ_LOG_TAG, ENABLE_LOG_FUZZ).log()
+#define FUZZ_LOG() FuzzLog(FUZZ_LOG_TAG).log()
+#ifdef ENABLE_LOG_FUZZ
class FuzzLog {
public:
- FuzzLog(const std::string& tag, bool log) : mTag(tag), mLog(log) {}
- ~FuzzLog() {
- if (mLog) {
- std::cout << mTag << ": " << mOs.str() << std::endl;
- }
- }
+ FuzzLog(const char* tag) : mTag(tag) {}
+ ~FuzzLog() { std::cout << mTag << ": " << mOs.str() << std::endl; }
- std::stringstream& log() {
- return mOs;
- }
+ std::stringstream& log() { return mOs; }
private:
- std::string mTag;
- bool mLog;
+ const char* mTag = nullptr;
std::stringstream mOs;
};
+#else
+class FuzzLog {
+public:
+ FuzzLog(const char* /*tag*/) {}
+ template <typename T>
+ FuzzLog& operator<<(const T& /*t*/) {
+ return *this;
+ }
+ FuzzLog& log() { return *this; }
+};
+#endif
std::string hexString(const void* bytes, size_t len);
std::string hexString(const std::vector<uint8_t>& bytes);
diff --git a/libs/binder/include/binder/AppOpsManager.h b/libs/binder/include/binder/AppOpsManager.h
index 0ab40b8..2744ce1 100644
--- a/libs/binder/include/binder/AppOpsManager.h
+++ b/libs/binder/include/binder/AppOpsManager.h
@@ -130,16 +130,17 @@
int32_t checkOp(int32_t op, int32_t uid, const String16& callingPackage);
int32_t checkAudioOpNoThrow(int32_t op, int32_t usage, int32_t uid,
const String16& callingPackage);
- // @Deprecated, use noteOp(int32_t, int32_t uid, const String16&, const String16&) instead
+ // @Deprecated, use noteOp(int32_t, int32_t uid, const String16&, const String16&,
+ // const String16&) instead
int32_t noteOp(int32_t op, int32_t uid, const String16& callingPackage);
int32_t noteOp(int32_t op, int32_t uid, const String16& callingPackage,
- const String16& message);
- // @Deprecated, use startOpNoThrow(int32_t, int32_t, const String16&, bool, const String16&)
- // instead
+ const String16& featureId, const String16& message);
+ // @Deprecated, use startOpNoThrow(int32_t, int32_t, const String16&, bool, const String16&,
+ // const String16&) instead
int32_t startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage,
bool startIfModeDefault);
int32_t startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage,
- bool startIfModeDefault, const String16& message);
+ bool startIfModeDefault, const String16& featureId, const String16& message);
void finishOp(int32_t op, int32_t uid, const String16& callingPackage);
void startWatchingMode(int32_t op, const String16& packageName,
const sp<IAppOpsCallback>& callback);
@@ -147,7 +148,7 @@
int32_t permissionToOpCode(const String16& permission);
void setCameraAudioRestriction(int32_t mode);
void noteAsyncOp(const String16& callingPackageName, int32_t uid, const String16& packageName,
- int32_t opCode, const String16& message);
+ int32_t opCode, const String16& featureId, const String16& message);
private:
Mutex mLock;
@@ -155,7 +156,7 @@
sp<IAppOpsService> getService();
void markAppOpNoted(int32_t uid, const String16& packageName, int32_t opCode,
- const String16& message);
+ const String16& featureId, const String16& message);
bool shouldCollectNotes(int32_t opCode);
};
diff --git a/libs/binder/include/binder/IAppOpsService.h b/libs/binder/include/binder/IAppOpsService.h
index 8b8a3c2..ad34bc5 100644
--- a/libs/binder/include/binder/IAppOpsService.h
+++ b/libs/binder/include/binder/IAppOpsService.h
@@ -49,7 +49,8 @@
const String16& packageName) = 0;
virtual void setCameraAudioRestriction(int32_t mode) = 0;
virtual void noteAsyncOp(const String16& callingPackageName, int32_t uid,
- const String16& packageName, int32_t opCode, const String16& message) = 0;
+ const String16& packageName, int32_t opCode, const String16& featureId,
+ const String16& message) = 0;
virtual bool shouldCollectNotes(int32_t opCode) = 0;
enum {
diff --git a/libs/binder/include/binder/IBinder.h b/libs/binder/include/binder/IBinder.h
index 64f3052..64604b7 100644
--- a/libs/binder/include/binder/IBinder.h
+++ b/libs/binder/include/binder/IBinder.h
@@ -62,7 +62,11 @@
DEBUG_PID_TRANSACTION = B_PACK_CHARS('_', 'P', 'I', 'D'),
// Corresponds to TF_ONE_WAY -- an asynchronous call.
- FLAG_ONEWAY = 0x00000001
+ FLAG_ONEWAY = 0x00000001,
+
+ // Private userspace flag for transaction which is being requested from
+ // a vendor context.
+ FLAG_PRIVATE_VENDOR = 0x10000000,
};
IBinder();
diff --git a/libs/binder/include/binder/Parcel.h b/libs/binder/include/binder/Parcel.h
index 8726681..0f8abab 100644
--- a/libs/binder/include/binder/Parcel.h
+++ b/libs/binder/include/binder/Parcel.h
@@ -19,6 +19,7 @@
#include <map> // for legacy reasons
#include <string>
+#include <type_traits>
#include <vector>
#include <android-base/unique_fd.h>
@@ -157,6 +158,18 @@
status_t writeStrongBinderVector(const std::unique_ptr<std::vector<sp<IBinder>>>& val);
status_t writeStrongBinderVector(const std::vector<sp<IBinder>>& val);
+ // Write an Enum vector with underlying type int8_t.
+ // Does not use padding; each byte is contiguous.
+ template<typename T, std::enable_if_t<std::is_enum_v<T> && std::is_same_v<typename std::underlying_type_t<T>,int8_t>, bool> = 0>
+ status_t writeEnumVector(const std::vector<T>& val);
+ template<typename T, std::enable_if_t<std::is_enum_v<T> && std::is_same_v<typename std::underlying_type_t<T>,int8_t>, bool> = 0>
+ status_t writeEnumVector(const std::unique_ptr<std::vector<T>>& val);
+ // Write an Enum vector with underlying type != int8_t.
+ template<typename T, std::enable_if_t<std::is_enum_v<T> && !std::is_same_v<typename std::underlying_type_t<T>,int8_t>, bool> = 0>
+ status_t writeEnumVector(const std::vector<T>& val);
+ template<typename T, std::enable_if_t<std::is_enum_v<T> && !std::is_same_v<typename std::underlying_type_t<T>,int8_t>, bool> = 0>
+ status_t writeEnumVector(const std::unique_ptr<std::vector<T>>& val);
+
template<typename T>
status_t writeParcelableVector(const std::unique_ptr<std::vector<std::unique_ptr<T>>>& val);
template<typename T>
@@ -275,6 +288,19 @@
status_t readStrongBinder(sp<IBinder>* val) const;
status_t readNullableStrongBinder(sp<IBinder>* val) const;
+
+ // Read an Enum vector with underlying type int8_t.
+ // Does not use padding; each byte is contiguous.
+ template<typename T, std::enable_if_t<std::is_enum_v<T> && std::is_same_v<typename std::underlying_type_t<T>,int8_t>, bool> = 0>
+ status_t readEnumVector(std::vector<T>* val) const;
+ template<typename T, std::enable_if_t<std::is_enum_v<T> && std::is_same_v<typename std::underlying_type_t<T>,int8_t>, bool> = 0>
+ status_t readEnumVector(std::unique_ptr<std::vector<T>>* val) const;
+ // Read an Enum vector with underlying type != int8_t.
+ template<typename T, std::enable_if_t<std::is_enum_v<T> && !std::is_same_v<typename std::underlying_type_t<T>,int8_t>, bool> = 0>
+ status_t readEnumVector(std::vector<T>* val) const;
+ template<typename T, std::enable_if_t<std::is_enum_v<T> && !std::is_same_v<typename std::underlying_type_t<T>,int8_t>, bool> = 0>
+ status_t readEnumVector(std::unique_ptr<std::vector<T>>* val) const;
+
template<typename T>
status_t readParcelableVector(
std::unique_ptr<std::vector<std::unique_ptr<T>>>* val) const;
@@ -438,6 +464,19 @@
status_t writeRawNullableParcelable(const Parcelable*
parcelable);
+ template<typename T, std::enable_if_t<std::is_same_v<typename std::underlying_type_t<T>,int32_t>, bool> = 0>
+ status_t writeEnum(const T& val);
+ template<typename T, std::enable_if_t<std::is_same_v<typename std::underlying_type_t<T>,int64_t>, bool> = 0>
+ status_t writeEnum(const T& val);
+
+ template<typename T, std::enable_if_t<std::is_same_v<typename std::underlying_type_t<T>,int32_t>, bool> = 0>
+ status_t readEnum(T* pArg) const;
+ template<typename T, std::enable_if_t<std::is_same_v<typename std::underlying_type_t<T>,int64_t>, bool> = 0>
+ status_t readEnum(T* pArg) const;
+
+ status_t writeByteVectorInternal(const int8_t* data, size_t size);
+ status_t readByteVectorInternal(int8_t* data, size_t size) const;
+
template<typename T, typename U>
status_t unsafeReadTypedVector(std::vector<T>* val,
status_t(Parcel::*read_func)(U*) const) const;
@@ -913,6 +952,66 @@
return unsafeWriteTypedVector(*val, &Parcel::writeNullableParcelable<T>);
}
+template<typename T, std::enable_if_t<std::is_same_v<typename std::underlying_type_t<T>,int32_t>, bool>>
+status_t Parcel::writeEnum(const T& val) {
+ return writeInt32(static_cast<int32_t>(val));
+}
+template<typename T, std::enable_if_t<std::is_same_v<typename std::underlying_type_t<T>,int64_t>, bool>>
+status_t Parcel::writeEnum(const T& val) {
+ return writeInt64(static_cast<int64_t>(val));
+}
+
+template<typename T, std::enable_if_t<std::is_enum_v<T> && std::is_same_v<typename std::underlying_type_t<T>,int8_t>, bool>>
+status_t Parcel::writeEnumVector(const std::vector<T>& val) {
+ return writeByteVectorInternal(reinterpret_cast<const int8_t*>(val.data()), val.size());
+}
+template<typename T, std::enable_if_t<std::is_enum_v<T> && std::is_same_v<typename std::underlying_type_t<T>,int8_t>, bool>>
+status_t Parcel::writeEnumVector(const std::unique_ptr<std::vector<T>>& val) {
+ if (!val) return writeInt32(-1);
+ return writeByteVectorInternal(reinterpret_cast<const int8_t*>(val->data()), val->size());
+}
+template<typename T, std::enable_if_t<std::is_enum_v<T> && !std::is_same_v<typename std::underlying_type_t<T>,int8_t>, bool>>
+status_t Parcel::writeEnumVector(const std::vector<T>& val) {
+ return writeTypedVector(val, &Parcel::writeEnum);
+}
+template<typename T, std::enable_if_t<std::is_enum_v<T> && !std::is_same_v<typename std::underlying_type_t<T>,int8_t>, bool>>
+status_t Parcel::writeEnumVector(const std::unique_ptr<std::vector<T>>& val) {
+ return writeNullableTypedVector(val, &Parcel::writeEnum);
+}
+
+template<typename T, std::enable_if_t<std::is_same_v<typename std::underlying_type_t<T>,int32_t>, bool>>
+status_t Parcel::readEnum(T* pArg) const {
+ return readInt32(reinterpret_cast<int32_t *>(pArg));
+}
+template<typename T, std::enable_if_t<std::is_same_v<typename std::underlying_type_t<T>,int64_t>, bool>>
+status_t Parcel::readEnum(T* pArg) const {
+ return readInt64(reinterpret_cast<int64_t *>(pArg));
+}
+
+template<typename T, std::enable_if_t<std::is_enum_v<T> && std::is_same_v<typename std::underlying_type_t<T>,int8_t>, bool>>
+status_t Parcel::readEnumVector(std::vector<T>* val) const {
+ if (status_t status = resizeOutVector(val); status != OK) return status;
+ return readByteVectorInternal(reinterpret_cast<int8_t*>(val->data()), val->size());
+}
+template<typename T, std::enable_if_t<std::is_enum_v<T> && std::is_same_v<typename std::underlying_type_t<T>,int8_t>, bool>>
+status_t Parcel::readEnumVector(std::unique_ptr<std::vector<T>>* val) const {
+ if (status_t status = resizeOutVector(val); status != OK) return status;
+ if (val->get() == nullptr) {
+ // resizeOutVector does not create the out vector if size is < 0.
+ // This occurs when writing a null Enum vector.
+ return OK;
+ }
+ return readByteVectorInternal(reinterpret_cast<int8_t*>((*val)->data()), (*val)->size());
+}
+template<typename T, std::enable_if_t<std::is_enum_v<T> && !std::is_same_v<typename std::underlying_type_t<T>,int8_t>, bool>>
+status_t Parcel::readEnumVector(std::vector<T>* val) const {
+ return readTypedVector(val, &Parcel::readEnum);
+}
+template<typename T, std::enable_if_t<std::is_enum_v<T> && !std::is_same_v<typename std::underlying_type_t<T>,int8_t>, bool>>
+status_t Parcel::readEnumVector(std::unique_ptr<std::vector<T>>* val) const {
+ return readNullableTypedVector(val, &Parcel::readEnum);
+}
+
// ---------------------------------------------------------------------------
inline TextOutput& operator<<(TextOutput& to, const Parcel& parcel)
diff --git a/libs/binder/ndk/ibinder.cpp b/libs/binder/ndk/ibinder.cpp
index b06ca86..e752c45 100644
--- a/libs/binder/ndk/ibinder.cpp
+++ b/libs/binder/ndk/ibinder.cpp
@@ -17,6 +17,7 @@
#include <android/binder_ibinder.h>
#include "ibinder_internal.h"
+#include <android/binder_stability.h>
#include <android/binder_status.h>
#include "parcel_internal.h"
#include "status_internal.h"
@@ -542,7 +543,8 @@
return STATUS_UNKNOWN_TRANSACTION;
}
- if ((flags & ~FLAG_ONEWAY) != 0) {
+ constexpr binder_flags_t kAllFlags = FLAG_PRIVATE_VENDOR | FLAG_ONEWAY;
+ if ((flags & ~kAllFlags) != 0) {
LOG(ERROR) << __func__ << ": Unrecognized flags sent: " << flags;
return STATUS_BAD_VALUE;
}
diff --git a/libs/binder/ndk/include_ndk/android/binder_auto_utils.h b/libs/binder/ndk/include_ndk/android/binder_auto_utils.h
index c6868b0..dc3c8d2 100644
--- a/libs/binder/ndk/include_ndk/android/binder_auto_utils.h
+++ b/libs/binder/ndk/include_ndk/android/binder_auto_utils.h
@@ -201,7 +201,22 @@
/**
* See AStatus_isOk.
*/
- bool isOk() { return get() != nullptr && AStatus_isOk(get()); }
+ bool isOk() const { return get() != nullptr && AStatus_isOk(get()); }
+
+ /**
+ * See AStatus_getExceptionCode
+ */
+ binder_exception_t getExceptionCode() const { return AStatus_getExceptionCode(get()); }
+
+ /**
+ * See AStatus_getServiceSpecificError
+ */
+ int32_t getServiceSpecificError() const { return AStatus_getServiceSpecificError(get()); }
+
+ /**
+ * See AStatus_getStatus
+ */
+ binder_status_t getStatus() const { return AStatus_getStatus(get()); }
/**
* Convenience method for okay status.
diff --git a/libs/binder/ndk/include_platform/android/binder_stability.h b/libs/binder/ndk/include_platform/android/binder_stability.h
index b03fce1..e1a8cfd 100644
--- a/libs/binder/ndk/include_platform/android/binder_stability.h
+++ b/libs/binder/ndk/include_platform/android/binder_stability.h
@@ -20,7 +20,21 @@
__BEGIN_DECLS
-#if defined(__ANDROID_VNDK__) && !defined(__ANDROID_APEX__)
+/**
+ * Private addition to binder_flag_t.
+ */
+enum {
+ /**
+ * Indicates that this transaction is coupled w/ vendor.img
+ */
+ FLAG_PRIVATE_VENDOR = 0x10000000,
+};
+
+#if (defined(__ANDROID_VNDK__) && !defined(__ANDROID_APEX__))
+
+enum {
+ FLAG_PRIVATE_LOCAL = FLAG_PRIVATE_VENDOR,
+};
/**
* This interface has the stability of the vendor image.
@@ -33,6 +47,10 @@
#else // defined(__ANDROID_VNDK__) && !defined(__ANDROID_APEX__)
+enum {
+ FLAG_PRIVATE_LOCAL = 0,
+};
+
/**
* This interface has the stability of the system image.
*/
diff --git a/libs/binder/ndk/test/Android.bp b/libs/binder/ndk/test/Android.bp
index bb1fe2f..1c5dba3 100644
--- a/libs/binder/ndk/test/Android.bp
+++ b/libs/binder/ndk/test/Android.bp
@@ -67,3 +67,31 @@
srcs: ["main_server.cpp"],
gtest: false,
}
+
+cc_test {
+ name: "binderVendorDoubleLoadTest",
+ vendor: true,
+ srcs: [
+ "binderVendorDoubleLoadTest.cpp",
+ ],
+ static_libs: [
+ "IBinderVendorDoubleLoadTest-cpp",
+ "IBinderVendorDoubleLoadTest-ndk_platform",
+ ],
+ shared_libs: [
+ "libbase",
+ "libbinder",
+ "libbinder_ndk",
+ "libutils",
+ ],
+ test_suites: ["device-tests"],
+}
+
+aidl_interface {
+ name: "IBinderVendorDoubleLoadTest",
+ // TODO(b/119771576): only vendor is needed
+ vendor_available: true,
+ srcs: [
+ "IBinderVendorDoubleLoadTest.aidl",
+ ],
+}
diff --git a/libs/binder/ndk/test/AndroidTest.xml b/libs/binder/ndk/test/AndroidTest.xml
new file mode 100644
index 0000000..89646f7
--- /dev/null
+++ b/libs/binder/ndk/test/AndroidTest.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2019 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.
+-->
+<configuration description="Runs binderVendorDoubleLoadTest.">
+ <option name="test-suite-tag" value="apct" />
+ <option name="test-suite-tag" value="apct-native" />
+
+ <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer"/>
+
+ <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
+ <option name="cleanup" value="true" />
+ <option name="push" value="binderVendorDoubleLoadTest->/data/nativetest/vendor/binderVendorDoubleLoadTest" />
+ </target_preparer>
+
+ <test class="com.android.tradefed.testtype.GTest" >
+ <option name="native-test-device-path" value="/data/nativetest/vendor" />
+ <option name="module-name" value="binderVendorDoubleLoadTest" />
+ </test>
+</configuration>
+
diff --git a/libs/binder/ndk/test/IBinderVendorDoubleLoadTest.aidl b/libs/binder/ndk/test/IBinderVendorDoubleLoadTest.aidl
new file mode 100644
index 0000000..3a5bd9c
--- /dev/null
+++ b/libs/binder/ndk/test/IBinderVendorDoubleLoadTest.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+interface IBinderVendorDoubleLoadTest {
+ @utf8InCpp String RepeatString(@utf8InCpp String toRepeat);
+}
diff --git a/libs/binder/ndk/test/binderVendorDoubleLoadTest.cpp b/libs/binder/ndk/test/binderVendorDoubleLoadTest.cpp
new file mode 100644
index 0000000..f72dc36
--- /dev/null
+++ b/libs/binder/ndk/test/binderVendorDoubleLoadTest.cpp
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <BnBinderVendorDoubleLoadTest.h>
+#include <aidl/BnBinderVendorDoubleLoadTest.h>
+#include <android-base/logging.h>
+#include <android-base/properties.h>
+#include <android-base/strings.h>
+#include <android/binder_ibinder.h>
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
+#include <android/binder_stability.h>
+#include <binder/IPCThreadState.h>
+#include <binder/IServiceManager.h>
+#include <binder/ProcessState.h>
+#include <binder/Stability.h>
+#include <binder/Status.h>
+#include <gtest/gtest.h>
+
+#include <sys/prctl.h>
+
+using namespace android;
+using ::android::base::EndsWith;
+using ::android::base::GetProperty;
+using ::android::base::Split;
+using ::android::binder::Status;
+using ::android::internal::Stability;
+using ::ndk::ScopedAStatus;
+using ::ndk::SharedRefBase;
+using ::ndk::SpAIBinder;
+
+static const std::string kLocalNdkServerName = "NdkServer-local-IBinderVendorDoubleLoadTest";
+static const std::string kRemoteNdkServerName = "NdkServer-remote-IBinderVendorDoubleLoadTest";
+
+class NdkServer : public aidl::BnBinderVendorDoubleLoadTest {
+ ScopedAStatus RepeatString(const std::string& in, std::string* out) override {
+ *out = in;
+ return ScopedAStatus::ok();
+ }
+};
+class CppServer : public BnBinderVendorDoubleLoadTest {
+ Status RepeatString(const std::string& in, std::string* out) override {
+ *out = in;
+ return Status::ok();
+ }
+};
+
+TEST(DoubleBinder, VendorCppCantCallIntoSystem) {
+ Vector<String16> services = defaultServiceManager()->listServices();
+ EXPECT_TRUE(services.empty());
+}
+
+TEST(DoubleBinder, VendorCppCantRegisterService) {
+ sp<CppServer> cppServer = new CppServer;
+ status_t status = defaultServiceManager()->addService(String16("anything"), cppServer);
+ EXPECT_EQ(EX_TRANSACTION_FAILED, status);
+}
+
+TEST(DoubleBinder, CppVendorCantManuallyMarkVintfStability) {
+ // this test also implies that stability logic is turned on in vendor
+ ASSERT_DEATH(
+ {
+ sp<IBinder> binder = new CppServer();
+ Stability::markVintf(binder.get());
+ },
+ "Should only mark known object.");
+}
+
+TEST(DoubleBinder, NdkVendorCantManuallyMarkVintfStability) {
+ // this test also implies that stability logic is turned on in vendor
+ ASSERT_DEATH(
+ {
+ std::shared_ptr<NdkServer> ndkServer = SharedRefBase::make<NdkServer>();
+ AIBinder_markVintfStability(ndkServer->asBinder().get());
+ },
+ "Should only mark known object.");
+}
+
+TEST(DoubleBinder, CallIntoNdk) {
+ for (const std::string& serviceName : {kLocalNdkServerName, kRemoteNdkServerName}) {
+ SpAIBinder binder = SpAIBinder(AServiceManager_checkService(serviceName.c_str()));
+ ASSERT_NE(nullptr, binder.get()) << serviceName;
+ EXPECT_EQ(STATUS_OK, AIBinder_ping(binder.get())) << serviceName;
+
+ std::shared_ptr<aidl::IBinderVendorDoubleLoadTest> server =
+ aidl::IBinderVendorDoubleLoadTest::fromBinder(binder);
+
+ ASSERT_NE(nullptr, server.get()) << serviceName;
+
+ EXPECT_EQ(STATUS_OK, AIBinder_ping(server->asBinder().get()));
+
+ std::string outString;
+ ScopedAStatus status = server->RepeatString("foo", &outString);
+ EXPECT_EQ(STATUS_OK, AStatus_getExceptionCode(status.get())) << serviceName;
+ EXPECT_EQ("foo", outString) << serviceName;
+ }
+}
+
+void initDrivers() {
+ // Explicitly instantiated with the same driver that system would use.
+ // __ANDROID_VNDK__ right now uses /dev/vndbinder by default.
+ ProcessState::initWithDriver("/dev/binder");
+ ProcessState::self()->startThreadPool();
+ ABinderProcess_startThreadPool();
+}
+
+int main(int argc, char** argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+
+ if (fork() == 0) {
+ // child process
+
+ prctl(PR_SET_PDEATHSIG, SIGHUP);
+
+ initDrivers();
+
+ // REMOTE SERVERS
+ std::shared_ptr<NdkServer> ndkServer = SharedRefBase::make<NdkServer>();
+ CHECK(STATUS_OK == AServiceManager_addService(ndkServer->asBinder().get(),
+ kRemoteNdkServerName.c_str()));
+
+ // OR sleep forever or whatever, it doesn't matter
+ IPCThreadState::self()->joinThreadPool(true);
+ exit(1); // should not reach
+ }
+
+ sleep(1);
+
+ initDrivers();
+
+ // LOCAL SERVERS
+ std::shared_ptr<NdkServer> ndkServer = SharedRefBase::make<NdkServer>();
+ AServiceManager_addService(ndkServer->asBinder().get(), kLocalNdkServerName.c_str());
+
+ return RUN_ALL_TESTS();
+}
diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp
index 30f5f73..2859111 100644
--- a/libs/graphicsenv/GraphicsEnv.cpp
+++ b/libs/graphicsenv/GraphicsEnv.cpp
@@ -307,6 +307,13 @@
}
}
+bool GraphicsEnv::setInjectLayersPrSetDumpable() {
+ if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
+ return false;
+ }
+ return true;
+}
+
void* GraphicsEnv::loadLibrary(std::string name) {
const android_dlextinfo dlextinfo = {
.flags = ANDROID_DLEXT_USE_NAMESPACE,
diff --git a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h
index a47f468..83448d4 100644
--- a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h
+++ b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h
@@ -68,6 +68,14 @@
void setDriverLoaded(GpuStatsInfo::Api api, bool isDriverLoaded, int64_t driverLoadingTime);
/*
+ * Api for Vk/GL layer injection. Presently, drivers enable certain
+ * profiling features when prctl(PR_GET_DUMPABLE) returns true.
+ * Calling this when layer injection metadata is present allows the driver
+ * to enable profiling even when in a non-debuggable app
+ */
+ bool setInjectLayersPrSetDumpable();
+
+ /*
* Apis for ANGLE
*/
// Check if the requested app should use ANGLE.
diff --git a/libs/gui/Android.bp b/libs/gui/Android.bp
index da51675..e6d442d 100644
--- a/libs/gui/Android.bp
+++ b/libs/gui/Android.bp
@@ -35,6 +35,7 @@
":libgui_bufferqueue_sources",
"BitTube.cpp",
+ "BLASTBufferQueue.cpp",
"BufferHubConsumer.cpp",
"BufferHubProducer.cpp",
"BufferItemConsumer.cpp",
diff --git a/libs/gui/BLASTBufferQueue.cpp b/libs/gui/BLASTBufferQueue.cpp
new file mode 100644
index 0000000..9a50175
--- /dev/null
+++ b/libs/gui/BLASTBufferQueue.cpp
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gui/BLASTBufferQueue.h>
+#include <gui/BufferItemConsumer.h>
+
+#include <chrono>
+
+using namespace std::chrono_literals;
+
+namespace android {
+
+BLASTBufferQueue::BLASTBufferQueue(const sp<SurfaceControl>& surface, int width, int height)
+ : mSurfaceControl(surface), mWidth(width), mHeight(height) {
+ BufferQueue::createBufferQueue(&mProducer, &mConsumer);
+ mBufferItemConsumer =
+ new BufferItemConsumer(mConsumer, AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER, 1, true);
+ mBufferItemConsumer->setName(String8("BLAST Consumer"));
+ mBufferItemConsumer->setFrameAvailableListener(this);
+ mBufferItemConsumer->setBufferFreedListener(this);
+ mBufferItemConsumer->setDefaultBufferSize(mWidth, mHeight);
+ mBufferItemConsumer->setDefaultBufferFormat(PIXEL_FORMAT_RGBA_8888);
+}
+
+void BLASTBufferQueue::update(const sp<SurfaceControl>& surface, int width, int height) {
+ std::unique_lock _lock{mMutex};
+ mSurfaceControl = surface;
+ mWidth = width;
+ mHeight = height;
+ mBufferItemConsumer->setDefaultBufferSize(mWidth, mHeight);
+}
+
+static void transactionCallbackThunk(void* context, nsecs_t latchTime,
+ const sp<Fence>& presentFence,
+ const std::vector<SurfaceControlStats>& stats) {
+ if (context == nullptr) {
+ return;
+ }
+ BLASTBufferQueue* bq = static_cast<BLASTBufferQueue*>(context);
+ bq->transactionCallback(latchTime, presentFence, stats);
+}
+
+void BLASTBufferQueue::transactionCallback(nsecs_t /*latchTime*/, const sp<Fence>& /*presentFence*/,
+ const std::vector<SurfaceControlStats>& stats) {
+ std::unique_lock _lock{mMutex};
+
+ if (stats.size() > 0 && mNextCallbackBufferItem.mGraphicBuffer != nullptr) {
+ mBufferItemConsumer->releaseBuffer(mNextCallbackBufferItem,
+ stats[0].previousReleaseFence
+ ? stats[0].previousReleaseFence
+ : Fence::NO_FENCE);
+ mNextCallbackBufferItem = BufferItem();
+ }
+ mDequeueWaitCV.notify_all();
+ decStrong((void*)transactionCallbackThunk);
+}
+
+void BLASTBufferQueue::onFrameAvailable(const BufferItem& item) {
+ std::unique_lock _lock{mMutex};
+
+ SurfaceComposerClient::Transaction localTransaction;
+ bool applyTransaction = true;
+ SurfaceComposerClient::Transaction* t = &localTransaction;
+ if (mNextTransaction != nullptr) {
+ t = mNextTransaction;
+ mNextTransaction = nullptr;
+ applyTransaction = false;
+ }
+
+ int status = OK;
+ mNextCallbackBufferItem = mLastSubmittedBufferItem;
+
+ mLastSubmittedBufferItem = BufferItem();
+ status = mBufferItemConsumer->acquireBuffer(&mLastSubmittedBufferItem, -1, false);
+ if (status != OK) {
+ ALOGE("Failed to acquire?");
+ }
+
+ auto buffer = mLastSubmittedBufferItem.mGraphicBuffer;
+
+ if (buffer == nullptr) {
+ ALOGE("Null buffer");
+ return;
+ }
+
+
+ // Ensure BLASTBufferQueue stays alive until we receive the transaction complete callback.
+ incStrong((void*)transactionCallbackThunk);
+
+ t->setBuffer(mSurfaceControl, buffer);
+ t->setAcquireFence(mSurfaceControl,
+ item.mFence ? new Fence(item.mFence->dup()) : Fence::NO_FENCE);
+ t->addTransactionCompletedCallback(transactionCallbackThunk, static_cast<void*>(this));
+
+ t->setFrame(mSurfaceControl, {0, 0, (int32_t)buffer->getWidth(), (int32_t)buffer->getHeight()});
+ t->setCrop(mSurfaceControl, {0, 0, (int32_t)buffer->getWidth(), (int32_t)buffer->getHeight()});
+
+ if (applyTransaction) {
+ ALOGE("Apply transaction");
+ t->apply();
+
+ if (mNextCallbackBufferItem.mGraphicBuffer != nullptr) {
+ mDequeueWaitCV.wait_for(_lock, 5000ms);
+ }
+ }
+}
+
+void BLASTBufferQueue::setNextTransaction(SurfaceComposerClient::Transaction* t) {
+ std::unique_lock _lock{mMutex};
+ mNextTransaction = t;
+}
+
+} // namespace android
diff --git a/libs/gui/include/gui/BLASTBufferQueue.h b/libs/gui/include/gui/BLASTBufferQueue.h
new file mode 100644
index 0000000..6320556
--- /dev/null
+++ b/libs/gui/include/gui/BLASTBufferQueue.h
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_GUI_BLAST_BUFFER_QUEUE_H
+#define ANDROID_GUI_BLAST_BUFFER_QUEUE_H
+
+#include <gui/IGraphicBufferProducer.h>
+#include <gui/BufferItemConsumer.h>
+#include <gui/BufferItem.h>
+#include <gui/SurfaceComposerClient.h>
+
+#include <utils/Condition.h>
+#include <utils/Mutex.h>
+#include <utils/RefBase.h>
+
+#include <system/window.h>
+
+namespace android {
+
+class BufferItemConsumer;
+
+class BLASTBufferQueue
+ : public ConsumerBase::FrameAvailableListener, public BufferItemConsumer::BufferFreedListener
+{
+public:
+ BLASTBufferQueue(const sp<SurfaceControl>& surface, int width, int height);
+ sp<IGraphicBufferProducer> getIGraphicBufferProducer() const {
+ return mProducer;
+ }
+
+ void onBufferFreed(const wp<GraphicBuffer>&/* graphicBuffer*/) override { /* TODO */ }
+ void onFrameReplaced(const BufferItem& item) override {onFrameAvailable(item);}
+ void onFrameAvailable(const BufferItem& item) override;
+
+ void transactionCallback(nsecs_t latchTime, const sp<Fence>& presentFence,
+ const std::vector<SurfaceControlStats>& stats);
+ void setNextTransaction(SurfaceComposerClient::Transaction *t);
+
+ void update(const sp<SurfaceControl>& surface, int width, int height);
+
+
+ virtual ~BLASTBufferQueue() = default;
+
+private:
+ friend class BLASTBufferQueueHelper;
+
+ // can't be copied
+ BLASTBufferQueue& operator = (const BLASTBufferQueue& rhs);
+ BLASTBufferQueue(const BLASTBufferQueue& rhs);
+
+ sp<SurfaceControl> mSurfaceControl;
+
+ mutable std::mutex mMutex;
+
+ static const int MAX_BUFFERS = 2;
+ struct BufferInfo {
+ sp<GraphicBuffer> buffer;
+ int fence;
+ };
+
+ int mDequeuedBuffers = 0;
+
+ int mWidth;
+ int mHeight;
+
+ BufferItem mLastSubmittedBufferItem;
+ BufferItem mNextCallbackBufferItem;
+ sp<Fence> mLastFence;
+
+ std::condition_variable mDequeueWaitCV;
+
+ sp<IGraphicBufferConsumer> mConsumer;
+ sp<IGraphicBufferProducer> mProducer;
+ sp<BufferItemConsumer> mBufferItemConsumer;
+
+ SurfaceComposerClient::Transaction* mNextTransaction = nullptr;
+};
+
+} // namespace android
+
+#endif // ANDROID_GUI_SURFACE_H
diff --git a/libs/gui/tests/Android.bp b/libs/gui/tests/Android.bp
index cbda6b2..7f960ab 100644
--- a/libs/gui/tests/Android.bp
+++ b/libs/gui/tests/Android.bp
@@ -13,7 +13,8 @@
],
srcs: [
- "BufferItemConsumer_test.cpp",
+ "BLASTBufferQueue_test.cpp",
+ "BufferItemConsumer_test.cpp",
"BufferQueue_test.cpp",
"CpuConsumer_test.cpp",
"EndToEndNativeInputTest.cpp",
diff --git a/libs/gui/tests/BLASTBufferQueue_test.cpp b/libs/gui/tests/BLASTBufferQueue_test.cpp
new file mode 100644
index 0000000..db1ac24
--- /dev/null
+++ b/libs/gui/tests/BLASTBufferQueue_test.cpp
@@ -0,0 +1,237 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#define LOG_TAG "BLASTBufferQueue_test"
+
+#include <gui/BLASTBufferQueue.h>
+
+#include <android/hardware/graphics/common/1.2/types.h>
+#include <gui/IGraphicBufferProducer.h>
+#include <gui/IProducerListener.h>
+#include <gui/SurfaceComposerClient.h>
+#include <private/gui/ComposerService.h>
+#include <ui/DisplayInfo.h>
+#include <ui/GraphicBuffer.h>
+#include <ui/GraphicTypes.h>
+
+#include <gtest/gtest.h>
+
+using namespace std::chrono_literals;
+
+namespace android {
+
+using Transaction = SurfaceComposerClient::Transaction;
+using android::hardware::graphics::common::V1_2::BufferUsage;
+
+class BLASTBufferQueueHelper {
+public:
+ BLASTBufferQueueHelper(const sp<SurfaceControl>& sc, int width, int height) {
+ mBlastBufferQueueAdapter = new BLASTBufferQueue(sc, width, height);
+ }
+
+ void update(const sp<SurfaceControl>& sc, int width, int height) {
+ mBlastBufferQueueAdapter->update(sc, width, height);
+ }
+
+ void setNextTransaction(Transaction* next) {
+ mBlastBufferQueueAdapter->setNextTransaction(next);
+ }
+
+ int getWidth() { return mBlastBufferQueueAdapter->mWidth; }
+
+ int getHeight() { return mBlastBufferQueueAdapter->mHeight; }
+
+ Transaction* getNextTransaction() { return mBlastBufferQueueAdapter->mNextTransaction; }
+
+ sp<IGraphicBufferProducer> getIGraphicBufferProducer() {
+ return mBlastBufferQueueAdapter->getIGraphicBufferProducer();
+ }
+
+ const sp<SurfaceControl> getSurfaceControl() {
+ return mBlastBufferQueueAdapter->mSurfaceControl;
+ }
+
+ void waitForCallback() {
+ std::unique_lock lock{mBlastBufferQueueAdapter->mMutex};
+ mBlastBufferQueueAdapter->mDequeueWaitCV.wait_for(lock, 1s);
+ }
+
+private:
+ sp<BLASTBufferQueue> mBlastBufferQueueAdapter;
+};
+
+class BLASTBufferQueueTest : public ::testing::Test {
+public:
+protected:
+ BLASTBufferQueueTest() {
+ const ::testing::TestInfo* const testInfo =
+ ::testing::UnitTest::GetInstance()->current_test_info();
+ ALOGV("Begin test: %s.%s", testInfo->test_case_name(), testInfo->name());
+ }
+
+ ~BLASTBufferQueueTest() {
+ const ::testing::TestInfo* const testInfo =
+ ::testing::UnitTest::GetInstance()->current_test_info();
+ ALOGV("End test: %s.%s", testInfo->test_case_name(), testInfo->name());
+ }
+
+ void SetUp() {
+ mComposer = ComposerService::getComposerService();
+ mClient = new SurfaceComposerClient();
+ mDisplayToken = mClient->getInternalDisplayToken();
+ ASSERT_NE(nullptr, mDisplayToken.get());
+ Transaction t;
+ t.setDisplayLayerStack(mDisplayToken, 0);
+ t.apply();
+ t.clear();
+
+ DisplayInfo info;
+ ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayInfo(mDisplayToken, &info));
+ mDisplayWidth = info.w;
+ mDisplayHeight = info.h;
+
+ mSurfaceControl = mClient->createSurface(String8("TestSurface"), mDisplayWidth,
+ mDisplayHeight, PIXEL_FORMAT_RGBA_8888,
+ ISurfaceComposerClient::eFXSurfaceBufferState,
+ /*parent*/ nullptr);
+ t.setLayerStack(mSurfaceControl, 0)
+ .setLayer(mSurfaceControl, std::numeric_limits<int32_t>::max())
+ .setFrame(mSurfaceControl, Rect(0, 0, mDisplayWidth, mDisplayHeight))
+ .show(mSurfaceControl)
+ .setDataspace(mSurfaceControl, ui::Dataspace::V0_SRGB)
+ .apply();
+ }
+
+ void fillBuffer(uint32_t* bufData, uint32_t width, uint32_t height, uint32_t stride, uint8_t r,
+ uint8_t g, uint8_t b) {
+ for (uint32_t row = 0; row < height; row++) {
+ for (uint32_t col = 0; col < width; col++) {
+ uint8_t* pixel = (uint8_t*)(bufData + (row * stride) + col);
+ *pixel = r;
+ *(pixel + 1) = g;
+ *(pixel + 2) = b;
+ *(pixel + 3) = 255;
+ }
+ }
+ }
+
+ void checkScreenCapture(uint8_t r, uint8_t g, uint8_t b) {
+ const auto width = mScreenCaptureBuf->getWidth();
+ const auto height = mScreenCaptureBuf->getHeight();
+ const auto stride = mScreenCaptureBuf->getStride();
+
+ uint32_t* bufData;
+ mScreenCaptureBuf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_READ_OFTEN),
+ reinterpret_cast<void**>(&bufData));
+
+ for (uint32_t row = 0; row < height; row++) {
+ for (uint32_t col = 0; col < width; col++) {
+ uint8_t* pixel = (uint8_t*)(bufData + (row * stride) + col);
+ EXPECT_EQ(r, *(pixel));
+ EXPECT_EQ(g, *(pixel + 1));
+ EXPECT_EQ(b, *(pixel + 2));
+ }
+ }
+ mScreenCaptureBuf->unlock();
+ ASSERT_EQ(false, ::testing::Test::HasFailure());
+ }
+
+ sp<SurfaceComposerClient> mClient;
+ sp<ISurfaceComposer> mComposer;
+
+ sp<IBinder> mDisplayToken;
+
+ sp<SurfaceControl> mSurfaceControl;
+ sp<GraphicBuffer> mScreenCaptureBuf;
+
+ uint32_t mDisplayWidth;
+ uint32_t mDisplayHeight;
+};
+
+TEST_F(BLASTBufferQueueTest, CreateBLASTBufferQueue) {
+ // create BLASTBufferQueue adapter associated with this surface
+ BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight);
+ ASSERT_EQ(mSurfaceControl, adapter.getSurfaceControl());
+ ASSERT_EQ(mDisplayWidth, adapter.getWidth());
+ ASSERT_EQ(mDisplayHeight, adapter.getHeight());
+ ASSERT_EQ(nullptr, adapter.getNextTransaction());
+}
+
+TEST_F(BLASTBufferQueueTest, Update) {
+ BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight);
+ sp<SurfaceControl> updateSurface =
+ mClient->createSurface(String8("UpdateTest"), mDisplayWidth / 2, mDisplayHeight / 2,
+ PIXEL_FORMAT_RGBA_8888);
+ adapter.update(updateSurface, mDisplayWidth / 2, mDisplayHeight / 2);
+ ASSERT_EQ(updateSurface, adapter.getSurfaceControl());
+ ASSERT_EQ(mDisplayWidth / 2, adapter.getWidth());
+ ASSERT_EQ(mDisplayHeight / 2, adapter.getHeight());
+}
+
+TEST_F(BLASTBufferQueueTest, SetNextTransaction) {
+ BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight);
+ Transaction next;
+ adapter.setNextTransaction(&next);
+ ASSERT_EQ(&next, adapter.getNextTransaction());
+}
+
+TEST_F(BLASTBufferQueueTest, onFrameAvailable_Apply) {
+ uint8_t r = 255;
+ uint8_t g = 0;
+ uint8_t b = 0;
+
+ BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight);
+ auto igbProducer = adapter.getIGraphicBufferProducer();
+ ASSERT_NE(nullptr, igbProducer.get());
+ IGraphicBufferProducer::QueueBufferOutput qbOutput;
+ ASSERT_EQ(NO_ERROR,
+ igbProducer->connect(new DummyProducerListener, NATIVE_WINDOW_API_CPU, false,
+ &qbOutput));
+ ASSERT_EQ(NO_ERROR, igbProducer->setMaxDequeuedBufferCount(3));
+
+ int slot;
+ sp<Fence> fence;
+ sp<GraphicBuffer> buf;
+ auto ret = igbProducer->dequeueBuffer(&slot, &fence, mDisplayWidth, mDisplayHeight,
+ PIXEL_FORMAT_RGBA_8888, GRALLOC_USAGE_SW_WRITE_OFTEN,
+ nullptr, nullptr);
+ ASSERT_EQ(IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION, ret);
+ ASSERT_EQ(OK, igbProducer->requestBuffer(slot, &buf));
+
+ uint32_t* bufData;
+ buf->lock(static_cast<uint32_t>(GraphicBuffer::USAGE_SW_WRITE_OFTEN),
+ reinterpret_cast<void**>(&bufData));
+ fillBuffer(bufData, buf->getWidth(), buf->getHeight(), buf->getStride(), r, g, b);
+ buf->unlock();
+
+ IGraphicBufferProducer::QueueBufferInput input(systemTime(), false, HAL_DATASPACE_UNKNOWN,
+ Rect(mDisplayWidth, mDisplayHeight),
+ NATIVE_WINDOW_SCALING_MODE_FREEZE, 0,
+ Fence::NO_FENCE);
+ igbProducer->queueBuffer(slot, input, &qbOutput);
+
+ adapter.waitForCallback();
+
+ // capture screen and verify that it is red
+ bool capturedSecureLayers;
+ ASSERT_EQ(NO_ERROR,
+ mComposer->captureScreen(mDisplayToken, &mScreenCaptureBuf, capturedSecureLayers,
+ ui::Dataspace::V0_SRGB, ui::PixelFormat::RGBA_8888, Rect(),
+ mDisplayWidth, mDisplayHeight,
+ /*useIdentityTransform*/ false));
+ ASSERT_NO_FATAL_FAILURE(checkScreenCapture(r, g, b));
+}
+} // namespace android
diff --git a/libs/gui/tests/EndToEndNativeInputTest.cpp b/libs/gui/tests/EndToEndNativeInputTest.cpp
index 09eeaea..03b9cd7 100644
--- a/libs/gui/tests/EndToEndNativeInputTest.cpp
+++ b/libs/gui/tests/EndToEndNativeInputTest.cpp
@@ -405,12 +405,11 @@
surface->expectTap(1, 1);
}
-/**
- * TODO(b/139494112) fix tests once we define expected behavior
- *
-// Ensure we send the input to the right surface when the surface visibility changes due to the
-// first buffer being submitted. ref: b/120839715
-TEST_F(InputSurfacesTest, input_respects_buffer_layer_buffer) {
+// TODO(b/139494112) update tests once we define expected behavior
+// Ensure we still send input to the surface regardless of surface visibility changes due to the
+// first buffer being submitted or alpha changes.
+// 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);
@@ -419,14 +418,14 @@
bufferSurface->showAt(10, 10);
injectTap(11, 11);
- bgSurface->expectTap(1, 1);
+ bufferSurface->expectTap(1, 1);
postBuffer(bufferSurface->mSurfaceControl);
injectTap(11, 11);
bufferSurface->expectTap(1, 1);
}
-TEST_F(InputSurfacesTest, input_respects_buffer_layer_alpha) {
+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);
@@ -441,10 +440,10 @@
bufferSurface->doTransaction([](auto &t, auto &sc) { t.setAlpha(sc, 0.0); });
injectTap(11, 11);
- bgSurface->expectTap(1, 1);
+ bufferSurface->expectTap(1, 1);
}
-TEST_F(InputSurfacesTest, input_respects_color_layer_alpha) {
+TEST_F(InputSurfacesTest, input_ignores_color_layer_alpha) {
std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100);
@@ -457,9 +456,8 @@
fgSurface->doTransaction([](auto &t, auto &sc) { t.setAlpha(sc, 0.0); });
injectTap(11, 11);
- bgSurface->expectTap(1, 1);
+ fgSurface->expectTap(1, 1);
}
-*/
TEST_F(InputSurfacesTest, input_respects_container_layer_visiblity) {
std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
diff --git a/libs/nativewindow/AHardwareBuffer.cpp b/libs/nativewindow/AHardwareBuffer.cpp
index 9bd3095..1ec73ce 100644
--- a/libs/nativewindow/AHardwareBuffer.cpp
+++ b/libs/nativewindow/AHardwareBuffer.cpp
@@ -266,10 +266,10 @@
char buf[CMSG_SPACE(kFdBufferSize)];
struct msghdr msg = {
- .msg_control = buf,
- .msg_controllen = sizeof(buf),
.msg_iov = &iov[0],
.msg_iovlen = 1,
+ .msg_control = buf,
+ .msg_controllen = sizeof(buf),
};
struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg);
@@ -306,10 +306,10 @@
iov[0].iov_len = kMessageBufferSize;
struct msghdr msg = {
- .msg_control = fdBuf,
- .msg_controllen = sizeof(fdBuf),
.msg_iov = &iov[0],
.msg_iovlen = 1,
+ .msg_control = fdBuf,
+ .msg_controllen = sizeof(fdBuf),
};
int result;
diff --git a/opengl/tests/gl_perf/fill_common.cpp b/opengl/tests/gl_perf/fill_common.cpp
index fefedc0..613f1c6 100644
--- a/opengl/tests/gl_perf/fill_common.cpp
+++ b/opengl/tests/gl_perf/fill_common.cpp
@@ -191,10 +191,10 @@
static void randUniform(int pgm, const char *var) {
GLint loc = glGetUniformLocation(pgm, var);
if (loc >= 0) {
- float x = ((float)rand()) / RAND_MAX;
- float y = ((float)rand()) / RAND_MAX;
- float z = ((float)rand()) / RAND_MAX;
- float w = ((float)rand()) / RAND_MAX;
+ float x = ((float)rand()) / (float)RAND_MAX;
+ float y = ((float)rand()) / (float)RAND_MAX;
+ float z = ((float)rand()) / (float)RAND_MAX;
+ float w = ((float)rand()) / (float)RAND_MAX;
glUniform4f(loc, x, y, z, w);
}
}
diff --git a/services/inputflinger/InputManager.cpp b/services/inputflinger/InputManager.cpp
index 7d30672..e7640dd 100644
--- a/services/inputflinger/InputManager.cpp
+++ b/services/inputflinger/InputManager.cpp
@@ -128,7 +128,7 @@
"from non shell/root entity (PID: %d)", ipc->getCallingPid());
return;
}
- mDispatcher->registerInputChannel(channel, false);
+ mDispatcher->registerInputChannel(channel);
}
void InputManager::unregisterInputChannel(const sp<InputChannel>& channel) {
diff --git a/services/inputflinger/dispatcher/Entry.cpp b/services/inputflinger/dispatcher/Entry.cpp
index 640a69a..930c7c7 100644
--- a/services/inputflinger/dispatcher/Entry.cpp
+++ b/services/inputflinger/dispatcher/Entry.cpp
@@ -18,10 +18,12 @@
#include "Connection.h"
+#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <cutils/atomic.h>
#include <inttypes.h>
+using android::base::GetBoolProperty;
using android::base::StringPrintf;
namespace android::inputdispatcher {
@@ -133,7 +135,11 @@
KeyEntry::~KeyEntry() {}
void KeyEntry::appendDescription(std::string& msg) const {
- msg += StringPrintf("KeyEvent(deviceId=%d, source=0x%08x, displayId=%" PRId32 ", action=%s, "
+ msg += StringPrintf("KeyEvent");
+ if (!GetBoolProperty("ro.debuggable", false)) {
+ return;
+ }
+ msg += StringPrintf("(deviceId=%d, source=0x%08x, displayId=%" PRId32 ", action=%s, "
"flags=0x%08x, keyCode=%d, scanCode=%d, metaState=0x%08x, "
"repeatCount=%d), policyFlags=0x%08x",
deviceId, source, displayId, keyActionToString(action).c_str(), flags,
@@ -189,7 +195,11 @@
MotionEntry::~MotionEntry() {}
void MotionEntry::appendDescription(std::string& msg) const {
- msg += StringPrintf("MotionEvent(deviceId=%d, source=0x%08x, displayId=%" PRId32
+ msg += StringPrintf("MotionEvent");
+ if (!GetBoolProperty("ro.debuggable", false)) {
+ return;
+ }
+ msg += StringPrintf("(deviceId=%d, source=0x%08x, displayId=%" PRId32
", action=%s, actionButton=0x%08x, flags=0x%08x, metaState=0x%08x, "
"buttonState=0x%08x, "
"classification=%s, edgeFlags=0x%08x, xPrecision=%.1f, yPrecision=%.1f, "
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 4db9ae2..ee8c344 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -3865,11 +3865,9 @@
}
}
-status_t InputDispatcher::registerInputChannel(const sp<InputChannel>& inputChannel,
- int32_t displayId) {
+status_t InputDispatcher::registerInputChannel(const sp<InputChannel>& inputChannel) {
#if DEBUG_REGISTRATION
- ALOGD("channel '%s' ~ registerInputChannel - displayId=%" PRId32,
- inputChannel->getName().c_str(), displayId);
+ ALOGD("channel '%s' ~ registerInputChannel", inputChannel->getName().c_str());
#endif
{ // acquire lock
diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h
index 0d9d6b0..1f906e4 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.h
+++ b/services/inputflinger/dispatcher/InputDispatcher.h
@@ -106,8 +106,7 @@
virtual bool transferTouchFocus(const sp<IBinder>& fromToken,
const sp<IBinder>& toToken) override;
- virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel,
- int32_t displayId) override;
+ virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel) override;
virtual status_t registerInputMonitor(const sp<InputChannel>& inputChannel, int32_t displayId,
bool isGestureMonitor) override;
virtual status_t unregisterInputChannel(const sp<InputChannel>& inputChannel) override;
diff --git a/services/inputflinger/dispatcher/TouchState.cpp b/services/inputflinger/dispatcher/TouchState.cpp
index 18848a0..2baceba 100644
--- a/services/inputflinger/dispatcher/TouchState.cpp
+++ b/services/inputflinger/dispatcher/TouchState.cpp
@@ -93,15 +93,6 @@
std::end(newMonitors));
}
-void TouchState::removeWindow(const sp<InputWindowHandle>& windowHandle) {
- for (size_t i = 0; i < windows.size(); i++) {
- if (windows[i].windowHandle == windowHandle) {
- windows.erase(windows.begin() + i);
- return;
- }
- }
-}
-
void TouchState::removeWindowByToken(const sp<IBinder>& token) {
for (size_t i = 0; i < windows.size(); i++) {
if (windows[i].windowHandle->getToken() == token) {
diff --git a/services/inputflinger/dispatcher/TouchState.h b/services/inputflinger/dispatcher/TouchState.h
index 3e0e0eb..623c6a8 100644
--- a/services/inputflinger/dispatcher/TouchState.h
+++ b/services/inputflinger/dispatcher/TouchState.h
@@ -49,7 +49,6 @@
BitSet32 pointerIds);
void addPortalWindow(const sp<android::InputWindowHandle>& windowHandle);
void addGestureMonitors(const std::vector<TouchedMonitor>& monitors);
- void removeWindow(const sp<android::InputWindowHandle>& windowHandle);
void removeWindowByToken(const sp<IBinder>& token);
void filterNonAsIsTouchWindows();
void filterNonMonitors();
diff --git a/services/inputflinger/dispatcher/include/InputDispatcherInterface.h b/services/inputflinger/dispatcher/include/InputDispatcherInterface.h
index 9329ca6..ce7366f 100644
--- a/services/inputflinger/dispatcher/include/InputDispatcherInterface.h
+++ b/services/inputflinger/dispatcher/include/InputDispatcherInterface.h
@@ -126,8 +126,7 @@
*
* This method may be called on any thread (usually by the input manager).
*/
- virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel,
- int32_t displayId) = 0;
+ virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel) = 0;
/* Registers input channels to be used to monitor input events.
*
diff --git a/services/inputflinger/host/InputDriver.cpp b/services/inputflinger/host/InputDriver.cpp
index 2f046c3..683c05d 100644
--- a/services/inputflinger/host/InputDriver.cpp
+++ b/services/inputflinger/host/InputDriver.cpp
@@ -127,10 +127,10 @@
input_bus_t bus, const char* uniqueId) {
auto identifier = new ::input_device_identifier {
.name = name,
- .productId = productId,
- .vendorId = vendorId,
- .bus = bus,
.uniqueId = uniqueId,
+ .bus = bus,
+ .vendorId = vendorId,
+ .productId = productId,
};
// TODO: store this identifier somewhere
return identifier;
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp
index aa98ef7..7d69854 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -471,7 +471,7 @@
FakeInputReceiver(dispatcher, name, displayId),
mFocused(false), mFrame(Rect(0, 0, WIDTH, HEIGHT)), mLayoutParamFlags(0) {
mServerChannel->setToken(new BBinder());
- mDispatcher->registerInputChannel(mServerChannel, displayId);
+ mDispatcher->registerInputChannel(mServerChannel);
inputApplicationHandle->updateInfo();
mInfo.applicationInfo = *inputApplicationHandle->getInfo();
diff --git a/services/surfaceflinger/BufferLayer.cpp b/services/surfaceflinger/BufferLayer.cpp
index b500ad3..603a9f7 100644
--- a/services/surfaceflinger/BufferLayer.cpp
+++ b/services/surfaceflinger/BufferLayer.cpp
@@ -61,7 +61,7 @@
mTextureName(args.textureName),
mCompositionLayer{mFlinger->getCompositionEngine().createLayer(
compositionengine::LayerCreationArgs{this})} {
- ALOGV("Creating Layer %s", args.name.string());
+ ALOGV("Creating Layer %s", getDebugName());
mPremultipliedAlpha = !(args.flags & ISurfaceComposerClient::eNonPremultiplied);
diff --git a/services/surfaceflinger/BufferQueueLayer.cpp b/services/surfaceflinger/BufferQueueLayer.cpp
index d80a70e..a4f7797 100644
--- a/services/surfaceflinger/BufferQueueLayer.cpp
+++ b/services/surfaceflinger/BufferQueueLayer.cpp
@@ -62,7 +62,7 @@
std::vector<OccupancyTracker::Segment> history;
status_t result = mConsumer->getOccupancyHistory(forceFlush, &history);
if (result != NO_ERROR) {
- ALOGW("[%s] Failed to obtain occupancy history (%d)", mName.string(), result);
+ ALOGW("[%s] Failed to obtain occupancy history (%d)", getDebugName(), result);
return {};
}
return history;
@@ -110,7 +110,7 @@
ALOGW_IF(!isPlausible,
"[%s] Timestamp %" PRId64 " seems implausible "
"relative to expectedPresent %" PRId64,
- mName.string(), addedTime, expectedPresentTime);
+ getDebugName(), addedTime, expectedPresentTime);
const bool isDue = addedTime < expectedPresentTime;
return isDue || !isPlausible;
@@ -225,7 +225,7 @@
bool queuedBuffer = false;
const int32_t layerID = getSequence();
LayerRejecter r(mDrawingState, getCurrentState(), recomputeVisibleRegions,
- getProducerStickyTransform() != 0, mName.string(), mOverrideScalingMode,
+ getProducerStickyTransform() != 0, mName, mOverrideScalingMode,
getTransformToDisplayInverse());
if (isRemovedFromCurrentState()) {
@@ -398,7 +398,7 @@
while (item.mFrameNumber != mLastFrameNumberReceived + 1) {
status_t result = mQueueItemCondition.waitRelative(mQueueItemLock, ms2ns(500));
if (result != NO_ERROR) {
- ALOGE("[%s] Timed out waiting on callback", mName.string());
+ ALOGE("[%s] Timed out waiting on callback", getDebugName());
}
}
@@ -426,7 +426,7 @@
while (item.mFrameNumber != mLastFrameNumberReceived + 1) {
status_t result = mQueueItemCondition.waitRelative(mQueueItemLock, ms2ns(500));
if (result != NO_ERROR) {
- ALOGE("[%s] Timed out waiting on callback", mName.string());
+ ALOGE("[%s] Timed out waiting on callback", getDebugName());
}
}
@@ -459,12 +459,14 @@
// Creates a custom BufferQueue for SurfaceFlingerConsumer to use
sp<IGraphicBufferProducer> producer;
sp<IGraphicBufferConsumer> consumer;
- BufferQueue::createBufferQueue(&producer, &consumer, true);
- mProducer = new MonitoredProducer(producer, mFlinger, this);
- mConsumer = new BufferLayerConsumer(consumer, mFlinger->getRenderEngine(), mTextureName, this);
+ mFlinger->getFactory().createBufferQueue(&producer, &consumer, true);
+ mProducer = mFlinger->getFactory().createMonitoredProducer(producer, mFlinger, this);
+ mConsumer =
+ mFlinger->getFactory().createBufferLayerConsumer(consumer, mFlinger->getRenderEngine(),
+ mTextureName, this);
mConsumer->setConsumerUsageBits(getEffectiveUsage(0));
mConsumer->setContentsChangedListener(this);
- mConsumer->setName(mName);
+ mConsumer->setName(String8(mName.data(), mName.size()));
// BufferQueueCore::mMaxDequeuedBufferCount is default to 1
if (!mFlinger->isLayerTripleBufferingDisabled()) {
@@ -527,9 +529,7 @@
}
sp<Layer> BufferQueueLayer::createClone() {
- const String8 name = mName + " (Mirror)";
- LayerCreationArgs args =
- LayerCreationArgs(mFlinger.get(), nullptr, name, 0, 0, 0, LayerMetadata());
+ LayerCreationArgs args(mFlinger.get(), nullptr, mName + " (Mirror)", 0, 0, 0, LayerMetadata());
args.textureName = mTextureName;
sp<BufferQueueLayer> layer = mFlinger->getFactory().createBufferQueueLayer(args);
layer->setInitialValuesForClone(this);
diff --git a/services/surfaceflinger/BufferStateLayer.cpp b/services/surfaceflinger/BufferStateLayer.cpp
index 75fc0e9..6fe89c4 100644
--- a/services/surfaceflinger/BufferStateLayer.cpp
+++ b/services/surfaceflinger/BufferStateLayer.cpp
@@ -136,7 +136,7 @@
return;
}
mPendingStates.push_back(mCurrentState);
- ATRACE_INT(mTransactionName.string(), mPendingStates.size());
+ ATRACE_INT(mTransactionName.c_str(), mPendingStates.size());
}
bool BufferStateLayer::applyPendingStates(Layer::State* stateToCommit) {
@@ -479,7 +479,7 @@
(s.active.w != bufferWidth || s.active.h != bufferHeight)) {
ALOGE("[%s] rejecting buffer: "
"bufferWidth=%d, bufferHeight=%d, front.active.{w=%d, h=%d}",
- mName.string(), bufferWidth, bufferHeight, s.active.w, s.active.h);
+ getDebugName(), bufferWidth, bufferHeight, s.active.w, s.active.h);
mFlinger->mTimeStats->removeTimeRecord(layerID, mFrameNumber);
return BAD_VALUE;
}
@@ -669,9 +669,7 @@
}
sp<Layer> BufferStateLayer::createClone() {
- const String8 name = mName + " (Mirror)";
- LayerCreationArgs args =
- LayerCreationArgs(mFlinger.get(), nullptr, name, 0, 0, 0, LayerMetadata());
+ LayerCreationArgs args(mFlinger.get(), nullptr, mName + " (Mirror)", 0, 0, 0, LayerMetadata());
args.textureName = mTextureName;
sp<BufferStateLayer> layer = mFlinger->getFactory().createBufferStateLayer(args);
layer->mHwcSlotGenerator = mHwcSlotGenerator;
diff --git a/services/surfaceflinger/ColorLayer.cpp b/services/surfaceflinger/ColorLayer.cpp
index 172d445..8bfa569 100644
--- a/services/surfaceflinger/ColorLayer.cpp
+++ b/services/surfaceflinger/ColorLayer.cpp
@@ -108,13 +108,11 @@
}
sp<Layer> ColorLayer::createClone() {
- String8 name = mName + " (Mirror)";
sp<ColorLayer> layer = mFlinger->getFactory().createColorLayer(
- LayerCreationArgs(mFlinger.get(), nullptr, name, 0, 0, 0, LayerMetadata()));
+ LayerCreationArgs(mFlinger.get(), nullptr, mName + " (Mirror)", 0, 0, 0,
+ LayerMetadata()));
layer->setInitialValuesForClone(this);
return layer;
}
-// ---------------------------------------------------------------------------
-
-}; // namespace android
+} // namespace android
diff --git a/services/surfaceflinger/ContainerLayer.cpp b/services/surfaceflinger/ContainerLayer.cpp
index e58e6f4..ab664be 100644
--- a/services/surfaceflinger/ContainerLayer.cpp
+++ b/services/surfaceflinger/ContainerLayer.cpp
@@ -31,10 +31,11 @@
}
sp<Layer> ContainerLayer::createClone() {
- String8 name = mName + " (Mirror)";
sp<ContainerLayer> layer = mFlinger->getFactory().createContainerLayer(
- LayerCreationArgs(mFlinger.get(), nullptr, name, 0, 0, 0, LayerMetadata()));
+ LayerCreationArgs(mFlinger.get(), nullptr, mName + " (Mirror)", 0, 0, 0,
+ LayerMetadata()));
layer->setInitialValuesForClone(this);
return layer;
}
+
} // namespace android
diff --git a/services/surfaceflinger/EventLog/EventLog.cpp b/services/surfaceflinger/EventLog/EventLog.cpp
index 365a0bd..a532fc1 100644
--- a/services/surfaceflinger/EventLog/EventLog.cpp
+++ b/services/surfaceflinger/EventLog/EventLog.cpp
@@ -17,13 +17,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <log/log.h>
-#include <utils/String8.h>
#include "EventLog.h"
-// ---------------------------------------------------------------------------
namespace android {
-// ---------------------------------------------------------------------------
ANDROID_SINGLETON_STATIC_INSTANCE(EventLog)
@@ -31,11 +28,11 @@
EventLog::EventLog() {
}
-void EventLog::doLogFrameDurations(const String8& window,
- const int32_t* durations, size_t numDurations) {
+void EventLog::doLogFrameDurations(const std::string_view& name, const int32_t* durations,
+ size_t numDurations) {
EventLog::TagBuffer buffer(LOGTAG_SF_FRAME_DUR);
buffer.startList(1 + numDurations);
- buffer.writeString8(window);
+ buffer.writeString(name);
for (size_t i = 0; i < numDurations; i++) {
buffer.writeInt32(durations[i]);
}
@@ -43,10 +40,9 @@
buffer.log();
}
-void EventLog::logFrameDurations(const String8& window,
- const int32_t* durations, size_t numDurations) {
- EventLog::getInstance().doLogFrameDurations(window, durations,
- numDurations);
+void EventLog::logFrameDurations(const std::string_view& name, const int32_t* durations,
+ size_t numDurations) {
+ EventLog::getInstance().doLogFrameDurations(name, durations, numDurations);
}
// ---------------------------------------------------------------------------
@@ -113,9 +109,9 @@
mPos += needed;
}
-void EventLog::TagBuffer::writeString8(const String8& value) {
+void EventLog::TagBuffer::writeString(const std::string_view& value) {
if (mOverflow) return;
- const int32_t stringLen = value.length();
+ const size_t stringLen = value.length();
const size_t needed = 1 + sizeof(int32_t) + stringLen;
if (mPos + needed > STORAGE_MAX_SIZE) {
mOverflow = true;
@@ -123,11 +119,8 @@
}
mStorage[mPos + 0] = EVENT_TYPE_STRING;
memcpy(&mStorage[mPos + 1], &stringLen, sizeof(int32_t));
- memcpy(&mStorage[mPos + 5], value.string(), stringLen);
+ memcpy(&mStorage[mPos + 5], value.data(), stringLen);
mPos += needed;
}
-// ---------------------------------------------------------------------------
-}// namespace android
-
-// ---------------------------------------------------------------------------
+} // namespace android
diff --git a/services/surfaceflinger/EventLog/EventLog.h b/services/surfaceflinger/EventLog/EventLog.h
index efc5d70..ee3587e 100644
--- a/services/surfaceflinger/EventLog/EventLog.h
+++ b/services/surfaceflinger/EventLog/EventLog.h
@@ -14,24 +14,21 @@
* limitations under the License.
*/
-#include <stdint.h>
+#pragma once
+
#include <utils/Errors.h>
#include <utils/Singleton.h>
-#ifndef ANDROID_SF_EVENTLOG_H
-#define ANDROID_SF_EVENTLOG_H
+#include <cstdint>
+#include <string_view>
-// ---------------------------------------------------------------------------
namespace android {
-// ---------------------------------------------------------------------------
-
-class String8;
class EventLog : public Singleton<EventLog> {
public:
- static void logFrameDurations(const String8& window,
- const int32_t* durations, size_t numDurations);
+ static void logFrameDurations(const std::string_view& name, const int32_t* durations,
+ size_t numDurations);
protected:
EventLog();
@@ -54,18 +51,13 @@
public:
explicit TagBuffer(int32_t tag);
- // starts list of items
void startList(int8_t count);
- // terminates the list
void endList();
- // write a 32-bit integer
- void writeInt32(int32_t value);
- // write a 64-bit integer
- void writeInt64(int64_t value);
- // write a C string
- void writeString8(const String8& value);
- // outputs the the buffer to the log
+ void writeInt32(int32_t);
+ void writeInt64(int64_t);
+ void writeString(const std::string_view&);
+
void log();
};
@@ -74,12 +66,8 @@
EventLog& operator =(const EventLog&);
enum { LOGTAG_SF_FRAME_DUR = 60100 };
- void doLogFrameDurations(const String8& window, const int32_t* durations,
- size_t numDurations);
+ void doLogFrameDurations(const std::string_view& name, const int32_t* durations,
+ size_t numDurations);
};
-// ---------------------------------------------------------------------------
-}// namespace android
-// ---------------------------------------------------------------------------
-
-#endif /* ANDROID_SF_EVENTLOG_H */
+} // namespace android
diff --git a/services/surfaceflinger/FrameTracker.cpp b/services/surfaceflinger/FrameTracker.cpp
index f4cc49b..a6e511e 100644
--- a/services/surfaceflinger/FrameTracker.cpp
+++ b/services/surfaceflinger/FrameTracker.cpp
@@ -21,7 +21,6 @@
#include <android-base/stringprintf.h>
#include <android/log.h>
-#include <utils/String8.h>
#include <ui/FrameStats.h>
@@ -139,7 +138,7 @@
}
}
-void FrameTracker::logAndResetStats(const String8& name) {
+void FrameTracker::logAndResetStats(const std::string_view& name) {
Mutex::Autolock lock(mMutex);
logStatsLocked(name);
resetFrameCountersLocked();
@@ -217,7 +216,7 @@
}
}
-void FrameTracker::logStatsLocked(const String8& name) const {
+void FrameTracker::logStatsLocked(const std::string_view& name) const {
for (int i = 0; i < NUM_FRAME_BUCKETS; i++) {
if (mNumFrames[i] > 0) {
EventLog::logFrameDurations(name, mNumFrames, NUM_FRAME_BUCKETS);
diff --git a/services/surfaceflinger/FrameTracker.h b/services/surfaceflinger/FrameTracker.h
index 555dcc1..35382be 100644
--- a/services/surfaceflinger/FrameTracker.h
+++ b/services/surfaceflinger/FrameTracker.h
@@ -14,21 +14,18 @@
* limitations under the License.
*/
-#ifndef ANDROID_FRAMETRACKER_H
-#define ANDROID_FRAMETRACKER_H
+#pragma once
#include <ui/FenceTime.h>
-
-#include <stddef.h>
-
#include <utils/Mutex.h>
-#include <utils/Timers.h>
#include <utils/RefBase.h>
+#include <utils/Timers.h>
+
+#include <cstddef>
+#include <string_view>
namespace android {
-class String8;
-
// FrameTracker tracks information about the most recently rendered frames. It
// uses a circular buffer of frame records, and is *NOT* thread-safe -
// mutexing must be done at a higher level if multi-threaded access is
@@ -87,7 +84,7 @@
// logAndResetStats dumps the current statistics to the binary event log
// and then resets the accumulated statistics to their initial values.
- void logAndResetStats(const String8& name);
+ void logAndResetStats(const std::string_view& name);
// dumpStats dump appends the current frame display time history to the result string.
void dumpStats(std::string& result) const;
@@ -123,7 +120,7 @@
void resetFrameCountersLocked();
// logStatsLocked dumps the current statistics to the binary event log.
- void logStatsLocked(const String8& name) const;
+ void logStatsLocked(const std::string_view& name) const;
// isFrameValidLocked returns true if the data for the given frame index is
// valid and has all arrived (i.e. there are no oustanding fences).
@@ -160,6 +157,4 @@
mutable Mutex mMutex;
};
-}
-
-#endif // ANDROID_FRAMETRACKER_H
+} // namespace android
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 6a45625..37caab2 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -83,8 +83,6 @@
if (args.flags & ISurfaceComposerClient::eOpaque) layerFlags |= layer_state_t::eLayerOpaque;
if (args.flags & ISurfaceComposerClient::eSecure) layerFlags |= layer_state_t::eLayerSecure;
- mTransactionName = String8("TX - ") + mName;
-
mCurrentState.active_legacy.w = args.w;
mCurrentState.active_legacy.h = args.h;
mCurrentState.flags = layerFlags;
@@ -137,11 +135,11 @@
}
LayerCreationArgs::LayerCreationArgs(SurfaceFlinger* flinger, const sp<Client>& client,
- const String8& name, uint32_t w, uint32_t h, uint32_t flags,
+ std::string name, uint32_t w, uint32_t h, uint32_t flags,
LayerMetadata metadata)
: flinger(flinger),
client(client),
- name(name),
+ name(std::move(name)),
w(w),
h(h),
flags(flags),
@@ -235,10 +233,6 @@
// set-up
// ---------------------------------------------------------------------------
-const String8& Layer::getName() const {
- return mName;
-}
-
bool Layer::getPremultipledAlpha() const {
return mPremultipliedAlpha;
}
@@ -523,7 +517,7 @@
}
const char* Layer::getDebugName() const {
- return mName.string();
+ return mName.c_str();
}
// ---------------------------------------------------------------------------
@@ -614,7 +608,7 @@
if (mCurrentState.barrierLayer_legacy != nullptr && !isRemovedFromCurrentState()) {
sp<Layer> barrierLayer = mCurrentState.barrierLayer_legacy.promote();
if (barrierLayer == nullptr) {
- ALOGE("[%s] Unable to promote barrier Layer.", mName.string());
+ ALOGE("[%s] Unable to promote barrier Layer.", getDebugName());
// If we can't promote the layer we are intended to wait on,
// then it is expired or otherwise invalid. Allow this transaction
// to be applied as per normal (no synchronization).
@@ -638,7 +632,7 @@
mFlinger->setTransactionFlags(eTraversalNeeded);
}
mPendingStates.push_back(mCurrentState);
- ATRACE_INT(mTransactionName.string(), mPendingStates.size());
+ ATRACE_INT(mTransactionName.c_str(), mPendingStates.size());
}
void Layer::popPendingState(State* stateToCommit) {
@@ -646,7 +640,7 @@
*stateToCommit = mPendingStates[0];
mPendingStates.removeAt(0);
- ATRACE_INT(mTransactionName.string(), mPendingStates.size());
+ ATRACE_INT(mTransactionName.c_str(), mPendingStates.size());
}
bool Layer::applyPendingStates(State* stateToCommit) {
@@ -657,7 +651,7 @@
// If we don't have a sync point for this, apply it anyway. It
// will be visually wrong, but it should keep us from getting
// into too much trouble.
- ALOGE("[%s] No local sync point found", mName.string());
+ ALOGE("[%s] No local sync point found", getDebugName());
popPendingState(stateToCommit);
stateUpdateAvailable = true;
continue;
@@ -665,7 +659,7 @@
if (mRemoteSyncPoints.front()->getFrameNumber() !=
mPendingStates[0].frameNumber_legacy) {
- ALOGE("[%s] Unexpected sync point frame number found", mName.string());
+ ALOGE("[%s] Unexpected sync point frame number found", getDebugName());
// Signal our end of the sync point and then dispose of it
mRemoteSyncPoints.front()->setTransactionApplied();
@@ -717,7 +711,7 @@
" requested={ wh={%4u,%4u} }}\n"
" drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
" requested={ wh={%4u,%4u} }}\n",
- this, getName().string(), getBufferTransform(), getEffectiveScalingMode(),
+ this, getName().c_str(), getBufferTransform(), getEffectiveScalingMode(),
stateToCommit->active_legacy.w, stateToCommit->active_legacy.h,
stateToCommit->crop_legacy.left, stateToCommit->crop_legacy.top,
stateToCommit->crop_legacy.right, stateToCommit->crop_legacy.bottom,
@@ -908,7 +902,6 @@
}
setZOrderRelativeOf(nullptr);
}
- mCurrentState.isRelativeOf = false;
setTransactionFlags(eTransactionNeeded);
return true;
}
@@ -931,6 +924,8 @@
mCurrentState.zOrderRelativeOf = relativeOf;
mCurrentState.sequence++;
mCurrentState.modified = true;
+ mCurrentState.isRelativeOf = relativeOf != nullptr;
+
setTransactionFlags(eTransactionNeeded);
}
@@ -952,7 +947,6 @@
mCurrentState.sequence++;
mCurrentState.modified = true;
mCurrentState.z = relativeZ;
- mCurrentState.isRelativeOf = true;
auto oldZOrderRelativeOf = mCurrentState.zOrderRelativeOf.promote();
if (oldZOrderRelativeOf != nullptr) {
@@ -999,9 +993,10 @@
if (!mCurrentState.bgColorLayer && alpha != 0) {
// create background color layer if one does not yet exist
uint32_t flags = ISurfaceComposerClient::eFXSurfaceColor;
- const String8& name = mName + "BackgroundColorLayer";
+ std::string name = mName + "BackgroundColorLayer";
mCurrentState.bgColorLayer = mFlinger->getFactory().createColorLayer(
- LayerCreationArgs(mFlinger.get(), nullptr, name, 0, 0, flags, LayerMetadata()));
+ LayerCreationArgs(mFlinger.get(), nullptr, std::move(name), 0, 0, flags,
+ LayerMetadata()));
// add to child list
addChild(mCurrentState.bgColorLayer);
@@ -1196,11 +1191,13 @@
// TODO(marissaw): add new layer state info to layer debugging
LayerDebugInfo Layer::getLayerDebugInfo() const {
+ using namespace std::string_literals;
+
LayerDebugInfo info;
const State& ds = getDrawingState();
info.mName = getName();
sp<Layer> parent = getParent();
- info.mParentName = (parent == nullptr ? std::string("none") : parent->getName().string());
+ info.mParentName = parent ? parent->getName() : "none"s;
info.mType = getType();
info.mTransparentRegion = ds.activeTransparentRegion_legacy;
@@ -1267,12 +1264,12 @@
std::string name;
if (mName.length() > 77) {
std::string shortened;
- shortened.append(mName.string(), 36);
+ shortened.append(mName, 0, 36);
shortened.append("[...]");
- shortened.append(mName.string() + (mName.length() - 36), 36);
- name = shortened;
+ shortened.append(mName, mName.length() - 36);
+ name = std::move(shortened);
} else {
- name = std::string(mName.string(), mName.size());
+ name = mName;
}
StringAppendF(&result, " %s\n", name.c_str());
@@ -1319,14 +1316,14 @@
}
void Layer::dumpFrameEvents(std::string& result) {
- StringAppendF(&result, "- Layer %s (%s, %p)\n", getName().string(), getType(), this);
+ StringAppendF(&result, "- Layer %s (%s, %p)\n", getName().c_str(), getType(), this);
Mutex::Autolock lock(mFrameEventHistoryMutex);
mFrameEventHistory.checkFencesForCompletion();
mFrameEventHistory.dump(result);
}
void Layer::dumpCallingUidPid(std::string& result) const {
- StringAppendF(&result, "Layer %s (%s) pid:%d uid:%d\n", getName().string(), getType(),
+ StringAppendF(&result, "Layer %s (%s) pid:%d uid:%d\n", getName().c_str(), getType(),
mCallingPid, mCallingUid);
}
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 3023cf5..ad81920 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -34,7 +34,6 @@
#include <ui/Region.h>
#include <ui/Transform.h>
#include <utils/RefBase.h>
-#include <utils/String8.h>
#include <utils/Timers.h>
#include <cstdint>
@@ -79,12 +78,12 @@
// ---------------------------------------------------------------------------
struct LayerCreationArgs {
- LayerCreationArgs(SurfaceFlinger* flinger, const sp<Client>& client, const String8& name,
+ LayerCreationArgs(SurfaceFlinger* flinger, const sp<Client>& client, std::string name,
uint32_t w, uint32_t h, uint32_t flags, LayerMetadata metadata);
SurfaceFlinger* flinger;
const sp<Client>& client;
- const String8& name;
+ std::string name;
uint32_t w;
uint32_t h;
uint32_t flags;
@@ -804,7 +803,7 @@
// Creates a new handle each time, so we only expect
// this to be called once.
sp<IBinder> getHandle();
- const String8& getName() const;
+ const std::string& getName() const { return mName; }
virtual void notifyAvailableFrames(nsecs_t /*expectedPresentTime*/) {}
virtual PixelFormat getPixelFormat() const { return PIXEL_FORMAT_NONE; }
bool getPremultipledAlpha() const;
@@ -820,8 +819,8 @@
bool usingRelativeZ(LayerVector::StateSet stateSet) const;
bool mPremultipliedAlpha{true};
- String8 mName;
- String8 mTransactionName; // A cached version of "TX - " + mName for systraces
+ const std::string mName;
+ const std::string mTransactionName{"TX - " + mName};
bool mPrimaryDisplayOnly = false;
diff --git a/services/surfaceflinger/LayerRejecter.cpp b/services/surfaceflinger/LayerRejecter.cpp
index 8a22183..1a60f1e 100644
--- a/services/surfaceflinger/LayerRejecter.cpp
+++ b/services/surfaceflinger/LayerRejecter.cpp
@@ -24,7 +24,7 @@
namespace android {
LayerRejecter::LayerRejecter(Layer::State& front, Layer::State& current,
- bool& recomputeVisibleRegions, bool stickySet, const char* name,
+ bool& recomputeVisibleRegions, bool stickySet, const std::string& name,
int32_t overrideScalingMode, bool transformToDisplayInverse)
: mFront(front),
mCurrent(current),
@@ -90,7 +90,7 @@
"(%4d,%4d) "
"}\n"
" requested_legacy={ wh={%4u,%4u} }}\n",
- mName, bufWidth, bufHeight, item.mTransform, item.mScalingMode,
+ mName.c_str(), bufWidth, bufHeight, item.mTransform, item.mScalingMode,
mFront.active_legacy.w, mFront.active_legacy.h, mFront.crop_legacy.left,
mFront.crop_legacy.top, mFront.crop_legacy.right, mFront.crop_legacy.bottom,
mFront.crop_legacy.getWidth(), mFront.crop_legacy.getHeight(),
@@ -102,7 +102,8 @@
// reject this buffer
ALOGE("[%s] rejecting buffer: "
"bufWidth=%d, bufHeight=%d, front.active_legacy.{w=%d, h=%d}",
- mName, bufWidth, bufHeight, mFront.active_legacy.w, mFront.active_legacy.h);
+ mName.c_str(), bufWidth, bufHeight, mFront.active_legacy.w,
+ mFront.active_legacy.h);
return true;
}
}
diff --git a/services/surfaceflinger/LayerRejecter.h b/services/surfaceflinger/LayerRejecter.h
index 1bd0c26..fb5c750 100644
--- a/services/surfaceflinger/LayerRejecter.h
+++ b/services/surfaceflinger/LayerRejecter.h
@@ -14,30 +14,29 @@
* limitations under the License.
*/
-#ifndef ANDROID_LAYER_REJECTER_H
-#define ANDROID_LAYER_REJECTER_H
+#pragma once
#include "Layer.h"
#include "BufferLayerConsumer.h"
namespace android {
- class LayerRejecter : public BufferLayerConsumer::BufferRejecter {
- public:
- LayerRejecter(Layer::State &front, Layer::State ¤t, bool &recomputeVisibleRegions,
- bool stickySet, const char *name, int32_t overrideScalingMode,
- bool transformToDisplayInverse);
- virtual bool reject(const sp<GraphicBuffer> &buf, const BufferItem &item);
+class LayerRejecter : public BufferLayerConsumer::BufferRejecter {
+public:
+ LayerRejecter(Layer::State& front, Layer::State& current, bool& recomputeVisibleRegions,
+ bool stickySet, const std::string& name, int32_t overrideScalingMode,
+ bool transformToDisplayInverse);
- private:
- Layer::State &mFront;
- Layer::State &mCurrent;
- bool &mRecomputeVisibleRegions;
- bool mStickyTransformSet;
- const char *mName;
- int32_t mOverrideScalingMode;
- bool mTransformToDisplayInverse;
- };
-} // namespace android
+ virtual bool reject(const sp<GraphicBuffer>&, const BufferItem&);
-#endif // ANDROID_LAYER_REJECTER_H
+private:
+ Layer::State& mFront;
+ Layer::State& mCurrent;
+ bool& mRecomputeVisibleRegions;
+ const bool mStickyTransformSet;
+ const std::string& mName;
+ const int32_t mOverrideScalingMode;
+ const bool mTransformToDisplayInverse;
+};
+
+} // namespace android
diff --git a/services/surfaceflinger/RegionSamplingThread.cpp b/services/surfaceflinger/RegionSamplingThread.cpp
index 1c1367c..30027de 100644
--- a/services/surfaceflinger/RegionSamplingThread.cpp
+++ b/services/surfaceflinger/RegionSamplingThread.cpp
@@ -436,7 +436,7 @@
}
if (!intersectsAnyArea) return;
- ALOGV("Traversing [%s] [%d, %d, %d, %d]", layer->getName().string(), bounds.left,
+ ALOGV("Traversing [%s] [%d, %d, %d, %d]", layer->getDebugName(), bounds.left,
bounds.top, bounds.right, bounds.bottom);
visitor(layer);
};
diff --git a/services/surfaceflinger/Scheduler/LayerHistory.cpp b/services/surfaceflinger/Scheduler/LayerHistory.cpp
index f80c233..5473db6 100644
--- a/services/surfaceflinger/Scheduler/LayerHistory.cpp
+++ b/services/surfaceflinger/Scheduler/LayerHistory.cpp
@@ -40,7 +40,7 @@
LayerHistory::LayerHistory() {
char value[PROPERTY_VALUE_MAX];
property_get("debug.sf.layer_history_trace", value, "0");
- mTraceEnabled = bool(atoi(value));
+ mTraceEnabled = static_cast<bool>(atoi(value));
}
LayerHistory::~LayerHistory() = default;
@@ -128,19 +128,23 @@
// Iterate through all layers that have been recently updated, and find the max refresh rate.
for (const auto& [layerId, layerInfo] : mActiveLayerInfos) {
- const float layerRefreshRate = layerInfo->getDesiredRefreshRate();
- if (mTraceEnabled) {
- // Store the refresh rate in traces for easy debugging.
- std::string layerName = "LFPS " + layerInfo->getName();
- ATRACE_INT(layerName.c_str(), std::round(layerRefreshRate));
- ALOGD("%s: %f", layerName.c_str(), std::round(layerRefreshRate));
- }
- if (layerInfo->isRecentlyActive() && layerRefreshRate > newRefreshRate) {
- newRefreshRate = layerRefreshRate;
+ const bool recent = layerInfo->isRecentlyActive();
+ if (recent || CC_UNLIKELY(mTraceEnabled)) {
+ const float refreshRate = layerInfo->getDesiredRefreshRate();
+ if (recent && refreshRate > newRefreshRate) {
+ newRefreshRate = refreshRate;
+ }
+
+ if (CC_UNLIKELY(mTraceEnabled)) {
+ std::string name = "LFPS " + layerInfo->getName();
+ const float rate = std::round(refreshRate);
+ ATRACE_INT(name.c_str(), rate);
+ ALOGD("%s: %f", name.c_str(), rate);
+ }
}
isHDR |= layerInfo->getHDRContent();
}
- if (mTraceEnabled) {
+ if (CC_UNLIKELY(mTraceEnabled)) {
ALOGD("LayerHistory DesiredRefreshRate: %.2f", newRefreshRate);
}
@@ -158,7 +162,7 @@
(!it->second->getHDRContent() && it->second->getLastUpdatedTime() < obsoleteEpsilon)) {
// erase() function returns the iterator of the next
// to last deleted element.
- if (mTraceEnabled) {
+ if (CC_UNLIKELY(mTraceEnabled)) {
ALOGD("Layer %s obsolete", it->second->getName().c_str());
// Make sure to update systrace to indicate that the layer was erased.
std::string layerName = "LFPS " + it->second->getName();
@@ -189,4 +193,4 @@
}
} // namespace scheduler
-} // namespace android
\ No newline at end of file
+} // namespace android
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 54e2065..0e33f10 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -122,6 +122,8 @@
namespace android {
+using namespace std::string_literals;
+
using namespace android::hardware::configstore;
using namespace android::hardware::configstore::V1_0;
using namespace android::sysprop;
@@ -1911,8 +1913,7 @@
layer->onPostComposition(displayDevice->getId(), glCompositionDoneFenceTime,
presentFenceTime, compositorTiming);
if (frameLatched) {
- recordBufferingStats(layer->getName().string(),
- layer->getOccupancyHistory(false));
+ recordBufferingStats(layer->getName(), layer->getOccupancyHistory(false));
}
});
@@ -2574,7 +2575,7 @@
if (!mLayersPendingRemoval.isEmpty()) {
// Notify removed layers now that they can't be drawn from
for (const auto& l : mLayersPendingRemoval) {
- recordBufferingStats(l->getName().string(), l->getOccupancyHistory(true));
+ recordBufferingStats(l->getName(), l->getOccupancyHistory(true));
// Ensure any buffers set to display on any children are released.
if (l->isRemovedFromCurrentState()) {
@@ -3244,11 +3245,12 @@
// everything else inherits layer stack from its parent.
if (layer->hasParent()) {
ALOGE("Attempt to set layer stack on layer with parent (%s) is invalid",
- layer->getName().string());
+ layer->getDebugName());
} else if (idx < 0) {
ALOGE("Attempt to set layer stack on layer without parent (%s) that "
- "that also does not appear in the top level layer list. Something"
- " has gone wrong.", layer->getName().string());
+ "that also does not appear in the top level layer list. Something"
+ " has gone wrong.",
+ layer->getDebugName());
} else if (layer->setLayerStack(s.layerStack)) {
mCurrentState.layersSortedByZ.removeAt(idx);
mCurrentState.layersSortedByZ.add(layer);
@@ -3406,7 +3408,7 @@
sp<Layer> mirrorLayer;
sp<Layer> mirrorFrom;
- String8 uniqueName = getUniqueLayerName(String8("MirrorRoot"));
+ std::string uniqueName = getUniqueLayerName("MirrorRoot");
{
Mutex::Autolock _l(mStateLock);
@@ -3415,8 +3417,8 @@
return NAME_NOT_FOUND;
}
- status_t result = createContainerLayer(client, uniqueName, -1, -1, 0, LayerMetadata(),
- outHandle, &mirrorLayer);
+ status_t result = createContainerLayer(client, std::move(uniqueName), -1, -1, 0,
+ LayerMetadata(), outHandle, &mirrorLayer);
if (result != NO_ERROR) {
return result;
}
@@ -3447,7 +3449,7 @@
sp<Layer> layer;
- String8 uniqueName = getUniqueLayerName(name);
+ std::string uniqueName = getUniqueLayerName(name.string());
bool primaryDisplayOnly = false;
@@ -3463,13 +3465,13 @@
switch (flags & ISurfaceComposerClient::eFXSurfaceMask) {
case ISurfaceComposerClient::eFXSurfaceBufferQueue:
- result = createBufferQueueLayer(client, uniqueName, w, h, flags, std::move(metadata),
- format, handle, gbp, &layer);
+ result = createBufferQueueLayer(client, std::move(uniqueName), w, h, flags,
+ std::move(metadata), format, handle, gbp, &layer);
break;
case ISurfaceComposerClient::eFXSurfaceBufferState:
- result = createBufferStateLayer(client, uniqueName, w, h, flags, std::move(metadata),
- handle, &layer);
+ result = createBufferStateLayer(client, std::move(uniqueName), w, h, flags,
+ std::move(metadata), handle, &layer);
break;
case ISurfaceComposerClient::eFXSurfaceColor:
// check if buffer size is set for color layer.
@@ -3479,8 +3481,8 @@
return BAD_VALUE;
}
- result = createColorLayer(client, uniqueName, w, h, flags, std::move(metadata), handle,
- &layer);
+ result = createColorLayer(client, std::move(uniqueName), w, h, flags,
+ std::move(metadata), handle, &layer);
break;
case ISurfaceComposerClient::eFXSurfaceContainer:
// check if buffer size is set for container layer.
@@ -3489,8 +3491,8 @@
int(w), int(h));
return BAD_VALUE;
}
- result = createContainerLayer(client, uniqueName, w, h, flags, std::move(metadata),
- handle, &layer);
+ result = createContainerLayer(client, std::move(uniqueName), w, h, flags,
+ std::move(metadata), handle, &layer);
break;
default:
result = BAD_VALUE;
@@ -3517,35 +3519,32 @@
return result;
}
-String8 SurfaceFlinger::getUniqueLayerName(const String8& name)
-{
- bool matchFound = true;
- uint32_t dupeCounter = 0;
+std::string SurfaceFlinger::getUniqueLayerName(const char* name) {
+ unsigned dupeCounter = 0;
// Tack on our counter whether there is a hit or not, so everyone gets a tag
- String8 uniqueName = name + "#" + String8(std::to_string(dupeCounter).c_str());
+ std::string uniqueName = base::StringPrintf("%s#%u", name, dupeCounter);
// Grab the state lock since we're accessing mCurrentState
Mutex::Autolock lock(mStateLock);
// Loop over layers until we're sure there is no matching name
+ bool matchFound = true;
while (matchFound) {
matchFound = false;
mCurrentState.traverseInZOrder([&](Layer* layer) {
if (layer->getName() == uniqueName) {
matchFound = true;
- uniqueName = name + "#" + String8(std::to_string(++dupeCounter).c_str());
+ uniqueName = base::StringPrintf("%s#%u", name, ++dupeCounter);
}
});
}
- ALOGV_IF(dupeCounter > 0, "duplicate layer name: changing %s to %s", name.c_str(),
- uniqueName.c_str());
-
+ ALOGV_IF(dupeCounter > 0, "duplicate layer name: changing %s to %s", name, uniqueName.c_str());
return uniqueName;
}
-status_t SurfaceFlinger::createBufferQueueLayer(const sp<Client>& client, const String8& name,
+status_t SurfaceFlinger::createBufferQueueLayer(const sp<Client>& client, std::string name,
uint32_t w, uint32_t h, uint32_t flags,
LayerMetadata metadata, PixelFormat& format,
sp<IBinder>* handle,
@@ -3563,8 +3562,7 @@
}
sp<BufferQueueLayer> layer;
- LayerCreationArgs args =
- LayerCreationArgs(this, client, name, w, h, flags, std::move(metadata));
+ LayerCreationArgs args(this, client, std::move(name), w, h, flags, std::move(metadata));
args.textureName = getNewTexture();
{
// Grab the SF state lock during this since it's the only safe way to access
@@ -3585,12 +3583,11 @@
return err;
}
-status_t SurfaceFlinger::createBufferStateLayer(const sp<Client>& client, const String8& name,
+status_t SurfaceFlinger::createBufferStateLayer(const sp<Client>& client, std::string name,
uint32_t w, uint32_t h, uint32_t flags,
LayerMetadata metadata, sp<IBinder>* handle,
sp<Layer>* outLayer) {
- LayerCreationArgs args =
- LayerCreationArgs(this, client, name, w, h, flags, std::move(metadata));
+ LayerCreationArgs args(this, client, std::move(name), w, h, flags, std::move(metadata));
args.displayDevice = getDefaultDisplayDevice();
args.textureName = getNewTexture();
sp<BufferStateLayer> layer = getFactory().createBufferStateLayer(args);
@@ -3600,26 +3597,25 @@
return NO_ERROR;
}
-status_t SurfaceFlinger::createColorLayer(const sp<Client>& client, const String8& name, uint32_t w,
+status_t SurfaceFlinger::createColorLayer(const sp<Client>& client, std::string name, uint32_t w,
uint32_t h, uint32_t flags, LayerMetadata metadata,
sp<IBinder>* handle, sp<Layer>* outLayer) {
*outLayer = getFactory().createColorLayer(
- LayerCreationArgs(this, client, name, w, h, flags, std::move(metadata)));
+ {this, client, std::move(name), w, h, flags, std::move(metadata)});
*handle = (*outLayer)->getHandle();
return NO_ERROR;
}
-status_t SurfaceFlinger::createContainerLayer(const sp<Client>& client, const String8& name,
+status_t SurfaceFlinger::createContainerLayer(const sp<Client>& client, std::string name,
uint32_t w, uint32_t h, uint32_t flags,
LayerMetadata metadata, sp<IBinder>* handle,
sp<Layer>* outLayer) {
*outLayer = getFactory().createContainerLayer(
- LayerCreationArgs(this, client, name, w, h, flags, std::move(metadata)));
+ {this, client, std::move(name), w, h, flags, std::move(metadata)});
*handle = (*outLayer)->getHandle();
return NO_ERROR;
}
-
void SurfaceFlinger::markLayerPendingRemovalLocked(const sp<Layer>& layer) {
mLayersPendingRemoval.add(layer);
mLayersRemoved = true;
@@ -3828,8 +3824,6 @@
strerror(-err), err);
}
- using namespace std::string_literals;
-
static const std::unordered_map<std::string, Dumper> dumpers = {
{"--display-id"s, dumper(&SurfaceFlinger::dumpDisplayIdentificationData)},
{"--dispsync"s,
@@ -3885,7 +3879,7 @@
void SurfaceFlinger::listLayersLocked(std::string& result) const {
mCurrentState.traverseInZOrder(
- [&](Layer* layer) { StringAppendF(&result, "%s\n", layer->getName().string()); });
+ [&](Layer* layer) { StringAppendF(&result, "%s\n", layer->getDebugName()); });
}
void SurfaceFlinger::dumpStatsLocked(const DumpArgs& args, std::string& result) const {
@@ -3894,7 +3888,7 @@
if (args.size() > 1) {
const auto name = String8(args[1]);
mCurrentState.traverseInZOrder([&](Layer* layer) {
- if (name == layer->getName()) {
+ if (layer->getName() == name.string()) {
layer->dumpFrameStats(result);
}
});
@@ -3904,8 +3898,11 @@
}
void SurfaceFlinger::clearStatsLocked(const DumpArgs& args, std::string&) {
+ const bool clearAll = args.size() < 2;
+ const auto name = clearAll ? String8() : String8(args[1]);
+
mCurrentState.traverseInZOrder([&](Layer* layer) {
- if (args.size() < 2 || String8(args[1]) == layer->getName()) {
+ if (clearAll || layer->getName() == name.string()) {
layer->clearFrameStats();
}
});
@@ -3924,7 +3921,7 @@
layer->logFrameStats();
});
- mAnimFrameTracker.logAndResetStats(String8("<win-anim>"));
+ mAnimFrameTracker.logAndResetStats("<win-anim>");
}
void SurfaceFlinger::appendSfConfigString(std::string& result) const {
@@ -3982,8 +3979,8 @@
bucketTimeSec, percent);
}
-void SurfaceFlinger::recordBufferingStats(const char* layerName,
- std::vector<OccupancyTracker::Segment>&& history) {
+void SurfaceFlinger::recordBufferingStats(const std::string& layerName,
+ std::vector<OccupancyTracker::Segment>&& history) {
Mutex::Autolock lock(getBE().mBufferingStatsMutex);
auto& stats = getBE().mBufferingStats[layerName];
for (const auto& segment : history) {
@@ -5031,13 +5028,14 @@
drawLayers();
} else {
Rect bounds = getBounds();
+ uint32_t w = static_cast<uint32_t>(bounds.getWidth());
+ uint32_t h = static_cast<uint32_t>(bounds.getHeight());
// In the "childrenOnly" case we reparent the children to a screenshot
// layer which has no properties set and which does not draw.
sp<ContainerLayer> screenshotParentLayer =
- mFlinger->getFactory().createContainerLayer(
- LayerCreationArgs(mFlinger, nullptr, String8("Screenshot Parent"),
- bounds.getWidth(), bounds.getHeight(), 0,
- LayerMetadata()));
+ mFlinger->getFactory().createContainerLayer({mFlinger, nullptr,
+ "Screenshot Parent"s, w, h, 0,
+ LayerMetadata()});
ReparentForDrawing reparent(mLayer, screenshotParentLayer, sourceCrop);
drawLayers();
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 9f3a914..b719245 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -607,27 +607,27 @@
sp<IBinder>* handle, sp<IGraphicBufferProducer>* gbp,
const sp<IBinder>& parentHandle, const sp<Layer>& parentLayer = nullptr);
- status_t createBufferQueueLayer(const sp<Client>& client, const String8& name, uint32_t w,
+ status_t createBufferQueueLayer(const sp<Client>& client, std::string name, uint32_t w,
uint32_t h, uint32_t flags, LayerMetadata metadata,
PixelFormat& format, sp<IBinder>* outHandle,
sp<IGraphicBufferProducer>* outGbp, sp<Layer>* outLayer);
- status_t createBufferStateLayer(const sp<Client>& client, const String8& name, uint32_t w,
+ status_t createBufferStateLayer(const sp<Client>& client, std::string name, uint32_t w,
uint32_t h, uint32_t flags, LayerMetadata metadata,
sp<IBinder>* outHandle, sp<Layer>* outLayer);
- status_t createColorLayer(const sp<Client>& client, const String8& name, uint32_t w, uint32_t h,
+ status_t createColorLayer(const sp<Client>& client, std::string name, uint32_t w, uint32_t h,
uint32_t flags, LayerMetadata metadata, sp<IBinder>* outHandle,
sp<Layer>* outLayer);
- status_t createContainerLayer(const sp<Client>& client, const String8& name, uint32_t w,
+ status_t createContainerLayer(const sp<Client>& client, std::string name, uint32_t w,
uint32_t h, uint32_t flags, LayerMetadata metadata,
sp<IBinder>* outHandle, sp<Layer>* outLayer);
status_t mirrorLayer(const sp<Client>& client, const sp<IBinder>& mirrorFromHandle,
sp<IBinder>* outHandle);
- String8 getUniqueLayerName(const String8& name);
+ std::string getUniqueLayerName(const char* name);
// called when all clients have released all their references to
// this layer meaning it is entirely safe to destroy all
@@ -866,8 +866,8 @@
// Not const because each Layer needs to query Fences and cache timestamps.
void dumpFrameEventsLocked(std::string& result);
- void recordBufferingStats(const char* layerName,
- std::vector<OccupancyTracker::Segment>&& history);
+ void recordBufferingStats(const std::string& layerName,
+ std::vector<OccupancyTracker::Segment>&& history);
void dumpBufferingStats(std::string& result) const;
void dumpDisplayIdentificationData(std::string& result) const;
void dumpRawDisplayIdentificationData(const DumpArgs&, std::string& result) const;
diff --git a/services/surfaceflinger/SurfaceFlingerDefaultFactory.cpp b/services/surfaceflinger/SurfaceFlingerDefaultFactory.cpp
index f0457e3..4f439da 100644
--- a/services/surfaceflinger/SurfaceFlingerDefaultFactory.cpp
+++ b/services/surfaceflinger/SurfaceFlingerDefaultFactory.cpp
@@ -17,12 +17,14 @@
#include <compositionengine/impl/CompositionEngine.h>
#include <ui/GraphicBuffer.h>
+#include "BufferLayerConsumer.h"
#include "BufferQueueLayer.h"
#include "BufferStateLayer.h"
#include "ColorLayer.h"
#include "ContainerLayer.h"
#include "DisplayDevice.h"
#include "Layer.h"
+#include "MonitoredProducer.h"
#include "NativeWindowSurface.h"
#include "StartPropertySetThread.h"
#include "SurfaceFlingerDefaultFactory.h"
@@ -92,6 +94,18 @@
BufferQueue::createBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger);
}
+sp<IGraphicBufferProducer> DefaultFactory::createMonitoredProducer(
+ const sp<IGraphicBufferProducer>& producer, const sp<SurfaceFlinger>& flinger,
+ const wp<Layer>& layer) {
+ return new MonitoredProducer(producer, flinger, layer);
+}
+
+sp<BufferLayerConsumer> DefaultFactory::createBufferLayerConsumer(
+ const sp<IGraphicBufferConsumer>& consumer, renderengine::RenderEngine& renderEngine,
+ uint32_t textureName, Layer* layer) {
+ return new BufferLayerConsumer(consumer, renderEngine, textureName, layer);
+}
+
std::unique_ptr<surfaceflinger::NativeWindowSurface> DefaultFactory::createNativeWindowSurface(
const sp<IGraphicBufferProducer>& producer) {
return surfaceflinger::impl::createNativeWindowSurface(producer);
diff --git a/services/surfaceflinger/SurfaceFlingerDefaultFactory.h b/services/surfaceflinger/SurfaceFlingerDefaultFactory.h
index 89e0679..42bb177 100644
--- a/services/surfaceflinger/SurfaceFlingerDefaultFactory.h
+++ b/services/surfaceflinger/SurfaceFlingerDefaultFactory.h
@@ -42,6 +42,12 @@
void createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
sp<IGraphicBufferConsumer>* outConsumer,
bool consumerIsSurfaceFlinger) override;
+ sp<IGraphicBufferProducer> createMonitoredProducer(const sp<IGraphicBufferProducer>&,
+ const sp<SurfaceFlinger>&,
+ const wp<Layer>&) override;
+ sp<BufferLayerConsumer> createBufferLayerConsumer(const sp<IGraphicBufferConsumer>&,
+ renderengine::RenderEngine&, uint32_t tex,
+ Layer*) override;
std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface(
const sp<IGraphicBufferProducer>&) override;
std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() override;
diff --git a/services/surfaceflinger/SurfaceFlingerFactory.h b/services/surfaceflinger/SurfaceFlingerFactory.h
index 3fd4de8..20784d2 100644
--- a/services/surfaceflinger/SurfaceFlingerFactory.h
+++ b/services/surfaceflinger/SurfaceFlingerFactory.h
@@ -30,6 +30,7 @@
class BufferQueueLayer;
class BufferStateLayer;
+class BufferLayerConsumer;
class ColorLayer;
class ContainerLayer;
class DisplayDevice;
@@ -39,6 +40,7 @@
class HWComposer;
class IGraphicBufferConsumer;
class IGraphicBufferProducer;
+class Layer;
class MessageQueue;
class Scheduler;
class StartPropertySetThread;
@@ -85,6 +87,13 @@
virtual void createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
sp<IGraphicBufferConsumer>* outConsumer,
bool consumerIsSurfaceFlinger) = 0;
+ virtual sp<IGraphicBufferProducer> createMonitoredProducer(const sp<IGraphicBufferProducer>&,
+ const sp<SurfaceFlinger>&,
+ const wp<Layer>&) = 0;
+ virtual sp<BufferLayerConsumer> createBufferLayerConsumer(const sp<IGraphicBufferConsumer>&,
+ renderengine::RenderEngine&,
+ uint32_t tex, Layer*) = 0;
+
virtual std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface(
const sp<IGraphicBufferProducer>&) = 0;
diff --git a/services/surfaceflinger/SurfaceInterceptor.cpp b/services/surfaceflinger/SurfaceInterceptor.cpp
index a02d14c..7e6c472 100644
--- a/services/surfaceflinger/SurfaceInterceptor.cpp
+++ b/services/surfaceflinger/SurfaceInterceptor.cpp
@@ -165,10 +165,6 @@
return layer;
}
-const std::string SurfaceInterceptor::getLayerName(const sp<const Layer>& layer) const {
- return layer->getName().string();
-}
-
int32_t SurfaceInterceptor::getLayerId(const sp<const Layer>& layer) const {
return layer->sequence;
}
@@ -490,7 +486,7 @@
{
SurfaceCreation* creation(increment->mutable_surface_creation());
creation->set_id(getLayerId(layer));
- creation->set_name(getLayerName(layer));
+ creation->set_name(layer->getName());
creation->set_w(layer->mCurrentState.active_legacy.w);
creation->set_h(layer->mCurrentState.active_legacy.h);
}
diff --git a/services/surfaceflinger/SurfaceInterceptor.h b/services/surfaceflinger/SurfaceInterceptor.h
index 6858c4d..72b734b 100644
--- a/services/surfaceflinger/SurfaceInterceptor.h
+++ b/services/surfaceflinger/SurfaceInterceptor.h
@@ -123,7 +123,6 @@
status_t writeProtoFileLocked();
const sp<const Layer> getLayer(const wp<const IBinder>& weakHandle) const;
- const std::string getLayerName(const sp<const Layer>& layer) const;
int32_t getLayerId(const sp<const Layer>& layer) const;
int32_t getLayerIdFromWeakRef(const wp<const Layer>& layer) const;
int32_t getLayerIdFromHandle(const sp<const IBinder>& weakHandle) const;
diff --git a/services/surfaceflinger/tests/RelativeZ_test.cpp b/services/surfaceflinger/tests/RelativeZ_test.cpp
index 8549db2..8c56d27 100644
--- a/services/surfaceflinger/tests/RelativeZ_test.cpp
+++ b/services/surfaceflinger/tests/RelativeZ_test.cpp
@@ -144,4 +144,63 @@
sc->checkPixel(1, 1, Color::GREEN.r, Color::GREEN.g, Color::GREEN.b);
}
}
+
+TEST_F(RelativeZTest, LayerAndRelativeRemoved) {
+ std::unique_ptr<ScreenCapture> sc;
+
+ // Background layer (RED)
+ // Foregroud layer (GREEN)
+ // Child layer (BLUE) (relative to relativeToLayer layer)
+ // Relative layer (WHITE)
+ sp<SurfaceControl> childLayer =
+ createColorLayer("Child layer", Color::BLUE, mForegroundLayer.get());
+ sp<SurfaceControl> relativeToLayer =
+ createColorLayer("Relative layer", Color::WHITE, mForegroundLayer.get());
+
+ Transaction{}
+ .setRelativeLayer(childLayer, relativeToLayer->getHandle(), 1)
+ .show(childLayer)
+ .show(relativeToLayer)
+ .apply();
+
+ {
+ // The childLayer should be in front of relativeToLayer.
+ ScreenCapture::captureScreen(&sc);
+ sc->checkPixel(1, 1, Color::BLUE.r, Color::BLUE.g, Color::BLUE.b);
+ }
+
+ // Remove layer that childLayer is relative to
+ // Background layer (RED)
+ // Foregroud layer (GREEN)
+ // Child layer (BLUE) (relative to relativeToLayer layer)
+ Transaction{}.reparent(relativeToLayer, nullptr).apply();
+ relativeToLayer = 0;
+
+ {
+ // The child layer is relative to an deleted layer so it won't be drawn.
+ ScreenCapture::captureScreen(&sc);
+ sc->checkPixel(1, 1, Color::GREEN.r, Color::GREEN.g, Color::GREEN.b);
+ }
+
+ // Background layer (RED)
+ // Foregroud layer (GREEN)
+ Transaction{}.reparent(childLayer, nullptr).apply();
+
+ {
+ // The child layer is offscreen, so it won't be drawn.
+ ScreenCapture::captureScreen(&sc);
+ sc->checkPixel(1, 1, Color::GREEN.r, Color::GREEN.g, Color::GREEN.b);
+ }
+
+ // Background layer (RED)
+ // Foregroud layer (GREEN)
+ // Child layer (BLUE)
+ Transaction{}.reparent(childLayer, mForegroundLayer->getHandle()).apply();
+
+ {
+ // The relative z info for child layer should be reset, leaving the child layer on top.
+ ScreenCapture::captureScreen(&sc);
+ sc->checkPixel(1, 1, Color::BLUE.r, Color::BLUE.g, Color::BLUE.b);
+ }
+}
} // namespace android
diff --git a/services/surfaceflinger/tests/unittests/CompositionTest.cpp b/services/surfaceflinger/tests/unittests/CompositionTest.cpp
index 8aff096..60da70f 100644
--- a/services/surfaceflinger/tests/unittests/CompositionTest.cpp
+++ b/services/surfaceflinger/tests/unittests/CompositionTest.cpp
@@ -839,7 +839,7 @@
static FlingerLayerType createLayer(CompositionTest* test) {
FlingerLayerType layer = Base::template createLayerWithFactory<ColorLayer>(test, [test]() {
return new ColorLayer(LayerCreationArgs(test->mFlinger.mFlinger.get(), sp<Client>(),
- String8("test-layer"), LayerProperties::WIDTH,
+ "test-layer", LayerProperties::WIDTH,
LayerProperties::HEIGHT,
LayerProperties::LAYER_FLAGS, LayerMetadata()));
});
@@ -879,11 +879,9 @@
FlingerLayerType layer =
Base::template createLayerWithFactory<BufferQueueLayer>(test, [test]() {
sp<Client> client;
- String8 name("test-layer");
- LayerCreationArgs args =
- LayerCreationArgs(test->mFlinger.mFlinger.get(), client, name,
- LayerProperties::WIDTH, LayerProperties::HEIGHT,
- LayerProperties::LAYER_FLAGS, LayerMetadata());
+ LayerCreationArgs args(test->mFlinger.mFlinger.get(), client, "test-layer",
+ LayerProperties::WIDTH, LayerProperties::HEIGHT,
+ LayerProperties::LAYER_FLAGS, LayerMetadata());
args.textureName = test->mFlinger.mutableTexturePool().back();
return new BufferQueueLayer(args);
});
diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
index b85c1b6..c7664fb 100644
--- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
+++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
@@ -62,23 +62,19 @@
~Factory() = default;
std::unique_ptr<DispSync> createDispSync(const char*, bool) override {
- // TODO: Use test-fixture controlled factory
return nullptr;
}
std::unique_ptr<EventControlThread> createEventControlThread(
std::function<void(bool)>) override {
- // TODO: Use test-fixture controlled factory
return nullptr;
}
std::unique_ptr<HWComposer> createHWComposer(const std::string&) override {
- // TODO: Use test-fixture controlled factory
return nullptr;
}
std::unique_ptr<MessageQueue> createMessageQueue() override {
- // TODO: Use test-fixture controlled factory
return std::make_unique<android::impl::MessageQueue>();
}
@@ -88,39 +84,49 @@
std::unique_ptr<Scheduler> createScheduler(std::function<void(bool)>,
const scheduler::RefreshRateConfigs&) override {
- // TODO: Use test-fixture controlled factory
return nullptr;
}
std::unique_ptr<SurfaceInterceptor> createSurfaceInterceptor(SurfaceFlinger* flinger) override {
- // TODO: Use test-fixture controlled factory
return std::make_unique<android::impl::SurfaceInterceptor>(flinger);
}
sp<StartPropertySetThread> createStartPropertySetThread(bool timestampPropertyValue) override {
- // TODO: Use test-fixture controlled factory
return new StartPropertySetThread(timestampPropertyValue);
}
sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs&& creationArgs) override {
- // TODO: Use test-fixture controlled factory
return new DisplayDevice(std::move(creationArgs));
}
sp<GraphicBuffer> createGraphicBuffer(uint32_t width, uint32_t height, PixelFormat format,
uint32_t layerCount, uint64_t usage,
std::string requestorName) override {
- // TODO: Use test-fixture controlled factory
return new GraphicBuffer(width, height, format, layerCount, usage, requestorName);
}
void createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
sp<IGraphicBufferConsumer>* outConsumer,
bool consumerIsSurfaceFlinger) override {
- if (!mCreateBufferQueue) return;
+ if (!mCreateBufferQueue) {
+ BufferQueue::createBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger);
+ return;
+ }
mCreateBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger);
}
+ sp<IGraphicBufferProducer> createMonitoredProducer(const sp<IGraphicBufferProducer>& producer,
+ const sp<SurfaceFlinger>& flinger,
+ const wp<Layer>& layer) override {
+ return new MonitoredProducer(producer, flinger, layer);
+ }
+
+ sp<BufferLayerConsumer> createBufferLayerConsumer(const sp<IGraphicBufferConsumer>& consumer,
+ renderengine::RenderEngine& renderEngine,
+ uint32_t textureName, Layer* layer) override {
+ return new BufferLayerConsumer(consumer, renderEngine, textureName, layer);
+ }
+
std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface(
const sp<IGraphicBufferProducer>& producer) override {
if (!mCreateNativeWindowSurface) return nullptr;
@@ -132,22 +138,18 @@
}
sp<BufferQueueLayer> createBufferQueueLayer(const LayerCreationArgs&) override {
- // TODO: Use test-fixture controlled factory
return nullptr;
}
sp<BufferStateLayer> createBufferStateLayer(const LayerCreationArgs&) override {
- // TODO: Use test-fixture controlled factory
return nullptr;
}
sp<ColorLayer> createColorLayer(const LayerCreationArgs&) override {
- // TODO: Use test-fixture controlled factory
return nullptr;
}
sp<ContainerLayer> createContainerLayer(const LayerCreationArgs&) override {
- // TODO: Use test-fixture controlled factory
return nullptr;
}