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

Commit b40b2499 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "libdrm: Added support for Combined Delivery and Separate Delivery"

parents 2923c9ef 53837fcd
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -10126,6 +10126,14 @@ package android.drm {
    field public static final java.lang.String REMAINING_REPEAT_COUNT = "remaining_repeat_count";
  }
  public static class DrmStore.DrmDeliveryType {
    ctor public DrmStore.DrmDeliveryType();
    field public static final int COMBINED_DELIVERY = 2; // 0x2
    field public static final int FORWARD_LOCK = 1; // 0x1
    field public static final int SEPARATE_DELIVERY = 3; // 0x3
    field public static final int SEPARATE_DELIVERY_FL = 4; // 0x4
  }
  public static class DrmStore.DrmObjectType {
    ctor public deprecated DrmStore.DrmObjectType();
    field public static final int CONTENT = 1; // 0x1
@@ -10455,15 +10463,23 @@ package android.graphics {
  public class BitmapFactory {
    ctor public BitmapFactory();
    method public static android.graphics.Bitmap decodeByteArray(byte[], int, int, android.graphics.BitmapFactory.Options);
    method public static android.graphics.Bitmap decodeByteArray(byte[], int, int, android.graphics.BitmapFactory.Options, boolean);
    method public static android.graphics.Bitmap decodeByteArray(byte[], int, int);
    method public static android.graphics.Bitmap decodeByteArray(byte[], int, int, boolean);
    method public static android.graphics.Bitmap decodeFile(java.lang.String, android.graphics.BitmapFactory.Options);
    method public static android.graphics.Bitmap decodeFile(java.lang.String, android.graphics.BitmapFactory.Options, boolean);
    method public static android.graphics.Bitmap decodeFile(java.lang.String);
    method public static android.graphics.Bitmap decodeFileDescriptor(java.io.FileDescriptor, android.graphics.Rect, android.graphics.BitmapFactory.Options);
    method public static android.graphics.Bitmap decodeFileDescriptor(java.io.FileDescriptor, android.graphics.Rect, android.graphics.BitmapFactory.Options, boolean);
    method public static android.graphics.Bitmap decodeFileDescriptor(java.io.FileDescriptor);
    method public static android.graphics.Bitmap decodeResource(android.content.res.Resources, int, android.graphics.BitmapFactory.Options);
    method public static android.graphics.Bitmap decodeResource(android.content.res.Resources, int, android.graphics.BitmapFactory.Options, boolean);
    method public static android.graphics.Bitmap decodeResource(android.content.res.Resources, int);
    method public static android.graphics.Bitmap decodeResource(android.content.res.Resources, int, boolean);
    method public static android.graphics.Bitmap decodeResourceStream(android.content.res.Resources, android.util.TypedValue, java.io.InputStream, android.graphics.Rect, android.graphics.BitmapFactory.Options);
    method public static android.graphics.Bitmap decodeResourceStream(android.content.res.Resources, android.util.TypedValue, java.io.InputStream, android.graphics.Rect, android.graphics.BitmapFactory.Options, boolean);
    method public static android.graphics.Bitmap decodeStream(java.io.InputStream, android.graphics.Rect, android.graphics.BitmapFactory.Options);
    method public static android.graphics.Bitmap decodeStream(java.io.InputStream, android.graphics.Rect, android.graphics.BitmapFactory.Options, boolean);
    method public static android.graphics.Bitmap decodeStream(java.io.InputStream);
  }
+1 −0
Original line number Diff line number Diff line
@@ -239,6 +239,7 @@ LOCAL_SHARED_LIBRARIES := \
	libjpeg \
	libusbhost \
	libharfbuzz_ng \
	libdrmframework \
	libz \
	libaudioutils \
	libpdfium \
+113 −13
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

#include "BitmapFactory.h"
#include "NinePatchPeeker.h"
#include "SkData.h"
#include "SkFrontBufferedStream.h"
#include "SkImageDecoder.h"
#include "SkMath.h"
@@ -23,6 +24,9 @@
#include <stdio.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <drm/DrmManagerClient.h>
#include <utils/Log.h>
#include <fcntl.h>

jfieldID gOptions_justBoundsFieldID;
jfieldID gOptions_sampleSizeFieldID;
@@ -206,7 +210,8 @@ private:
    const unsigned int mSize;
};

static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding, jobject options) {
static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding,
        jobject options, bool consumeRights ) {

    int sampleSize = 1;

@@ -254,6 +259,76 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding
    const bool willScale = scale != 1.0f;

    SkImageDecoder* decoder = SkImageDecoder::Factory(stream);
    if (NULL == decoder) {
        DrmManagerClient* mDrmManagerClient = new DrmManagerClient();
        sp<DecryptHandle> mDecryptHandle = NULL;
        if (mDrmManagerClient != NULL) {
            const int size = 4096;
            int readBytes = 0;
            int encodedFD = -1;
            char tempFile[50];
            char tempDecodedFile[50];
            int temp1 = rand();
            int temp2 = rand();
            sprintf(tempFile, "/data/local/.Drm/%d.temp", temp1);
            sprintf(tempDecodedFile, "/data/local/.Drm/%d.temp", temp2);
            ALOGV("dodecode:t1=%s ,t2=%s", tempFile, tempDecodedFile);

            encodedFD = open (tempFile, O_WRONLY | O_CREAT, 0777);
            char* encodedData = new char[size];

            while ((readBytes = stream->read(encodedData, size)) > 0) {
                write(encodedFD, encodedData, readBytes);
            }
            close(encodedFD);
            if (encodedData != NULL) {
                delete [] encodedData;
            }
            encodedFD = -1;
            encodedFD = open (tempFile, O_RDONLY);

            mDecryptHandle = mDrmManagerClient->openDecryptSession(encodedFD, 0, 1, NULL);
            if ((mDecryptHandle != NULL) && (mDecryptHandle->status == RightsStatus::RIGHTS_VALID)) {
                char* data = new char[size];
                int len = 0;
                int decodedFD = -1;

                decodedFD = open(tempDecodedFile, O_WRONLY | O_CREAT, 0777);
                int offset = 0;
                while ((len = mDrmManagerClient->pread(mDecryptHandle, data, size, offset)) > 0) {
                    write(decodedFD, data, len);
                    offset += len;
                }

                //Consume  Rights
                if (consumeRights) {
                    ALOGV("bitmap factory:doDecode: calling consumeRights");
                    mDrmManagerClient->consumeRights(mDecryptHandle, Action::DISPLAY, true);
                }
                close(decodedFD);
                decodedFD = -1;
                decodedFD = open(tempDecodedFile, O_RDONLY);
                bool weOwnTheFD = true;
                SkAutoTUnref<SkData> drmdata(SkData::NewFromFD(decodedFD));
                stream = new SkMemoryStream(drmdata);
                decoder = SkImageDecoder::Factory(stream);
                if (data != NULL)
                    delete [] data;
            }
            if (mDecryptHandle != NULL) {
                mDrmManagerClient->closeDecryptSession(mDecryptHandle);
                mDecryptHandle = NULL;
            }
            if (mDrmManagerClient != NULL) {
                delete mDrmManagerClient;
                mDrmManagerClient = NULL;
            }
            if (encodedFD >= 0) close(encodedFD);
            remove(tempFile);
            remove(tempDecodedFile);
        }
    }

    if (decoder == NULL) {
        return nullObjectReturn("SkImageDecoder::Factory returned null");
    }
@@ -459,7 +534,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding
#define BYTES_TO_BUFFER 64

static jobject nativeDecodeStream(JNIEnv* env, jobject clazz, jobject is, jbyteArray storage,
        jobject padding, jobject options) {
        jobject padding, jobject options, jboolean consumeRights = true) {

    jobject bitmap = NULL;
    SkAutoTUnref<SkStream> stream(CreateJavaInputStreamAdaptor(env, is, storage));
@@ -468,13 +543,13 @@ static jobject nativeDecodeStream(JNIEnv* env, jobject clazz, jobject is, jbyteA
        SkAutoTUnref<SkStreamRewindable> bufferedStream(
                SkFrontBufferedStream::Create(stream, BYTES_TO_BUFFER));
        SkASSERT(bufferedStream.get() != NULL);
        bitmap = doDecode(env, bufferedStream, padding, options);
        bitmap = doDecode(env, bufferedStream, padding, options, consumeRights);
    }
    return bitmap;
}

static jobject nativeDecodeFileDescriptor(JNIEnv* env, jobject clazz, jobject fileDescriptor,
        jobject padding, jobject bitmapFactoryOptions) {
        jobject padding, jobject bitmapFactoryOptions, jboolean consumeRights = true) {

    NPE_CHECK_RETURN_ZERO(env, fileDescriptor);

@@ -503,27 +578,52 @@ static jobject nativeDecodeFileDescriptor(JNIEnv* env, jobject clazz, jobject fi
    SkAutoTUnref<SkStreamRewindable> stream(SkFrontBufferedStream::Create(fileStream,
            BYTES_TO_BUFFER));

    return doDecode(env, stream, padding, bitmapFactoryOptions);
    //return doDecode(env, stream, padding, bitmapFactoryOptions, isPurgeable);
    jobject obj = doDecode(env, stream, padding, bitmapFactoryOptions, false);
    if (consumeRights) {
        ALOGV("nativeDecodeFileDescriptor1 with consumeRights=true");
        DrmManagerClient* drmManagerClient = new DrmManagerClient();
        sp<DecryptHandle> decryptHandle = NULL;
        decryptHandle = drmManagerClient->openDecryptSession(descriptor, 0, 1, NULL);
        if (decryptHandle != NULL) {
            //Consume Rights
            if (consumeRights) {
                ALOGV("bitmap factory: calling consumeRights");
                drmManagerClient->consumeRights(decryptHandle, Action::DISPLAY, true);
            }
        }
        if (decryptHandle != NULL) {
            drmManagerClient->closeDecryptSession(decryptHandle);
            decryptHandle = NULL;
        }
        if (drmManagerClient != NULL) {
            delete drmManagerClient;
            drmManagerClient = NULL;
        }
    } else {
        ALOGV("nativeDecodeFileDescriptor1 with consumeRights=false");
    }
    return obj;
}

static jobject nativeDecodeAsset(JNIEnv* env, jobject clazz, jlong native_asset,
        jobject padding, jobject options) {
        jobject padding, jobject options, jboolean consumeRights = true) {

    Asset* asset = reinterpret_cast<Asset*>(native_asset);
    // since we know we'll be done with the asset when we return, we can
    // just use a simple wrapper
    SkAutoTUnref<SkStreamRewindable> stream(new AssetStreamAdaptor(asset,
            AssetStreamAdaptor::kNo_OwnAsset, AssetStreamAdaptor::kNo_HasMemoryBase));
    return doDecode(env, stream, padding, options);
    return doDecode(env, stream, padding, options, consumeRights);
}

static jobject nativeDecodeByteArray(JNIEnv* env, jobject, jbyteArray byteArray,
        jint offset, jint length, jobject options) {
        jint offset, jint length, jobject options, jboolean consumeRights = true) {

    AutoJavaByteArray ar(env, byteArray);
    SkMemoryStream* stream = new SkMemoryStream(ar.ptr() + offset, length, false);
    SkAutoUnref aur(stream);
    return doDecode(env, stream, NULL, options);
    return doDecode(env, stream, NULL, options, consumeRights);
}

static void nativeRequestCancel(JNIEnv*, jobject joptions) {
@@ -539,22 +639,22 @@ static jboolean nativeIsSeekable(JNIEnv* env, jobject, jobject fileDescriptor) {

static JNINativeMethod gMethods[] = {
    {   "nativeDecodeStream",
        "(Ljava/io/InputStream;[BLandroid/graphics/Rect;Landroid/graphics/BitmapFactory$Options;)Landroid/graphics/Bitmap;",
        "(Ljava/io/InputStream;[BLandroid/graphics/Rect;Landroid/graphics/BitmapFactory$Options;Z)Landroid/graphics/Bitmap;",
        (void*)nativeDecodeStream
    },

    {   "nativeDecodeFileDescriptor",
        "(Ljava/io/FileDescriptor;Landroid/graphics/Rect;Landroid/graphics/BitmapFactory$Options;)Landroid/graphics/Bitmap;",
        "(Ljava/io/FileDescriptor;Landroid/graphics/Rect;Landroid/graphics/BitmapFactory$Options;Z)Landroid/graphics/Bitmap;",
        (void*)nativeDecodeFileDescriptor
    },

    {   "nativeDecodeAsset",
        "(JLandroid/graphics/Rect;Landroid/graphics/BitmapFactory$Options;)Landroid/graphics/Bitmap;",
        "(JLandroid/graphics/Rect;Landroid/graphics/BitmapFactory$Options;Z)Landroid/graphics/Bitmap;",
        (void*)nativeDecodeAsset
    },

    {   "nativeDecodeByteArray",
        "([BIILandroid/graphics/BitmapFactory$Options;)Landroid/graphics/Bitmap;",
        "([BIILandroid/graphics/BitmapFactory$Options;Z)Landroid/graphics/Bitmap;",
        (void*)nativeDecodeByteArray
    },

+74 −1
Original line number Diff line number Diff line
@@ -13,7 +13,6 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "BitmapRegionDecoder"

#include "SkBitmap.h"
@@ -34,6 +33,9 @@
#include "android_util_Binder.h"
#include "android_nio_utils.h"
#include "CreateJavaOutputStreamAdaptor.h"
#include <drm/DrmManagerClient.h>
#include <utils/Log.h>
#include <fcntl.h>

#include <binder/Parcel.h>
#include <jni.h>
@@ -78,6 +80,77 @@ private:
static jobject createBitmapRegionDecoder(JNIEnv* env, SkStreamRewindable* stream) {
    SkImageDecoder* decoder = SkImageDecoder::Factory(stream);
    int width, height;
    if (NULL == decoder) {
        ALOGV("decoder is null and entered drm path");
        DrmManagerClient* mDrmManagerClient = new DrmManagerClient();
        sp<DecryptHandle> mDecryptHandle = NULL;
        if (mDrmManagerClient != NULL) {
            const int size = 4096;
            int readBytes = 0;
            int encodedFD = -1;
            char tempFile[50];
            char temp[50];
            int temp1 = rand();
            int temp2 = rand();
            sprintf(tempFile, "/data/local/.Drm/%d.tmp", temp1);
            sprintf(temp, "/data/local/.Drm/%d.tmp", temp2);
            ALOGV("dodecode:t1=%s ,t2=%s", tempFile, temp);
            encodedFD = open(tempFile, O_WRONLY | O_CREAT, 0777);
            char* encodedData = new char[size];

            while ((readBytes = stream->read(encodedData, size)) > 0)
                write(encodedFD, encodedData, readBytes);

            close(encodedFD);
            if (encodedData != NULL)
                delete [] encodedData;

            encodedFD = -1;
            encodedFD = open (tempFile, O_RDONLY);

            ALOGV("opening Decrypt Session");
            mDecryptHandle = mDrmManagerClient->openDecryptSession(encodedFD, 0, 1, NULL);
            if(mDecryptHandle == NULL) {
                ALOGV("Got mDecryptHandle == NULL");
            }
            if ((mDecryptHandle != NULL) && (mDecryptHandle->status == RightsStatus::RIGHTS_VALID)) {
                ALOGV("bitmap factory: mDecryptHandle not null");
                char* data = new char[size];
                int len = 0;
                int decodedFD = -1;

                decodedFD = open(temp, O_WRONLY | O_CREAT, 0777);
                int offset = 0;
                while ((len = mDrmManagerClient->pread(mDecryptHandle, data, size, offset)) > 0) {
                    ALOGV("pread returned bytes=%d", len);
                    write(decodedFD, data, len);
                    offset += len;
                }
                close(decodedFD);
                decodedFD = -1;
                decodedFD = open (temp, O_RDONLY);
                bool weOwnTheFD = true;
                SkAutoTUnref<SkData> drmdata(SkData::NewFromFD(decodedFD));
                stream = new SkMemoryStream(drmdata);
                decoder = SkImageDecoder::Factory(stream);
                if (data != NULL)
                    delete [] data;
            }

            if (mDecryptHandle != NULL) {
                mDrmManagerClient->closeDecryptSession(mDecryptHandle);
                mDecryptHandle = NULL;
            }
            if (mDrmManagerClient != NULL) {
                delete mDrmManagerClient;
                mDrmManagerClient = NULL;
            }
            if (encodedFD >= 0) close(encodedFD);
            remove(tempFile);
            remove(temp);
        }
    }

    if (NULL == decoder) {
        doThrowIOE(env, "Image format not supported");
        return nullObjectReturn("SkImageDecoder::Factory returned null");
+45 −3
Original line number Diff line number Diff line
@@ -28,8 +28,12 @@ import android.util.Log;
import libcore.io.IoBridge;
import libcore.io.Streams;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileInputStream;
import java.io.FileDescriptor;
import java.io.FilterOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.UnknownServiceException;
@@ -73,7 +77,44 @@ public class DrmOutputStream extends OutputStream {
            } catch (ErrnoException e) {
                e.rethrowAsIOException();
            }
            IoBridge.write(mFd, status.convertedData, 0, status.convertedData.length);

            // IoBridge.write(mFd, status.convertedData, 0, status.convertedData.length);
            InputStream ipStream = null;
            String path = null;
            try {
                byte[] filePath = status.convertedData;
                path = new String(filePath);
                if (path != null) ipStream = new FileInputStream(path);
                byte[] buffer = new byte[4096];
                int size=0;
                do {
                    size = ipStream.read(buffer);
                    if (size > 0) {
                       IoBridge.write(mFd, buffer, 0, size);
                    }
                } while(size > 0);
            } catch (FileNotFoundException e) {
                Log.w(TAG, "File: " + mFd + " could not be found.", e);
            } catch (IOException e) {
                Log.w(TAG, "Could not access File: " + mFd + " .", e);
            } catch (IllegalArgumentException e) {
                Log.w(TAG, "Could not open file in mode: rw", e);
            } catch (SecurityException e) {
                Log.w(TAG, "Access to File: " + mFd +
                        " was denied denied by SecurityManager.", e);
            } finally {
                try {
                    File file = null;
                    if (path != null) file = new File(path);
                    if (file.delete()) {
                        Log.i(TAG, "deleted the temp file ");
                    } else {
                        Log.i(TAG, "could not deleted the temp file ");
                    }
                } catch (Exception e) {
                    Log.e(TAG, "exeption");
                }
            }
            mSessionId = INVALID_SESSION;
        } else {
            throw new IOException("Unexpected DRM status: " + status.statusCode);
@@ -82,7 +123,7 @@ public class DrmOutputStream extends OutputStream {

    @Override
    public void close() throws IOException {
        if (mSessionId == INVALID_SESSION) {
        if (mSessionId != INVALID_SESSION) {
            Log.w(TAG, "Closing stream without finishing");
        }

@@ -103,7 +144,8 @@ public class DrmOutputStream extends OutputStream {

        final DrmConvertedStatus status = mClient.convertData(mSessionId, exactBuffer);
        if (status.statusCode == STATUS_OK) {
            IoBridge.write(mFd, status.convertedData, 0, status.convertedData.length);
            // Do not write converted data here. Converted data will write on finish()
            // IoBridge.write(mFd, status.convertedData, 0, status.convertedData.length);
        } else {
            throw new IOException("Unexpected DRM status: " + status.statusCode);
        }
Loading