pelya / android-keyboard-gadget

Convert your Android device into USB keyboard/mouse, control your PC from your Android device remotely, including BIOS/bootloader.
Apache License 2.0
1.25k stars 314 forks source link

regression when updating from version 1.05 to 1.06 #18

Closed benoit-pierre closed 9 years ago

benoit-pierre commented 9 years ago

I have 2 devices:

Version 1.05 works fine on both:

With the latest 1.06 version however:

One difference before and after running 1.05 is the devices rights.

Before:

> adb shell ls -l /dev/hidg\*
crw------- root     root     244,   0 2014-11-30 15:24 hidg0
crw------- root     root     244,   1 2014-11-30 15:24 hidg1

After:

> adb shell ls -l /dev/hidg\*
crw------- u0_a62   root     244,   0 2014-11-30 15:24 hidg0
crw------- u0_a62   root     244,   1 2014-11-30 15:24 hidg1
pelya commented 9 years ago

I've pushed a fix, please tell me if it works for you.

On Sun, Nov 30, 2014 at 4:36 PM, Benoit Pierre notifications@github.com wrote:

I have 2 devices:

  • a Sony Xperia Tipo running CyanogenMod 10 (Jelly Bean 4.1.2), with a kernel patched with your HID patch (3.0.8)
  • a Nexus 7 (2013) running CyanogenMod 11 (KitKat 4.4.4), still using the CyanogenMod kernel (so without the HID patch)

Version 1.05 works fine on both:

  • on the Tipo, mouse and keyboard work fine
  • on the Nexus, of course I get the screen telling me a custom kernel is needed

With the latest 1.06 version however:

  • on the Nexus: I get left with a black screen after the SDL splash screen and allowing root access
  • on the Tipo: it works fine, if version 1.05 has been started before, but I get the same thing as the Nexus after rebooting

One difference before and after running 1.05 is the devices rights.

Before:

adb shell ls -l /dev/hidg* crw------- root root 244, 0 2014-11-30 15:24 hidg0 crw------- root root 244, 1 2014-11-30 15:24 hidg1

After:

adb shell ls -l /dev/hidg* crw------- u0_a62 root 244, 0 2014-11-30 15:24 hidg0 crw------- u0_a62 root 244, 1 2014-11-30 15:24 hidg1

— Reply to this email directly or view it on GitHub https://github.com/pelya/android-keyboard-gadget/issues/18.

benoit-pierre commented 9 years ago

It works fine on the Tipo, but I still get a black screen on the Nexus. It seems the code does not detect that the devices are missing; as I can see from the traces it's trying to fix the permissions on those:

I/HID keyboard( 9490): void changeDevicePermissions(): echo chown 10107 /dev/hidg0 /dev/hidg1 | su
I/HID keyboard( 9490): void changeDevicePermissions(): echo chmod 600 /dev/hidg0 /dev/hidg1 | su

Also, looking at the code, there is no check for the exit status of those commands.

pelya commented 9 years ago

Yes, the problem is that on Lollipop the /dev directory cannot be searched, so I've used a trick with su command to determine if these files exist, but this trick does not work on your device. More improvements are necessary, but at least it's not broken now.

On Mon, Dec 1, 2014 at 10:52 PM, Benoit Pierre notifications@github.com wrote:

It works fine on the Tipo, but I still get a black screen on the Nexus. It seems the code does not detect that the devices are missing; as I can see from the traces the code is trying to fix the permissions on those:

I/HID keyboard( 9490): void changeDevicePermissions(): echo chown 10107 /dev/hidg0 /dev/hidg1 | su I/HID keyboard( 9490): void changeDevicePermissions(): echo chmod 600 /dev/hidg0 /dev/hidg1 | su

Also, looking at the code, there is no check for the exit status of those commands.

— Reply to this email directly or view it on GitHub https://github.com/pelya/android-keyboard-gadget/issues/18#issuecomment-65132696 .

benoit-pierre commented 9 years ago

OK, so I took a closer look at this, and it's still possible to check for the devices existence on Lollipop; since stat will return an error whether or not the device is present, but errno will be different:

Here is a patch for this:

diff --git i/remote-client/input.cpp w/remote-client/input.cpp
index d3c2bc8..0d8dddd 100644
--- i/remote-client/input.cpp
+++ w/remote-client/input.cpp
@@ -131,16 +131,24 @@ static void changeDevicePermissions()
    system(cmd);
 }

-static int devicesExist()
+static int deviceExist(const char *path)
 {
    struct stat st;
-   if (stat(DEV_KEYBOARD, &st) == 0 && stat(DEV_MOUSE, &st) == 0)
-       return 1;
-   return 0;
+
+   /*
+   ** On Lollipop, we don't have permission to stat a device; but we know
+   ** it exists because errno is set to EACCES, and not ENOENT.
+   */
+   return 0 == stat(path, &st) || EACCES == errno;
 }

 void openInput()
 {
+   if( !deviceExist(DEV_KEYBOARD) || !deviceExist(DEV_MOUSE) )
+   {
+       flashCustomKernel();
+       return;
+   }
    openDevices();
    if( keyboardFd == -1 || mouseFd == -1 )
    {
@@ -151,7 +159,7 @@ void openInput()
    {
        openDevicesSuperuser();
    }
-   if( (keyboardFd == -1 || mouseFd == -1) && devicesExist() )
+   if( (keyboardFd == -1 || mouseFd == -1) )
    {
        char cmd[256];
        createDialog();

Tested on my Tipo and Nexus 7 (updated to stock Lollipop), with and without a kernel patched with USB HID gadget support.

pelya commented 9 years ago

Merged that, thanks. I'll add one feature to the app, and publish an update, in a week or so.

pelya commented 9 years ago

On the second thought, I've pushed an update, with just this patch. The feature I want to implement might take a lot of time.