Aandroid 4.2 让系统开机不锁屏,并永不进入屏幕保护.

      最近做的项目要求开机就不锁屏,而且还永远不休眠,哇哦..这直接就可以通过设置改就是了嘛.多简单的事.

      什么?这项目没有屏幕,哇哦..改代码吧.

     1:禁止锁屏需要更改的代码路径如下:/frameworks/base/policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewMediator.java  贴上相关部分代码。代码位   于  842行左右

     

          /**
     * Enable the keyguard if the settings are appropriate.
     */
    private void doKeyguardLocked(Bundle options) {
        // if another app is disabling us, don't show
        if (!mExternallyEnabled) {                   //让此行永远为true就可以了,这样改后锁屏就不可用了。
            if (DEBUG) Log.d(TAG, "doKeyguard: not showing because externally disabled");

            // note: we *should* set mNeedToReshowWhenReenabled=true here, but that makes
            // for an occasional ugly flicker in this situation:
            // 1) receive a call with the screen on (no keyguard) or make a call
            // 2) screen times out
            // 3) user hits key to turn screen back on
            // instead, we reenable the keyguard when we know the screen is off and the call
            // ends (see the broadcast receiver below)
            // TODO: clean this up when we have better support at the window manager level
            // for apps that wish to be on top of the keyguard
            return;
        }

        // if the keyguard is already showing, don't bother
        if (mKeyguardViewManager.isShowing()) {
            if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing");
            return;
        }
           ...........................

          More code here

           ...........................

  }//end of the 




   3:让系统永不休眠的方法还有修改默认值的方法,修改frameworks/base/packages/SettingsProvider/res/values/defaults.xml文件里的def_screen_off_timeout的值为-1

          然后在services/java/com/android/server/power/PowerManagerService.java 文件里的  private int getScreenOffTimeoutLocked() 函数里添加如下代码.

         int DonotSleeptimeout;

         DonotSleeptimeout = mScreenOffTimeoutSetting;
        if(DonotSleeptimeout  < 0)
        {
             DonotSleeptimeout = mMaximumScreenOffTimeoutFromDeviceAdmin ;
            return Math.max(DonotSleeptimeout, mMaximumScreenOffTimeoutFromDeviceAdmin);
         }

        在Aandroid 4.2系统下测试ok..
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值