Emulator(Native Android)

The Uzebox now have a fully functional emulator! Download and discuss it here.
User avatar
L4rry
Posts: 242
Joined: Sun Dec 28, 2014 7:19 am
Location: Cape Town, South Africa

Re: Emulator(Native Android)

Post by L4rry »

So I've followed the instructions in the README. Created the folder, gave it storage permissions, activiated developer mode and copied the uze files and the bootloader in the folder. The app just crashes at startup though on my galaxy S5. I went to 'My Files' then 'Device storage' to create the folder.

I'm running Android 6.0.1
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Emulator(Native Android)

Post by Artcfox »

L4rry wrote: Sun Sep 24, 2017 7:44 am So I've followed the instructions in the README. Created the folder, gave it storage permissions, activiated developer mode and copied the uze files and the bootloader in the folder. The app just crashes at startup though on my galaxy S5. I went to 'My Files' then 'Device storage' to create the folder.

I'm running Android 6.0.1
I'm not sure if that is putting the cuzebox folder in the right place.

Try using Total Commander (it is free and no spyware), and you right from its home screen you can click on Downloads or Photos, and then click the .. (up arrow) at the top to go up a level. That should bring you to /storage/emulated/0 and then you can click on the top right vertical ... menu and create a new folder called cuzebox.
User avatar
L4rry
Posts: 242
Joined: Sun Dec 28, 2014 7:19 am
Location: Cape Town, South Africa

Re: Emulator(Native Android)

Post by L4rry »

Thanks! That did the trick. I didn't realize that the /storage/emulated/0 folder was already the root of my file manager.

It's pretty epic seeing the Uzebox run on my phone :) I bet I'm looking really silly right now twisting and turning my arms with elbows everywhere trying to jump on those bugz :mrgreen:

Nice work.
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Emulator(Native Android)

Post by Artcfox »

L4rry wrote: Sun Sep 24, 2017 11:25 am Thanks! That did the trick. I didn't realize that the /storage/emulated/0 folder was already the root of my file manager.
Yay! Glad it works for you now! :)
L4rry wrote: Sun Sep 24, 2017 11:25 am It's pretty epic seeing the Uzebox run on my phone :) I bet I'm looking really silly right now twisting and turning my arms with elbows everywhere trying to jump on those bugz :mrgreen:

Nice work.
Haha! Thanks.

I'll try to get this patched up so it just works without having to do any configuration. The only thing that I'm really unsure of is how to make it grab the permissions automatically when you install it, rather than having to enable them after the fact. No other app that I know of makes me do that. I wonder if that's a side effect of side-loading?
User avatar
L4rry
Posts: 242
Joined: Sun Dec 28, 2014 7:19 am
Location: Cape Town, South Africa

Re: Emulator(Native Android)

Post by L4rry »

Artcfox wrote: Sun Sep 24, 2017 1:05 pm The only thing that I'm really unsure of is how to make it grab the permissions automatically when you install it, rather than having to enable them after the fact. No other app that I know of makes me do that. I wonder if that's a side effect of side-loading?
From memory, with the limited android dev I've had, permission to access storage, network and other resources is something you configure as part of your package build config. Then on install, the user should be prompted with a dialog to accept that the app will be using these resources. Not sure if it's different for side loading.
User avatar
L4rry
Posts: 242
Joined: Sun Dec 28, 2014 7:19 am
Location: Cape Town, South Africa

Re: Emulator(Native Android)

Post by L4rry »

Halamix2
Posts: 17
Joined: Mon Jun 06, 2016 10:04 pm

Re: Emulator(Native Android)

Post by Halamix2 »

That's true for Android <6.0. In6.0 and newer you additionally ask user about permission (https://developer.android.com/training/ ... sting.html). When app doesn't request permission you may have to grant them manually (in some cases app ask automatically about them and crashes until you grant privileges and restart it)
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Emulator(Native Android)

Post by Artcfox »

Halamix2 wrote: Sun Sep 24, 2017 2:23 pm That's true for Android <6.0. In6.0 and newer you additionally ask user about permission (https://developer.android.com/training/ ... sting.html). When app doesn't request permission you may have to grant them manually (in some cases app ask automatically about them and crashes until you grant privileges and restart it)
Thanks for the info, that explains it completely! :)

Rather than add a whole bunch of Java code to I-have-no-idea-where, because this app is not coded in Java, I just changed the targetSdkVersion to 22 and then I get the old behavior of it requesting and granting the required permissions at install time. It is so much easier to change just a single character in a config file (the number 26 -> 22) as opposed to adding a ton of Java code to work around their new API changes. They built that compatibility layer, so why not use it?

I pushed the changes onto my master branch, along with updating the app to use SDL 2.0.6, since that was just released as well. I haven't made any new builds yet, because I want to get the other changes in there so it can just work with a simple install and run.
Halamix2
Posts: 17
Joined: Mon Jun 06, 2016 10:04 pm

Re: Emulator(Native Android)

Post by Halamix2 »

IIRC you can just paste this between super.onCreate and SDLActivity.Initialize in protected void onCreate in SDLActivity:
Based on https://developer.android.com/training/ ... sting.html and previous experiments

Code: Select all

super.onCreate(savedInstanceState);
//new code here
	//only for new androids
        if(Build.VERSION.SDK_INT>=23) {
            //did user granted this permission?
            if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

                //should we show toast with info WHY do we need this permission form user?
                if(shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                    final Toast info =  Toast.makeText(this, "We need to access your SD card and/or internal storage", Toast.LENGTH_LONG);
                }
                //popup where user can grant us power to write SD
                //dunno why 13, there have to be some kind of hardcoded number so I just typed in 13
                requestPermissions(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, 13);
            }

        }
        
        //new cod end
        SDLActivity.initialize();
        
This grants me access to memory and everything works fine after uploading bootloader to /0/cuzebox/ (Android 6.0 here)
I also made pull request to repo
Maybe better idea is to replace if(checkSelfPermission...) with while(...) since now when user deny permission the app crashes
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Emulator(Native Android)

Post by Artcfox »

Cool! Though with the SDL 2.0.6 upgrade, I was glad I didn't touch SDLActivity.java at all because they modified it quite a bit and I had to copy the new one over the old one to keep the app running. I was thinking that I might remove my own copy of SDLActivity.java completely and just link to the one inside the SDL distribution so I can never forget to update that when the SDL source code gets updated again.

In order to rename the applicationId, I had to add a minimal CUzeBoxActivity.java to the project that extends SDLActivity.java. I'm guessing that any custom Java code belongs there and SDLActivity.java should remain unchanged?

Maybe I'm just being silly trying to keep the whole project in C?

Maybe the resource extraction part where it grabs the bootloader.hex, gamecontrollerdb.txt, instruct.uze and instruct.txt files from inside the .apk itself and extracts it to an appropriate external storage location should be written in Java? Then if something goes wrong I'll at least have a way to notify the user, vs not being able to so if it I do that from native code, and we won't have to clutter up CUzeBox with this highly Android-specific stuff at all.

The more I type this out, the more I realize that this is probably the right way to proceed. Will your changes work if done in CUzeBoxActivity.java, or do they need to go in SDLActivity.java in between those two lines?
Post Reply