Merge "Workaround missing OnChannelClose for DisplayManagerService" into pi-dev
am: 409a80198b
Change-Id: Id1947aa9f534671f9f183cdeec2932da50439e12
diff --git a/libs/vr/libpdx/private/pdx/service.h b/libs/vr/libpdx/private/pdx/service.h
index 0d30614..13aa3e9 100644
--- a/libs/vr/libpdx/private/pdx/service.h
+++ b/libs/vr/libpdx/private/pdx/service.h
@@ -589,6 +589,14 @@
}
/*
+ * Return true if a channel with the given ID exists in the Channel map.
+ */
+ bool HasChannelId(int channel_id) const {
+ std::lock_guard<std::mutex> autolock(channels_mutex_);
+ return channels_.find(channel_id) != channels_.end();
+ }
+
+ /*
* Subclasses of Service may override this method to provide a text string
* describing the state of the service. This method is called by
* HandleSystemMessage in response to the standard
diff --git a/libs/vr/libvrflinger/display_manager_service.cpp b/libs/vr/libvrflinger/display_manager_service.cpp
index ef8cca3..34b3b0a 100644
--- a/libs/vr/libvrflinger/display_manager_service.cpp
+++ b/libs/vr/libvrflinger/display_manager_service.cpp
@@ -45,6 +45,14 @@
const int user_id = message.GetEffectiveUserId();
const bool trusted = user_id == AID_ROOT || IsTrustedUid(user_id);
+ // Check if the display_manager_ has a defunct channel.
+ if (display_manager_ && !HasChannelId(display_manager_->channel_id())) {
+ ALOGE("DisplayManagerService::OnChannelOpen: Found defunct channel %d with "
+ "no OnChannelClose, clearing prior display manager.",
+ display_manager_->channel_id());
+ display_manager_ = nullptr;
+ }
+
// Prevent more than one display manager from registering at a time or
// untrusted UIDs from connecting.
if (display_manager_ || !trusted) {