phhusson / treble_experimentations

Notes about tinkering with Android Project Treble
3.41k stars 659 forks source link

[Meizu 18] No vibration #1891

Open AndyCGYan opened 3 years ago

AndyCGYan commented 3 years ago

Device: Meizu 18 (meizu_18_CN) PHH AOSP version: v309 Vendor version: R (Flyme 9)

No vibration anywhere in the OS. Logcat notably says: E servicemanager: Could not find android.hardware.vibrator.IVibrator/default in the VINTF manifest.

lshal on stock and GSI: lshal-stock.txt, lshal-gsi.txt dumpsys sensorservice: sensorservice.txt Logcat since boot on GSI: log-since-boot.txt

phhusson commented 3 years ago

That's uh fun, there is no vibrator HAL at all?!

K uh, got a dump of stock ROM?

AndyCGYan commented 3 years ago

Dumped: here

phhusson commented 3 years ago

Ok so vibrator events go to android.os.FlymeVibratorHelper

It directly access /sys

.field private static final BACK_STRENGTH:Ljava/lang/String; = "/sys/class/meizu/motor/set_mback"
.field private static final CONTROL_PATH_EFFECT:Ljava/lang/String; = "/sys/class/meizu/motor/on_off"
.field private static final CONTROL_PATH_RTP:Ljava/lang/String; = "/sys/class/meizu/motor/rtp"
.field private static final CONTROL_PATH_TIMEOUT:Ljava/lang/String; = "/sys/class/timed_output/vibrator/enable"
.field private static final PATH_WAVE_NUMBER:Ljava/lang/String; = "/sys/class/meizu/motor/waveform"
.field private static final PRESSURE_STRENGTH:Ljava/lang/String; = "/sys/class/meizu/motor/set_cspress"
.field private static final RTPID_PATH:Ljava/lang/String; = "/sys/class/meizu/motor/set_rtp"

vibrator on is echo 1 > /sys/class/timed_output/vibrator/enable; vibrator off is echo 0 > /sys/class/timed_output/vibrator/enable

I don't know how this works, but /sys/class/meizu/motor/set_mback contains the force of the feedback when pressing back key, it can be "2 0" for weakest, "1 0" for half, "0 0" for strongest.

Likewise, with /sys/class/meizu/motor/set_cspress for home key

There are some pre-set """musics""", which are triggered by writing their id to /sys/class/meizu/motor/rtp; Some can probably be mapped to android.hardware.vibrator@1.3::Effect. Only effect id i have is 5105 and 5001. By following flyme_phone_ringid and flyme_alarm_ringid it's possible to find more.

AndyCGYan commented 3 years ago

Interesting, so it's (again) implementing custom patterns alongside linear motor.

vibrator on is echo 1 > /sys/class/timed_output/vibrator/enable; vibrator off is echo 0 > /sys/class/timed_output/vibrator/enable

FYI, doing this on GSI triggers a very short vibe (like tapping a key) instead of a constant one.

phhusson commented 3 years ago

Well implementing custom pattern is the main usage of linear motor

Uh yeah, misread, syntax for enable is echo $durationInMs $amplitude > /sys/class/timed_output/vibrator/enable so echo 100 will do a 100ms duration, at default amplitudee I have no idea what are the possible amplituds

AndyCGYan commented 3 years ago

Weird, it doesn't seem to work the way you analyzed...

AndyCGYan commented 3 years ago

Updating recent findings here for documentation sake:

AndyCGYan commented 3 years ago

Solved by implementing a vibrator HAL - details and PR soon.

AndyCGYan commented 3 years ago

PR here: https://github.com/phhusson/device_phh_treble/pull/266