summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/gallery3d/app')
-rw-r--r--src/com/android/gallery3d/app/AlbumPage.java115
-rw-r--r--src/com/android/gallery3d/app/AlbumSetPage.java79
-rw-r--r--src/com/android/gallery3d/app/GalleryActivity.java82
-rw-r--r--src/com/android/gallery3d/app/MovieActivity.java47
-rwxr-xr-xsrc/com/android/gallery3d/app/PhotoDataAdapter.java6
-rwxr-xr-xsrc/com/android/gallery3d/app/PhotoPage.java201
-rw-r--r--src/com/android/gallery3d/app/SlideshowPage.java16
-rw-r--r--src/com/android/gallery3d/app/Wallpaper.java1
8 files changed, 74 insertions, 473 deletions
diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java
index d0056fcfd..629e88210 100644
--- a/src/com/android/gallery3d/app/AlbumPage.java
+++ b/src/com/android/gallery3d/app/AlbumPage.java
@@ -18,24 +18,14 @@ package com.android.gallery3d.app;
import android.app.Activity;
import android.content.Context;
-import android.content.ContentValues;
import android.content.Intent;
-import android.database.Cursor;
-import android.drm.DrmManagerClientWrapper;
-import android.drm.DrmRights;
-import android.drm.DrmStore.Action;
-import android.drm.DrmStore.DrmDeliveryType;
-import android.drm.DrmStore.RightsStatus;
-import android.graphics.BitmapFactory;
-import android.graphics.BitmapFactory.Options;
+import android.drm.DrmHelper;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
-import android.provider.MediaStore.Video.VideoColumns;
-import android.text.TextUtils;
import android.text.TextUtils;
import android.view.HapticFeedbackConstants;
import android.view.Menu;
@@ -47,7 +37,6 @@ import android.widget.Toast;
import com.android.gallery3d.R;
import com.android.gallery3d.common.Utils;
import com.android.gallery3d.data.DataManager;
-import com.android.gallery3d.data.LocalMediaItem;
import com.android.gallery3d.data.MediaDetails;
import com.android.gallery3d.data.MediaItem;
import com.android.gallery3d.data.MediaObject;
@@ -74,20 +63,12 @@ import com.android.gallery3d.util.GalleryUtils;
import com.android.gallery3d.util.MediaSetUtils;
import java.util.Locale;
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Random;
-
public class AlbumPage extends ActivityState implements GalleryActionBar.ClusterRunner,
SelectionManager.SelectionListener, MediaSet.SyncListener, GalleryActionBar.OnAlbumModeSelectedListener {
@SuppressWarnings("unused")
private static final String TAG = "AlbumPage";
- public static final String BUY_LICENSE = "android.drmservice.intent.action.BUY_LICENSE";
-
public static final String KEY_MEDIA_PATH = "media-path";
public static final String KEY_PARENT_MEDIA_PATH = "parent-media-path";
public static final String KEY_SET_CENTER = "set-center";
@@ -121,8 +102,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
private boolean mGetContent;
private boolean mShowClusterMenu;
- private boolean mIsWallpaper;
- private boolean mIsContactPhoto;
+
private ActionModeHandler mActionModeHandler;
private int mFocusIndex = 0;
private DetailsHelper mDetailsHelper;
@@ -331,6 +311,12 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
if (isLayoutRtl && item == null) {
return; // Item not ready yet, ignore the click
}
+ if (DrmHelper.isDrmFile(DrmHelper.getFilePath(
+ mActivity.getAndroidContext(), item.getContentUri()))) {
+ Toast.makeText(mActivity, R.string.no_permission_for_drm,
+ Toast.LENGTH_SHORT).show();
+ return;
+ }
onGetContent(item);
} else if (mLaunchedFromPhotoPage) {
if (isLayoutRtl && item == null) {
@@ -343,65 +329,6 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
transitions.put(PhotoPage.KEY_INDEX_HINT, slotIndex);
onBackPressed();
} else {
- Context context = (Context) mActivity;
- Uri uri = item.getContentUri();
- Log.d(TAG, "pickPhoto:uri=" + item.getContentUri());
- String path = null;
- String scheme = uri.getScheme();
- if ("file".equals(scheme)) {
- path = uri.getPath();
- } else {
- Cursor cursor = null;
- try {
- cursor = context.getContentResolver().query(uri,
- new String[] {VideoColumns.DATA}, null, null, null);
- if (cursor != null && cursor.moveToNext()) {
- path = cursor.getString(0);
- }
- } catch (Throwable t) {
- Log.d(TAG, "cannot get path from: " + uri);
- } finally {
- if (cursor != null) cursor.close();
- }
- }
-
- Log.d(TAG, "pickPhoto:path = " + path);
- if (path != null && (path.endsWith(".dcf") || path.endsWith(".dm"))) {
- DrmManagerClientWrapper drmClient = new DrmManagerClientWrapper(context);
- path = path.replace("/storage/emulated/0", "/storage/emulated/legacy");
- int status = -1;
- Log.d(TAG, "pickPhoto:item type = " + Integer.toString(item.getMediaType()));
-
- if (item.getMediaType() == MediaObject.MEDIA_TYPE_IMAGE) {
- status = drmClient.checkRightsStatus(path, Action.DISPLAY);
- } else {
- status = drmClient.checkRightsStatus(path, Action.PLAY);
- }
- Log.d(TAG, "pickPhoto:status fron drmClient.checkRightsStatus is "
- + Integer.toString(status));
-
- ContentValues values = drmClient.getMetadata(path);
- if (RightsStatus.RIGHTS_VALID!= status) {
- String address = values.getAsString("Rights-Issuer");
- Log.d(TAG, "pickPhoto:address = " + address);
- Intent intent = new Intent(BUY_LICENSE);
- intent.putExtra("DRM_FILE_PATH", address);
- context.sendBroadcast(intent);
- return;
- }
-
- int drmType = values.getAsInteger("DRM-TYPE");
- Log.d(TAG, "onSingleTapUp:drm-type = " + Integer.toString(drmType));
- if (drmType > DrmDeliveryType.FORWARD_LOCK) {
- if (item.getMediaType() == MediaObject.MEDIA_TYPE_IMAGE) {
- item.setConsumeRights(true);
- }
- Toast.makeText(context, R.string.action_consumes_rights,
- Toast.LENGTH_LONG).show();
- }
- if (drmClient != null) drmClient.release();
- }
-
// Get into the PhotoPage.
// mAlbumView.savePositions(PositionRepository.getInstance(mActivity));
Bundle data = new Bundle();
@@ -435,7 +362,6 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
Activity activity = mActivity;
if (mData.getString(GalleryActivity.EXTRA_CROP) != null) {
Uri uri = dm.getContentUri(item.getPath());
-
Intent intent = new Intent(CropActivity.CROP_ACTION, uri)
.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT)
.putExtras(getData());
@@ -444,29 +370,6 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
}
activity.startActivity(intent);
activity.finish();
- } else if (mIsWallpaper != true && mIsContactPhoto != true) {
- String path = null;
- if (item instanceof LocalMediaItem) {
- path = ((LocalMediaItem)item).filePath;
- }
- if (path != null && (path.endsWith(".dcf") || path.endsWith(".dm"))) {
- DrmManagerClientWrapper drmClient = new DrmManagerClientWrapper((Context) mActivity);
- path = path.replace("/storage/emulated/0", "/storage/emulated/legacy");
- ContentValues values = drmClient.getMetadata(path);
- int drmType = values.getAsInteger("DRM-TYPE");
- Log.d(TAG, "onGetContent:DRM-TYPE = " + Integer.toString(drmType));
- if (drmType == DrmDeliveryType.SEPARATE_DELIVERY) {
- activity.setResult(Activity.RESULT_OK, new Intent(null, item.getContentUri()));
- } else {
- Toast.makeText((Context) mActivity, R.string.no_permission_for_drm,
- Toast.LENGTH_LONG).show();
- }
- if (drmClient != null) drmClient.release();
- } else {
- activity.setResult(Activity.RESULT_OK,
- new Intent(null, item.getContentUri()));
- }
- activity.finish();
} else {
Intent intent = new Intent(null, item.getContentUri())
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
@@ -509,8 +412,6 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
initializeViews();
initializeData(data);
mGetContent = data.getBoolean(GalleryActivity.KEY_GET_CONTENT, false);
- mIsWallpaper = data.getBoolean("com.android.gallery3d.IsWallpaper", false);
- mIsContactPhoto = data.getBoolean("isContactPhoto", false);
mShowClusterMenu = data.getBoolean(KEY_SHOW_CLUSTER_MENU, false);
mDetailsSource = new MyDetailsSource();
Context context = mActivity.getAndroidContext();
diff --git a/src/com/android/gallery3d/app/AlbumSetPage.java b/src/com/android/gallery3d/app/AlbumSetPage.java
index 5e100498c..c09b91f6e 100644
--- a/src/com/android/gallery3d/app/AlbumSetPage.java
+++ b/src/com/android/gallery3d/app/AlbumSetPage.java
@@ -21,21 +21,12 @@ package com.android.gallery3d.app;
import android.app.Activity;
import android.content.Context;
-import android.content.ContentValues;
import android.content.Intent;
-import android.database.Cursor;
-import android.drm.DrmManagerClientWrapper;
-import android.drm.DrmRights;
-import android.drm.DrmStore.Action;
-import android.drm.DrmStore.DrmDeliveryType;
-import android.drm.DrmStore.RightsStatus;
import android.graphics.Rect;
import android.net.Uri;
-import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
-import android.provider.MediaStore.Video.VideoColumns;
import android.view.HapticFeedbackConstants;
import android.view.Menu;
import android.view.MenuInflater;
@@ -72,13 +63,8 @@ import com.android.gallery3d.util.Future;
import com.android.gallery3d.util.GalleryUtils;
import com.android.gallery3d.util.HelpUtils;
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
-import java.util.Random;
public class AlbumSetPage extends ActivityState implements
SelectionManager.SelectionListener, GalleryActionBar.ClusterRunner,
@@ -88,8 +74,6 @@ public class AlbumSetPage extends ActivityState implements
private static final int MSG_PICK_ALBUM = 1;
- public static final String BUY_LICENSE = "android.drmservice.intent.action.BUY_LICENSE";
-
public static final String KEY_MEDIA_PATH = "media-path";
public static final String KEY_SET_TITLE = "set-title";
public static final String KEY_SET_SUBTITLE = "set-subtitle";
@@ -258,69 +242,6 @@ public class AlbumSetPage extends ActivityState implements
if (!mIsActive) return;
MediaSet targetSet = mAlbumSetDataAdapter.getMediaSet(slotIndex);
- if (targetSet.getTotalMediaItemCount() == 1) {
- MediaItem item = null;
- item = targetSet.getCoverMediaItem();
- Uri uri = item.getContentUri();
- Context context = (Context) mActivity;
-
- Log.d(TAG, "pickAlbum:uri=" + item.getContentUri());
- String path = null;
- String scheme = uri.getScheme();
- if ("file".equals(scheme)) {
- path = uri.getPath();
- } else {
- Cursor cursor = null;
- try {
- cursor = context.getContentResolver().query(uri,
- new String[] {VideoColumns.DATA}, null, null, null);
- if (cursor != null && cursor.moveToNext()) {
- path = cursor.getString(0);
- }
- } catch (Throwable t) {
- Log.w(TAG, "cannot get path from: " + uri);
- } finally {
- if (cursor != null) cursor.close();
- }
- }
-
- Log.d(TAG, "pickAlbum:path = " + path);
- if (path != null && (path.endsWith(".dcf") || path.endsWith(".dm"))) {
- DrmManagerClientWrapper drmClient = new DrmManagerClientWrapper(context);
- int status = -1;
- path = path.replace("/storage/emulated/0", "/storage/emulated/legacy");
- Log.d(TAG, "pickAlbum:item type = " + Integer.toString(item.getMediaType()));
- if (item.getMediaType() == MediaObject.MEDIA_TYPE_IMAGE) {
- status = drmClient.checkRightsStatus(path, Action.DISPLAY);
- } else {
- status = drmClient.checkRightsStatus(path, Action.PLAY);
- }
- Log.d(TAG, "pickAlbum:status fron drmClient.checkRightsStatus is "
- + Integer.toString(status));
-
- ContentValues values = drmClient.getMetadata(path);
-
- if (RightsStatus.RIGHTS_VALID != status) {
- String address = values.getAsString("Rights-Issuer");
- Log.d(TAG, "pickAlbum:address = " + address);
- Intent intent = new Intent(BUY_LICENSE);
- intent.putExtra("DRM_FILE_PATH", address);
- context.sendBroadcast(intent);
- return;
- }
-
- int drmType = values.getAsInteger("DRM-TYPE");
- Log.d(TAG, "pickAlbum:drm-type = " + Integer.toString(drmType));
- if (drmType > DrmDeliveryType.FORWARD_LOCK) {
- if (item.getMediaType() == MediaObject.MEDIA_TYPE_IMAGE) {
- item.setConsumeRights(true);
- }
- Toast.makeText(context, R.string.action_consumes_rights,
- Toast.LENGTH_LONG).show();
- }
- if (drmClient != null) drmClient.release();
- }
- }
if (targetSet == null) return; // Content is dirty, we shall reload soon
if (targetSet.getTotalMediaItemCount() == 0) {
showEmptyAlbumToast(Toast.LENGTH_SHORT);
diff --git a/src/com/android/gallery3d/app/GalleryActivity.java b/src/com/android/gallery3d/app/GalleryActivity.java
index d918e1457..1be5e73c8 100644
--- a/src/com/android/gallery3d/app/GalleryActivity.java
+++ b/src/com/android/gallery3d/app/GalleryActivity.java
@@ -18,19 +18,11 @@ package com.android.gallery3d.app;
import android.app.Dialog;
import android.content.ContentResolver;
-import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
-import android.database.Cursor;
-import android.drm.DrmManagerClient;
-import android.drm.DrmManagerClientWrapper;
-import android.drm.DrmStore.Action;
-import android.drm.DrmStore.DrmDeliveryType;
-import android.drm.DrmStore.RightsStatus;
import android.net.Uri;
import android.os.Bundle;
-import android.provider.MediaStore.Video.VideoColumns;
import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.View;
@@ -42,14 +34,12 @@ import com.android.gallery3d.R;
import com.android.gallery3d.common.Utils;
import com.android.gallery3d.data.DataManager;
import com.android.gallery3d.data.MediaItem;
-import com.android.gallery3d.data.MediaObject;
import com.android.gallery3d.data.MediaSet;
import com.android.gallery3d.data.Path;
import com.android.gallery3d.picasasource.PicasaSource;
import com.android.gallery3d.util.GalleryUtils;
public final class GalleryActivity extends AbstractGalleryActivity implements OnCancelListener {
- public static final String BUY_LICENSE = "android.drmservice.intent.action.BUY_LICENSE";
public static final String EXTRA_SLIDESHOW = "slideshow";
public static final String EXTRA_DREAM = "dream";
public static final String EXTRA_CROP = "crop";
@@ -213,77 +203,7 @@ public final class GalleryActivity extends AbstractGalleryActivity implements On
startDefaultPage();
}
} else {
- Path itemPath = null;
- String imagePath = null;
- String scheme = uri.getScheme();
- if ("file".equals(scheme)) {
- imagePath = uri.getPath();
- } else {
- Cursor cursor = null;
- try {
- cursor = this.getContentResolver().query(uri,
- new String[] {VideoColumns.DATA}, null, null, null);
- if (cursor != null && cursor.moveToNext()) {
- imagePath = cursor.getString(0);
- }
- } catch (Throwable t) {
- Log.d(TAG, "cannot get path from: " + uri);
- } finally {
- if (cursor != null) cursor.close();
- }
- }
- String mime_Type = intent.getType();
- if (imagePath != null
- && (imagePath.endsWith(".dcf") || imagePath.endsWith(".dm"))
- && "*/*".equals(mime_Type)) {
- imagePath = imagePath.replace("/storage/emulated/0", "/storage/emulated/legacy");
- DrmManagerClient drmClient = new DrmManagerClient(this);
- mime_Type = drmClient.getOriginalMimeType(imagePath);
- if (drmClient != null) drmClient.release();
- }
-
- Log.d(TAG, "DRM mime_Type==" + mime_Type);
- itemPath = getDataManager().findPathByUri(uri, mime_Type);
- Log.d(TAG, "itemPath=" + itemPath);
- // If item path not correct, just finish starting the gallery
- if (itemPath == null) {
- finish();
- return;
- }
-
- Log.d(TAG,"imagePath=" + imagePath);
- if (intent.getBooleanExtra("WidgetClick", false) == true) {
- DrmManagerClientWrapper drmClient = new DrmManagerClientWrapper(this);
- int status = drmClient.checkRightsStatus(imagePath, Action.DISPLAY);
- if (RightsStatus.RIGHTS_VALID != status) {
- ContentValues values = drmClient.getMetadata(imagePath);
- String address = values.getAsString("Rights-Issuer");
- Intent buyIntent = new Intent(BUY_LICENSE);
- buyIntent.putExtra("DRM_FILE_PATH", address);
- sendBroadcast(buyIntent);
- Log.d(TAG, "startViewAction:WidgetClick, intent sent");
- }
- if (drmClient != null) drmClient.release();
- }
-
- if (imagePath != null
- && (imagePath.endsWith(".dcf") || imagePath.endsWith(".dm"))) {
- DrmManagerClientWrapper drmClient = new DrmManagerClientWrapper(this);
- imagePath = imagePath.replace("/storage/emulated/0", "/storage/emulated/legacy");
- ContentValues values = drmClient.getMetadata(imagePath);
- int drmType = values.getAsInteger("DRM-TYPE");
- if (drmType > DrmDeliveryType.FORWARD_LOCK) {
- MediaItem mediaItem = (MediaItem) getDataManager()
- .getMediaObject(itemPath);
- if (mediaItem.getMediaType() == MediaObject.MEDIA_TYPE_IMAGE) {
- mediaItem.setConsumeRights(true);
- }
- Toast.makeText(this, R.string.action_consumes_rights,
- Toast.LENGTH_LONG).show();
- }
- if (drmClient != null) drmClient.release();
- }
-
+ Path itemPath = dm.findPathByUri(uri, contentType);
Path albumPath = dm.getDefaultSetOf(itemPath);
data.putString(PhotoPage.KEY_MEDIA_ITEM_PATH, itemPath.toString());
diff --git a/src/com/android/gallery3d/app/MovieActivity.java b/src/com/android/gallery3d/app/MovieActivity.java
index 0943195a7..f6fcaf87c 100644
--- a/src/com/android/gallery3d/app/MovieActivity.java
+++ b/src/com/android/gallery3d/app/MovieActivity.java
@@ -27,9 +27,6 @@ import android.bluetooth.BluetoothDevice;
import android.content.AsyncQueryHandler;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
-import android.content.ContentValues;
-import android.content.Context;
-import android.content.DialogInterface;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@@ -38,8 +35,7 @@ import android.content.res.Configuration;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.database.Cursor;
-import android.drm.DrmManagerClientWrapper;
-import android.drm.DrmStore.DrmDeliveryType;
+import android.drm.DrmHelper;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.media.AudioManager;
@@ -53,7 +49,6 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
-import android.provider.MediaStore.Video.VideoColumns;
import android.provider.OpenableColumns;
import android.view.Gravity;
import android.view.KeyEvent;
@@ -245,6 +240,16 @@ public class MovieActivity extends Activity {
initEffects(mp.getAudioSessionId());
}
});
+
+ // DRM validation
+ Uri original = intent.getData();
+ String mimeType = intent.getType();
+ String filepath = DrmHelper.getFilePath(this, original);
+ if (DrmHelper.isDrmFile(filepath)) {
+ if (!DrmHelper.validateLicense(this, filepath, mimeType)) {
+ finish();
+ }
+ }
}
private void setActionBarLogoFromIntent(Intent intent) {
@@ -312,36 +317,6 @@ public class MovieActivity extends Activity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
- String path = null;
- String scheme = mUri.getScheme();
- if ("file".equals(scheme)) {
- path = mUri.getPath();
- } else {
- Cursor cursor = null;
- try {
- cursor = getContentResolver().query(mUri,
- new String[] {VideoColumns.DATA}, null, null, null);
- if (cursor != null && cursor.moveToNext()) {
- path = cursor.getString(0);
- }
- } catch (Throwable t) {
- Log.d(TAG, "cannot get path from: " + mUri);
- } finally {
- if (cursor != null) cursor.close();
- }
- }
- Log.d(TAG, "onCreateOptionsMenu= " + path);
- if ((path != null) && ((path.endsWith(".dcf") || path.endsWith(".dm")))) {
- DrmManagerClientWrapper drmClient = new DrmManagerClientWrapper(this);
- ContentValues values = drmClient.getMetadata(path);
- int drmType = values.getAsInteger("DRM-TYPE");
- Log.d(TAG, "onCreateOptionsMenu:DRM-TYPE = " + Integer.toString(drmType));
- if (drmType != DrmDeliveryType.SEPARATE_DELIVERY) {
- return true;
- }
- if (drmClient != null) drmClient.release();
- }
-
getMenuInflater().inflate(R.menu.movie, menu);
MenuItem shareMenu = menu.findItem(R.id.action_share);
ShareActionProvider provider = (ShareActionProvider) shareMenu.getActionProvider();
diff --git a/src/com/android/gallery3d/app/PhotoDataAdapter.java b/src/com/android/gallery3d/app/PhotoDataAdapter.java
index 4322d9b7a..5812bf82d 100755
--- a/src/com/android/gallery3d/app/PhotoDataAdapter.java
+++ b/src/com/android/gallery3d/app/PhotoDataAdapter.java
@@ -522,9 +522,9 @@ public class PhotoDataAdapter implements PhotoPage.Model {
@Override
public boolean isVideo(int offset) {
MediaItem item = getItem(mCurrentIndex + offset);
- return (item == null)
- ? false
- : item.getMediaType() == MediaItem.MEDIA_TYPE_VIDEO;
+ return (item == null) ? false
+ : item.getMediaType() == MediaItem.MEDIA_TYPE_VIDEO
+ || item.getMediaType() == MediaItem.MEDIA_TYPE_DRM_VIDEO;
}
@Override
diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java
index 7bc9c9d4f..65c26278a 100755
--- a/src/com/android/gallery3d/app/PhotoPage.java
+++ b/src/com/android/gallery3d/app/PhotoPage.java
@@ -20,18 +20,11 @@ import android.annotation.TargetApi;
import android.app.ActionBar.OnMenuVisibilityListener;
import android.app.Activity;
import android.content.ActivityNotFoundException;
-import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
-import android.database.Cursor;
-import android.drm.DrmManagerClientWrapper;
-import android.drm.DrmStore.Action;
-import android.drm.DrmStore.DrmDeliveryType;
-import android.drm.DrmStore.RightsStatus;
-import android.graphics.BitmapFactory;
-import android.graphics.BitmapFactory.Options;
+import android.drm.DrmHelper;
import android.graphics.Rect;
import android.media.MediaFile;
import android.net.Uri;
@@ -42,8 +35,6 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
-import android.provider.MediaStore;
-import android.provider.MediaStore.Video.VideoColumns;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
@@ -54,7 +45,6 @@ import android.widget.Toast;
import com.android.gallery3d.R;
import com.android.gallery3d.common.ApiHelper;
-import com.android.gallery3d.common.Utils;
import com.android.gallery3d.data.ComboAlbum;
import com.android.gallery3d.data.DataManager;
import com.android.gallery3d.data.FilterDeleteSet;
@@ -87,11 +77,6 @@ import com.android.gallery3d.util.GalleryUtils;
import com.android.gallery3d.util.UsageStatistics;
import com.android.gallery3d.util.ViewGifImage;
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.IOException;
-
import java.util.ArrayList;
import java.util.Locale;
@@ -100,8 +85,6 @@ public abstract class PhotoPage extends ActivityState implements
PhotoPageBottomControls.Delegate, GalleryActionBar.OnAlbumModeSelectedListener {
private static final String TAG = "PhotoPage";
- public static final String BUY_LICENSE = "android.drmservice.intent.action.BUY_LICENSE";
-
private static final int MSG_HIDE_BARS = 1;
private static final int MSG_ON_FULL_SCREEN_CHANGED = 4;
private static final int MSG_UPDATE_ACTION_BAR = 5;
@@ -590,16 +573,6 @@ public abstract class PhotoPage extends ActivityState implements
PhotoPage.this);
}
}
- MediaItem item = mModel.getMediaItem(0);
- if (item != null
- && item.getMediaType() == MediaObject.MEDIA_TYPE_IMAGE
- && item.getConsumeRights() == true) {
- Log.d(TAG, "onDestroy,consume rights = true");
- item.setConsumeRights(false);
- Uri uri = item.getContentUri();
- Log.d(TAG, "onDestroy:uri=" + uri);
- consumeRights(uri);
- }
}
@Override
@@ -639,40 +612,6 @@ public abstract class PhotoPage extends ActivityState implements
});
}
- private void consumeRights(Uri uri) {
- Log.d(TAG, "consumeRights:uri=" + uri);
- String filepath = null;
- String scheme = uri.getScheme();
- if ("file".equals(scheme)) {
- filepath = uri.getPath();
- } else {
- Cursor cursor = null;
- try {
- cursor = mActivity.getContentResolver().query(uri,
- 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: " + uri);
- } finally {
- if (cursor != null) cursor.close();
- }
- }
- Options options = new Options();
- FileInputStream fis = null;
- try {
- fis = new FileInputStream(new File(filepath));
- FileDescriptor fd = fis.getFD();
- Log.d(TAG, "onLoadingFinished:calling decodeFileDescriptor with true");
- BitmapFactory.decodeFileDescriptor(fd, new Rect(), options, true);
- } catch(IOException e) {
- Log.w(TAG, "IOException");
- } finally {
- Utils.closeSilently(fis);
- }
- }
-
@Override
public void onPictureCenter(boolean isCamera) {
isCamera = isCamera || (mHasCameraScreennailOrPlaceholder && mAppBridge == null);
@@ -748,40 +687,6 @@ public abstract class PhotoPage extends ActivityState implements
private Intent createShareIntent(MediaObject mediaObject) {
int type = mediaObject.getMediaType();
- Uri uri = mediaObject.getContentUri();
- Log.d(TAG, "updateShareURI:uri:" + uri);
- String filepath = null;
- String scheme = uri.getScheme();
- if ("file".equals(scheme)) {
- filepath = uri.getPath();
- } else {
- Cursor cursor = null;
- try {
- cursor = mApplication.getContentResolver().query(uri,
- 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: " + uri);
- } finally {
- if (cursor != null) cursor.close();
- }
- }
-
- if (filepath != null && filepath.endsWith(".dcf")) {
- DrmManagerClientWrapper drmClient = new DrmManagerClientWrapper(mActivity.getAndroidContext());
- filepath = filepath.replace("/storage/emulated/0", "/storage/emulated/legacy");
- ContentValues values = drmClient.getMetadata(filepath);
- int drmType = values.getAsInteger("DRM-TYPE");
- Log.d(TAG, "updateShareURI:drmType returned= " + Integer.toString(drmType)
- + " for path= " + filepath);
- if (drmType != DrmDeliveryType.SEPARATE_DELIVERY) {
- return null;
- }
- if (drmClient != null) drmClient.release();
- }
-
return new Intent(Intent.ACTION_SEND)
.setType(MenuExecutor.getMimeType(type))
.putExtra(Intent.EXTRA_STREAM, mediaObject.getContentUri())
@@ -899,6 +804,20 @@ public abstract class PhotoPage extends ActivityState implements
requestDeferredUpdate();
} else {
updateUIForCurrentPhoto();
+
+ // Manage DRM rights while image selection changed. this
+ // flow will comes for both image and video, but here
+ // we will consume rights for image files only.
+ // Do not consume rights of a GIF image and video here.
+ // ViewGifImage will take care of GIF rights consumption stub.
+ // MediaPlayer will handle the video rights consumption stub.
+ String mime = mCurrentPhoto.getMimeType();
+ if (!TextUtils.isEmpty(mime) && !mime.equals("image/gif")
+ && !mime.startsWith("video/")) {
+ DrmHelper.manageDrmLicense(mActivity.getAndroidContext(),
+ mHandler, mCurrentPhoto.getFilePath(),
+ mCurrentPhoto.getMimeType());
+ }
}
}
@@ -1255,32 +1174,10 @@ public abstract class PhotoPage extends ActivityState implements
mMenuExecutor.onMenuClicked(item, confirmMsg, mConfirmDialogListener);
return true;
case R.id.action_drm_info:
- Uri uri = manager.getContentUri(path);
- Log.d(TAG, "executeuri:" + uri);
- String filepath = null;
- String scheme = uri.getScheme();
- if ("file".equals(scheme)) {
- filepath = uri.getPath();
- } else {
- Cursor cursor = null;
- try {
- cursor = mActivity.getAndroidContext().getContentResolver().query(uri,
- 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: " + uri);
- } finally {
- if (cursor != null) cursor.close();
- }
+ String filepath = current.getFilePath();
+ if (DrmHelper.isDrmFile(filepath)) {
+ DrmHelper.showDrmInfo(mActivity.getAndroidContext(), filepath);
}
- filepath = filepath.replace("/storage/emulated/0", "/storage/emulated/legacy");
- Intent drmintent = new Intent("android.drmservice.intent.action.SHOW_PROPERTIES");
- drmintent.putExtra("DRM_FILE_PATH", filepath);
- drmintent.putExtra("DRM_TYPE", "OMAV1");
- Log.d(TAG,"-----filepath===" + path);
- mActivity.getAndroidContext().sendBroadcast(drmintent);
return true;
default :
return false;
@@ -1417,37 +1314,6 @@ public abstract class PhotoPage extends ActivityState implements
public void playVideo(Activity activity, Uri uri, String title) {
try {
- String scheme = uri.getScheme();
- Log.d(TAG, "playVideo:uri= " + uri);
- String path = null;
- if (scheme.equals("content")) {
- Cursor c = activity.getContentResolver().query(uri,
- new String[] { MediaStore.Images.ImageColumns.DATA }, null, null, null);
- if (c != null && c.getCount() > 0) {
- c.moveToFirst();
- path = c.getString(c.getColumnIndex(MediaStore.Images.ImageColumns.DATA));
- Log.d(TAG, "playVideo:path= " + path);
- }
- if (c != null) c.close();
- } else {
- path = uri.getPath();
- }
- if (path.endsWith(".dcf")) {
- DrmManagerClientWrapper drmClient = new DrmManagerClientWrapper(activity);
- path = path.replace("/storage/emulated/0", "/storage/emulated/legacy");
- int status = drmClient.checkRightsStatus(path, Action.PLAY);
- if (RightsStatus.RIGHTS_VALID != status) {
- ContentValues values = drmClient.getMetadata(path);
- String address = values.getAsString("Rights-Issuer");
- Log.d(TAG, "playVideo, address= " + address);
- Intent intent = new Intent(BUY_LICENSE);
- intent.putExtra("DRM_FILE_PATH", address);
- activity.sendBroadcast(intent);
- return;
- }
- if (drmClient != null) drmClient.release();
- }
-
Intent intent = new Intent(Intent.ACTION_VIEW)
.setDataAndType(uri, "video/*")
.putExtra(Intent.EXTRA_TITLE, title)
@@ -1552,17 +1418,6 @@ public abstract class PhotoPage extends ActivityState implements
@Override
public void onCurrentImageUpdated() {
- if (mSetPathString == null) {
- MediaItem item = mModel.getMediaItem(0);
- if (item.getMediaType() == MediaObject.MEDIA_TYPE_IMAGE
- && item.getConsumeRights() == true) {
- Log.d(TAG, "onCurrentImageUpdated,consume rights = true");
- item.setConsumeRights(false);
- Uri uri = item.getContentUri();
- Log.d(TAG, "onCurrentImageUpdated:uri=" + uri);
- consumeRights(uri);
- }
- }
mActivity.getGLRoot().unfreeze();
}
@@ -1590,6 +1445,23 @@ public abstract class PhotoPage extends ActivityState implements
UsageStatistics.onContentViewChanged(
UsageStatistics.COMPONENT_CAMERA, "Unknown"); // TODO
}
+
+ // Manage DRM rights while image selection changed. this
+ // flow will comes for both image and video, but here
+ // we will consume rights for image files only.
+ // Do not consume rights of a GIF image and video here.
+ // ViewGifImage will take care of GIF rights consumption stub.
+ // MediaPlayer will handle the video rights consumption stub.
+ if ((mMediaSet != null && mMediaSet.getMediaItemCount() > 1)
+ || !(this instanceof SinglePhotoPage)) {
+ String mime = mCurrentPhoto.getMimeType();
+ if (!TextUtils.isEmpty(mime) && !mime.equals("image/gif")
+ && !mime.startsWith("video/")) {
+ DrmHelper.manageDrmLicense(mActivity.getAndroidContext(),
+ mHandler, mCurrentPhoto.getFilePath(),
+ mCurrentPhoto.getMimeType());
+ }
+ }
}
}
@@ -1784,6 +1656,9 @@ public abstract class PhotoPage extends ActivityState implements
private static void viewAnimateGif(Activity activity, Uri uri) {
Intent intent = new Intent(ViewGifImage.VIEW_GIF_ACTION, uri);
+ if (DrmHelper.isDrmFile(uri.toString())) {
+ intent.setDataAndType(uri, "image/gif");
+ }
activity.startActivity(intent);
}
}
diff --git a/src/com/android/gallery3d/app/SlideshowPage.java b/src/com/android/gallery3d/app/SlideshowPage.java
index 174058dc8..2b15ab96e 100644
--- a/src/com/android/gallery3d/app/SlideshowPage.java
+++ b/src/com/android/gallery3d/app/SlideshowPage.java
@@ -16,8 +16,12 @@
package com.android.gallery3d.app;
+import java.util.ArrayList;
+import java.util.Random;
+
import android.app.Activity;
import android.content.Intent;
+import android.drm.DrmHelper;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
@@ -38,9 +42,6 @@ import com.android.gallery3d.ui.SynchronizedHandler;
import com.android.gallery3d.util.Future;
import com.android.gallery3d.util.FutureListener;
-import java.util.ArrayList;
-import java.util.Random;
-
public class SlideshowPage extends ActivityState {
private static final String TAG = "SlideshowPage";
@@ -338,6 +339,15 @@ public class SlideshowPage extends ActivityState {
mData = mMediaSet.getMediaItem(index, DATA_SIZE);
mDataStart = index;
dataEnd = index + mData.size();
+
+ // Consume license once in each element of the slide-show
+ // This is a non-blocking loop operation
+ for (int i = 0; i < mData.size(); i++) {
+ String path = mData.get(i).getFilePath();
+ if (DrmHelper.isDrmFile(path)) {
+ DrmHelper.consumeDrmRights(path, "image/*");
+ }
+ }
}
return (index < mDataStart || index >= dataEnd) ? null : mData.get(index - mDataStart);
diff --git a/src/com/android/gallery3d/app/Wallpaper.java b/src/com/android/gallery3d/app/Wallpaper.java
index f9bbc1301..5c19d9016 100644
--- a/src/com/android/gallery3d/app/Wallpaper.java
+++ b/src/com/android/gallery3d/app/Wallpaper.java
@@ -97,7 +97,6 @@ public class Wallpaper extends Activity {
Intent request = new Intent(Intent.ACTION_GET_CONTENT)
.setClass(this, DialogPicker.class)
.setType(IMAGE_TYPE);
- request.putExtra("com.android.gallery3d.IsWallpaper", true);
startActivityForResult(request, STATE_PHOTO_PICKED);
return;
}