This also adds some optional debug code to detect more easily possible future occurrences of the same problem. Bug: 5195017 Change-Id: I2558b468e46f7090de868f1ec2dc9e24895d670f
This is internal refactoring, done as preliminary work to fix Bug: 5175740 Change-Id: I21bd4c001c27e7b925ddb87a152105b4dcab320a