Skip to content

Commit

Permalink
Build flavors instead of download source
Browse files Browse the repository at this point in the history
#210

Check for application update was using download source - play
update and others. Now post fdroid release the app update
check should happen for apps which are downloaded from
playstore and website. So the the download source checks are
modified to build flavor check.
https://f-droid.org/en/docs/Release_Channels_and_Signing_Keys/

PLAY, FDROID and WEBSITE flavors.
Local blocklist will be available for the website and fdroid flavors.

application dependencies are updated to the suggested latest
version.
  • Loading branch information
hussainmohd-a committed Mar 15, 2021
1 parent e210771 commit 6cd41ec
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 36 deletions.
23 changes: 14 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ android {
applicationId "com.celzero.bravedns"
minSdkVersion 23
targetSdkVersion 30
versionCode 13 // For version name 053b
versionName "0.5.3b"
versionCode 14 // For version name 053c
versionName "0.5.3c"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -52,7 +52,6 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

}
flavorDimensions "releaseChannel"
productFlavors {
Expand All @@ -62,6 +61,9 @@ android {
fdroid {
dimension "releaseChannel"
}
website {
dimension "releaseChannel"
}
}
kotlinOptions {
jvmTarget = '1.8'
Expand All @@ -73,7 +75,7 @@ android {
}

dependencies {
androidTestImplementation 'androidx.test:rules:1.3.0-beta01'
androidTestImplementation 'androidx.test:rules:1.4.0-alpha04'
def koin_version = '2.2.2'
def room_version = "2.2.6"
def paging_version = "2.1.2"
Expand All @@ -82,7 +84,7 @@ dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.3.0-beta01'
implementation 'androidx.core:core-ktx:1.5.0-beta01'
implementation 'androidx.core:core-ktx:1.5.0-beta02'
implementation("androidx.preference:preference-ktx:1.1.1")
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "com.mikepenz:fastadapter:5.0.0-a04"
Expand All @@ -104,20 +106,20 @@ dependencies {
implementation "androidx.room:room-ktx:$room_version"

implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0'

// https://mvnrepository.com/artifact/org.jsoup/jsoup
implementation group: 'org.jsoup', name: 'jsoup', version: '1.8.3'

//For paging - connection tracker
implementation "androidx.paging:paging-runtime-ktx:$paging_version"
implementation "androidx.fragment:fragment-ktx:1.2.5"
implementation "com.google.android.material:material:1.3.0-rc01"
implementation "androidx.fragment:fragment-ktx:1.3.0"
implementation "com.google.android.material:material:1.4.0-alpha01"
implementation "androidx.viewpager2:viewpager2:1.1.0-alpha01"


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

//Glide implementation
implementation 'com.github.bumptech.glide:glide:4.11.0'
Expand Down Expand Up @@ -145,4 +147,7 @@ dependencies {

//Tun2socks
implementation 'com.github.celzero:firestack:f78e9b50a1'

//Work manager
implementation 'android.arch.work:work-runtime-ktx:1.0.1'
}
59 changes: 34 additions & 25 deletions app/src/main/java/com/celzero/bravedns/ui/HomeScreenActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package com.celzero.bravedns.ui

import android.app.DownloadManager
import android.content.*
import android.content.pm.ApplicationInfo
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.content.res.Configuration
Expand All @@ -35,6 +34,7 @@ import androidx.core.content.ContextCompat
import androidx.core.net.toUri
import androidx.lifecycle.MutableLiveData
import by.kirich1409.viewbindingdelegate.viewBinding
import com.celzero.bravedns.BuildConfig
import com.celzero.bravedns.NonStoreAppUpdater
import com.celzero.bravedns.R
import com.celzero.bravedns.automaton.FirewallRules
Expand All @@ -49,7 +49,7 @@ import com.celzero.bravedns.service.PersistentState
import com.celzero.bravedns.ui.HomeScreenActivity.GlobalVariable.DEBUG
import com.celzero.bravedns.ui.HomeScreenActivity.GlobalVariable.appMode
import com.celzero.bravedns.util.*
import com.celzero.bravedns.util.Constants.Companion.DOWNLOAD_SOURCE_OTHERS
import com.celzero.bravedns.util.Constants.Companion.DOWNLOAD_SOURCE_PLAY_STORE
import com.celzero.bravedns.util.Constants.Companion.LOG_TAG
import com.celzero.bravedns.util.HttpRequestHelper.Companion.checkStatus
import com.google.android.material.bottomnavigation.BottomNavigationView
Expand Down Expand Up @@ -96,8 +96,7 @@ class HomeScreenActivity : AppCompatActivity(R.layout.activity_home_screen) {
var appMode: AppMode? = null
var filesDownloaded: Int = 0
var lifeTimeQueries: Int = -1
var medianP90: Long = -1
var median50: MutableLiveData<Long> = MutableLiveData()

var blockedCount: MutableLiveData<Int> = MutableLiveData()
var lifeTimeQ : MutableLiveData<Int> = MutableLiveData()
var braveModeToggler : MutableLiveData<Int> = MutableLiveData()
Expand All @@ -107,18 +106,14 @@ class HomeScreenActivity : AppCompatActivity(R.layout.activity_home_screen) {
var appStartTime: Long = System.currentTimeMillis()
var isBackgroundEnabled: Boolean = false
var firewallRules: HashMultimap<Int, String> = HashMultimap.create()
var DEBUG = false
var DEBUG = true

//Screen off - whether the screen preference is set 0-off, 1- on. -1 not initialized
var isScreenLockedSetting: Int = -1

//Screen off state - set - 0 if screen is off, 1 - screen is on, -1 not initialized.
var isScreenLocked : Int = -1

//Local blocklist download complete listener
// 0 - Not initiated, 1 - initiated, 2 - success, -1 - failure
var localDownloadStatus : MutableLiveData<Int> = MutableLiveData()

//Remove the usage of below variable(isSearchEnabled)
var isSearchEnabled : Boolean = true

Expand Down Expand Up @@ -155,6 +150,7 @@ class HomeScreenActivity : AppCompatActivity(R.layout.activity_home_screen) {
GlobalVariable.connectedDNS.postValue(Constants.RETHINK_DNS)
launchOnBoardingActivity()
updateNewVersion()
updateInstallSource()
}else{
showNewFeaturesDialog()
}
Expand Down Expand Up @@ -184,16 +180,28 @@ class HomeScreenActivity : AppCompatActivity(R.layout.activity_home_screen) {
}

persistentState.setScreenLockData(false)
updateInstallSource()
initUpdateCheck()

backgroundAccessibilityCheck()

}

private fun backgroundAccessibilityCheck() {
if (Utilities.isAccessibilityServiceEnabledEnhanced(this, BackgroundAccessibilityService::class.java)) {
if (!Utilities.isAccessibilityServiceEnabled(this, BackgroundAccessibilityService::class.java) && persistentState.backgroundEnabled) {
persistentState.backgroundEnabled = false
persistentState.isAccessibilityCrashDetected = true
}
}
}

private fun updateForLocalDownload(){
private fun updateForDownload(){
persistentState.blockListFilesDownloaded = false
persistentState.numberOfLocalBlocklists = 0
persistentState.localBlocklistEnabled = false
persistentState.localBlockListDownloadTime = 0
persistentState.remoteBraveDNSDownloaded = false
persistentState.remoteBlockListDownloadTime = 0
}

private fun updateNewVersion() {
Expand All @@ -211,26 +219,27 @@ class HomeScreenActivity : AppCompatActivity(R.layout.activity_home_screen) {
}

private fun updateInstallSource() {
val packageManager = packageManager
try {
val applicationInfo: ApplicationInfo = packageManager.getApplicationInfo(packageName, 0)
if (DEBUG) Log.d(LOG_TAG, "Install location: ${packageManager.getInstallerPackageName(applicationInfo.packageName)}")
if ("com.android.vending" == packageManager.getInstallerPackageName(applicationInfo.packageName)) {
// App was installed by Play Store
persistentState.downloadSource = Constants.DOWNLOAD_SOURCE_PLAY_STORE
} else {
// App was installed from somewhere else
persistentState.downloadSource = DOWNLOAD_SOURCE_OTHERS
when(BuildConfig.FLAVOR){
Constants.FLAVOR_PLAY -> {
persistentState.downloadSource = DOWNLOAD_SOURCE_PLAY_STORE
} Constants.FLAVOR_FDROID -> {
persistentState.downloadSource = Constants.DOWNLOAD_SOURCE_FDROID
} else -> {
persistentState.downloadSource = Constants.DOWNLOAD_SOURCE_WEBSITE
}
}
} catch (e: PackageManager.NameNotFoundException) {

} catch (e: java.lang.Exception) {
Log.e(LOG_TAG, "Exception while fetching the app download source: ${e.message}", e)
}
}


private fun showNewFeaturesDialog() {
if (checkToShowNewFeatures()) {
updateForLocalDownload()
updateInstallSource()
updateForDownload()
val inflater: LayoutInflater = LayoutInflater.from(this)
val view: View = inflater.inflate(R.layout.dialog_whatsnew, null)
val builder = AlertDialog.Builder(this)
Expand Down Expand Up @@ -287,9 +296,9 @@ class HomeScreenActivity : AppCompatActivity(R.layout.activity_home_screen) {
}

fun checkForUpdate(userInitiation: Boolean = false) {
if (persistentState.downloadSource == Constants.DOWNLOAD_SOURCE_PLAY_STORE) {
if (BuildConfig.FLAVOR == Constants.FLAVOR_PLAY) {
appUpdateManager.checkForAppUpdate(userInitiation, this, installStateUpdatedListener) // Might be play updater or web updater
} else {
} else if(BuildConfig.FLAVOR == Constants.FLAVOR_WEBSITE){
get<NonStoreAppUpdater>().checkForAppUpdate(userInitiation, this, installStateUpdatedListener) // Always web updater
}
}
Expand Down Expand Up @@ -383,7 +392,7 @@ class HomeScreenActivity : AppCompatActivity(R.layout.activity_home_screen) {
Log.i(LOG_TAG, "Server response for the new version download is $updateValue, response version number- $responseVersion, timestamp- $timeStamp")
if (responseVersion == 1) {
if (updateValue) {
if (persistentState.downloadSource == DOWNLOAD_SOURCE_OTHERS) {
if (persistentState.downloadSource != DOWNLOAD_SOURCE_PLAY_STORE) {
(context as HomeScreenActivity).runOnUiThread {
popupSnackBarForBlocklistUpdate()
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.21'
ext.kotlin_version = '1.4.31'
repositories {
google()
jcenter()
Expand Down
9 changes: 8 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#Sat Oct 17 13:45:19 IST 2020
#Thu Mar 11 20:31:16 IST 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
#Below distributionSha256Sum is added for the issue#210 -FDriod build.
#https://docs.gradle.org/current/userguide/gradle_wrapper.html#sec:verification
#https://gitlab.com/fdroid/rfp/-/issues/1552
#https://github.com/celzero/rethink-app/issues/210
#App freezes if the checksum verification is failed.
#https://github.com/gradle/gradle/issues/9361
distributionSha256Sum=381dff8aa434499aa93bc25572b049c8c586a67faff2c02f375e4f23e17e49de

0 comments on commit 6cd41ec

Please sign in to comment.