Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@
.cxx


vpnLib/build/.transforms/*
vpnLib/build/generated/*
vpnLib/build/*
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 33 additions & 15 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
apply plugin: 'com.android.application'
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

android {
compileSdkVersion 33
compileSdk 34
defaultConfig {
minSdkVersion 16
targetSdkVersion 33
namespace 'com.lazycoder.cakevpn'
minSdk 21
targetSdk 34
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
applicationId 'com.lazycoder.cakevpn'
multiDexEnabled true
}
buildTypes {
release {
Expand All @@ -18,32 +23,45 @@ android {
}
buildFeatures {
dataBinding true
buildConfig = true
// for view binding:
// viewBinding true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_21
targetCompatibility JavaVersion.VERSION_21
}
kotlinOptions {
jvmTarget = '21'
}
buildFeatures {
viewBinding true
}
packagingOptions {
jniLibs {
useLegacyPackaging = true
}
}
buildToolsVersion '30.0.1'
}

dependencies {

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
testImplementation 'junit:junit:4.13'

implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'androidx.core:core:1.13.1'
implementation 'androidx.constraintlayout:constraintlayout:2.2.1'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.android.material:material:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
implementation 'com.google.android.material:material:1.12.0'

implementation 'com.squareup.retrofit2:retrofit:2.7.0'
implementation 'com.squareup.retrofit2:retrofit:2.11.0'

// Glide image loader
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
implementation project(path: ':vpnLib')
implementation 'androidx.multidex:multidex:2.0.1'
}
89 changes: 47 additions & 42 deletions app/src/main/java/com/lazycoder/cakevpn/view/MainFragment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.lazycoder.cakevpn.view;

import static android.app.Activity.RESULT_OK;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
Expand All @@ -11,7 +13,6 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.widget.Toast;

import androidx.annotation.Nullable;
Expand All @@ -38,8 +39,6 @@
import de.blinkt.openvpn.core.OpenVPNThread;
import de.blinkt.openvpn.core.VpnStatus;

import static android.app.Activity.RESULT_OK;

public class MainFragment extends Fragment implements View.OnClickListener, ChangeServer {

private Server server;
Expand Down Expand Up @@ -93,21 +92,20 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
*/
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.vpnBtn:
// Vpn is running, user would like to disconnect current connection.
if (vpnStart) {
confirmDisconnect();
}else {
prepareVpn();
}
if (v.getId() == R.id.vpnBtn) {
// Vpn is running, user would like to disconnect current connection.
if (vpnStart) {
confirmDisconnect();
} else {
prepareVpn();
}
}
}

/**
* Show show disconnect confirm dialog
*/
public void confirmDisconnect(){
public void confirmDisconnect() {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(getActivity().getString(R.string.connection_close_confirm));

Expand Down Expand Up @@ -159,6 +157,7 @@ private void prepareVpn() {

/**
* Stop vpn
*
* @return boolean: VPN status
*/
public boolean stopVpn() {
Expand Down Expand Up @@ -237,41 +236,43 @@ private void startVpn() {

/**
* Status change with corresponding vpn connection status
*
* @param connectionState
*/
public void setStatus(String connectionState) {
if (connectionState!= null)
switch (connectionState) {
case "DISCONNECTED":
status("connect");
vpnStart = false;
vpnService.setDefaultStatus();
binding.logTv.setText("");
break;
case "CONNECTED":
vpnStart = true;// it will use after restart this activity
status("connected");
binding.logTv.setText("");
break;
case "WAIT":
binding.logTv.setText("waiting for server connection!!");
break;
case "AUTH":
binding.logTv.setText("server authenticating!!");
break;
case "RECONNECTING":
status("connecting");
binding.logTv.setText("Reconnecting...");
break;
case "NONETWORK":
binding.logTv.setText("No network connection");
break;
}
if (connectionState != null)
switch (connectionState) {
case "DISCONNECTED":
status("connect");
vpnStart = false;
vpnService.setDefaultStatus();
binding.logTv.setText("");
break;
case "CONNECTED":
vpnStart = true;// it will use after restart this activity
status("connected");
binding.logTv.setText("");
break;
case "WAIT":
binding.logTv.setText("waiting for server connection!!");
break;
case "AUTH":
binding.logTv.setText("server authenticating!!");
break;
case "RECONNECTING":
status("connecting");
binding.logTv.setText("Reconnecting...");
break;
case "NONETWORK":
binding.logTv.setText("No network connection");
break;
}

}

/**
* Change button background color and text
*
* @param status: VPN current status
*/
public void status(String status) {
Expand Down Expand Up @@ -334,10 +335,11 @@ public void onReceive(Context context, Intent intent) {

/**
* Update status UI
* @param duration: running time
*
* @param duration: running time
* @param lastPacketReceive: last packet receive time
* @param byteIn: incoming data
* @param byteOut: outgoing data
* @param byteIn: incoming data
* @param byteOut: outgoing data
*/
public void updateConnectionStatus(String duration, String lastPacketReceive, String byteIn, String byteOut) {
binding.durationTv.setText("Duration: " + duration);
Expand All @@ -348,6 +350,7 @@ public void updateConnectionStatus(String duration, String lastPacketReceive, St

/**
* Show toast message
*
* @param message: toast message
*/
public void showToast(String message) {
Expand All @@ -356,6 +359,7 @@ public void showToast(String message) {

/**
* VPN server country icon change
*
* @param serverIcon: icon URL
*/
public void updateCurrentServerIcon(String serverIcon) {
Expand All @@ -366,6 +370,7 @@ public void updateCurrentServerIcon(String serverIcon) {

/**
* Change server when user select new server
*
* @param server ovpn server details
*/
@Override
Expand Down
27 changes: 9 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.packagecloud_token = 'e38fd147bab499ff7f01663c0ea8079d4748cadb99f7f351'

repositories {
mavenLocal()
google()
mavenCentral()


}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }

classpath 'com.android.tools.build:gradle:8.6.1'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22'
}
}

task clean(type: Delete) {
delete rootProject.buildDir
plugins {
id 'com.android.application' version '8.6.1' apply false
id 'com.android.library' version '8.6.1' apply false
id 'org.jetbrains.kotlin.android' version '1.9.22' apply false
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
android.bundle.enableUncompressedNativeLibs=false
android.buildFeatures.aidl=true
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Jul 23 17:33:38 SGT 2020
#Thu Mar 13 08:28:18 EET 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
23 changes: 21 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
include ':app', ':vpnLib'
rootProject.name='Cake VPN'
pluginManagement {
repositories {
google()
mavenLocal()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenLocal()
mavenCentral()
}
}

rootProject.name = 'Cake VPN'
include ':app'
include ':vpnLib'

Loading