Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android編程入門 >> Android - 永不鎖屏,開機不鎖屏,刪除設置中休眠時間選項

Android - 永不鎖屏,開機不鎖屏,刪除設置中休眠時間選項

編輯:Android編程入門

Android 永不鎖屏,開機不鎖屏,刪除設置中休眠時間選項

Android 6.0.1
Create:2016-02-29

1.Settings 刪掉屏幕待機選項

packages/apps/Settings/res/xml/display_settings.xml

     <!-- Hide screen sleep
     <ListPreference
             android:key="screen_timeout"
             android:title="@string/screen_timeout"
             android:summary="@string/screen_timeout_summary"
             android:persistent="false"
             android:entries="@array/screen_timeout_entries"
             android:entryValues="@array/screen_timeout_values" /> -->

注釋掉這個ListPreference

packages/apps/Settings/src/com/android/settings/DisplaySettings.java
添加if條件,如果沒有找到這個preference就不執行相關操作;具體可以參考被隱藏的 night_mode

        mScreenTimeoutPreference = (ListPreference) findPreference(KEY_SCREEN_TIMEOUT);
        if (mScreenTimeoutPreference !=null ) {
            final long currentTimeout = Settings.System.getLong(resolver, SCREEN_OFF_TIMEOUT,
                    FALLBACK_SCREEN_TIMEOUT_VALUE);
            mScreenTimeoutPreference.setValue(String.valueOf(currentTimeout));
            mScreenTimeoutPreference.setOnPreferenceChangeListener(this);
            disableUnusableTimeouts(mScreenTimeoutPreference);
            updateTimeoutPreferenceDescription(currentTimeout);
        }

2.禁止鎖屏

frameworks/base/packages/SettingsProvider/res/values/defaults.xml
<bool name="def_lockscreen_disabled">false</bool> 改為 true;即默認禁止鎖屏

frameworks/base/core/res/res/values/config.xml
<integer name="config_multiuserMaximumUsers">1</integer> 不允許多用戶;即最大用戶數為1

分別編譯frameworks/base/packages/SettingsProvider 與 frameworks/base
編譯後push 到 system/priv-app/SettingsProvider/SettingsProvider.apk system/framework/framework.jar
刪去機器中對應的oat目錄。重啟或恢復出廠設置。第一次開機時,會先出現status bar,launcher要等一會才出來。
之後重啟就可以直接進入launcher。機器會默認不鎖屏。但還是會進入sleep狀態。


源碼流程:

frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java

if (upgradeVersion == 54)// 版本為54才會設置timeout
......
    private void upgradeScreenTimeoutFromNever(SQLiteDatabase db) {
        // See if the timeout is -1 (for "Never").
        Cursor c = db.query(TABLE_SYSTEM, new String[] { "_id", "value" }, "name=? AND value=?",
                new String[] { Settings.System.SCREEN_OFF_TIMEOUT, "-1" },
                null, null, null);

        SQLiteStatement stmt = null;
        if (c.getCount() > 0) {
            c.close();
            try {
                stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)"
                        + " VALUES(?,?);");

                // Set the timeout to 30 minutes in milliseconds
                loadSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
                        Integer.toString(30 * 60 * 1000));
            } finally {
                if (stmt != null) stmt.close();
            }
        } else {
            c.close();
        }
    }
    ......
            if (SystemProperties.getBoolean("ro.lockscreen.disable.default", false) == true) {
                loadSetting(stmt, Settings.System.LOCKSCREEN_DISABLED, "1");
            } else {
                loadBooleanSetting(stmt, Settings.System.LOCKSCREEN_DISABLED,
                        R.bool.def_lockscreen_disabled);
            }

timeout若是-1,則永不鎖屏
讀取"ro.lockscreen.disable.default",如果默認為true,則設置禁止鎖屏;否則從xml中讀配置

frameworks/base/packages/SettingsProvider/res/values/defaults.xml

    <integer name="def_screen_off_timeout">60000</integer>

    <bool name="def_lockscreen_disabled">false</bool>`

禁止鎖屏默認為false

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved