You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
implement file sharing by file descriptor
Using custom gdbus code, as libportal doesn't expose the raw org.freedesktop.portal.OpenURI.OpenFile method.
This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.Map;
|
||||
import android.content.pm.PackageParser;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
|
||||
public abstract class ContentProvider {
|
||||
|
||||
@@ -34,4 +35,8 @@ public abstract class ContentProvider {
|
||||
|
||||
public abstract int delete(Uri uri, String selection, String[] selectionArgs);
|
||||
|
||||
public abstract String getType(Uri uri);
|
||||
|
||||
public abstract ParcelFileDescriptor openFile(Uri uri, String mode);
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,15 @@ public class ContentResolver {
|
||||
}
|
||||
|
||||
public ParcelFileDescriptor openFileDescriptor(Uri uri, String mode) throws FileNotFoundException {
|
||||
return ParcelFileDescriptor.open(new File(uri.toString()), ParcelFileDescriptor.parseMode(mode));
|
||||
if ("file".equals(uri.getScheme())) {
|
||||
return ParcelFileDescriptor.open(new File(uri.toString()), ParcelFileDescriptor.parseMode(mode));
|
||||
} else {
|
||||
ContentProvider provider = ContentProvider.providers.get(uri.getAuthority());
|
||||
if (provider != null)
|
||||
return provider.openFile(uri, mode);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
|
||||
@@ -53,4 +61,12 @@ public class ContentResolver {
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getType(Uri uri) {
|
||||
ContentProvider provider = ContentProvider.providers.get(uri.getAuthority());
|
||||
if (provider != null)
|
||||
return provider.getType(uri);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.PowerManager;
|
||||
import android.os.Vibrator;
|
||||
import android.telephony.TelephonyManager;
|
||||
@@ -116,6 +117,7 @@ public class Context extends Object {
|
||||
|
||||
private static native String native_get_apk_path();
|
||||
protected static native void native_updateConfig(Configuration config);
|
||||
private static native void nativeOpenFile(int fd);
|
||||
|
||||
static Application createApplication(long native_window) throws Exception {
|
||||
Application application;
|
||||
@@ -494,6 +496,15 @@ public class Context extends Object {
|
||||
ClipboardManager.native_set_clipboard(text);
|
||||
} else if (intent.getData() != null) {
|
||||
Slog.i(TAG, "starting extern activity with intent: " + intent);
|
||||
if (intent.getData().getScheme().equals("content")) {
|
||||
try {
|
||||
ParcelFileDescriptor fd = getContentResolver().openFileDescriptor(intent.getData(), "r");
|
||||
nativeOpenFile(fd.getFd());
|
||||
return;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Activity.nativeOpenURI(String.valueOf(intent.getData()));
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -2,6 +2,7 @@ package android.content;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
|
||||
public class SearchRecentSuggestionsProvider extends ContentProvider {
|
||||
public void setupSuggestions(String s, int i) {}
|
||||
@@ -20,4 +21,14 @@ public class SearchRecentSuggestionsProvider extends ContentProvider {
|
||||
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'delete'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType(Uri uri) {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getType'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParcelFileDescriptor openFile(Uri uri, String mode) {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'openFile'");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user