diff options
| -rw-r--r-- | cmds/atrace/atrace.rc | 28 | ||||
| -rw-r--r-- | cmds/dumpstate/DumpstateInternal.cpp | 2 | ||||
| -rw-r--r-- | cmds/dumpstate/dumpstate.cpp | 2 | ||||
| -rw-r--r-- | libs/binder/ndk/include_cpp/android/binder_parcel_utils.h | 48 | ||||
| -rw-r--r-- | libs/gui/LayerState.cpp | 2 | ||||
| -rw-r--r-- | libs/gui/include/gui/LayerState.h | 10 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.cpp | 37 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.h | 2 | ||||
| -rw-r--r-- | services/surfaceflinger/Layer.cpp | 5 | ||||
| -rw-r--r-- | services/surfaceflinger/Layer.h | 8 | ||||
| -rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 116 | ||||
| -rw-r--r-- | services/surfaceflinger/SurfaceFlinger.h | 9 | ||||
| -rw-r--r-- | vulkan/libvulkan/Android.bp | 2 | ||||
| -rw-r--r-- | vulkan/libvulkan/driver.cpp | 50 |
14 files changed, 205 insertions, 116 deletions
diff --git a/cmds/atrace/atrace.rc b/cmds/atrace/atrace.rc index 994375b30e..d95d04a8d9 100644 --- a/cmds/atrace/atrace.rc +++ b/cmds/atrace/atrace.rc @@ -131,6 +131,34 @@ on late-init chmod 0666 /sys/kernel/tracing/events/task/task_newtask/enable chmod 0666 /sys/kernel/debug/tracing/events/gpu_mem/gpu_mem_total/enable chmod 0666 /sys/kernel/tracing/events/gpu_mem/gpu_mem_total/enable + chmod 0666 /sys/kernel/debug/tracing/events/irq/enable + chmod 0666 /sys/kernel/tracing/events/irq/enable + chmod 0666 /sys/kernel/debug/tracing/events/irq/irq_handler_entry/enable + chmod 0666 /sys/kernel/tracing/events/irq/irq_handler_entry/enable + chmod 0666 /sys/kernel/debug/tracing/events/irq/irq_handler_exit/enable + chmod 0666 /sys/kernel/tracing/events/irq/irq_handler_exit/enable + chmod 0666 /sys/kernel/debug/tracing/events/irq/softirq_entry/enable + chmod 0666 /sys/kernel/tracing/events/irq/softirq_entry/enable + chmod 0666 /sys/kernel/debug/tracing/events/irq/softirq_exit/enable + chmod 0666 /sys/kernel/tracing/events/irq/softirq_exit/enable + chmod 0666 /sys/kernel/debug/tracing/events/irq/softirq_raise/enable + chmod 0666 /sys/kernel/tracing/events/irq/softirq_raise/enable + chmod 0666 /sys/kernel/debug/tracing/events/irq/tasklet_entry/enable + chmod 0666 /sys/kernel/tracing/events/irq/tasklet_entry/enable + chmod 0666 /sys/kernel/debug/tracing/events/irq/tasklet_exit/enable + chmod 0666 /sys/kernel/tracing/events/irq/tasklet_exit/enable + chmod 0666 /sys/kernel/debug/tracing/events/irq/tasklet_hi_entry/enable + chmod 0666 /sys/kernel/tracing/events/irq/tasklet_hi_entry/enable + chmod 0666 /sys/kernel/debug/tracing/events/irq/tasklet_hi_exit/enable + chmod 0666 /sys/kernel/tracing/events/irq/tasklet_hi_exit/enable + chmod 0666 /sys/kernel/debug/tracing/events/ipi/enable + chmod 0666 /sys/kernel/tracing/events/ipi/enable + chmod 0666 /sys/kernel/debug/tracing/events/ipi/ipi_entry/enable + chmod 0666 /sys/kernel/tracing/events/ipi/ipi_entry/enable + chmod 0666 /sys/kernel/debug/tracing/events/ipi/ipi_exit/enable + chmod 0666 /sys/kernel/tracing/events/ipi/ipi_exit/enable + chmod 0666 /sys/kernel/debug/tracing/events/ipi/ipi_raise/enable + chmod 0666 /sys/kernel/tracing/events/ipi/ipi_raise/enable # disk chmod 0666 /sys/kernel/tracing/events/f2fs/f2fs_get_data_block/enable diff --git a/cmds/dumpstate/DumpstateInternal.cpp b/cmds/dumpstate/DumpstateInternal.cpp index bbc724c4c0..3091f6b5d0 100644 --- a/cmds/dumpstate/DumpstateInternal.cpp +++ b/cmds/dumpstate/DumpstateInternal.cpp @@ -69,7 +69,7 @@ bool DropRootUser() { static const std::vector<std::string> group_names{ "log", "sdcard_r", "sdcard_rw", "mount", "inet", "net_bw_stats", - "readproc", "bluetooth", "wakelock"}; + "readproc", "bluetooth", "wakelock", "nfc"}; std::vector<gid_t> groups(group_names.size(), 0); for (size_t i = 0; i < group_names.size(); ++i) { grp = getgrnam(group_names[i].c_str()); diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 91d5524062..a81cdafc61 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -1636,6 +1636,8 @@ static Dumpstate::RunStatus dumpstate() { /* Dump Bluetooth HCI logs */ ds.AddDir("/data/misc/bluetooth/logs", true); + /* Dump Nfc NCI logs */ + ds.AddDir("/data/misc/nfc/logs", true); if (ds.options_->do_screenshot && !ds.do_early_screenshot_) { MYLOGI("taking late screenshot\n"); diff --git a/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h b/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h index 09949ea259..054aebeb50 100644 --- a/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h +++ b/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h @@ -45,7 +45,7 @@ static inline bool AParcel_stdVectorAllocator(void* vectorData, int32_t length, std::vector<T>* vec = static_cast<std::vector<T>*>(vectorData); if (static_cast<size_t>(length) > vec->max_size()) return false; - vec->resize(length); + vec->resize(static_cast<size_t>(length)); *outBuffer = vec->data(); return true; } @@ -66,7 +66,7 @@ static inline bool AParcel_nullableStdVectorAllocator(void* vectorData, int32_t *vec = std::optional<std::vector<T>>(std::vector<T>{}); if (static_cast<size_t>(length) > (*vec)->max_size()) return false; - (*vec)->resize(length); + (*vec)->resize(static_cast<size_t>(length)); *outBuffer = (*vec)->data(); return true; @@ -90,7 +90,7 @@ static inline bool AParcel_stdVectorExternalAllocator(void* vectorData, int32_t std::vector<T>* vec = static_cast<std::vector<T>*>(vectorData); if (static_cast<size_t>(length) > vec->max_size()) return false; - vec->resize(length); + vec->resize(static_cast<size_t>(length)); return true; } @@ -117,7 +117,7 @@ static inline bool AParcel_nullableStdVectorExternalAllocator(void* vectorData, *vec = std::optional<std::vector<T>>(std::vector<T>{}); if (static_cast<size_t>(length) > (*vec)->max_size()) return false; - (*vec)->resize(length); + (*vec)->resize(static_cast<size_t>(length)); return true; } @@ -257,7 +257,7 @@ static inline bool AParcel_stdStringAllocator(void* stringData, int32_t length, if (length <= 0) return false; std::string* str = static_cast<std::string*>(stringData); - str->resize(length - 1); + str->resize(static_cast<size_t>(length) - 1); *buffer = &(*str)[0]; return true; } @@ -279,7 +279,7 @@ static inline bool AParcel_nullableStdStringAllocator(void* stringData, int32_t } *str = std::optional<std::string>(std::string{}); - (*str)->resize(length - 1); + (*str)->resize(static_cast<size_t>(length) - 1); *buffer = &(**str)[0]; return true; } @@ -303,7 +303,7 @@ static inline const char* AParcel_stdVectorStringElementGetter(const void* vecto const std::vector<std::string>* vec = static_cast<const std::vector<std::string>*>(vectorData); const std::string& element = vec->at(index); - *outLength = element.size(); + *outLength = static_cast<int32_t>(element.size()); return element.c_str(); } @@ -337,7 +337,7 @@ static inline const char* AParcel_nullableStdVectorStringElementGetter(const voi return nullptr; } - *outLength = element->size(); + *outLength = static_cast<int32_t>(element->size()); return element->c_str(); } @@ -345,7 +345,7 @@ static inline const char* AParcel_nullableStdVectorStringElementGetter(const voi * Convenience API for writing a std::string. */ static inline binder_status_t AParcel_writeString(AParcel* parcel, const std::string& str) { - return AParcel_writeString(parcel, str.c_str(), str.size()); + return AParcel_writeString(parcel, str.c_str(), static_cast<int32_t>(str.size())); } /** @@ -365,7 +365,7 @@ static inline binder_status_t AParcel_writeString(AParcel* parcel, return AParcel_writeString(parcel, nullptr, -1); } - return AParcel_writeString(parcel, str->c_str(), str->size()); + return AParcel_writeString(parcel, str->c_str(), static_cast<int32_t>(str->size())); } /** @@ -383,7 +383,7 @@ static inline binder_status_t AParcel_readString(const AParcel* parcel, static inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<std::string>& vec) { const void* vectorData = static_cast<const void*>(&vec); - return AParcel_writeStringArray(parcel, vectorData, vec.size(), + return AParcel_writeStringArray(parcel, vectorData, static_cast<int32_t>(vec.size()), AParcel_stdVectorStringElementGetter); } @@ -404,7 +404,8 @@ static inline binder_status_t AParcel_readVector(const AParcel* parcel, static inline binder_status_t AParcel_writeVector( AParcel* parcel, const std::optional<std::vector<std::optional<std::string>>>& vec) { const void* vectorData = static_cast<const void*>(&vec); - return AParcel_writeStringArray(parcel, vectorData, (vec ? vec->size() : -1), + return AParcel_writeStringArray(parcel, vectorData, + (vec ? static_cast<int32_t>(vec->size()) : -1), AParcel_nullableStdVectorStringElementGetter); } @@ -545,7 +546,7 @@ inline binder_status_t AParcel_readStdVectorParcelableElement<ScopedFileDescript template <typename P> static inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<P>& vec) { const void* vectorData = static_cast<const void*>(&vec); - return AParcel_writeParcelableArray(parcel, vectorData, vec.size(), + return AParcel_writeParcelableArray(parcel, vectorData, static_cast<int32_t>(vec.size()), AParcel_writeStdVectorParcelableElement<P>); } @@ -564,7 +565,7 @@ static inline binder_status_t AParcel_readVector(const AParcel* parcel, std::vec * Writes a vector of int32_t to the next location in a non-null parcel. */ inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<int32_t>& vec) { - return AParcel_writeInt32Array(parcel, vec.data(), vec.size()); + return AParcel_writeInt32Array(parcel, vec.data(), static_cast<int32_t>(vec.size())); } /** @@ -597,7 +598,7 @@ inline binder_status_t AParcel_readVector(const AParcel* parcel, * Writes a vector of uint32_t to the next location in a non-null parcel. */ inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<uint32_t>& vec) { - return AParcel_writeUint32Array(parcel, vec.data(), vec.size()); + return AParcel_writeUint32Array(parcel, vec.data(), static_cast<int32_t>(vec.size())); } /** @@ -631,7 +632,7 @@ inline binder_status_t AParcel_readVector(const AParcel* parcel, * Writes a vector of int64_t to the next location in a non-null parcel. */ inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<int64_t>& vec) { - return AParcel_writeInt64Array(parcel, vec.data(), vec.size()); + return AParcel_writeInt64Array(parcel, vec.data(), static_cast<int32_t>(vec.size())); } /** @@ -664,7 +665,7 @@ inline binder_status_t AParcel_readVector(const AParcel* parcel, * Writes a vector of uint64_t to the next location in a non-null parcel. */ inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<uint64_t>& vec) { - return AParcel_writeUint64Array(parcel, vec.data(), vec.size()); + return AParcel_writeUint64Array(parcel, vec.data(), static_cast<int32_t>(vec.size())); } /** @@ -698,7 +699,7 @@ inline binder_status_t AParcel_readVector(const AParcel* parcel, * Writes a vector of float to the next location in a non-null parcel. */ inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<float>& vec) { - return AParcel_writeFloatArray(parcel, vec.data(), vec.size()); + return AParcel_writeFloatArray(parcel, vec.data(), static_cast<int32_t>(vec.size())); } /** @@ -731,7 +732,7 @@ inline binder_status_t AParcel_readVector(const AParcel* parcel, * Writes a vector of double to the next location in a non-null parcel. */ inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<double>& vec) { - return AParcel_writeDoubleArray(parcel, vec.data(), vec.size()); + return AParcel_writeDoubleArray(parcel, vec.data(), static_cast<int32_t>(vec.size())); } /** @@ -764,8 +765,8 @@ inline binder_status_t AParcel_readVector(const AParcel* parcel, * Writes a vector of bool to the next location in a non-null parcel. */ inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<bool>& vec) { - return AParcel_writeBoolArray(parcel, static_cast<const void*>(&vec), vec.size(), - AParcel_stdVectorGetter<bool>); + return AParcel_writeBoolArray(parcel, static_cast<const void*>(&vec), + static_cast<int32_t>(vec.size()), AParcel_stdVectorGetter<bool>); } /** @@ -801,7 +802,7 @@ inline binder_status_t AParcel_readVector(const AParcel* parcel, * Writes a vector of char16_t to the next location in a non-null parcel. */ inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<char16_t>& vec) { - return AParcel_writeCharArray(parcel, vec.data(), vec.size()); + return AParcel_writeCharArray(parcel, vec.data(), static_cast<int32_t>(vec.size())); } /** @@ -834,7 +835,8 @@ inline binder_status_t AParcel_readVector(const AParcel* parcel, * Writes a vector of uint8_t to the next location in a non-null parcel. */ inline binder_status_t AParcel_writeVector(AParcel* parcel, const std::vector<uint8_t>& vec) { - return AParcel_writeByteArray(parcel, reinterpret_cast<const int8_t*>(vec.data()), vec.size()); + return AParcel_writeByteArray(parcel, reinterpret_cast<const int8_t*>(vec.data()), + static_cast<int32_t>(vec.size())); } /** diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp index 782f35ae02..2e4d279a5b 100644 --- a/libs/gui/LayerState.cpp +++ b/libs/gui/LayerState.cpp @@ -586,6 +586,7 @@ status_t CaptureArgs::write(Parcel& output) const { SAFE_PARCEL(output.writeBool, captureSecureLayers); SAFE_PARCEL(output.writeInt32, uid); SAFE_PARCEL(output.writeInt32, static_cast<int32_t>(dataspace)); + SAFE_PARCEL(output.writeBool, allowProtected); return NO_ERROR; } @@ -599,6 +600,7 @@ status_t CaptureArgs::read(const Parcel& input) { SAFE_PARCEL(input.readInt32, &uid); SAFE_PARCEL(input.readInt32, &value); dataspace = static_cast<ui::Dataspace>(value); + SAFE_PARCEL(input.readBool, &allowProtected); return NO_ERROR; } diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h index abd7d64809..5942fd03af 100644 --- a/libs/gui/include/gui/LayerState.h +++ b/libs/gui/include/gui/LayerState.h @@ -318,6 +318,14 @@ struct CaptureArgs { // NOTE: In normal cases, we want the screen to be captured in display's colorspace. ui::Dataspace dataspace = ui::Dataspace::UNKNOWN; + // The receiver of the capture can handle protected buffer. A protected buffer has + // GRALLOC_USAGE_PROTECTED usage bit and must not be accessed unprotected behaviour. + // Any read/write access from unprotected context will result in undefined behaviour. + // Protected contents are typically DRM contents. This has no direct implication to the + // secure property of the surface, which is specified by the application explicitly to avoid + // the contents being accessed/captured by screenshot or unsecure display. + bool allowProtected = false; + virtual status_t write(Parcel& output) const; virtual status_t read(const Parcel& input); }; @@ -345,7 +353,7 @@ struct ScreenCaptureResults { sp<GraphicBuffer> buffer; bool capturedSecureLayers{false}; ui::Dataspace capturedDataspace{ui::Dataspace::V0_SRGB}; - status_t result = NO_ERROR; + status_t result = OK; status_t write(Parcel& output) const; status_t read(const Parcel& input); diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index d7aea4e891..8052084925 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -37,6 +37,10 @@ // Log debug messages about input focus tracking. static constexpr bool DEBUG_FOCUS = false; +// Log debug messages about touch occlusion +// STOPSHIP(b/169067926): Set to false +static constexpr bool DEBUG_TOUCH_OCCLUSION = true; + // Log debug messages about the app switch latency optimization. #define DEBUG_APP_SWITCH 0 @@ -1774,6 +1778,12 @@ InputEventInjectionResult InputDispatcher::findTouchedWindowTargetsLocked( TouchOcclusionInfo occlusionInfo = computeTouchOcclusionInfoLocked(newTouchedWindowHandle, x, y); if (!isTouchTrustedLocked(occlusionInfo)) { + if (DEBUG_TOUCH_OCCLUSION) { + ALOGD("Stack of obscuring windows during untrusted touch (%d, %d):", x, y); + for (const auto& log : occlusionInfo.debugInfo) { + ALOGD("%s", log.c_str()); + } + } onUntrustedTouchLocked(occlusionInfo.obscuringPackage); if (mBlockUntrustedTouchesMode == BlockUntrustedTouchesMode::BLOCK) { ALOGW("Dropping untrusted touch event due to %s/%d", @@ -2215,7 +2225,8 @@ static bool canBeObscuredBy(const sp<InputWindowHandle>& windowHandle, */ InputDispatcher::TouchOcclusionInfo InputDispatcher::computeTouchOcclusionInfoLocked( const sp<InputWindowHandle>& windowHandle, int32_t x, int32_t y) const { - int32_t displayId = windowHandle->getInfo()->displayId; + const InputWindowInfo* windowInfo = windowHandle->getInfo(); + int32_t displayId = windowInfo->displayId; const std::vector<sp<InputWindowHandle>>& windowHandles = getWindowHandlesLocked(displayId); TouchOcclusionInfo info; info.hasBlockingOcclusion = false; @@ -2228,8 +2239,11 @@ InputDispatcher::TouchOcclusionInfo InputDispatcher::computeTouchOcclusionInfoLo } const InputWindowInfo* otherInfo = otherHandle->getInfo(); if (canBeObscuredBy(windowHandle, otherHandle) && - windowHandle->getInfo()->ownerUid != otherInfo->ownerUid && - otherInfo->frameContainsPoint(x, y)) { + windowInfo->ownerUid != otherInfo->ownerUid && otherInfo->frameContainsPoint(x, y)) { + if (DEBUG_TOUCH_OCCLUSION) { + info.debugInfo.push_back( + dumpWindowForTouchOcclusion(otherInfo, /* isTouchedWindow */ false)); + } // canBeObscuredBy() has returned true above, which means this window is untrusted, so // we perform the checks below to see if the touch can be propagated or not based on the // window's touch occlusion mode @@ -2255,9 +2269,26 @@ InputDispatcher::TouchOcclusionInfo InputDispatcher::computeTouchOcclusionInfoLo } } } + if (DEBUG_TOUCH_OCCLUSION) { + info.debugInfo.push_back( + dumpWindowForTouchOcclusion(windowInfo, /* isTouchedWindow */ true)); + } return info; } +std::string InputDispatcher::dumpWindowForTouchOcclusion(const InputWindowInfo* info, + bool isTouchedWindow) const { + return StringPrintf(INDENT2 "* %stype=%s, package=%s/%" PRId32 ", mode=%s, alpha=%.2f, " + "frame=[%" PRId32 ",%" PRId32 "][%" PRId32 ",%" PRId32 + "], window=%s, applicationInfo=%s, flags=%s\n", + (isTouchedWindow) ? "[TOUCHED] " : "", + NamedEnum::string(info->type).c_str(), info->packageName.c_str(), + info->ownerUid, toString(info->touchOcclusionMode).c_str(), info->alpha, + info->frameLeft, info->frameTop, info->frameRight, info->frameBottom, + info->name.c_str(), info->applicationInfo.name.c_str(), + info->flags.string().c_str()); +} + bool InputDispatcher::isTouchTrustedLocked(const TouchOcclusionInfo& occlusionInfo) const { if (occlusionInfo.hasBlockingOcclusion) { ALOGW("Untrusted touch due to occlusion by %s/%d", occlusionInfo.obscuringPackage.c_str(), diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h index 235a8d3c25..98dea0bfdf 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.h +++ b/services/inputflinger/dispatcher/InputDispatcher.h @@ -461,6 +461,7 @@ private: float obscuringOpacity; std::string obscuringPackage; int32_t obscuringUid; + std::vector<std::string> debugInfo; }; TouchOcclusionInfo computeTouchOcclusionInfoLocked(const sp<InputWindowHandle>& windowHandle, @@ -469,6 +470,7 @@ private: bool isWindowObscuredAtPointLocked(const sp<InputWindowHandle>& windowHandle, int32_t x, int32_t y) const REQUIRES(mLock); bool isWindowObscuredLocked(const sp<InputWindowHandle>& windowHandle) const REQUIRES(mLock); + std::string dumpWindowForTouchOcclusion(const InputWindowInfo* info, bool isTouchWindow) const; std::string getApplicationWindowLabel( const std::shared_ptr<InputApplicationHandle>& applicationHandle, const sp<InputWindowHandle>& windowHandle); diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 1f4c1f4327..629bee832e 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -2446,6 +2446,7 @@ InputWindowInfo Layer::fillInputInfo() { ySurfaceInset = std::round(ySurfaceInset * yScale); } + // Transform the layer bounds from layer coordinate space to display coordinate space. Rect transformedLayerBounds = t.transform(layerBounds); // clamp inset to layer bounds @@ -2470,7 +2471,7 @@ InputWindowInfo Layer::fillInputInfo() { transformedLayerBounds.bottom = tmp; } - // Input coordinate should match the layer bounds. + // Input coordinates should be in display coordinate space. info.frameLeft = transformedLayerBounds.left; info.frameTop = transformedLayerBounds.top; info.frameRight = transformedLayerBounds.right; @@ -2483,7 +2484,7 @@ InputWindowInfo Layer::fillInputInfo() { // the final frame calculated. // 1. Take the original transform set on the window and get the inverse transform. This is // used to get the final bounds in display space (ignorning the transform). Apply the - // inverse transform on the layerBounds to get the untransformed frame (in display space) + // inverse transform on the layerBounds to get the untransformed frame (in layer space) // 2. Take the top and left of the untransformed frame to get the real position on screen. // Apply the layer transform on top/left so it includes any scale or rotation. These will // be the new translation values for the transform. diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index 51e392aa30..7112cbc435 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -465,7 +465,7 @@ public: virtual bool canReceiveInput() const; /* - * isProtected - true if the layer may contain protected content in the + * isProtected - true if the layer may contain protected contents in the * GRALLOC_USAGE_PROTECTED sense. */ virtual bool isProtected() const { return false; } @@ -677,7 +677,8 @@ public: /* * isSecure - true if this surface is secure, that is if it prevents - * screenshots or VNC servers. + * screenshots or VNC servers. A surface can be set to be secure by the + * application, being secure doesn't mean the surface has DRM contents. */ bool isSecure() const; @@ -1073,7 +1074,8 @@ private: sp<Layer> getRootLayer(); // Cached properties computed from drawing state - // Effective transform taking into account parent transforms and any parent scaling. + // Effective transform taking into account parent transforms and any parent scaling, which is + // a transform from the current layer coordinate space to display(screen) coordinate space. ui::Transform mEffectiveTransform; // Bounds of the layer before any transformation is applied and before it has been cropped diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 8ab3ed3f91..964bd015f2 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -5381,6 +5381,45 @@ static status_t validateScreenshotPermissions(const CaptureArgs& captureArgs) { return PERMISSION_DENIED; } +status_t SurfaceFlinger::setSchedFifo(bool enabled) { + static constexpr int kFifoPriority = 2; + static constexpr int kOtherPriority = 0; + + struct sched_param param = {0}; + int sched_policy; + if (enabled) { + sched_policy = SCHED_FIFO; + param.sched_priority = kFifoPriority; + } else { + sched_policy = SCHED_OTHER; + param.sched_priority = kOtherPriority; + } + + if (sched_setscheduler(0, sched_policy, ¶m) != 0) { + return -errno; + } + return NO_ERROR; +} + +sp<DisplayDevice> SurfaceFlinger::getDisplayByIdOrLayerStack(uint64_t displayOrLayerStack) { + if (const sp<IBinder> displayToken = + getPhysicalDisplayTokenLocked(PhysicalDisplayId{displayOrLayerStack})) { + return getDisplayDeviceLocked(displayToken); + } + // Couldn't find display by displayId. Try to get display by layerStack since virtual displays + // may not have a displayId. + return getDisplayByLayerStack(displayOrLayerStack); +} + +sp<DisplayDevice> SurfaceFlinger::getDisplayByLayerStack(uint64_t layerStack) { + for (const auto& [token, display] : mDisplays) { + if (display->getLayerStack() == layerStack) { + return display; + } + } + return nullptr; +} + status_t SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { ATRACE_CALL(); @@ -5429,46 +5468,7 @@ status_t SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args, }; return captureScreenCommon(std::move(renderAreaFuture), traverseLayers, reqSize, - args.pixelFormat, captureListener); -} - -status_t SurfaceFlinger::setSchedFifo(bool enabled) { - static constexpr int kFifoPriority = 2; - static constexpr int kOtherPriority = 0; - - struct sched_param param = {0}; - int sched_policy; - if (enabled) { - sched_policy = SCHED_FIFO; - param.sched_priority = kFifoPriority; - } else { - sched_policy = SCHED_OTHER; - param.sched_priority = kOtherPriority; - } - - if (sched_setscheduler(0, sched_policy, ¶m) != 0) { - return -errno; - } - return NO_ERROR; -} - -sp<DisplayDevice> SurfaceFlinger::getDisplayByIdOrLayerStack(uint64_t displayOrLayerStack) { - if (const sp<IBinder> displayToken = - getPhysicalDisplayTokenLocked(PhysicalDisplayId{displayOrLayerStack})) { - return getDisplayDeviceLocked(displayToken); - } - // Couldn't find display by displayId. Try to get display by layerStack since virtual displays - // may not have a displayId. - return getDisplayByLayerStack(displayOrLayerStack); -} - -sp<DisplayDevice> SurfaceFlinger::getDisplayByLayerStack(uint64_t layerStack) { - for (const auto& [token, display] : mDisplays) { - if (display->getLayerStack() == layerStack) { - return display; - } - } - return nullptr; + args.pixelFormat, args.allowProtected, captureListener); } status_t SurfaceFlinger::captureDisplay(uint64_t displayOrLayerStack, @@ -5503,7 +5503,8 @@ status_t SurfaceFlinger::captureDisplay(uint64_t displayOrLayerStack, }; return captureScreenCommon(std::move(renderAreaFuture), traverseLayers, size, - ui::PixelFormat::RGBA_8888, captureListener); + ui::PixelFormat::RGBA_8888, false /* allowProtected */, + captureListener); } status_t SurfaceFlinger::captureLayers(const LayerCaptureArgs& args, @@ -5624,18 +5625,32 @@ status_t SurfaceFlinger::captureLayers(const LayerCaptureArgs& args, }; return captureScreenCommon(std::move(renderAreaFuture), traverseLayers, reqSize, - args.pixelFormat, captureListener); + args.pixelFormat, args.allowProtected, captureListener); } status_t SurfaceFlinger::captureScreenCommon(RenderAreaFuture renderAreaFuture, TraverseLayersFunction traverseLayers, ui::Size bufferSize, ui::PixelFormat reqPixelFormat, + const bool allowProtected, const sp<IScreenCaptureListener>& captureListener) { ATRACE_CALL(); - // TODO(b/116112787) Make buffer usage a parameter. - const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | - GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE; + // Loop over all visible layers to see whether there's any protected layer. A protected layer is + // typically a layer with DRM contents, or have the GRALLOC_USAGE_PROTECTED set on the buffer. + // A protected layer has no implication on whether it's secure, which is explicitly set by + // application to avoid being screenshot or drawn via unsecure display. + const bool supportsProtected = getRenderEngine().supportsProtectedContent(); + bool hasProtectedLayer = false; + if (allowProtected && supportsProtected) { + traverseLayers([&](Layer* layer) { + hasProtectedLayer = hasProtectedLayer || (layer->isVisible() && layer->isProtected()); + }); + } + + const uint32_t usage = GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE | + (hasProtectedLayer && allowProtected && supportsProtected + ? GRALLOC_USAGE_PROTECTED + : GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); sp<GraphicBuffer> buffer = getFactory().createGraphicBuffer(bufferSize.getWidth(), bufferSize.getHeight(), static_cast<android_pixel_format>(reqPixelFormat), @@ -5646,7 +5661,7 @@ status_t SurfaceFlinger::captureScreenCommon(RenderAreaFuture renderAreaFuture, status_t SurfaceFlinger::captureScreenCommon(RenderAreaFuture renderAreaFuture, TraverseLayersFunction traverseLayers, - sp<GraphicBuffer>& buffer, bool regionSampling, + sp<GraphicBuffer>& buffer, const bool regionSampling, const sp<IScreenCaptureListener>& captureListener) { ATRACE_CALL(); @@ -5704,6 +5719,8 @@ status_t SurfaceFlinger::renderScreenImplLocked(const RenderArea& renderArea, captureResults.capturedSecureLayers || (layer->isVisible() && layer->isSecure()); }); + const bool useProtected = buffer->getUsage() & GRALLOC_USAGE_PROTECTED; + // We allow the system server to take screenshots of secure layers for // use in situations like the Screen-rotation animation and place // the impetus on WindowManager to not persist them. @@ -5748,14 +5765,13 @@ status_t SurfaceFlinger::renderScreenImplLocked(const RenderArea& renderArea, std::vector<Layer*> renderedLayers; Region clearRegion = Region::INVALID_REGION; traverseLayers([&](Layer* layer) { - const bool supportProtectedContent = false; Region clip(renderArea.getBounds()); compositionengine::LayerFE::ClientCompositionTargetSettings targetSettings{ clip, layer->needsFilteringForScreenshots(display.get(), transform) || renderArea.needsFiltering(), renderArea.isSecure(), - supportProtectedContent, + useProtected, clearRegion, layerStackSpaceRect, clientCompositionDisplay.outputDataspace, @@ -5793,7 +5809,7 @@ status_t SurfaceFlinger::renderScreenImplLocked(const RenderArea& renderArea, // there is no need for synchronization with the GPU. base::unique_fd bufferFence; base::unique_fd drawFence; - getRenderEngine().useProtectedContext(false); + getRenderEngine().useProtectedContext(useProtected); getRenderEngine().drawLayers(clientCompositionDisplay, clientCompositionLayerPointers, buffer, /*useFramebufferCache=*/false, std::move(bufferFence), &drawFence); @@ -5805,6 +5821,8 @@ status_t SurfaceFlinger::renderScreenImplLocked(const RenderArea& renderArea, layer->onLayerDisplayed(releaseFence); } } + // Always switch back to unprotected context. + getRenderEngine().useProtectedContext(false); return NO_ERROR; } diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index f55dd90789..5bb5a0de82 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -797,13 +797,14 @@ private: // Boot animation, on/off animations and screen capture void startBootAnim(); - status_t renderScreenImplLocked(const RenderArea&, TraverseLayersFunction, - const sp<GraphicBuffer>&, bool forSystem, int* outSyncFd, - bool regionSampling, ScreenCaptureResults&); status_t captureScreenCommon(RenderAreaFuture, TraverseLayersFunction, ui::Size bufferSize, - ui::PixelFormat, const sp<IScreenCaptureListener>&); + ui::PixelFormat, const bool allowProtected, + const sp<IScreenCaptureListener>&); status_t captureScreenCommon(RenderAreaFuture, TraverseLayersFunction, sp<GraphicBuffer>&, bool regionSampling, const sp<IScreenCaptureListener>&); + status_t renderScreenImplLocked(const RenderArea&, TraverseLayersFunction, + const sp<GraphicBuffer>&, bool forSystem, int* outSyncFd, + bool regionSampling, ScreenCaptureResults&); sp<DisplayDevice> getDisplayByIdOrLayerStack(uint64_t displayOrLayerStack) REQUIRES(mStateLock); sp<DisplayDevice> getDisplayByLayerStack(uint64_t layerStack) REQUIRES(mStateLock); diff --git a/vulkan/libvulkan/Android.bp b/vulkan/libvulkan/Android.bp index f69de1f324..aa8040b8f2 100644 --- a/vulkan/libvulkan/Android.bp +++ b/vulkan/libvulkan/Android.bp @@ -89,7 +89,6 @@ cc_library_shared { "libhardware", "libsync", "libbase", - "libdl_android", "libhidlbase", "liblog", "libui", @@ -100,6 +99,7 @@ cc_library_shared { "libnativebridge_lazy", "libnativeloader_lazy", "libnativewindow", + "libvndksupport", "android.hardware.graphics.common@1.0", "libSurfaceFlingerProp", ], diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp index 4068a16d80..5c1d023ce9 100644 --- a/vulkan/libvulkan/driver.cpp +++ b/vulkan/libvulkan/driver.cpp @@ -28,20 +28,17 @@ #include <android/dlext.h> #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> #include <configstore/Utils.h> -#include <cutils/properties.h> #include <graphicsenv/GraphicsEnv.h> #include <log/log.h> -#include <nativeloader/dlext_namespaces.h> #include <sys/prctl.h> #include <utils/Timers.h> #include <utils/Trace.h> +#include <vndksupport/linker.h> #include <algorithm> #include <array> #include <climits> #include <new> -#include <string_view> -#include <sstream> #include <vector> #include "stubhal.h" @@ -157,19 +154,11 @@ class CreateInfoWrapper { Hal Hal::hal_; -void* LoadLibrary(const android_dlextinfo& dlextinfo, - const std::string_view subname) { - ATRACE_CALL(); - - std::stringstream ss; - ss << "vulkan." << subname << ".so"; - return android_dlopen_ext(ss.str().c_str(), RTLD_LOCAL | RTLD_NOW, &dlextinfo); -} - const std::array<const char*, 2> HAL_SUBNAME_KEY_PROPERTIES = {{ "ro.hardware.vulkan", "ro.board.platform", }}; +constexpr int LIB_DL_FLAGS = RTLD_LOCAL | RTLD_NOW; // LoadDriver returns: // * 0 when succeed, or @@ -180,20 +169,26 @@ int LoadDriver(android_namespace_t* library_namespace, const hwvulkan_module_t** module) { ATRACE_CALL(); - const android_dlextinfo dlextinfo = { - .flags = ANDROID_DLEXT_USE_NAMESPACE, - .library_namespace = library_namespace, - }; void* so = nullptr; - char prop[PROPERTY_VALUE_MAX]; for (auto key : HAL_SUBNAME_KEY_PROPERTIES) { - int prop_len = property_get(key, prop, nullptr); - if (prop_len > 0 && prop_len <= UINT_MAX) { - std::string_view lib_name(prop, static_cast<unsigned int>(prop_len)); - so = LoadLibrary(dlextinfo, lib_name); - if (so) - break; + std::string lib_name = android::base::GetProperty(key, ""); + if (lib_name.empty()) + continue; + + lib_name = "vulkan." + lib_name + ".so"; + if (library_namespace) { + // load updated driver + const android_dlextinfo dlextinfo = { + .flags = ANDROID_DLEXT_USE_NAMESPACE, + .library_namespace = library_namespace, + }; + so = android_dlopen_ext(lib_name.c_str(), LIB_DL_FLAGS, &dlextinfo); + } else { + // load built-in driver + so = android_load_sphal_library(lib_name.c_str(), LIB_DL_FLAGS); } + if (so) + break; } if (!so) return -ENOENT; @@ -217,12 +212,9 @@ int LoadDriver(android_namespace_t* library_namespace, int LoadBuiltinDriver(const hwvulkan_module_t** module) { ATRACE_CALL(); - auto ns = android_get_exported_namespace("sphal"); - if (!ns) - return -ENOENT; android::GraphicsEnv::getInstance().setDriverToLoad( android::GpuStatsInfo::Driver::VULKAN); - return LoadDriver(ns, module); + return LoadDriver(nullptr, module); } int LoadUpdatedDriver(const hwvulkan_module_t** module) { @@ -323,7 +315,7 @@ void Hal::UnloadBuiltinDriver() { "hw_device_t::close() failed."); // Close the opened shared library in the hw_module_t - dlclose(hal_.dev_->common.module->dso); + android_unload_sphal_library(hal_.dev_->common.module->dso); hal_.dev_ = nullptr; hal_.debug_report_index_ = -1; |