limit video transcoding to api >= 18 and other api 16 fixes

This commit is contained in:
Daniel Gultsch 2018-12-10 13:58:05 +01:00
parent c071a53595
commit ae9bfe1643
7 changed files with 28 additions and 6 deletions

View File

@ -19,6 +19,7 @@ import android.os.Environment;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.provider.OpenableColumns; import android.provider.OpenableColumns;
import android.support.annotation.RequiresApi;
import android.support.v4.content.FileProvider; import android.support.v4.content.FileProvider;
import android.system.Os; import android.system.Os;
import android.system.StructStat; import android.system.StructStat;
@ -299,7 +300,12 @@ public class FileBackend {
if (dimensions != null) { if (dimensions != null) {
return dimensions; return dimensions;
} }
int rotation = extractRotationFromMediaRetriever(metadataRetriever); final int rotation;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
rotation = extractRotationFromMediaRetriever(metadataRetriever);
} else {
rotation = 0;
}
boolean rotated = rotation == 90 || rotation == 270; boolean rotated = rotation == 90 || rotation == 270;
int height; int height;
try { try {
@ -320,6 +326,7 @@ public class FileBackend {
return rotated ? new Dimensions(width, height) : new Dimensions(height, width); return rotated ? new Dimensions(width, height) : new Dimensions(height, width);
} }
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
private static int extractRotationFromMediaRetriever(MediaMetadataRetriever metadataRetriever) { private static int extractRotationFromMediaRetriever(MediaMetadataRetriever metadataRetriever) {
String r = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION); String r = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
try { try {

View File

@ -5,6 +5,7 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.RequiresApi;
import android.util.Log; import android.util.Log;
import net.ypresto.androidtranscoder.MediaTranscoder; import net.ypresto.androidtranscoder.MediaTranscoder;
@ -88,6 +89,7 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod
} }
} }
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
private void processAsVideo() throws FileNotFoundException { private void processAsVideo() throws FileNotFoundException {
Log.d(Config.LOGTAG,"processing file as video"); Log.d(Config.LOGTAG,"processing file as video");
mXmppConnectionService.startForcingForegroundNotification(); mXmppConnectionService.startForcingForegroundNotification();
@ -158,7 +160,7 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod
@Override @Override
public void run() { public void run() {
if (isVideoMessage) { if (isVideoMessage && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
try { try {
processAsVideo(); processAsVideo();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {

View File

@ -1522,7 +1522,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
switch (attachmentChoice) { switch (attachmentChoice) {
case ATTACHMENT_CHOICE_CHOOSE_IMAGE: case ATTACHMENT_CHOICE_CHOOSE_IMAGE:
intent.setAction(Intent.ACTION_GET_CONTENT); intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}
intent.setType("image/*"); intent.setType("image/*");
chooser = true; chooser = true;
break; break;
@ -1540,7 +1542,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
case ATTACHMENT_CHOICE_CHOOSE_FILE: case ATTACHMENT_CHOICE_CHOOSE_FILE:
chooser = true; chooser = true;
intent.setType("*/*"); intent.setType("*/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}
intent.addCategory(Intent.CATEGORY_OPENABLE); intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setAction(Intent.ACTION_GET_CONTENT); intent.setAction(Intent.ACTION_GET_CONTENT);
break; break;

View File

@ -41,10 +41,12 @@ import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.databinding.DataBindingUtil; import android.databinding.DataBindingUtil;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings; import android.provider.Settings;
import android.support.annotation.IdRes; import android.support.annotation.IdRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
@ -218,6 +220,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
private void openBatteryOptimizationDialogIfNeeded() { private void openBatteryOptimizationDialogIfNeeded() {
if (hasAccountWithoutPush() if (hasAccountWithoutPush()
&& isOptimizingBattery() && isOptimizingBattery()
&& android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M
&& getPreferences().getBoolean(getBatteryOptimizationPreferenceKey(), true)) { && getPreferences().getBoolean(getBatteryOptimizationPreferenceKey(), true)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.battery_optimizations_enabled); builder.setTitle(R.string.battery_optimizations_enabled);

View File

@ -1143,7 +1143,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
private void showOsOptimizationWarning(boolean showBatteryWarning, boolean showDataSaverWarning) { private void showOsOptimizationWarning(boolean showBatteryWarning, boolean showDataSaverWarning) {
this.binding.osOptimization.setVisibility(showBatteryWarning || showDataSaverWarning ? View.VISIBLE : View.GONE); this.binding.osOptimization.setVisibility(showBatteryWarning || showDataSaverWarning ? View.VISIBLE : View.GONE);
if (showDataSaverWarning) { if (showDataSaverWarning && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
this.binding.osOptimizationHeadline.setText(R.string.data_saver_enabled); this.binding.osOptimizationHeadline.setText(R.string.data_saver_enabled);
this.binding.osOptimizationBody.setText(R.string.data_saver_enabled_explained); this.binding.osOptimizationBody.setText(R.string.data_saver_enabled_explained);
this.binding.osOptimizationDisable.setText(R.string.allow); this.binding.osOptimizationDisable.setText(R.string.allow);
@ -1157,7 +1157,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
Toast.makeText(EditAccountActivity.this, R.string.device_does_not_support_data_saver, Toast.LENGTH_SHORT).show(); Toast.makeText(EditAccountActivity.this, R.string.device_does_not_support_data_saver, Toast.LENGTH_SHORT).show();
} }
}); });
} else if (showBatteryWarning) { } else if (showBatteryWarning && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
this.binding.osOptimizationDisable.setText(R.string.disable); this.binding.osOptimizationDisable.setText(R.string.disable);
this.binding.osOptimizationHeadline.setText(R.string.battery_optimizations_enabled); this.binding.osOptimizationHeadline.setText(R.string.battery_optimizations_enabled);
this.binding.osOptimizationBody.setText(R.string.battery_optimizations_enabled_explained); this.binding.osOptimizationBody.setText(R.string.battery_optimizations_enabled_explained);

View File

@ -2,6 +2,8 @@ package eu.siacs.conversations.utils;
import android.media.MediaCodecInfo; import android.media.MediaCodecInfo;
import android.media.MediaFormat; import android.media.MediaFormat;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.Log; import android.util.Log;
import net.ypresto.androidtranscoder.format.MediaFormatExtraConstants; import net.ypresto.androidtranscoder.format.MediaFormatExtraConstants;
@ -26,6 +28,7 @@ public class Android360pFormatStrategy implements MediaFormatStrategy {
mAudioChannels = 2; mAudioChannels = 2;
} }
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override @Override
public MediaFormat createVideoOutputFormat(MediaFormat inputFormat) { public MediaFormat createVideoOutputFormat(MediaFormat inputFormat) {
int width = inputFormat.getInteger(MediaFormat.KEY_WIDTH); int width = inputFormat.getInteger(MediaFormat.KEY_WIDTH);

View File

@ -2,6 +2,8 @@ package eu.siacs.conversations.utils;
import android.media.MediaCodecInfo; import android.media.MediaCodecInfo;
import android.media.MediaFormat; import android.media.MediaFormat;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.Log; import android.util.Log;
import net.ypresto.androidtranscoder.format.MediaFormatExtraConstants; import net.ypresto.androidtranscoder.format.MediaFormatExtraConstants;
@ -26,6 +28,7 @@ public class Android720pFormatStrategy implements MediaFormatStrategy {
mAudioChannels = 2; mAudioChannels = 2;
} }
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override @Override
public MediaFormat createVideoOutputFormat(MediaFormat inputFormat) { public MediaFormat createVideoOutputFormat(MediaFormat inputFormat) {
int width = inputFormat.getInteger(MediaFormat.KEY_WIDTH); int width = inputFormat.getInteger(MediaFormat.KEY_WIDTH);