DivestOS/Patches/LineageOS-14.1/android_frameworks_base/0001-Reduced_Resolution.patch

178 lines
6.6 KiB
Diff
Raw Normal View History

2017-10-20 16:54:46 -04:00
From 26c93270376c4c786d76ceed0f6ae78f822dbda6 Mon Sep 17 00:00:00 2001
From: Tad <tad@spotco.us>
2017-10-20 16:54:46 -04:00
Date: Fri, 20 Oct 2017 16:53:48 -0400
Subject: [PATCH] Reduced Resolution Feature 2/2
2017-10-20 16:54:46 -04:00
Change-Id: I53234c8db2bd522c90c2d8fe734670482c9c8caa
---
2017-10-20 16:54:46 -04:00
core/java/android/os/IPowerManager.aidl | 2 +
core/java/android/os/PowerManager.java | 16 +++++
.../android/server/power/PowerManagerService.java | 69 ++++++++++++++++++++++
3 files changed, 87 insertions(+)
2017-10-20 16:54:46 -04:00
diff --git a/core/java/android/os/IPowerManager.aidl b/core/java/android/os/IPowerManager.aidl
index 26eb7f169a0..86e4175f444 100644
--- a/core/java/android/os/IPowerManager.aidl
+++ b/core/java/android/os/IPowerManager.aidl
@@ -46,6 +46,8 @@ interface IPowerManager
boolean isInteractive();
boolean isPowerSaveMode();
boolean setPowerSaveMode(boolean mode);
+ boolean isReducedResolution()
+ setReducedResolution(boolean mode)
boolean isDeviceIdleMode();
boolean isLightDeviceIdleMode();
diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java
2017-10-20 16:54:46 -04:00
index 5c8effec0ed..358fe61c46f 100644
--- a/core/java/android/os/PowerManager.java
+++ b/core/java/android/os/PowerManager.java
2017-10-20 16:54:46 -04:00
@@ -988,6 +988,22 @@ public final class PowerManager {
}
}
2017-10-20 16:54:46 -04:00
+ public boolean isReducedResolution() {
+ try {
+ return mService.isReducedResolution();
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
2017-10-20 16:54:46 -04:00
+ public boolean setReducedResolution(boolean mode) {
+ try {
+ return mService.setReducedResolution(mode);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
2017-10-20 16:54:46 -04:00
/**
* 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
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
index 55d0809ee4e..7328dfd4dc9 100644
--- a/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -29,6 +29,7 @@ import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.database.ContentObserver;
+import android.graphics.Point;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
@@ -67,6 +68,7 @@ import android.util.Slog;
import android.util.SparseIntArray;
import android.util.TimeUtils;
import android.view.Display;
+import android.view.IWindowManager;
import android.view.WindowManagerPolicy;
import com.android.internal.app.IAppOpsService;
@@ -203,6 +205,7 @@ public final class PowerManagerService extends SystemService
private final Context mContext;
private final ServiceThread mHandlerThread;
private final PowerManagerHandler mHandler;
+ private final IWindowManager mWm;
private LightsManager mLightsManager;
private BatteryManagerInternal mBatteryManagerInternal;
@@ -583,6 +586,8 @@ public final class PowerManagerService extends SystemService
Process.THREAD_PRIORITY_DISPLAY, false /*allowIo*/);
mHandlerThread.start();
mHandler = new PowerManagerHandler(mHandlerThread.getLooper());
+ mWm = IWindowManager.Stub.asInterface(ServiceManager.checkService(
+ Context.WINDOW_SERVICE));
2017-10-20 16:54:46 -04:00
qcNsrmPowExt = new QCNsrmPowerExtension(this);
synchronized (mLock) {
mWakeLockSuspendBlocker = createSuspendBlockerLocked("PowerManagerService.WakeLocks");
@@ -2658,6 +2663,43 @@ public final class PowerManagerService extends SystemService
}
}
2017-10-20 16:54:46 -04:00
+ private boolean isReducedResolutionInternal() {
+ synchronized (mLock) {
+ Point initialSize = new Point();
+ Point baseSize = new Point();
+
+ mWm.getInitialDisplaySize(Display.DEFAULT_DISPLAY, initialSize);
+ mWm.getBaseDisplaySize(Display.DEFAULT_DISPLAY, baseSize);
+
+ return !initialSize.equals(baseSize);
+ }
+ }
+
2017-10-20 16:54:46 -04:00
+ private boolean isLowPowerModeInternal(boolean mode) {
+ synchronized (mLock) {
+ 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);
+ }
2017-10-20 16:54:46 -04:00
+ return isReducedResolutionInternal();
+ }
+ }
+
2017-10-20 16:54:46 -04:00
boolean isDeviceIdleModeInternal() {
synchronized (mLock) {
return mDeviceIdleMode;
@@ -3833,6 +3875,28 @@ public final class PowerManagerService extends SystemService
}
}
+ @Override // Binder call
+ public boolean isReducedResolutionMode() {
+ final long ident = Binder.clearCallingIdentity();
+ try {
+ return isReducedResolutionInternal();
+ } finally {
+ Binder.restoreCallingIdentity(ident);
+ }
+ }
+
+ @Override // Binder call
+ public boolean setReducedResolutionode(boolean mode) {
+ mContext.enforceCallingOrSelfPermission(
+ android.Manifest.permission.DEVICE_POWER, null);
+ final long ident = Binder.clearCallingIdentity();
+ try {
+ return setReducedResolutionInternal(mode);
+ } finally {
+ Binder.restoreCallingIdentity(ident);
+ }
+ }
+
@Override // Binder call
public boolean isDeviceIdleMode() {
final long ident = Binder.clearCallingIdentity();
@@ -4214,6 +4278,11 @@ public final class PowerManagerService extends SystemService
return setLowPowerModeInternal(mode);
}
+ @Override
+ public boolean setReducedResolution(boolean mode) {
+ return setReducedResolutionInternal(mode);
+ }
+
@Override
public int getFeature(int featureId) {
return nativeGetFeature(featureId);
--
2.14.2