mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 08:47:46 +00:00
8caaf057e8
Now that our minSdk is 19, we can remove a lot of old code paths that only ran pre-19.
38 lines
1.1 KiB
Java
38 lines
1.1 KiB
Java
package org.thoughtcrime.securesms.util;
|
|
|
|
|
|
import android.os.Build;
|
|
import android.os.MemoryFile;
|
|
import android.os.ParcelFileDescriptor;
|
|
|
|
import java.io.FileDescriptor;
|
|
import java.io.IOException;
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
|
|
public class MemoryFileUtil {
|
|
|
|
public static ParcelFileDescriptor getParcelFileDescriptor(MemoryFile file) throws IOException {
|
|
try {
|
|
Method method = MemoryFile.class.getDeclaredMethod("getFileDescriptor");
|
|
FileDescriptor fileDescriptor = (FileDescriptor) method.invoke(file);
|
|
|
|
Field field = fileDescriptor.getClass().getDeclaredField("descriptor");
|
|
field.setAccessible(true);
|
|
|
|
int fd = field.getInt(fileDescriptor);
|
|
|
|
return ParcelFileDescriptor.adoptFd(fd);
|
|
} catch (IllegalAccessException e) {
|
|
throw new IOException(e);
|
|
} catch (InvocationTargetException e) {
|
|
throw new IOException(e);
|
|
} catch (NoSuchMethodException e) {
|
|
throw new IOException(e);
|
|
} catch (NoSuchFieldException e) {
|
|
throw new IOException(e);
|
|
}
|
|
}
|
|
}
|