Open AndyCGYan opened 3 years ago
That's uh fun, there is no vibrator HAL at all?!
K uh, got a dump of stock ROM?
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.
Interesting, so it's (again) implementing custom patterns alongside linear motor.
vibrator on is
echo 1 > /sys/class/timed_output/vibrator/enable
; vibrator off isecho 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.
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
Weird, it doesn't seem to work the way you analyzed...
echo $durationInMs > /sys/class/timed_output/vibrator/enable
where durationInMs ≤ 50 triggers the same short vibe as beforeecho $durationInMs > /sys/class/timed_output/vibrator/enable
where durationInMs > 50 triggers a constant but "loose" (for the lack of a better word) vibeUpdating recent findings here for documentation sake:
$amplitude
does work but in a subtle way - the range is [1, 255], and the difference is hard to notice./sys/class/timed_output/vibrator/enable
can't be read, states "I/O error"./sys/class/timed_output/vibrator/activate
and /sys/class/timed_output/vibrator/duration
nodes, which aren't referenced in the framework - these work to an extent, but seems like there's some other precursory node that needs to be set (by triggering a vibration from the OS) before they work as intended.HapticFeedbackConstants
class.Solved by implementing a vibrator HAL - details and PR soon.
PR here: https://github.com/phhusson/device_phh_treble/pull/266
/sys/class/timed_output/vibrator/enable
takes duration and (optionally) amplitude as parameter, but since amplitude can't be set on its own, I set supportsAmplitudeControl()
to false. Default amplitude is the maximum 255./sys/class/meizu/motor/waveform
takes waveform IDs corresponding to different forms of oneshot vibration. The two used most by stock are 1 (short tap) and 13 (medium strength long vibe); I tried and found out 10, 11, 12 are stronger long vibes, but 10 and 11 are so strong they might damage the device, so I chose 12./sys/class/meizu/motor/on_off
takes RTP effect IDs from the HapticFeedbackConstants
class. @xingrz 's 1.3 implementation already laid out handily how they correspond to native effects.
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.txtdumpsys sensorservice
: sensorservice.txt Logcat since boot on GSI: log-since-boot.txt