React Native Module for Malwarelytics

npm license

How To Install The Plugin

1. Get Malwarelytics native SDK and credentials

The SDK and credentials can be found under the “Get The SDK” section in the Malwarelytics Console.

2. Install native SDK to your local maven repository

After retrieving the SDK, install its content to your local Maven Repository (usually inside ~/.m2/repository).

Dont forget to add your local maven repository into your gradle file if it’s not added yet:

repositories {
  mavenLocal()
}
npm i react-native-malwarelytics --save
npx react-native link

4. Configure the SDK

In your apps build.gradle file (located in android/app/), apply gradle plugin with

apply from: "../../node_modules/react-native-malwarelytics/android/configure.gradle"

and then configure it your app credentials

android {
    defaultConfig {
        configureMalwarelytics owner, "USERNAME", "PASSWORD" //, "R.style.CustomAppTheme", "R.mipmap.ic_launcher"
    }
}

Last two parameters are optional in initial setup and can be omitted.

  • third parameter is a resource reference to your theme. For more information on styling see Styling Threat Screen.
  • fourth parameter is a resource reference to an icon that will be displayed in Malwarelytics notifications. You can use R.style.R.mipmap.ic_launcher to reuse your app icon.

PRO-TIP: You can configure the Malwarelytics for each flavor to provide different credentials for your testing environment.

5. Initialize and use the plugin

In your application, you can now import module with import Malwarelytics from 'react-native-malwarelytics';.

Initializing the module:

Malwarelytics
    .initialize({enableSilentMode: false})
    .then(function() {
      console.log("initialized");
    })
    .catch(function(e) { 
        console.log("failed");
    });

Call the scan:

Malwarelytics
    .triggerSmartProtection()
    .then(function() {
        console.log("Smart Protection finished...");
    .catch(function (error) {
        console.log(error.type);
    });

Styling Threat Screen

Threat screen can by styled by setting custom theme for the activity and by changing icons for the image buttons on the screen.

There are two icons. Delete icon and settings icon. Delete icon serves for button requesting app uninstall (for apps that can be uninstalled). Settings icon serves for button opening app’s detail in system settings (for apps that cannot be uninstalled) where user can disable the app.

The theme for the screen should contain standard Android attributes and can contain couple of extra attributes defined by the AV SDK.

We recommend to derive the theme from AppCompat themes. The usage of ActionBar in the screen is derived from the theme. Use NoActionBar version of the theme for design without the ActionBar (contains the app name). Alternatively you can hide the ActionBar by adding

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>

to your theme.

Following is an example of a theme using Wultra-defined attributes that you can put into your android/app/src/main/res/values/malwarelytics.xml file.

<resources>
    <style name="CustomAppTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="colorPrimary">#FF0000</item>
        <item name="colorPrimaryDark">#222222</item>
        <item name="colorAccent">#FF0000</item>

        <item name="titleTextColor">@android:color/black</item>

        <!-- <item name="android:windowBackground">@drawable/img_bg_app</item> -->

        <!-- <item name="android:fontFamily">@font/font_family_roboto</item>
        <item name="fontFamily">@font/font_family_roboto</item> -->

        <!-- <item name="buttonStyle">@style/CustomAppTheme.Button.Filled</item> -->
        <item name="imageButtonStyle">@style/CustomAppTheme.ImageButton.Borderless</item>

        <item name="wultraThreatTitleTextAppearance">@style/CustomAppTheme.TextAppearance.Title</item>
        <item name="wultraThreatTitleStyle">@style/CustomAppTheme.TextView.Title</item>
        <item name="wultraThreatDescriptionTextAppearance">@style/CustomAppTheme.TextAppearance.Description</item>
        <item name="wultraThreatDescriptionStyle">@style/CustomAppTheme.TextView.Description</item>
        <item name="wultraThreatProtipTextAppearance">@style/CustomAppTheme.TextAppearance.Description</item>
        <item name="wultraThreatProtipStyle">@style/CustomAppTheme.TextView.Description</item>
    </style>

    <style name="CustomAppTheme.TextAppearance.Button" parent="TextAppearance.AppCompat.Button">
        <item name="android:textColor">@android:color/black</item>
        <item name="android:textSize">19.2sp</item>
        <item name="android:textStyle">bold</item>
    </style>

    <style name="CustomAppTheme.Button.Filled" parent="Widget.AppCompat.Button">
        <item name="android:textAppearance">@style/CustomAppTheme.TextAppearance.Button</item>
        <item name="android:textAllCaps">false</item>
        <!-- <item name="android:background">@drawable/bg_button_filled</item> -->
    </style>

    <style name="CustomAppTheme.ImageButton.Borderless" parent="Widget.AppCompat.ImageButton">
        <!-- <item name="android:background">@drawable/bg_button_borderless</item> -->
    </style>

    <style name="CustomAppTheme.TextView"/>

    <style name="CustomAppTheme.TextView.Title">
        <item name="android:gravity">center</item>
    </style>

    <style name="CustomAppTheme.TextAppearance.Title" parent="TextAppearance.AppCompat.Title">
        <item name="android:textColor">#FF0000</item>
    </style>

    <style name="CustomAppTheme.TextView.Description">
        <item name="android:gravity">center</item>
    </style>

    <style name="CustomAppTheme.TextAppearance.Description" parent="TextAppearance.AppCompat.Medium">
        <item name="android:textColor">@android:color/white</item>
        <item name="android:textSize">16.8sp</item>
    </style>
</resources>

Such custom theme can be set via gradle configuration of malwarelytics by

configureMalwarelytics owner, "USERNAME", "PASSWORD", "R.style.CustomAppTheme"

Support and Compatibility

React Native Library Native Library
0.11.x 0.11.x
Last updated on Jul 17, 2020 (15:22) View product
Search

0.11.x

Malwarelytics for React Native