Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c12b8b10 authored by Paramananda's avatar Paramananda Committed by Gerrit - the friendly Code Review server
Browse files

Gallery2 : Uses internal Drm image decoder api in Gallery app

- Remove all previous drm implementation which is basically uses
  base bitmap decode apis to decode drm image files.
- Introduced new hidden apis on BitmapFactory and
  BitmapRegionDecoder specific to DRM content which
  is more practical to DRM framework.
- Uses DrmHelper a utility drm api library to code reusability.
- This approch will fix the issue on sharing images from
  Third party application.

CRs-fixed : 804191

Change-Id: I2e9489800c57df4fdeeb21f1548fbccc6dfbd3f9
parent 75b8670f
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -24,4 +24,12 @@
            android:layout_width="wrap_content"
            android:scaleType="fitCenter"
            android:adjustViewBounds="true" />

    <ImageView
        android:id="@+id/drm_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@drawable/drm_image" />

</FrameLayout>
+5 −0
Original line number Diff line number Diff line
@@ -436,4 +436,9 @@
    <item quantity="one" msgid="6949174783125614798">"%1$d foto"</item>
    <item quantity="other" msgid="3813306834113858135">"%1$d fotos"</item>
  </plurals>

    <string name="no_permission_for_drm">Los archivos DRM no pueden compartirse.</string>
    <string name="drm_license_info">Información de licencia Drm</string>
    <string name="mimetype_not_supported">No puede reproducirse este archivo.</string>
    <string name="action_consumes_rights">Se agotarán los derechos para reproducir este multimedia.</string>
</resources>
+8 −107
Original line number Diff line number Diff line
@@ -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";
@@ -120,8 +101,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;
@@ -330,6 +310,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) {
@@ -342,65 +328,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();
@@ -434,7 +361,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());
@@ -443,29 +369,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);
@@ -508,8 +411,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();
+0 −79
Original line number Diff line number Diff line
@@ -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);
+1 −81
Original line number Diff line number Diff line
@@ -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());
Loading