Skip to content

Commit

Permalink
Upgrade to Android 11
Browse files Browse the repository at this point in the history
  • Loading branch information
xarantolus committed May 27, 2021
1 parent cbc2417 commit f42e21f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 24 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ There are three different commands:
### Supported phones
Whether or not this works on your phone might not only depend on the model used, but also the operating system. Different variants of Android might not behave in the way this module expects them to.

The only system I tested this on is [LineageOS 17.1](https://lineageos.org/) for the [Xiaomi Mi Mix 2](https://wiki.lineageos.org/devices/chiron) in combination with [Magisk 21.4](https://github.com/topjohnwu/Magisk).
The only system I tested this on is [LineageOS 18.1](https://lineageos.org/) (Android 11) for the [Xiaomi Mi Mix 2](https://wiki.lineageos.org/devices/chiron) in combination with [Magisk 23.0](https://github.com/topjohnwu/Magisk). The older version (before 2021-05-27 / last commit with it is `cbc2417`) worked on LineageOS 17.1 (Android 10), but I no longer use that version.

The program is very device specific and will very likely not work at all if you don't have the *exact* same configuration. It should however be possible to [adapt the program](#adapting-to-other-phones) to run on your phone.

This program *might* work on your phone if all of these conditions are met:
* You have Magisk installed
* The command `echo -n 200 > /sys/devices/virtual/timed_output/vibrator/enable` in a root shell vibrates your phone
* You have adb logs enabled ("Log buffer size" in developer options should *not* be set to "Off")
* The commands `echo -n 200 > /sys/class/leds/vibrator/duration && echo -n 1 > /sys/class/leds/vibrator/activate` in a root shell vibrates your phone
* The `singletap` executable (that can be built from [`cmd/singletap/main.go`](cmd/singletap/main.go)) correctly taps the top left of your screen
* The output of `getevent -pl` (again, in a root shell on your phone) looks something like this (`/dev/input/event0` (power button) and `/dev/input/event1` (display) are particularly important)

Expand Down Expand Up @@ -138,7 +137,7 @@ If that's the case, you can run...
If not, you have to look into what the `GOARCH` environment variable does and then edit `build.sh` to use the correct value for your phone.

### Adapting to other phones
Adapting this program to run on other phone models and configurations should be possible. You would have to change the `logcat` line that is detected and the way these commands are executed. It is likely that the names of input devices differ. The way the touchscreen tap works should be the same, as that's based on on a protocol that seems to have been used for quite a long time by many different companies (since it's part of Linux).
Adapting this program to run on other phone models and configurations should be possible. You would have to change the `logcat` line that is detected and the way these commands are executed. It is likely that the names of input devices differ. The way the touchscreen tap works should be the same, as that's based on on the Linux multitouch protocol.

### [License](LICENSE)
This is free as in freedom software. Do whatever you like with it.
14 changes: 1 addition & 13 deletions cmd/backtap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ func main() {

// Open all device files we want to write to

// Vibrator: When we write a number as string, the devices vibrates for that amount in milliseconds
debug("opening vibrator device")
vibratorDevice, err := os.OpenFile("/sys/devices/virtual/timed_output/vibrator/enable", os.O_WRONLY, os.ModeDevice)
if err != nil {
panic("cannot open vibrator device: " + err.Error())
}
defer vibratorDevice.Close()

// Key: This input allows us to simulate a power button press
debug("opening key device")
keyDevice, err := os.OpenFile("/dev/input/event0", os.O_WRONLY, os.ModeDevice)
Expand Down Expand Up @@ -139,7 +131,7 @@ func main() {
case <-buttonAbort:
debug("aborted APP_SWITCH command")
return
case <-time.After(250 * time.Millisecond):
case <-time.After(200 * time.Millisecond):
debug("Running APP_SWITCH command")

backButtonLock.Lock()
Expand All @@ -150,10 +142,6 @@ func main() {
if err != nil {
panic("pressing APP_SWITCH button: " + err.Error())
}
err = input.Vibrate(vibratorDevice, 50)
if err != nil {
panic("cannot vibrate: " + err.Error())
}
debug("Finished APP_SWITCH command")
}
}()
Expand Down
2 changes: 1 addition & 1 deletion input/buttons.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

/*
Press power button:
$ getevents
$ getevent
/dev/input/event0: 0001 0074 00000001
/dev/input/event0: 0000 0000 00000000
Expand Down
38 changes: 34 additions & 4 deletions input/vibrate.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
package input

import (
"io"
"os"
"path/filepath"
"strconv"
)

func Vibrate(device io.Writer, ms int) (err error) {
_, err = device.Write([]byte(strconv.Itoa(ms)))
return
// Vibrate vibrates the device (duh). The vibratorPath is **not** a device file,
// but rather the path to the device directory.
// It is probably /sys/class/leds/vibrator/, but it could depend on the device.
// Also see https://stackoverflow.com/a/62678837
func Vibrate(vibratorPath string, milliseconds int) (err error) {
// At first, we write the duration (as string) to the file named "duration",
// then we activate it by writing "1" to the file named "activate"

// I do not know who thought that it is a good idea to have the
// vibration device under LEDS, but it sure as hell is confusing

err = writeInt(filepath.Join(vibratorPath, "duration"), milliseconds)
if err != nil {
return
}

return writeInt(filepath.Join(vibratorPath, "activate"), 1)
}

func writeInt(path string, i int) (err error) {
f, err := os.OpenFile(path, os.O_WRONLY, os.ModeDevice)
if err != nil {
return
}

_, err = f.Write([]byte(strconv.Itoa(i)))
if err != nil {
_ = f.Close()
return
}

return f.Close()
}
4 changes: 2 additions & 2 deletions module/backtap/module.prop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id=backtap
name=backtap
version=v1.0
versionCode=00100
version=v2.0
versionCode=00200
author=xarantolus
description=Enables several gestures when tapping the fingerprint sensor of a Xiaomi Mi Mix 2

0 comments on commit f42e21f

Please sign in to comment.