2222 */
2323
2424/*
25- * WinRT-backed services for the Windows port (biometric / Windows Hello, and --
26- * added incrementally -- location, contacts, share). WinRT is consumed through
27- * the WRL ABI projection (RoGetActivationFactory + the ABI:: interfaces), the
28- * same COM-based mechanism the Media Foundation layer already uses, so no
29- * C++/WinRT (cppwinrt) projection headers are required.
25+ * WinRT-backed services for the Windows port: biometric (Windows Hello), location,
26+ * contacts and system share. WinRT is consumed through the WRL ABI projection
27+ * (RoGetActivationFactory / RoActivateInstance + the ABI:: interfaces), the same
28+ * COM-based mechanism the Media Foundation layer already uses -- no C++/WinRT
29+ * (cppwinrt) projection headers are required, and runtimeobject.lib is linked
30+ * unconditionally. The WinRT ABI headers + runtimeobject ship in every Windows
31+ * SDK the port builds against, including the xwin-laid-out SDK used by the
32+ * Windows-free Linux cross-compile (verified by that CI leg compiling this file).
3033 *
31- * The whole real implementation is gated on CN1_HAVE_WINRT, which the generated
32- * CMake defines only after a probe confirms the WinRT ABI headers +
33- * runtimeobject.lib are present and link on the build toolchain. When it is not
34- * defined (e.g. a cross-compile sysroot without WinRT) every bridge below
35- * compiles as an honest "unsupported" stub, so the Windows-free build stays green
36- * and the matching CN1 capability simply reports false / null.
34+ * Each bridge still degrades honestly at RUNTIME -- a missing device, disabled
35+ * Windows setting or denied permission surfaces as false / null (never fabricated
36+ * data) -- which is what the matching CN1 capability reports as "unsupported".
3737 */
3838
3939#ifdef _WIN32
4040
4141#include " cn1_windows.h"
4242
43- #ifdef CN1_HAVE_WINRT
44-
4543#include < roapi.h>
4644#include < stdlib.h>
4745#include < string.h>
@@ -74,10 +72,9 @@ using namespace Microsoft::WRL::Wrappers;
7472/* Blocks the calling (CN1 worker) thread until a WinRT IAsyncOperation<T>
7573 * completes, then fetches its result. Used for the inherently-async WinRT APIs;
7674 * callers invoke these natives off the EDT (via AsyncResource) so blocking is
77- * fine. */
78- /* TOp is the operation's logical result type (a value type, or a runtimeclass --
79- * for which GetResults yields the ABI *interface* pointer, so the result pointer
80- * type TResultPtr is kept separate from TOp). */
75+ * fine. TOp is the operation's logical result type (a value type, or a
76+ * runtimeclass -- for which GetResults yields the ABI *interface* pointer, so the
77+ * result pointer type TResultPtr is kept separate from TOp). */
8178template <typename TOp, typename TResultPtr>
8279static HRESULT cn1AwaitOp (IAsyncOperation<TOp>* op, TResultPtr result) {
8380 Event done (CreateEventExW (nullptr , nullptr , 0 , EVENT_ALL_ACCESS ));
@@ -162,18 +159,15 @@ static void cn1AppendHString(CN1Buf* out, HSTRING h) {
162159 free (tmp);
163160}
164161
165- #endif /* CN1_HAVE_WINRT */
166-
167162extern " C" {
168163
169164/* ------------------------------------------------------------- biometric
170165 *
171166 * Maps Windows Hello (UserConsentVerifier) to com.codename1.security.Biometrics.
172167 * Returns the UserConsentVerifierAvailability enum: 0 Available, 1
173168 * DeviceNotPresent, 2 NotConfiguredForUser, 3 DisabledByPolicy, 4 DeviceBusy.
174- * The Java side treats 0 as supported+ready. The stub reports DeviceNotPresent . */
169+ * The Java side treats 0 as supported+ready; anything else degrades honestly . */
175170JAVA_INT com_codename1_impl_windows_WindowsNative_biometricAvailability___R_int (CODENAME_ONE_THREAD_STATE ) {
176- #ifdef CN1_HAVE_WINRT
177171 cn1WinRtInit ();
178172 ComPtr<IUserConsentVerifierStatics> statics;
179173 HRESULT hr = RoGetActivationFactory (
@@ -191,16 +185,12 @@ JAVA_INT com_codename1_impl_windows_WindowsNative_biometricAvailability___R_int(
191185 return 1 ;
192186 }
193187 return (JAVA_INT ) avail;
194- #else
195- return 1 ; /* DeviceNotPresent: no WinRT -> report unsupported */
196- #endif
197188}
198189
199190/* Shows the Windows Hello consent prompt with the given reason; returns true
200- * when the user is verified. Stub returns false. */
191+ * when the user is verified. */
201192JAVA_BOOLEAN com_codename1_impl_windows_WindowsNative_biometricAuthenticate___java_lang_String_R_boolean (
202193 CODENAME_ONE_THREAD_STATE , JAVA_OBJECT message) {
203- #ifdef CN1_HAVE_WINRT
204194 cn1WinRtInit ();
205195 ComPtr<IUserConsentVerifierStatics> statics;
206196 HRESULT hr = RoGetActivationFactory (
@@ -225,32 +215,17 @@ JAVA_BOOLEAN com_codename1_impl_windows_WindowsNative_biometricAuthenticate___ja
225215 return JAVA_FALSE ;
226216 }
227217 return result == UserConsentVerificationResult_Verified ? JAVA_TRUE : JAVA_FALSE ;
228- #else
229- (void ) message;
230- return JAVA_FALSE ;
231- #endif
232- }
233-
234- /* True when the port was built with WinRT (so a real Geolocator can be used);
235- * lets getLocationManager() return null honestly on a stub build. */
236- JAVA_BOOLEAN com_codename1_impl_windows_WindowsNative_locationSupported___R_boolean (CODENAME_ONE_THREAD_STATE ) {
237- #ifdef CN1_HAVE_WINRT
238- return JAVA_TRUE ;
239- #else
240- return JAVA_FALSE ;
241- #endif
242218}
243219
244220/* -------------------------------------------------------------- location
245221 *
246222 * Maps Windows.Devices.Geolocation.Geolocator to LocationManager. Fills `out`
247223 * with [latitude, longitude, accuracy(m), altitude(m), direction(deg),
248- * velocity(m/s), timestampMillis ] and returns true; false when location is
249- * unavailable / disabled (Windows location off, or WinRT stub build ) so the
250- * port reports unsupported honestly rather than fabricating a position. */
224+ * velocity(m/s)] and returns true; false when location is unavailable / disabled
225+ * (Windows location off or permission denied ) so the port reports unsupported
226+ * honestly rather than fabricating a position. */
251227JAVA_BOOLEAN com_codename1_impl_windows_WindowsNative_locationGetCurrent___double_1ARRAY_R_boolean (
252228 CODENAME_ONE_THREAD_STATE , JAVA_OBJECT outArr) {
253- #ifdef CN1_HAVE_WINRT
254229 if (outArr == JAVA_NULL ) {
255230 return JAVA_FALSE ;
256231 }
@@ -305,10 +280,6 @@ JAVA_BOOLEAN com_codename1_impl_windows_WindowsNative_locationGetCurrent___doubl
305280 if (n > 4 ) { out[4 ] = heading; }
306281 if (n > 5 ) { out[5 ] = speed; }
307282 return JAVA_TRUE ;
308- #else
309- (void ) outArr;
310- return JAVA_FALSE ;
311- #endif
312283}
313284
314285/* -------------------------------------------------------------- contacts
@@ -317,10 +288,9 @@ JAVA_BOOLEAN com_codename1_impl_windows_WindowsNative_locationGetCurrent___doubl
317288 * single record-delimited blob: each contact is "id US name US phone US email"
318289 * (field separator 0x1F, record separator 0x1E). The Java side parses it into CN1
319290 * Contact objects. One native call avoids a chatty per-field bridge. Returns null
320- * when the store is inaccessible (no WinRT, or access denied) and an empty string
321- * when the store simply has no contacts -- both honest, never fabricated. */
291+ * when the store is inaccessible (access denied) and an empty string when the
292+ * store simply has no contacts -- both honest, never fabricated. */
322293JAVA_OBJECT com_codename1_impl_windows_WindowsNative_contactsGetAll___R_java_lang_String (CODENAME_ONE_THREAD_STATE ) {
323- #ifdef CN1_HAVE_WINRT
324294 cn1WinRtInit ();
325295 ComPtr<IContactManagerStatics2> statics;
326296 if (FAILED (RoGetActivationFactory (
@@ -408,9 +378,6 @@ JAVA_OBJECT com_codename1_impl_windows_WindowsNative_contactsGetAll___R_java_lan
408378 free (blob.data );
409379 return s;
410380 }
411- #else
412- return JAVA_NULL ;
413- #endif
414381}
415382
416383/* ----------------------------------------------------------------- share
@@ -421,15 +388,12 @@ JAVA_OBJECT com_codename1_impl_windows_WindowsNative_contactsGetAll___R_java_lan
421388 * and cn1WinShareHandleMessage runs here on the pump thread. The text/title are
422389 * stashed in file-static state read by the (same-thread) DataRequested handler.
423390 * Shares text (the common case); image-file sharing is a later addition. */
424- #ifdef CN1_HAVE_WINRT
425391static WCHAR * g_shareTextW = NULL ;
426392static WCHAR * g_shareTitleW = NULL ;
427393static bool g_shareHandlerRegistered = false ;
428394static ComPtr<IDataTransferManager> g_shareDtm;
429- #endif
430395
431396void cn1WinShareHandleMessage (WPARAM wParam) {
432- #ifdef CN1_HAVE_WINRT
433397 /* wParam carries [textW, titleW] allocated by the caller; take ownership. */
434398 WCHAR ** data = (WCHAR **) wParam;
435399 if (g_shareTextW != NULL ) { free (g_shareTextW); }
@@ -475,16 +439,12 @@ void cn1WinShareHandleMessage(WPARAM wParam) {
475439 g_shareHandlerRegistered = true ;
476440 }
477441 interop->ShowShareUIForWindow (cn1Win.hwnd );
478- #else
479- (void ) wParam;
480- #endif
481442}
482443
483444/* Java bridge: marshals the share request to the window thread. Returns false in
484- * headless / WinRT-less builds . */
445+ * headless mode (no host window) . */
485446JAVA_BOOLEAN com_codename1_impl_windows_WindowsNative_shareText___java_lang_String_java_lang_String_R_boolean (
486447 CODENAME_ONE_THREAD_STATE , JAVA_OBJECT textObj, JAVA_OBJECT titleObj) {
487- #ifdef CN1_HAVE_WINRT
488448 if (cn1Win.hwnd == NULL ) {
489449 return JAVA_FALSE ;
490450 }
@@ -496,11 +456,6 @@ JAVA_BOOLEAN com_codename1_impl_windows_WindowsNative_shareText___java_lang_Stri
496456 data[1 ] = titleObj != JAVA_NULL ? cn1WinJavaStringToWide (threadStateData, titleObj, NULL ) : NULL ;
497457 PostMessageW (cn1Win.hwnd , WM_CN1_SHARE , (WPARAM ) data, 0 );
498458 return JAVA_TRUE ;
499- #else
500- (void ) textObj;
501- (void ) titleObj;
502- return JAVA_FALSE ;
503- #endif
504459}
505460
506461} /* extern "C" */
0 commit comments