Parcourir la source

Worked on open wifi connection, integrated on fastestvpn compose app

Khubaib il y a 3 mois
Parent
commit
e36c3a0c2e

+ 2 - 2
.idea/deploymentTargetSelector.xml

@@ -4,10 +4,10 @@
     <selectionStates>
       <SelectionState runConfigName="app">
         <option name="selectionMode" value="DROPDOWN" />
-        <DropdownSelection timestamp="2024-09-27T11:18:35.350023906Z">
+        <DropdownSelection timestamp="2024-10-03T14:06:18.452564143Z">
           <Target type="DEFAULT_BOOT">
             <handle>
-              <DeviceId pluginId="PhysicalDevice" identifier="serial=1C051FDF60048Z" />
+              <DeviceId pluginId="LocalEmulator" identifier="path=/home/ubuntu/.android/avd/Small_Phone_API_25.avd" />
             </handle>
           </Target>
         </DropdownSelection>

+ 21 - 0
app/src/main/AndroidManifest.xml

@@ -14,6 +14,10 @@
 
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
+    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
     <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
     <uses-permission android:name="com.android.vending.BILLING" />
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
@@ -200,6 +204,23 @@
                 android:value="true" />
         </service>
 
+        <receiver
+            android:name=".utils.WifiScanReceiver"
+            android:enabled="true"
+            android:exported="true">
+            <intent-filter>
+                <action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
+                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
+                <action android:name="android.net.wifi.STATE_CHANGE" />
+                <action android:name="android.net.wifi.SCAN_RESULTS" />
+                <action android:name="android.net.wifi.supplicant.CONNECTION_CHANGE" />
+            </intent-filter>
+        </receiver>
+
+        <service
+            android:name=".fcm.NetworkJobService"
+            android:permission="android.permission.BIND_JOB_SERVICE" />
+
     </application>
 
 </manifest>

+ 36 - 3
app/src/main/java/com/vpn/fastestvpnservice/MainActivity.kt

@@ -2,9 +2,11 @@ package com.vpn.fastestvpnservice
 
 import android.content.Context
 import android.content.Intent
+import android.content.IntentFilter
 import android.content.pm.ActivityInfo
 import android.content.pm.PackageManager
 import android.net.Uri
+import android.net.wifi.WifiManager
 import android.os.Build
 import android.os.Bundle
 import android.provider.Settings
@@ -13,6 +15,7 @@ import android.view.WindowInsets
 import android.view.WindowInsetsController
 import android.view.WindowManager
 import androidx.activity.compose.setContent
+import androidx.annotation.RequiresApi
 import androidx.compose.foundation.isSystemInDarkTheme
 import androidx.compose.runtime.getValue
 import androidx.compose.runtime.mutableStateOf
@@ -21,6 +24,7 @@ import androidx.compose.ui.graphics.toArgb
 import androidx.compose.ui.platform.LocalContext
 import androidx.compose.ui.res.colorResource
 import androidx.core.app.ActivityCompat
+import androidx.core.content.ContextCompat
 import androidx.core.view.WindowCompat
 import androidx.fragment.app.FragmentManager
 import androidx.navigation.compose.rememberNavController
@@ -43,11 +47,16 @@ import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.isSwitch
 import com.vpn.fastestvpnservice.screens.helpScreensAll.fileChooserCallback
 import com.vpn.fastestvpnservice.ui.theme.FastestVPNTheme
 import com.vpn.fastestvpnservice.utils.StaticMethods
+import com.vpn.fastestvpnservice.utils.WifiScanReceiver
 import de.blinkt.openvpn.core.App
 
 
 open class MainActivity : DockActivity(), ConnectivityReceiver.ConnectivityReceiverListener {
 
+    lateinit var wifiManager: WifiManager
+    lateinit var wifiScanReceiver: WifiScanReceiver
+    lateinit var intentFilter: IntentFilter
+
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
 //        if (Thread.getDefaultUncaughtExceptionHandler() !is CustomExceptionHandler) {
@@ -80,6 +89,14 @@ open class MainActivity : DockActivity(), ConnectivityReceiver.ConnectivityRecei
             }
         }
 
+        ActivityCompat.requestPermissions(this,
+            arrayOf(
+                android.Manifest.permission.ACCESS_FINE_LOCATION,
+                android.Manifest.permission.ACCESS_COARSE_LOCATION
+            ),
+            PackageManager.PERMISSION_GRANTED
+        )
+
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && Settings.canDrawOverlays(this)) {
             isSwitch.value = true
             basePreferenceHelper.saveLaunchState(true)
@@ -87,6 +104,13 @@ open class MainActivity : DockActivity(), ConnectivityReceiver.ConnectivityRecei
 
         WindowCompat.setDecorFitsSystemWindows(window, false)
 
+        wifiManager = applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
+        wifiScanReceiver = WifiScanReceiver()
+        intentFilter = IntentFilter()
+        intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION)
+
+        ContextCompat.registerReceiver(applicationContext, wifiScanReceiver, intentFilter, ContextCompat.RECEIVER_NOT_EXPORTED)
+
         setContent {
             val context = LocalContext.current
 //                val basePreferenceHelper = BasePreferenceHelper(context)
@@ -96,7 +120,8 @@ open class MainActivity : DockActivity(), ConnectivityReceiver.ConnectivityRecei
             val systemTheme by remember { mutableStateOf(isSystemInDarkTheme) }
             if (selectedTheme == themesList[0]) {
                 isDarkTheme.value = systemTheme
-            } else {
+            }
+            else {
                 isDarkTheme.value = selectedTheme == themesList[2]
             }
 
@@ -110,7 +135,8 @@ open class MainActivity : DockActivity(), ConnectivityReceiver.ConnectivityRecei
                     val navController = rememberNavController()
                     SetUpNavGraphTV(navHostController = navController, this)
                 }
-            } else {
+            }
+            else {
                 Log.d("test_platform_android", "Mobile")
                 FastestVPNTheme(isDarkTheme.value) {
                     window.statusBarColor = colorResource(id = R.color.blue_text).toArgb()
@@ -118,7 +144,6 @@ open class MainActivity : DockActivity(), ConnectivityReceiver.ConnectivityRecei
                     SetUpNavGraph(navHostController = navController, this)
                 }
             }
-
         }
 
 //        hideSystemUI()
@@ -201,6 +226,13 @@ open class MainActivity : DockActivity(), ConnectivityReceiver.ConnectivityRecei
 //        return 0
 //    }
 
+    override fun onResume() {
+        super.onResume()
+
+
+    }
+
+
     override fun onDestroy() {
         super.onDestroy()
 
@@ -210,6 +242,7 @@ open class MainActivity : DockActivity(), ConnectivityReceiver.ConnectivityRecei
         }
         Log.d("test_conn_ser_obj", "onDestroy() called")
 
+//        unregisterReceiver(wifiScanReceiver)
     }
 
     fun getCallingIntent(_context: Context?): Intent {

+ 231 - 0
app/src/main/java/com/vpn/fastestvpnservice/fcm/NetworkJobService.java

@@ -0,0 +1,231 @@
+package com.vpn.fastestvpnservice.fcm;
+
+import android.Manifest;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.job.JobInfo;
+import android.app.job.JobParameters;
+import android.app.job.JobScheduler;
+import android.app.job.JobService;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.media.RingtoneManager;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.net.Uri;
+import android.net.wifi.ScanResult;
+import android.net.wifi.SupplicantState;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.os.Build;
+import android.util.Log;
+import androidx.core.app.ActivityCompat;
+import androidx.core.app.NotificationCompat;
+
+import com.vpn.fastestvpnservice.MainActivity;
+import com.vpn.fastestvpnservice.R;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+import de.blinkt.openvpn.core.App;
+
+public class NetworkJobService extends JobService {
+
+    private WifiManager wifiManager;
+    public Context context = null;
+    Timer timer;
+    private static final int WIFI_SCAN_INTERVAL = 60 * 1000; // 60 sec
+
+    @Override
+    public boolean onStartJob(JobParameters jobParameters) {
+        Log.d("NetworkJobService", "Job started");
+
+        wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
+        if (wifiManager != null) {
+            wifiManager.startScan();
+        }
+
+//        handleScanResults(jobParameters);
+
+        timer = new Timer();
+        timer.scheduleAtFixedRate(new TimerTask() {
+            @Override
+            public void run() {
+                Log.d("NetworkJobService", "Job handleScanResults");
+
+                handleScanResults(jobParameters);
+            }
+        }, 10000, WIFI_SCAN_INTERVAL);
+
+//        jobFinished(jobParameters, false);
+
+        return true;
+    }
+
+    private void handleScanResults(JobParameters jobParameters) {
+        String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION,
+                Manifest.permission.ACCESS_COARSE_LOCATION};
+        Boolean isOpenWifiConnected = false;
+
+
+        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+            // TODO: Consider calling
+            //    ActivityCompat#requestPermissions
+            // here to request the missing permissions, and then overriding
+            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
+            //                                          int[] grantResults)
+            // to handle the case where the user grants the permission. See the documentation
+            // for ActivityCompat#requestPermissions for more details.
+          return;
+        }
+        List<ScanResult> scanResults = wifiManager.getScanResults();
+        Log.d("NetworkJobService", "Job scanResults + " + scanResults.size());
+
+        List<ScanResult> nonZeroList = new ArrayList<>();
+
+        if (scanResults.size() > 0) {
+            Log.d("nonZeroList_test 1", scanResults.size() + "");
+
+            nonZeroList.addAll(scanResults);
+        }
+        else {
+//            Log.d("nonZeroList test 2", WiFiMonitorService.scanResultsStatic.size() + "");
+            Log.d("nonZeroList_test 2", WiFiMonitorService.scanResultsStatic.size() + "");
+
+//            nonZeroList.addAll(WiFiMonitorService.scanResultsStatic);
+        }
+
+        Log.d("NetworkJobService Start", "Started");
+
+        Log.d("NetworkJobService in", "Inside");
+
+        WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
+
+
+        if (wifiManager.isWifiEnabled()) {
+
+            Log.d("NetworkJobService res", scanResults.size() + "isWifiEnabled()");
+
+            ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
+            NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
+
+            if (activeNetwork != null && activeNetwork.isConnected() && activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
+                WifiManager wifiManager1 = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
+                WifiInfo wifiInfo = wifiManager1.getConnectionInfo();
+
+                if (wifiInfo != null && wifiInfo.getSupplicantState() == SupplicantState.COMPLETED) {
+                    String connectedSSID = wifiInfo.getSSID().replace("\"", "");
+
+                    Log.d("NetworkJobService cssid", connectedSSID);
+
+                    for (ScanResult scanResult : nonZeroList) {
+
+                        Log.d("NetworkJobService list", scanResult.SSID);
+
+                        String ssid = scanResult.SSID;
+
+                        if (scanResult.capabilities != null) {
+                            if (scanResult.capabilities.equals("[ESS]")) {
+                                Log.d("NetworkJobService ESS", "Open wifi detected " + ssid);
+
+                                String targetSSID = ssid;
+                                Log.d("NetworkJobService Conn", "Normal wifi connected " + connectedSSID);
+
+                                if (connectedSSID.equals(targetSSID)) {
+                                    Log.d("NetworkJobService con", "Device is connected to the open Wi-Fi network: " + connectedSSID);
+                                    sendNotification("Your Wi-Fi connection is unsafe", "Connect to VPN to protect your data");
+//                                    jobFinished(jobParameters, false); // now set to true
+                                    return;
+                                } else {
+                                    Log.d("NetworkJobService conn", "Device is connected to the Normal Wi-Fi network: " + connectedSSID);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        jobFinished(jobParameters, true); // set to true for continuously, otherwise will set to false for 15 min each job
+    }
+
+    @Override
+    public boolean onStopJob(JobParameters jobParameters) {
+        Log.d("NetworkJobService Stop", "Job Stop");
+
+        return true;
+    }
+
+    public static void scheduleJob(Context context) {
+        Log.d("NetworkJobService scdul", "Job scheduleJob");
+        JobScheduler jobScheduler = (JobScheduler) context.getApplicationContext().getSystemService(JOB_SCHEDULER_SERVICE);
+        if (jobScheduler != null) {
+            ComponentName componentName = new ComponentName(context.getApplicationContext(), NetworkJobService.class);
+            JobInfo jobInfo = new JobInfo.Builder(1, componentName)
+                    .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
+                    .setRequiresCharging(false)
+                    .setPeriodic(15 * 60 * 1000) // Job will be run every 15 minutes (minimum interval)
+                    .build();
+
+            jobScheduler.schedule(jobInfo);
+        }
+    }
+
+    private void sendNotification(String title, String messageBody) {
+        Intent intent = new Intent(getApplicationContext(), MainActivity.class);
+        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+//        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
+//                PendingIntent.FLAG_ONE_SHOT);
+//        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
+//                PendingIntent.FLAG_IMMUTABLE);
+        PendingIntent pendingIntent = null;
+
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+            pendingIntent = PendingIntent.getActivity(getApplicationContext(), (int) System.currentTimeMillis() /* Request code */, intent,
+                    PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
+        }
+//        else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+//            pendingIntent = PendingIntent.getForegroundService(this, 0, intent,
+//                    PendingIntent.FLAG_IMMUTABLE);
+//        }
+        else{
+            pendingIntent = PendingIntent.getActivity(getApplicationContext(), (int) System.currentTimeMillis() /* Request code */, intent,
+                    PendingIntent.FLAG_IMMUTABLE);
+        }
+
+        String channelId = getApplicationContext().getString(R.string.default_notification_channel_id);
+        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
+
+        NotificationManager notificationManager =
+                (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
+
+        // Since android Oreo notification channel is needed.
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+            NotificationChannel channel = new NotificationChannel(channelId,
+                    "FastestVPN",
+                    NotificationManager.IMPORTANCE_HIGH);
+            notificationManager.createNotificationChannel(channel);
+        }
+
+        NotificationCompat.Builder notificationBuilder =
+                new NotificationCompat.Builder(getApplicationContext(), channelId)
+//                        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_logo))
+                        .setSmallIcon(R.drawable.ic_logo_notify)
+                        .setColor(getApplicationContext().getResources().getColor(R.color.app_yellow_color))
+//                        .setContentTitle("New Message")
+                        .setContentTitle(title)
+                        .setContentText(messageBody)
+                        .setAutoCancel(false)
+                        .setSound(defaultSoundUri)
+                        .setPriority(NotificationCompat.PRIORITY_HIGH)
+                        .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
+                        .setContentIntent(pendingIntent);
+
+
+        notificationManager.notify(App.NOTIFICATION_ID /* ID of notification */, notificationBuilder.build());
+    }
+
+}

+ 132 - 0
app/src/main/java/com/vpn/fastestvpnservice/fcm/WiFiMonitorService.java

@@ -0,0 +1,132 @@
+package com.vpn.fastestvpnservice.fcm;
+
+import android.Manifest;
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.net.wifi.ScanResult;
+import android.net.wifi.WifiManager;
+import android.os.Build;
+import android.os.IBinder;
+import android.util.Log;
+
+import androidx.annotation.Nullable;
+import androidx.core.app.ActivityCompat;
+
+import com.vpn.fastestvpnservice.R;
+import com.vpn.fastestvpnservice.utils.WifiScanReceiver;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Timer;
+
+public class WiFiMonitorService extends Service {
+
+    private static final int WIFI_SCAN_INTERVAL = 10 * 1000; // 10 seconds
+    private Timer timer;
+    private WifiScanReceiver wifiScanReceiver;
+    private WifiManager wifiManager;
+    private static final int NOTIFICATION_ID = 2;
+
+    private IntentFilter intentFilter;
+
+    public static final List<ScanResult> scanResultsStatic = new ArrayList<>();
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+
+        wifiScanReceiver = new WifiScanReceiver();
+        intentFilter = new IntentFilter();
+        intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
+
+//        NetworkJobService.scheduleJob(getApplicationContext());
+
+    }
+
+    @Override
+    public int onStartCommand(Intent intent, int flags, int startId) {
+
+//        timer = new Timer();
+//        timer.scheduleAtFixedRate(new TimerTask() {
+//            @Override
+//            public void run() {
+//                ConnectivityManager connectivityManager = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
+//
+//                if (connectivityManager != null) {
+//                    Log.d("open wifi rec ssid", "1");
+//                    NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
+//                    if (activeNetwork != null) {
+//                        Log.d("open wifi rec ssid", "2");
+//                        if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
+//                            // Connected to a Wi-Fi network, check if it's open
+//                            Log.d("open wifi rec ssid", "3");
+//                            WifiInfo wifiInfo = wifiManager.getConnectionInfo();
+//                            String ssid = wifiInfo.getSSID();
+//                            Log.d("open wifi rec ssid", ssid);
+//                        }
+//                    }
+//                }
+//            }
+//        }, 0, WIFI_SCAN_INTERVAL);
+
+//        startNotification();
+
+        Log.d("open wifi rec s Start", "Started onStartCommand");
+        wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
+        registerReceiver(wifiScanReceiver, intentFilter);
+        boolean status = wifiManager.startScan();
+        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+            // TODO: Consider calling
+            //    ActivityCompat#requestPermissions
+            // here to request the missing permissions, and then overriding
+            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
+            //                                          int[] grantResults)
+            // to handle the case where the user grants the permission. See the documentation
+            // for ActivityCompat#requestPermissions for more details.
+            return START_STICKY;
+        }
+        List<ScanResult> results = wifiManager.getScanResults();
+        scanResultsStatic.addAll(results);
+        Log.d("open wifi rec s results", results.size() + " " + status);
+
+        return START_STICKY;
+    }
+
+    private void startNotification() {
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+
+            String channelId = "FastestVPN_Foreground";
+            NotificationChannel channel = new NotificationChannel(channelId, "FastestVPN", NotificationManager.IMPORTANCE_LOW);
+            NotificationManager notificationManager = getSystemService(NotificationManager.class);
+            notificationManager.createNotificationChannel(channel);
+
+
+            Notification.Builder notification = new Notification.Builder(getApplicationContext(), channelId)
+                    .setContentTitle("Foreground Service")
+                    .setContentText("Monitoring Wi-Fi state changes")
+                    .setColor(getApplicationContext().getResources().getColor(R.color.app_yellow_color))
+                    .setSmallIcon(R.drawable.ic_logo_notify);
+
+            startForeground(NOTIFICATION_ID, notification.build());
+
+        }
+    }
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+//        unregisterReceiver(wifiScanReceiver);
+    }
+
+    @Nullable
+    @Override
+    public IBinder onBind(Intent intent) {
+        return null;
+    }
+}

+ 96 - 0
app/src/main/java/com/vpn/fastestvpnservice/utils/WifiScanReceiver.java

@@ -0,0 +1,96 @@
+package com.vpn.fastestvpnservice.utils;
+
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.media.RingtoneManager;
+import android.net.Uri;
+import android.net.wifi.WifiManager;
+import android.os.Build;
+import android.util.Log;
+import androidx.core.app.NotificationCompat;
+
+import com.vpn.fastestvpnservice.MainActivity;
+import com.vpn.fastestvpnservice.R;
+import com.vpn.fastestvpnservice.fcm.NetworkJobService;
+
+import de.blinkt.openvpn.core.App;
+
+public class WifiScanReceiver extends BroadcastReceiver {
+
+    Context context;
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        this.context = context;
+
+        Log.d("open_wifi_rec", "WifiScanReceiver");
+
+        String action = intent.getAction();
+
+        if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
+
+            Log.d("open_wifi_rec in", "Inside");
+
+            NetworkJobService.scheduleJob(context); // now commenting, will use later...
+
+        }
+    }
+
+    private void sendNotification(String title, String messageBody) {
+        Intent intent = new Intent(context, MainActivity.class);
+        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+//        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
+//                PendingIntent.FLAG_ONE_SHOT);
+//        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
+//                PendingIntent.FLAG_IMMUTABLE);
+        PendingIntent pendingIntent = null;
+
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+            pendingIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis() /* Request code */, intent,
+                    PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
+        }
+//        else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+//            pendingIntent = PendingIntent.getForegroundService(this, 0, intent,
+//                    PendingIntent.FLAG_IMMUTABLE);
+//        }
+        else{
+            pendingIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis() /* Request code */, intent,
+                    PendingIntent.FLAG_IMMUTABLE);
+        }
+
+        String channelId = context.getString(R.string.default_notification_channel_id);
+        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
+
+        NotificationManager notificationManager =
+                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+
+        // Since android Oreo notification channel is needed.
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+            NotificationChannel channel = new NotificationChannel(channelId,
+                    "FastestVPN",
+                    NotificationManager.IMPORTANCE_HIGH);
+            notificationManager.createNotificationChannel(channel);
+        }
+
+        NotificationCompat.Builder notificationBuilder =
+                new NotificationCompat.Builder(context, channelId)
+//                        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_logo))
+                        .setSmallIcon(R.drawable.ic_logo_notify)
+                        .setColor(context.getResources().getColor(R.color.app_yellow_color))
+//                        .setContentTitle("New Message")
+                        .setContentTitle(title)
+                        .setContentText(messageBody)
+                        .setAutoCancel(true)
+                        .setSound(defaultSoundUri)
+                        .setPriority(NotificationCompat.PRIORITY_HIGH)
+                        .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
+                        .setContentIntent(pendingIntent);
+
+
+        notificationManager.notify(App.NOTIFICATION_ID /* ID of notification */, notificationBuilder.build());
+    }
+}