summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/gallery3d/data')
-rw-r--r--src/com/android/gallery3d/data/DecodeUtils.java22
-rw-r--r--src/com/android/gallery3d/data/ImageCacheRequest.java34
-rw-r--r--src/com/android/gallery3d/data/LocalImage.java38
-rw-r--r--src/com/android/gallery3d/data/LocalVideo.java31
-rw-r--r--src/com/android/gallery3d/data/MediaObject.java13
-rw-r--r--src/com/android/gallery3d/data/UriImage.java56
6 files changed, 171 insertions, 23 deletions
diff --git a/src/com/android/gallery3d/data/DecodeUtils.java b/src/com/android/gallery3d/data/DecodeUtils.java
index 825c4bbea..12405184c 100644
--- a/src/com/android/gallery3d/data/DecodeUtils.java
+++ b/src/com/android/gallery3d/data/DecodeUtils.java
@@ -87,7 +87,7 @@ public class DecodeUtils {
jc.setCancelListener(new DecodeCanceller(options));
setOptionsMutable(options);
return ensureGLCompatibleBitmap(
- BitmapFactory.decodeByteArray(bytes, offset, length, options));
+ BitmapFactory.decodeByteArray(bytes, offset, length, options, false));
}
public static void decodeBounds(JobContext jc, byte[] bytes, int offset,
@@ -95,7 +95,7 @@ public class DecodeUtils {
Utils.assertTrue(options != null);
options.inJustDecodeBounds = true;
jc.setCancelListener(new DecodeCanceller(options));
- BitmapFactory.decodeByteArray(bytes, offset, length, options);
+ BitmapFactory.decodeByteArray(bytes, offset, length, options, false);
options.inJustDecodeBounds = false;
}
@@ -120,7 +120,7 @@ public class DecodeUtils {
jc.setCancelListener(new DecodeCanceller(options));
options.inJustDecodeBounds = true;
- BitmapFactory.decodeFileDescriptor(fd, null, options);
+ BitmapFactory.decodeFileDescriptor(fd, null, options, false);
if (jc.isCancelled()) return null;
int w = options.outWidth;
@@ -148,7 +148,7 @@ public class DecodeUtils {
options.inJustDecodeBounds = false;
setOptionsMutable(options);
- Bitmap result = BitmapFactory.decodeFileDescriptor(fd, null, options);
+ Bitmap result = BitmapFactory.decodeFileDescriptor(fd, null, options, false);
if (result == null) return null;
// We need to resize down if the decoder does not support inSampleSize
@@ -174,7 +174,7 @@ public class DecodeUtils {
jc.setCancelListener(new DecodeCanceller(options));
options.inJustDecodeBounds = true;
- BitmapFactory.decodeByteArray(data, 0, data.length, options);
+ BitmapFactory.decodeByteArray(data, 0, data.length, options, false);
if (jc.isCancelled()) return null;
if (options.outWidth < targetSize || options.outHeight < targetSize) {
return null;
@@ -184,8 +184,16 @@ public class DecodeUtils {
options.inJustDecodeBounds = false;
setOptionsMutable(options);
- return ensureGLCompatibleBitmap(
- BitmapFactory.decodeByteArray(data, 0, data.length, options));
+ Bitmap bitmap = null;
+
+ try {
+ bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options, false);
+
+ } catch (OutOfMemoryError ex) {
+ bitmap = null;
+ Log.e(TAG, "OutOfMemoryError : image is too large");
+ }
+ return ensureGLCompatibleBitmap(bitmap);
}
// TODO: This function should not be called directly from
diff --git a/src/com/android/gallery3d/data/ImageCacheRequest.java b/src/com/android/gallery3d/data/ImageCacheRequest.java
index 6cbc5c5ea..f93f6e28a 100644
--- a/src/com/android/gallery3d/data/ImageCacheRequest.java
+++ b/src/com/android/gallery3d/data/ImageCacheRequest.java
@@ -16,6 +16,9 @@
package com.android.gallery3d.data;
+import android.drm.DrmManagerClient;
+import android.drm.DrmStore.Action;
+import android.drm.DrmStore.RightsStatus;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -32,14 +35,18 @@ abstract class ImageCacheRequest implements Job<Bitmap> {
private Path mPath;
private int mType;
private int mTargetSize;
+ private String mFilePath;
+ private String mMimeType;
private long mTimeModified;
public ImageCacheRequest(GalleryApp application,
- Path path, long timeModified, int type, int targetSize) {
+ Path path, long timeModified, int type, int targetSize, String filePath, String mimetype) {
mApplication = application;
mPath = path;
mType = type;
mTargetSize = targetSize;
+ mFilePath = filePath;
+ mMimeType = mimetype;
mTimeModified = timeModified;
}
@@ -53,6 +60,31 @@ abstract class ImageCacheRequest implements Job<Bitmap> {
public Bitmap run(JobContext jc) {
ImageCacheService cacheService = mApplication.getImageCacheService();
+ if (mFilePath != null && mFilePath.endsWith(".dcf")) {
+ DrmManagerClient drmClient = new DrmManagerClient(mApplication.getAndroidContext());
+ mFilePath = mFilePath.replace("/storage/emulated/0", "/storage/emulated/legacy");
+
+ // This hack is added to work FL. It will remove after the sdcard permission issue solved
+ int statusDisplay = drmClient.checkRightsStatus(mFilePath, Action.DISPLAY);
+ statusDisplay = RightsStatus.RIGHTS_VALID;
+ int statusPlay = drmClient.checkRightsStatus(mFilePath, Action.PLAY);
+ statusPlay = RightsStatus.RIGHTS_VALID;
+
+ if (mMimeType == null) {
+ if ((RightsStatus.RIGHTS_VALID != statusDisplay)
+ && (RightsStatus.RIGHTS_VALID != statusPlay)) {
+ return null;
+ }
+ } else if (mMimeType.startsWith("video/")
+ && RightsStatus.RIGHTS_VALID != statusPlay) {
+ return null;
+ } else if (mMimeType.startsWith("image/")
+ && RightsStatus.RIGHTS_VALID != statusDisplay) {
+ return null;
+ }
+ if (drmClient != null) drmClient.release();
+ }
+
BytesBuffer buffer = MediaItem.getBytesBufferPool().get();
try {
boolean found = cacheService.getImageData(mPath, mTimeModified, mType, buffer);
diff --git a/src/com/android/gallery3d/data/LocalImage.java b/src/com/android/gallery3d/data/LocalImage.java
index 2b01c1e22..32c4880d7 100644
--- a/src/com/android/gallery3d/data/LocalImage.java
+++ b/src/com/android/gallery3d/data/LocalImage.java
@@ -20,6 +20,8 @@ import android.annotation.TargetApi;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
+import android.drm.DrmManagerClient;
+import android.drm.DrmStore.DrmDeliveryType;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapRegionDecoder;
@@ -173,16 +175,16 @@ public class LocalImage extends LocalMediaItem {
@Override
public Job<Bitmap> requestImage(int type) {
return new LocalImageRequest(mApplication, mPath, dateModifiedInSec,
- type, filePath);
+ type, filePath, mimeType);
}
public static class LocalImageRequest extends ImageCacheRequest {
private String mLocalFilePath;
LocalImageRequest(GalleryApp application, Path path, long timeModified,
- int type, String localFilePath) {
+ int type, String localFilePath, String mimetype) {
super(application, path, timeModified, type,
- MediaItem.getTargetSize(type));
+ MediaItem.getTargetSize(type), localFilePath, mimetype);
mLocalFilePath = localFilePath;
}
@@ -236,10 +238,24 @@ public class LocalImage extends LocalMediaItem {
@Override
public int getSupportedOperations() {
- int operation = SUPPORT_DELETE | SUPPORT_SHARE | SUPPORT_CROP
- | SUPPORT_SETAS | SUPPORT_PRINT | SUPPORT_INFO;
+ int operation = SUPPORT_DELETE | SUPPORT_SETAS | SUPPORT_INFO;
+ if (filePath != null && (filePath.endsWith(".dcf") || filePath.endsWith(".dm"))) {
+ filePath = filePath.replace("/storage/emulated/0", "/storage/emulated/legacy");
+ operation |= SUPPORT_DRM_INFO;
+ DrmManagerClient drmClient = new DrmManagerClient(mApplication.getAndroidContext());
+ ContentValues values = drmClient.getMetadata(filePath);
+ int drmType = values.getAsInteger("DRM-TYPE");
+ Log.d(TAG, "getSupportedOperations:drmType returned= "
+ + Integer.toString(drmType) + " for path= " + filePath);
+ if (drmType == DrmDeliveryType.SEPARATE_DELIVERY) {
+ operation |= SUPPORT_SHARE;
+ }
+ if (drmClient != null) drmClient.release();
+ } else {
+ operation |= SUPPORT_SHARE | SUPPORT_EDIT | SUPPORT_CROP | SUPPORT_PRINT;
+ }
if (BitmapUtils.isSupportedByRegionDecoder(mimeType)) {
- operation |= SUPPORT_FULL_IMAGE | SUPPORT_EDIT;
+ operation |= SUPPORT_FULL_IMAGE;
}
if (BitmapUtils.isRotationSupported(mimeType)) {
@@ -347,4 +363,14 @@ public class LocalImage extends LocalMediaItem {
public String getFilePath() {
return filePath;
}
+
+ @Override
+ public void setConsumeRights(boolean flag) {
+ consumeRights = flag;
+ }
+
+ @Override
+ public boolean getConsumeRights() {
+ return consumeRights;
+ }
}
diff --git a/src/com/android/gallery3d/data/LocalVideo.java b/src/com/android/gallery3d/data/LocalVideo.java
index 4b8774ca4..d5e21e983 100644
--- a/src/com/android/gallery3d/data/LocalVideo.java
+++ b/src/com/android/gallery3d/data/LocalVideo.java
@@ -17,7 +17,10 @@
package com.android.gallery3d.data;
import android.content.ContentResolver;
+import android.content.ContentValues;
import android.database.Cursor;
+import android.drm.DrmManagerClient;
+import android.drm.DrmStore.DrmDeliveryType;
import android.graphics.Bitmap;
import android.graphics.BitmapRegionDecoder;
import android.net.Uri;
@@ -152,17 +155,18 @@ public class LocalVideo extends LocalMediaItem {
@Override
public Job<Bitmap> requestImage(int type) {
- return new LocalVideoRequest(mApplication, getPath(), dateModifiedInSec,
- type, filePath);
+ // Drm start
+ return new LocalVideoRequest(mApplication, getPath(), dateModifiedInSec,type, filePath, mimeType);
+ // Drm end
}
public static class LocalVideoRequest extends ImageCacheRequest {
private String mLocalFilePath;
LocalVideoRequest(GalleryApp application, Path path, long timeModified,
- int type, String localFilePath) {
+ int type, String localFilePath, String mimetype) {
super(application, path, timeModified, type,
- MediaItem.getTargetSize(type));
+ MediaItem.getTargetSize(type),localFilePath, mimetype);
mLocalFilePath = localFilePath;
}
@@ -182,7 +186,24 @@ public class LocalVideo extends LocalMediaItem {
@Override
public int getSupportedOperations() {
- return SUPPORT_DELETE | SUPPORT_SHARE | SUPPORT_PLAY | SUPPORT_INFO | SUPPORT_TRIM | SUPPORT_MUTE;
+ int supported = SUPPORT_DELETE | SUPPORT_PLAY | SUPPORT_INFO;
+ if (filePath != null && (filePath.endsWith(".dcf") || filePath.endsWith(".dm"))) {
+ supported |= SUPPORT_DRM_INFO;
+ DrmManagerClient drmClient = new DrmManagerClient(mApplication.getAndroidContext());
+ ContentValues values = drmClient.getMetadata(filePath);
+ int drmType = values.getAsInteger("DRM-TYPE");
+ Log.d("LocalVideo", "getSupportedOperations:drmType returned= "
+ + Integer.toString(drmType) + " for path= " + filePath);
+ if (drmType == DrmDeliveryType.SEPARATE_DELIVERY) {
+ supported |= SUPPORT_SHARE;
+ }
+ if (drmClient != null) drmClient.release();
+ } else {
+ Log.e("LocalVideo", "yy:share added for path= " + filePath);
+ supported |= SUPPORT_SHARE;
+ }
+
+ return supported;
}
@Override
diff --git a/src/com/android/gallery3d/data/MediaObject.java b/src/com/android/gallery3d/data/MediaObject.java
index 530ee306e..68a58ea70 100644
--- a/src/com/android/gallery3d/data/MediaObject.java
+++ b/src/com/android/gallery3d/data/MediaObject.java
@@ -42,12 +42,15 @@ public abstract class MediaObject {
public static final int SUPPORT_CAMERA_SHORTCUT = 1 << 15;
public static final int SUPPORT_MUTE = 1 << 16;
public static final int SUPPORT_PRINT = 1 << 17;
+ public static final int SUPPORT_DRM_INFO = 1 << 18;
public static final int SUPPORT_ALL = 0xffffffff;
// These are the bits returned from getMediaType():
public static final int MEDIA_TYPE_UNKNOWN = 1;
public static final int MEDIA_TYPE_IMAGE = 2;
public static final int MEDIA_TYPE_VIDEO = 4;
+ public static final int MEDIA_TYPE_DRM_VIDEO = 5;
+ public static final int MEDIA_TYPE_DRM_IMAGE = 6;
public static final int MEDIA_TYPE_ALL = MEDIA_TYPE_IMAGE | MEDIA_TYPE_VIDEO;
public static final String MEDIA_TYPE_IMAGE_STRING = "image";
@@ -66,7 +69,7 @@ public abstract class MediaObject {
public static final int CACHE_STATUS_CACHED_FULL = 3;
private static long sVersionSerial = 0;
-
+ protected boolean consumeRights = false;
protected long mDataVersion;
protected final Path mPath;
@@ -145,6 +148,14 @@ public abstract class MediaObject {
throw new UnsupportedOperationException();
}
+ public void setConsumeRights(boolean flag) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean getConsumeRights() {
+ throw new UnsupportedOperationException();
+ }
+
public static synchronized long nextVersionNumber() {
return ++MediaObject.sVersionSerial;
}
diff --git a/src/com/android/gallery3d/data/UriImage.java b/src/com/android/gallery3d/data/UriImage.java
index b3fe1de03..fba34a0b3 100644
--- a/src/com/android/gallery3d/data/UriImage.java
+++ b/src/com/android/gallery3d/data/UriImage.java
@@ -17,12 +17,17 @@
package com.android.gallery3d.data;
import android.content.ContentResolver;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.drm.DrmManagerClient;
+import android.drm.DrmStore.DrmDeliveryType;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory.Options;
import android.graphics.BitmapRegionDecoder;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
+import android.provider.MediaStore.Video.VideoColumns;
import com.android.gallery3d.app.GalleryApp;
import com.android.gallery3d.app.PanoramaMetadataSupport;
@@ -211,10 +216,45 @@ public class UriImage extends MediaItem {
@Override
public int getSupportedOperations() {
- int supported = SUPPORT_PRINT | SUPPORT_SETAS;
- if (isSharable()) supported |= SUPPORT_SHARE;
+ int supported = SUPPORT_SETAS;
+ String filePath = null;
+ String scheme = mUri.getScheme();
+ if ("file".equals(scheme)) {
+ filePath = mUri.getPath();
+ } else {
+ Cursor cursor = null;
+ try {
+ cursor = mApplication.getContentResolver().query(mUri,
+ new String[] {VideoColumns.DATA}, null, null, null);
+ if (cursor != null && cursor.moveToNext()) {
+ filePath = cursor.getString(0);
+ }
+ } catch (Throwable t) {
+ Log.w(TAG, "cannot get path from: " + mUri);
+ } finally {
+ if (cursor != null) cursor.close();
+ }
+ }
+
+ if (filePath != null && (filePath.endsWith(".dcf") || filePath.endsWith(".dm"))) {
+ supported |= SUPPORT_DRM_INFO;
+ filePath = filePath.replace("/storage/emulated/0", "/storage/emulated/legacy");
+ DrmManagerClient drmClient = new DrmManagerClient(mApplication.getAndroidContext());
+ ContentValues values = drmClient.getMetadata(filePath);
+ int drmType = values.getAsInteger("DRM-TYPE");
+ Log.d(TAG, "getSupportedOperations:drmType returned= "
+ + Integer.toString(drmType) + " for path= " + filePath);
+ if (drmType == DrmDeliveryType.SEPARATE_DELIVERY) {
+ if (isSharable()) supported |= SUPPORT_SHARE;
+ }
+ if (drmClient != null) drmClient.release();
+ } else {
+ supported |= SUPPORT_EDIT | SUPPORT_PRINT;
+ if (isSharable()) supported |= SUPPORT_SHARE;
+ }
+
if (BitmapUtils.isSupportedByRegionDecoder(mContentType)) {
- supported |= SUPPORT_EDIT | SUPPORT_FULL_IMAGE;
+ supported |= SUPPORT_FULL_IMAGE;
}
return supported;
}
@@ -295,4 +335,14 @@ public class UriImage extends MediaItem {
public int getRotation() {
return mRotation;
}
+
+ @Override
+ public void setConsumeRights(boolean flag) {
+ consumeRights = flag;
+ }
+
+ @Override
+ public boolean getConsumeRights() {
+ return consumeRights;
+ }
}