(基于framework 目录下)
一、base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
开机执行到:systemReady()方法,调用 mKeyguardMediator.onSystemReady();开始锁屏
修改是否锁屏
public void systemReady() {
if (mKeyguardMediator != null) {
try {
//自己添加的,一个变量,如果是0,表示不锁屏,其他锁屏
int lock=Settings.System.getInt(mContext.getContentResolver(), "password_switch");
if(lock!=0){
mKeyguardMediator.onSystemReady();
}
} catch (SettingNotFoundException e) {
}
}
synchronized (mLock) {
updateOrientationListenerLp();
mSystemReady = true;
mHandler.post(new Runnable() {
public void run() {
updateSettings();
}
});
}
}
二、base/policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewMediator.java
执行:onSystemReady()方法,
设置锁屏超时时间:
修改 base\services\java\com\android\server\power\PowerManagerService.java
文件中的 MINIMUM_SCREEN_OFF_TIMEOUT 常量,默认为 10*1000.
private boolean mExternallyEnabled = true; 此变量控制是否显示锁屏,true 锁,false 不锁
三、直接显示密码输入界面:
base/policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java
修改:void showPrimarySecurityScreen(boolean turningOff)方法体,
showSecurityScreen(securityMode);==>showSecurityScreen(SecurityMode.SimPin);
四、解锁失败后,直接关机:
base/services/java/com/android/server/power/PowerManagerService.java
修改:private void updateDisplayPowerStateLocked 方法体:
添加:shutdown(false,false);
if (newScreenState != mDisplayPowerRequest.screenState) {
if (newScreenState == DisplayPowerRequest.SCREEN_STATE_OFF
&& mDisplayPowerRequest.screenState
!= DisplayPowerRequest.SCREEN_STATE_OFF) {
mLastScreenOffEventElapsedRealTime = SystemClock.elapsedRealtime();
}
mDisplayPowerRequest.screenState = newScreenState;
//add by ytmfdw ,no screen off ,to shutdown
shutdown(false, false);
// nativeSetPowerState(
// newScreenState != DisplayPowerRequest.SCREEN_STATE_OFF,
// newScreenState == DisplayPowerRequest.SCREEN_STATE_BRIGHT);
}
五、锁屏密码验证
如果显示的是: SecurityMode.SimPin
base/policy/src/com/android/internal/policy/impl/keyguard/KeyguardSimPinView.java
修改:CheckSimPin类:
run()方法里,修改验证代码
verifyPasswordAndUnlock()方法里,修改密码长度验证
如果显示的是: SecurityMode.SimPuk
base/policy/src/com/android/internal/policy/impl/keyguard/KeyguardSimPukView.java
修改:CheckSimPuk类:
run()方法里,修改验证代码
private boolean checkPuk(),修改密码长度验证
private boolean checkPin(),修改密码长度验证
应用程序调用锁屏分析:
private DevicePolicyManager dpm;
private void sysLock(){
dpm = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
boolean active = dpm.isAdminActive(componentName);
if (active) {
dpm.lockNow();
}
}
DevicePolicyManagerService.java
(包名:package com.android.server;)
public void lockNow() {
synchronized (this) {
// This API can only be called by an active device admin,
// so try to retrieve it to check that the caller is one.
getActiveAdminForCallerLocked(null,
DeviceAdminInfo.USES_POLICY_FORCE_LOCK);
lockNowUnchecked();
}
}
->lockNowUnChecked();
private void lockNowUnchecked() {
long ident = Binder.clearCallingIdentity();
try {
// Power off the display
getIPowerManager().goToSleep(SystemClock.uptimeMillis(),
PowerManager.GO_TO_SLEEP_REASON_DEVICE_ADMIN);
// Ensure the device is locked
getWindowManager().lockNow(null);
} catch (RemoteException e) {
} finally {
Binder.restoreCallingIdentity(ident);
}
}
->getWindowManager().lockNow(null);
调用的是WindowManagerService.java中的
(包名:package com.android.server.wm;)
public void lockNow(Bundle options) {
mPolicy.lockNow(options);
}
mPolicy.lockNow(options)调用的是:
PhoneWindowManager.java中的
(包名:package com.android.internal.policy.impl;)
public void lockNow(Bundle options) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
mHandler.removeCallbacks(mScreenLockTimeout);
if (options != null) {
// In case multiple calls are made to lockNow, we don't wipe out the options
// until the runnable actually executes.
mScreenLockTimeout.setLockOptions(options);
}
mHandler.post(mScreenLockTimeout);
}
mHandler.post(mScreenLockTimeout); 执行的是:
(PhoneWindowManager.java中的内部类)
class ScreenLockTimeout implements Runnable {
Bundle options;
@Override
public void run() {
synchronized (this) {
if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
if (mKeyguardMediator != null) {
mKeyguardMediator.doKeyguardTimeout(options);
}
mLockScreenTimerActive = false;
options = null;
}
}
public void setLockOptions(Bundle options) {
this.options = options;
}
}
mKeyguardMediator.doKeyguardTimeout(options);调用的是
KeyguardViewMediator.java中的
(包名:package com.android.internal.policy.impl.keyguard;)
public void doKeyguardTimeout(Bundle options) {
mHandler.removeMessages(KEYGUARD_TIMEOUT);
Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT, options);
mHandler.sendMessage(msg);
}
mHandler处理KEYGUARD_TIMEOUT消息:
case KEYGUARD_TIMEOUT:
synchronized (KeyguardViewMediator.this) {
doKeyguardLocked((Bundle) msg.obj);
}
break;
doKeyguardLocked((Bundle) msg.obj); 调用的是:
KeyguardViewMediator.java中的
showLocked(options);
private void showLocked(Bundle options) {
if (DEBUG) Log.d(TAG, "showLocked");
// ensure we stay awake until we are finished displaying the keyguard
mShowKeyguardWakeLock.acquire();
Message msg = mHandler.obtainMessage(SHOW, options);
mHandler.sendMessage(msg);
}
mHandler处理SHOW消息:
case SHOW:
handleShow((Bundle) msg.obj);
return ;
handleShow((Bundle) msg.obj); 调用的是:
KeyguardViewManager.java中的
(包名:package com.android.internal.policy.impl.keyguard;)
mKeyguardViewManager.show(options);
这里面调用的是:
maybeCreateKeyguardLocked(enableScreenRotation, false, options);
接下来调用:
inflateKeyguardView(options);