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

Commit b397a2a9 authored by Craig Donner's avatar Craig Donner
Browse files

Allows protected content when the consumer has USAGE_PROTECTED set, even if...

Allows protected content when the consumer has USAGE_PROTECTED set, even if the native window does not queue to the window composer.

Bug: 22775237
Bug: 22855417

Change-Id: I2aa9d8c724efcf1be5debdb69b1ca0bd3be18bb5
parent 197f766a
Loading
Loading
Loading
Loading
+11 −10
Original line number Original line Diff line number Diff line
@@ -55,11 +55,17 @@ status_t setNativeWindowSizeFormatAndUsage(
        return err;
        return err;
    }
    }


    int consumerUsage = 0;
    err = nativeWindow->query(nativeWindow, NATIVE_WINDOW_CONSUMER_USAGE_BITS, &consumerUsage);
    if (err != NO_ERROR) {
        ALOGW("failed to get consumer usage bits. ignoring");
        err = NO_ERROR;
    }

    // Make sure to check whether either Stagefright or the video decoder
    // Make sure to check whether either Stagefright or the video decoder
    // requested protected buffers.
    // requested protected buffers.
    if (usage & GRALLOC_USAGE_PROTECTED) {
    if (usage & GRALLOC_USAGE_PROTECTED) {
        // Verify that the ANativeWindow sends images directly to
        // Check if the ANativeWindow sends images directly to SurfaceFlinger.
        // SurfaceFlinger.
        int queuesToNativeWindow = 0;
        int queuesToNativeWindow = 0;
        err = nativeWindow->query(
        err = nativeWindow->query(
                nativeWindow, NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER, &queuesToNativeWindow);
                nativeWindow, NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER, &queuesToNativeWindow);
@@ -67,19 +73,14 @@ status_t setNativeWindowSizeFormatAndUsage(
            ALOGE("error authenticating native window: %s (%d)", strerror(-err), -err);
            ALOGE("error authenticating native window: %s (%d)", strerror(-err), -err);
            return err;
            return err;
        }
        }
        if (queuesToNativeWindow != 1) {

        // Check if the ANativeWindow uses hardware protected buffers.
        if (queuesToNativeWindow != 1 && !(consumerUsage & GRALLOC_USAGE_PROTECTED)) {
            ALOGE("native window could not be authenticated");
            ALOGE("native window could not be authenticated");
            return PERMISSION_DENIED;
            return PERMISSION_DENIED;
        }
        }
    }
    }


    int consumerUsage = 0;
    err = nativeWindow->query(nativeWindow, NATIVE_WINDOW_CONSUMER_USAGE_BITS, &consumerUsage);
    if (err != NO_ERROR) {
        ALOGW("failed to get consumer usage bits. ignoring");
        err = NO_ERROR;
    }

    int finalUsage = usage | consumerUsage;
    int finalUsage = usage | consumerUsage;
    ALOGV("gralloc usage: %#x(producer) + %#x(consumer) = %#x", usage, consumerUsage, finalUsage);
    ALOGV("gralloc usage: %#x(producer) + %#x(consumer) = %#x", usage, consumerUsage, finalUsage);
    err = native_window_set_usage(nativeWindow, finalUsage);
    err = native_window_set_usage(nativeWindow, finalUsage);