Cordova Plugin for Malwarelytics

How To Install The Plugin

1. Get Malwarelytics native SDK and credentials

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

2. Create the malwarelytics.xml file

Create the malwarelytics.xml file inside your app root folder with your app credentials and the path to the native library.

<?xml version='1.0' encoding='utf-8'?>
<malwarelytics>
    <!-- REQUIRED ITEMS -->
    <username>MALWARELYTICS_USERNAME</username>
    <password>MALWARELYTICS_PASSWORD</password>
    <library-path>./path/to/the/antivirus.aar</library-path>

    <!-- OPTIONAL ITEMS -->
    <!-- <theme></theme> -->
    <!-- <notification-icon></notification-icon> -->
</malwarelytics>
  • <theme> is a resource reference to your theme. For more information on styling see Styling Threat Screen.
  • <notificaition-icon> is a resource reference to an icon that will be displayed in malwarelytics notififcations. You can use com.yourcompany.app.bundle.R.style.R.mipmap.ic_launcher to reuse your app icon.

PRO-TIP: Add malwarelytics.xml to your .gitignore file to ensure that the credentials are not leaked.

3. Install the plugin into your app

For “vanilla” Cordova app

cordova plugin add cordova-plugin-malwarelytics

For Ionic Cordova app

ionic cordova plugin add cordova-plugin-malwarelytics

4. Initialize and use the plugin

In your app js file, you can now access window.plugins.malwarelytics property.

Initialize the plugin:

window.plugins.malwarelytics.initialize({
        enableSilentMode: false
    }, function () {
        console.log("initialized");
    }, function (error) {
        console.log(error);
});

Call the scan:

window.plugins.malwarelytics.triggerSmartProtection(function () {
        console.log("Smart Protection finished...");
    }, function (error) {
        console.log(error.type);
});

Typescript support

In case that you’re using TypeScript to build the app, there is a Malwarelytics.d.ts definition file in the package. You can reference it in your file and use it as follow:

/// <reference path="../../plugins/cordova-plugin-malwarelytics/www/MalwarelyticsPlugin.d.ts"/>

declare interface Window {
    plugins: {
        malwarelytics: MalwarelyticsPlugin;
    }
}

// now you can use window.plugins.malwarelytics with autocompletion

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 platforms/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 into your malwarelytics.xml configuration file by

<theme>com.yourcompany.app.bundle.R.style.CustomAppTheme</theme>

Support and Compatibility

Cordova Library Native Library
1.0.x 0.11.x
Last updated on Aug 20, 2020 (09:58) Edit on Github Send Feedback
Search

1.0.x

Malwarelytics for Cordova