diff options
author | Tyler Nijmeh <tylernij@gmail.com> | 2021-03-31 02:12:53 -0700 |
---|---|---|
committer | Tyler Nijmeh <tylernij@gmail.com> | 2021-03-31 02:12:53 -0700 |
commit | e4020a7517fb25d8e048282429a71c216ce84668 (patch) | |
tree | 1377faa1b9809f379f343692b8420d169a08300b | |
parent | 9a63ecfe6217fa94f495c2f2877917eda6aa57b8 (diff) |
Read settings in from device
Signed-off-by: Tyler Nijmeh <tylernij@gmail.com>
-rw-r--r-- | app/src/main/java/com/draco/buoy/fragments/MainPreferenceFragment.kt | 42 | ||||
-rw-r--r-- | app/src/main/java/com/draco/buoy/models/BatterySaverConstantsConfig.kt | 4 | ||||
-rw-r--r-- | app/src/main/java/com/draco/buoy/utils/BatterySaverManager.kt | 10 | ||||
-rw-r--r-- | app/src/main/res/values/arrays.xml | 17 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 105 | ||||
-rw-r--r-- | app/src/main/res/xml/main.xml | 114 |
6 files changed, 250 insertions, 42 deletions
diff --git a/app/src/main/java/com/draco/buoy/fragments/MainPreferenceFragment.kt b/app/src/main/java/com/draco/buoy/fragments/MainPreferenceFragment.kt index e0be6d3..f757d39 100644 --- a/app/src/main/java/com/draco/buoy/fragments/MainPreferenceFragment.kt +++ b/app/src/main/java/com/draco/buoy/fragments/MainPreferenceFragment.kt @@ -4,8 +4,7 @@ import android.content.Context import android.content.Intent import android.net.Uri import android.os.Bundle -import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat +import androidx.preference.* import com.draco.buoy.R import com.draco.buoy.models.BatterySaverConstantsConfig import com.draco.buoy.repositories.BatterySaverConstantsConfigProfiles @@ -27,11 +26,11 @@ class MainPreferenceFragment : PreferenceFragmentCompat() { override fun onPreferenceTreeClick(preference: Preference): Boolean { when (preference.key) { - getString(R.string.profile_key_reset) -> resetProfile() - getString(R.string.profile_key_light) -> applyProfile(BatterySaverConstantsConfigProfiles.LIGHT) - getString(R.string.profile_key_moderate) -> applyProfile(BatterySaverConstantsConfigProfiles.MODERATE) - getString(R.string.profile_key_high) -> applyProfile(BatterySaverConstantsConfigProfiles.HIGH) - getString(R.string.profile_key_extreme) -> applyProfile(BatterySaverConstantsConfigProfiles.EXTREME) + getString(R.string.pref_profile_key_reset) -> resetProfile() + getString(R.string.pref_profile_key_light) -> applyProfile(BatterySaverConstantsConfigProfiles.LIGHT) + getString(R.string.pref_profile_key_moderate) -> applyProfile(BatterySaverConstantsConfigProfiles.MODERATE) + getString(R.string.pref_profile_key_high) -> applyProfile(BatterySaverConstantsConfigProfiles.HIGH) + getString(R.string.pref_profile_key_extreme) -> applyProfile(BatterySaverConstantsConfigProfiles.EXTREME) getString(R.string.pref_developer_key) -> openURL(getString(R.string.developer_url)) getString(R.string.pref_source_key) -> openURL(getString(R.string.source_url)) @@ -45,11 +44,39 @@ class MainPreferenceFragment : PreferenceFragmentCompat() { return true } + private fun updateSettings() { + val currentProfileString = batterySaverManager.getConstantsString() + val currentProfile = BatterySaverConstantsConfig().also { + if (currentProfileString != null) + it.import(currentProfileString) + } + + findPreference<SwitchPreference>(getString(R.string.pref_config_key_advertise_is_enabled))?.isChecked = currentProfile.advertiseIsEnabled + findPreference<SwitchPreference>(getString(R.string.pref_config_key_datasaver_enabled))?.isChecked = !currentProfile.dataSaverDisabled + findPreference<SwitchPreference>(getString(R.string.pref_config_key_enable_night_mode))?.isChecked = currentProfile.enableNightMode + findPreference<SwitchPreference>(getString(R.string.pref_config_key_launch_boost_enabled))?.isChecked = !currentProfile.launchBoostDisabled + findPreference<SwitchPreference>(getString(R.string.pref_config_key_vibration_enabled))?.isChecked = !currentProfile.vibrationDisabled + findPreference<SwitchPreference>(getString(R.string.pref_config_key_animation_enabled))?.isChecked = !currentProfile.animationDisabled + findPreference<SwitchPreference>(getString(R.string.pref_config_key_soundtrigger_enabled))?.isChecked = !currentProfile.soundTriggerDisabled + findPreference<SwitchPreference>(getString(R.string.pref_config_key_fullbackup_deferred))?.isChecked = currentProfile.fullBackupDeferred + findPreference<SwitchPreference>(getString(R.string.pref_config_key_keyvaluebackup_deferred))?.isChecked = currentProfile.keyValueBackupDeferred + findPreference<SwitchPreference>(getString(R.string.pref_config_key_firewall_enabled))?.isChecked = !currentProfile.fireWallDisabled + findPreference<ListPreference>(getString(R.string.pref_config_key_gps_mode))?.value = currentProfile.gpsMode.toString() + findPreference<SwitchPreference>(getString(R.string.pref_config_key_adjust_brightness_enabled))?.isChecked = !currentProfile.adjustBrightnessDisabled + findPreference<SeekBarPreference>(getString(R.string.pref_config_key_adjust_brightness_factor))?.value = (currentProfile.adjustBrightnessFactor * 100).toInt() + findPreference<SwitchPreference>(getString(R.string.pref_config_key_force_all_apps_standby))?.isChecked = currentProfile.forceAllAppsStandby + findPreference<SwitchPreference>(getString(R.string.pref_config_key_force_background_check))?.isChecked = currentProfile.forceBackgroundCheck + findPreference<SwitchPreference>(getString(R.string.pref_config_key_optional_sensors_disabled))?.isChecked = currentProfile.optionalSensorsDisabled + findPreference<SwitchPreference>(getString(R.string.pref_config_key_aod_enabled))?.isChecked = currentProfile.aodDisabled + findPreference<SwitchPreference>(getString(R.string.pref_config_key_quick_doze_enabled))?.isChecked = currentProfile.quickDozeEnabled + } + private fun applyProfile(profile: BatterySaverConstantsConfig) { batterySaverManager.setConstantsConfig(profile) batterySaverManager.setLowPower(true) batterySaverManager.setLowPowerSticky(true) batterySaverManager.setLowPowerStickyAutoDisableEnabled(false) + updateSettings() } private fun resetProfile() { @@ -57,6 +84,7 @@ class MainPreferenceFragment : PreferenceFragmentCompat() { batterySaverManager.setLowPower(false) batterySaverManager.setLowPowerSticky(false) batterySaverManager.setLowPowerStickyAutoDisableEnabled(true) + updateSettings() } private fun openURL(url: String) { diff --git a/app/src/main/java/com/draco/buoy/models/BatterySaverConstantsConfig.kt b/app/src/main/java/com/draco/buoy/models/BatterySaverConstantsConfig.kt index 6733227..c26ab01 100644 --- a/app/src/main/java/com/draco/buoy/models/BatterySaverConstantsConfig.kt +++ b/app/src/main/java/com/draco/buoy/models/BatterySaverConstantsConfig.kt @@ -32,7 +32,7 @@ data class BatterySaverConstantsConfig( "${BatterySaverConstants.ANIMATION_DISABLED}=$animationDisabled," + "${BatterySaverConstants.SOUNDTRIGGER_DISABLED}=$soundTriggerDisabled," + "${BatterySaverConstants.FULLBACKUP_DEFERRED}=$fullBackupDeferred," + - "${BatterySaverConstants.KEYVALUEBACKUP_DEFERRED}=$keyValueBackupDeferred" + + "${BatterySaverConstants.KEYVALUEBACKUP_DEFERRED}=$keyValueBackupDeferred," + "${BatterySaverConstants.FIREWALL_DISABLED}=$fireWallDisabled," + "${BatterySaverConstants.GPS_MODE}=$gpsMode," + "${BatterySaverConstants.ADJUST_BRIGHTNESS_DISABLED}=$adjustBrightnessDisabled," + @@ -44,7 +44,7 @@ data class BatterySaverConstantsConfig( "${BatterySaverConstants.QUICK_DOZE_ENABLED}=$quickDozeEnabled" } - fun fromString(string: String) { + fun import(string: String) { val keyValueMap = string.split(",").associate { val (key, value) = it.split("=") key to value diff --git a/app/src/main/java/com/draco/buoy/utils/BatterySaverManager.kt b/app/src/main/java/com/draco/buoy/utils/BatterySaverManager.kt index dbc2d37..f63b681 100644 --- a/app/src/main/java/com/draco/buoy/utils/BatterySaverManager.kt +++ b/app/src/main/java/com/draco/buoy/utils/BatterySaverManager.kt @@ -65,6 +65,16 @@ class BatterySaverManager(private val contentResolver: ContentResolver) { } /** + * Get the raw battery saver constants secure setting + */ + fun getConstantsString(): String? { + return Settings.Global.getString( + contentResolver, + BatterySaverSecureSettings.BATTERY_SAVER_CONSTANTS + ) + } + + /** * Set the battery saver constants secure setting via a config */ fun setConstantsConfig(config: BatterySaverConstantsConfig) { diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml new file mode 100644 index 0000000..6f690d3 --- /dev/null +++ b/app/src/main/res/values/arrays.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string-array name="location_modes_values"> + <item>0</item> + <item>1</item> + <item>2</item> + <item>3</item> + <item>4</item> + </string-array> + <string-array name="location_modes_entries"> + <item>Standard location access</item> + <item>GPS disabled when screen off</item> + <item>All disabled when screen off</item> + <item>Foreground location updates only</item> + <item>Throttle when screen off</item> + </string-array> +</resources>
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1ffd3d1..8e22ca1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -16,28 +16,101 @@ <string name="source_url">https://www.github.com/tytydraco/Buoy</string> <string name="contact_url">mailto:tylernij@gmail.com</string> - <string name="category_actions">Actions</string> + <string name="category_profiles">Profiles</string> <string name="category_about">About</string> + <string name="category_config">Configuration</string> - <string name="profile_key_reset">reset</string> - <string name="profile_title_reset">Reset</string> - <string name="profile_summary_reset">Undo all changes done by the app and restore secure settings to default</string> + <string name="pref_profile_key_reset">reset</string> + <string name="pref_profile_title_reset">Reset</string> + <string name="pref_profile_summary_reset">Undo all changes done by the app and restore secure settings to default</string> - <string name="profile_key_light">light</string> - <string name="profile_title_light">Light</string> - <string name="profile_summary_light">Marginally conserve battery without impeding the user experience</string> + <string name="pref_profile_key_light">light</string> + <string name="pref_profile_title_light">Light</string> + <string name="pref_profile_summary_light">Marginally conserve battery without impeding the user experience</string> - <string name="profile_key_moderate">moderate</string> - <string name="profile_title_moderate">Moderate</string> - <string name="profile_summary_moderate">Apply additional tweaks to save more battery without yet sacrificing performance</string> + <string name="pref_profile_key_moderate">moderate</string> + <string name="pref_profile_title_moderate">Moderate</string> + <string name="pref_profile_summary_moderate">Apply additional tweaks to save more battery without yet sacrificing performance</string> - <string name="profile_key_high">high</string> - <string name="profile_title_high">High</string> - <string name="profile_summary_high">Sacrifice significant performance for a significant gain in power</string> + <string name="pref_profile_key_high">high</string> + <string name="pref_profile_title_high">High</string> + <string name="pref_profile_summary_high">Sacrifice significant performance for a significant gain in power</string> - <string name="profile_key_extreme">extreme</string> - <string name="profile_title_extreme">Extreme</string> - <string name="profile_summary_extreme">Apply the maximum changes available to save power at the expense of a fluid user experience</string> + <string name="pref_profile_key_extreme">extreme</string> + <string name="pref_profile_title_extreme">Extreme</string> + <string name="pref_profile_summary_extreme">Apply the maximum changes available to save power at the expense of a fluid user experience</string> + + <string name="pref_config_key_advertise_is_enabled">advertise_is_enabled</string> + <string name="pref_config_title_advertise_is_enabled">Advertise Power Saver</string> + <string name="pref_config_summary_advertise_is_enabled">Alert apps that the device is in low power mode; some apps will use this information to reduce their power draw</string> + + <string name="pref_config_key_datasaver_enabled">datasaver_enabled</string> + <string name="pref_config_title_datasaver_enabled">Enable Data Saver</string> + <string name="pref_config_summary_datasaver_enabled">Reduce the data sent and received on metered connections and on mobile data</string> + + <string name="pref_config_key_enable_night_mode">enable_night_mode</string> + <string name="pref_config_title_enable_night_mode">Enable Night Mode</string> + <string name="pref_config_summary_enable_night_mode">Use darker colors to reduce the power draw on OLED panels</string> + + <string name="pref_config_key_launch_boost_enabled">launch_boost_enabled</string> + <string name="pref_config_title_launch_boost_enabled">Enable Launch Boost</string> + <string name="pref_config_summary_launch_boost_enabled">Accelerate the CPU while opening applications to expedite their startup time</string> + + <string name="pref_config_key_vibration_enabled">vibration_enabled</string> + <string name="pref_config_title_vibration_enabled">Enable Vibrations</string> + <string name="pref_config_summary_vibration_enabled">Allow touch and notification vibrations</string> + + <string name="pref_config_key_animation_enabled">animation_enabled</string> + <string name="pref_config_title_animation_enabled">Enable Animations</string> + <string name="pref_config_summary_animation_enabled">Continue to display animations</string> + + <string name="pref_config_key_soundtrigger_enabled">soundtrigger_enabled</string> + <string name="pref_config_title_soundtrigger_enabled">Enable Sound Triggers</string> + <string name="pref_config_summary_soundtrigger_enabled">::TODO::</string> + + <string name="pref_config_key_fullbackup_deferred">fullbackup_deferred</string> + <string name="pref_config_title_fullbackup_deferred">Defer Full Backups</string> + <string name="pref_config_summary_fullbackup_deferred">Reschedule device cloud backups for later</string> + + <string name="pref_config_key_keyvaluebackup_deferred">keyvaluebackup_deferred</string> + <string name="pref_config_title_keyvaluebackup_deferred">Defer KeyValue Backups</string> + <string name="pref_config_summary_keyvaluebackup_deferred">Reschedule application settings cloud backups for later</string> + + <string name="pref_config_key_firewall_enabled">firewall_enabled</string> + <string name="pref_config_title_firewall_enabled">Enable Firewall</string> + <string name="pref_config_summary_firewall_enabled">Defend against possibly malicious web requests</string> + + <string name="pref_config_key_gps_mode">gps_mode</string> + <string name="pref_config_title_gps_mode">Location Mode</string> + <string name="pref_config_summary_gps_mode">How location requests are handled in low power mode</string> + + <string name="pref_config_key_adjust_brightness_enabled">adjust_brightness_disabled</string> + <string name="pref_config_title_adjust_brightness_enabled">Adjust Brightness</string> + <string name="pref_config_summary_adjust_brightness_enabled">Reduce the maximum brightness on the panel</string> + + <string name="pref_config_key_adjust_brightness_factor">adjust_brightness_factor</string> + <string name="pref_config_title_adjust_brightness_factor">Brightness Factor</string> + <string name="pref_config_summary_adjust_brightness_factor">By what factor to reduce the screen brightness by</string> + + <string name="pref_config_key_force_all_apps_standby">force_all_apps_standby</string> + <string name="pref_config_title_force_all_apps_standby">Force Apps Into Standby</string> + <string name="pref_config_summary_force_all_apps_standby">Background apps are put to sleep very quickly</string> + + <string name="pref_config_key_force_background_check">force_background_check</string> + <string name="pref_config_title_force_background_check">Force Background Check</string> + <string name="pref_config_summary_force_background_check">::TODO::</string> + + <string name="pref_config_key_optional_sensors_disabled">optional_sensors_disabled</string> + <string name="pref_config_title_optional_sensors_disabled">Disable Optional Sensors</string> + <string name="pref_config_summary_optional_sensors_disabled">Do not detect unnecessary sensor requests (i.e. edge sensors)</string> + + <string name="pref_config_key_aod_enabled">aod_enabled</string> + <string name="pref_config_title_aod_enabled">Always-On-Display Enabled</string> + <string name="pref_config_summary_aod_enabled">Display the AOD in sleep mode</string> + + <string name="pref_config_key_quick_doze_enabled">quick_doze_enabled</string> + <string name="pref_config_title_quick_doze_enabled">Quick Doze Enabled</string> + <string name="pref_config_summary_quick_doze_enabled">Enter deep sleep as soon as the screen is turned off</string> <string name="pref_developer_title">Developer</string> <string name="pref_developer_summary">Tyler Nijmeh</string> diff --git a/app/src/main/res/xml/main.xml b/app/src/main/res/xml/main.xml index b383e10..a08daa6 100644 --- a/app/src/main/res/xml/main.xml +++ b/app/src/main/res/xml/main.xml @@ -1,26 +1,106 @@ <?xml version="1.0" encoding="utf-8"?> -<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> - <PreferenceCategory android:title="@string/category_actions"> +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto"> + <PreferenceCategory android:title="@string/category_profiles"> <Preference - android:title="@string/profile_title_reset" - android:summary="@string/profile_summary_reset" - android:key="@string/profile_key_reset" /> + android:title="@string/pref_profile_title_reset" + android:summary="@string/pref_profile_summary_reset" + android:key="@string/pref_profile_key_reset" /> <Preference - android:title="@string/profile_title_light" - android:summary="@string/profile_summary_light" - android:key="@string/profile_key_light" /> + android:title="@string/pref_profile_title_light" + android:summary="@string/pref_profile_summary_light" + android:key="@string/pref_profile_key_light" /> <Preference - android:title="@string/profile_title_moderate" - android:summary="@string/profile_summary_moderate" - android:key="@string/profile_key_moderate" /> + android:title="@string/pref_profile_title_moderate" + android:summary="@string/pref_profile_summary_moderate" + android:key="@string/pref_profile_key_moderate" /> <Preference - android:title="@string/profile_title_high" - android:summary="@string/profile_summary_high" - android:key="@string/profile_key_high" /> + android:title="@string/pref_profile_title_high" + android:summary="@string/pref_profile_summary_high" + android:key="@string/pref_profile_key_high" /> <Preference - android:title="@string/profile_title_extreme" - android:summary="@string/profile_summary_extreme" - android:key="@string/profile_key_extreme" /> + android:title="@string/pref_profile_title_extreme" + android:summary="@string/pref_profile_summary_extreme" + android:key="@string/pref_profile_key_extreme" /> + </PreferenceCategory> + <PreferenceCategory android:title="@string/category_config"> + <SwitchPreference + android:title="@string/pref_config_title_advertise_is_enabled" + android:summary="@string/pref_config_summary_advertise_is_enabled" + android:key="@string/pref_config_key_advertise_is_enabled" /> + <SwitchPreference + android:title="@string/pref_config_title_datasaver_enabled" + android:summary="@string/pref_config_summary_datasaver_enabled" + android:key="@string/pref_config_key_datasaver_enabled" /> + <SwitchPreference + android:title="@string/pref_config_title_enable_night_mode" + android:summary="@string/pref_config_summary_enable_night_mode" + android:key="@string/pref_config_key_enable_night_mode" /> + <SwitchPreference + android:title="@string/pref_config_title_launch_boost_enabled" + android:summary="@string/pref_config_summary_launch_boost_enabled" + android:key="@string/pref_config_key_launch_boost_enabled" /> + <SwitchPreference + android:title="@string/pref_config_title_vibration_enabled" + android:summary="@string/pref_config_summary_vibration_enabled" + android:key="@string/pref_config_key_vibration_enabled" /> + <SwitchPreference + android:title="@string/pref_config_title_animation_enabled" + android:summary="@string/pref_config_summary_animation_enabled" + android:key="@string/pref_config_key_animation_enabled" /> + <SwitchPreference + android:title="@string/pref_config_title_soundtrigger_enabled" + android:summary="@string/pref_config_summary_soundtrigger_enabled" + android:key="@string/pref_config_key_soundtrigger_enabled" /> + <SwitchPreference + android:title="@string/pref_config_title_fullbackup_deferred" + android:summary="@string/pref_config_summary_fullbackup_deferred" + android:key="@string/pref_config_key_fullbackup_deferred" /> + <SwitchPreference + android:title="@string/pref_config_title_keyvaluebackup_deferred" + android:summary="@string/pref_config_summary_keyvaluebackup_deferred" + android:key="@string/pref_config_key_keyvaluebackup_deferred" /> + <SwitchPreference + android:title="@string/pref_config_title_firewall_enabled" + android:summary="@string/pref_config_summary_firewall_enabled" + android:key="@string/pref_config_key_firewall_enabled" /> + <ListPreference + android:title="@string/pref_config_title_gps_mode" + android:summary="@string/pref_config_summary_gps_mode" + android:key="@string/pref_config_key_gps_mode" + android:entries="@array/location_modes_entries" + android:entryValues="@array/location_modes_values" /> + <SwitchPreference + android:title="@string/pref_config_title_adjust_brightness_enabled" + android:summary="@string/pref_config_summary_adjust_brightness_enabled" + android:key="@string/pref_config_key_adjust_brightness_enabled" /> + <SeekBarPreference + android:title="@string/pref_config_title_adjust_brightness_factor" + android:summary="@string/pref_config_summary_adjust_brightness_factor" + android:key="@string/pref_config_key_adjust_brightness_factor" + android:dependency="@string/pref_config_key_adjust_brightness_enabled" + android:max="100" + app:showSeekBarValue="true"/> + <SwitchPreference + android:title="@string/pref_config_title_force_all_apps_standby" + android:summary="@string/pref_config_summary_force_all_apps_standby" + android:key="@string/pref_config_key_force_all_apps_standby" /> + <SwitchPreference + android:title="@string/pref_config_title_force_background_check" + android:summary="@string/pref_config_summary_force_background_check" + android:key="@string/pref_config_key_force_background_check" /> + <SwitchPreference + android:title="@string/pref_config_title_optional_sensors_disabled" + android:summary="@string/pref_config_summary_optional_sensors_disabled" + android:key="@string/pref_config_key_optional_sensors_disabled" /> + <SwitchPreference + android:title="@string/pref_config_title_aod_enabled" + android:summary="@string/pref_config_summary_aod_enabled" + android:key="@string/pref_config_key_aod_enabled" /> + <SwitchPreference + android:title="@string/pref_config_title_quick_doze_enabled" + android:summary="@string/pref_config_summary_quick_doze_enabled" + android:key="@string/pref_config_key_quick_doze_enabled" /> </PreferenceCategory> <PreferenceCategory android:title="@string/category_about"> <Preference |