diff --git a/api/current.txt b/api/current.txt index 61345fde1823a..85abae926b458 100644 --- a/api/current.txt +++ b/api/current.txt @@ -43630,6 +43630,7 @@ package android.view { method public void setSharedElementsUseOverlay(boolean); method public void setSoftInputMode(int); method public abstract void setStatusBarColor(int); + method public void setSustainedPerformanceMode(boolean); method public abstract void setTitle(java.lang.CharSequence); method public abstract deprecated void setTitleColor(int); method public void setTransitionBackgroundFadeDuration(long); diff --git a/api/system-current.txt b/api/system-current.txt index d44e15708dc35..4cf6436379983 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -46579,6 +46579,7 @@ package android.view { method public void setSharedElementsUseOverlay(boolean); method public void setSoftInputMode(int); method public abstract void setStatusBarColor(int); + method public void setSustainedPerformanceMode(boolean); method public abstract void setTitle(java.lang.CharSequence); method public abstract deprecated void setTitleColor(int); method public void setTransitionBackgroundFadeDuration(long); diff --git a/api/test-current.txt b/api/test-current.txt index 40209933e7d06..3dddfcf8bc253 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -43707,6 +43707,7 @@ package android.view { method public void setSharedElementsUseOverlay(boolean); method public void setSoftInputMode(int); method public abstract void setStatusBarColor(int); + method public void setSustainedPerformanceMode(boolean); method public abstract void setTitle(java.lang.CharSequence); method public abstract deprecated void setTitleColor(int); method public void setTransitionBackgroundFadeDuration(long); diff --git a/core/java/android/os/PowerManagerInternal.java b/core/java/android/os/PowerManagerInternal.java index 9801e1bef2c2d..b3cf710094e03 100644 --- a/core/java/android/os/PowerManagerInternal.java +++ b/core/java/android/os/PowerManagerInternal.java @@ -55,12 +55,16 @@ public abstract class PowerManagerInternal { /** - * Power hint: The user is interacting with the device. The corresponding data field must be + * Power hint: + * Interaction: The user is interacting with the device. The corresponding data field must be * the expected duration of the fling, or 0 if unknown. * - * This must be kept in sync with the values in hardware/libhardware/include/hardware/power.h + * Sustained Performance Mode: Enable/Disables Sustained Performance Mode. + * + * These must be kept in sync with the values in hardware/libhardware/include/hardware/power.h */ public static final int POWER_HINT_INTERACTION = 2; + public static final int POWER_HINT_SUSTAINED_PERFORMANCE_MODE = 6; public static String wakefulnessToString(int wakefulness) { switch (wakefulness) { diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java index 2f3f0bfa9612b..51356578fd9bf 100644 --- a/core/java/android/view/Window.java +++ b/core/java/android/view/Window.java @@ -1177,6 +1177,15 @@ public abstract class Window { return false; } + /* Sets the Sustained Performance requirement for the calling window. + * @param enable disables or enables the mode. + */ + public void setSustainedPerformanceMode(boolean enable) { + setPrivateFlags(enable + ? WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE : 0, + WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE); + } + private boolean isOutOfBounds(Context context, MotionEvent event) { final int x = (int) event.getX(); final int y = (int) event.getY(); diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java index 89e146b3fed88..54e9942db4d08 100644 --- a/core/java/android/view/WindowManager.java +++ b/core/java/android/view/WindowManager.java @@ -1246,6 +1246,13 @@ public interface WindowManager extends ViewManager { */ public static final int PRIVATE_FLAG_FORCE_DRAW_STATUS_BAR_BACKGROUND = 0x00020000; + /** + * Flag to indicate that this window needs Sustained Performance Mode if + * the device supports it. + * @hide + */ + public static final int PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE = 0x00020000; + /** * Control flags that are private to the platform. * @hide diff --git a/services/core/java/com/android/server/wm/WindowSurfacePlacer.java b/services/core/java/com/android/server/wm/WindowSurfacePlacer.java index 1e6c585da12de..928fcc03255a1 100644 --- a/services/core/java/com/android/server/wm/WindowSurfacePlacer.java +++ b/services/core/java/com/android/server/wm/WindowSurfacePlacer.java @@ -8,6 +8,7 @@ import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION; +import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE; import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; import static android.view.WindowManager.LayoutParams.TYPE_DREAM; @@ -128,6 +129,9 @@ class WindowSurfacePlacer { private boolean mTraversalScheduled; private int mDeferDepth = 0; + private boolean mSustainedPerformanceModeEnabled = false; + private boolean mSustainedPerformanceModeCurrent = false; + private static final class LayerAndToken { public int layer; public AppWindowToken token; @@ -288,7 +292,7 @@ class WindowSurfacePlacer { mButtonBrightness = -1; mUserActivityTimeout = -1; mObscureApplicationContentOnSecondaryDisplays = false; - + mSustainedPerformanceModeCurrent = false; mService.mTransactionSequence++; final DisplayContent defaultDisplay = mService.getDefaultDisplayContentLocked(); @@ -487,6 +491,13 @@ class WindowSurfacePlacer { mUserActivityTimeout); } + if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) { + mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent; + mService.mPowerManagerInternal.powerHint( + mService.mPowerManagerInternal.POWER_HINT_SUSTAINED_PERFORMANCE_MODE, + (mSustainedPerformanceModeEnabled ? 1 : 0)); + } + if (mService.mTurnOnScreen) { if (mService.mAllowTheaterModeWakeFromLayout || Settings.Global.getInt(mService.mContext.getContentResolver(), @@ -1409,6 +1420,7 @@ class WindowSurfacePlacer { final LayoutParams attrs = w.mAttrs; final int attrFlags = attrs.flags; final boolean canBeSeen = w.isDisplayedLw(); + final int privateflags = attrs.privateFlags; if (canBeSeen && w.isObscuringFullscreen(dispInfo)) { // This window completely covers everything behind it, @@ -1469,6 +1481,9 @@ class WindowSurfacePlacer { && w.mAttrs.preferredDisplayModeId != 0) { mPreferredModeId = w.mAttrs.preferredDisplayModeId; } + if ((privateflags & PRIVATE_FLAG_SUSTAINED_PERFORMANCE_MODE) != 0) { + mSustainedPerformanceModeCurrent = true; + } } } }