Skip to content

Commit

Permalink
Bug fixes - Firewall progressbar, Screenlock service stop
Browse files Browse the repository at this point in the history
*Firewall progressbar
   *Removed the illustrations_loading_svg file and replaced it with the progressbar.
*Screenlock service
   *Screenlock service is started when the device receives SCREEN_LOCK event, the service is stopped once the automatically lock by android smartlock criteria is met.

#29

Former-commit-id: af7ac30
  • Loading branch information
hussainmohd-a committed Aug 15, 2020
1 parent cc6a699 commit 052bee1
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 729 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
</service>

<service
android:name=".receiver.ScreenLockService"
android:name=".receiver.DeviceLockService"
android:enabled="true"
android:exported="false"
android:stopWithTask="false">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.content.pm.PackageManager
import android.util.Log
import com.celzero.bravedns.database.AppDatabase
import com.celzero.bravedns.database.AppInfo
import com.celzero.bravedns.service.BraveVPNService
import com.celzero.bravedns.service.PersistentState
import com.celzero.bravedns.ui.ApplicationManagerActivity
import com.celzero.bravedns.ui.HomeScreenActivity
Expand All @@ -21,9 +20,9 @@ class BraveScreenStateReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (intent!!.action.equals(Intent.ACTION_SCREEN_OFF)) {
if(PersistentState.getFirewallModeForScreenState(context!!) && !PersistentState.getScreenLockData(context)) {
val newIntent = Intent(context, ScreenLockService::class.java)
newIntent.action = ScreenLockService.ACTION_CHECK_LOCK
newIntent.putExtra(ScreenLockService.EXTRA_STATE, intent.action)
val newIntent = Intent(context, DeviceLockService::class.java)
newIntent.action = DeviceLockService.ACTION_CHECK_LOCK
newIntent.putExtra(DeviceLockService.EXTRA_STATE, intent.action)
context.startService(newIntent)
}
} else if (intent.action.equals(Intent.ACTION_USER_PRESENT)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@ package com.celzero.bravedns.receiver

import android.app.KeyguardManager
import android.app.Service
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.IBinder
import android.os.PowerManager
import android.os.ResultReceiver
import android.util.Log
import com.celzero.bravedns.service.BraveVPNService
import com.celzero.bravedns.service.PersistentState
import kotlinx.coroutines.InternalCoroutinesApi
import java.sql.Time
import java.util.*



class ScreenLockService : Service(){
class DeviceLockService : Service(){

private val timer = Timer()
private var checkLockTask: CheckLockTask? = null
Expand All @@ -26,15 +20,13 @@ class ScreenLockService : Service(){
return null
}

@InternalCoroutinesApi
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if(intent != null && intent.action == ACTION_CHECK_LOCK){
checkLock(intent)
}
return super.onStartCommand(intent, flags, startId)
}

@InternalCoroutinesApi
private fun checkLock(intent: Intent) {
val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
Expand All @@ -56,14 +48,17 @@ class ScreenLockService : Service(){
checkLockTask = CheckLockTask(this, delayIndex)
/*Log.i("BraveDNS", java.lang.String.format("LM.checkLock: scheduling CheckLockTask[%x] for %d ms",
System.identityHashCode(checkLockTask), checkLockDelays.get(delayIndex)))*/
val task = CheckLockTask(this , checkLockDelays.get(delayIndex))
timer.schedule(task, checkLockDelays.get(delayIndex).toLong())
//val task = CheckLockTask(this , checkLockDelays.get(delayIndex))
timer.schedule(checkLockTask, checkLockDelays.get(delayIndex).toLong())
this.stopSelf()
} else {
//Log.d("BraveDNS", "LM.checkLock: no need to schedule CheckLockTask")
if (isProtected && isLocked) {
//Log.e("BraveDNS", "Block Traffic Now!")
if(PersistentState.getFirewallModeForScreenState(this) && !PersistentState.getScreenLockData(this)) {
PersistentState.setScreenLockData(this,true)
checkLockTask?.cancel()
timer.cancel()
this.stopSelf()
}
}
}
Expand Down Expand Up @@ -108,7 +103,7 @@ class ScreenLockService : Service(){

class CheckLockTask(val context: Context, val delayIndex: Int) : TimerTask() {
override fun run() {
val newIntent = Intent(context, ScreenLockService::class.java)
val newIntent = Intent(context, DeviceLockService::class.java)
newIntent.action = ACTION_CHECK_LOCK
newIntent.putExtra(EXTRA_CHECK_LOCK_DELAY_INDEX, getSafeCheckLockDelay(delayIndex + 1))
context.startService(newIntent)
Expand Down
16 changes: 7 additions & 9 deletions app/src/main/java/com/celzero/bravedns/ui/FirewallActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import android.content.Intent
import android.os.Bundle
import android.provider.Settings
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.*
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView
Expand Down Expand Up @@ -50,7 +47,7 @@ class FirewallActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
lateinit var itemAdapter: ItemAdapter<FirewallApk>
lateinit var headerAdapter : ItemAdapter<FirewallHeader>
private lateinit var progressImageView: ImageView
private lateinit var loadingProgressBar: ContentLoadingProgressBar
private lateinit var loadingProgressBar: ProgressBar

private lateinit var firewallAllAppsToggle : SwitchCompat
private lateinit var firewallAllAppsTxt : TextView
Expand Down Expand Up @@ -116,7 +113,7 @@ class FirewallActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
}else{
firewallNotEnabledLL.visibility = View.VISIBLE
firewallEnableTxt.visibility = View.GONE
progressImageView.setImageDrawable(getDrawable(R.drawable.ic_illustrations_loading))
//progressImageView.setImageDrawable(getDrawable(R.drawable.ic_illustrations_loading))
}

categoryState = false
Expand Down Expand Up @@ -287,7 +284,8 @@ class FirewallActivity : AppCompatActivity(), SearchView.OnQueryTextListener {


fun updateUI(){
progressBarHolder.visibility = View.VISIBLE
loadingProgressBar.visibility = View.VISIBLE
//progressBarHolder.visibility = View.VISIBLE
itemAdapter = ItemAdapter()
headerAdapter = ItemAdapter()
itemAdapter.clear()
Expand Down Expand Up @@ -366,8 +364,8 @@ class FirewallActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
itemAdapter.add(apkList)
fastAdapter.notifyAdapterDataSetChanged()
fastAdapter.notifyDataSetChanged()

progressBarHolder.visibility = View.GONE
loadingProgressBar.visibility = View.GONE
//progressBarHolder.visibility = View.GONE
}
}

Expand Down
Loading

0 comments on commit 052bee1

Please sign in to comment.