Attempt to detect tether offload support dynamically on Android 8-
Addresses #224.
This commit is contained in:
@@ -48,7 +48,7 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
|
||||
SummaryFallbackProvider(findPreference(UpstreamMonitor.KEY)!!)
|
||||
SummaryFallbackProvider(findPreference(FallbackUpstreamMonitor.KEY)!!)
|
||||
findPreference<SwitchPreference>("system.enableTetherOffload")!!.apply {
|
||||
if (Build.VERSION.SDK_INT >= 27) {
|
||||
if (TetherOffloadManager.supported) {
|
||||
isChecked = TetherOffloadManager.enabled
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
if (TetherOffloadManager.enabled != newValue) viewLifecycleOwner.lifecycleScope.launchWhenCreated {
|
||||
|
||||
@@ -2,7 +2,6 @@ package be.mygod.vpnhotspot.manage
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.view.View
|
||||
import androidx.databinding.BaseObservable
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
@@ -17,7 +16,7 @@ object ManageBar : Manager() {
|
||||
private const val SETTINGS_2 = "com.android.settings.TetherSettings"
|
||||
|
||||
object Data : BaseObservable() {
|
||||
val offloadEnabled get() = Build.VERSION.SDK_INT >= 27 && TetherOffloadManager.enabled
|
||||
val offloadEnabled get() = TetherOffloadManager.supported && TetherOffloadManager.enabled
|
||||
}
|
||||
class ViewHolder(binding: ListitemManageBinding) : RecyclerView.ViewHolder(binding.root), View.OnClickListener {
|
||||
init {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package be.mygod.vpnhotspot.net
|
||||
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
import androidx.annotation.RequiresApi
|
||||
import be.mygod.vpnhotspot.App.Companion.app
|
||||
import be.mygod.vpnhotspot.root.SettingsGlobalPut
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* It's hard to change tethering rules with Tethering hardware acceleration enabled for now.
|
||||
@@ -13,8 +14,11 @@ import be.mygod.vpnhotspot.root.SettingsGlobalPut
|
||||
* https://android.googlesource.com/platform/frameworks/base/+/android-8.1.0_r1/services/core/java/com/android/server/connectivity/tethering/OffloadHardwareInterface.java#45
|
||||
* https://android.googlesource.com/platform/hardware/qcom/data/ipacfg-mgr/+/master/msm8998/ipacm/src/IPACM_OffloadManager.cpp
|
||||
*/
|
||||
@RequiresApi(27)
|
||||
object TetherOffloadManager {
|
||||
val supported by lazy {
|
||||
Build.VERSION.SDK_INT >= 27 || Settings.Global::class.java.getDeclaredField("TETHER_OFFLOAD_DISABLED")
|
||||
.get(null).also { if (it != TETHER_OFFLOAD_DISABLED) Timber.w(Exception("Unknown field $it")) } != null
|
||||
}
|
||||
private const val TETHER_OFFLOAD_DISABLED = "tether_offload_disabled"
|
||||
val enabled get() = Settings.Global.getInt(app.contentResolver, TETHER_OFFLOAD_DISABLED, 0) == 0
|
||||
suspend fun setEnabled(value: Boolean) = SettingsGlobalPut.int(TETHER_OFFLOAD_DISABLED, if (value) 0 else 1)
|
||||
|
||||
Reference in New Issue
Block a user