继续研究fingerprint在Android中的添加。上篇中HAL层的实现算是找到了,但是不知道是不是真的是这个,也不知道有没有被应用,既然驱动没有,那就往上看吧。
开机时会开启各种服务,我们从开始启动指纹识别的service开始。
路径:
framework/base/services/java/com/android/server/SystemServer.java
private void run() {
........
startOtherServices();
..........
}
private void startOtherServices() {
..............
//这部分代码在Android M上是没有的,但是Android N上有,所以就加在这了。
if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
mSystemServiceManager.startService(FingerprintService.class);
}
............
}
这里调用SystemServiceManager的startService来启动指纹识别服务。
路径:
frameworks/base/services/core/java/com/android/server/SystemServiceManager.java
public
T startService(Class serviceClass) {
..............
try {
service.onStart();
} catch (RuntimeException ex) {
throw new RuntimeException("Failed to start service " + name
+ ": onStart threw an exception", ex);
}
return service;
}
在FingerprintService.java中调用了onStart()
路径:
frameworks/base/services/core/java/com/android/server/fingerprint/FingerprintService.java
public void onStart() {
publishBinderService(Context.FINGERPRINT_SERVICE, new FingerprintServiceWrapper());
IFingerprintDaemon daemon = getFingerprintDaemon();
if (DEBUG) Slog.v(TAG, "Fingerprint HAL id: " + mHalDeviceId);
listenForUserSwitches();
}
接下来,先看看publishBinderService的实现,
路径:
frameworks/base/services/core/java/com/android/server/SystemService.java
protected final void publishBinderService(String name, IBinder service) {
publishBinderService(name, service, false);
}
protected final void publishBinderService(String name, IBinder service,
boolean allowIsolated) {
ServiceManager.addService(name, service, allowIsolated);
}
可以看到在ServiceManager.java中调用了addService
路径:
frameworks/base/core/java/android/os/ServiceManager.java
public static void addService(String name, IBinder service, boolean allowIsolated) {
try {
getIServiceManager().addService(name, service, allowIsolated);
} catch (RemoteException e) {
Log.e(TAG, "error in addService", e);
}
}
可以看到到这里真正的将指纹识别的服务加进去了,今天先到这,后面在继续。