In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to analyze the Android vibrator system. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Platform MTK6573
Android vibrator system architecture
Driving layer
Hardware abstraction layer
JNI frame layer
Java application layer
1. Driver layer
Android modifies and adds Linux kernel files
/ kernel/drivers/staging/android/timed_output.h/kernel/drivers/staging/android/timed_output.c
Timed_output.h defines the timed_output_dev structure
Struct timed_output_dev {const char * name; / * enable the output and set the timer * / void (* enable) (struct timed_output_dev * sdev, int timeout); / * returns the current number of milliseconds remaining on the timer * / int (* get_time) (struct timed_output_dev * sdev); / * private data * / struct device * dev; int index; int state;}
Timed_output.c implements the structure, using the function timed_output_dev_register to register and timed_output_dev_unregister to log out.
Int timed_output_dev_register (struct timed_output_dev * tdev) {int ret; if (! tdev | |! tdev- > name | |! tdev- > enable | |! tdev- > get_time) return-EINVAL; ret = create_timed_output_class (); if (ret
< 0) return ret; tdev->Index = atomic_inc_return (& device_count); tdev- > dev = device_create (timed_output_class, NULL, MKDEV (0, tdev- > index), NULL, tdev- > name); if (IS_ERR (tdev- > dev)) return PTR_ERR (tdev- > dev); ret = device_create_file (tdev- > dev, & dev_attr_enable); if (ret
< 0) goto err_create_file; dev_set_drvdata(tdev->Dev, tdev); tdev- > state = 0; return 0; err_create_file: device_destroy (timed_output_class, MKDEV (0, tdev- > index)); printk (KERN_ERR "timed_output: Failed to register driver% s\ n", tdev- > name); return ret;} EXPORT_SYMBOL_GPL (timed_output_dev_register) Void timed_output_dev_unregister (struct timed_output_dev * tdev) {device_remove_file (tdev- > dev, & dev_attr_enable); device_destroy (timed_output_class, MKDEV (0, tdev- > index)); dev_set_drvdata (tdev- > dev, NULL);} EXPORT_SYMBOL_GPL (timed_output_dev_unregister)
Driver to achieve migration
Take MTK 6573 platform as an example
. / mediatek/platform/mt6573/kernel/drivers/vibrator/vibrator.c
Operating equipment
First, open the phone to debug, connect to USB, execute adb shell, and enter / sys/devices/timed_output/vibrator/
Execute echo "10000" enable and find the phone is vibrating
# echo "10000" enable echo "10000" enable 10000 enable
Execute cat enable to view the current vibration time remaining:
# cat enable cat enable 0
Second, hardware abstraction layer
Android encapsulates the call to the underlying driver and becomes the hardware abstraction layer.
/ hardware/libhardware_legacy/vibrator/vibrator.c
Int vibrator_on (int timeout_ms) {/ * constant on, up to maximum allowed time * / return sendit (timeout_ms);} int vibrator_off () {return sendit (0);}
Third, JNI framework layer
The Android JNI framework layer makes it easy for Java to call the Cmax Cobb + method.
. / frameworks/base/services/jni/com_android_server_VibratorService.cpp
Namespace android {static void vibratorOn (JNIEnv * env, jobject clazz, jlong timeout_ms) {/ / LOGI ("vibratorOn\ n"); vibrator_on (timeout_ms);} static void vibratorOff (JNIEnv * env, jobject clazz) {/ / LOGI ("vibratorOff\ n"); vibrator_off () } static JNINativeMethod method_table [] = {{"vibratorOn", "(J) V", (void*) vibratorOn}, {"vibratorOff", "() V", (void*) vibratorOff}}; int register_android_server_VibratorService (JNIEnv * env) {return jniRegisterNativeMethods (env, "com/android/server/VibratorService", method_table, NELEM (method_table));}}
4. Java application layer
This layer includes Java application invocation, Android system service Java layer
. / frameworks/base/services/java/com/android/server/VibratorService.java
On how to analyze the Android vibrator system to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.