This is a direct reimplementation in L of fixes applied to N in these two commits: 8dc8d37c e8741d23 Bug 19285814 Change-Id: I59bcc8f1d41c426e9da635bea9ad1d7c6756d5aa