Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor all things mk 2 #354

Merged
merged 21 commits into from
Sep 19, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ android {
applicationId "com.celzero.bravedns"
minSdkVersion 23
targetSdkVersion 30
versionCode 17 // For version name 053f
versionName "0.5.3f"
versionCode 18 // For version name 053g
versionName "053g"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled true //Disabled this option for open testing to get more log details
// Modified as part of #352
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
Expand Down Expand Up @@ -94,9 +95,8 @@ dependencies {
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
implementation 'org.minidns:minidns-core:1.0.0'
implementation 'org.minidns:minidns-hla:1.0.0'
// To check if the play services is available
implementation 'com.google.android.gms:play-services-base:17.6.0'

// For liveData implementation
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'

implementation 'com.google.code.gson:gson:2.8.6'

Expand All @@ -119,6 +119,7 @@ dependencies {


implementation 'com.squareup.okhttp3:okhttp:4.9.0'
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.9.0'
playImplementation 'com.google.android.play:core:1.10.0'//for new version updater

//Glide implementation
Expand Down
29 changes: 23 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
<uses-permission
android:name="android.permission.INTERACT_ACROSS_USERS"
android:protectionLevel="signature"
tools:ignore="ProtectedPermissions" />

<application
android:name=".RethinkDnsApplication"
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:roundIcon="@drawable/ic_launcher"
android:supportsRtl="true"
android:name=".RethinkDnsApplication"
android:theme="@style/AppThemeInitial">
<meta-data
android:name="android.webkit.WebView.MetricsOptOut"
Expand All @@ -46,17 +48,21 @@
android:launchMode="singleTask" />
<activity
android:name=".ui.WelcomeActivity"
android:noHistory="true"
android:launchMode="singleTask"/>
android:launchMode="singleTask"
android:noHistory="true" />
<activity
android:name=".ui.AppInfoActivity"
android:launchMode="singleInstance" />
<activity
android:name=".ui.FaqWebViewActivity"
android:launchMode="singleInstance" />
<activity
android:name=".ui.PauseActivity"
android:launchMode="singleTop" />
<activity
android:name=".ui.DNSConfigureWebViewActivity"
android:launchMode="singleInstance" />

<service
android:name=".util.BackgroundAccessibilityService"
android:label="@string/accessibility_service_label"
Expand All @@ -80,8 +86,8 @@
</receiver>
<receiver
android:name=".receiver.NotificationActionReceiver"
android:label="@string/app_name">
</receiver>
android:label="@string/app_name"></receiver>

<service
android:name=".service.BraveVPNService"
android:permission="android.permission.BIND_VPN_SERVICE"
Expand All @@ -103,6 +109,17 @@
android:name="android.service.quicksettings.ACTIVE_TILE"
android:value="true" />
</service>

<provider
ignoramous marked this conversation as resolved.
Show resolved Hide resolved
android:name="androidx.core.content.FileProvider"
android:authorities="com.celzero.bravedns.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>

</application>

</manifest>
ignoramous marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 9 additions & 1 deletion app/src/main/java/com/celzero/bravedns/NonStoreAppUpdater.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ import com.celzero.bravedns.util.Constants.Companion.JSON_VERSION
import com.celzero.bravedns.util.Constants.Companion.RESPONSE_VERSION
import com.celzero.bravedns.util.LoggerConstants.Companion.LOG_TAG_APP_UPDATE
import okhttp3.*
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.dnsoverhttps.DnsOverHttps
import org.json.JSONObject
import java.io.IOException
import java.net.InetAddress

class NonStoreAppUpdater(private val baseUrl: String,
private val persistentState: PersistentState) : AppUpdater {
Expand All @@ -37,7 +40,12 @@ class NonStoreAppUpdater(private val baseUrl: String,
Log.i(LOG_TAG_APP_UPDATE, "Beginning update check")
val url = baseUrl + BuildConfig.VERSION_CODE

val client = OkHttpClient()
val bootstrapClient = OkHttpClient()
val dns = DnsOverHttps.Builder().client(bootstrapClient).url(
"https://1.1.1.1/dns-query".toHttpUrl()).bootstrapDnsHosts(
ignoramous marked this conversation as resolved.
Show resolved Hide resolved
InetAddress.getByName("1.1.1.1"), InetAddress.getByName("1.0.0.1")).build()

val client = bootstrapClient.newBuilder().dns(dns).build()
val request = Request.Builder().url(url).build()

client.newCall(request).enqueue(object : Callback {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private val updaterModule = module {
}

private val orbotHelperModule = module {
single { OrbotHelper(androidContext(), get(), get(), get()) }
single { OrbotHelper(androidContext(), get(), get()) }
}

private val appDownloadManagerModule = module {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ limitations under the License.
package com.celzero.bravedns.adapter

import android.content.Context
import android.content.res.TypedArray
import android.graphics.drawable.Drawable
import android.util.Log
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -36,6 +34,7 @@ import com.celzero.bravedns.glide.GlideApp
import com.celzero.bravedns.service.FirewallRuleset
import com.celzero.bravedns.ui.ConnTrackerBottomSheetFragment
import com.celzero.bravedns.util.Constants
import com.celzero.bravedns.util.Constants.Companion.TIME_FORMAT_1
import com.celzero.bravedns.util.KnownPorts
import com.celzero.bravedns.util.LoggerConstants.Companion.LOG_TAG_UI
import com.celzero.bravedns.util.Protocol
Expand Down Expand Up @@ -100,7 +99,7 @@ class ConnectionTrackerAdapter(val context: Context) :
}

private fun displayTransactionDetails(connTracker: ConnectionTracker) {
val time = Utilities.convertLongToTime(connTracker.timeStamp)
val time = Utilities.convertLongToTime(connTracker.timeStamp, TIME_FORMAT_1)
b.connectionResponseTime.text = time
b.connectionFlag.text = connTracker.flag
b.connectionIpAddress.text = connTracker.ipAddress
Expand Down Expand Up @@ -139,7 +138,6 @@ class ConnectionTrackerAdapter(val context: Context) :
}

private fun displayFirewallRulesetHint(isBlocked: Boolean, ruleName: String?) {
Log.d(LOG_TAG_UI, "ConnTrack UI issue: $isBlocked, $ruleName")
when {
// hint red when blocked
isBlocked -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CustomSpinnerAdapter(val context: Context, var dataSource: List<String>) :
vh = view.tag as ItemHolder
}
vh.label.text = dataSource[position]
if (position == (appMode.getDNSType().minus(1))) {
if (position == (appMode.getDnsType().minus(1))) {
vh.img.visibility = View.VISIBLE
} else {
vh.img.visibility = View.INVISIBLE
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class DNSCryptEndpointAdapter(private val context: Context, private val appMode:

private fun updateDNSCryptDetails(endpoint: DNSCryptEndpoint, isSelected: Boolean) {
CoroutineScope(Dispatchers.IO).launch {
if (!isSelected && !appMode.isRemoveDnscryptAllowed(endpoint)) {
if (!isSelected && !appMode.canRemoveDnscrypt(endpoint)) {
// Do not unselect the only user-selected dnscrypt endpoint, that is
// when the getConnectedDnsCrypt returns a list of size 1
withContext(Dispatchers.Main) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class DNSCryptRelayEndpointAdapter(private val context: Context, private val app
isSelected: Boolean) {

CoroutineScope(Dispatchers.IO).launch {
if (isSelected && !appMode.isRelaySelectable()) {
if (isSelected && !appMode.isDnscryptRelaySelectable()) {
withContext(Dispatchers.Main) {
Toast.makeText(context,
context.getString(R.string.dns_crypt_relay_error_toast),
Expand All @@ -175,7 +175,7 @@ class DNSCryptRelayEndpointAdapter(private val context: Context, private val app

private fun deleteEndpoint(id: Int) {
CoroutineScope(Dispatchers.IO).launch {
appMode.deleteDnscryptEndpoint(id)
appMode.deleteDnscryptRelayEndpoint(id)
withContext(Dispatchers.Main) {
Toast.makeText(context, R.string.dns_crypt_relay_remove_success,
Toast.LENGTH_SHORT).show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ class DoHEndpointAdapter(private val context: Context, private val persistentSta
b.dohEndpointListUrlExplanation.text = ""
b.dohEndpointListCheckImage.isChecked = endpoint.isSelected
Log.i(LOG_TAG_DNS,
"connected to doh - ${endpoint.dohName} isSelected? - ${endpoint.isSelected}")
"connected to doh: ${endpoint.dohName} isSelected? ${endpoint.isSelected}")
if (endpoint.isSelected) {
val count = persistentState.numberOfRemoteBlocklists
val count = appMode.getRemoteBlocklistCount()
b.dohEndpointListUrlExplanation.text = if (endpoint.isRethinkDnsPlus() && count > 0) {
context.getString(R.string.dns_connected_rethink_plus, count.toString())
} else {
Expand Down Expand Up @@ -209,9 +209,7 @@ class DoHEndpointAdapter(private val context: Context, private val persistentSta
Utilities.showToastUiCentered(context, context.getString(
R.string.info_dialog_url_copy_toast_msg), Toast.LENGTH_SHORT)
}
val alertDialog: AlertDialog = builder.create()
alertDialog.setCancelable(true)
alertDialog.show()
builder.create().show()
}

private fun showDeleteDnsDialog(id: Int) {
Expand All @@ -226,9 +224,7 @@ class DoHEndpointAdapter(private val context: Context, private val persistentSta
builder.setNegativeButton(context.getString(R.string.dns_delete_negative)) { _, _ ->

}
val alertDialog: AlertDialog = builder.create()
alertDialog.setCancelable(true)
alertDialog.show()
builder.create().show()
}

private fun showDohConfigureDialog() {
Expand All @@ -244,9 +240,7 @@ class DoHEndpointAdapter(private val context: Context, private val persistentSta
builder.setNegativeButton(context.getString(R.string.dns_delete_negative)) { _, _ ->
b.dohEndpointListCheckImage.isChecked = false
}
val alertDialog: AlertDialog = builder.create()
alertDialog.setCancelable(true)
alertDialog.show()
builder.create().show()
}

}
Expand Down
Loading