touchHLE icon indicating copy to clipboard operation
touchHLE copied to clipboard

Accelerometer not working on Android on some phones

Open pc6969 opened this issue 2 years ago • 21 comments
trafficstars

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

pc6969 avatar Sep 02 '23 01:09 pc6969

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

roomnoom avatar Sep 02 '23 02:09 roomnoom

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 avatar Sep 02 '23 04:09 hikari-no-yume

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.

hikari-no-yume avatar Sep 02 '23 13:09 hikari-no-yume

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

franzmcfreya avatar Sep 02 '23 21:09 franzmcfreya

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

SavunOski avatar Sep 03 '23 09:09 SavunOski

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

hikari-no-yume avatar Sep 03 '23 10:09 hikari-no-yume

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.

Raypuia avatar Sep 03 '23 23:09 Raypuia

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

Tetriser avatar Sep 08 '23 07:09 Tetriser

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

hikari-no-yume avatar Sep 11 '23 08:09 hikari-no-yume

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

hikari-no-yume avatar Sep 11 '23 13:09 hikari-no-yume

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 https://github.com/libgdx/libgdx/issues/5596)

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

ciciplusplus avatar Dec 21 '23 16:12 ciciplusplus

Log file from that user: log.txt

hikari-no-yume avatar Dec 21 '23 16:12 hikari-no-yume

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

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

mjcox244 avatar Apr 02 '24 13:04 mjcox244

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.

notprogramminggames avatar Apr 03 '24 16:04 notprogramminggames

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;
        }

Oscar1640 avatar Apr 15 '24 18:04 Oscar1640

The problem is not only on android but also on steam os (steam deck)

Steam deck doesn't use the same implementation, it would need to be custom for it.

mjcox244 avatar Apr 21 '24 17:04 mjcox244

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

hikari-no-yume avatar Apr 21 '24 17:04 hikari-no-yume

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?

ciciplusplus avatar May 14 '24 07:05 ciciplusplus

@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 avatar May 18 '24 03:05 Oscar1640

@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.

ciciplusplus avatar May 21 '24 17:05 ciciplusplus

Hello, please, touchscreen works perfectly on my phone, but why does Hero of Sparta 2 doom resistance residence evil crash?

postal12 avatar May 22 '24 16:05 postal12

Hello, please, touchscreen works perfectly on my phone, but why does Hero of Sparta 2 doom resistance residence evil crash?

you already have your answer here https://github.com/touchHLE/touchHLE/issues/311#issuecomment-2124538826, but you continue to produce off-topic messages. i'm blocking you from repo for 7 days, if you continue to produce off-topic messages and noise after that, you'll be blocked permanently

ciciplusplus avatar May 22 '24 17:05 ciciplusplus

A fix by @Oscar1640 has being merged here https://github.com/touchHLE/touchHLE/commit/a5e501c92eec00a634f00e4ccf8096d0d5f97e51 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.

ciciplusplus avatar Jun 19 '24 09:06 ciciplusplus

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

Tetriser avatar Jun 19 '24 11:06 Tetriser

Thanks for confirmation!

ciciplusplus avatar Jun 19 '24 11:06 ciciplusplus

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

hikari-no-yume avatar Jun 19 '24 11:06 hikari-no-yume

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

ciciplusplus avatar Jun 19 '24 11:06 ciciplusplus

I have a Xiaomi 10c MIUI 13 And it's sadly not working Touch works well only issue is with the Accelerometer

Getroekah avatar Sep 20 '24 10:09 Getroekah

I have a Xiaomi 10c MIUI 13 And it's sadly not working Touch works well only issue is with the Accelerometer

what is the version of touchHLE that you're using?

ciciplusplus avatar Sep 20 '24 10:09 ciciplusplus