直接给个结论: 在没有密码的情况下默认不使用滑动解锁屏
Set default lockscreen disabled
diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml
index bb128c5..43ef213 100644
--- a/packages/SettingsProvider/res/values/defaults.xml
+++ b/packages/SettingsProvider/res/values/defaults.xml
@@ -80,7 +80,7 @@
/system/media/audio/ui/Trusted.ogg
/system/media/audio/ui/WirelessChargingStarted.ogg
- false
+ true
false
1
打开"安全"设置读取配置
packages/apps/Settings/src/com/android/settings/SecuritySettings.java
其中isLockScreenDisabled是去读取def_lockscreen_disabled的值设置为true就不会开机自动锁屏
private static int getResIdForLockUnlockScreen(Context context,
LockPatternUtils lockPatternUtils, ManagedLockPasswordProvider managedPasswordProvider,
int userId) {
final boolean isMyUser = userId == MY_USER_ID;
int resid = 0;
if (!lockPatternUtils.isSecure(userId)) {
//当前用户没有密码,根据isLockScreenDisabled来选择不同的类型
if (!isMyUser) {
resid = R.xml.security_settings_lockscreen_profile;
} else if (lockPatternUtils.isLockScreenDisabled(userId)) {
//屏幕锁定: 无
resid = R.xml.security_settings_lockscreen;
} else {
//屏幕锁定: 滑动
resid = R.xml.security_settings_chooser;
}
} else {
//当前用户有密码,判断密码类型
switch (lockPatternUtils.getKeyguardStoredPasswordQuality(userId)) {
case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
resid = isMyUser ? R.xml.security_settings_pattern
: R.xml.security_settings_pattern_profile;
break;
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
resid = isMyUser ? R.xml.security_settings_pin
: R.xml.security_settings_pin_profile;
break;
case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
resid = isMyUser ? R.xml.security_settings_password
: R.xml.security_settings_password_profile;
break;
case DevicePolicyManager.PASSWORD_QUALITY_MANAGED:
resid = managedPasswordProvider.getResIdForLockUnlockScreen(!isMyUser);
break;
}
}
return resid;
}
final Preference lockPreference =
root.findPreference(KEY_UNLOCK_SET_OR_CHANGE_PROFILE);
锁屏ILockSettings.aidl调用锁屏服务LockSettingsService.java
frameworks/base/core/java/com/android/internal/widget/ILockSettings.aidl
读写设置, getLockSettings()调用ILockSettings.aidl
frameworks/base/core/java/com/android/internal/widget/LockPatternUtils.java
getLockSettings()获得lock settings的服务
private ILockSettings
getLockSettings() {
if (mLockSettingsService == null) {
ILockSettings service = ILockSettings.Stub.asInterface(
ServiceManager.getService("lock_settings"));
mLockSettingsService= service;
}
return mLockSettingsService;
}
getLong获得数据 - 加密类型
public final static String PASSWORD_TYPE_KEY = "lockscreen.password_type";
public int getKeyguardStoredPasswordQuality(int userHandle) {
return (int) getLong(
PASSWORD_TYPE_KEY,
DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, userHandle);
}
private long getLong(String secureSettingKey, long defaultValue, int userHandle) {
try {
return getLockSettings().getLong(secureSettingKey, defaultValue, userHandle);
} catch (RemoteException re) {
return defaultValue;
}
}
锁屏服务LockSettingsService.java
frameworks/base/services/core/java/com/android/server/LockSettingsService.java
初始化LockSettingsStorage存储数据
public LockSettingsService(Context context) {
mContext = context;
mHandler = new Handler();
mStrongAuth = new LockSettingsStrongAuth(context);
// Open the database
mLockPatternUtils = new LockPatternUtils(context);
mFirstCallToVold = true;
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_USER_ADDED);
filter.addAction(Intent.ACTION_USER_STARTING);
filter.addAction(Intent.ACTION_USER_REMOVED);
mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null);
mStorage = new LockSettingsStorage(context, new LockSettingsStorage.Callback() {
@Override
public void initialize(SQLiteDatabase db) {
// Get the lockscreen default from a system property, if available
boolean lockScreenDisable = SystemProperties.getBoolean(
"ro.lockscreen.disable.default", false);
if (lockScreenDisable) {
mStorage.writeKeyValue(db, LockPatternUtils.DISABLE_LOCKSCREEN_KEY, "1", 0);
}
}
});
mNotificationManager = (NotificationManager)
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
mStrongAuthTracker = new SynchronizedStrongAuthTracker(mContext);
mStrongAuthTracker.register();
}
获取getLong的值
public String getStringUnchecked(String key, String defaultValue, int userId) {
if (Settings.Secure.
LOCK_PATTERN_ENABLED.equals(key)) {
long ident = Binder.clearCallingIdentity();
try {
return mLockPatternUtils.isLockPatternEnabled(userId) ? "1" : "0";
} finally {
Binder.restoreCallingIdentity(ident);
}
}
if (LockPatternUtils.LEGACY_LOCK_PATTERN_ENABLED.equals(key)) {
key = Settings.Secure.LOCK_PATTERN_ENABLED;
}
// Settings.Secure.LOCK_PATTERN_ENABLED定义, 并不是我们要查的PASSWORD_TYPE_KEY = "lockscreen.password_type";
// frameworks/base/core/java/android/provider/Settings.java
// public static final String LOCK_PATTERN_ENABLED = "lock_pattern_autolock"; //Whether autolock is enabled (0 = false, 1 = true)
//读取数据 private final LockSettingsStorage mStorage;
return mStorage.readKeyValue(key, defaultValue, userId);
}
从LockSettingsStorage 读取数据
frameworks/base/services/core/java/com/android/server/LockSettingsStorage.java
一些数据库参数
private static final String TABLE = "
locksettings";
private static final String COLUMN_KEY = "name";
private static final String COLUMN_USERID = "user";
private static final String COLUMN_VALUE = "value";
private static final String SYSTEM_DIRECTORY = "/system/";
private static final String LOCK_PATTERN_FILE = "gatekeeper.pattern.key";
private static final String BASE_ZERO_LOCK_PATTERN_FILE = "gatekeeper.gesture.key";
private static final String LEGACY_LOCK_PATTERN_FILE = "gesture.key";
private static final String LOCK_PASSWORD_FILE = "gatekeeper.password.key";
private static final String LEGACY_LOCK_PASSWORD_FILE = "password.key";
private static final String CHILD_PROFILE_LOCK_FILE = "gatekeeper.profile.key";
数据保存的路径/data/system/locksettings.db
String dataSystemDirectory = android.os.Environment.getDataDirectory().getAbsolutePath() + SYSTEM_DIRECTORY;
打开数据库
public LockSettingsStorage(Context context, Callback callback) {
mContext = context;
mOpenHelper = new DatabaseHelper(context, callback);
mStoredCredentialType = new SparseArray();
}
读取数据
public String readKeyValue(String key, String defaultValue, int userId) {
int version;
synchronized (mCache) {
if (mCache.hasKeyValue(key, userId)) {
return mCache.peekKeyValue(key, defaultValue, userId);
}
version = mCache.getVersion();
}
Cursor cursor;
Object result = DEFAULT;
SQLiteDatabase db = mOpenHelper.getReadableDatabase();
if ((cursor = db.query(TABLE, COLUMNS_FOR_QUERY,
COLUMN_USERID + "=? AND " + COLUMN_KEY + "=?",
new String[] { Integer.toString(userId), key },
null, null, null)) != null) {
if (cursor.moveToFirst()) {
result = cursor.getString(0);
}
cursor.close();
}
mCache.putKeyValueIfUnchanged(key, result, userId, version);
return result == DEFAULT ? defaultValue : (String) result;
}
抛砖引玉, 仅供参考.