authgear / authgear-sdk-xamarin

Authgear authentication SDK for Xamarin applications
https://www.authgear.com/
Other
1 stars 9 forks source link

Use [DllImport] or equivalent to call uname on ios #16

Closed roxk closed 2 years ago

louischan-oursky commented 2 years ago
{
  "ios": {
    "uname": {
      "machine": "rfc1123",
      "release": "21.4.0.0",
      "sysname": "Unix",
      "version": "Unix 21.4.0.0",
      "nodename": "rfc1123"
    },
    "NSBundle": {
      "CFBundleName": "Authgear Xamarin",
      "CFBundleVersion": "1.0",
      "CFBundleExecutable": "XamarinFormSample.iOS",
      "CFBundleIdentifier": "com.authgear.exampleapp.xamarin",
      "CFBundleDisplayName": "Authgear Xamarin",
      "CFBundleShortVersionString": "1.0"
    },
    "UIDevice": {
      "name": "rfc1123",
      "model": "iPhone",
      "systemName": "iOS",
      "systemVersion": "15.4.1",
      "userInterfaceIdiom": "Phone"
    },
    "NSProcessInfo": {
      "isiOSAppOnMac": false,
      "isMacCatalystApp": false
    }
  },
  "android": null
}

Just tested and the current implementation does not look good.

roxk commented 2 years ago

Which are wrongs? Unix? rfc1123 seems to be the device name so that looks correct to me.

louischan-oursky commented 2 years ago
{
  "ios": {
    "uname": {
      "machine": "iPhone13,1",
      "release": "21.4.0",
      "sysname": "Darwin",
      "version": "Darwin Kernel Version 21.4.0: Mon Feb 21 21:27:55 PST 2022; root:xnu-8020.102.3~1/RELEASE_ARM64_T8101",
      "nodename": "rfc1123"
    },
    "NSBundle": {
      "CFBundleName": "Authgear Flutter",
      "CFBundleVersion": "1",
      "CFBundleExecutable": "Runner",
      "CFBundleIdentifier": "com.authgear.exampleapp.flutter",
      "CFBundleDisplayName": "Authgear Flutter",
      "CFBundleShortVersionString": "1.0.0"
    },
    "UIDevice": {
      "name": "rfc1123",
      "model": "iPhone",
      "systemName": "iOS",
      "systemVersion": "15.4.1",
      "userInterfaceIdiom": "phone"
    },
    "NSProcessInfo": {
      "isiOSAppOnMac": false,
      "isMacCatalystApp": false
    }
  }
}

Everything except nodename is wrong. In particular, we need machine to be correct because we use that to infer the device model for display purpose.

roxk commented 2 years ago

In that case I think can see see if DeviceInfo in xamarin essential is returning useful stuff. Lemme see see. If still doesn't show iphone model specifically, we could go down the Dll import rabbit hole (it's a rabbit hole since Idk what the dll name should be for calling syscall)

roxk commented 2 years ago

https://github.com/xamarin/Essentials/blob/e054b7e19b7fb8f1787af41c95ce4447660422ed/Xamarin.Essentials/Platform/Platform.ios.tvos.watchos.cs#L45

Seems we can reference how xamarin essential does it.

louischan-oursky commented 2 years ago

According to observation, DeviceInfo.Name is nodename, DeviceInfo.Machine is machine. Let's see if we can get the dllImport stuff work. If not, just provide DeviceInfo.Name and DeviceInfo.Machine and leave other fields as empty string.

roxk commented 2 years ago

https://github.com/xamarin/Essentials/blob/7218ab88f7fbe00ec3379bd54e6c0ce35ffc0c22/Xamarin.Essentials/DeviceInfo/DeviceInfo.ios.tvos.watchos.cs#L20

Any chance other information are stored in this "sysctl" API as well? If there are we can use this API to grab them.

In the mean time, I'm working on dllimport.

roxk commented 2 years ago

Looks promising, just need to figure out the property name of release and sysname.

image

roxk commented 2 years ago

Fixed by using sysctlbyname.