Android鎖屏控制

來源:互聯網
上載者:User

1.鎖屏時間

鎖屏時間控制碼位於:frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java  

private void loadSystemSettings(SQLiteDatabase db) {  
  ……
  loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT, R.integer.def_screen_off_timeout);
  ……

控制資料位元於:frameworks/base/packages/SettingsProvider/res/values/defaults.xml  

可以找到:<integer name="def_screen_off_timeout">60000</integer>  

60000以毫秒為單位,即1分鐘,若設定為-1即不鎖屏,這樣修改的話,啟動後依舊會進入鎖屏狀態,解鎖之後就再也不會鎖屏了。

2.禁止開機鎖屏

開機鎖屏代碼位於:frameworks/base/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java

  /**
     * External apps (like the phone app) can tell us to disable the keygaurd.
     */
  private boolean mExternallyEnabled = true;

由此可知預設是鎖屏狀態的。

尋找該變數會發現如下代碼:

    public void setKeyguardEnabled(boolean enabled) {
        synchronized (this) {
            if (DEBUG) Log.d(TAG, "setKeyguardEnabled(" + enabled + ")");

            mExternallyEnabled = enabled;
所以可以在程式中調用setKeyguardEnabled來控制鎖屏狀態。

 3.與鎖屏其他相關設定

留意2中的代碼,會發現還有很多預設參數在此設定。

例如:

    /**      * How long to wait after the screen turns off due to timeout before
     * turning on the keyguard (i.e, the user has this much time to turn
     * the screen back on without having to face the keyguard).
     */
    private static final int KEYGUARD_DELAY_MS = 5000;

這個參數就是背光熄滅後5秒內按鍵啟用螢幕的話,不需要重新解鎖。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.