Remove the usage of Downloads.* constants.
Replaced them with local constants as it is only for
internal use.
Test: basic sanity
Bug: 140908357
Merged-in: Icebabc4d16c2e6d5b6e2fb311fee697e8acfa285
Change-Id: Icebabc4d16c2e6d5b6e2fb311fee697e8acfa285
(cherry picked from commit 113d4543ad)
This commit is contained in:
@@ -20,7 +20,6 @@ import android.compat.annotation.UnsupportedAppUsage;
|
||||
import android.content.Context;
|
||||
import android.drm.DrmConvertedStatus;
|
||||
import android.drm.DrmManagerClient;
|
||||
import android.provider.Downloads;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -33,6 +32,13 @@ public class DrmConvertSession {
|
||||
private int mConvertSessionId;
|
||||
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) {
|
||||
mDrmClient = drmClient;
|
||||
mConvertSessionId = convertSessionId;
|
||||
@@ -118,38 +124,38 @@ public class DrmConvertSession {
|
||||
* Ends a conversion session of a file.
|
||||
*
|
||||
* @param fileName The filename of the converted file.
|
||||
* @return Downloads.Impl.STATUS_SUCCESS if execution is ok.
|
||||
* Downloads.Impl.STATUS_FILE_ERROR in case converted file can not
|
||||
* be accessed. Downloads.Impl.STATUS_NOT_ACCEPTABLE if a problem
|
||||
* @return STATUS_SUCCESS if execution is ok.
|
||||
* STATUS_FILE_ERROR in case converted file can not
|
||||
* be accessed. STATUS_NOT_ACCEPTABLE if a problem
|
||||
* occurs when accessing drm framework.
|
||||
* Downloads.Impl.STATUS_UNKNOWN_ERROR if a general error occurred.
|
||||
* STATUS_UNKNOWN_ERROR if a general error occurred.
|
||||
*/
|
||||
@UnsupportedAppUsage
|
||||
public int close(String filename) {
|
||||
DrmConvertedStatus convertedStatus = null;
|
||||
int result = Downloads.Impl.STATUS_UNKNOWN_ERROR;
|
||||
int result = STATUS_UNKNOWN_ERROR;
|
||||
if (mDrmClient != null && mConvertSessionId >= 0) {
|
||||
try {
|
||||
convertedStatus = mDrmClient.closeConvertSession(mConvertSessionId);
|
||||
if (convertedStatus == null ||
|
||||
convertedStatus.statusCode != DrmConvertedStatus.STATUS_OK ||
|
||||
convertedStatus.convertedData == null) {
|
||||
result = Downloads.Impl.STATUS_NOT_ACCEPTABLE;
|
||||
result = STATUS_NOT_ACCEPTABLE;
|
||||
} else {
|
||||
RandomAccessFile rndAccessFile = null;
|
||||
try {
|
||||
rndAccessFile = new RandomAccessFile(filename, "rw");
|
||||
rndAccessFile.seek(convertedStatus.offset);
|
||||
rndAccessFile.write(convertedStatus.convertedData);
|
||||
result = Downloads.Impl.STATUS_SUCCESS;
|
||||
result = STATUS_SUCCESS;
|
||||
} catch (FileNotFoundException e) {
|
||||
result = Downloads.Impl.STATUS_FILE_ERROR;
|
||||
result = STATUS_FILE_ERROR;
|
||||
Log.w(TAG, "File: " + filename + " could not be found.", e);
|
||||
} catch (IOException e) {
|
||||
result = Downloads.Impl.STATUS_FILE_ERROR;
|
||||
result = STATUS_FILE_ERROR;
|
||||
Log.w(TAG, "Could not access File: " + filename + " .", 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);
|
||||
} catch (SecurityException e) {
|
||||
Log.w(TAG, "Access to File: " + filename +
|
||||
@@ -159,7 +165,7 @@ public class DrmConvertSession {
|
||||
try {
|
||||
rndAccessFile.close();
|
||||
} catch (IOException e) {
|
||||
result = Downloads.Impl.STATUS_FILE_ERROR;
|
||||
result = STATUS_FILE_ERROR;
|
||||
Log.w(TAG, "Failed to close File:" + filename
|
||||
+ ".", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user