From 6cd41ec27f26155ad603a92b19bcdb19628d116a Mon Sep 17 00:00:00 2001 From: hussainmohd-a Date: Mon, 15 Mar 2021 21:07:47 +0530 Subject: [PATCH] Build flavors instead of download source https://github.com/celzero/rethink-app/issues/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. --- app/build.gradle | 23 +++++--- .../celzero/bravedns/ui/HomeScreenActivity.kt | 59 +++++++++++-------- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 9 ++- 4 files changed, 57 insertions(+), 36 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 307d63d33..f5640331b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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" } @@ -52,7 +52,6 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } - } flavorDimensions "releaseChannel" productFlavors { @@ -62,6 +61,9 @@ android { fdroid { dimension "releaseChannel" } + website { + dimension "releaseChannel" + } } kotlinOptions { jvmTarget = '1.8' @@ -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" @@ -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" @@ -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' @@ -145,4 +147,7 @@ dependencies { //Tun2socks implementation 'com.github.celzero:firestack:f78e9b50a1' + + //Work manager + implementation 'android.arch.work:work-runtime-ktx:1.0.1' } diff --git a/app/src/main/java/com/celzero/bravedns/ui/HomeScreenActivity.kt b/app/src/main/java/com/celzero/bravedns/ui/HomeScreenActivity.kt index 34f90a5b8..904804e96 100644 --- a/app/src/main/java/com/celzero/bravedns/ui/HomeScreenActivity.kt +++ b/app/src/main/java/com/celzero/bravedns/ui/HomeScreenActivity.kt @@ -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 @@ -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 @@ -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 @@ -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 = MutableLiveData() + var blockedCount: MutableLiveData = MutableLiveData() var lifeTimeQ : MutableLiveData = MutableLiveData() var braveModeToggler : MutableLiveData = MutableLiveData() @@ -107,7 +106,7 @@ class HomeScreenActivity : AppCompatActivity(R.layout.activity_home_screen) { var appStartTime: Long = System.currentTimeMillis() var isBackgroundEnabled: Boolean = false var firewallRules: HashMultimap = 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 @@ -115,10 +114,6 @@ class HomeScreenActivity : AppCompatActivity(R.layout.activity_home_screen) { //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 = MutableLiveData() - //Remove the usage of below variable(isSearchEnabled) var isSearchEnabled : Boolean = true @@ -155,6 +150,7 @@ class HomeScreenActivity : AppCompatActivity(R.layout.activity_home_screen) { GlobalVariable.connectedDNS.postValue(Constants.RETHINK_DNS) launchOnBoardingActivity() updateNewVersion() + updateInstallSource() }else{ showNewFeaturesDialog() } @@ -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() { @@ -211,18 +219,18 @@ 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) } } @@ -230,7 +238,8 @@ class HomeScreenActivity : AppCompatActivity(R.layout.activity_home_screen) { 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) @@ -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().checkForAppUpdate(userInitiation, this, installStateUpdatedListener) // Always web updater } } @@ -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() } diff --git a/build.gradle b/build.gradle index c647a4443..db1f6349d 100644 --- a/build.gradle +++ b/build.gradle @@ -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() diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41b0269ac..725313803 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 \ No newline at end of file