mirror of
https://github.com/Divested-Mobile/DivestOS-Build.git
synced 2025-05-08 09:25:19 -04:00
Initial implementation of allowing the user to reduce screen resolution to save power
This commit is contained in:
parent
cfaed310f1
commit
b3108b9e7f
5 changed files with 206 additions and 2 deletions
|
@ -0,0 +1,84 @@
|
|||
From 259267c0ffa34a99aad3af08d58dfd5aa340bd04 Mon Sep 17 00:00:00 2001
|
||||
From: Tad <tad@spotco.us>
|
||||
Date: Fri, 20 Oct 2017 15:29:25 -0400
|
||||
Subject: [PATCH] Reduced Resolution Feature 2/2
|
||||
|
||||
Change-Id: Ib3d363e4fc66821ebb5303a974589c0b18c5ef9b
|
||||
---
|
||||
core/java/android/os/PowerManager.java | 46 ++++++++++++++++++++++++++++++++++
|
||||
1 file changed, 46 insertions(+)
|
||||
|
||||
diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java
|
||||
index 5c8effec0ed..62954ddadea 100644
|
||||
--- a/core/java/android/os/PowerManager.java
|
||||
+++ b/core/java/android/os/PowerManager.java
|
||||
@@ -438,6 +438,8 @@ public final class PowerManager {
|
||||
final IPowerManager mService;
|
||||
final Handler mHandler;
|
||||
|
||||
+ final IWindowManager mWm;
|
||||
+
|
||||
IDeviceIdleController mIDeviceIdleController;
|
||||
|
||||
/**
|
||||
@@ -447,6 +449,9 @@ public final class PowerManager {
|
||||
mContext = context;
|
||||
mService = service;
|
||||
mHandler = handler;
|
||||
+
|
||||
+ mWm = IWindowManager.Stub.asInterface(ServiceManager.checkService(
|
||||
+ Context.WINDOW_SERVICE));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -988,6 +993,47 @@ public final class PowerManager {
|
||||
}
|
||||
}
|
||||
|
||||
+ public boolean isReducedResolution() {
|
||||
+ try {
|
||||
+ Point initialSize = new Point();
|
||||
+ Point baseSize = new Point();
|
||||
+
|
||||
+ mWm.getInitialDisplaySize(Display.DEFAULT_DISPLAY, initialSize);
|
||||
+ mWm.getBaseDisplaySize(Display.DEFAULT_DISPLAY, baseSize);
|
||||
+
|
||||
+ return !initialSize.equals(baseSize);
|
||||
+ } catch (Exception e) {
|
||||
+ throw e.rethrowFromSystemServer();
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public boolean setReducedResolution(boolean mode) {
|
||||
+ try {
|
||||
+ if (mode) {
|
||||
+ Point initialSize = new Point();
|
||||
+ mWm.getInitialDisplaySize(Display.DEFAULT_DISPLAY, initialSize);
|
||||
+
|
||||
+ Point newSize;
|
||||
+
|
||||
+ switch(initialSize.x) {
|
||||
+ case 1440:
|
||||
+ newSize = new Point(1080, 1920);
|
||||
+ case 1080:
|
||||
+ newSize = new Point(720, 1280);
|
||||
+ default:
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ mWm.setForcedDisplaySize(Display.DEFAULT_DISPLAY, newSize.x, newSize.y);
|
||||
+ } else {
|
||||
+ mWm.clearForcedDisplaySize(Display.DEFAULT_DISPLAY);
|
||||
+ }
|
||||
+ return isReducedResolution();
|
||||
+ } catch (Exception e) {
|
||||
+ throw e.rethrowFromSystemServer();
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
/**
|
||||
* Returns true if the device is currently in idle mode. This happens when a device
|
||||
* has been sitting unused and unmoving for a sufficiently long period of time, so that
|
||||
--
|
||||
2.14.2
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
From 4205a403acba83df87feef538bd9495f3f49c951 Mon Sep 17 00:00:00 2001
|
||||
From: Tad <tad@spotco.us>
|
||||
Date: Fri, 20 Oct 2017 15:28:00 -0400
|
||||
Subject: [PATCH] Reduced Resolution Feature 1/2
|
||||
|
||||
Change-Id: Id76c429a7bf806db59726d7d64a4dca267cb36c1
|
||||
---
|
||||
res/values/strings.xml | 2 ++
|
||||
res/xml/perf_profile_settings.xml | 5 +++++
|
||||
.../cyanogenmod/cmparts/power/PerfProfileSettings.java | 16 ++++++++++++++++
|
||||
3 files changed, 23 insertions(+)
|
||||
|
||||
diff --git a/res/values/strings.xml b/res/values/strings.xml
|
||||
index a7e31ca..cfaef0b 100644
|
||||
--- a/res/values/strings.xml
|
||||
+++ b/res/values/strings.xml
|
||||
@@ -576,6 +576,8 @@
|
||||
<string name="power_save_category_title">Battery saving</string>
|
||||
<string name="power_save_title">Extreme power saver</string>
|
||||
<string name="power_save_summary">Restrict device performance and background activity to save power</string>
|
||||
+ <string name="reduce_resolution_title">Reduce screen resolution</string>
|
||||
+ <string name="reduce_resolution_summary">Lowers the screen resolution to save power</string>
|
||||
<string name="auto_power_save_title">Automatic power saver</string>
|
||||
<string name="auto_power_save_summary_on">Automatically enable power save mode at %s battery</string>
|
||||
<string name="auto_power_save_summary_off">Do not enable power save mode automatically</string>
|
||||
diff --git a/res/xml/perf_profile_settings.xml b/res/xml/perf_profile_settings.xml
|
||||
index 3585cb7..0513137 100644
|
||||
--- a/res/xml/perf_profile_settings.xml
|
||||
+++ b/res/xml/perf_profile_settings.xml
|
||||
@@ -29,6 +29,11 @@
|
||||
android:summary="@string/power_save_summary"
|
||||
android:persistent="false" />
|
||||
|
||||
+ <SwitchPreference
|
||||
+ android:key="reduce_resolution"
|
||||
+ android:title="@string/reduce_resolution_title"
|
||||
+ android:summary="@string/reduce_resoution_summary" />
|
||||
+
|
||||
<ListPreference
|
||||
android:key="auto_power_save"
|
||||
android:title="@string/auto_power_save_title"
|
||||
diff --git a/src/org/cyanogenmod/cmparts/power/PerfProfileSettings.java b/src/org/cyanogenmod/cmparts/power/PerfProfileSettings.java
|
||||
index ec2138d..d77c51c 100644
|
||||
--- a/src/org/cyanogenmod/cmparts/power/PerfProfileSettings.java
|
||||
+++ b/src/org/cyanogenmod/cmparts/power/PerfProfileSettings.java
|
||||
@@ -56,11 +56,13 @@ public class PerfProfileSettings extends SettingsPreferenceFragment
|
||||
private static final String KEY_PERF_PROFILE_CATEGORY = "perf_profile_category";
|
||||
private static final String KEY_AUTO_POWER_SAVE = "auto_power_save";
|
||||
private static final String KEY_POWER_SAVE = "power_save";
|
||||
+ private static final String KEY_REDUCE_RESOLUTION = "reduce_resolution";
|
||||
private static final String KEY_PER_APP_PROFILES = "app_perf_profiles_enabled";
|
||||
private static final String KEY_PERF_SEEKBAR = "perf_seekbar";
|
||||
|
||||
private ListPreference mAutoPowerSavePref;
|
||||
private SwitchPreference mPowerSavePref;
|
||||
+ private SwitchPreference mReduceResolutionPref;
|
||||
|
||||
private SeekBarPreference mPerfSeekBar;
|
||||
private StopMotionVectorDrawable mPerfDrawable;
|
||||
@@ -90,6 +92,7 @@ public class PerfProfileSettings extends SettingsPreferenceFragment
|
||||
mPerfSeekBar = (SeekBarPreference) findPreference(KEY_PERF_SEEKBAR);
|
||||
mAutoPowerSavePref = (ListPreference) findPreference(KEY_AUTO_POWER_SAVE);
|
||||
mPowerSavePref = (SwitchPreference) findPreference(KEY_POWER_SAVE);
|
||||
+ mReduceResolutionPref = (SwitchPreference) findPreference(KEY_REDUCE_RESOLUTION);
|
||||
mPerAppProfilesPref = (SwitchPreference) findPreference(KEY_PER_APP_PROFILES);
|
||||
|
||||
mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
@@ -124,6 +127,7 @@ public class PerfProfileSettings extends SettingsPreferenceFragment
|
||||
updateAutoPowerSaveValue();
|
||||
mAutoPowerSavePref.setOnPreferenceChangeListener(this);
|
||||
mPowerSavePref.setOnPreferenceChangeListener(this);
|
||||
+ mReduceResolutionPref.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -245,6 +249,14 @@ public class PerfProfileSettings extends SettingsPreferenceFragment
|
||||
final int level = Integer.parseInt((String) newValue);
|
||||
Global.putInt(getContentResolver(), Global.LOW_POWER_MODE_TRIGGER_LEVEL, level);
|
||||
updateAutoPowerSaveSummary(level);
|
||||
+ } else if (preference = mReduceResolutionPref) {
|
||||
+ if (!mPowerManager.setReducedResolution((boolean) newValue)) {
|
||||
+ // Don't just fail silently, inform the user as well
|
||||
+ Toast.makeText(getActivity(),
|
||||
+ R.string.perf_profile_fail_toast, Toast.LENGTH_SHORT).show();
|
||||
+ return false;
|
||||
+ }
|
||||
+ updateReducedResolutionValue();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -262,6 +274,10 @@ public class PerfProfileSettings extends SettingsPreferenceFragment
|
||||
PartsUpdater.notifyChanged(getActivity(), getPreferenceScreen().getKey());
|
||||
}
|
||||
|
||||
+ private void updateReduceResolutionValue() {
|
||||
+ mReduceResolution.setChecked(mPowerManager.isReducedResolution());
|
||||
+ }
|
||||
+
|
||||
private void updateAutoPowerSaveValue() {
|
||||
final int level = Global.getInt(
|
||||
getContentResolver(), Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
|
||||
--
|
||||
2.14.2
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue