一、APP调用goToSleep,权限检查失败,虚拟机shut down是报错:
java.lang.SecurityException: Neither user nor current process has android.permission.DEVICE_POWER.
解决办法:
public void goToSleep(long time)
{
Log.d(TAG,"goToSleep/n");
//注释掉这句代码
//mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
synchronized (mLocks) {
goToSleepLocked(time);
}
}
二、唤醒之后直接回到睡眠前的状态,不要显示锁屏:
方法1(这种改法会影响所有的应用及其他用到唤醒的地方):
frameworks/policies/base/phone/com/android/internal/policy/impl/KeyguardUpdateMonitor.java
中,把如下的函数直接返回false
public boolean isDeviceProvisioned() {
//return mDeviceProvisioned;
return false;
}
方法2(只针对当前应用):
SDK文档里面有这个接口:
KeyguardManager.KeyguardLock
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();