(一)去掉锁屏功能,1,

frameworks\base\packages\SettingsProvider\res\values\defaults.xml,<bool name="def_lockscreen_disabled">true</bool>这个之本来是false,(改后进入shell删除data/data/com.android.providers.settings/databases/settings.db),

2,重新编译settingsProviders,   push进去,重启设备,这样锁屏功能就没了,随便你在setting-》安全里面还能看到选项,但是锁屏是没用的


1,锁屏文件源码位置:Z:\myandroid\packages\apps\Settings\src\com\android\settings\ChooseLockGeneric.java

2,假如想删除其他锁屏方式,只剩下密码锁

private void updatePreferencesOrFinish() {
Intent intent = getActivity().getIntent();
int quality = intent.getIntExtra(LockPatternUtils.PASSWORD_TYPE_KEY, -1);
if (quality == -1) {
// If caller didn't specify password quality, show UI and allow the user to choose.
quality = intent.getIntExtra(MINIMUM_QUALITY_KEY, -1);
MutableBoolean allowBiometric = new MutableBoolean(false);
quality = upgradeQuality(quality, allowBiometric);
final PreferenceScreen prefScreen = getPreferenceScreen();
if (prefScreen != null) {
prefScreen.removeAll();
}
addPreferencesFromResource(R.xml.security_settings_picker);
//wdh add 这里remove掉就可以了
getPreferenceScreen().removePreference(findPreference(KEY_UNLOCK_SET_OFF));
getPreferenceScreen().removePreference(findPreference(KEY_UNLOCK_SET_PIN));
getPreferenceScreen().removePreference(findPreference(KEY_UNLOCK_SET_PATTERN));
getPreferenceScreen().removePreference(findPreference(KEY_UNLOCK_SET_BIOMETRIC_WEAK));
getPreferenceScreen().removePreference(findPreference(KEY_UNLOCK_SET_NONE));disableUnusablePreferences(quality, allowBiometric);
} else {
updateUnlockMethodAndFinish(quality, false);
}
}

3,下面是看到的一篇文章,详细介绍密码锁:

Android M 之前锁屏密码的存储

/data/system/locksettings.db 中。密码在存储的时候,会将输入的密码加上此随机数组成新的字符串。然后对新的字符串分别进行 SHA-1 和 MD5 加密,将加密后的密文通过 MD5 + SHA-1 的方式进行字符串拼接,组成新的密文存储在 /data/system/password.key

/data/system # cat password.key
B40C2F6FE4E89F3386D4E689B135304410D64951914FB35770FDAC58B694177B29297A80


/data/system/device_policies.xml

/data/system # cat device_policies.xml
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<policies setup-complete="true">
<active-password quality="196608" length="4" uppercase="0" lowercase="0" letters="0" numeric="4" symbols="0" nonletter="4" />
</policies>


其中主要用到的两个字段 quality 是密码的类型,简单密码和复杂密码的值不同,length 是密码的长度,其他字段存储密码中各种字符的数量。

Android M 中锁屏密码的存储

/system/gatekeeper/include/gatekeeper/password_handle.h

typedef uint64_t secure_id_t;
typedef uint64_t salt_t;
/**
 * structure for easy serialization
 * and deserialization of password handles.
 */
static const uint8_t HANDLE_VERSION = 2;
struct __attribute__ ((__packed__)) password_handle_t {
    // fields included in signature
    uint8_t version;
    secure_id_t user_id;
    uint64_t flags;

    // fields not included in signature
    salt_t salt;
    uint8_t signature[32];

    bool hardware_backed;
};

typedef uint64_t secure_id_t;
typedef uint64_t salt_t;
/**
 * structure for easy serialization
 * and deserialization of password handles.
 */
static const uint8_t HANDLE_VERSION = 2;
struct __attribute__ ((__packed__)) password_handle_t {
    // fields included in signature
    uint8_t version;
    secure_id_t user_id;
    uint64_t flags;

    // fields not included in signature
    salt_t salt;
    uint8_t signature[32];

    bool hardware_backed;
};


其中 version 默认是 2,user_id 是 Android 用户 id ,signature 存储的便是密文,hardware_backed 存储的是加密方式,0 表示密文是软件加密,而 1 表示密文是通过 TEE 环境进行加密得到的。

password_handle_t 格式存储在 /data/system/gatekeeper.password.key 中。密码的生成和校验,在 HAL 层是通过 system/core/gatekeeperd/gatekeeperd.cpp 中的函数实现的。其在系统启动时被注册为 gatekeeperd 服务,服务在启动的时候会调用 GateKeeperProxy()system/core/gatekeeperd/gatekeeperd.cpp

int verify(uint32_t uid, const uint8_t *enrolled_password_handle,
            uint32_t enrolled_password_handle_length,
            const uint8_t *provided_password, uint32_t provided_password_length,
            bool *request_reenroll)


system/core/gatekeeperd/SoftGateKeeperDevice.cpp

int SoftGateKeeperDevice::verify(uint32_t uid,
    uint64_t challenge, const uint8_t *enrolled_password_handle,
    uint32_t enrolled_password_handle_length, const uint8_t *provided_password,
    uint32_t provided_password_length, uint8_t **auth_token, uint32_t *auth_token_length,
    bool *request_reenroll)


system/gatekeeper/gatekeeper.cpp

void GateKeeper::Verify(const VerifyRequest &request, VerifyResponse *response)


进行处理,在这里对参数进行一系列处理和重新组织后再交给


bool GateKeeper::DoVerify(const password_handle_t *expected_handle, const SizedBuffer &password)


进行校验,在此函数中,再调用


bool GateKeeper::CreatePasswordHandle(SizedBuffer *password_handle_buffer, salt_t salt,
    secure_id_t user_id, uint64_t flags, uint8_t handle_version, const uint8_t *password,
    uint32_t password_length)


/data/system/gatekeeper.password.key

ComputePasswordSignature(password_handle->signature, sizeof(password_handle->signature),
            password_key, password_key_length, to_sign, sizeof(to_sign), salt);


system/core/gatekeeperd/SoftGateKeeper.h

crypto_scrypt(password, password_length, reinterpret_cast<uint8_t *>(&salt),
        sizeof(salt), N, r, p, signature, signature_length);

crypto_scrypt(password, password_length, reinterpret_cast<uint8_t *>(&salt),
        sizeof(salt), N, r, p, signature, signature_length);


将输入的密码存储在 signature 中并返回。此函数最终会通过 SHA256 进行加密,参数中的 N, r, p 默认为如下值:


static const uint64_t N = 16384;
static const uint32_t r = 8;
static const uint32_t p = 1;


通过以上处理后对输入的密码加密后得到的密文与手机中存储的密文进行比较后返回校验结果,从而判断输入的密码的正确与否。

在 Android M 中,改变了之前直接在 Java 层进行密码校验的方式,将密码的校验通过 HAL 层的服务进行处理,同时加入对 TEE 的支持,使得锁屏密码的安全性大大提升,同时也可以方便的支持其他的安全特性,提升了整个系统的安全性。