Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b9fc0b0 authored by Chavi Weingarten's avatar Chavi Weingarten Committed by Android (Google) Code Review
Browse files

Merge changes I129b5a7f,I633f293e

* changes:
  Allow screen capture for a specified uid.
  Store Layer ownerUid based on metadata or callingUid.
parents 6cd89aa3 4b9d5e1c
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -509,7 +509,8 @@ status_t CaptureArgs::write(Parcel& output) const {
    status_t status = output.writeInt32(static_cast<int32_t>(pixelFormat)) ?:
        output.write(sourceCrop) ?:
        output.writeFloat(frameScale) ?:
        output.writeBool(captureSecureLayers);
        output.writeBool(captureSecureLayers) ?:
        output.writeInt32(uid);
    return status;
}

@@ -518,7 +519,8 @@ status_t CaptureArgs::read(const Parcel& input) {
    status_t status = input.readInt32(&format) ?:
        input.read(sourceCrop) ?:
        input.readFloat(&frameScale) ?:
        input.readBool(&captureSecureLayers);
        input.readBool(&captureSecureLayers) ?:
        input.readInt32(&uid);

    pixelFormat = static_cast<ui::PixelFormat>(format);
    return status;
+2 −0
Original line number Diff line number Diff line
@@ -314,12 +314,14 @@ static inline int compare_type(const DisplayState& lhs, const DisplayState& rhs)
bool ValidateFrameRate(float frameRate, int8_t compatibility, const char* functionName);

struct CaptureArgs {
    const static int32_t UNSET_UID = -1;
    virtual ~CaptureArgs() = default;

    ui::PixelFormat pixelFormat{ui::PixelFormat::RGBA_8888};
    Rect sourceCrop;
    float frameScale{1};
    bool captureSecureLayers{false};
    int32_t uid{UNSET_UID};

    virtual status_t write(Parcel& output) const;
    virtual status_t read(const Parcel& input);
+13 −2
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@
#include <gui/LayerDebugInfo.h>
#include <gui/Surface.h>
#include <math.h>
#include <private/android_filesystem_config.h>
#include <renderengine/RenderEngine.h>
#include <stdint.h>
#include <stdlib.h>
@@ -139,6 +140,14 @@ Layer::Layer(const LayerCreationArgs& args)

    mCallingPid = args.callingPid;
    mCallingUid = args.callingUid;

    if (mCallingUid == AID_GRAPHICS || mCallingUid == AID_SYSTEM) {
        // If the system didn't send an ownerUid, use the callingUid for the ownerUid.
        mOwnerUid = args.metadata.getInt32(METADATA_OWNER_UID, mCallingUid);
    } else {
        // A create layer request from a non system request cannot specify the owner uid
        mOwnerUid = mCallingUid;
    }
}

void Layer::onFirstRef() {
@@ -1669,8 +1678,8 @@ void Layer::dumpFrameEvents(std::string& result) {
}

void Layer::dumpCallingUidPid(std::string& result) const {
    StringAppendF(&result, "Layer %s (%s) pid:%d uid:%d\n", getName().c_str(), getType(),
                  mCallingPid, mCallingUid);
    StringAppendF(&result, "Layer %s (%s) callingPid:%d callingUid:%d ownerUid:%d\n",
                  getName().c_str(), getType(), mCallingPid, mCallingUid, mOwnerUid);
}

void Layer::onDisconnect() {
@@ -2343,6 +2352,8 @@ void Layer::writeToProtoCommonState(LayerProto* layerInfo, LayerVector::StateSet
        }

        layerInfo->set_is_relative_of(state.isRelativeOf);

        layerInfo->set_owner_uid(mOwnerUid);
    }

    if (traceFlags & SurfaceTracing::TRACE_INPUT) {
+7 −3
Original line number Diff line number Diff line
@@ -436,9 +436,7 @@ public:
    // Deprecated, please use compositionengine::Output::belongsInOutput()
    // instead.
    // TODO(lpique): Move the remaining callers (screencap) to the new function.
    bool belongsToDisplay(uint32_t layerStack, bool isPrimaryDisplay) const {
        return getLayerStack() == layerStack && (!mPrimaryDisplayOnly || isPrimaryDisplay);
    }
    bool belongsToDisplay(uint32_t layerStack) const { return getLayerStack() == layerStack; }

    FloatRect getBounds(const Region& activeTransparentRegion) const;
    FloatRect getBounds() const;
@@ -967,6 +965,8 @@ public:
     */
    virtual bool needsInputInfo() const { return hasInputInfo(); }

    uid_t getOwnerUid() { return mOwnerUid; }

protected:
    compositionengine::OutputLayer* findOutputLayerForDisplay(const DisplayDevice*) const;

@@ -1089,6 +1089,10 @@ private:
    pid_t mCallingPid;
    uid_t mCallingUid;

    // The owner of the layer. If created from a non system process, it will be the calling uid.
    // If created from a system process, the value can be passed in.
    uid_t mOwnerUid;

    // The current layer is a clone of mClonedFrom. This means that this layer will update it's
    // properties based on mClonedFrom. When mClonedFrom latches a new buffer for BufferLayers,
    // this layer will update it's buffer. When mClonedFrom updates it's drawing state, children,
+1 −1
Original line number Diff line number Diff line
@@ -429,7 +429,7 @@ void RegionSamplingThread::captureSample() {
                  bounds.top, bounds.right, bounds.bottom);
            visitor(layer);
        };
        mFlinger.traverseLayersInLayerStack(layerStack, filterVisitor);
        mFlinger.traverseLayersInLayerStack(layerStack, CaptureArgs::UNSET_UID, filterVisitor);
    };

    sp<GraphicBuffer> buffer = nullptr;
Loading