上层应用:
Vibrator mVibrator;
mVibrator.vibrate( );
a) 上层调用:
Vibrator.java
public void vibrate(long milliseconds)
{
mService.vibrate(milliseconds, mToken);
}
ps:
其中mService = IVibratorService.Stub.asInterface(
ServiceManager.getService("vibrator"));
b) AIDL处理
(IVibratorService.aidl)
VibratorService.java
public class VibratorService extends IVibratorService.Stub
{
public void vibrate(long milliseconds, IBinder token) {
Vibration vib = new Vibration(token, milliseconds, uid);
startVibrationLocked(vib);
}
private void startVibrationLocked(final Vibration vib) {
vibratorOn(vib.mTimeout);
}
}
}
c) JNI 转化(JAVA -->C/C++)
com_android_server_VibratorService.cpp
static JNINativeMethod method_table[] = {
{ "vibratorOn", "(J)V", (void*)vibratorOn },
{ "vibratorOff", "()V", (void*)vibratorOff }
};
static void vibratorOn(JNIEnv *env, jobject clazz, jlong timeout_ms)
{
LOGI("com_android_server_VibratorService.cpp libin vibratorOn\n");
vibrator_on(timeout_ms);
}
d) 底层处理
vibrator.c
int vibrator_on(int timeout_ms)