Skip to content

Commit

Permalink
Use ordinary content:// protocol instead of love2d://.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikuAuahDark committed Jan 16, 2025
1 parent 3ad966d commit 85ac733
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 33 deletions.
36 changes: 4 additions & 32 deletions app/src/main/java/org/love2d/android/GameActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.util.DisplayMetrics;
Expand Down Expand Up @@ -324,11 +323,6 @@ public void requestRecordAudioPermission() {
}
}

@Keep
public int convertToFileDescriptor(String uri) {
return convertToFileDescriptor(Uri.parse(uri));
}

public int getAudioSMP() {
int smp = 256;
AudioManager a = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Expand All @@ -354,12 +348,8 @@ public int getAudioFreq() {
}

public boolean isNativeLibsExtracted() {
if (android.os.Build.VERSION.SDK_INT >= 23) {
ApplicationInfo appInfo = getApplicationInfo();
return (appInfo.flags & ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS) != 0;
}

return false;
ApplicationInfo appInfo = getApplicationInfo();
return (appInfo.flags & ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS) != 0;
}

public void sendUriAsDroppedFile(Uri uri) {
Expand Down Expand Up @@ -426,32 +416,14 @@ private HashMap<String, Boolean> buildFileTree(AssetManager assetManager, String
return map;
}

private int convertToFileDescriptor(Uri uri) {
int fd = -1;

try {
ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(uri, "r");
if (pfd == null) {
throw new RuntimeException("pfd is null");
}

fd = pfd.dup().detachFd();
pfd.close();
} catch (Exception e) {
Log.e(TAG, "Failed attempt to convert " + uri.toString() + " to file descriptor", e);
}

return fd;
}

private void processOpenGame(Uri game) {
String scheme = game.getScheme();
String path = game.getPath();

if (scheme != null) {
if (scheme.equals("content")) {
// Convert the URI to file descriptor.
args = new String[]{"love2d://fd/" + convertToFileDescriptor(game)};
// Pass content URI as-is.
args = new String[]{game.toString()};
} else if (scheme.equals("file")) {
// Regular file, pass as-is.
args = new String[]{path};
Expand Down

0 comments on commit 85ac733

Please sign in to comment.