Skip to content

Commit

Permalink
Fix bug introduced from #1041 where snowflake proxy wasn't turned off
Browse files Browse the repository at this point in the history
This is because the KindnessFragment never specified that the Intents it sends to OrbotService
weren't system intents... Fixed this here.

Also made global extension function for things like putNotSystem() so each fragment, activity, etc
doesn't need to locally define that extension function...
  • Loading branch information
bitmold committed Jan 25, 2024
1 parent 75f3913 commit a9c6c39
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 184 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/org/torproject/android/ConnectFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.text.Html
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -24,6 +23,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import net.freehaven.tor.control.TorControlCommands
import org.torproject.android.core.putNotSystem
import org.torproject.android.service.OrbotConstants
import org.torproject.android.service.OrbotService
import org.torproject.android.service.util.Prefs
Expand Down Expand Up @@ -365,14 +365,14 @@ class ConnectFragment : Fragment(), ConnectionHelperCallbacks,
refreshMenuList(requireContext())
}

private fun Intent.putNotSystem(): Intent = this.putExtra(OrbotConstants.EXTRA_NOT_SYSTEM, true)

/** Sends intent to service, first modifying it to indicate it is not from the system */
private fun sendIntentToService(intent: Intent) =
ContextCompat.startForegroundService(requireActivity(), intent.putNotSystem())

private fun sendIntentToService(action: String) =
private fun sendIntentToService(action: String) {
sendIntentToService(Intent(requireActivity(), OrbotService::class.java).apply {
this.action = action
})
}
}
28 changes: 8 additions & 20 deletions app/src/main/java/org/torproject/android/KindnessFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import android.widget.Button
import android.widget.TextView
import androidx.appcompat.widget.SwitchCompat
import androidx.core.content.ContextCompat
import org.torproject.android.core.putNotSystem
import org.torproject.android.service.OrbotConstants
import org.torproject.android.service.OrbotService
import org.torproject.android.service.util.Prefs

class KindnessFragment : Fragment() {
Expand All @@ -28,10 +28,10 @@ class KindnessFragment : Fragment() {
): View? {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_kindness, container, false)
tvAlltimeTotal = view.findViewById<TextView>(R.id.tvAlltimeTotal)
tvWeeklyTotal = view.findViewById<TextView>(R.id.tvWeeklyTotal)
swVolunteerMode = view.findViewById<SwitchCompat>(R.id.swVolunteerMode)
btnActionActivate = view.findViewById<Button>(R.id.btnActionActivate)
tvAlltimeTotal = view.findViewById(R.id.tvAlltimeTotal)
tvWeeklyTotal = view.findViewById(R.id.tvWeeklyTotal)
swVolunteerMode = view.findViewById(R.id.swVolunteerMode)
btnActionActivate = view.findViewById(R.id.btnActionActivate)
pnlActivate = view.findViewById(R.id.panel_kindness_activate)
pnlStatus = view.findViewById(R.id.panel_kindness_status)
tvAlltimeTotal.text = Prefs.getSnowflakesServed().toString()
Expand All @@ -41,25 +41,16 @@ class KindnessFragment : Fragment() {
swVolunteerMode.setOnCheckedChangeListener { _, isChecked ->
Prefs.setBeSnowflakeProxy(isChecked)
showPanelStatus(isChecked)
sendIntentToService(
Intent(
requireActivity(),
OrbotService::class.java
).setAction(OrbotConstants.CMD_SNOWFLAKE_PROXY)
)
sendIntentToService(OrbotConstants.CMD_SNOWFLAKE_PROXY)
}

view.findViewById<TextView>(R.id.swVolunteerAdjust).setOnClickListener {

KindessConfigBottomSheet().show(
requireActivity().supportFragmentManager, CustomBridgeBottomSheet.TAG
)

}

btnActionActivate.setOnClickListener {
// Prefs.setBeSnowflakeProxy(true)
// showPanelStatus(true)
swVolunteerMode.isChecked = true
Prefs.setBeSnowflakeProxy(true)
sendIntentToService(OrbotConstants.CMD_ACTIVE)
Expand All @@ -71,7 +62,7 @@ class KindnessFragment : Fragment() {
}

private fun sendIntentToService(intent: Intent) =
ContextCompat.startForegroundService(requireContext(), intent)
ContextCompat.startForegroundService(requireContext(), intent.putNotSystem())

private fun sendIntentToService(action: String) = sendIntentToService(Intent(
requireContext(), org.torproject.android.service.OrbotService::class.java
Expand All @@ -97,10 +88,7 @@ class KindnessFragment : Fragment() {

} else {
pnlActivate.visibility = View.VISIBLE
pnlActivate.animate().alpha(1f).setDuration(duration).withEndAction {

}

pnlActivate.animate().alpha(1f).setDuration(duration).withEndAction {}

pnlStatus.animate().alpha(0f).setDuration(duration).withEndAction {
pnlStatus.visibility = View.GONE
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/org/torproject/android/OrbotActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.navigation.ui.setupWithNavController
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.scottyab.rootbeer.RootBeer
import org.torproject.android.core.LocaleHelper
import org.torproject.android.core.putNotSystem
import org.torproject.android.core.ui.BaseActivity
import org.torproject.android.service.OrbotConstants
import org.torproject.android.service.util.Prefs
Expand Down Expand Up @@ -146,8 +147,6 @@ class OrbotActivity : BaseActivity() {
}


private fun Intent.putNotSystem(): Intent = this.putExtra(OrbotConstants.EXTRA_NOT_SYSTEM, true)

/** Sends intent to service, first modifying it to indicate it is not from the system */
private fun sendIntentToService(intent: Intent) =
ContextCompat.startForegroundService(this, intent.putNotSystem())
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/org/torproject/android/OrbotApp.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.torproject.android

import android.app.Application
import android.content.Intent
import android.content.res.Configuration
import org.torproject.android.core.Languages
import org.torproject.android.core.LocaleHelper
Expand All @@ -11,6 +12,7 @@ import java.util.Locale

class OrbotApp : Application(), OrbotConstants {


override fun onCreate() {
super.onCreate()

Expand Down
Loading

0 comments on commit a9c6c39

Please sign in to comment.