|
46 | 46 | import android.os.Looper; |
47 | 47 | import android.os.Message; |
48 | 48 | import android.os.ParcelFileDescriptor; |
| 49 | +import android.os.PowerManager; |
49 | 50 | import android.os.Process; |
50 | 51 | import android.os.RemoteException; |
51 | 52 | import android.os.SystemClock; |
@@ -390,6 +391,9 @@ public ViewRootImpl(Context context) { |
390 | 391 | mProfileRendering = Boolean.parseBoolean( |
391 | 392 | SystemProperties.get(PROPERTY_PROFILE_RENDERING, "false")); |
392 | 393 | mChoreographer = Choreographer.getInstance(); |
| 394 | + |
| 395 | + PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); |
| 396 | + mAttachInfo.mScreenOn = powerManager.isScreenOn(); |
393 | 397 | } |
394 | 398 |
|
395 | 399 | /** |
@@ -757,6 +761,16 @@ void handleGetNewSurface() { |
757 | 761 | scheduleTraversals(); |
758 | 762 | } |
759 | 763 |
|
| 764 | + void handleScreenStatusChange(boolean on) { |
| 765 | + if (on != mAttachInfo.mScreenOn) { |
| 766 | + mAttachInfo.mScreenOn = on; |
| 767 | + if (on) { |
| 768 | + mFullRedrawNeeded = true; |
| 769 | + scheduleTraversals(); |
| 770 | + } |
| 771 | + } |
| 772 | + } |
| 773 | + |
760 | 774 | /** |
761 | 775 | * {@inheritDoc} |
762 | 776 | */ |
@@ -1886,6 +1900,8 @@ private void trackFPS() { |
1886 | 1900 | } |
1887 | 1901 |
|
1888 | 1902 | private void performDraw() { |
| 1903 | + if (!mAttachInfo.mScreenOn) return; |
| 1904 | + |
1889 | 1905 | final long drawStartTime; |
1890 | 1906 | if (ViewDebug.DEBUG_LATENCY) { |
1891 | 1907 | drawStartTime = System.nanoTime(); |
@@ -2018,8 +2034,7 @@ private void draw(boolean fullRedrawNeeded) { |
2018 | 2034 | } |
2019 | 2035 |
|
2020 | 2036 | if (!dirty.isEmpty() || mIsAnimating) { |
2021 | | - if (mAttachInfo.mHardwareRenderer != null |
2022 | | - && mAttachInfo.mHardwareRenderer.isEnabled()) { |
| 2037 | + if (mAttachInfo.mHardwareRenderer != null && mAttachInfo.mHardwareRenderer.isEnabled()) { |
2023 | 2038 | // Draw with hardware renderer. |
2024 | 2039 | mIsAnimating = false; |
2025 | 2040 | mHardwareYOffset = yoff; |
@@ -2485,6 +2500,7 @@ private static void forceLayout(View view) { |
2485 | 2500 | private final static int MSG_FIND_ACCESSIBLITY_NODE_INFO_BY_VIEW_ID = 21; |
2486 | 2501 | private final static int MSG_FIND_ACCESSIBLITY_NODE_INFO_BY_TEXT = 22; |
2487 | 2502 | private final static int MSG_PROCESS_INPUT_EVENTS = 23; |
| 2503 | + private final static int MSG_DISPATCH_SCREEN_STATUS = 24; |
2488 | 2504 |
|
2489 | 2505 | final class ViewRootHandler extends Handler { |
2490 | 2506 | @Override |
@@ -2741,6 +2757,11 @@ public void handleMessage(Message msg) { |
2741 | 2757 | .findAccessibilityNodeInfosByTextUiThread(msg); |
2742 | 2758 | } |
2743 | 2759 | } break; |
| 2760 | + case MSG_DISPATCH_SCREEN_STATUS: { |
| 2761 | + if (mView != null) { |
| 2762 | + handleScreenStatusChange(msg.arg1 == 1); |
| 2763 | + } |
| 2764 | + } break; |
2744 | 2765 | } |
2745 | 2766 | } |
2746 | 2767 | } |
@@ -4121,6 +4142,12 @@ public void dispatchAppVisibility(boolean visible) { |
4121 | 4142 | mHandler.sendMessage(msg); |
4122 | 4143 | } |
4123 | 4144 |
|
| 4145 | + public void dispatchScreenStatusChange(boolean on) { |
| 4146 | + Message msg = mHandler.obtainMessage(MSG_DISPATCH_SCREEN_STATUS); |
| 4147 | + msg.arg1 = on ? 1 : 0; |
| 4148 | + mHandler.sendMessage(msg); |
| 4149 | + } |
| 4150 | + |
4124 | 4151 | public void dispatchGetNewSurface() { |
4125 | 4152 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_GET_NEW_SURFACE); |
4126 | 4153 | mHandler.sendMessage(msg); |
@@ -4322,6 +4349,13 @@ public void dispatchAppVisibility(boolean visible) { |
4322 | 4349 | } |
4323 | 4350 | } |
4324 | 4351 |
|
| 4352 | + public void dispatchScreenStatus(boolean on) { |
| 4353 | + final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 4354 | + if (viewAncestor != null) { |
| 4355 | + viewAncestor.dispatchScreenStatusChange(on); |
| 4356 | + } |
| 4357 | + } |
| 4358 | + |
4325 | 4359 | public void dispatchGetNewSurface() { |
4326 | 4360 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
4327 | 4361 | if (viewAncestor != null) { |
|
0 commit comments