From ae9bfe16432fdab600fd6a32a846228ee62ef19f Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 10 Dec 2018 13:58:05 +0100 Subject: [PATCH] limit video transcoding to api >= 18 and other api 16 fixes --- .../eu/siacs/conversations/persistance/FileBackend.java | 9 ++++++++- .../services/AttachFileToConversationRunnable.java | 4 +++- .../eu/siacs/conversations/ui/ConversationFragment.java | 8 ++++++-- .../eu/siacs/conversations/ui/ConversationsActivity.java | 3 +++ .../eu/siacs/conversations/ui/EditAccountActivity.java | 4 ++-- .../conversations/utils/Android360pFormatStrategy.java | 3 +++ .../conversations/utils/Android720pFormatStrategy.java | 3 +++ 7 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index cb130c24e..df3b63bf9 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -19,6 +19,7 @@ import android.os.Environment; import android.os.ParcelFileDescriptor; import android.provider.MediaStore; import android.provider.OpenableColumns; +import android.support.annotation.RequiresApi; import android.support.v4.content.FileProvider; import android.system.Os; import android.system.StructStat; @@ -299,7 +300,12 @@ public class FileBackend { if (dimensions != null) { 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; int height; try { @@ -320,6 +326,7 @@ public class FileBackend { return rotated ? new Dimensions(width, height) : new Dimensions(height, width); } + @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1) private static int extractRotationFromMediaRetriever(MediaMetadataRetriever metadataRetriever) { String r = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION); try { diff --git a/src/main/java/eu/siacs/conversations/services/AttachFileToConversationRunnable.java b/src/main/java/eu/siacs/conversations/services/AttachFileToConversationRunnable.java index 2d4b12c47..ed4474d9e 100644 --- a/src/main/java/eu/siacs/conversations/services/AttachFileToConversationRunnable.java +++ b/src/main/java/eu/siacs/conversations/services/AttachFileToConversationRunnable.java @@ -5,6 +5,7 @@ import android.net.Uri; import android.os.Build; import android.os.ParcelFileDescriptor; import android.preference.PreferenceManager; +import android.support.annotation.RequiresApi; import android.util.Log; 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 { Log.d(Config.LOGTAG,"processing file as video"); mXmppConnectionService.startForcingForegroundNotification(); @@ -158,7 +160,7 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod @Override public void run() { - if (isVideoMessage) { + if (isVideoMessage && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { try { processAsVideo(); } catch (FileNotFoundException e) { diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 60bd52c76..664d17ec4 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1522,7 +1522,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke switch (attachmentChoice) { case ATTACHMENT_CHOICE_CHOOSE_IMAGE: 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/*"); chooser = true; break; @@ -1540,7 +1542,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke case ATTACHMENT_CHOICE_CHOOSE_FILE: chooser = true; 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.setAction(Intent.ACTION_GET_CONTENT); break; diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java index b79b1360d..6c61f3027 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java @@ -41,10 +41,12 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.databinding.DataBindingUtil; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.provider.Settings; import android.support.annotation.IdRes; import android.support.annotation.NonNull; +import android.support.annotation.RequiresApi; import android.support.v7.app.ActionBar; import android.support.v7.app.AlertDialog; import android.support.v7.widget.Toolbar; @@ -218,6 +220,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio private void openBatteryOptimizationDialogIfNeeded() { if (hasAccountWithoutPush() && isOptimizingBattery() + && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M && getPreferences().getBoolean(getBatteryOptimizationPreferenceKey(), true)) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.battery_optimizations_enabled); diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index b3e8ab421..a5fcc3423 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -1143,7 +1143,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat private void showOsOptimizationWarning(boolean showBatteryWarning, boolean showDataSaverWarning) { 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.osOptimizationBody.setText(R.string.data_saver_enabled_explained); 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(); } }); - } 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.osOptimizationHeadline.setText(R.string.battery_optimizations_enabled); this.binding.osOptimizationBody.setText(R.string.battery_optimizations_enabled_explained); diff --git a/src/main/java/eu/siacs/conversations/utils/Android360pFormatStrategy.java b/src/main/java/eu/siacs/conversations/utils/Android360pFormatStrategy.java index 50de54b75..4215a2611 100644 --- a/src/main/java/eu/siacs/conversations/utils/Android360pFormatStrategy.java +++ b/src/main/java/eu/siacs/conversations/utils/Android360pFormatStrategy.java @@ -2,6 +2,8 @@ package eu.siacs.conversations.utils; import android.media.MediaCodecInfo; import android.media.MediaFormat; +import android.os.Build; +import android.support.annotation.RequiresApi; import android.util.Log; import net.ypresto.androidtranscoder.format.MediaFormatExtraConstants; @@ -26,6 +28,7 @@ public class Android360pFormatStrategy implements MediaFormatStrategy { mAudioChannels = 2; } + @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) @Override public MediaFormat createVideoOutputFormat(MediaFormat inputFormat) { int width = inputFormat.getInteger(MediaFormat.KEY_WIDTH); diff --git a/src/main/java/eu/siacs/conversations/utils/Android720pFormatStrategy.java b/src/main/java/eu/siacs/conversations/utils/Android720pFormatStrategy.java index 5389c4260..e54b078de 100644 --- a/src/main/java/eu/siacs/conversations/utils/Android720pFormatStrategy.java +++ b/src/main/java/eu/siacs/conversations/utils/Android720pFormatStrategy.java @@ -2,6 +2,8 @@ package eu.siacs.conversations.utils; import android.media.MediaCodecInfo; import android.media.MediaFormat; +import android.os.Build; +import android.support.annotation.RequiresApi; import android.util.Log; import net.ypresto.androidtranscoder.format.MediaFormatExtraConstants; @@ -26,6 +28,7 @@ public class Android720pFormatStrategy implements MediaFormatStrategy { mAudioChannels = 2; } + @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) @Override public MediaFormat createVideoOutputFormat(MediaFormat inputFormat) { int width = inputFormat.getInteger(MediaFormat.KEY_WIDTH);