From a15b454f1b66c0cd470c011fd88f509f788d3941 Mon Sep 17 00:00:00 2001 From: ukanth Date: Fri, 25 Oct 2024 20:34:43 +0530 Subject: [PATCH] more fixes for target sdk 34 --- .../dev/ukanth/ufirewall/MainActivity.java | 23 ++++++++++++++++--- .../ufirewall/service/FirewallService.java | 20 +++++++++++++--- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/dev/ukanth/ufirewall/MainActivity.java b/app/src/main/java/dev/ukanth/ufirewall/MainActivity.java index 292bf2bd..2ec8b4b8 100644 --- a/app/src/main/java/dev/ukanth/ufirewall/MainActivity.java +++ b/app/src/main/java/dev/ukanth/ufirewall/MainActivity.java @@ -31,6 +31,7 @@ import static dev.ukanth.ufirewall.util.SecurityUtil.REQ_ENTER_PATTERN; import android.Manifest; +import android.annotation.SuppressLint; import android.app.KeyguardManager; import android.app.NotificationManager; import android.content.ActivityNotFoundException; @@ -113,6 +114,7 @@ import dev.ukanth.ufirewall.util.PackageComparator; import dev.ukanth.ufirewall.util.SecurityUtil; import haibison.android.lockpattern.utils.AlpSettings; +import kotlin.Suppress; public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener, OnClickListener, SwipeRefreshLayout.OnRefreshListener, @@ -280,6 +282,7 @@ private void registerLogService() { } } + @SuppressLint("UnspecifiedRegisterReceiverFlag") private void registerUIRefresh() { IntentFilter filter = new IntentFilter("dev.ukanth.ufirewall.ui.CHECKREFRESH"); uiRefreshReceiver = new BroadcastReceiver() { @@ -295,9 +298,14 @@ public void onReceive(Context context, Intent intent) { } } }; - registerReceiver(uiRefreshReceiver, filter); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + registerReceiver(uiRefreshReceiver, filter, RECEIVER_EXPORTED); + } else { + registerReceiver(uiRefreshReceiver, filter); + } } + @SuppressLint("UnspecifiedRegisterReceiverFlag") private void registerThemeIntent() { IntentFilter filter = new IntentFilter("dev.ukanth.ufirewall.theme.REFRESH"); @@ -308,7 +316,11 @@ public void onReceive(Context context, Intent intent) { recreate(); } }; - registerReceiver(themeRefreshReceiver, filter); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + registerReceiver(themeRefreshReceiver, filter, RECEIVER_EXPORTED); + } else { + registerReceiver(themeRefreshReceiver, filter); + } } private void probeLogTarget() { @@ -416,6 +428,7 @@ public void onBackPressed() { }*/ + @SuppressLint("UnspecifiedRegisterReceiverFlag") private void registerToastbroadcast() { IntentFilter filter = new IntentFilter("TOAST"); toastReceiver = new BroadcastReceiver() { @@ -424,7 +437,11 @@ public void onReceive(Context context, Intent intent) { Api.toast(getApplicationContext(), intent.getExtras().get("MSG") != null ? intent.getExtras().get("MSG").toString() : "", Toast.LENGTH_SHORT); } }; - registerReceiver(toastReceiver, filter); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + registerReceiver(toastReceiver, filter, RECEIVER_EXPORTED); + } else { + registerReceiver(toastReceiver, filter); + } } private void registerUIbroadcast4() { diff --git a/app/src/main/java/dev/ukanth/ufirewall/service/FirewallService.java b/app/src/main/java/dev/ukanth/ufirewall/service/FirewallService.java index 53ecccd2..b7f0c79f 100644 --- a/app/src/main/java/dev/ukanth/ufirewall/service/FirewallService.java +++ b/app/src/main/java/dev/ukanth/ufirewall/service/FirewallService.java @@ -189,17 +189,31 @@ public int onStartCommand(Intent intent, int flags, int startId) { connectivityReciver = new ConnectivityChangeReceiver(); filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); filter.addAction(ConnectivityChangeReceiver.TETHER_STATE_CHANGED_ACTION); - registerReceiver(connectivityReciver, filter); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + registerReceiver(connectivityReciver, filter, RECEIVER_EXPORTED); + } else { + registerReceiver(connectivityReciver, filter); + } IntentFilter intentFilter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); intentFilter.addDataScheme("package"); packageReceiver = new PackageBroadcast(); - registerReceiver(packageReceiver, intentFilter); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + registerReceiver(packageReceiver, intentFilter, RECEIVER_EXPORTED); + } else { + registerReceiver(packageReceiver, intentFilter); + } intentFilter = new IntentFilter(Intent.ACTION_PACKAGE_REMOVED); intentFilter.addDataScheme("package"); - registerReceiver(packageReceiver, intentFilter); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + registerReceiver(packageReceiver, intentFilter,RECEIVER_EXPORTED); + } else { + registerReceiver(packageReceiver, intentFilter); + } if(bluetoothAdapter == null) { bluetoothAdapter = getBTAdapter(context);