Repository: nvaccess/nvda

Issue:
NVDA-alpha-23765 abnormal behavior on the secure desktop

### Steps to reproduce:
1. Install Alpha-23765.
2. Press Ctrl + Alt + Delete to enter the safe desktop;
3. Press the Tab key to try to navigate the contents of the secure desktop.
4. NVDA+N to open the NVDA menu.

### Actual behavior:
1. Execute step 3 NVDA does not announce anything.
2. Execute step 4 NVDA can announce the contents of the NVDA menu normally.

### Expected behavior:
Execute step 3, NVDA reads "lock", "logout" and other items.

### System configuration
#### NVDA installed/portable/running from source:
installed
#### NVDA version:
Alpha-23765 
#### Windows version:
Windows 10 21H1 (x64) build 19043.1237
#### Name and version of other software in use when reproducing the issue:
None
#### Other information about your system:
None
### Other questions
#### Does the issue still occur after restarting your computer?
Yes
#### Have you tried any other versions of NVDA? If so, please report their behaviors.
NVDA-Alpha-23763 and NVDA 2021.2 work as expected
#### If add-ons are disabled, is your problem still occurring?
Yes
#### Does the issue still occur after you run the COM Registration Fixing Tool in NVDA's tools menu?
Yes


Discussion:
I can reproduce this.

Resolving patch:
diff --git a/source/_UIAHandler.py b/source/_UIAHandler.py
--- a/source/_UIAHandler.py
+++ b/source/_UIAHandler.py
@@ -746,36 +746,36 @@ def _isUIAWindowHelper(self,hwnd):
 		# Ask the window if it supports UIA natively
 		res=windll.UIAutomationCore.UiaHasServerSideProvider(hwnd)
 		if res:
-			# The window does support UIA natively, but MS Word documents now
-			# have a fairly usable UI Automation implementation.
+			# The window does support UIA natively.
+
+			# MS Word documents now have a fairly usable UI Automation implementation.
 			# However, builds of MS Office 2016 before build 13901 or so had bugs which
 			# we cannot work around.
 			# Therefore for less recent versions of Office,
 			# if we can inject in-process, refuse to use UIA and instead
 			# fall back to the MS Word object model.
-			canUseOlderInProcessApproach = bool(appModule.helperLocalBindingHandle)
-			isOfficeApp = appModule.productName.startswith(("Microsoft Office", "Microsoft Outlook"))
-			if (
-				(
-					winVersion.getWinVer() < winVersion.WIN10
-					or (
-						# An MS Office app before build 13901
-						isOfficeApp
-						and (
-							tuple(int(x) for x in appModule.productVersion.split('.')[:3])
-							< (16, 0, 13901)
+			if windowClass == "_WwG":
+				canUseOlderInProcessApproach = bool(appModule.helperLocalBindingHandle)
+				isOfficeApp = appModule.productName.startswith(("Microsoft Office", "Microsoft Outlook"))
+				if (
+					(
+						winVersion.getWinVer() < winVersion.WIN10
+						or (
+							# An MS Office app before build 13901
+							isOfficeApp
+							and (
+								tuple(int(x) for x in appModule.productVersion.split('.')[:3])
+								< (16, 0, 13901)
+							)
 						)
 					)
-				)
-				# An MS Word document window
-				and windowClass == "_WwG"
-				# Disabling is only useful if we can inject in-process (and use our older code)
-				and canUseOlderInProcessApproach
-				# Allow the user to still explicitly force UIA support
-				# no matter the Office version
-				and not config.conf['UIA']['useInMSWordWhenAvailable']
-			):
-				return False
+					# Disabling is only useful if we can inject in-process (and use our older code)
+					and canUseOlderInProcessApproach
+					# Allow the user to still explicitly force UIA support
+					# no matter the Office version
+					and not config.conf['UIA']['useInMSWordWhenAvailable']
+				):
+					return False
 			# MS Excel spreadsheets now have a fairly usable UI Automation implementation.
 			# However, builds of MS Office 2016 before build 9000 or so had bugs which we
 			# cannot work around.
@@ -807,7 +807,7 @@ def _isUIAWindowHelper(self,hwnd):
 				)
 			):
 				return False
-			if windowClass == "ConsoleWindowClass":
+			elif windowClass == "ConsoleWindowClass":
 				return UIAUtils._shouldUseUIAConsole(hwnd)
 		return bool(res)
 


Test patch: