Merge "Collect update_engine logs in dumpstate" into pi-dev
diff --git a/cmds/atrace/atrace.rc b/cmds/atrace/atrace.rc
index cb6d0c6..8421568 100644
--- a/cmds/atrace/atrace.rc
+++ b/cmds/atrace/atrace.rc
@@ -104,6 +104,12 @@
chmod 0666 /sys/kernel/tracing/events/block/block_rq_complete/enable
chmod 0666 /sys/kernel/debug/tracing/events/block/block_rq_complete/enable
+ # graphics
+ chmod 0666 /sys/kernel/tracing/events/sde/enable
+ chmod 0666 /sys/kernel/debug/tracing/events/sde/enable
+ chmod 0666 /sys/kernel/tracing/events/mdss/enable
+ chmod 0666 /sys/kernel/debug/tracing/events/mdss/enable
+
# Tracing disabled by default
write /sys/kernel/debug/tracing/tracing_on 0
write /sys/kernel/tracing/tracing_on 0
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 8330fe5..5ce597a 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -1433,19 +1433,40 @@
printf("== Running Application Activities\n");
printf("========================================================\n");
- RunDumpsys("APP ACTIVITIES", {"activity", "-v", "all"});
+ // The following dumpsys internally collects output from running apps, so it can take a long
+ // time. So let's extend the timeout.
+
+ const CommandOptions DUMPSYS_COMPONENTS_OPTIONS = CommandOptions::WithTimeout(60).Build();
+
+ RunDumpsys("APP ACTIVITIES", {"activity", "-v", "all"}, DUMPSYS_COMPONENTS_OPTIONS);
printf("========================================================\n");
- printf("== Running Application Services\n");
+ printf("== Running Application Services (platform)\n");
printf("========================================================\n");
- RunDumpsys("APP SERVICES", {"activity", "service", "all"});
+ RunDumpsys("APP SERVICES PLATFORM", {"activity", "service", "all-platform"},
+ DUMPSYS_COMPONENTS_OPTIONS);
printf("========================================================\n");
- printf("== Running Application Providers\n");
+ printf("== Running Application Services (non-platform)\n");
printf("========================================================\n");
- RunDumpsys("APP PROVIDERS", {"activity", "provider", "all"});
+ RunDumpsys("APP SERVICES NON-PLATFORM", {"activity", "service", "all-non-platform"},
+ DUMPSYS_COMPONENTS_OPTIONS);
+
+ printf("========================================================\n");
+ printf("== Running Application Providers (platform)\n");
+ printf("========================================================\n");
+
+ RunDumpsys("APP PROVIDERS PLATFORM", {"activity", "provider", "all-platform"},
+ DUMPSYS_COMPONENTS_OPTIONS);
+
+ printf("========================================================\n");
+ printf("== Running Application Providers (non-platform)\n");
+ printf("========================================================\n");
+
+ RunDumpsys("APP PROVIDERS NON-PLATFORM", {"activity", "provider", "all-non-platform"},
+ DUMPSYS_COMPONENTS_OPTIONS);
printf("========================================================\n");
printf("== Dropbox crashes\n");
diff --git a/cmds/installd/otapreopt_chroot.cpp b/cmds/installd/otapreopt_chroot.cpp
index c402c3c..3ae56db 100644
--- a/cmds/installd/otapreopt_chroot.cpp
+++ b/cmds/installd/otapreopt_chroot.cpp
@@ -114,14 +114,29 @@
LOG(ERROR) << "Target slot suffix not legal: " << arg[2];
exit(207);
}
- std::string vendor_partition = StringPrintf("/dev/block/bootdevice/by-name/vendor%s",
- arg[2]);
- int vendor_result = mount(vendor_partition.c_str(),
- "/postinstall/vendor",
- "ext4",
- MS_RDONLY,
- /* data */ nullptr);
- UNUSED(vendor_result);
+ {
+ std::string vendor_partition = StringPrintf("/dev/block/bootdevice/by-name/vendor%s",
+ arg[2]);
+ int vendor_result = mount(vendor_partition.c_str(),
+ "/postinstall/vendor",
+ "ext4",
+ MS_RDONLY,
+ /* data */ nullptr);
+ UNUSED(vendor_result);
+ }
+
+ // Try to mount the product partition. update_engine doesn't do this for us, but we
+ // want it for product APKs. Same notes as vendor above.
+ {
+ std::string product_partition = StringPrintf("/dev/block/bootdevice/by-name/product%s",
+ arg[2]);
+ int product_result = mount(product_partition.c_str(),
+ "/postinstall/product",
+ "ext4",
+ MS_RDONLY,
+ /* data */ nullptr);
+ UNUSED(product_result);
+ }
// Chdir into /postinstall.
if (chdir("/postinstall") != 0) {
diff --git a/data/etc/android.hardware.strongbox_keystore.xml b/data/etc/android.hardware.strongbox_keystore.xml
new file mode 100644
index 0000000..2a0ec37
--- /dev/null
+++ b/data/etc/android.hardware.strongbox_keystore.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 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.
+-->
+
+<!-- Feature for devices with Keymaster in StrongBox. -->
+<permissions>
+ <feature name="android.hardware.strongbox_keystore" />
+</permissions>
diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp
index 6103188..7c1eaaf 100644
--- a/libs/binder/Android.bp
+++ b/libs/binder/Android.bp
@@ -75,6 +75,28 @@
":libbinder_aidl",
],
+ target: {
+ vendor: {
+ exclude_srcs: [
+ "ActivityManager.cpp",
+ "AppOpsManager.cpp",
+ "IActivityManager.cpp",
+ "IAppOpsCallback.cpp",
+ "IAppOpsService.cpp",
+ "IBatteryStats.cpp",
+ "IMediaResourceMonitor.cpp",
+ "IPermissionController.cpp",
+ "IProcessInfoService.cpp",
+ "IUidObserver.cpp",
+ "PermissionCache.cpp",
+ "PermissionController.cpp",
+ "ProcessInfoService.cpp",
+ "IpPrefix.cpp",
+ ":libbinder_aidl",
+ ],
+ },
+ },
+
aidl: {
export_aidl_headers: true,
},
diff --git a/libs/binder/IPermissionController.cpp b/libs/binder/IPermissionController.cpp
index ef67ab8..89ebc6c 100644
--- a/libs/binder/IPermissionController.cpp
+++ b/libs/binder/IPermissionController.cpp
@@ -49,6 +49,19 @@
return reply.readInt32() != 0;
}
+ virtual int32_t noteOp(const String16& op, int32_t uid, const String16& packageName)
+ {
+ Parcel data, reply;
+ data.writeInterfaceToken(IPermissionController::getInterfaceDescriptor());
+ data.writeString16(op);
+ data.writeInt32(uid);
+ data.writeString16(packageName);
+ remote()->transact(NOTE_OP_TRANSACTION, data, &reply);
+ // fail on exception
+ if (reply.readExceptionCode() != 0) return 2; // MODE_ERRORED
+ return reply.readInt32();
+ }
+
virtual void getPackagesForUid(const uid_t uid, Vector<String16>& packages)
{
Parcel data, reply;
@@ -111,6 +124,17 @@
return NO_ERROR;
} break;
+ case NOTE_OP_TRANSACTION: {
+ CHECK_INTERFACE(IPermissionController, data, reply);
+ String16 op = data.readString16();
+ int32_t uid = data.readInt32();
+ String16 packageName = data.readString16();
+ int32_t res = noteOp(op, uid, packageName);
+ reply->writeNoException();
+ reply->writeInt32(res);
+ return NO_ERROR;
+ } break;
+
case GET_PACKAGES_FOR_UID_TRANSACTION: {
CHECK_INTERFACE(IPermissionController, data, reply);
int32_t uid = data.readInt32();
diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp
index 70f5108..711143c 100644
--- a/libs/binder/IServiceManager.cpp
+++ b/libs/binder/IServiceManager.cpp
@@ -20,6 +20,9 @@
#include <utils/Log.h>
#include <binder/IPCThreadState.h>
+#ifndef __ANDROID_VNDK__
+#include <binder/IPermissionController.h>
+#endif
#include <binder/Parcel.h>
#include <utils/String8.h>
#include <utils/SystemClock.h>
@@ -48,6 +51,9 @@
return gDefaultServiceManager;
}
+#ifndef __ANDROID_VNDK__
+// IPermissionController is not accessible to vendors
+
bool checkCallingPermission(const String16& permission)
{
return checkCallingPermission(permission, NULL, NULL);
@@ -122,6 +128,8 @@
}
}
+#endif //__ANDROID_VNDK__
+
// ----------------------------------------------------------------------
class BpServiceManager : public BpInterface<IServiceManager>
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index cb542bf..2e7edd7 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -1535,7 +1535,12 @@
&& len <= pad_size(len)) {
if (mObjectsSize > 0) {
status_t err = validateReadData(mDataPos + pad_size(len));
- if(err != NO_ERROR) return err;
+ if(err != NO_ERROR) {
+ // Still increment the data position by the expected length
+ mDataPos += pad_size(len);
+ ALOGV("read Setting data pos of %p to %zu", this, mDataPos);
+ return err;
+ }
}
memcpy(outData, mData+mDataPos, len);
mDataPos += pad_size(len);
@@ -1557,7 +1562,12 @@
&& len <= pad_size(len)) {
if (mObjectsSize > 0) {
status_t err = validateReadData(mDataPos + pad_size(len));
- if(err != NO_ERROR) return NULL;
+ if(err != NO_ERROR) {
+ // Still increment the data position by the expected length
+ mDataPos += pad_size(len);
+ ALOGV("readInplace Setting data pos of %p to %zu", this, mDataPos);
+ return NULL;
+ }
}
const void* data = mData+mDataPos;
@@ -1575,7 +1585,11 @@
if ((mDataPos+sizeof(T)) <= mDataSize) {
if (mObjectsSize > 0) {
status_t err = validateReadData(mDataPos + sizeof(T));
- if(err != NO_ERROR) return err;
+ if(err != NO_ERROR) {
+ // Still increment the data position by the expected length
+ mDataPos += sizeof(T);
+ return err;
+ }
}
const void* data = mData+mDataPos;
diff --git a/libs/binder/PermissionController.cpp b/libs/binder/PermissionController.cpp
index 25748ca..96df33c 100644
--- a/libs/binder/PermissionController.cpp
+++ b/libs/binder/PermissionController.cpp
@@ -59,6 +59,12 @@
return service != NULL ? service->checkPermission(permission, pid, uid) : false;
}
+int32_t PermissionController::noteOp(const String16& op, int32_t uid, const String16& packageName)
+{
+ sp<IPermissionController> service = getService();
+ return service != NULL ? service->noteOp(op, uid, packageName) : MODE_ERRORED;
+}
+
void PermissionController::getPackagesForUid(const uid_t uid, Vector<String16> &packages)
{
sp<IPermissionController> service = getService();
diff --git a/libs/binder/Static.cpp b/libs/binder/Static.cpp
index f0613d1..9899b65 100644
--- a/libs/binder/Static.cpp
+++ b/libs/binder/Static.cpp
@@ -94,6 +94,8 @@
Mutex gDefaultServiceManagerLock;
sp<IServiceManager> gDefaultServiceManager;
+#ifndef __ANDROID_VNDK__
sp<IPermissionController> gPermissionController;
+#endif
} // namespace android
diff --git a/libs/binder/include/binder/ActivityManager.h b/libs/binder/include/binder/ActivityManager.h
index 3090cae..b8db091 100644
--- a/libs/binder/include/binder/ActivityManager.h
+++ b/libs/binder/include/binder/ActivityManager.h
@@ -17,6 +17,8 @@
#ifndef ANDROID_ACTIVITY_MANAGER_H
#define ANDROID_ACTIVITY_MANAGER_H
+#ifndef __ANDROID_VNDK__
+
#include <binder/IActivityManager.h>
#include <utils/threads.h>
@@ -64,4 +66,8 @@
}; // namespace android
// ---------------------------------------------------------------------------
+#else // __ANDROID_VNDK__
+#error "This header is not visible to vendors"
+#endif // __ANDROID_VNDK__
+
#endif // ANDROID_ACTIVITY_MANAGER_H
diff --git a/libs/binder/include/binder/AppOpsManager.h b/libs/binder/include/binder/AppOpsManager.h
index a44d270..c5b57c7 100644
--- a/libs/binder/include/binder/AppOpsManager.h
+++ b/libs/binder/include/binder/AppOpsManager.h
@@ -17,6 +17,8 @@
#ifndef ANDROID_APP_OPS_MANAGER_H
#define ANDROID_APP_OPS_MANAGER_H
+#ifndef __ANDROID_VNDK__
+
#include <binder/IAppOpsService.h>
#include <utils/threads.h>
@@ -117,4 +119,8 @@
}; // namespace android
// ---------------------------------------------------------------------------
+#else // __ANDROID_VNDK__
+#error "This header is not visible to vendors"
+#endif // __ANDROID_VNDK__
+
#endif // ANDROID_APP_OPS_MANAGER_H
diff --git a/libs/binder/include/binder/IActivityManager.h b/libs/binder/include/binder/IActivityManager.h
index 6607c0e..f34969b 100644
--- a/libs/binder/include/binder/IActivityManager.h
+++ b/libs/binder/include/binder/IActivityManager.h
@@ -17,6 +17,8 @@
#ifndef ANDROID_IACTIVITY_MANAGER_H
#define ANDROID_IACTIVITY_MANAGER_H
+#ifndef __ANDROID_VNDK__
+
#include <binder/IInterface.h>
#include <binder/IUidObserver.h>
@@ -49,4 +51,8 @@
}; // namespace android
+#else // __ANDROID_VNDK__
+#error "This header is not visible to vendors"
+#endif // __ANDROID_VNDK__
+
#endif // ANDROID_IACTIVITY_MANAGER_H
diff --git a/libs/binder/include/binder/IAppOpsCallback.h b/libs/binder/include/binder/IAppOpsCallback.h
index b62e9e2..e5b12a9 100644
--- a/libs/binder/include/binder/IAppOpsCallback.h
+++ b/libs/binder/include/binder/IAppOpsCallback.h
@@ -18,6 +18,8 @@
#ifndef ANDROID_IAPP_OPS_CALLBACK_H
#define ANDROID_IAPP_OPS_CALLBACK_H
+#ifndef __ANDROID_VNDK__
+
#include <binder/IInterface.h>
namespace android {
@@ -51,5 +53,9 @@
}; // namespace android
+#else // __ANDROID_VNDK__
+#error "This header is not visible to vendors"
+#endif // __ANDROID_VNDK__
+
#endif // ANDROID_IAPP_OPS_CALLBACK_H
diff --git a/libs/binder/include/binder/IAppOpsService.h b/libs/binder/include/binder/IAppOpsService.h
index ecba5d6..f0c5e17 100644
--- a/libs/binder/include/binder/IAppOpsService.h
+++ b/libs/binder/include/binder/IAppOpsService.h
@@ -18,6 +18,8 @@
#ifndef ANDROID_IAPP_OPS_SERVICE_H
#define ANDROID_IAPP_OPS_SERVICE_H
+#ifndef __ANDROID_VNDK__
+
#include <binder/IAppOpsCallback.h>
#include <binder/IInterface.h>
@@ -75,4 +77,8 @@
}; // namespace android
+#else // __ANDROID_VNDK__
+#error "This header is not visible to vendors"
+#endif // __ANDROID_VNDK__
+
#endif // ANDROID_IAPP_OPS_SERVICE_H
diff --git a/libs/binder/include/binder/IBatteryStats.h b/libs/binder/include/binder/IBatteryStats.h
index e15d6f0..59e806c 100644
--- a/libs/binder/include/binder/IBatteryStats.h
+++ b/libs/binder/include/binder/IBatteryStats.h
@@ -17,6 +17,8 @@
#ifndef ANDROID_IBATTERYSTATS_H
#define ANDROID_IBATTERYSTATS_H
+#ifndef __ANDROID_VNDK__
+
#include <binder/IInterface.h>
namespace android {
@@ -76,4 +78,8 @@
}; // namespace android
+#else // __ANDROID_VNDK__
+#error "This header is not visible to vendors"
+#endif // __ANDROID_VNDK__
+
#endif // ANDROID_IBATTERYSTATS_H
diff --git a/libs/binder/include/binder/IMediaResourceMonitor.h b/libs/binder/include/binder/IMediaResourceMonitor.h
index b21047f..213ee63 100644
--- a/libs/binder/include/binder/IMediaResourceMonitor.h
+++ b/libs/binder/include/binder/IMediaResourceMonitor.h
@@ -17,6 +17,8 @@
#ifndef ANDROID_I_MEDIA_RESOURCE_MONITOR_H
#define ANDROID_I_MEDIA_RESOURCE_MONITOR_H
+#ifndef __ANDROID_VNDK__
+
#include <binder/IInterface.h>
namespace android {
@@ -52,4 +54,8 @@
}; // namespace android
+#else // __ANDROID_VNDK__
+#error "This header is not visible to vendors"
+#endif // __ANDROID_VNDK__
+
#endif // ANDROID_I_MEDIA_RESOURCE_MONITOR_H
diff --git a/libs/binder/include/binder/IPermissionController.h b/libs/binder/include/binder/IPermissionController.h
index 2f63677..3ec459f 100644
--- a/libs/binder/include/binder/IPermissionController.h
+++ b/libs/binder/include/binder/IPermissionController.h
@@ -18,6 +18,8 @@
#ifndef ANDROID_IPERMISSION_CONTROLLER_H
#define ANDROID_IPERMISSION_CONTROLLER_H
+#ifndef __ANDROID_VNDK__
+
#include <binder/IInterface.h>
#include <stdlib.h>
@@ -32,6 +34,8 @@
virtual bool checkPermission(const String16& permission, int32_t pid, int32_t uid) = 0;
+ virtual int32_t noteOp(const String16& op, int32_t uid, const String16& packageName) = 0;
+
virtual void getPackagesForUid(const uid_t uid, Vector<String16> &packages) = 0;
virtual bool isRuntimePermission(const String16& permission) = 0;
@@ -40,9 +44,10 @@
enum {
CHECK_PERMISSION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
- GET_PACKAGES_FOR_UID_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION + 1,
- IS_RUNTIME_PERMISSION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION + 2,
- GET_PACKAGE_UID_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION + 3
+ NOTE_OP_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION + 1,
+ GET_PACKAGES_FOR_UID_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION + 2,
+ IS_RUNTIME_PERMISSION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION + 3,
+ GET_PACKAGE_UID_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION + 4
};
};
@@ -61,5 +66,9 @@
}; // namespace android
+#else // __ANDROID_VNDK__
+#error "This header is not visible to vendors"
+#endif // __ANDROID_VNDK__
+
#endif // ANDROID_IPERMISSION_CONTROLLER_H
diff --git a/libs/binder/include/binder/IProcessInfoService.h b/libs/binder/include/binder/IProcessInfoService.h
index 2669f91..033c145 100644
--- a/libs/binder/include/binder/IProcessInfoService.h
+++ b/libs/binder/include/binder/IProcessInfoService.h
@@ -17,6 +17,8 @@
#ifndef ANDROID_I_PROCESS_INFO_SERVICE_H
#define ANDROID_I_PROCESS_INFO_SERVICE_H
+#ifndef __ANDROID_VNDK__
+
#include <binder/IInterface.h>
namespace android {
@@ -46,4 +48,8 @@
}; // namespace android
+#else // __ANDROID_VNDK__
+#error "This header is not visible to vendors"
+#endif // __ANDROID_VNDK__
+
#endif // ANDROID_I_PROCESS_INFO_SERVICE_H
diff --git a/libs/binder/include/binder/IServiceManager.h b/libs/binder/include/binder/IServiceManager.h
index cf4c08a..197026d 100644
--- a/libs/binder/include/binder/IServiceManager.h
+++ b/libs/binder/include/binder/IServiceManager.h
@@ -19,7 +19,6 @@
#define ANDROID_ISERVICE_MANAGER_H
#include <binder/IInterface.h>
-#include <binder/IPermissionController.h>
#include <utils/Vector.h>
#include <utils/String16.h>
diff --git a/libs/binder/include/binder/IUidObserver.h b/libs/binder/include/binder/IUidObserver.h
index fd4d8a6..d81789e 100644
--- a/libs/binder/include/binder/IUidObserver.h
+++ b/libs/binder/include/binder/IUidObserver.h
@@ -18,6 +18,8 @@
#ifndef ANDROID_IUID_OBSERVER_H
#define ANDROID_IUID_OBSERVER_H
+#ifndef __ANDROID_VNDK__
+
#include <binder/IInterface.h>
namespace android {
@@ -55,4 +57,8 @@
}; // namespace android
+#else // __ANDROID_VNDK__
+#error "This header is not visible to vendors"
+#endif // __ANDROID_VNDK__
+
#endif // ANDROID_IUID_OBSERVER_H
diff --git a/libs/binder/include/binder/IpPrefix.h b/libs/binder/include/binder/IpPrefix.h
index 96ebaac..dd5bc3a 100644
--- a/libs/binder/include/binder/IpPrefix.h
+++ b/libs/binder/include/binder/IpPrefix.h
@@ -17,6 +17,8 @@
#ifndef ANDROID_IP_PREFIX_H
#define ANDROID_IP_PREFIX_H
+#ifndef __ANDROID_VNDK__
+
#include <netinet/in.h>
#include <binder/Parcelable.h>
@@ -85,4 +87,8 @@
} // namespace android
+#else // __ANDROID_VNDK__
+#error "This header is not visible to vendors"
+#endif // __ANDROID_VNDK__
+
#endif // ANDROID_IP_PREFIX_H
diff --git a/libs/binder/include/binder/PermissionCache.h b/libs/binder/include/binder/PermissionCache.h
index bcdf0c2..95eabff 100644
--- a/libs/binder/include/binder/PermissionCache.h
+++ b/libs/binder/include/binder/PermissionCache.h
@@ -17,6 +17,8 @@
#ifndef BINDER_PERMISSION_H
#define BINDER_PERMISSION_H
+#ifndef __ANDROID_VNDK__
+
#include <stdint.h>
#include <unistd.h>
@@ -77,4 +79,8 @@
// ---------------------------------------------------------------------------
}; // namespace android
+#else // __ANDROID_VNDK__
+#error "This header is not visible to vendors"
+#endif // __ANDROID_VNDK__
+
#endif /* BINDER_PERMISSION_H */
diff --git a/libs/binder/include/binder/PermissionController.h b/libs/binder/include/binder/PermissionController.h
index c4c98d0..d81f514 100644
--- a/libs/binder/include/binder/PermissionController.h
+++ b/libs/binder/include/binder/PermissionController.h
@@ -17,6 +17,8 @@
#ifndef ANDROID_PERMISSION_CONTROLLER_H
#define ANDROID_PERMISSION_CONTROLLER_H
+#ifndef __ANDROID_VNDK__
+
#include <binder/IPermissionController.h>
#include <utils/threads.h>
@@ -35,9 +37,17 @@
MATCH_INSTANT = 1<<23
};
+ enum {
+ MODE_ALLOWED = 0,
+ MODE_IGNORED = 1,
+ MODE_ERRORED = 2,
+ MODE_DEFAULT = 3,
+ };
+
PermissionController();
bool checkPermission(const String16& permission, int32_t pid, int32_t uid);
+ int32_t noteOp(const String16& op, int32_t uid, const String16& packageName);
void getPackagesForUid(const uid_t uid, Vector<String16>& packages);
bool isRuntimePermission(const String16& permission);
int getPackageUid(const String16& package, int flags);
@@ -52,4 +62,8 @@
}; // namespace android
// ---------------------------------------------------------------------------
+#else // __ANDROID_VNDK__
+#error "This header is not visible to vendors"
+#endif // __ANDROID_VNDK__
+
#endif // ANDROID_PERMISSION_CONTROLLER_H
diff --git a/libs/binder/include/binder/ProcessInfoService.h b/libs/binder/include/binder/ProcessInfoService.h
index 0da61ee..a03aae9 100644
--- a/libs/binder/include/binder/ProcessInfoService.h
+++ b/libs/binder/include/binder/ProcessInfoService.h
@@ -17,6 +17,8 @@
#ifndef ANDROID_PROCESS_INFO_SERVICE_H
#define ANDROID_PROCESS_INFO_SERVICE_H
+#ifndef __ANDROID_VNDK__
+
#include <binder/IProcessInfoService.h>
#include <utils/Errors.h>
#include <utils/Singleton.h>
@@ -78,5 +80,9 @@
}; // namespace android
+#else // __ANDROID_VNDK__
+#error "This header is not visible to vendors"
+#endif // __ANDROID_VNDK__
+
#endif // ANDROID_PROCESS_INFO_SERVICE_H
diff --git a/libs/binder/include/private/binder/Static.h b/libs/binder/include/private/binder/Static.h
index 3d10456..f04bcae 100644
--- a/libs/binder/include/private/binder/Static.h
+++ b/libs/binder/include/private/binder/Static.h
@@ -21,7 +21,9 @@
#include <binder/IBinder.h>
#include <binder/ProcessState.h>
+#ifndef __ANDROID_VNDK__
#include <binder/IPermissionController.h>
+#endif
#include <binder/IServiceManager.h>
namespace android {
@@ -36,6 +38,8 @@
// For IServiceManager.cpp
extern Mutex gDefaultServiceManagerLock;
extern sp<IServiceManager> gDefaultServiceManager;
+#ifndef __ANDROID_VNDK__
extern sp<IPermissionController> gPermissionController;
+#endif
} // namespace android
diff --git a/libs/dumputils/dump_utils.cpp b/libs/dumputils/dump_utils.cpp
index 835da20..8f6b1bd 100644
--- a/libs/dumputils/dump_utils.cpp
+++ b/libs/dumputils/dump_utils.cpp
@@ -47,6 +47,7 @@
"android.hardware.drm@1.0::IDrmFactory",
"android.hardware.graphics.composer@2.1::IComposer",
"android.hardware.media.omx@1.0::IOmx",
+ "android.hardware.media.omx@1.0::IOmxStore",
"android.hardware.sensors@1.0::ISensors",
"android.hardware.vr@1.0::IVr",
NULL,
diff --git a/libs/gui/BufferQueueConsumer.cpp b/libs/gui/BufferQueueConsumer.cpp
index 17cf677..d70e142 100644
--- a/libs/gui/BufferQueueConsumer.cpp
+++ b/libs/gui/BufferQueueConsumer.cpp
@@ -35,7 +35,9 @@
#include <gui/IProducerListener.h>
#include <binder/IPCThreadState.h>
+#ifndef __ANDROID_VNDK__
#include <binder/PermissionCache.h>
+#endif
#include <system/window.h>
@@ -757,12 +759,18 @@
}
const IPCThreadState* ipc = IPCThreadState::self();
- const pid_t pid = ipc->getCallingPid();
const uid_t uid = ipc->getCallingUid();
+#ifndef __ANDROID_VNDK__
+ // permission check can't be done for vendors as vendors have no access to
+ // the PermissionController
+ const pid_t pid = ipc->getCallingPid();
if ((uid != shellUid) &&
!PermissionCache::checkPermission(String16("android.permission.DUMP"), pid, uid)) {
outResult->appendFormat("Permission Denial: can't dump BufferQueueConsumer "
"from pid=%d, uid=%d\n", pid, uid);
+#else
+ if (uid != shellUid) {
+#endif
android_errorWriteWithInfoLog(0x534e4554, "27046057",
static_cast<int32_t>(uid), NULL, 0);
return PERMISSION_DENIED;
diff --git a/libs/nativewindow/include/android/hardware_buffer.h b/libs/nativewindow/include/android/hardware_buffer.h
index cc67aca..78cec41 100644
--- a/libs/nativewindow/include/android/hardware_buffer.h
+++ b/libs/nativewindow/include/android/hardware_buffer.h
@@ -214,7 +214,7 @@
* Allocates a buffer that backs an AHardwareBuffer using the passed
* AHardwareBuffer_Desc.
*
- * \return NO_ERROR on success, or an error number of the allocation fails for
+ * \return 0 on success, or an error number of the allocation fails for
* any reason. The returned buffer has a reference count of 1.
*/
int AHardwareBuffer_allocate(const AHardwareBuffer_Desc* desc,
@@ -267,7 +267,7 @@
* may return an error or leave the buffer's content into an indeterminate
* state.
*
- * \return NO_ERROR on success, BAD_VALUE if \a buffer is NULL or if the usage
+ * \return 0 on success, -EINVAL if \a buffer is NULL or if the usage
* flags are not a combination of AHARDWAREBUFFER_USAGE_CPU_*, or an error
* number of the lock fails for any reason.
*/
@@ -281,7 +281,7 @@
* completed. The caller is responsible for closing the fence when it is no
* longer needed.
*
- * \return NO_ERROR on success, BAD_VALUE if \a buffer is NULL, or an error
+ * \return 0 on success, -EINVAL if \a buffer is NULL, or an error
* number if the unlock fails for any reason.
*/
int AHardwareBuffer_unlock(AHardwareBuffer* buffer, int32_t* fence);
@@ -289,7 +289,7 @@
/**
* Send the AHardwareBuffer to an AF_UNIX socket.
*
- * \return NO_ERROR on success, BAD_VALUE if \a buffer is NULL, or an error
+ * \return 0 on success, -EINVAL if \a buffer is NULL, or an error
* number if the operation fails for any reason.
*/
int AHardwareBuffer_sendHandleToUnixSocket(const AHardwareBuffer* buffer, int socketFd);
@@ -297,7 +297,7 @@
/**
* Receive the AHardwareBuffer from an AF_UNIX socket.
*
- * \return NO_ERROR on success, BAD_VALUE if \a outBuffer is NULL, or an error
+ * \return 0 on success, -EINVAL if \a outBuffer is NULL, or an error
* number if the operation fails for any reason.
*/
int AHardwareBuffer_recvHandleFromUnixSocket(int socketFd, AHardwareBuffer** outBuffer);
diff --git a/libs/sensor/SensorManager.cpp b/libs/sensor/SensorManager.cpp
index 6fe72a1..b9ae524 100644
--- a/libs/sensor/SensorManager.cpp
+++ b/libs/sensor/SensorManager.cpp
@@ -27,6 +27,7 @@
#include <utils/Singleton.h>
#include <binder/IBinder.h>
+#include <binder/IPermissionController.h>
#include <binder/IServiceManager.h>
#include <sensor/ISensorServer.h>
diff --git a/libs/ui/HdrCapabilities.cpp b/libs/ui/HdrCapabilities.cpp
index 755e60c..50f9bf1 100644
--- a/libs/ui/HdrCapabilities.cpp
+++ b/libs/ui/HdrCapabilities.cpp
@@ -33,7 +33,7 @@
sizeof(mMaxAverageLuminance) +
sizeof(mMinLuminance) +
sizeof(int32_t) +
- mSupportedHdrTypes.size() * sizeof(int32_t);
+ mSupportedHdrTypes.size() * sizeof(ui::Hdr);
}
status_t HdrCapabilities::flatten(void* buffer, size_t size) const {
@@ -48,7 +48,7 @@
reinterpret_cast<float&>(buf[2]) = mMinLuminance;
buf[3] = static_cast<int32_t>(mSupportedHdrTypes.size());
for (size_t i = 0, c = mSupportedHdrTypes.size(); i < c; ++i) {
- buf[4 + i] = mSupportedHdrTypes[i];
+ buf[4 + i] = static_cast<int32_t>(mSupportedHdrTypes[i]);
}
return NO_ERROR;
}
@@ -78,7 +78,7 @@
if (itemCount) {
mSupportedHdrTypes.resize(itemCount);
for (size_t i = 0; i < itemCount; ++i) {
- mSupportedHdrTypes[i] = buf[4 + i];
+ mSupportedHdrTypes[i] = static_cast<ui::Hdr>(buf[4 + i]);
}
}
return NO_ERROR;
diff --git a/libs/ui/include/ui/GraphicTypes.h b/libs/ui/include/ui/GraphicTypes.h
index bd5722f..0fa819d 100644
--- a/libs/ui/include/ui/GraphicTypes.h
+++ b/libs/ui/include/ui/GraphicTypes.h
@@ -24,6 +24,7 @@
namespace android {
namespace ui {
+using android::hardware::graphics::common::V1_0::Hdr;
using android::hardware::graphics::common::V1_1::ColorMode;
using android::hardware::graphics::common::V1_1::Dataspace;
using android::hardware::graphics::common::V1_1::PixelFormat;
diff --git a/libs/ui/include/ui/HdrCapabilities.h b/libs/ui/include/ui/HdrCapabilities.h
index 925aa1b..4e98c28 100644
--- a/libs/ui/include/ui/HdrCapabilities.h
+++ b/libs/ui/include/ui/HdrCapabilities.h
@@ -21,6 +21,7 @@
#include <vector>
+#include <ui/GraphicTypes.h>
#include <utils/Flattenable.h>
namespace android {
@@ -28,7 +29,7 @@
class HdrCapabilities : public LightFlattenable<HdrCapabilities>
{
public:
- HdrCapabilities(const std::vector<int32_t /*android_hdr_t*/>& types,
+ HdrCapabilities(const std::vector<ui::Hdr>& types,
float maxLuminance, float maxAverageLuminance, float minLuminance)
: mSupportedHdrTypes(types),
mMaxLuminance(maxLuminance),
@@ -47,7 +48,7 @@
~HdrCapabilities();
- const std::vector<int32_t /*android_hdr_t*/>& getSupportedHdrTypes() const {
+ const std::vector<ui::Hdr>& getSupportedHdrTypes() const {
return mSupportedHdrTypes;
}
float getDesiredMaxLuminance() const { return mMaxLuminance; }
@@ -61,7 +62,7 @@
status_t unflatten(void const* buffer, size_t size);
private:
- std::vector<int32_t /*android_hdr_t*/> mSupportedHdrTypes;
+ std::vector<ui::Hdr> mSupportedHdrTypes;
float mMaxLuminance;
float mMaxAverageLuminance;
float mMinLuminance;
diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp
index f3a9ad8..d6c254d 100644
--- a/opengl/libs/EGL/eglApi.cpp
+++ b/opengl/libs/EGL/eglApi.cpp
@@ -489,6 +489,9 @@
bool haveColorSpaceSupport = dp->haveExtension("EGL_KHR_gl_colorspace");
switch (format) {
case HAL_PIXEL_FORMAT_RGBA_8888:
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ // RGB_888 is never returned by getNativePixelFormat, but is included here for completeness.
+ case HAL_PIXEL_FORMAT_RGB_888:
if (haveColorSpaceSupport) {
// Spec says:
// [fn1] Only OpenGL and OpenGL ES contexts which support sRGB
diff --git a/services/surfaceflinger/BufferLayer.cpp b/services/surfaceflinger/BufferLayer.cpp
index 2aa4cd3..57f474b 100644
--- a/services/surfaceflinger/BufferLayer.cpp
+++ b/services/surfaceflinger/BufferLayer.cpp
@@ -515,7 +515,27 @@
recomputeVisibleRegions = true;
}
- setDataSpace(mConsumer->getCurrentDataSpace());
+ // Dataspace::V0_SRGB and Dataspace::V0_SRGB_LINEAR are not legacy
+ // data space, however since framework doesn't distinguish them out of
+ // legacy SRGB, we have to treat them as the same for now.
+ // UNKNOWN is treated as legacy SRGB when the connected api is EGL.
+ ui::Dataspace dataSpace = mConsumer->getCurrentDataSpace();
+ switch (dataSpace) {
+ case ui::Dataspace::V0_SRGB:
+ dataSpace = ui::Dataspace::SRGB;
+ break;
+ case ui::Dataspace::V0_SRGB_LINEAR:
+ dataSpace = ui::Dataspace::SRGB_LINEAR;
+ break;
+ case ui::Dataspace::UNKNOWN:
+ if (mConsumer->getCurrentApi() == NATIVE_WINDOW_API_EGL) {
+ dataSpace = ui::Dataspace::SRGB;
+ }
+ break;
+ default:
+ break;
+ }
+ setDataSpace(dataSpace);
Rect crop(mConsumer->getCurrentCrop());
const uint32_t transform(mConsumer->getCurrentTransform());
diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp
index d90ab1d..cd41662 100644
--- a/services/surfaceflinger/DisplayDevice.cpp
+++ b/services/surfaceflinger/DisplayDevice.cpp
@@ -55,6 +55,7 @@
using namespace android::hardware::configstore;
using namespace android::hardware::configstore::V1_0;
using android::ui::ColorMode;
+using android::ui::Hdr;
using android::ui::RenderIntent;
/*
@@ -77,7 +78,7 @@
int displayWidth,
int displayHeight,
bool hasWideColorGamut,
- bool hasHdr10,
+ const HdrCapabilities& hdrCapabilities,
int initialPowerMode)
: lastCompositionHadVisibleLayers(false),
mFlinger(flinger),
@@ -100,9 +101,26 @@
mActiveColorMode(ColorMode::NATIVE),
mColorTransform(HAL_COLOR_TRANSFORM_IDENTITY),
mHasWideColorGamut(hasWideColorGamut),
- mHasHdr10(hasHdr10)
+ mHasHdr10(false),
+ mHasHLG(false),
+ mHasDolbyVision(false)
{
// clang-format on
+ for (Hdr hdrType : hdrCapabilities.getSupportedHdrTypes()) {
+ switch (hdrType) {
+ case Hdr::HDR10:
+ mHasHdr10 = true;
+ break;
+ case Hdr::HLG:
+ mHasHLG = true;
+ break;
+ case Hdr::DOLBY_VISION:
+ mHasDolbyVision = true;
+ break;
+ default:
+ ALOGE("UNKNOWN HDR capability: %d", static_cast<int32_t>(hdrType));
+ }
+ }
// initialize the display orientation transform.
setProjection(DisplayState::eOrientationDefault, mViewport, mFrame);
diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h
index b8a8906..cd0bed6 100644
--- a/services/surfaceflinger/DisplayDevice.h
+++ b/services/surfaceflinger/DisplayDevice.h
@@ -85,7 +85,7 @@
int displayWidth,
int displayHeight,
bool hasWideColorGamut,
- bool hasHdr10,
+ const HdrCapabilities& hdrCapabilities,
int initialPowerMode);
// clang-format on
@@ -136,7 +136,9 @@
status_t beginFrame(bool mustRecompose) const;
status_t prepareFrame(HWComposer& hwc);
bool hasWideColorGamut() const { return mHasWideColorGamut; }
- bool hasHdr10() const { return mHasHdr10; }
+ bool hasHDR10Support() const { return mHasHdr10; }
+ bool hasHLGSupport() const { return mHasHLG; }
+ bool hasDolbyVisionSupport() const { return mHasDolbyVision; }
void swapBuffers(HWComposer& hwc) const;
@@ -255,6 +257,8 @@
// Fed to RenderEngine during composition.
bool mHasWideColorGamut;
bool mHasHdr10;
+ bool mHasHLG;
+ bool mHasDolbyVision;
};
struct DisplayDeviceState {
diff --git a/services/surfaceflinger/DisplayHardware/HWC2.cpp b/services/surfaceflinger/DisplayHardware/HWC2.cpp
index 5f94bb4..0667f8d 100644
--- a/services/surfaceflinger/DisplayHardware/HWC2.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWC2.cpp
@@ -448,26 +448,21 @@
return Error::None;
}
-Error Display::getHdrCapabilities(
- std::unique_ptr<HdrCapabilities>* outCapabilities) const
+Error Display::getHdrCapabilities(HdrCapabilities* outCapabilities) const
{
float maxLuminance = -1.0f;
float maxAverageLuminance = -1.0f;
float minLuminance = -1.0f;
- std::vector<Hwc2::Hdr> intTypes;
- auto intError = mComposer.getHdrCapabilities(mId, &intTypes,
+ std::vector<Hwc2::Hdr> types;
+ auto intError = mComposer.getHdrCapabilities(mId, &types,
&maxLuminance, &maxAverageLuminance, &minLuminance);
auto error = static_cast<HWC2::Error>(intError);
- std::vector<int32_t> types;
- for (auto type : intTypes) {
- types.push_back(static_cast<int32_t>(type));
- }
if (error != Error::None) {
return error;
}
- *outCapabilities = std::make_unique<HdrCapabilities>(std::move(types),
+ *outCapabilities = HdrCapabilities(std::move(types),
maxLuminance, maxAverageLuminance, minLuminance);
return Error::None;
}
diff --git a/services/surfaceflinger/DisplayHardware/HWC2.h b/services/surfaceflinger/DisplayHardware/HWC2.h
index e5779d4..aa907ea 100644
--- a/services/surfaceflinger/DisplayHardware/HWC2.h
+++ b/services/surfaceflinger/DisplayHardware/HWC2.h
@@ -228,7 +228,7 @@
[[clang::warn_unused_result]] Error getType(DisplayType* outType) const;
[[clang::warn_unused_result]] Error supportsDoze(bool* outSupport) const;
[[clang::warn_unused_result]] Error getHdrCapabilities(
- std::unique_ptr<android::HdrCapabilities>* outCapabilities) const;
+ android::HdrCapabilities* outCapabilities) const;
[[clang::warn_unused_result]] Error getReleaseFences(
std::unordered_map<Layer*,
android::sp<android::Fence>>* outFences) const;
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
index 8db8aa6..0a3ac84 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
@@ -824,24 +824,22 @@
mDisplayData[displayId].releaseFences.clear();
}
-std::unique_ptr<HdrCapabilities> HWComposer::getHdrCapabilities(
- int32_t displayId) {
+status_t HWComposer::getHdrCapabilities(
+ int32_t displayId, HdrCapabilities* outCapabilities) {
if (!isValidDisplay(displayId)) {
ALOGE("getHdrCapabilities: Display %d is not valid", displayId);
- return nullptr;
+ return BAD_INDEX;
}
auto& hwcDisplay = mDisplayData[displayId].hwcDisplay;
- std::unique_ptr<HdrCapabilities> capabilities;
- auto error = hwcDisplay->getHdrCapabilities(&capabilities);
+ auto error = hwcDisplay->getHdrCapabilities(outCapabilities);
if (error != HWC2::Error::None) {
ALOGE("getOutputCapabilities: Failed to get capabilities on display %d:"
- " %s (%d)", displayId, to_string(error).c_str(),
- static_cast<int32_t>(error));
- return nullptr;
+ " %s (%d)", displayId, to_string(error).c_str(),
+ static_cast<int32_t>(error));
+ return UNKNOWN_ERROR;
}
-
- return capabilities;
+ return NO_ERROR;
}
std::vector<ui::RenderIntent> HWComposer::getRenderIntents(int32_t displayId,
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.h b/services/surfaceflinger/DisplayHardware/HWComposer.h
index e86d621..138e1f1 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.h
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.h
@@ -134,8 +134,8 @@
// it can call this to clear the shared pointers in the release fence map
void clearReleaseFences(int32_t displayId);
- // Returns the HDR capabilities of the given display
- std::unique_ptr<HdrCapabilities> getHdrCapabilities(int32_t displayId);
+ // Fetches the HDR capabilities of the given display
+ status_t getHdrCapabilities(int32_t displayId, HdrCapabilities* outCapabilities);
// Returns the available RenderIntent of the given display.
std::vector<ui::RenderIntent> getRenderIntents(int32_t displayId, ui::ColorMode colorMode) const;
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 8c0050e..66ad2f6 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -23,6 +23,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <sys/types.h>
+#include <algorithm>
#include <cutils/compiler.h>
#include <cutils/native_handle.h>
@@ -1643,19 +1644,9 @@
return true;
}
-// Dataspace::UNKNOWN, Dataspace::SRGB, Dataspace::SRGB_LINEAR,
-// Dataspace::V0_SRGB and Dataspace::V0_SRGB_LINEAR are considered legacy
-// SRGB data space for now.
-// Note that Dataspace::V0_SRGB and Dataspace::V0_SRGB_LINEAR are not legacy
-// data space, however since framework doesn't distinguish them out of legacy
-// SRGB, we have to treat them as the same for now.
bool Layer::isLegacySrgbDataSpace() const {
- // TODO(lpy) b/77652630, need to figure out when UNKNOWN can be treated as SRGB.
- return mDrawingState.dataSpace == ui::Dataspace::UNKNOWN ||
- mDrawingState.dataSpace == ui::Dataspace::SRGB ||
- mDrawingState.dataSpace == ui::Dataspace::SRGB_LINEAR ||
- mDrawingState.dataSpace == ui::Dataspace::V0_SRGB ||
- mDrawingState.dataSpace == ui::Dataspace::V0_SRGB_LINEAR;
+ return mDrawingState.dataSpace == ui::Dataspace::SRGB ||
+ mDrawingState.dataSpace == ui::Dataspace::SRGB_LINEAR;
}
void Layer::setParent(const sp<Layer>& layer) {
@@ -1787,29 +1778,81 @@
}
}
-/**
- * Traverse only children in z order, ignoring relative layers.
- */
-void Layer::traverseChildrenInZOrder(LayerVector::StateSet stateSet,
- const LayerVector::Visitor& visitor) {
+LayerVector Layer::makeChildrenTraversalList(LayerVector::StateSet stateSet,
+ const std::vector<Layer*>& layersInTree) {
+ LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid,
+ "makeTraversalList received invalid stateSet");
const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
+ const State& state = useDrawing ? mDrawingState : mCurrentState;
+
+ LayerVector traverse;
+ for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
+ sp<Layer> strongRelative = weakRelative.promote();
+ // Only add relative layers that are also descendents of the top most parent of the tree.
+ // If a relative layer is not a descendent, then it should be ignored.
+ if (std::binary_search(layersInTree.begin(), layersInTree.end(), strongRelative.get())) {
+ traverse.add(strongRelative);
+ }
+ }
+
+ for (const sp<Layer>& child : children) {
+ const State& childState = useDrawing ? child->mDrawingState : child->mCurrentState;
+ // If a layer has a relativeOf layer, only ignore if the layer it's relative to is a
+ // descendent of the top most parent of the tree. If it's not a descendent, then just add
+ // the child here since it won't be added later as a relative.
+ if (std::binary_search(layersInTree.begin(), layersInTree.end(),
+ childState.zOrderRelativeOf.promote().get())) {
+ continue;
+ }
+ traverse.add(child);
+ }
+
+ return traverse;
+}
+
+void Layer::traverseChildrenInZOrderInner(const std::vector<Layer*>& layersInTree,
+ LayerVector::StateSet stateSet,
+ const LayerVector::Visitor& visitor) {
+ const LayerVector list = makeChildrenTraversalList(stateSet, layersInTree);
size_t i = 0;
- for (; i < children.size(); i++) {
- const auto& relative = children[i];
+ for (; i < list.size(); i++) {
+ const auto& relative = list[i];
if (relative->getZ() >= 0) {
break;
}
- relative->traverseChildrenInZOrder(stateSet, visitor);
+ relative->traverseChildrenInZOrderInner(layersInTree, stateSet, visitor);
}
+
visitor(this);
- for (; i < children.size(); i++) {
- const auto& relative = children[i];
- relative->traverseChildrenInZOrder(stateSet, visitor);
+ for (; i < list.size(); i++) {
+ const auto& relative = list[i];
+ relative->traverseChildrenInZOrderInner(layersInTree, stateSet, visitor);
}
}
+std::vector<Layer*> Layer::getLayersInTree(LayerVector::StateSet stateSet) {
+ const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
+ const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
+
+ std::vector<Layer*> layersInTree = {this};
+ for (size_t i = 0; i < children.size(); i++) {
+ const auto& child = children[i];
+ std::vector<Layer*> childLayers = child->getLayersInTree(stateSet);
+ layersInTree.insert(layersInTree.end(), childLayers.cbegin(), childLayers.cend());
+ }
+
+ return layersInTree;
+}
+
+void Layer::traverseChildrenInZOrder(LayerVector::StateSet stateSet,
+ const LayerVector::Visitor& visitor) {
+ std::vector<Layer*> layersInTree = getLayersInTree(stateSet);
+ std::sort(layersInTree.begin(), layersInTree.end());
+ traverseChildrenInZOrderInner(layersInTree, stateSet, visitor);
+}
+
Transform Layer::getTransform() const {
Transform t;
const auto& p = mDrawingParent.promote();
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index d382a1a..be3967b 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -51,6 +51,7 @@
#include "RenderEngine/Texture.h"
#include <math/vec4.h>
+#include <vector>
using namespace android::surfaceflinger;
@@ -564,6 +565,10 @@
const LayerVector::Visitor& visitor);
void traverseInZOrder(LayerVector::StateSet stateSet, const LayerVector::Visitor& visitor);
+ /**
+ * Traverse only children in z order, ignoring relative layers that are not children of the
+ * parent.
+ */
void traverseChildrenInZOrder(LayerVector::StateSet stateSet,
const LayerVector::Visitor& visitor);
@@ -778,6 +783,22 @@
wp<Layer> mDrawingParent;
mutable LayerBE mBE;
+
+private:
+ /**
+ * Returns an unsorted vector of all layers that are part of this tree.
+ * That includes the current layer and all its descendants.
+ */
+ std::vector<Layer*> getLayersInTree(LayerVector::StateSet stateSet);
+ /**
+ * Traverses layers that are part of this tree in the correct z order.
+ * layersInTree must be sorted before calling this method.
+ */
+ void traverseChildrenInZOrderInner(const std::vector<Layer*>& layersInTree,
+ LayerVector::StateSet stateSet,
+ const LayerVector::Visitor& visitor);
+ LayerVector makeChildrenTraversalList(LayerVector::StateSet stateSet,
+ const std::vector<Layer*>& layersInTree);
};
// ---------------------------------------------------------------------------
diff --git a/services/surfaceflinger/RenderEngine/Description.cpp b/services/surfaceflinger/RenderEngine/Description.cpp
index 5e79e7a..323bdb2 100644
--- a/services/surfaceflinger/RenderEngine/Description.cpp
+++ b/services/surfaceflinger/RenderEngine/Description.cpp
@@ -73,8 +73,4 @@
mOutputTransferFunction = transferFunction;
}
-void Description::enableToneMapping(bool enable) {
- mToneMappingEnabled = enable;
-}
-
} /* namespace android */
diff --git a/services/surfaceflinger/RenderEngine/Description.h b/services/surfaceflinger/RenderEngine/Description.h
index 75c1981..5854ba4 100644
--- a/services/surfaceflinger/RenderEngine/Description.h
+++ b/services/surfaceflinger/RenderEngine/Description.h
@@ -51,12 +51,11 @@
LINEAR,
SRGB,
ST2084,
+ HLG, // Hybrid Log-Gamma for HDR.
};
void setInputTransferFunction(TransferFunction transferFunction);
void setOutputTransferFunction(TransferFunction transferFunction);
- void enableToneMapping(bool enable);
-
private:
friend class Program;
friend class ProgramCache;
@@ -84,9 +83,6 @@
// transfer functions for the input/output
TransferFunction mInputTransferFunction = TransferFunction::LINEAR;
TransferFunction mOutputTransferFunction = TransferFunction::LINEAR;
-
- // tone-map the color
- bool mToneMappingEnabled = false;
};
} /* namespace android */
diff --git a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp
index 1efe0ac..6e0fa32 100644
--- a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp
+++ b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp
@@ -316,7 +316,12 @@
wideColorState.setColorMatrix(mState.getColorMatrix() * mBt2020ToDisplayP3);
wideColorState.setInputTransferFunction(Description::TransferFunction::ST2084);
wideColorState.setOutputTransferFunction(Description::TransferFunction::SRGB);
- wideColorState.enableToneMapping(true);
+ break;
+ case Dataspace::BT2020_HLG:
+ case Dataspace::BT2020_ITU_HLG:
+ wideColorState.setColorMatrix(mState.getColorMatrix() * mBt2020ToDisplayP3);
+ wideColorState.setInputTransferFunction(Description::TransferFunction::HLG);
+ wideColorState.setOutputTransferFunction(Description::TransferFunction::SRGB);
break;
default:
// treat all other dataspaces as sRGB
diff --git a/services/surfaceflinger/RenderEngine/ProgramCache.cpp b/services/surfaceflinger/RenderEngine/ProgramCache.cpp
index 6a34981..d1887ee 100644
--- a/services/surfaceflinger/RenderEngine/ProgramCache.cpp
+++ b/services/surfaceflinger/RenderEngine/ProgramCache.cpp
@@ -143,6 +143,9 @@
case Description::TransferFunction::ST2084:
needs.set(Key::INPUT_TF_MASK, Key::INPUT_TF_ST2084);
break;
+ case Description::TransferFunction::HLG:
+ needs.set(Key::INPUT_TF_MASK, Key::INPUT_TF_HLG);
+ break;
}
switch (description.mOutputTransferFunction) {
@@ -156,10 +159,10 @@
case Description::TransferFunction::ST2084:
needs.set(Key::OUTPUT_TF_MASK, Key::OUTPUT_TF_ST2084);
break;
+ case Description::TransferFunction::HLG:
+ needs.set(Key::OUTPUT_TF_MASK, Key::OUTPUT_TF_HLG);
+ break;
}
-
- needs.set(Key::TONE_MAPPING_MASK,
- description.mToneMappingEnabled ? Key::TONE_MAPPING_ON : Key::TONE_MAPPING_OFF);
}
return needs;
@@ -220,6 +223,8 @@
if (needs.hasColorMatrix()) {
fs << "uniform mat4 colorMatrix;";
+ // Generate EOTF that converts signal values to relative display light,
+ // both normalized to [0, 1].
switch (needs.getInputTF()) {
case Key::INPUT_TF_LINEAR:
default:
@@ -259,8 +264,123 @@
}
)__SHADER__";
break;
+ case Key::INPUT_TF_HLG:
+ fs << R"__SHADER__(
+ highp float EOTF_channel(const highp float channel) {
+ const highp float a = 0.17883277;
+ const highp float b = 0.28466892;
+ const highp float c = 0.55991073;
+ return channel <= 0.5 ? channel * channel / 3.0 :
+ (exp((channel - c) / a) + b) / 12.0;
+ }
+
+ vec3 EOTF(const highp vec3 color) {
+ return vec3(EOTF_channel(color.r), EOTF_channel(color.g),
+ EOTF_channel(color.b));
+ }
+ )__SHADER__";
+ break;
}
+ fs << R"__SHADER__(
+ highp float CalculateY(const highp vec3 color) {
+ // BT2020 standard uses the unadjusted KR = 0.2627,
+ // KB = 0.0593 luminance interpretation for RGB conversion.
+ return color.r * 0.262700 + color.g * 0.677998 +
+ color.b * 0.059302;
+ }
+ )__SHADER__";
+
+ // Generate OOTF that modifies the relative display light.
+ switch(needs.getInputTF()) {
+ case Key::INPUT_TF_ST2084:
+ fs << R"__SHADER__(
+ highp vec3 OOTF(const highp vec3 color) {
+ const float maxLumi = 10000.0;
+ const float maxMasteringLumi = 1000.0;
+ const float maxContentLumi = 1000.0;
+ const float maxInLumi = min(maxMasteringLumi, maxContentLumi);
+ const float maxOutLumi = 500.0;
+
+ // Calculate Y value in XYZ color space.
+ float colorY = CalculateY(color);
+
+ // convert to nits first
+ float nits = colorY * maxLumi;
+
+ // clamp to max input luminance
+ nits = clamp(nits, 0.0, maxInLumi);
+
+ // scale [0.0, maxInLumi] to [0.0, maxOutLumi]
+ if (maxInLumi <= maxOutLumi) {
+ nits *= maxOutLumi / maxInLumi;
+ } else {
+ // three control points
+ const float x0 = 10.0;
+ const float y0 = 17.0;
+ const float x1 = maxOutLumi * 0.75;
+ const float y1 = x1;
+ const float x2 = x1 + (maxInLumi - x1) / 2.0;
+ const float y2 = y1 + (maxOutLumi - y1) * 0.75;
+
+ // horizontal distances between the last three control points
+ const float h12 = x2 - x1;
+ const float h23 = maxInLumi - x2;
+ // tangents at the last three control points
+ const float m1 = (y2 - y1) / h12;
+ const float m3 = (maxOutLumi - y2) / h23;
+ const float m2 = (m1 + m3) / 2.0;
+
+ if (nits < x0) {
+ // scale [0.0, x0] to [0.0, y0] linearly
+ const float slope = y0 / x0;
+ nits *= slope;
+ } else if (nits < x1) {
+ // scale [x0, x1] to [y0, y1] linearly
+ const float slope = (y1 - y0) / (x1 - x0);
+ nits = y0 + (nits - x0) * slope;
+ } else if (nits < x2) {
+ // scale [x1, x2] to [y1, y2] using Hermite interp
+ float t = (nits - x1) / h12;
+ nits = (y1 * (1.0 + 2.0 * t) + h12 * m1 * t) * (1.0 - t) * (1.0 - t) +
+ (y2 * (3.0 - 2.0 * t) + h12 * m2 * (t - 1.0)) * t * t;
+ } else {
+ // scale [x2, maxInLumi] to [y2, maxOutLumi] using Hermite interp
+ float t = (nits - x2) / h23;
+ nits = (y2 * (1.0 + 2.0 * t) + h23 * m2 * t) * (1.0 - t) * (1.0 - t) +
+ (maxOutLumi * (3.0 - 2.0 * t) + h23 * m3 * (t - 1.0)) * t * t;
+ }
+ }
+
+ // convert back to [0.0, 1.0]
+ float targetY = nits / maxOutLumi;
+ return color * (targetY / max(1e-6, colorY));
+ }
+ )__SHADER__";
+ break;
+ case Key::INPUT_TF_HLG:
+ fs << R"__SHADER__(
+ highp vec3 OOTF(const highp vec3 color) {
+ const float maxOutLumi = 500.0;
+ const float gamma = 1.2 + 0.42 * log(maxOutLumi / 1000.0) / log(10.0);
+ // The formula is:
+ // alpha * pow(Y, gamma - 1.0) * color + beta;
+ // where alpha is 1.0, beta is 0.0 as recommended in
+ // Rec. ITU-R BT.2100-1 TABLE 5.
+ return pow(CalculateY(color), gamma - 1.0) * color;
+ }
+ )__SHADER__";
+ break;
+ default:
+ fs << R"__SHADER__(
+ highp vec3 OOTF(const highp vec3 color) {
+ return color;
+ }
+ )__SHADER__";
+ }
+
+ // Generate OETF that converts relative display light to signal values,
+ // both normalized to [0, 1]
switch (needs.getOutputTF()) {
case Key::OUTPUT_TF_LINEAR:
default:
@@ -301,84 +421,22 @@
}
)__SHADER__";
break;
- }
-
- if (needs.hasToneMapping()) {
- fs << R"__SHADER__(
- float CalculateY(const vec3 color) {
- // BT2020 standard uses the unadjusted KR = 0.2627,
- // KB = 0.0593 luminance interpretation for RGB conversion.
- return color.r * 0.262700 + color.g * 0.677998 +
- color.b * 0.059302;
- }
- vec3 ToneMap(const vec3 color) {
- const float maxLumi = 10000.0;
- const float maxMasteringLumi = 1000.0;
- const float maxContentLumi = 1000.0;
- const float maxInLumi = min(maxMasteringLumi, maxContentLumi);
- const float maxOutLumi = 500.0;
-
- // Calculate Y value in XYZ color space.
- float colorY = CalculateY(color);
-
- // convert to nits first
- float nits = colorY * maxLumi;
-
- // clamp to max input luminance
- nits = clamp(nits, 0.0, maxInLumi);
-
- // scale [0.0, maxInLumi] to [0.0, maxOutLumi]
- if (maxInLumi <= maxOutLumi) {
- nits *= maxOutLumi / maxInLumi;
- } else {
- // three control points
- const float x0 = 10.0;
- const float y0 = 17.0;
- const float x1 = maxOutLumi * 0.75;
- const float y1 = x1;
- const float x2 = x1 + (maxInLumi - x1) / 2.0;
- const float y2 = y1 + (maxOutLumi - y1) * 0.75;
-
- // horizontal distances between the last three control points
- const float h12 = x2 - x1;
- const float h23 = maxInLumi - x2;
- // tangents at the last three control points
- const float m1 = (y2 - y1) / h12;
- const float m3 = (maxOutLumi - y2) / h23;
- const float m2 = (m1 + m3) / 2.0;
-
- if (nits < x0) {
- // scale [0.0, x0] to [0.0, y0] linearly
- const float slope = y0 / x0;
- nits *= slope;
- } else if (nits < x1) {
- // scale [x0, x1] to [y0, y1] linearly
- const float slope = (y1 - y0) / (x1 - x0);
- nits = y0 + (nits - x0) * slope;
- } else if (nits < x2) {
- // scale [x1, x2] to [y1, y2] using Hermite interp
- float t = (nits - x1) / h12;
- nits = (y1 * (1.0 + 2.0 * t) + h12 * m1 * t) * (1.0 - t) * (1.0 - t) +
- (y2 * (3.0 - 2.0 * t) + h12 * m2 * (t - 1.0)) * t * t;
- } else {
- // scale [x2, maxInLumi] to [y2, maxOutLumi] using Hermite interp
- float t = (nits - x2) / h23;
- nits = (y2 * (1.0 + 2.0 * t) + h23 * m2 * t) * (1.0 - t) * (1.0 - t) +
- (maxOutLumi * (3.0 - 2.0 * t) + h23 * m3 * (t - 1.0)) * t * t;
- }
+ case Key::OUTPUT_TF_HLG:
+ fs << R"__SHADER__(
+ highp float OETF_channel(const highp float channel) {
+ const highp float a = 0.17883277;
+ const highp float b = 0.28466892;
+ const highp float c = 0.55991073;
+ return channel <= 1.0 / 12.0 ? sqrt(3.0 * channel) :
+ a * log(12.0 * channel - b) + c;
}
- // convert back to [0.0, 1.0]
- float targetY = nits / maxOutLumi;
- return color * (targetY / max(1e-6, colorY));
- }
- )__SHADER__";
- } else {
- fs << R"__SHADER__(
- vec3 ToneMap(const vec3 color) {
- return color;
- }
- )__SHADER__";
+ vec3 OETF(const highp vec3 color) {
+ return vec3(OETF_channel(color.r), OETF_channel(color.g),
+ OETF_channel(color.b));
+ }
+ )__SHADER__";
+ break;
}
}
@@ -411,7 +469,7 @@
// avoid divide by 0 by adding 0.5/256 to the alpha channel
fs << "gl_FragColor.rgb = gl_FragColor.rgb / (gl_FragColor.a + 0.0019);";
}
- fs << "vec4 transformed = colorMatrix * vec4(ToneMap(EOTF(gl_FragColor.rgb)), 1);";
+ fs << "vec4 transformed = colorMatrix * vec4(OOTF(EOTF(gl_FragColor.rgb)), 1);";
// the transformation from a wider colorspace to a narrower one can
// result in >1.0 or <0.0 pixel values
fs << "transformed.rgb = clamp(transformed.rgb, 0.0, 1.0);";
diff --git a/services/surfaceflinger/RenderEngine/ProgramCache.h b/services/surfaceflinger/RenderEngine/ProgramCache.h
index dcc8cc6..f67e132 100644
--- a/services/surfaceflinger/RenderEngine/ProgramCache.h
+++ b/services/surfaceflinger/RenderEngine/ProgramCache.h
@@ -81,19 +81,16 @@
INPUT_TF_LINEAR = 0 << INPUT_TF_SHIFT,
INPUT_TF_SRGB = 1 << INPUT_TF_SHIFT,
INPUT_TF_ST2084 = 2 << INPUT_TF_SHIFT,
+ INPUT_TF_HLG = 3 << INPUT_TF_SHIFT,
OUTPUT_TF_SHIFT = 8,
OUTPUT_TF_MASK = 3 << OUTPUT_TF_SHIFT,
OUTPUT_TF_LINEAR = 0 << OUTPUT_TF_SHIFT,
OUTPUT_TF_SRGB = 1 << OUTPUT_TF_SHIFT,
OUTPUT_TF_ST2084 = 2 << OUTPUT_TF_SHIFT,
+ OUTPUT_TF_HLG = 3 << OUTPUT_TF_SHIFT,
- TONE_MAPPING_SHIFT = 10,
- TONE_MAPPING_MASK = 1 << TONE_MAPPING_SHIFT,
- TONE_MAPPING_OFF = 0 << TONE_MAPPING_SHIFT,
- TONE_MAPPING_ON = 1 << TONE_MAPPING_SHIFT,
-
- Y410_BT2020_SHIFT = 11,
+ Y410_BT2020_SHIFT = 10,
Y410_BT2020_MASK = 1 << Y410_BT2020_SHIFT,
Y410_BT2020_OFF = 0 << Y410_BT2020_SHIFT,
Y410_BT2020_ON = 1 << Y410_BT2020_SHIFT,
@@ -115,7 +112,6 @@
inline bool hasColorMatrix() const { return (mKey & COLOR_MATRIX_MASK) == COLOR_MATRIX_ON; }
inline int getInputTF() const { return (mKey & INPUT_TF_MASK); }
inline int getOutputTF() const { return (mKey & OUTPUT_TF_MASK); }
- inline bool hasToneMapping() const { return (mKey & TONE_MAPPING_MASK) == TONE_MAPPING_ON; }
inline bool isY410BT2020() const { return (mKey & Y410_BT2020_MASK) == Y410_BT2020_ON; }
// this is the definition of a friend function -- not a method of class Needs
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 57f729b..58e4fbe 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -106,6 +106,7 @@
using namespace android::hardware::configstore::V1_0;
using ui::ColorMode;
using ui::Dataspace;
+using ui::Hdr;
using ui::RenderIntent;
namespace {
@@ -1118,21 +1119,23 @@
return BAD_VALUE;
}
- std::unique_ptr<HdrCapabilities> capabilities =
- getBE().mHwc->getHdrCapabilities(displayDevice->getHwcDisplayId());
- if (capabilities) {
- if (displayDevice->hasWideColorGamut() && !displayDevice->hasHdr10()) {
+ HdrCapabilities capabilities;
+ int status = getBE().mHwc->getHdrCapabilities(
+ displayDevice->getHwcDisplayId(), &capabilities);
+ if (status == NO_ERROR) {
+ if (displayDevice->hasWideColorGamut() &&
+ !displayDevice->hasHDR10Support()) {
// insert HDR10 as we will force client composition for HDR10
// layers
- std::vector<int32_t> types = capabilities->getSupportedHdrTypes();
- types.push_back(HAL_HDR_HDR10);
+ std::vector<Hdr> types = capabilities.getSupportedHdrTypes();
+ types.push_back(Hdr::HDR10);
*outCapabilities = HdrCapabilities(types,
- capabilities->getDesiredMaxLuminance(),
- capabilities->getDesiredMaxAverageLuminance(),
- capabilities->getDesiredMinLuminance());
+ capabilities.getDesiredMaxLuminance(),
+ capabilities.getDesiredMaxAverageLuminance(),
+ capabilities.getDesiredMinLuminance());
} else {
- *outCapabilities = std::move(*capabilities);
+ *outCapabilities = std::move(capabilities);
}
} else {
return BAD_VALUE;
@@ -1906,7 +1909,7 @@
// Historically, HDR dataspaces are ignored by SurfaceFlinger. But
// since SurfaceFlinger simulates HDR support now, it should honor
// them unless there is also native support.
- if (!displayDevice->hasHdr10()) {
+ if (!displayDevice->hasHDR10Support()) {
return Dataspace::V0_SCRGB_LINEAR;
}
break;
@@ -2024,7 +2027,7 @@
for (auto& layer : displayDevice->getVisibleLayersSortedByZ()) {
if ((layer->getDataSpace() == Dataspace::BT2020_PQ ||
layer->getDataSpace() == Dataspace::BT2020_ITU_PQ) &&
- !displayDevice->hasHdr10()) {
+ !displayDevice->hasHDR10Support()) {
layer->forceClientComposition(hwcId);
}
@@ -2277,13 +2280,8 @@
}
}
- bool hasHdr10 = false;
- std::unique_ptr<HdrCapabilities> hdrCapabilities = getHwComposer().getHdrCapabilities(hwcId);
- if (hdrCapabilities) {
- const std::vector<int32_t> types = hdrCapabilities->getSupportedHdrTypes();
- auto iter = std::find(types.cbegin(), types.cend(), HAL_HDR_HDR10);
- hasHdr10 = iter != types.cend();
- }
+ HdrCapabilities hdrCapabilities;
+ getHwComposer().getHdrCapabilities(hwcId, &hdrCapabilities);
auto nativeWindowSurface = mCreateNativeWindowSurface(producer);
auto nativeWindow = nativeWindowSurface->getNativeWindow();
@@ -2316,7 +2314,7 @@
sp<DisplayDevice> hw =
new DisplayDevice(this, state.type, hwcId, state.isSecure, display, nativeWindow,
dispSurface, std::move(renderSurface), displayWidth, displayHeight,
- hasWideColorGamut, hasHdr10, initialPowerMode);
+ hasWideColorGamut, hdrCapabilities, initialPowerMode);
if (maxFrameBufferAcquiredBuffers >= 3) {
nativeWindowSurface->preallocateBuffers();
diff --git a/services/surfaceflinger/tests/Transaction_test.cpp b/services/surfaceflinger/tests/Transaction_test.cpp
index a0f12f1..5108279 100644
--- a/services/surfaceflinger/tests/Transaction_test.cpp
+++ b/services/surfaceflinger/tests/Transaction_test.cpp
@@ -2376,6 +2376,58 @@
mCapture->expectColor(Rect(0, 10, 9, 19), {0, 0, 0, 0});
}
+TEST_F(ScreenCaptureTest, DontCaptureRelativeOutsideTree) {
+ auto fgHandle = mFGSurfaceControl->getHandle();
+
+ sp<SurfaceControl> child =
+ mComposerClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888,
+ 0, mFGSurfaceControl.get());
+ sp<SurfaceControl> relative = mComposerClient->createSurface(String8("Relative surface"), 10,
+ 10, PIXEL_FORMAT_RGBA_8888, 0);
+ fillSurfaceRGBA8(child, 200, 200, 200);
+ fillSurfaceRGBA8(relative, 100, 100, 100);
+
+ SurfaceComposerClient::Transaction()
+ .show(child)
+ // Set relative layer above fg layer so should be shown above when computing all layers.
+ .setRelativeLayer(relative, fgHandle, 1)
+ .show(relative)
+ .apply(true);
+
+ // Captures mFGSurfaceControl layer and its child. Relative layer shouldn't be captured.
+ ScreenCapture::captureLayers(&mCapture, fgHandle);
+ mCapture->expectFGColor(10, 10);
+ mCapture->expectChildColor(0, 0);
+}
+
+TEST_F(ScreenCaptureTest, CaptureRelativeInTree) {
+ auto fgHandle = mFGSurfaceControl->getHandle();
+
+ sp<SurfaceControl> child =
+ mComposerClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888,
+ 0, mFGSurfaceControl.get());
+ sp<SurfaceControl> relative =
+ mComposerClient->createSurface(String8("Relative surface"), 10, 10,
+ PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get());
+ fillSurfaceRGBA8(child, 200, 200, 200);
+ fillSurfaceRGBA8(relative, 100, 100, 100);
+
+ SurfaceComposerClient::Transaction()
+ .show(child)
+ // Set relative layer below fg layer but relative to child layer so it should be shown
+ // above child layer.
+ .setLayer(relative, -1)
+ .setRelativeLayer(relative, child->getHandle(), 1)
+ .show(relative)
+ .apply(true);
+
+ // Captures mFGSurfaceControl layer and its children. Relative layer is a child of fg so its
+ // relative value should be taken into account, placing it above child layer.
+ ScreenCapture::captureLayers(&mCapture, fgHandle);
+ mCapture->expectFGColor(10, 10);
+ // Relative layer is showing on top of child layer
+ mCapture->expectColor(Rect(0, 0, 9, 9), {100, 100, 100, 255});
+}
// In the following tests we verify successful skipping of a parent layer,
// so we use the same verification logic and only change how we mutate
diff --git a/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp b/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp
index 0705b5c..2551a9c 100644
--- a/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp
+++ b/services/surfaceflinger/tests/unittests/DisplayTransactionTest.cpp
@@ -81,7 +81,7 @@
sp<DisplayDevice> build() {
return new DisplayDevice(mFlinger.mFlinger.get(), mType, mHwcId, false, mDisplayToken,
mNativeWindow, mDisplaySurface, std::move(mRenderSurface), 0,
- 0, false, false, HWC_POWER_MODE_NORMAL);
+ 0, false, {}, HWC_POWER_MODE_NORMAL);
}
FakeDisplayDeviceFactory& setNativeWindow(const sp<ANativeWindow>& nativeWindow) {