Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for USB Drive Support on Newer Android Versions (14+) #148

Open
coffincolors opened this issue Jan 29, 2025 · 1 comment
Open

Request for USB Drive Support on Newer Android Versions (14+) #148

coffincolors opened this issue Jan 29, 2025 · 1 comment

Comments

@coffincolors
Copy link

Hi Bruno,

First off, thanks for all your hard work on Winlator!

I’d like to request renewed support for USB flash drives on newer Android versions (14+). In older releases (before v8), I could enable this by adding MANAGE_EXTERNAL_STORAGE to the manifest, granting “All Files Access,” and specifying a path such as /mnt/media_rw/XXXX-XXXX in the container config. This worked fine in Wine. However, since v8, even with those permissions in place, the drive appears in Wine configuration but remains inaccessible.

I’ve experimented with a fix in my own fork by modifying FileUtils.java and ContainerDetailFragment.java to properly detect external storage paths. I can't really show you a proper commit, because of deactivation of my previous GitHub, but below is a snippet of how I implemented it (please note it’s a bit hacky and may break on older devices that mount external storage differently):

In ContainerDetailFragment.java:

@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    if (requestCode == MainActivity.OPEN_DIRECTORY_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
        if (data != null) {
            Uri uri = data.getData();
            Log.d(TAG, "URI obtained in onActivityResult: " + uri.toString());
            String path = FileUtils.getFilePathFromUri(getContext(), uri);
            Log.d(TAG, "File path in onActivityResult: " + path);
            if (path != null) {
                if (openDirectoryCallback != null) {
                    openDirectoryCallback.call(path);
                }
            } else {
                Toast.makeText(getContext(), "Invalid directory selected", Toast.LENGTH_SHORT).show();
            }
        }
        openDirectoryCallback = null;
    }
}

Then in FileUtils.java:

public static String getFilePathFromUriUsingSAF(Context context, Uri uri) {
    Log.d(TAG, "getFilePathFromUriUsingSAF called with URI: " + uri.toString());
    String documentId;
    try {
        documentId = DocumentsContract.getTreeDocumentId(uri);
    } catch (IllegalArgumentException e) {
        Log.e(TAG, "Invalid URI: " + uri.toString(), e);
        return null;
    }

    Log.d(TAG, "Document ID: " + documentId);
    String[] split = documentId.split(":");
    String type = split[0];
    String path = split.length > 1 ? split[1] : "";

    try {
        path = URLDecoder.decode(path, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, "Error decoding path: " + path, e);
        return null;
    }

    if ("primary".equalsIgnoreCase(type)) {
        return Environment.getExternalStorageDirectory() + "/" + path;
    } else {
        return "/mnt/media_rw/" + type + "/" + path;
    }
}

public static String getFilePathFromUri(Context context, Uri uri) {
    Log.d(TAG, "getFilePathFromUri called with URI: " + uri.toString());
    String filePath = getFilePathFromUriUsingSAF(context, uri);
    Log.d(TAG, "File path obtained: " + filePath);
    return filePath;
}

While this code helps construct the correct path from a file picker in Winlator v7.1, accessing the drive in newer Winlator releases (v9) with the path explicitly defined in a container's settings still doesn’t work for me. I’m not sure if this is due to changes in container file management or something else in Wine itself. Any insight you have would be greatly appreciated—external drives are crucial for me to run larger games and applications.

Side Note: True Mouse Control Feature

I also have a feature I’d love to PR called “True Mouse Control.” It uses requestPointerCapture() in XServerDisplayActivity and a delta-based movement approach in TouchPadView.java. This provides a full-range mouse experience without being limited by the bounds of the Android screen or status bar. I also added an additional device filter that prevents devices like Mice from being considered as Game Controllers (without this, games like Skyrim will think some mice are a controller, overriding your actual controller, preventing any form of input). If you’re interested in merging that, I can attempt to prepare a proper PR using the 7.1 source code.

Again, thank you for all that you've done towards the continued development of Winlator, and I hope this feedback is helpful! Let me know if you have any questions or need additional details.

@brunodev85
Copy link
Owner

Hello coffincolors,

from version 8.0, Tiny PRoot was introduced which I believe the /mnt path is not being checked, later I will check it. About mouse movement using requestPointerCapture()/onCapturedPointerEvent() is a cool feature, thanks for the suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants