Fix VR mode handling when the screen blanks and unblanks.
When blanking the screen, turn off VR mode if it's enabled, and when waking up
after the keyboard goes away, turn it on if the top activity has requested VR
mode.
Bug: 26751056
Change-Id: Ib57b1c59e083e3615a02408d922c8c7be645ce92
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 3ec51e3..bf1cb79 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -1468,6 +1468,7 @@
static final int NOTIFY_PINNED_STACK_ANIMATION_ENDED_LISTENERS_MSG = 66;
static final int NOTIFY_FORCED_RESIZABLE_MSG = 67;
static final int NOTIFY_ACTIVITY_DISMISSING_DOCKED_STACK_MSG = 68;
+ static final int VR_MODE_APPLY_IF_NEEDED_MSG = 69;
static final int FIRST_ACTIVITY_STACK_MSG = 100;
static final int FIRST_BROADCAST_QUEUE_MSG = 200;
@@ -2238,6 +2239,17 @@
}
vrService.setVrMode(vrMode, requestedPackage, userId, callingPackage);
} break;
+ case VR_MODE_APPLY_IF_NEEDED_MSG: {
+ final ActivityRecord r = (ActivityRecord) msg.obj;
+ final boolean needsVrMode = r != null && r.requestedVrComponent != null;
+ if (needsVrMode) {
+ VrManagerInternal vrService =
+ LocalServices.getService(VrManagerInternal.class);
+ boolean enable = msg.arg1 == 1;
+ vrService.setVrMode(enable, r.requestedVrComponent, r.userId,
+ r.info.getComponentName());
+ }
+ } break;
}
}
};
@@ -3018,6 +3030,11 @@
mHandler.obtainMessage(VR_MODE_CHANGE_MSG, 0, 0, r));
}
+ private void applyVrModeIfNeededLocked(ActivityRecord r, boolean enable) {
+ mHandler.sendMessage(
+ mHandler.obtainMessage(VR_MODE_APPLY_IF_NEEDED_MSG, enable ? 1 : 0, 0, r));
+ }
+
final void showAskCompatModeDialogLocked(ActivityRecord r) {
Message msg = Message.obtain();
msg.what = SHOW_COMPAT_MODE_DIALOG_UI_MSG;
@@ -6534,6 +6551,7 @@
// Some stack visibility might change (e.g. docked stack)
mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
+ applyVrModeIfNeededLocked(mFocusedActivity, true);
}
}
} finally {
@@ -20905,6 +20923,7 @@
SleepTokenImpl token = new SleepTokenImpl(tag);
mSleepTokens.add(token);
updateSleepIfNeededLocked();
+ applyVrModeIfNeededLocked(mFocusedActivity, false);
return token;
}
}