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.
You can visit malwarelytics.xml inside the demo app.
<?xml version='1.0' encoding='utf-8'?>
<malwarelytics>
<!-- REQUIRED AUTH ITEMS -->
<!-- Username for the Malwarelytics service -->
<username>MALWARELYTICS_USERNAME</username>
<!-- Password for the Malwarelytics service -->
<password>MALWARELYTICS_PASSWORD</password>
<!-- Path to the native library -->
<library-path>./path/to/the/antivirus.aar</library-path>
<!-- OPTIONAL AUTH ITEMS -->
<!-- Public key for the Malwarelytics service -->
<api-public-key>API_KEY</api-public-key>
<!-- OPTIONAL UI ITEMS -->
<!-- Folder that will be copied (merged) into the android app resources folder -->
<resources-folder></resources-folder>
<!-- Theme resource path that will be applied to the threat screen -->
<theme></theme>
<!-- Resource icon used in threat notifications -->
<notification-icon></notification-icon>
<!-- Resource icon used in threat screen for settings -->
<settings-icon></settings-icon>
<!-- Resource icon used in threat screen for deleting apps -->
<delete-icon></delete-icon>
</malwarelytics>
<resources-folder>
is a relative path to a folder. Content of this folder will be copied inside the app resource folder (platforms/android/app/src/main/res
). This can be used for adding custom theme file or localization files.<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 useR.mipmap.ic_launcher
to reuse your app icon.<settings-icon>
is a resource reference to a drawable that will be displayed as an uninstall button in Malwarelytics UI. (For exampleR.drawable.custom_av_settings_outline
).<delete-icon>
is a resource reference to a drawable that will be displayed as a delete button in Malwarelytics UI. (For exampleR.drawable.custom_av_delete_outline
).
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
Language Configuration
To support different than included languages, you need to provide custom strings. To do that, prepare a resources folder and set it to <resources-folder>
tag inside the malwarelytics.xml
file. Contents of such resource folder will be copied inside the android project as any other resource.
For an example implementation, you can visit the malwarelytics.xml and custom resources inside the demo application.
You can then set your preferred language both in the initialize
method as a property of MalwarelyticsConfig
or via changeAppLanguage
after the plugin is initialized.
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 such theme.
<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>R.style.CustomAppTheme</theme>
Support and Compatibility
Cordova Library | Native Library |
---|---|
1.1.x |
0.13.x |
1.0.x |
0.11.x and 0.12.x |