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

Commit 07a1c98a authored by Vasantha Balla's avatar Vasantha Balla Committed by Linux Build Service Account
Browse files

Gallery2: Fix crash for unsupported format on mute operation

MPEG4Writer does not support formats other than mp4/h264/h263. The
app needs to check for unsupported formats before starting any mute
operation. Add a condition in the app to check for unsupported
formats and display a toast message.

CRs-Fixed: 514347 696137
Change-Id: Ib2ce48d2b8ebaef80936bc7a446e1c97e3a10c31
parent d73fd7eb
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -522,6 +522,9 @@
    <!-- Toast if the trimmed video is too short to trim. [CHAR LIMIT=80] -->
    <string name="trim_too_short">Can not trim : target video is too short</string>

    <!-- Toast if the muted video is not supported. [CHAR LIMIT=80] -->
    <string name="mute_nosupport">Can not mute : not supported video</string>

    <!-- Text to show with progress bar while stitching in Gallery -->
    <string name="pano_progress_text">Rendering panorama</string>

+37 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.gallery3d.app;

import java.util.ArrayList;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
@@ -40,6 +42,13 @@ public class MuteVideo {
    private SaveVideoFileInfo mDstFileInfo = null;
    private Activity mActivity = null;
    private final Handler mHandler = new Handler();
    private String mMimeType;
    ArrayList<String> mUnsupportedMuteFileTypes = new ArrayList<String>();
    private final String FILE_TYPE_DIVX = "video/divx";
    private final String FILE_TYPE_AVI = "video/avi";
    private final String FILE_TYPE_WMV = "video/x-ms-wmv";
    private final String FILE_TYPE_ASF = "video/x-ms-asf";
    private final String FILE_TYPE_WEBM = "video/webm";

    final String TIME_STAMP_NAME = "'MUTE'_yyyyMMdd_HHmmss";

@@ -47,6 +56,13 @@ public class MuteVideo {
        mUri = uri;
        mFilePath = filePath;
        mActivity = activity;
        if (mUnsupportedMuteFileTypes != null) {
            mUnsupportedMuteFileTypes.add(FILE_TYPE_DIVX);
            mUnsupportedMuteFileTypes.add(FILE_TYPE_AVI);
            mUnsupportedMuteFileTypes.add(FILE_TYPE_WMV);
            mUnsupportedMuteFileTypes.add(FILE_TYPE_ASF);
            mUnsupportedMuteFileTypes.add(FILE_TYPE_WEBM);
        }
    }

    public void muteInBackground() {
@@ -54,6 +70,15 @@ public class MuteVideo {
                mActivity.getContentResolver(), mUri,
                mActivity.getString(R.string.folder_download));

        mMimeType = mActivity.getContentResolver().getType(mUri);
        if(!isValidFileForMute(mMimeType)) {
            Toast.makeText(mActivity.getApplicationContext(),
                           mActivity.getString(R.string.mute_nosupport),
                           Toast.LENGTH_SHORT)
                           .show();
            return;
        }

        showProgressDialog();
        new Thread(new Runnable() {
                @Override
@@ -101,4 +126,16 @@ public class MuteVideo {
        mMuteProgress.setCanceledOnTouchOutside(false);
        mMuteProgress.show();
    }
    private boolean isValidFileForMute(String mimeType) {
        if (mimeType != null) {
            for (String fileType : mUnsupportedMuteFileTypes) {
               if (mimeType.equals(fileType)) {
                   return false;
               }
            }
            return true;
        } else {
            return false;
        }
    }
}