Merge changes from topic "Delete RcsMessage code" am: 32f87fc6fb
Change-Id: I19a4c8f9ce6715dae1799d6429c9a61efcc02e25
This commit is contained in:
@@ -20,7 +20,6 @@ import android.compat.annotation.UnsupportedAppUsage;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.drm.DrmConvertedStatus;
|
import android.drm.DrmConvertedStatus;
|
||||||
import android.drm.DrmManagerClient;
|
import android.drm.DrmManagerClient;
|
||||||
import android.provider.Downloads;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@@ -33,6 +32,13 @@ public class DrmConvertSession {
|
|||||||
private int mConvertSessionId;
|
private int mConvertSessionId;
|
||||||
private static final String TAG = "DrmConvertSession";
|
private static final String TAG = "DrmConvertSession";
|
||||||
|
|
||||||
|
// These values are copied from Downloads.Impl.* for backward compatibility since
|
||||||
|
// {@link #close()} that uses it is marked @UnsupportedAppUsage.
|
||||||
|
public static final int STATUS_SUCCESS = 200;
|
||||||
|
public static final int STATUS_NOT_ACCEPTABLE = 406;
|
||||||
|
public static final int STATUS_UNKNOWN_ERROR = 491;
|
||||||
|
public static final int STATUS_FILE_ERROR = 492;
|
||||||
|
|
||||||
private DrmConvertSession(DrmManagerClient drmClient, int convertSessionId) {
|
private DrmConvertSession(DrmManagerClient drmClient, int convertSessionId) {
|
||||||
mDrmClient = drmClient;
|
mDrmClient = drmClient;
|
||||||
mConvertSessionId = convertSessionId;
|
mConvertSessionId = convertSessionId;
|
||||||
@@ -118,38 +124,38 @@ public class DrmConvertSession {
|
|||||||
* Ends a conversion session of a file.
|
* Ends a conversion session of a file.
|
||||||
*
|
*
|
||||||
* @param fileName The filename of the converted file.
|
* @param fileName The filename of the converted file.
|
||||||
* @return Downloads.Impl.STATUS_SUCCESS if execution is ok.
|
* @return STATUS_SUCCESS if execution is ok.
|
||||||
* Downloads.Impl.STATUS_FILE_ERROR in case converted file can not
|
* STATUS_FILE_ERROR in case converted file can not
|
||||||
* be accessed. Downloads.Impl.STATUS_NOT_ACCEPTABLE if a problem
|
* be accessed. STATUS_NOT_ACCEPTABLE if a problem
|
||||||
* occurs when accessing drm framework.
|
* occurs when accessing drm framework.
|
||||||
* Downloads.Impl.STATUS_UNKNOWN_ERROR if a general error occurred.
|
* STATUS_UNKNOWN_ERROR if a general error occurred.
|
||||||
*/
|
*/
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
public int close(String filename) {
|
public int close(String filename) {
|
||||||
DrmConvertedStatus convertedStatus = null;
|
DrmConvertedStatus convertedStatus = null;
|
||||||
int result = Downloads.Impl.STATUS_UNKNOWN_ERROR;
|
int result = STATUS_UNKNOWN_ERROR;
|
||||||
if (mDrmClient != null && mConvertSessionId >= 0) {
|
if (mDrmClient != null && mConvertSessionId >= 0) {
|
||||||
try {
|
try {
|
||||||
convertedStatus = mDrmClient.closeConvertSession(mConvertSessionId);
|
convertedStatus = mDrmClient.closeConvertSession(mConvertSessionId);
|
||||||
if (convertedStatus == null ||
|
if (convertedStatus == null ||
|
||||||
convertedStatus.statusCode != DrmConvertedStatus.STATUS_OK ||
|
convertedStatus.statusCode != DrmConvertedStatus.STATUS_OK ||
|
||||||
convertedStatus.convertedData == null) {
|
convertedStatus.convertedData == null) {
|
||||||
result = Downloads.Impl.STATUS_NOT_ACCEPTABLE;
|
result = STATUS_NOT_ACCEPTABLE;
|
||||||
} else {
|
} else {
|
||||||
RandomAccessFile rndAccessFile = null;
|
RandomAccessFile rndAccessFile = null;
|
||||||
try {
|
try {
|
||||||
rndAccessFile = new RandomAccessFile(filename, "rw");
|
rndAccessFile = new RandomAccessFile(filename, "rw");
|
||||||
rndAccessFile.seek(convertedStatus.offset);
|
rndAccessFile.seek(convertedStatus.offset);
|
||||||
rndAccessFile.write(convertedStatus.convertedData);
|
rndAccessFile.write(convertedStatus.convertedData);
|
||||||
result = Downloads.Impl.STATUS_SUCCESS;
|
result = STATUS_SUCCESS;
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
result = Downloads.Impl.STATUS_FILE_ERROR;
|
result = STATUS_FILE_ERROR;
|
||||||
Log.w(TAG, "File: " + filename + " could not be found.", e);
|
Log.w(TAG, "File: " + filename + " could not be found.", e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
result = Downloads.Impl.STATUS_FILE_ERROR;
|
result = STATUS_FILE_ERROR;
|
||||||
Log.w(TAG, "Could not access File: " + filename + " .", e);
|
Log.w(TAG, "Could not access File: " + filename + " .", e);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
result = Downloads.Impl.STATUS_FILE_ERROR;
|
result = STATUS_FILE_ERROR;
|
||||||
Log.w(TAG, "Could not open file in mode: rw", e);
|
Log.w(TAG, "Could not open file in mode: rw", e);
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
Log.w(TAG, "Access to File: " + filename +
|
Log.w(TAG, "Access to File: " + filename +
|
||||||
@@ -159,7 +165,7 @@ public class DrmConvertSession {
|
|||||||
try {
|
try {
|
||||||
rndAccessFile.close();
|
rndAccessFile.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
result = Downloads.Impl.STATUS_FILE_ERROR;
|
result = STATUS_FILE_ERROR;
|
||||||
Log.w(TAG, "Failed to close File:" + filename
|
Log.w(TAG, "Failed to close File:" + filename
|
||||||
+ ".", e);
|
+ ".", e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user