From 0979b6363082c36cb032bc113c6f48f1cb3824c6 Mon Sep 17 00:00:00 2001 From: hussainmohd-a Date: Tue, 16 May 2023 18:46:13 +0530 Subject: [PATCH 01/85] Resolving Issue Encountered with REBOOT Intent #893 Previously, the expected behavior of starting the VPN upon receiving the REBOOT intent was not consistent across various Android device manufacturers. In certain instances, the VPN initiation process would occur twice instead of once, resulting in failure notification. This fix will listen to the reboot and initiate the VPN start once. --- .../celzero/bravedns/RethinkDnsApplication.kt | 13 ------------- .../receiver/BraveAutoStartReceiver.kt | 6 +----- .../celzero/bravedns/ui/HomeScreenFragment.kt | 19 +++++++++++++++++-- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/app/src/full/java/com/celzero/bravedns/RethinkDnsApplication.kt b/app/src/full/java/com/celzero/bravedns/RethinkDnsApplication.kt index 51bf35f4a..8684d81fe 100644 --- a/app/src/full/java/com/celzero/bravedns/RethinkDnsApplication.kt +++ b/app/src/full/java/com/celzero/bravedns/RethinkDnsApplication.kt @@ -53,19 +53,6 @@ class RethinkDnsApplication : Application() { // database refresh is used in both headless and main project get().scheduleDatabaseRefreshJob() get().schedulePurgeConnectionsLog() - - /** - * Issue fix - https://github.com/celzero/rethink-app/issues/57 When the application - * crashes/updates it goes into red waiting state. This causes confusion to the users also - * requires click of START button twice to start the app. FIX : The check for the controller - * state. If persistence state has vpn enabled and the VPN is not connected then the start - * will be initiated. - */ - val state = VpnController.state() - if (state.activationRequested && !state.on) { - Log.i(LoggerConstants.LOG_TAG_VPN, "start VPN (previous state)") - if (VpnService.prepare(this) == null) VpnController.start(this) - } else VpnController.stop(this) } private fun turnOnStrictMode() { diff --git a/app/src/full/java/com/celzero/bravedns/receiver/BraveAutoStartReceiver.kt b/app/src/full/java/com/celzero/bravedns/receiver/BraveAutoStartReceiver.kt index 9e298146f..fdf85f109 100644 --- a/app/src/full/java/com/celzero/bravedns/receiver/BraveAutoStartReceiver.kt +++ b/app/src/full/java/com/celzero/bravedns/receiver/BraveAutoStartReceiver.kt @@ -54,7 +54,7 @@ class BraveAutoStartReceiver : BroadcastReceiver(), KoinComponent { try { VpnService.prepare(context) } catch (e: NullPointerException) { - Log.w(LOG_TAG_VPN, "Device does not support system-wide VPN mode.") + Log.w(LOG_TAG_VPN, "Device does not support system-wide VPN mode") return } @@ -62,10 +62,6 @@ class BraveAutoStartReceiver : BroadcastReceiver(), KoinComponent { VpnController.start(context) return } - - val startIntent = Intent(context, HomeScreenActivity::class.java) - startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(startIntent) } } } diff --git a/app/src/full/java/com/celzero/bravedns/ui/HomeScreenFragment.kt b/app/src/full/java/com/celzero/bravedns/ui/HomeScreenFragment.kt index 8104f95fc..e5f40e84f 100644 --- a/app/src/full/java/com/celzero/bravedns/ui/HomeScreenFragment.kt +++ b/app/src/full/java/com/celzero/bravedns/ui/HomeScreenFragment.kt @@ -70,12 +70,12 @@ import com.celzero.bravedns.util.Utilities.isPrivateDnsActive import com.celzero.bravedns.util.Utilities.showToastUiCentered import com.facebook.shimmer.Shimmer import com.google.android.material.snackbar.Snackbar +import java.util.* +import java.util.concurrent.TimeUnit import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.koin.android.ext.android.inject -import java.util.* -import java.util.concurrent.TimeUnit class HomeScreenFragment : Fragment(R.layout.fragment_home_screen) { private val b by viewBinding(FragmentHomeScreenBinding::bind) @@ -821,12 +821,27 @@ class HomeScreenFragment : Fragment(R.layout.fragment_home_screen) { override fun onResume() { super.onResume() handleShimmer() + maybeAutoStartVpn() updateCardsUi() syncDnsStatus() handleQuickSettingsChips() handleLockdownModeIfNeeded() } + /** + * Issue fix - https://github.com/celzero/rethink-app/issues/57 When the application + * crashes/updates it goes into red waiting state. This causes confusion to the users also + * requires click of START button twice to start the app. FIX : The check for the controller + * state. If persistence state has vpn enabled and the VPN is not connected then the start will + * be initiated. + */ + private fun maybeAutoStartVpn() { + if (isVpnActivated && !VpnController.state().on) { + Log.i(LOG_TAG_VPN, "start VPN (previous state)") + prepareAndStartVpn() + } + } + // set the app mode to dns+firewall mode when vpn in lockdown state private fun handleLockdownModeIfNeeded() { if (VpnController.isVpnLockdown() && !appConfig.getBraveMode().isDnsFirewallMode()) { From cae49843eb395b96254e73986bdd6bf59a419c8c Mon Sep 17 00:00:00 2001 From: hussainmohd-a Date: Tue, 16 May 2023 18:48:15 +0530 Subject: [PATCH 02/85] minor fix in DAO files --- .../com/celzero/bravedns/database/ConnectionTrackerDAO.kt | 4 ++-- .../java/com/celzero/bravedns/database/DnsCryptEndpointDAO.kt | 2 +- .../com/celzero/bravedns/database/DnsCryptRelayEndpointDAO.kt | 2 +- app/src/main/java/com/celzero/bravedns/database/DnsLogDAO.kt | 4 ++-- .../com/celzero/bravedns/database/RethinkRemoteFileTagDao.kt | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/celzero/bravedns/database/ConnectionTrackerDAO.kt b/app/src/main/java/com/celzero/bravedns/database/ConnectionTrackerDAO.kt index f5ea69e41..a44b7a8bf 100644 --- a/app/src/main/java/com/celzero/bravedns/database/ConnectionTrackerDAO.kt +++ b/app/src/main/java/com/celzero/bravedns/database/ConnectionTrackerDAO.kt @@ -26,9 +26,9 @@ interface ConnectionTrackerDAO { @Update fun update(connectionTracker: ConnectionTracker) - @Insert(onConflict = OnConflictStrategy.IGNORE) fun insert(connectionTracker: ConnectionTracker) + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(connectionTracker: ConnectionTracker) - @Insert(onConflict = OnConflictStrategy.IGNORE) + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insertBatch(connTrackerList: List) @Delete fun delete(connectionTracker: ConnectionTracker) diff --git a/app/src/main/java/com/celzero/bravedns/database/DnsCryptEndpointDAO.kt b/app/src/main/java/com/celzero/bravedns/database/DnsCryptEndpointDAO.kt index 7bbc1a0aa..49e3cc534 100644 --- a/app/src/main/java/com/celzero/bravedns/database/DnsCryptEndpointDAO.kt +++ b/app/src/main/java/com/celzero/bravedns/database/DnsCryptEndpointDAO.kt @@ -24,7 +24,7 @@ interface DnsCryptEndpointDAO { @Update fun update(dnsCryptEndpoint: DnsCryptEndpoint) - @Insert(onConflict = OnConflictStrategy.IGNORE) fun insert(dnsCryptEndpoint: DnsCryptEndpoint) + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(dnsCryptEndpoint: DnsCryptEndpoint) @Delete fun delete(dnsCryptEndpoint: DnsCryptEndpoint) diff --git a/app/src/main/java/com/celzero/bravedns/database/DnsCryptRelayEndpointDAO.kt b/app/src/main/java/com/celzero/bravedns/database/DnsCryptRelayEndpointDAO.kt index 036b47bc1..0a1d0d419 100644 --- a/app/src/main/java/com/celzero/bravedns/database/DnsCryptRelayEndpointDAO.kt +++ b/app/src/main/java/com/celzero/bravedns/database/DnsCryptRelayEndpointDAO.kt @@ -23,7 +23,7 @@ interface DnsCryptRelayEndpointDAO { @Update fun update(dnsCryptRelayEndpoint: DnsCryptRelayEndpoint) - @Insert(onConflict = OnConflictStrategy.IGNORE) + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(dnsCryptRelayEndpoint: DnsCryptRelayEndpoint) @Delete fun delete(dnsCryptRelayEndpoint: DnsCryptRelayEndpoint) diff --git a/app/src/main/java/com/celzero/bravedns/database/DnsLogDAO.kt b/app/src/main/java/com/celzero/bravedns/database/DnsLogDAO.kt index b70f2b97e..b60f8b34c 100644 --- a/app/src/main/java/com/celzero/bravedns/database/DnsLogDAO.kt +++ b/app/src/main/java/com/celzero/bravedns/database/DnsLogDAO.kt @@ -25,9 +25,9 @@ import com.celzero.bravedns.util.Constants.Companion.MAX_LOGS @Dao interface DnsLogDAO { - @Insert(onConflict = OnConflictStrategy.IGNORE) fun insert(dnsLog: DnsLog) + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(dnsLog: DnsLog) - @Insert(onConflict = OnConflictStrategy.IGNORE) fun insertBatch(dnsLogs: List) + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insertBatch(dnsLogs: List) // replace order by timeStamp desc with order by id desc, as order by timeStamp desc is building // the query with temporary index on the table. This is causing the query to be slow. diff --git a/app/src/main/java/com/celzero/bravedns/database/RethinkRemoteFileTagDao.kt b/app/src/main/java/com/celzero/bravedns/database/RethinkRemoteFileTagDao.kt index 2912d946f..1c4ee7aa2 100644 --- a/app/src/main/java/com/celzero/bravedns/database/RethinkRemoteFileTagDao.kt +++ b/app/src/main/java/com/celzero/bravedns/database/RethinkRemoteFileTagDao.kt @@ -25,7 +25,7 @@ interface RethinkRemoteFileTagDao { @Update fun update(fileTag: RethinkRemoteFileTag) - @Insert(onConflict = OnConflictStrategy.IGNORE) fun insert(fileTag: RethinkRemoteFileTag) + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(fileTag: RethinkRemoteFileTag) @Delete fun delete(fileTag: RethinkRemoteFileTag) From bef5e4db7ff07f1e7c238a57634d0488fc081dd8 Mon Sep 17 00:00:00 2001 From: hussainmohd-a Date: Sat, 10 Jun 2023 22:24:23 +0530 Subject: [PATCH 03/85] Fix: Some text is partially hidden in settings #913 --- app/src/main/res/layout/fragment_dns_configure.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/res/layout/fragment_dns_configure.xml b/app/src/main/res/layout/fragment_dns_configure.xml index 6db61d760..cf0cd4a48 100644 --- a/app/src/main/res/layout/fragment_dns_configure.xml +++ b/app/src/main/res/layout/fragment_dns_configure.xml @@ -296,6 +296,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="5dp" + android:paddingBottom="5dp" android:text="@string/cd_dns_alg_desc" android:textSize="@dimen/default_font_text_view" /> @@ -382,6 +383,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="5dp" + android:paddingBottom="5dp" android:text="@string/dc_dns_website_desc" android:textSize="@dimen/default_font_text_view" /> @@ -437,6 +439,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="5dp" + android:paddingBottom="5dp" android:text="@string/dc_setting_dns_cache_desc" android:textSize="@dimen/default_font_text_view" /> @@ -491,6 +494,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="5dp" + android:paddingBottom="5dp" android:text="@string/settings_custom_downloader_desc" android:textSize="@dimen/default_font_text_view" /> @@ -546,6 +550,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="5dp" + android:paddingBottom="5dp" android:text="@string/dc_check_update_desc" android:textSize="@dimen/default_font_text_view" /> @@ -602,6 +607,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="5dp" + android:paddingBottom="5dp" android:text="@string/dc_dns_leaks_desc" android:textSize="@dimen/default_font_text_view" /> From 89b320b882a0863c2bfab77f3083d490e636ad73 Mon Sep 17 00:00:00 2001 From: hussainmohd-a Date: Sat, 10 Jun 2023 23:18:52 +0530 Subject: [PATCH 04/85] Fix: In Logs, show all apps with the same uid #880 Now, there is no way to display the app list in the network log if there are more than one app. When you click on the app name in the bottom sheet of the network log, it will navigate to the app info screen. The 'i' icon on the screen will now show the list of app names. --- .../celzero/bravedns/ui/AppInfoActivity.kt | 47 +++++++++++++++---- .../java/com/celzero/bravedns/util/UIUtils.kt | 4 +- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/app/src/full/java/com/celzero/bravedns/ui/AppInfoActivity.kt b/app/src/full/java/com/celzero/bravedns/ui/AppInfoActivity.kt index 60b79466d..24e81737d 100644 --- a/app/src/full/java/com/celzero/bravedns/ui/AppInfoActivity.kt +++ b/app/src/full/java/com/celzero/bravedns/ui/AppInfoActivity.kt @@ -52,8 +52,8 @@ import com.celzero.bravedns.util.Constants.Companion.INVALID_UID import com.celzero.bravedns.util.Constants.Companion.VIEW_PAGER_SCREEN_TO_LOAD import com.celzero.bravedns.util.CustomLinearLayoutManager import com.celzero.bravedns.util.Themes -import com.celzero.bravedns.util.UIUtils.openAndroidAppInfo -import com.celzero.bravedns.util.UIUtils.updateHtmlEncodedText +import com.celzero.bravedns.util.UiUtils.openAndroidAppInfo +import com.celzero.bravedns.util.UiUtils.updateHtmlEncodedText import com.celzero.bravedns.util.Utilities import com.celzero.bravedns.util.Utilities.showToastUiCentered import com.celzero.bravedns.viewmodel.AppConnectionsViewModel @@ -77,7 +77,7 @@ class AppInfoActivity : private val domainRulesViewModel: CustomDomainViewModel by viewModel() private val networkLogsViewModel: AppConnectionsViewModel by viewModel() - private var uid: Int = 0 + private var uid: Int = INVALID_UID private lateinit var appInfo: AppInfo private var ipListUiState: Boolean = true @@ -149,10 +149,6 @@ class AppInfoActivity : val packages = FirewallManager.getPackageNamesByUid(appInfo.uid) - if (packages.count() != 1) { - b.aadAppInfoIcon.visibility = View.GONE - } - b.aadAppDetailName.text = appName(packages.count()) appStatus = FirewallManager.appStatus(appInfo.uid) connStatus = FirewallManager.connectionStatus(appInfo.uid) @@ -255,7 +251,20 @@ class AppInfoActivity : b.aadConnDetailSearch.setOnQueryTextListener(this) - b.aadAppInfoIcon.setOnClickListener { openAndroidAppInfo(this, appInfo.packageName) } + b.aadAppInfoIcon.setOnClickListener { + val packages = FirewallManager.getAppNamesByUid(appInfo.uid) + if (packages.count() == 1) { + openAndroidAppInfo(this, appInfo.packageName) + } else if (packages.count() > 1) { + showAppInfoDialog(packages) + } else { + showToastUiCentered( + this, + this.getString(R.string.ctbs_app_info_not_available_toast), + Toast.LENGTH_SHORT + ) + } + } TooltipCompat.setTooltipText( b.aadAppSettingsBypassDnsFirewall, @@ -378,6 +387,28 @@ class AppInfoActivity : b.aadConnDelete.setOnClickListener { showDeleteConnectionsDialog() } } + private fun showAppInfoDialog(packages: List) { + val builderSingle: android.app.AlertDialog.Builder = android.app.AlertDialog.Builder(this) + + builderSingle.setTitle(this.getString(R.string.about_settings_app_info)) + + val arrayAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_activated_1) + arrayAdapter.addAll(packages) + builderSingle.setCancelable(false) + + builderSingle.setItems(packages.toTypedArray(), null) + + builderSingle.setPositiveButton(getString(R.string.ada_noapp_dialog_positive)) { + dialog: DialogInterface, + _: Int -> + dialog.dismiss() + } + + val alertDialog: android.app.AlertDialog = builderSingle.create() + alertDialog.listView.setOnItemClickListener { _, _, _, _ -> } + alertDialog.show() + } + private fun setAppDns(url: String) { io { val endpoint = diff --git a/app/src/full/java/com/celzero/bravedns/util/UIUtils.kt b/app/src/full/java/com/celzero/bravedns/util/UIUtils.kt index fc4a3fdec..b55fdaee3 100644 --- a/app/src/full/java/com/celzero/bravedns/util/UIUtils.kt +++ b/app/src/full/java/com/celzero/bravedns/util/UIUtils.kt @@ -46,7 +46,7 @@ import java.util.TimeZone import java.util.regex.Matcher import java.util.regex.Pattern -object UIUtils { +object UiUtils { fun getDnsStatus(): Int { val status = VpnController.state() @@ -265,7 +265,7 @@ object UIUtils { if (isDgaDomain(dnsLog.queryStr)) return if (DEBUG) - Log.d(UIUtils::class.java.simpleName, "Glide - fetchFavIcon() -${dnsLog.queryStr}") + Log.d(LoggerConstants.LOG_TAG_UI, "Glide - fetchFavIcon():${dnsLog.queryStr}") // fetch fav icon in background using glide FavIconDownloader(context, dnsLog.queryStr).run() From b950fe8abb509671f140675fd59f00fc5ebcbed4 Mon Sep 17 00:00:00 2001 From: hussainmohd-a Date: Sat, 10 Jun 2023 23:31:58 +0530 Subject: [PATCH 05/85] Fix: Port lost when editing IP rules #910 --- .../com/celzero/bravedns/adapter/CustomIpAdapter.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/full/java/com/celzero/bravedns/adapter/CustomIpAdapter.kt b/app/src/full/java/com/celzero/bravedns/adapter/CustomIpAdapter.kt index 2c6b3518d..a7673dadf 100644 --- a/app/src/full/java/com/celzero/bravedns/adapter/CustomIpAdapter.kt +++ b/app/src/full/java/com/celzero/bravedns/adapter/CustomIpAdapter.kt @@ -39,8 +39,8 @@ import com.celzero.bravedns.databinding.ListItemCustomIpBinding import com.celzero.bravedns.service.IpRulesManager import com.celzero.bravedns.ui.CustomRulesActivity import com.celzero.bravedns.util.Constants.Companion.UID_EVERYBODY -import com.celzero.bravedns.util.UIUtils.fetchColor -import com.celzero.bravedns.util.UIUtils.fetchToggleBtnColors +import com.celzero.bravedns.util.UiUtils.fetchColor +import com.celzero.bravedns.util.UiUtils.fetchToggleBtnColors import com.celzero.bravedns.util.Utilities import com.celzero.bravedns.util.Utilities.getCountryCode import com.celzero.bravedns.util.Utilities.getFlag @@ -420,7 +420,12 @@ class CustomIpAdapter(private val context: Context) : dialog.window?.attributes = lp dBind.daciIpTitle.text = context.getString(R.string.ci_dialog_title) - dBind.daciIpEditText.setText(customIp.ipAddress) + if (customIp.port != 0) { + val ipPort = context.getString(R.string.ct_ip_port, customIp.ipAddress, customIp.port.toString()) + dBind.daciIpEditText.setText(ipPort) + } else { + dBind.daciIpEditText.setText(customIp.ipAddress) + } if (customIp.uid == UID_EVERYBODY) { dBind.daciTrustBtn.text = context.getString(R.string.bypass_universal) From 50ff192bc526653702a2979825bcd173c5b41213 Mon Sep 17 00:00:00 2001 From: hussainmohd-a Date: Mon, 12 Jun 2023 20:17:34 +0530 Subject: [PATCH 06/85] format styles.xml --- app/src/main/res/values/styles.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index bb285cce2..e5a5ba003 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -306,7 +306,7 @@