Skip to content

Commit

Permalink
Fix network change receiver crash.
Browse files Browse the repository at this point in the history
  • Loading branch information
rajiv-singaseni committed Jan 1, 2025
1 parent 147a7e8 commit 60cae2e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class MainActivity : AppActivity() {
SecurityChecker.SecurityCheckState.WARNING, // screenSharingCheck
SecurityChecker.SecurityCheckState.WARNING, // keyloggerCheck
SecurityChecker.SecurityCheckState.WARNING, // ongoingCallCheck
SecurityChecker.SecurityCheckState.WARNING, // appSignatureCheck
"com.webileapps.protect.sample", // expectedPackageName
"" // expectedSignature
)
Expand Down Expand Up @@ -103,8 +104,6 @@ class MainActivity : AppActivity() {

override fun onDestroy() {
super.onDestroy()
networkChangeReceiver?.let {
unregisterReceiver(it)
}
unregisterReceiver(networkChangeReceiver)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ public void onReceive(Context context, Intent intent) {
if (isNetworkConnected(context)) {
if (NetworkUtils.isVPNActive(context)) {
SecurityConfigManager.getSecurityChecker().showSecurityDialog(
AppActivity.context,
context,
context.getString(R.string.vpn_warning),
false,
() -> {}
(ok) -> {}
);
}
else if (NetworkUtils.isProxySet(context)) {
// Handle proxy detection
SecurityConfigManager.getSecurityChecker().showSecurityDialog(
AppActivity.context,
context,
context.getString(R.string.proxy_warning),
false,
() -> {}
(ok) -> {}
);
}
else if (!NetworkUtils.isWifiSecure(context)) {
// Handle unsecured Wi-Fi detection
SecurityConfigManager.getSecurityChecker().showSecurityDialog(
AppActivity.context,
context,
context.getString(R.string.usecured_network_warning),
false,
() -> {}
(ok) -> {}
);
}
} else {
Expand Down
36 changes: 24 additions & 12 deletions protect/src/main/java/com/webileapps/safeguard/SecurityChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public SecurityConfig(
SecurityCheckState screenSharingCheck,
SecurityCheckState keyloggerCheck,
SecurityCheckState ongoingCallCheck,
SecurityCheckState appSignature,
String expectedPackageName,
String expectedSignature
) {
Expand All @@ -98,7 +99,7 @@ public SecurityConfig(
this.networkSecurityCheck = networkSecurityCheck;
this.screenSharingCheck = screenSharingCheck;
this.keyloggerCheck = keyloggerCheck;
this.appSignature = SecurityCheckState.WARNING; // Default value
this.appSignature = appSignature;
this.ongoingCallCheck = ongoingCallCheck;
this.expectedPackageName = expectedPackageName;
this.expectedSignature = expectedSignature;
Expand Down Expand Up @@ -418,33 +419,44 @@ public SecurityCheck checkDeveloperOptions() {

try {
boolean developerMode = Settings.Global.getInt(
context.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED
context.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED
) != 0;

if (developerMode) {
return createDevOptionsResponse("Developer options are enabled.");
}
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}

try {
boolean usbDebugging = Settings.Global.getInt(
context.getContentResolver(),
Settings.Global.ADB_ENABLED
context.getContentResolver(),
Settings.Global.ADB_ENABLED
) != 0;
if (usbDebugging) {
return createDevOptionsResponse("USB debugging is enabled.");
}
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}

try {
boolean mockLocation = !"0".equals(Settings.Secure.getString(
context.getContentResolver(),
Settings.Secure.ALLOW_MOCK_LOCATION
));

if (developerMode) {
return createDevOptionsResponse("Developer options are enabled.");
} else if (usbDebugging) {
return createDevOptionsResponse("USB debugging is enabled.");
} else if (mockLocation) {
if (mockLocation) {
return createDevOptionsResponse("Mock location is enabled.");
} else if (isTimeManipulated()) {
return createDevOptionsResponse("Automatic time settings are disabled.");
}
} catch (Settings.SettingNotFoundException e) {
} catch (Exception e) {
e.printStackTrace();
}

return new SecurityCheck.Success();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ public static SecurityChecker.SecurityConfig getConfig() {
SecurityChecker.SecurityCheckState.ERROR, // developerOptionsCheck
SecurityChecker.SecurityCheckState.ERROR, // malwareCheck
SecurityChecker.SecurityCheckState.ERROR, // tamperingCheck
SecurityChecker.SecurityCheckState.WARNING, // appSpoofingCheck
SecurityChecker.SecurityCheckState.WARNING, // networkSecurityCheck
SecurityChecker.SecurityCheckState.WARNING, // screenSharingCheck
SecurityChecker.SecurityCheckState.WARNING, // appSpoofingCheck
SecurityChecker.SecurityCheckState.WARNING // keyloggerCheck
SecurityChecker.SecurityCheckState.WARNING, // keyloggerCheck
SecurityChecker.SecurityCheckState.WARNING, // onGoingCallCheck
SecurityChecker.SecurityCheckState.WARNING, // appSignatureCheck
"",
""
);
}
return config;
Expand Down

0 comments on commit 60cae2e

Please sign in to comment.