From 56c76ff50e2c410aec349110c23b95556d0f2ade Mon Sep 17 00:00:00 2001 From: Tad Date: Fri, 20 Oct 2017 18:57:18 -0400 Subject: [PATCH] Reduced Resolution Feature 2/2 Change-Id: If18913234f902410f87f8664f1017c83944544ee --- core/java/android/os/IPowerManager.aidl | 2 + core/java/android/os/PowerManager.java | 30 +++++++++ .../android/server/power/PowerManagerService.java | 72 ++++++++++++++++++++++ 3 files changed, 104 insertions(+) diff --git a/core/java/android/os/IPowerManager.aidl b/core/java/android/os/IPowerManager.aidl index 26eb7f169a0..38bd8a4e386 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(); + boolean setReducedResolution(boolean mode); boolean isDeviceIdleMode(); boolean isLightDeviceIdleMode(); diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index 5c8effec0ed..54dd5965373 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -988,6 +988,36 @@ public final class PowerManager { } } + /** + * Returns true if the WindowManager is running at a reduced resolution + * + * @return Returns true if WindowManager is set to a reduced resolution, else false. + */ + public boolean isReducedResolution() { + try { + return mService.isReducedResolution(); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * Set the reduced resolution mode + * + * @return True if the set was allowed. + * + * @see #isReducedResolution() + * + * @hide + */ + public boolean setReducedResolution(boolean mode) { + try { + return mService.setReducedResolution(mode); + } catch (RemoteException 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 diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index 55d0809ee4e..668176dc761 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)); qcNsrmPowExt = new QCNsrmPowerExtension(this); synchronized (mLock) { mWakeLockSuspendBlocker = createSuspendBlockerLocked("PowerManagerService.WakeLocks"); @@ -2658,6 +2663,46 @@ public final class PowerManagerService extends SystemService } } + 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); + } + } + + private boolean isLowPowerModeInternal(boolean mode) { + synchronized (mLock) { + if (mode) { + Point initialSize = new Point(); + mWm.getInitialDisplaySize(Display.DEFAULT_DISPLAY, initialSize); + + Point newSize; + + if (initialSize.x == 1440 && initialSize.y == 2560) {//16:9 + newSize = new Point(1080, 1920);//.75 + } else if(initialSize.x == 1200 && initialSize.y == 1920) {//16:10 + newSize = new Point(900, 1440);//.75 + } else if(initialSize.x == 1080 && initialSize.y == 1920) {//16:9 + newSize = new Point(720, 1280);//.50 + } else if(initialSize.x == 768 && initialSize.y == 1280) {//5:3 + newSize = new Point(576, 960);//.75 + } else { + return false; + } + + mWm.setForcedDisplaySize(Display.DEFAULT_DISPLAY, newSize.x, newSize.y); + } else { + mWm.clearForcedDisplaySize(Display.DEFAULT_DISPLAY); + } + return isReducedResolutionInternal(); + } + } + boolean isDeviceIdleModeInternal() { synchronized (mLock) { return mDeviceIdleMode; @@ -3833,6 +3878,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 +4281,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