Skip to content

Commit

Permalink
Merge pull request #1232 from hussainmohd-a/v055b
Browse files Browse the repository at this point in the history
v055b: Finalized Changes
  • Loading branch information
hussainmohd-a authored Mar 2, 2024
2 parents 1db9675 + 2b5db61 commit b426d8d
Show file tree
Hide file tree
Showing 190 changed files with 3,149 additions and 2,435 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4
- name: set up JDK
uses: actions/setup-java@v3
with:
Expand All @@ -23,5 +24,5 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
if: ${{ vars.VARIANT }}
run: ./gradlew ${{ vars.VARIANT }}
if: success()
run: ./gradlew assembleWebsiteFullAlpha --info --warning-mode all
10 changes: 8 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Monthly debug
name: Monthly alpha

on:
workflow_dispatch: # to be able to run it manually
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Build & notify
if: env.TELEGRAM_CHAT_ID && env.SCHEDULED_BUILD_VARIANT && env.TELEGRAM_TOKEN
run: |
./gradlew ${SCHEDULED_BUILD_VARIANT} -v
./gradlew ${SCHEDULED_BUILD_VARIANT} --info --warning-mode all
env:
ALPHA_KS_ALIAS: ${{ vars.ALPHA_KS_ALIAS }}
ALPHA_KS_FILE: ${{ vars.ALPHA_KS_FILE }}
Expand All @@ -56,6 +56,12 @@ jobs:
VERSION_CODE: ${{ github.run_number }}
# version-code: archive.is/y8uCB

- name: Grab APK
run: |
apk_path="$(find . -type f -iname '*.apk' | head -n1)"
echo $apk_path
echo "APKFILE=${apk_path}" >> $GITHUB_ENV
# github.com/actions/upload-artifact
- name: Artifact
uses: actions/upload-artifact@v3
Expand Down
27 changes: 23 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ def gitVersion = providers.exec {
commandLine("git", "describe", "--tags", "--always")
}.standardOutput.asText.get().toString().trim()

// for github builds, the version code is set in the github action via env
// for local builds, the version code is set in gradle.properties
def getVersionCode = {
def code = 0
try {
// parseInt throws NumberFormatException if the string does not contain a parsable integer
// but "as Integer" is a wrapper class, which silently returns null
code = Integer.parseInt(System.getenv("VERSION_CODE"))
logger.info("env version code: $code")
} catch (NumberFormatException ex) {
logger.info("missing env version code: $ex.message")
}
if (code == 0) {
code = project.properties['VERSION_CODE'] as Integer
logger.info("project properties version code: $code")
}
return code
}

try {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
} catch (Exception ex) {
Expand Down Expand Up @@ -73,7 +92,6 @@ android {
minifyEnabled true
shrinkResources true
signingConfig signingConfigs.alpha
versionCode System.getenv("VERSION_CODE")
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Expand Down Expand Up @@ -123,7 +141,8 @@ android {
dimension "releaseType"
// getPackageInfo().versionCode not returning the correct value (in prod builds) when
// value is set in AndroidManifest.xml so setting it here
versionCode = Integer.parseInt(System.getenv("VERSION_CODE"))
// for buildtype alpha, versionCode is set in env overriding gradle.properties
versionCode = getVersionCode()
versionName = gitVersion
vectorDrawables.useSupportLibrary = true
}
Expand Down Expand Up @@ -225,8 +244,8 @@ dependencies {
fullImplementation 'com.github.kirich1409:viewbindingpropertydelegate-noreflection:1.5.9'

// from: https://jitpack.io/#celzero/firestack
download 'com.github.celzero:firestack:72eb7e4898@aar'
implementation 'com.github.celzero:firestack:72eb7e4898@aar'
download 'com.github.celzero:firestack:8dc7dafcaa@aar'
implementation 'com.github.celzero:firestack:8dc7dafcaa@aar'

// Work manager
implementation('androidx.work:work-runtime-ktx:2.9.0') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.celzero.bravedns.util.Constants.Companion.JSON_LATEST
import com.celzero.bravedns.util.Constants.Companion.JSON_UPDATE
import com.celzero.bravedns.util.Constants.Companion.JSON_VERSION
import com.celzero.bravedns.util.Constants.Companion.UPDATE_CHECK_RESPONSE_VERSION
import com.celzero.bravedns.util.LoggerConstants.Companion.LOG_TAG_APP_UPDATE
import com.celzero.bravedns.util.Logger.Companion.LOG_TAG_APP_UPDATE
import okhttp3.Call
import okhttp3.Callback
import okhttp3.Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.os.StrictMode
import android.util.Log
import com.celzero.bravedns.scheduler.ScheduleManager
import com.celzero.bravedns.scheduler.WorkScheduler
import com.celzero.bravedns.util.LoggerConstants.Companion.LOG_TAG_SCHEDULER
import com.celzero.bravedns.util.Logger.Companion.LOG_TAG_SCHEDULER
import org.koin.android.ext.android.get
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
Expand Down
16 changes: 11 additions & 5 deletions app/src/full/java/com/celzero/bravedns/adapter/AlertAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
*//*
package com.celzero.bravedns.adapter
import android.content.Context
Expand Down Expand Up @@ -58,15 +59,17 @@ class AlertAdapter(
}
b.title.text = alert.alertTitle
val message = ""
/*when (AlertCategory.valueOf(alert.alertCategory)) {
*/
/*when (AlertCategory.valueOf(alert.alertCategory)) {
AlertCategory.DNS ->
"List of domains blocked in past one hour. Click to <<see more>>..."
AlertCategory.FIREWALL ->
"List of IP addresses blocked in past one hour. Click to <<see more>>..."
AlertCategory.APP ->
"List of apps blocked in past one hour. Click to <<see more>>..."
else -> "Unknown category"
}*/
}*//*
b.description.text = message
b.descriptionMore.text = alert.alertMessage
b.priority.text = alert.alertSeverity.lowercase().replaceFirstChar(Char::uppercase)
Expand Down Expand Up @@ -97,15 +100,17 @@ class AlertAdapter(
private fun showActionDialog(category: AlertCategory) {
// show dialog with actions to be taken on the alert
val message = ""
/*when (category) {
*/
/*when (category) {
AlertCategory.DNS ->
"Some actions to be taken on the alert \n\n 1. Allow the connection \n\n 2. Block the connection \n\n 3. Allow all connections from this domain \n\n 4. Block all connections from this domain"
AlertCategory.FIREWALL ->
"Some actions to be taken on the alert \n\n 1. Allow the connection \n\n 2. Block the connection \n\n 3. Allow this connections for all app \n\n 4. Block this connections for all app"
AlertCategory.APP ->
"Some actions to be taken on the alert \n\n 1. Allow the connection \n\n 2. Block the connection \n\n 3. Allow all connections from this app \n\n 4. Block all connections from this app"
else -> "Unknown category"
}*/
}*//*
MaterialAlertDialogBuilder(context)
.setTitle("Actions")
.setMessage(message)
Expand All @@ -118,3 +123,4 @@ class AlertAdapter(
}
}
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import com.celzero.bravedns.data.AppConnection
import com.celzero.bravedns.databinding.ListItemAppConnDetailsBinding
import com.celzero.bravedns.service.IpRulesManager
import com.celzero.bravedns.ui.bottomsheet.AppConnectionBottomSheet
import com.celzero.bravedns.util.LoggerConstants
import com.celzero.bravedns.util.Logger
import com.celzero.bravedns.util.UIUtils.fetchColor
import com.celzero.bravedns.util.Utilities.removeBeginningTrailingCommas

Expand Down Expand Up @@ -101,7 +101,7 @@ class AppConnectionAdapter(val context: Context, val uid: Int) :

private fun openBottomSheet(appConn: AppConnection) {
if (context !is AppCompatActivity) {
Log.wtf(LoggerConstants.LOG_TAG_UI, "Error opening the app conn bottom sheet")
Log.wtf(Logger.LOG_TAG_UI, "Error opening the app conn bottom sheet")
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import com.celzero.bravedns.service.VpnController
import com.celzero.bravedns.ui.bottomsheet.ConnTrackerBottomSheet
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.Logger.Companion.LOG_TAG_UI
import com.celzero.bravedns.util.Protocol
import com.celzero.bravedns.util.UIUtils.getDurationInHumanReadableFormat
import com.celzero.bravedns.util.Utilities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import com.celzero.bravedns.service.DomainRulesManager.isWildCardEntry
import com.celzero.bravedns.service.FirewallManager
import com.celzero.bravedns.ui.activity.CustomRulesActivity
import com.celzero.bravedns.util.Constants
import com.celzero.bravedns.util.LoggerConstants
import com.celzero.bravedns.util.Logger
import com.celzero.bravedns.util.UIUtils.fetchColor
import com.celzero.bravedns.util.UIUtils.fetchToggleBtnColors
import com.celzero.bravedns.util.Utilities
Expand Down Expand Up @@ -111,7 +111,7 @@ class CustomDomainAdapter(val context: Context, val rule: CustomRulesActivity.RU
} else if (holder is CustomDomainViewHolderWithoutHeader) {
holder.update(customDomain)
} else {
Log.w(LoggerConstants.LOG_TAG_UI, "unknown view holder in CustomDomainRulesAdapter")
Log.w(Logger.LOG_TAG_UI, "unknown view holder in CustomDomainRulesAdapter")
return
}
}
Expand Down Expand Up @@ -496,6 +496,11 @@ class CustomDomainAdapter(val context: Context, val rule: CustomRulesActivity.RU
}

if (isChecked) {
// See CustomIpAdapter.kt for the same code (ipRulesGroupListener)
val hasStatusChanged = customDomain.status != statusId.id
if (!hasStatusChanged) {
return@OnButtonCheckedListener
}
val t = toggleBtnUi(statusId)
// update toggle button
selectToggleBtnUi(b, t)
Expand Down Expand Up @@ -647,6 +652,11 @@ class CustomDomainAdapter(val context: Context, val rule: CustomRulesActivity.RU
}

if (isChecked) {
// See CustomIpAdapter.kt for the same code (ipRulesGroupListener)
val hasStatusChanged = customDomain.status != statusId.id
if (!hasStatusChanged) {
return@OnButtonCheckedListener
}
val t = toggleBtnUi(statusId)
// update toggle button
selectToggleBtnUi(b, t)
Expand Down
63 changes: 32 additions & 31 deletions app/src/full/java/com/celzero/bravedns/adapter/CustomIpAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import com.celzero.bravedns.service.FirewallManager
import com.celzero.bravedns.service.IpRulesManager
import com.celzero.bravedns.ui.activity.CustomRulesActivity
import com.celzero.bravedns.util.Constants.Companion.UID_EVERYBODY
import com.celzero.bravedns.util.LoggerConstants
import com.celzero.bravedns.util.Logger
import com.celzero.bravedns.util.UIUtils.fetchColor
import com.celzero.bravedns.util.UIUtils.fetchToggleBtnColors
import com.celzero.bravedns.util.Utilities
Expand Down Expand Up @@ -108,7 +108,7 @@ class CustomIpAdapter(private val context: Context, private val type: CustomRule
holder.update(customIp)
}
else -> {
Log.w(LoggerConstants.LOG_TAG_UI, "unknown view holder in CustomDomainRulesAdapter")
Log.w(Logger.LOG_TAG_UI, "unknown view holder in CustomDomainRulesAdapter")
return
}
}
Expand Down Expand Up @@ -355,7 +355,6 @@ class CustomIpAdapter(private val context: Context, private val type: CustomRule
private val ipRulesGroupListener =
MaterialButtonToggleGroup.OnButtonCheckedListener { group, checkedId, isChecked ->
val b: MaterialButton = b.customIpToggleGroup.findViewById(checkedId)

val statusId = findSelectedIpRule(getTag(b.tag))
// delete button
if (statusId == null && isChecked) {
Expand All @@ -370,13 +369,21 @@ class CustomIpAdapter(private val context: Context, private val type: CustomRule
}

if (isChecked) {
val t = getToggleBtnUiParams(statusId)
// update the toggle button
selectToggleBtnUi(b, t)
// update the status in desc and status flag (N/B/BU)
updateStatusUi(statusId)

changeIpStatus(statusId, customIp)
// checked change listener is called multiple times, even for position change
// so, check if the status has changed or not
// also see CustomDomainAdapter#domainRulesGroupListener
val hasStatusChanged = customIp.status != statusId.id
if (hasStatusChanged) {
val t = getToggleBtnUiParams(statusId)
// update the toggle button
selectToggleBtnUi(b, t)
// update the status in desc and status flag (N/B/BU)
updateStatusUi(statusId)

changeIpStatus(statusId, customIp)
} else {
// no-op
}
} else {
unselectToggleBtnUi(b)
}
Expand Down Expand Up @@ -589,13 +596,18 @@ class CustomIpAdapter(private val context: Context, private val type: CustomRule
}

if (isChecked) {
val t = getToggleBtnUiParams(statusId)
// update the toggle button
selectToggleBtnUi(b, t)
// update the status in desc and status flag (N/B/BU)
updateStatusUi(statusId)

changeIpStatus(statusId, customIp)
val hasStatusChanged = customIp.status != statusId.id
if (hasStatusChanged) {
val t = getToggleBtnUiParams(statusId)
// update the toggle button
selectToggleBtnUi(b, t)
// update the status in desc and status flag (N/B/BU)
updateStatusUi(statusId)

changeIpStatus(statusId, customIp)
} else {
// no-op
}
} else {
unselectToggleBtnUi(b)
}
Expand Down Expand Up @@ -748,7 +760,6 @@ class CustomIpAdapter(private val context: Context, private val type: CustomRule

dBind.daciBlockBtn.setOnClickListener {
handleIp(dBind, customIp, IpRulesManager.IpRuleStatus.BLOCK)
dialog.dismiss()
}

dBind.daciTrustBtn.setOnClickListener {
Expand All @@ -757,7 +768,6 @@ class CustomIpAdapter(private val context: Context, private val type: CustomRule
} else {
handleIp(dBind, customIp, IpRulesManager.IpRuleStatus.TRUST)
}
dialog.dismiss()
}

dBind.daciCancelBtn.setOnClickListener { dialog.dismiss() }
Expand Down Expand Up @@ -788,7 +798,7 @@ class CustomIpAdapter(private val context: Context, private val type: CustomRule
return@ui
}

updateCustomIp(customIp, hostName, status)
updateCustomIp(customIp, ipString, status)
}
}

Expand All @@ -805,19 +815,10 @@ class CustomIpAdapter(private val context: Context, private val type: CustomRule

private fun updateCustomIp(
prev: CustomIp,
hostName: HostName?,
ipString: String,
status: IpRulesManager.IpRuleStatus
) {
if (hostName == null) return

val new =
IpRulesManager.makeCustomIp(
prev.uid,
hostName.asAddress().toNormalizedString(),
hostName.port,
status
)
io { IpRulesManager.replaceIpRule(prev, new) }
io { IpRulesManager.replaceIpRule(prev, ipString, status) }
}

private suspend fun ioCtx(f: suspend () -> Unit) {
Expand Down
Loading

0 comments on commit b426d8d

Please sign in to comment.