UNPKG

react-native-malwarelytics

Version:

Malwarelytics for React Native protects your banking or fintech app from a broad range of mobile security threats with an industry-leading mobile threat intelligence solution.

96 lines (68 loc) 4.37 kB
# Screen Recording Detection Android devices are capable of recording their screen. Frequently a recorded screen is also shared elsewhere (similar to screen sharing). Screen recording can pose a security risk, as sensitive information might be leaking from app screens. Since Android 15, Malwarelytics for Android is able to detect that the screen is being recorded and can be configured to terminate the app in such a case. Info about the detections is then delivered through the `MalwarelyticsRaspListener`. > The screen recording detection feature is available only on Android 15+. The callbacks are not delivered on older versions of Android regardless of the configuration. Similarly, the manual check methods report valid data only on Android 15+. ## Configuration This feature can be configured during the Malwarelytics initialization in `MalwarelyticsConfig`. ```typescript import { MalwarelyticsConfig } from "react-native-malwarelytics"; const config: MalwarelyticsConfig = { android: { rasp: { screenRecording: { action: 'NOTIFY' // or 'EXIT' or 'NO_ACTION' // exitUrl: "https://your.exit.url" } } } } ``` Available values of `action`: | Value | Description | |---|---| | `'NO_ACTION'` | Indicates that a screen recording will not be automatically detected. And a manual check is not possible. | | `'NOTIFY'` | Indicates that a screen recording will be automatically detected and observers will be notified. This is the default action. | | `'EXIT'` | Indicates that a screen recording will be automatically detected and the app will be terminated. | List of available parameters: | Parameter | Description | |---|---| | `exitUrl: string` | Defines the URL to be opened when the app is terminated because of the automatic detection. Defaults to `null`. | ## Usage After initialization, the screen recording detection feature can be accessed via `malwarelytics.rasp`. This can be used to register an observer or to trigger a manual screen recording detection check. ### Registering an Observer To receive notifications about screen recording events, you need to implement the optional `onScreenRecordingDetected` method in your `MalwarelyticsRaspListener`. ```typescript import { Malwarelytics, MalwarelyticsRaspListener, ScreenRecordingDetectionInfo } from "react-native-malwarelytics"; const listener: MalwarelyticsRaspListener = { // ... other listener methods onScreenRecordingDetected(info: ScreenRecordingDetectionInfo): void { console.log(`Screen recording detected: ${JSON.stringify(info)}`) } } Malwarelytics.sharedInstance.rasp.setRaspListener(listener); ``` The `ScreenRecordingDetectionInfo` object contains the following properties: | Property | Description | |---|---| | `isScreenBeingRecorded: boolean` | Indicates whether an activity of the app is being recorded. | | `activityClassName?: string` | Contains the class name of the activity that is being recorded or that just stopped to be recorded. It is `null` when the `screenVisibility` value is `NO_DATA`. | | `screenVisibility: ScreenRecordingVisibilityStatus` | Indicates whether an activity of the app became visible or invisible in a recording. | The `ScreenRecordingVisibilityStatus` can have the following values: | Value | Description | |---|---| | `'BECOMES_VISIBLE'` | An activity of the app becomes visible in a screen recording. | | `'BECOMES_INVISIBLE'` | An activity of the app becomes invisible in a screen recording. | | `'NO_DATA'` | No activity has ever been visible in a screen recording since the SDK has been initialized. Or the feature is not supported for the current version of Android. | ### Triggering a Manual Check The screen recording detection check can be triggered manually. Two methods are available – `isScreenBeingRecorded()` gives a simple boolean answer, whereas `getScreenRecordingDetection()` provides more details. ```typescript import { Malwarelytics } from "react-native-malwarelytics"; async function checkScreenRecording() { const isRecording = await Malwarelytics.sharedInstance.rasp.isScreenBeingRecorded(); if (isRecording) { console.log("Screen is being recorded."); } const recordingInfo = await Malwarelytics.sharedInstance.rasp.getScreenRecordingDetection(); console.log("Screen recording details:", recordingInfo); } ```