Ensure memory file descriptor is available.
This commit is contained in:
parent
c6287547a3
commit
2141f1073e
2 changed files with 26 additions and 2 deletions
|
@ -6,13 +6,13 @@ import android.os.Build;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.attachments.Attachment;
|
import org.thoughtcrime.securesms.attachments.Attachment;
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
import org.thoughtcrime.securesms.util.BitmapDecodingException;
|
import org.thoughtcrime.securesms.util.BitmapDecodingException;
|
||||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||||
|
import org.thoughtcrime.securesms.util.MemoryFileDescriptor;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -76,6 +76,6 @@ public abstract class MediaConstraints {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isVideoTranscodeAvailable() {
|
public static boolean isVideoTranscodeAvailable() {
|
||||||
return Build.VERSION.SDK_INT >= 26;
|
return Build.VERSION.SDK_INT >= 26 && MemoryFileDescriptor.supported();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,33 @@ public final class MemoryFileDescriptor implements Closeable {
|
||||||
|
|
||||||
private static final String TAG = Log.tag(MemoryFileDescriptor.class);
|
private static final String TAG = Log.tag(MemoryFileDescriptor.class);
|
||||||
|
|
||||||
|
private static Boolean supported;
|
||||||
|
|
||||||
private final ParcelFileDescriptor parcelFileDescriptor;
|
private final ParcelFileDescriptor parcelFileDescriptor;
|
||||||
private final AtomicLong sizeEstimate;
|
private final AtomicLong sizeEstimate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does this device support memory file descriptor.
|
||||||
|
*/
|
||||||
|
public synchronized static boolean supported() {
|
||||||
|
if (supported == null) {
|
||||||
|
try {
|
||||||
|
int fileDescriptor = FileUtils.createMemoryFileDescriptor("CHECK");
|
||||||
|
|
||||||
|
if (fileDescriptor < 0) {
|
||||||
|
supported = false;
|
||||||
|
Log.w(TAG, "MemoryFileDescriptor is not available.");
|
||||||
|
} else {
|
||||||
|
supported = true;
|
||||||
|
ParcelFileDescriptor.adoptFd(fileDescriptor).close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.w(TAG, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return supported;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* memfd files do not show on the available RAM, so we must track our allocations in addition.
|
* memfd files do not show on the available RAM, so we must track our allocations in addition.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue