Fix unexpected VR mode exit on package update.

am: 1ad4a2d32e

Change-Id: Ic0c025d3f360197dc41fe2b999b5d20763285cd5
This commit is contained in:
Ruben Brunk
2017-01-06 21:14:27 +00:00
committed by android-build-merger

View File

@@ -320,7 +320,6 @@ public class VrManagerService extends SystemService implements EnabledComponentC
public void onEnabledComponentChanged() { public void onEnabledComponentChanged() {
synchronized (mLock) { synchronized (mLock) {
int currentUser = ActivityManager.getCurrentUser(); int currentUser = ActivityManager.getCurrentUser();
// Update listeners // Update listeners
ArraySet<ComponentName> enabledListeners = mComponentObserver.getEnabled(currentUser); ArraySet<ComponentName> enabledListeners = mComponentObserver.getEnabled(currentUser);
@@ -338,7 +337,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC
} }
// If there is a pending state change, we'd better deal with that first // If there is a pending state change, we'd better deal with that first
consumeAndApplyPendingStateLocked(); consumeAndApplyPendingStateLocked(false);
if (mCurrentVrService == null) { if (mCurrentVrService == null) {
return; // No active services return; // No active services
@@ -606,8 +605,9 @@ public class VrManagerService extends SystemService implements EnabledComponentC
if (!goingIntoVrMode) { if (!goingIntoVrMode) {
// Not going into VR mode, unbind whatever is running // Not going into VR mode, unbind whatever is running
if (mCurrentVrService != null) { if (mCurrentVrService != null) {
Slog.i(TAG, "Disconnecting " + mCurrentVrService.getComponent() + " for user " + Slog.i(TAG, "Leaving VR mode, disconnecting "
mCurrentVrService.getUserId()); + mCurrentVrService.getComponent() + " for user "
+ mCurrentVrService.getUserId());
mCurrentVrService.disconnect(); mCurrentVrService.disconnect();
mCurrentVrService = null; mCurrentVrService = null;
} else { } else {
@@ -619,8 +619,9 @@ public class VrManagerService extends SystemService implements EnabledComponentC
// Unbind any running service that doesn't match the latest component/user // Unbind any running service that doesn't match the latest component/user
// selection. // selection.
if (mCurrentVrService.disconnectIfNotMatching(component, userId)) { if (mCurrentVrService.disconnectIfNotMatching(component, userId)) {
Slog.i(TAG, "Disconnecting " + mCurrentVrService.getComponent() + Slog.i(TAG, "VR mode component changed to " + component
" for user " + mCurrentVrService.getUserId()); + ", disconnecting " + mCurrentVrService.getComponent()
+ " for user " + mCurrentVrService.getUserId());
createAndConnectService(component, userId); createAndConnectService(component, userId);
sendUpdatedCaller = true; sendUpdatedCaller = true;
} else { } else {
@@ -868,16 +869,30 @@ public class VrManagerService extends SystemService implements EnabledComponentC
sBinderChecker); sBinderChecker);
} }
/**
* Apply the pending VR state. If no state is pending, disconnect any currently bound
* VR listener service.
*/
private void consumeAndApplyPendingStateLocked() { private void consumeAndApplyPendingStateLocked() {
consumeAndApplyPendingStateLocked(true);
}
/**
* Apply the pending VR state.
*
* @param disconnectIfNoPendingState if {@code true}, then any currently bound VR listener
* service will be disconnected if no state is pending. If this is {@code false} then the
* nothing will be changed when there is no pending state.
*/
private void consumeAndApplyPendingStateLocked(boolean disconnectIfNoPendingState) {
if (mPendingState != null) { if (mPendingState != null) {
updateCurrentVrServiceLocked(mPendingState.enabled, updateCurrentVrServiceLocked(mPendingState.enabled,
mPendingState.targetPackageName, mPendingState.userId, mPendingState.targetPackageName, mPendingState.userId,
mPendingState.callingPackage); mPendingState.callingPackage);
mPendingState = null; mPendingState = null;
} else { } else if (disconnectIfNoPendingState) {
updateCurrentVrServiceLocked(false, null, 0, null); updateCurrentVrServiceLocked(false, null, 0, null);
} }
} }
private void logStateLocked() { private void logStateLocked() {