Proguard Rules, Notification, and Analytics Configurations

The documentation provides configuration and code snippets for integrating VPN capabilities into Android apps.

Proguard Rules

ProGuard is a tool that obfuscates, optimizes, and shrinks your code by removing unused code and renaming classes, fields, and methods with semantically obscure names.

Usage

  1. Copy the provided ProGuard rules into your project's proguard-rules.pro file.

  2. Make sure to include this file in your build configuration:

android {
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

Proguard Rules Explanation

Proguard rules are included in the SDK, but you can add your own custom rules if needed. Here's a breakdown of what each rule does:

-keep class * extends unified.vpn.sdk.ReportUrlProvider {
    public <init>(...);
}

-keep class * extends unified.vpn.sdk.BaseInfoCollector {
    public <init>(...);
}

-keep class * extends unified.vpn.sdk.TrackerTransportFactory {
    public <init>(...);
}

-keep class * extends unified.vpn.sdk.CredentialsSource {
    public <init>(...);
}

-keep class * extends unified.vpn.sdk.SdkTrackerDelegate {
    public <init>(...);
}
-keep enum unified.vpn.sdk.UnifiedSDKConfig$CallbackMode {
    *;
}

-keep class * extends unified.vpn.sdk.IStartConfigPatcher {
    public <init>(...);
}
-keep class * extends unified.vpn.sdk.ConfigPatcherFactory {
    public <init>(...);
}
-keep class * extends unified.vpn.sdk.IMiddleConfigPatcher {
    public <init>(...);
}

#DNSJava
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

-keepclassmembers class * implements javax.net.ssl.SSLSocketFactory {
    final javax.net.ssl.SSLSocketFactory delegate;
}

# https://stackoverflow.com/questions/56142150/fatal-exception-java-lang-nullpointerexception-in-release-build
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}
-dontwarn org.bouncycastle.jsse.BCSSLParameters
-dontwarn org.bouncycastle.jsse.BCSSLSocket
-dontwarn org.bouncycastle.jsse.provider.BouncyCastleJsseProvider
-dontwarn org.conscrypt.Conscrypt$Version
-dontwarn org.conscrypt.Conscrypt
-dontwarn org.conscrypt.ConscryptHostnameVerifier
-dontwarn org.openjsse.javax.net.ssl.SSLParameters
-dontwarn org.openjsse.javax.net.ssl.SSLSocket
-dontwarn org.openjsse.net.ssl.OpenJSSE
-dontwarn unified.vpn.sdk.HydraConnectionState

-keep class * extends unified.vpn.sdk.Daemon {
     public <init>(...);
 }

-dontwarn unified.vpn.sdk.KeyValueStorageImpl

-keep public class * extends unified.vpn.sdk.NetworkProbeFactory {
     public <init>(...);
 }

-keep class unified.vpn.sdk.PingService { *; }
-keep class unified.vpn.sdk.PingResult { *; }

# This dnsjava class uses old Sun API
-dontnote org.xbill.DNS.spi.DNSJavaNameServiceDescriptor
-dontwarn org.xbill.DNS.spi.DNSJavaNameServiceDescriptor

-keepclassmembers class org.xbill.DNS.Lookup {
    java.util.Map defaultCaches;
    org.xbill.DNS.Name[] defaultSearchPath;
    int defaultNdots;
}

-keep class * extends unified.vpn.sdk.WireguardPingJobFactory {
    public <init>(...);
}
-keepclassmembers class com.wireguard.** { *; }

-keepclassmembers class unified.vpn.sdk.HydraTransport$ApiHeaderListener {
    *** protect(...);
    *** onHdr(...);
}

-keep class com.anchorfree.hdr.** {*;}

-keep public class * extends unified.vpn.sdk.VpnException {
    *;
}

-keep public class * extends unified.vpn.sdk.CaptivePortalChecker {
    public <init>(...);
}

-keep public class * extends unified.vpn.sdk.TransportFactory {
    public <init>(...);
}

-keep class * extends unified.vpn.sdk.ReconnectExceptionHandler {
    public <init>(...);
}

Setting the VPN Process Name

To set a custom process name for the VPN, add the following string resource to your source file:

<string name="vpn_process_name" translatable="false">:vpn</string>

Enabling Java 8 Support

To add Java 8 support to your project, update your build.gradle file with the following:

compileOptions {
    sourceCompatibility 1.8
    targetCompatibility 1.8
}

If you cannot enable java 8 support in your project, please contact us for further details.

Configuring Notifications

To configure SDK notifications, use the NotificationConfig.Builder class.

Disabling Notifications

To disable notifications:

SdkNotificationConfig.Builder builder = SdkNotificationConfig.newBuilder();
builder = builder.disabled()

Notifications for Different States

// Notification to be displayed when VPN is connected
builder.inConnected("Title","Message");

//Notification to be displayed when VPN is not connected
builder.inIdle("Title","Message");

// Notification to be displayed when VPN is connecting
builder.inConnecting("Title","Message");

// Notification to be displayed when VPN is paused (waiting for network connection)
builder.inPause("Title","Message");

// Notification to be displayed if Client Network List feature is used
builder.inCnl("Title","Message");

Notification Message and Title Fallback

By default, the SDK displays notification for the CONNECTED and PAUSED states.

  • If inConnected was not called, it will try to use value set with title message

  • If NotificationConfig.Builder.title was not set, it will use App name as in launcher

  • If inConnected was not called, it will try to use string resource default_notification_connected_message

  • If inPause was not called, it will try to use string resource default_notification_paused_message

Notification Click Intent

To configure action when a user clicks a notification, use the clickAction method. You must have an Activity responding to the specified action. The action will be used to create an Intent. If clickAction is not specified, the SDK will open the application launch activity on notification click.

In the intent extras, the SDK will set a boolean value UnifiedSDKNotificationManager.EXTRA_NOTIFICATION as true.

To handle the click action, register intent-filter with your activity:

<intent-filter>
    <action android:name="com.sdk.notification.action"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

Updating Notification Preferences

Notification config can be updated by calling the SDK method:

UnifiedSDK.update(createNotificationConfig());

Notification Placeholders

For CONNECTED state notifications it's possible to use placeholders that will periodically update with their values:

Possible placeholders:

  • {dS} - downloadSpeed

  • {uS} - uploadSpeed

  • {dT} - downloadTraffic

  • {uT} - uploadTraffic

Analytics

SDK sends internal analytics events. They can be disabled by:

UnifiedSdk.setAnalyticsEnabled(false);

Last updated