Search in sources :

Example 1 with DrmManagerClient

use of android.drm.DrmManagerClient in project qksms by moezbhatti.

the class DrmUtils method isDrmType.

public static boolean isDrmType(String mimeType) {
    boolean result = false;
    DrmManagerClient drmManagerClient = QKSMSApp.getApplication().getDrmManagerClient();
    if (drmManagerClient != null) {
        try {
            if (drmManagerClient.canHandle("", mimeType)) {
                result = true;
            }
        } catch (IllegalArgumentException ex) {
            Log.w(TAG, "canHandle called with wrong parameters");
        } catch (IllegalStateException ex) {
            Log.w(TAG, "DrmManagerClient didn't initialize properly");
        }
    }
    return result;
}
Also used : DrmManagerClient(android.drm.DrmManagerClient)

Example 2 with DrmManagerClient

use of android.drm.DrmManagerClient in project qksms by moezbhatti.

the class DownloadDrmHelper method getOriginalMimeType.

/**
     * Gets the original mime type of DRM protected content.
     *
     * @param context The context
     * @param path Path to the file
     * @param containingMime The current mime type of of the file i.e. the
     *            containing mime type
     * @return The original mime type of the file if DRM protected else the
     *         currentMime
     */
public static String getOriginalMimeType(Context context, String path, String containingMime) {
    String result = containingMime;
    DrmManagerClient drmClient = new DrmManagerClient(context);
    try {
        if (drmClient.canHandle(path, null)) {
            result = drmClient.getOriginalMimeType(path);
        }
    } catch (IllegalArgumentException ex) {
        Log.w(TAG, "Can't get original mime type since path is null or empty string.");
    } catch (IllegalStateException ex) {
        Log.w(TAG, "DrmManagerClient didn't initialize properly.");
    }
    return result;
}
Also used : DrmManagerClient(android.drm.DrmManagerClient)

Example 3 with DrmManagerClient

use of android.drm.DrmManagerClient in project qksms by moezbhatti.

the class DrmConvertSession method open.

/**
     * Start of converting a file.
     *
     * @param context The context of the application running the convert session.
     * @param mimeType Mimetype of content that shall be converted.
     * @return A convert session or null in case an error occurs.
     */
public static DrmConvertSession open(Context context, String mimeType) {
    DrmManagerClient drmClient = null;
    int convertSessionId = -1;
    if (context != null && mimeType != null && !mimeType.equals("")) {
        try {
            drmClient = new DrmManagerClient(context);
            try {
                convertSessionId = drmClient.openConvertSession(mimeType);
            } catch (IllegalArgumentException e) {
                Log.w(TAG, "Conversion of Mimetype: " + mimeType + " is not supported.", e);
            } catch (IllegalStateException e) {
                Log.w(TAG, "Could not access Open DrmFramework.", e);
            }
        } catch (IllegalArgumentException e) {
            Log.w(TAG, "DrmManagerClient instance could not be created, context is Illegal.");
        } catch (IllegalStateException e) {
            Log.w(TAG, "DrmManagerClient didn't initialize properly.");
        }
    }
    if (drmClient == null || convertSessionId < 0) {
        return null;
    } else {
        return new DrmConvertSession(drmClient, convertSessionId);
    }
}
Also used : DrmManagerClient(android.drm.DrmManagerClient)

Example 4 with DrmManagerClient

use of android.drm.DrmManagerClient in project qksms by moezbhatti.

the class SmilHelper method createSmilDocument.

private static SMILDocument createSmilDocument(PduBody pb) {
    if (Config.LOGV) {
        Log.v(TAG, "Creating default SMIL document.");
    }
    SMILDocument document = new SmilDocumentImpl();
    // Create root element.
    // FIXME: Should we create root element in the constructor of document?
    SMILElement smil = (SMILElement) document.createElement("smil");
    smil.setAttribute("xmlns", "http://www.w3.org/2001/SMIL20/Language");
    document.appendChild(smil);
    // Create <head> and <layout> element.
    SMILElement head = (SMILElement) document.createElement("head");
    smil.appendChild(head);
    SMILLayoutElement layout = (SMILLayoutElement) document.createElement("layout");
    head.appendChild(layout);
    // Create <body> element and add a empty <par>.
    SMILElement body = (SMILElement) document.createElement("body");
    smil.appendChild(body);
    SMILParElement par = addPar(document);
    // Create media objects for the parts in PDU.
    int partsNum = pb.getPartsNum();
    if (partsNum == 0) {
        return document;
    }
    DrmManagerClient drmManagerClient = QKSMSApp.getApplication().getDrmManagerClient();
    boolean hasText = false;
    boolean hasMedia = false;
    for (int i = 0; i < partsNum; i++) {
        // Create new <par> element.
        if ((par == null) || (hasMedia && hasText)) {
            par = addPar(document);
            hasText = false;
            hasMedia = false;
        }
        PduPart part = pb.getPart(i);
        String contentType = new String(part.getContentType());
        if (ContentType.isDrmType(contentType)) {
            contentType = drmManagerClient.getOriginalMimeType(part.getDataUri());
        }
        if (contentType.equals(ContentType.TEXT_PLAIN) || contentType.equalsIgnoreCase(ContentType.APP_WAP_XHTML) || contentType.equals(ContentType.TEXT_HTML)) {
            SMILMediaElement textElement = createMediaElement(ELEMENT_TAG_TEXT, document, part.generateLocation());
            par.appendChild(textElement);
            hasText = true;
        } else if (ContentType.isImageType(contentType)) {
            SMILMediaElement imageElement = createMediaElement(ELEMENT_TAG_IMAGE, document, part.generateLocation());
            par.appendChild(imageElement);
            hasMedia = true;
        } else if (ContentType.isVideoType(contentType)) {
            SMILMediaElement videoElement = createMediaElement(ELEMENT_TAG_VIDEO, document, part.generateLocation());
            par.appendChild(videoElement);
            hasMedia = true;
        } else if (ContentType.isAudioType(contentType)) {
            SMILMediaElement audioElement = createMediaElement(ELEMENT_TAG_AUDIO, document, part.generateLocation());
            par.appendChild(audioElement);
            hasMedia = true;
        } else {
            // TODO: handle other media types.
            Log.w(TAG, "unsupport media type");
        }
    }
    return document;
}
Also used : SMILMediaElement(org.w3c.dom.smil.SMILMediaElement) SMILDocument(org.w3c.dom.smil.SMILDocument) SmilDocumentImpl(com.android.mms.dom.smil.SmilDocumentImpl) SMILLayoutElement(org.w3c.dom.smil.SMILLayoutElement) SMILParElement(org.w3c.dom.smil.SMILParElement) PduPart(com.google.android.mms.pdu_alt.PduPart) SMILElement(org.w3c.dom.smil.SMILElement) DrmManagerClient(android.drm.DrmManagerClient)

Aggregations

DrmManagerClient (android.drm.DrmManagerClient)4 SmilDocumentImpl (com.android.mms.dom.smil.SmilDocumentImpl)1 PduPart (com.google.android.mms.pdu_alt.PduPart)1 SMILDocument (org.w3c.dom.smil.SMILDocument)1 SMILElement (org.w3c.dom.smil.SMILElement)1 SMILLayoutElement (org.w3c.dom.smil.SMILLayoutElement)1 SMILMediaElement (org.w3c.dom.smil.SMILMediaElement)1 SMILParElement (org.w3c.dom.smil.SMILParElement)1