Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e06cbb57 authored by Brandon McAnsh's avatar Brandon McAnsh Committed by Roman Birg
Browse files

Development: Add choices to 'Stay Awake' preference



* Per a request on Google+ for Google Engineers to add to M, the stay awake values
    can now be never, while usb debugging, and always.
* Keep them pixels awake.

Change-Id: I7f43200bab0f000dc7547cc3142c4cacda2f4732
Signed-off-by: default avatarBrandon McAnsh <brandon.mcansh@gmail.com>
parent 4705f54a
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -348,4 +348,16 @@
        <item>1</item>
        <item>2</item>
    </string-array>

    <string-array name="keep_screen_on_titles" translatable="false">
        <item>@string/keep_screen_on_never</item>
        <item>@string/keep_screen_on_debugging</item>
        <item>@string/keep_screen_on_charging</item>
    </string-array>

    <string-array name="keep_screen_on_values" translatable="false">
        <item>0</item>
        <item>1</item>
        <item>2</item>
    </string-array>
</resources>
+4 −0
Original line number Diff line number Diff line
@@ -616,4 +616,8 @@
    <string name="edge_gesture_service_title">Block gesture touch events</string>
    <string name="edge_gesture_service_summary">Don\'t send touch events for navigation and status bar gestures to apps</string>

    <!-- Keep screen on strings -->
    <string name="keep_screen_on_never">Never</string>
    <string name="keep_screen_on_debugging">While USB debugging</string>
    <string name="keep_screen_on_charging">While charging</string>
</resources>
+6 −3
Original line number Diff line number Diff line
@@ -43,10 +43,13 @@
                android:targetClass="com.android.settings.SetFullBackupPassword" />
    </PreferenceScreen>

    <SwitchPreference
        android:key="keep_screen_on"
    <ListPreference
        android:key="keep_screen_on_modes"
        android:title="@string/keep_screen_on"
        android:summary="@string/keep_screen_on_summary"/>
        android:dialogTitle="@string/keep_screen_on"
        android:entries="@array/keep_screen_on_titles"
        android:entryValues="@array/keep_screen_on_values"
        android:persistent="false" />

    <ListPreference
        android:key="hdcp_checking"
+31 −10
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
    private static final String ADB_TCPIP = "adb_over_network";
    private static final String CLEAR_ADB_KEYS = "clear_adb_keys";
    private static final String ENABLE_TERMINAL = "enable_terminal";
    private static final String KEEP_SCREEN_ON = "keep_screen_on";
    private static final String KEEP_SCREEN_ON_MODES = "keep_screen_on_modes";
    private static final String BT_HCI_SNOOP_LOG = "bt_hci_snoop_log";
    private static final String ENABLE_OEM_UNLOCK = "oem_unlock_enable";
    private static final String HDCP_CHECKING_KEY = "hdcp_checking";
@@ -212,7 +212,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
    private SwitchPreference mEnableTerminal;
    private Preference mBugreport;
    private SwitchPreference mBugreportInPower;
    private SwitchPreference mKeepScreenOn;
    private ListPreference mKeepScreenOn;
    private SwitchPreference mBtHciSnoopLog;
    private SwitchPreference mEnableOemUnlock;
    private SwitchPreference mDebugViewAttributes;
@@ -334,7 +334,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment

        mBugreport = findPreference(BUGREPORT);
        mBugreportInPower = findAndInitSwitchPref(BUGREPORT_IN_POWER_KEY);
        mKeepScreenOn = findAndInitSwitchPref(KEEP_SCREEN_ON);
        mKeepScreenOn = addListPreference(KEEP_SCREEN_ON_MODES);
        mBtHciSnoopLog = findAndInitSwitchPref(BT_HCI_SNOOP_LOG);
        mEnableOemUnlock = findAndInitSwitchPref(ENABLE_OEM_UNLOCK);
        if (!showEnableOemUnlockPreference()) {
@@ -602,8 +602,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
        }
        updateSwitchPreference(mBugreportInPower, Settings.Secure.getInt(cr,
                Settings.Secure.BUGREPORT_IN_POWER_MENU, 0) != 0);
        updateSwitchPreference(mKeepScreenOn, Settings.Global.getInt(cr,
                Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0) != 0);
        updateStayAwakeOptions();
        updateSwitchPreference(mBtHciSnoopLog, Settings.Secure.getInt(cr,
                Settings.Secure.BLUETOOTH_HCI_LOG, 0) != 0);
        if (mEnableOemUnlock != null) {
@@ -749,6 +748,23 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
        updateRootAccessOptions();
    }

    private void updateStayAwakeOptions() {
        int index = Settings.Global.getInt(getActivity().getContentResolver(),
                Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0);
        final String[] values = getResources().getStringArray(R.array.keep_screen_on_values);
        final String[] summaries = getResources().getStringArray(R.array.keep_screen_on_titles);
        // The old value contained 0 (disable) or 3 (BATTERY_PLUGGED_AC|BATTERY_PLUGGED_USB)
        // Currently only have 3 values (0: Not enabled; 1: debugging over usb; >2: charging)
        // NOTE: If we have newer values, then we need to migrate
        // this property
        if (index >= values.length) {
            index = values.length - 1;
        }
        mKeepScreenOn.setValue(values[index]);
        mKeepScreenOn.setSummary(summaries[index]);
        mKeepScreenOn.setOnPreferenceChangeListener(this);
    }

    private void updateHdcpValues() {
        ListPreference hdcpChecking = (ListPreference) findPreference(HDCP_CHECKING_KEY);
        if (hdcpChecking != null) {
@@ -1145,6 +1161,13 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
        mShowNonRectClip.setSummary(mShowNonRectClip.getEntries()[0]);
    }

    private void writeStayAwakeOptions(Object newValue) {
        int val = Integer.parseInt((String) newValue);
        Settings.Global.putInt(getActivity().getContentResolver(),
                    Settings.Global.STAY_ON_WHILE_PLUGGED_IN, val);
        updateStayAwakeOptions();
    }

    private void writeShowNonRectClipOptions(Object newValue) {
        SystemProperties.set(HardwareRenderer.DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY,
                newValue == null ? "" : newValue.toString());
@@ -1750,11 +1773,6 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
            Settings.Secure.putInt(getActivity().getContentResolver(),
                    Settings.Secure.BUGREPORT_IN_POWER_MENU,
                    mBugreportInPower.isChecked() ? 1 : 0);
        } else if (preference == mKeepScreenOn) {
            Settings.Global.putInt(getActivity().getContentResolver(),
                    Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
                    mKeepScreenOn.isChecked() ?
                            (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB) : 0);
        } else if (preference == mBtHciSnoopLog) {
            writeBtHciSnoopLogOptions();
        } else if (preference == mEnableOemUnlock) {
@@ -1911,6 +1929,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
                writeRootAccessOptions(newValue);
            }
            return true;
        } else if (preference == mKeepScreenOn) {
            writeStayAwakeOptions(newValue);
            return true;
        }
        return false;
    }