Before Upload: On-Device Scan Flags ID Cards, Faces, and Phone Numbers in Images
Apps can now tell users what is in an image before any bytes reach a server, so privacy screening does not create a second leak. For HarmonyOS upload flows, the default changes from "user uploads, server stores original" to "device flags, user decides".
Uploaded screenshots and photos routinely carry ID cards, phone numbers, and faces. @ohos/ai-privacy-scan adds a pre-upload check that keeps the analysis on the device: OCR reads all text, face detection locates faces, and entity recognition pulls phone numbers, ID numbers, emails, URLs, names, locations, times, OTP codes, tracking numbers, flight numbers, and passports from the recognized text. Hits come back as RiskItem[] with bounding boxes, and the original pixels are never modified or sent to a server for inspection.
The library wraps three built-in HarmonyOS kits: Core Vision Kit for textRecognition and faceDetector, and Natural Language Kit for getEntity. Callers choose what to scan through PrivacyType enums, from FACE and PHONE to IDCARD, BANKCARD, EXPRESS, FLIGHT, PASSPORT, or ALL. A showWindow flag controls a confirmation dialog: true pops a "sensitive information" window with boxes and a scrollable list when hits exist; false delivers the list directly to onConfirm. If a scan fails partway, onError fires instead of returning an empty list that could be mistaken for a clean result.
Keeping the analysis on-device is a deliberate privacy boundary; the original image never reaches a server just to be checked, so the scan itself cannot leak the data it is meant to protect.
Returning an error on an incomplete scan instead of an empty result prevents a false "all clear"; a privacy check that reported no hits after a failed run would be worse than no check.
The library intentionally stops at warning. Blurring and upload decisions stay with the caller, which keeps it useful for legitimate uploads of sensitive documents.