Merge "Fix a race-condition that returns incorrect foreground call"