Skip to content

Commit

Permalink
Convert to java
Browse files Browse the repository at this point in the history
  • Loading branch information
rajiv-singaseni committed Jan 1, 2025
1 parent 0ee281b commit a498b17
Show file tree
Hide file tree
Showing 34 changed files with 1,705 additions and 1,561 deletions.
68 changes: 35 additions & 33 deletions app/src/main/java/com/webileapps/protect/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ import com.webileapps.safeguard.AppActivity
import com.webileapps.safeguard.NetworkChangeReceiver
import com.webileapps.safeguard.SecurityChecker
import com.webileapps.safeguard.SecurityConfigManager
import com.webileapps.safeguard.checkApplicationSpoofing
import com.webileapps.safeguard.checkDeveloperOptions
import com.webileapps.safeguard.checkKeyLoggerDetection
import com.webileapps.safeguard.checkMalware
import com.webileapps.safeguard.checkNetwork
import com.webileapps.safeguard.checkRoot
import com.webileapps.safeguard.checkScreenMirroring
import com.webileapps.safeguard.CyberUtils
import com.webileapps.protect.sample.databinding.ActivityMainBinding

class MainActivity : AppActivity() {
Expand All @@ -27,23 +21,21 @@ class MainActivity : AppActivity() {
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)


/*TODO: Mobile application shall check new network connections or connections for unsecured networks like VPN connection, proxy and unsecured Wi-Fi connections.77~@*/
// Initialize SecurityConfigManager with desired configuration
SecurityConfigManager.initialize(
this,
SecurityChecker.SecurityConfig(
rootCheck = SecurityChecker.SecurityCheckState.WARNING,
developerOptionsCheck = SecurityChecker.SecurityCheckState.WARNING,
malwareCheck = SecurityChecker.SecurityCheckState.WARNING,
tamperingCheck = SecurityChecker.SecurityCheckState.WARNING,
appSpoofingCheck = SecurityChecker.SecurityCheckState.WARNING,
networkSecurityCheck = SecurityChecker.SecurityCheckState.WARNING,
screenSharingCheck = SecurityChecker.SecurityCheckState.WARNING,
keyloggerCheck = SecurityChecker.SecurityCheckState.WARNING,
ongoingCallCheck = SecurityChecker.SecurityCheckState.WARNING,
expectedPackageName = "com.webileapps.protect.sample",
expectedSignature = ""
SecurityChecker.SecurityCheckState.WARNING, // rootCheck
SecurityChecker.SecurityCheckState.WARNING, // developerOptionsCheck
SecurityChecker.SecurityCheckState.WARNING, // malwareCheck
SecurityChecker.SecurityCheckState.WARNING, // tamperingCheck
SecurityChecker.SecurityCheckState.WARNING, // appSpoofingCheck
SecurityChecker.SecurityCheckState.WARNING, // networkSecurityCheck
SecurityChecker.SecurityCheckState.WARNING, // screenSharingCheck
SecurityChecker.SecurityCheckState.WARNING, // keyloggerCheck
SecurityChecker.SecurityCheckState.WARNING, // ongoingCallCheck
"com.webileapps.protect.sample", // expectedPackageName
"" // expectedSignature
)
)

Expand All @@ -54,55 +46,65 @@ class MainActivity : AppActivity() {
val filter = IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
registerReceiver(networkChangeReceiver, filter)

securityChecker.setupCallMonitoring(activity= this, onPermissionDenied = {
})
securityChecker.setupCallMonitoring(this) {
// Handle permission denied
}

setupButtons()
}

private fun setupButtons() {
// Update button click handlers to use lambda for better readability
binding.btnCheckRoot.setOnClickListener {
this.checkRoot(securityChecker) { success ->
CyberUtils.checkRoot(this, securityChecker) { success ->
logCheckResult("Root", success)
}
}

binding.btnCheckDeveloper.setOnClickListener {
this.checkDeveloperOptions(securityChecker) { success ->
CyberUtils.checkDeveloperOptions(this, securityChecker) { success ->
logCheckResult("Developer Options", success)
}
}

binding.btnCheckNetwork.setOnClickListener {
this.checkNetwork(securityChecker) { success ->
CyberUtils.checkNetwork(this, securityChecker) { success ->
logCheckResult("Network", success)
}
}

binding.btnCheckMalware.setOnClickListener {
this.checkMalware(securityChecker) { success ->
CyberUtils.checkMalware(this, securityChecker) { success ->
logCheckResult("Malware", success)
}
}

binding.btnCheckScreenMirroring.setOnClickListener {
this.checkScreenMirroring(securityChecker) { success ->
CyberUtils.checkScreenMirroring(this, securityChecker) { success ->
logCheckResult("Screen Mirroring", success)
}
}

binding.btnAppSpoofing.setOnClickListener {
this.checkApplicationSpoofing(securityChecker) { success ->
CyberUtils.checkApplicationSpoofing(this, securityChecker) { success ->
logCheckResult("App Spoofing", success)
}
}

binding.btnKeyLoggerDetection.setOnClickListener {
this.checkKeyLoggerDetection(securityChecker) { success ->
CyberUtils.checkKeyLoggerDetection(this, securityChecker) { success ->
logCheckResult("Keylogger", success)
}
}
}

private fun logCheckResult(checkName: String, success: Boolean) {
val result = if (success) "passed" else "failed"
Log.d("SecurityCheck", "$checkName check $result")
Log.d("SecurityCheck", "$checkName check result: $success")
}


override fun onDestroy() {
super.onDestroy()
networkChangeReceiver?.let {
unregisterReceiver(it)
}
}
}
15 changes: 10 additions & 5 deletions app/src/main/java/com/webileapps/protect/sample/MyApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,30 @@ import com.webileapps.safeguard.NetworkChangeReceiver

class MyApplication : Application() {
private var networkChangeReceiver: NetworkChangeReceiver? = null

override fun onCreate() {
super.onCreate()

/*TODO: Mobile application shall check new network connections or connections for unsecured networks like VPN connection, proxy and unsecured Wi-Fi connections.77~@*/
// Initialize network monitoring
networkChangeReceiver = NetworkChangeReceiver()
val filter = IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
registerReceiver(networkChangeReceiver, filter)

// Add lifecycle observer
ProcessLifecycleOwner.get().lifecycle.addObserver(
AppLifecycleObserver(
this
)
AppLifecycleObserver(this)
)
}


companion object {
private var currentActivity: Activity? = null

@JvmStatic
fun getCurrentActivity(): Activity? = currentActivity

@JvmStatic
fun setCurrentActivity(activity: Activity?) {
currentActivity = activity
}
}
}
5 changes: 0 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
buildscript {
ext {
kotlin_version = '1.8.0'
compose_version = '1.4.0'
}
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:8.6.1'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.20'
}
}

Expand Down
5 changes: 0 additions & 5 deletions protect/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'maven-publish'
}

Expand All @@ -26,13 +25,9 @@ android {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
}

dependencies {
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.scottyab:rootbeer-lib:0.1.0'
implementation 'com.google.android.material:material:1.10.0'
Expand Down
37 changes: 37 additions & 0 deletions protect/src/main/java/com/webileapps/safeguard/AppActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.webileapps.safeguard;

import android.content.Context;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.WindowManager;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.Toast;

public class AppActivity extends AppCompatActivity {
private static Context context;

public static Context getContext() {
return context;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Tapjacking Prevention
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE
);
context = this;
}

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if ((event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) {
// Alert user and block the touch event
Toast.makeText(this, getString(R.string.tap_jacking_alert), Toast.LENGTH_SHORT).show();
return false; // Block event processing
}
return super.dispatchTouchEvent(event); // Allow normal event processing
}
}
36 changes: 0 additions & 36 deletions protect/src/main/java/com/webileapps/safeguard/AppActivity.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.webileapps.safeguard;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.annotation.NonNull;

public class AppLifecycleObserver implements DefaultLifecycleObserver {
private final Context context;
private SecurityChecker securityChecker;

public AppLifecycleObserver(Context context) {
this.context = context;
}

@Override
public void onStart(@NonNull LifecycleOwner owner) {
Log.e("APP>>>", "App is in Foreground");
// Perform security checks in sequence
performSecurityChecks();
}

private void performSecurityChecks() {
securityChecker = SecurityConfigManager.getSecurityChecker();
securityChecker.runSecurityChecks();
}

@Override
public void onStop(@NonNull LifecycleOwner owner) {
Log.e("APP>>>", "App is in Background");
if (securityChecker != null) {
securityChecker.cleanup();
}
}

private void detectOverlayApps(Context context) {
PackageManager pm = context.getPackageManager();
for (PackageInfo packageInfo : pm.getInstalledPackages(PackageManager.GET_PERMISSIONS)) {
String[] requestedPermissions = packageInfo.requestedPermissions;
if (requestedPermissions != null) {
for (String permission : requestedPermissions) {
if ("android.permission.SYSTEM_ALERT_WINDOW".equals(permission)) {
// Log or handle apps with SYSTEM_ALERT_WINDOW permission
Log.d("OverlayDetection", "App using SYSTEM_ALERT_WINDOW: " + packageInfo.packageName);
}
}
}
}
}
}

This file was deleted.

Loading

0 comments on commit a498b17

Please sign in to comment.