Skip to content

Metadata: Environment and Device Information #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: fraud-signals-metadata
Choose a base branch
from

Conversation

tobitech
Copy link
Contributor

@tobitech tobitech commented Apr 9, 2025

User description

Story: https://app.shortcut.com/smileid/story/15152/

Summary

  • Collect metadata for timezone
  • Collect metadata for user's localed
  • Collect metadata for screen resolution
  • Collect metadata for available physical memory
  • Collect metadata for device orientation
  • Collect metadata for system architecture.

Known Issues

N/A.

Test Instructions

  • Run a job and inspect the metadata to confirm that the data points listed in the description above are collected and that they are in the right format based on the story.

Screenshot

N/A


PR Type

Enhancement


Description

  • Added device environment metadata collection

  • Fixed allowNewEnroll parameter type

  • Implemented extensions for device information


Changes walkthrough 📝

Relevant files
Bug fix
3 files
OrchestratedBiometricKycViewModel.swift
Fix allowNewEnroll parameter type                                               
+1/-1     
OrchestratedDocumentVerificationViewModel.swift
Fix allowNewEnroll parameter type                                               
+1/-1     
LocalStorage.swift
Fix allowNewEnroll parameter type                                               
+1/-1     
Enhancement
5 files
MetadataKey.swift
Add new metadata keys                                                                       
+6/-0     
MetadataManager.swift
Implement collection of environment metadata                         
+10/-0   
ProcessInfoExtension.swift
Add extension for memory and architecture info                     
+27/-0   
UIDeviceExtension.swift
Add device orientation detection                                                 
+28/-0   
UIScreenExtension.swift
Add screen resolution formatting                                                 
+11/-0   

Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @tobitech tobitech self-assigned this Apr 9, 2025
    @tobitech tobitech requested a review from a team as a code owner April 9, 2025 12:12
    @prfectionist
    Copy link

    prfectionist bot commented Apr 9, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Potential UI Thread Issue

    The code accesses UI elements (UIApplication.shared.windows) to determine orientation when device orientation is unknown. This could cause issues if called from a background thread.

    let interfaceOrientation = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation
    switch interfaceOrientation {
    case .portrait, .portraitUpsideDown:
        return "Portrait"
    case .landscapeLeft, .landscapeRight:
        return "Landscape"
    case .unknown, .none:
        return "Unknown"
    @unknown default:
        return "Unknown"
    }
    Memory Representation

    The available memory is returned as a string without formatting. Consider adding proper formatting (e.g., thousands separators) for better readability.

    var availableMemoryInMB: String {
        // Get physical memory in bytes
        let physicalMemory = self.physicalMemory
    
        // Convert to MB (1 MB = 1,048,576 bytes)
        let memoryInMB = physicalMemory / 1_048_576
    
        return "\(memoryInMB)"
    }

    Copy link

    github-actions bot commented Apr 9, 2025

    Warnings
    ⚠️ The source files were changed, but the tests remain unmodified. Consider updating or adding to the tests to match the source changes.
    ⚠️

    Sources/SmileID/Classes/SelfieCapture/SelfieViewModel.swift#L229 - TODOs should be resolved (Use mouth deformation as an al...). (todo)

    Generated by 🚫 Danger Swift against a638c10

    Comment on lines 24 to 50
    var orientationString: String {
    switch UIDevice.current.orientation {
    case .portrait, .portraitUpsideDown:
    return "Portrait"
    case .landscapeLeft, .landscapeRight:
    return "Landscape"
    case .faceUp:
    return "FaceUp"
    case .faceDown:
    return "FaceDown"
    case .unknown:
    // Default to UI orientation if device orientation is unknown
    let interfaceOrientation = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation
    switch interfaceOrientation {
    case .portrait, .portraitUpsideDown:
    return "Portrait"
    case .landscapeLeft, .landscapeRight:
    return "Landscape"
    case .unknown, .none:
    return "Unknown"
    @unknown default:
    return "Unknown"
    }
    @unknown default:
    return "Unknown"
    }
    }
    Copy link

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Suggestion: The code is using the deprecated UIApplication.shared.windows property which was deprecated in iOS 15. Use UIApplication.shared.connectedScenes instead to get the interface orientation. [possible issue, importance: 8]

    Suggested change
    var orientationString: String {
    switch UIDevice.current.orientation {
    case .portrait, .portraitUpsideDown:
    return "Portrait"
    case .landscapeLeft, .landscapeRight:
    return "Landscape"
    case .faceUp:
    return "FaceUp"
    case .faceDown:
    return "FaceDown"
    case .unknown:
    // Default to UI orientation if device orientation is unknown
    let interfaceOrientation = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation
    switch interfaceOrientation {
    case .portrait, .portraitUpsideDown:
    return "Portrait"
    case .landscapeLeft, .landscapeRight:
    return "Landscape"
    case .unknown, .none:
    return "Unknown"
    @unknown default:
    return "Unknown"
    }
    @unknown default:
    return "Unknown"
    }
    }
    var orientationString: String {
    switch UIDevice.current.orientation {
    case .portrait, .portraitUpsideDown:
    return "Portrait"
    case .landscapeLeft, .landscapeRight:
    return "Landscape"
    case .faceUp:
    return "FaceUp"
    case .faceDown:
    return "FaceDown"
    case .unknown:
    // Default to UI orientation if device orientation is unknown
    if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
    switch windowScene.interfaceOrientation {
    case .portrait, .portraitUpsideDown:
    return "Portrait"
    case .landscapeLeft, .landscapeRight:
    return "Landscape"
    case .unknown:
    return "Unknown"
    @unknown default:
    return "Unknown"
    }
    }
    return "Unknown"
    @unknown default:
    return "Unknown"
    }
    }

    @tobitech tobitech changed the title Metadata Environment and Device Information Metadata: Environment and Device Information Apr 9, 2025
    @@ -21,6 +21,34 @@ extension UIDevice {
    ?? identifier
    }

    var orientationString: String {
    Copy link
    Contributor

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    This value is also something that fluctuates over time (ie. depending on when it is recorded). I do wonder if we want to collect this in an array? The question then is how often and when do we want to sample this value? cc @Yeboahmedia

    Copy link
    Contributor

    @robin-smileid robin-smileid left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Code changes look fine to me. Tested the flow and the values are added correctly. Left a comment in case we want to collect device orientation as an array.

    Copy link
    Contributor

    @JNdhlovu JNdhlovu left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    @tobitech @robin-smileid I think like the orientation the available memory is also something that changes overtime, is that something we want to set on init when we init the metadata or this is something that should be set maybe when we begin a flow or something?

    @robin-smileid
    Copy link
    Contributor

    @tobitech @robin-smileid I think like the orientation the available memory is also something that changes overtime, is that something we want to set on init when we init the metadata or this is something that should be set maybe when we begin a flow or something?

    @JNdhlovu We actually record the total memory (RAM) of the device. This shouldn't change over time. We can also think about recording memory changes (available memory) and then that would need to recorded differently.

    Comment on lines 18 to 24
    return "ARM64"
    #elseif arch(x86_64)
    return "x86_64"
    #elseif arch(i386)
    return "i386"
    #else
    return "Unknown"
    Copy link
    Contributor

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Should we keep this all lower cased?

    Suggested change
    return "ARM64"
    #elseif arch(x86_64)
    return "x86_64"
    #elseif arch(i386)
    return "i386"
    #else
    return "Unknown"
    return "arm64"
    #elseif arch(x86_64)
    return "x86_64"
    #elseif arch(i386)
    return "i386"
    #else
    return "unknown"

    return "FaceUp"
    case .faceDown:
    return "FaceDown"
    case .unknown:
    Copy link
    Contributor

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    And maybe also here lower-case unknown. Just to keep consistency in case we can't extract it.

    Copy link
    Contributor

    @robin-smileid robin-smileid left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Code changes look fine to me so far. Can we please also add the device orientation recording when we do a document capture? Left some comments in terms of default value unknown in case we can't extract a value.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants