从Android的官方API可以查到,向上层提供接口的是FingerprintManager,它的代码在路径frameworks/base/core/java/android/hardware/fingerprint下。
/**
* A class that coordinates access to the fingerprint hardware.
* @deprecated See {@link BiometricPrompt} which shows a system-provided dialog upon starting
* authentication. In a world where devices may have different types of biometric authentication,
* it's much more realistic to have a system-provided authentication dialog since the method may
* vary by vendor/device.
*/
@Deprecated
@SystemService(Context.FINGERPRINT_SERVICE)
@RequiresFeature(PackageManager.FEATURE_FINGERPRINT)
public class FingerprintManager implements BiometricFingerprintConstants
frameworks/base/core/java/android/hardware/fingerprint目录下内容其实很少,一共只有几个文件。
这里除了FingerprintManager之外,就只有Fingerprint一个类了,其他都是aidl文件。
粗略的看了下Fingerprint类,它里面的内容超级少,主要是包含了几个成员变量,用来记录指纹的信息。
/**
* Container for fingerprint metadata.
* @hide
*/
public final class Fingerprint extends BiometricAuthenticator.BiometricIdentifier {
private CharSequence mName;
private int mGroupId;
private int mFingerId;
private long mDeviceId; // physical device this is associated with
public Fingerprint(CharSequence name, int groupId, int fingerId, long deviceId) {
mName = name;
mGroupId = groupId;
mFingerId = fingerId;
mDeviceId = deviceId;
}
//...
}
如果仔细看代码的话,可以发现一个很神奇的东西,那个就Fingerprint类的所有成员都是private的,并且没有提供任何public的set方法!
这个就厉害了,因为有做过指纹部分的朋友一定记得指纹提供一个rename的接口。没有public的set方法,那它又是怎么实现rename接口的呢?
带着问题看源码!
rename方法在Manager中的实现如下:
/**
* Renames the given fingerprint template
* @param fpId the fingerprint id
* @param userId the user who this fingerprint belongs to
* @param newName the new name
*
* @hide
*/
@RequiresPermission(MANAGE_FINGERPRINT)
public void rename(int fpId, int userId, String newName) {
// Renames the given fpId
if (mService != null) {
try {
mService.rename(fpId, userId, newName);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} else {