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

Commit bc2d2a32 authored by Tom Taylor's avatar Tom Taylor
Browse files

Support INSTALL_DRM permission

Add overloaded function to write to DRM with a
stream. Used by MMS to save protected content.
parent f88c0a06
Loading
Loading
Loading
Loading
+46 −20
Original line number Diff line number Diff line
@@ -101,12 +101,46 @@ public final class DrmStore
     */
    public static final Intent addDrmFile(ContentResolver cr, File file, String title) {
        FileInputStream fis = null;
        OutputStream os = null;
        Intent result = null;

        try {
            fis = new FileInputStream(file);
            DrmRawContent content = new DrmRawContent(fis, (int) file.length(),
            if (title == null) {
                title = file.getName();
                int lastDot = title.lastIndexOf('.');
                if (lastDot > 0) {
                    title = title.substring(0, lastDot);
                }
            }
            result = addDrmFile(cr, fis, title);
        } catch (Exception e) {
            Log.e(TAG, "pushing file failed", e);
        } finally {
            try {
                if (fis != null)
                    fis.close();
            } catch (IOException e) {
                Log.e(TAG, "IOException in DrmStore.addDrmFile()", e);
            }
        }

        return result;
    }

    /**
     * Utility function for inserting a file stream into the DRM content provider.
     *
     * @param cr The content resolver to use
     * @param fileStream The FileInputStream to insert
     * @param title The title for the content (or null)
     * @return uri to the DRM record or null
     */
    public static final Intent addDrmFile(ContentResolver cr, FileInputStream fis, String title) {
        OutputStream os = null;
        Intent result = null;

        try {
            DrmRawContent content = new DrmRawContent(fis, (int) fis.available(),
                    DrmRawContent.DRM_MIMETYPE_MESSAGE_STRING);
            String mimeType = content.getContentType();

@@ -126,14 +160,6 @@ public final class DrmStore

            if (contentUri != null) {
                ContentValues values = new ContentValues(3);
                // compute title from file name, if it is not specified
                if (title == null) {
                    title = file.getName();
                    int lastDot = title.lastIndexOf('.');
                    if (lastDot > 0) {
                        title = title.substring(0, lastDot);
                    }
                }
                values.put(DrmStore.Columns.TITLE, title);
                values.put(DrmStore.Columns.SIZE, size);
                values.put(DrmStore.Columns.MIME_TYPE, mimeType);
@@ -162,7 +188,7 @@ public final class DrmStore
                if (os != null)
                    os.close();
            } catch (IOException e) {
                Log.e(TAG, "IOException in DrmTest.onCreate()", e);
                Log.e(TAG, "IOException in DrmStore.addDrmFile()", e);
            }
        }