public static void parsePSSH(byte[] pssh, RequestManager.Task task) { try { task.mHeader = DrmPiffParser.getPlayReadyHeader(pssh); if (task.mHeader == null) { task.mHttpError = Constants.HTTP_ERROR_XML_PARSING_ERROR; } } catch (Exception e) { task.mHttpError = Constants.HTTP_ERROR_XML_PARSING_ERROR; DrmLog.logException(e); } }
public static void parseFile(Context context, String fileUri, RequestManager.Task task) { Uri uri = Uri.parse(fileUri); final StringBuffer headerString = new StringBuffer(); String tempFile = null; String scheme = uri.getScheme(); if ("http".equals(scheme)) { tempFile = getUniqueTempFileName(context, uri.getLastPathSegment()); if (tempFile != null) { final boolean manifest = fileUri.toLowerCase(Locale.US).endsWith(".ism/manifest"); final String callbackFile = tempFile; DataHandlerCallback dataCallback = new DataHandlerCallback() { @SuppressLint("WorldReadableFiles") public void handleData(InputStream is) { try { FileOutputStream fos = new FileOutputStream(callbackFile, true); int dataCounter = 0, read; byte[] buffer = new byte[2048]; try { while ((read = is.read(buffer)) != -1) { dataCounter += read; fos.write(buffer, 0, read); String header; if (manifest) { header = findManifestHeader(callbackFile); } else { header = findHeader(callbackFile); } if (header != null) { DrmLog.debug("header found"); // We have the header, stop download headerString.append(header); break; } if (!manifest && dataCounter > 20 * 1024) { // PR header has not been found in the // first 20kB of the file, it is // probably a non-DRM file, stop // trying to renew. break; } } } finally { fos.close(); } } catch (IOException e) { DrmLog.logException(e); } } }; Response response = UrlConnectionClient.get( context, task.mDlsSessionId, uri.toString(), null, dataCallback, null); if (response == null) { task.mHttpError = Constants.HTTP_ERROR_INTERNAL_ERROR; } else if (response.getStatus() != 200) { task.mHttpError = response.getStatus(); int innerHttpError = response.getInnerStatus(); if (innerHttpError != 0) { task.mInnerHttpError = innerHttpError; } } } } else if ((scheme == null || scheme.equals("file"))) { File file = null; try { file = new File(URLDecoder.decode(uri.getEncodedPath(), "UTF-8")); } catch (UnsupportedEncodingException e) { DrmLog.logException(e); } if (file != null && file.exists()) { String header = findHeader(file.getAbsolutePath()); if (header != null && header.length() > 0) { headerString.append(header); } } else { task.mHttpError = Constants.HTTP_ERROR_INTERNAL_ERROR; } } if (headerString.length() > 0) { String header = headerString.toString(); task.mHeader = header; } else if (task.mHttpError != Constants.HTTP_ERROR_INTERNAL_ERROR) { // The file is not a DRM file task.mHttpError = Constants.HTTP_ERROR_UNHANDLED_ERROR_IN_PK; } if (tempFile != null) { if (!(new File(tempFile).delete())) { // it's OK if we couldn't delete the file } } }