Initial implementation of allowing the user to reduce screen resolution to save power

This commit is contained in:
Tad 2017-10-20 15:31:04 -04:00
parent cfaed310f1
commit b3108b9e7f
5 changed files with 206 additions and 2 deletions

16
Misc/Scaling.txt Normal file
View File

@ -0,0 +1,16 @@
//frameworks/base/cmds/wm/src/com/android/commands/wm/Wm.java
IWindowManager mWm = IWindowManager.Stub.asInterface(ServiceManager.checkService(
Context.WINDOW_SERVICE));
Point initialSize = new Point();
Point baseSize = new Point();
mWm.getInitialDisplaySize(Display.DEFAULT_DISPLAY, initialSize); //Get true size
mWm.getBaseDisplaySize(Display.DEFAULT_DISPLAY, baseSize); //Get current size
mWm.setForcedDisplaySize(Display.DEFAULT_DISPLAY, w, h); //Set to custom size
mWm.clearForcedDisplaySize(Display.DEFAULT_DISPLAY); //Reset to true size
1440*2560
1080*1920
720*1280

View File

@ -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

View File

@ -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

View File

@ -3,8 +3,6 @@
#Attempts to increase performance and battery life
#TODO: Aggressive Doze (Easy), Lower screen resolutions (Hard)
base="/mnt/Drive-1/Development/Other/Android_ROMs/Build/LineageOS-14.1/"
echo "Optimizing..."

View File

@ -108,6 +108,7 @@ sed -i 's/com.android.messaging/org.smssecure.smssecure/' core/res/res/values/co
sed -i 's|config_longPressOnHomeBehavior">2|config_longPressOnHomeBehavior">0|' core/res/res/values/config.xml;
sed -i 's|config_doubleTapOnHomeBehavior">0|config_doubleTapOnHomeBehavior">8|' core/res/res/values/config.xml;
sed -i 's|config_permissionReviewRequired">false|config_permissionReviewRequired">true|' core/res/res/values/config.xml;
patch -p1 < $patches"android_frameworks_base/0001-Reduced_Resolution.patch" #Allow reducing resolution to save power
patch -p1 < $patches"android_frameworks_base/0003-Signature_Spoofing.patch" #Allow packages to spoof their signature (MicroG)
patch -p1 < $patches"android_frameworks_base/0005-Harden_Sig_Spoofing.patch" #Restrict signature spoofing to system apps signed with the platform key
rm -rf packages/PrintRecommendationService; #App that just creates popups to install proprietary print apps
@ -121,6 +122,7 @@ rm -rf src/org/cyanogenmod/cmparts/cmstats/ res/xml/anonymous_stats.xml res/xml/
git fetch https://review.lineageos.org/LineageOS/android_packages_apps_CMParts refs/changes/15/113415/25 && git cherry-pick FETCH_HEAD #network traffic
sed -i 's|config_showWeatherMenu">true|config_showWeatherMenu">false|' res/values/config.xml; #Disable Weather
patch -p1 < $patches"android_packages_apps_CMParts/0001-Remove_Analytics.patch" #Remove the rest of CMStats
patch -p1 < $patches"android_packages_apps_CMParts/0002-Reduced_Resolution.patch" #Allow reducing resolution to save power
enter "packages/apps/Updater"
patch -p1 < $patches"android_packages_apps_Updater/0001-Server.patch" #Switch to our server