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

Accelerometer not working on Android on some phones #151

Closed
pc6969 opened this issue Sep 2, 2023 · 30 comments
Closed

Accelerometer not working on Android on some phones #151

pc6969 opened this issue Sep 2, 2023 · 30 comments

Comments

@pc6969
Copy link

pc6969 commented Sep 2, 2023

It feels like version v0.2.0 is not very complete, some games like some games are not compatible and only some games are in the active list and there are a few versions that don't work, can't tilt the phone left or right to play racing and play games that require tilting and shaking the phone. Hopefully v0.3.0 will fix these 2 bugs

@roomnoom
Copy link

roomnoom commented Sep 2, 2023

gotta name it v0.0.0.0.2 to get the point across some people apparently

@hikari-no-yume
Copy link
Collaborator

hikari-no-yume commented Sep 2, 2023

some games are not compatible and only some games are in the active list

This emulator will never work with all early iPhone OS titles, and supporting a large number of them requires a huge amount of work. If someone told you that this emulator can run any iOS game, then please complain to them, not me. Obviously, I want to support more titles, but it's not like I can just snap my fingers and suddenly the entire library is available. Emulator development is not fast or easy.

can't tilt the phone left or right to play racing

The accelerometer is supposed to work, and it does for me. Can you tell me what phone you have, and what version of Android it's running?

@hikari-no-yume hikari-no-yume changed the title V0.2.0 version problem Accelerometer not working on Android Sep 2, 2023
@hikari-no-yume hikari-no-yume changed the title Accelerometer not working on Android Accelerometer not working on Android on some phones Sep 2, 2023
@hikari-no-yume
Copy link
Collaborator

Apparently someone has this issue on the “Redmi Note 9 4GB/128GB, running Android 12 and MIUI 13”. The highest Android version I've tested myself was Android 11, so perhaps that could be the problem.

@franzmcfreya
Copy link

franzmcfreya commented Sep 2, 2023

Apparently someone has this issue on the “Redmi Note 9 4GB/128GB, running Android 12 and MIUI 13”. The highest Android version I've tested myself was Android 11, so perhaps that could be the problem.

I was about to open an issue myself and found this, and yes accelerometer doesn't work on Redmi Note 12, Android 13 MIUI 14. I'm starting to think it's a Xiaomi issue but it does work in other apps. Please let me know if there's any way I could help. Great job on the emulator btw, nice progress y'all

@SavunOski
Copy link

Seems like a MIUI issue because it doesnt work for me as well (MIUI 14 with Android 12, Mi10T with Snapdragon 865), please let me know as well if there's any way I can help

@hikari-no-yume
Copy link
Collaborator

If anyone can test on an older MIUI version, that'd be helpful.

@Raypuia
Copy link

Raypuia commented Sep 3, 2023

It seems to be a specific issue with MIUI 14.
My phone is a Redmi Note 8 with MIUI 11 and accelerometer works flawlessly in touchHLE.

@Tetriser
Copy link

Tetriser commented Sep 8, 2023

Accelerometer doesn't work for me as well (Redmi 10C, MIUI 14, Android 13)

@hikari-no-yume
Copy link
Collaborator

Someone with “Android 10 on Redmi Note 7” also had problems. Very consistent Xiaomi pattern here…

@hikari-no-yume
Copy link
Collaborator

Someone with a “ZTE A7040” reported the same issue. That's the first non-Xiaomi, non-MIUI device. Huh.

@ciciplusplus
Copy link
Collaborator

Based on the logs obtained by some of MIUI user on Android I think the problem is that a fingerprint device is detected as a controller and take a precedence over accelerometer (same issue as libgdx/libgdx#5596)

I think filtering out uinput-fpc device from list of controllers reported by SDL may solve accelerometer issue on some Android phones

@hikari-no-yume
Copy link
Collaborator

Log file from that user: log.txt

@GuythatUhmCreatesRandomStuff

Apparently someone has this issue on the “Redmi Note 9 4GB/128GB, running Android 12 and MIUI 13”. The highest Android version I've tested myself was Android 11, so perhaps that could be the problem.

If i could test i could test the android 12 version, but i cant use the app since it crashes

@mjcox244
Copy link

mjcox244 commented Apr 2, 2024

Can confirm this issue still exists on 0.2.2 on HyperOS (miui) 1.0.4.0 (android 14) Poco F5

@notprogramminggames
Copy link

notprogramminggames commented Apr 3, 2024

On a Redmi Note 11 Pro+, with MIUI 14.0.7 and Android 13, the accelerometer won't work either. It might just be broken on models with fingerprint sensors on the power button.

@Oscar1640
Copy link
Contributor

Oscar1640 commented Apr 15, 2024

I managed to fix the problem, at least partially on some devices.

modifying the file in

touchHLE/vendor/SDL/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java

I added a filter to check that the fingerprint sensor is not a jostick:

// Check if a given device is considered a possible SDL joystick
 
   public static boolean isDeviceSDLJoystick(int deviceId) {
   
       InputDevice device = InputDevice.getDevice(deviceId);
       
       String deviceName = device.getName();
       
       // We cannot use InputDevice.isVirtual before API 16, so let's accept
       // only nonnegative device ids (VIRTUAL_KEYBOARD equals -1)
       
       if ((device == null) || (deviceId < 0) || deviceName.equals("uinput-fpc") || deviceName.equals("uinput-fortsense")) {
           return false;
       }

Or Alternatively

// Check if a given device is considered a possible SDL joystick
  
    public static boolean isDeviceSDLJoystick(int deviceId) {
    
        InputDevice device = InputDevice.getDevice(deviceId);
        
        String deviceName = device.getName();
        
        // We cannot use InputDevice.isVirtual before API 16, so let's accept
        // only nonnegative device ids (VIRTUAL_KEYBOARD equals -1)
        
        if ((device == null) || (deviceId < 0) || deviceName.matches("uinput-.*")) {
            return false;
        }

@omagadsamsa

This comment was marked as off-topic.

@mjcox244

This comment was marked as off-topic.

@omagadsamsa

This comment was marked as off-topic.

@hikari-no-yume
Copy link
Collaborator

I have hidden the comments about Steam Deck, it does not run Android so that's off-topic.

@ciciplusplus
Copy link
Collaborator

I managed to fix the problem, at least partially on some devices.

modifying the file in

touchHLE/vendor/SDL/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java

I added a filter to check that the fingerprint sensor is not a jostick:

// Check if a given device is considered a possible SDL joystick
 
   public static boolean isDeviceSDLJoystick(int deviceId) {
   
       InputDevice device = InputDevice.getDevice(deviceId);
       
       String deviceName = device.getName();
       
       // We cannot use InputDevice.isVirtual before API 16, so let's accept
       // only nonnegative device ids (VIRTUAL_KEYBOARD equals -1)
       
       if ((device == null) || (deviceId < 0) || deviceName.equals("uinput-fpc") || deviceName.equals("uinput-fortsense")) {
           return false;
       }

Or Alternatively

// Check if a given device is considered a possible SDL joystick
  
    public static boolean isDeviceSDLJoystick(int deviceId) {
    
        InputDevice device = InputDevice.getDevice(deviceId);
        
        String deviceName = device.getName();
        
        // We cannot use InputDevice.isVirtual before API 16, so let's accept
        // only nonnegative device ids (VIRTUAL_KEYBOARD equals -1)
        
        if ((device == null) || (deviceId < 0) || deviceName.matches("uinput-.*")) {
            return false;
        }

I do not have an affected device to confirm if it's working.

Regardless, I think we would prefer to not modify SDL Android code as it's currently just symlinked to the repo.
Can the same changes be implemented on the touchHLE side? Maybe inside controller_added() method of window.rs?

@Oscar1640
Copy link
Contributor

Oscar1640 commented May 18, 2024

@ciciplusplus My device is a Redmi 12c with Android 12 which is affected by this problem and the solution I proposed works

modify the controller_added() method in the window.rs file for not touch the SDL files as you suggested.

fn controller_added(&mut self, joystick_idx: u32) {
        let Ok(controller) = self.controller_ctx.open(joystick_idx) else {
            log!("Warning: A new controller was connected, but it couldn't be accessed!");
            return;
        };
        
        let controller_name = controller.name();
        if env::consts::OS == "android" {
        if controller_name.starts_with("uinput-") {
        
        return;
        
        }
        }
        log!(
            "New controller connected: {}. Left stick = device tilt. Right stick = touch input (press the stick or shoulder button to tap/hold).",
            controller_name
        );
        self.controllers.push(controller);
    }

@ciciplusplus
Copy link
Collaborator

@ciciplusplus My device is a Redmi 12c with Android 12 which is affected by this problem and the solution I proposed works

modify the controller_added() method in the window.rs file for not touch the SDL files as you suggested.

fn controller_added(&mut self, joystick_idx: u32) {
        let Ok(controller) = self.controller_ctx.open(joystick_idx) else {
            log!("Warning: A new controller was connected, but it couldn't be accessed!");
            return;
        };
        
        let controller_name = controller.name();
        if env::consts::OS == "android" {
        if controller_name.starts_with("uinput-") {
        
        return;
        
        }
        }
        log!(
            "New controller connected: {}. Left stick = device tilt. Right stick = touch input (press the stick or shoulder button to tap/hold).",
            controller_name
        );
        self.controllers.push(controller);
    }

@Oscar1640 Nice! Please follow https://github.com/touchHLE/touchHLE/blob/trunk/CONTRIBUTING.md to submit your patch set if you want it to be merged.

@postal12

This comment was marked as off-topic.

@ciciplusplus

This comment was marked as off-topic.

@ciciplusplus
Copy link
Collaborator

A fix by @Oscar1640 has being merged here a5e501c Many thanks for that!

Could someone with an impacted device confirm that problem is indeed fixed in the last trunk Android build?
Once confirmed, we can close this issue.

@Tetriser
Copy link

A fix by @Oscar1640 has being merged here a5e501c Many thanks for that!

Could someone with an impacted device confirm that problem is indeed fixed in the last trunk Android build? Once confirmed, we can close this issue.

I can confirm this build fixed the accelerometer issue

@ciciplusplus
Copy link
Collaborator

Thanks for confirmation!

@hikari-no-yume
Copy link
Collaborator

@ciciplusplus Will this be added to the changelog? I think it is the headline feature for a lot of Android users.

@ciciplusplus
Copy link
Collaborator

@hikari-no-yume yes, it should be there. will do chanelog update later

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