LockSettingsService.java
文件目录:/frameworks/base/services/java/com/android/server
与其它重要的系统Service一样,会在SystemServer中启动,它提供的服务名称为“lock_settings”
SystemServer.java initAndLoop()
lockSettings = new LockSettingsService(context);
ServiceManager.addService("lock_settings", lockSettings);
它继承ILockSettings接口,个人目前只关注下面几个方法:
interface ILockSettings {
void setLockPattern(in String pattern, int userId);
boolean checkPattern(in String pattern, int userId);
void setLockPassword(in String password, int userId);
boolean checkPassword(in String password, int userId);
boolean havePattern(int userId);
boolean havePassword(int userId);
void removeUser(int userId);
}
这些方法可以帮助我们设置、校验和判断是否存在图案解锁/密码解锁。
可以看到,每个方法都会传入一个userId的参数,需要留意,它应该是android为实现多用户而添加的。
无论是图案解锁还是密码解锁,密码是以srting类型传入的。
再看LockSettingsService是如何实现这几个方法的:
密码解锁和图案解锁设置后,会生成如下的文件;用户解锁时输入密码的正确与否就是要来通过已保存的文件进行比对;如果有如下文件,则表明havePattern或havePassword:
/data/system/gesture.key
/data/system/password.key
另外还有一个数据库:/data/system/locksettings.db,里面只有一个table:locksettings