8000 Switch to embedded NanoHTTPD with Storage Access Framework to access content · Issue #32 · gogins/csound-android · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Switch to embedded NanoHTTPD with Storage Access Framework to access content #32

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

Closed
gogins opened this issue Oct 22, 2024 · 27 comments
Closed
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@gogins
Copy link
Owner
gogins commented Oct 22, 2024

Prevents HTML pieces from working in Android 14. See:

https://chatgpt.com/c/67170112-4a64-8009-abaa-44fd858d4601

and:

https://developer.android.com/about/versions/14/behavior-changes-14

This might help work things out:

https://developer.android.com/guide/app-compatibility/test-debug

There may be a need for granular media types in accessing files.

@gogins gogins added bug Something isn't working documentation Improvements or additions to documentation labels Oct 22, 2024
@gogins gogins self-assigned this Oct 22, 2024
@gogins
Copy link
Owner Author
gogins commented Oct 24, 2024

This is quite interesting from ChatGPT. This implies that I could replace the Csound for Android app with a new and perhaps simpler app that serves cloud-5.

@gogins
Copy link
Owner Author
gogins commented Oct 24, 2024

Good news:

  • The Csound for Android app builds with the updated Android Studio and SDK just fine.
  • The emulator runs and debugs the Csound for Android app much better than it used to.
  • All the required files in the app's assets have been copied to the filesystem Music directory, as before.

Bad news:

  • The WebView will not load those files from the Music directory. This prevents the HTML examples from running.

@gogins
Copy link
Owner Author
gogins commented Oct 24, 2024

It is clear that Android has chosen to close as many security loopholes in WebKit as possible even at the compromise of functionality. I cannot and will not fight this.

I will investigate using a local Web server inside the app. This would be the Android equivalent of NW.js.

@gogins
Copy link
Owner Author
gogins commented Oct 24, 2024

Using a local Web server is not a panacea. The WebKit file access error will go away, but security risks remain. The best thing might be to configure the Storage Access Framework to grant permissions for the user's selected Web directory.

@gogins
Copy link
Owner Author
gogins commented Oct 24, 2024

It takes some work to make this work, see this response..

@gogins
Copy link
Owner Author
gogins commented Oct 24, 2024

At this moment, I don't want to do this. I suppose that Web server apps for Android work this way, I will take another look at them.

@gogins
Copy link
Owner Author
gogins commented Oct 25, 2024

Here is my plan:

  • Create a localhost branch in this repository.
  • Identify the steps to create an internal local Web server.
  • Start the work. If the work gets to be too much, remove the HTML functionality from the app -- all the other stuff still seems to work.

@gogins
Copy link
Owner Author
gogins commented Oct 25, 2024

The objective is to replace the current WebView functionality for HTML pieces, and perhaps for browsing external sites, with an embedded NanoHTTPD local Web server.

  • Add a build step to copy the cloud-5 distribution into the CsoundApplication's assets folder. Not doing.
  • Add a line in the app initialization to copy the cloud-5 directory from the assets to the Music/cloud-5 directory. For some reason I do not see all of the files that are in the .apk assets in the target directory. Perhaps there is a size limit? Not doing.
  • Add the NanoHTTPD library to the build.
  • Add the Web server port and Web directory to the settings. The Web directory already exists as the HTML directory. However there is now the cloud-5 directory that will be used as the html directory. Not so.
  • Subclass the NanoHTTPD library as CsoundHTTPD.
  • Create a csound_httpd instance of CsoundHTTPD using the default port and Web directory (for now, 8080 and Music/examples/Gogins). The Web directory must be picked to enable permissions.
  • If necessary, hardcode a piece and open it to see if things load and run.
  • From the Settings intent, trigger the SAF directory picker.
  • Handle the intent's results and make the selection persistent. Re-create csound_httpd with the new settings.
  • Create a file picker for pieces. Using existing picker.
  • Set up a ContentResolver to create an input stream for the picked file.
  • Use the NanoHTTPD API to request a response from that input stream.
  • NanoHTTPD will receive from the piece's Web page elements HTTP requests, which must be translated to input streams in the same way as for the piece.
  • Update documentation.
  • Do not include cloud-5, its menu is redundant with the app. Consider a new app just for cloud-5.
  • Test on an emulator for the earliest supported Android and API version.
  • Created a signed .apk.
  • Beta release on GitHub.

@gogins
Copy link
Owner Author
gogins commented Oct 26, 2024

NanoHTTPD has not had a commit in 5 years....

@gogins
Copy link
Owner Author
gogins commented Oct 26, 2024

I tried a better prompt.

gogins added a commit that referenced this issue Oct 26, 2024
@gogins
Copy link
Owner Author
gogins commented Oct 28, 2024

For reasons I don't fathom, the Csound for Android app has starting playing the HTML examples just fine in the emulator. Perhaps the emulator is out of date. I will look at that.

Yes, I was emulating Android 11. I created a new emulator for Android 15, Pixel Fold. It takes a long time to install because of cloud-5. Now it's behaving like my phone, and I can continue to debug it and try out the local Web server idea.

@gogins
Copy link
Owner Author
gogins commented Oct 28, 2024

I will need to resolve content and provide MIME types for file suffixes. This can be used.

@gogins
Copy link
Owner Author
gogins commented Oct 29, 2024

I have to do this before anything else: https://chatgpt.com/c/671ab00f-1a3c-8009-9c5b-1fd16edc8caf.

@gogins
Copy link
Owner Author
gogins commented Oct 29, 2024

This is all taking a very long time. There are many changes enforced by the SAF and new policies. Without ChaptGPT this would be taking 2 to 3 times as long, however.

@gogins gogins changed the title "WebView error for file: <filepath>" Switch to embedded NanoHTTPD with Storage Access Framework to access content Oct 30, 2024
@gogins
Copy link
Owner Author
gogins commented Oct 30, 2024

OK, Scrims shows up and controls work, but there's apparently no access to the Csound object, must be thanks to different JavaScript contexts.

@gogins
8000
Copy link
Owner Author
gogins commented Oct 30, 2024

I researched SimpleHTTPServer. I don't find source code. I don't find alternatives. I installed SimpleHTTPServer on my phone. It starts to render scrims.html but Csound doesn't start, probably because the operating system is identified as Android. In other words, behaves just like the localhost branch of this app.

The implication is that I can change csound_loader.js to load the WASM build if the native Csound is not detected.

In that case, there would be no difference between the Csound for Android app and SimpleHTTPServer as far as cloud-5 is concerned.

@gogins
Copy link
Owner Author
gogins commented Oct 30, 2024

More specific help including how to debug: https://chatgpt.com/c/67216fa8-6850-8009-9aef-7ffd00c59d6c.

@gogins
Copy link
Owner Author
gogins commented Oct 30, 2024

Subdirectories are an issue. I will have to recursively descend the tree, perhaps. For now, I'll test by moving all files to the root.

@gogins
Copy link
Owner Author
gogins commented Oct 30, 2024

I got player.html to work with csound_oboe so the app can definitely be made to run HTML pieces!

The subdirectory permissions appear to be a issue.

@gogins
Copy link
Owner Author
gogins commented Oct 30, 2024

This now actually seems to be working. The code has a straightforward recursive search through the Storage Access Framework HTML directory and serves input streams, not files. And the details are baroque. But it works.

This is the first substantial piece of code that I have written using ChatGPT. I think it helped quite a bit.

I will review and clean up the code soon.

@gogins
Copy link
Owner Author
gogins commented Oct 31, 2024

Doesn't work on my Galaxy S24 Ultra, which is Android 14, API 34, not 15 and 35.

@gogins
Copy link
Owner Author
gogins commented Oct 31, 2024
  • Debug on virtual device with Android 14, API 34.
  • If that doesn't help, debug on the phone.

@gogins
Copy link
Owner Author
gogins commented Oct 31, 2024

I had two names for shared preferences, have now switched to no name (defaults to activity class name).

gogins added a commit that referenced this issue Nov 1, 2024
@gogins
Copy link
Owner Author
gogins commented Nov 1, 2024

That didn't work either, fixed by using PreferenceManager.getDefaultSharedPreferences.

@gogins
Copy link
Owner Author
gogins commented Nov 1, 2024

I set up the emulator for a tablet running Android 14 API level 34. And message.html runs on it. But it still doesn't run on the phone.

gogins added a commit that referenced this issue Nov 2, 2024
@gogins
Copy link
Owner Author
gogins commented Nov 2, 2024

But that only works in the emulator. On the phone, it's not working. The jquery.js file is not loading.

@gogins
Copy link
Owner Author
gogins commented Nov 2, 2024

The problem was I selected the wrong examples/Gogins directory. With the correct directory, it works correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant
0