| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
package com.google.android.mms.util; |
| 19 |
|
| 20 |
import android.compat.annotation.UnsupportedAppUsage; |
| 21 |
import android.content.Context; |
| 22 |
import android.drm.DrmManagerClient; |
| 23 |
import android.os.Build; |
| 24 |
import android.util.Log; |
| 25 |
|
| 26 |
public class DownloadDrmHelper { |
| 27 |
private static final String TAG = "DownloadDrmHelper"; |
| 28 |
|
| 29 |
|
| 30 |
public static final String MIMETYPE_DRM_MESSAGE = "application/vnd.oma.drm.message"; |
| 31 |
|
| 32 |
|
| 33 |
public static final String EXTENSION_DRM_MESSAGE = ".dm"; |
| 34 |
|
| 35 |
public static final String EXTENSION_INTERNAL_FWDL = ".fl"; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public static boolean isDrmMimeType(Context context, String mimetype) { |
| 45 |
boolean result = false; |
| 46 |
if (context != null) { |
| 47 |
try { |
| 48 |
DrmManagerClient drmClient = new DrmManagerClient(context); |
| 49 |
if (drmClient != null && mimetype != null && mimetype.length() > 0) { |
| 50 |
result = drmClient.canHandle("", mimetype); |
| 51 |
} |
| 52 |
} catch (IllegalArgumentException e) { |
| 53 |
Log.w(TAG, |
| 54 |
"DrmManagerClient instance could not be created, context is Illegal."); |
| 55 |
} catch (IllegalStateException e) { |
| 56 |
Log.w(TAG, "DrmManagerClient didn't initialize properly."); |
| 57 |
} |
| 58 |
} |
| 59 |
return result; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
@UnsupportedAppUsage |
| 69 |
public static boolean isDrmConvertNeeded(String mimetype) { |
| 70 |
return MIMETYPE_DRM_MESSAGE.equals(mimetype); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 78 |
public static String modifyDrmFwLockFileExtension(String filename) { |
| 79 |
if (filename != null) { |
| 80 |
int extensionIndex; |
| 81 |
extensionIndex = filename.lastIndexOf("."); |
| 82 |
if (extensionIndex != -1) { |
| 83 |
filename = filename.substring(0, extensionIndex); |
| 84 |
} |
| 85 |
filename = filename.concat(EXTENSION_INTERNAL_FWDL); |
| 86 |
} |
| 87 |
return filename; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public static String getOriginalMimeType(Context context, String path, String containingMime) { |
| 101 |
String result = containingMime; |
| 102 |
DrmManagerClient drmClient = new DrmManagerClient(context); |
| 103 |
try { |
| 104 |
if (drmClient.canHandle(path, null)) { |
| 105 |
result = drmClient.getOriginalMimeType(path); |
| 106 |
} |
| 107 |
} catch (IllegalArgumentException ex) { |
| 108 |
Log.w(TAG, |
| 109 |
"Can't get original mime type since path is null or empty string."); |
| 110 |
} catch (IllegalStateException ex) { |
| 111 |
Log.w(TAG, "DrmManagerClient didn't initialize properly."); |
| 112 |
} |
| 113 |
return result; |
| 114 |
} |
| 115 |
} |