Merge "Improve device state callback for thread context." into main