Check if focused window is null to prevent NPE

Change-Id: I87926d4df9fb1ba7f68805ef32d9354643bdbd1a