Add shortcut for tether offload

Fix #41.
This commit is contained in:
Mygod
2019-07-11 11:09:24 +08:00
parent 07ce4f4e25
commit 9a69c4006e
8 changed files with 66 additions and 14 deletions

View File

@@ -98,8 +98,6 @@ Search the [issue tracker](https://github.com/Mygod/VPNHotspot/issues) for more.
### [What changes exactly can this app do to my system? (and how to revert them)](https://github.com/Mygod/VPNHotspot/issues/8#issuecomment-448529512)
### [Unable to find "Tethering hardware acceleration" in Developer options?](https://github.com/Mygod/VPNHotspot/issues/41#issuecomment-425732001)
### [No root?](https://github.com/Mygod/VPNHotspot/issues/62)
### Failed to create group due to internal error/repeater shuts down after a while?

View File

@@ -10,6 +10,7 @@ import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.net.Routing.Companion.IPTABLES
import be.mygod.vpnhotspot.net.TetherOffloadManager
import be.mygod.vpnhotspot.net.monitor.IpMonitor
import be.mygod.vpnhotspot.net.monitor.UpstreamMonitor
import be.mygod.vpnhotspot.net.wifi.WifiDoubleLock
@@ -17,6 +18,7 @@ import be.mygod.vpnhotspot.preference.AlwaysAutoCompleteEditTextPreferenceDialog
import be.mygod.vpnhotspot.preference.SharedPreferenceDataStore
import be.mygod.vpnhotspot.util.RootSession
import be.mygod.vpnhotspot.util.launchUrl
import be.mygod.vpnhotspot.widget.SmartSnackbar
import com.google.android.material.snackbar.Snackbar
import timber.log.Timber
import java.io.File
@@ -32,6 +34,21 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
preferenceManager.preferenceDataStore = SharedPreferenceDataStore(app.pref)
RoutingManager.masqueradeMode = RoutingManager.masqueradeMode // flush default value
addPreferencesFromResource(R.xml.pref_settings)
findPreference<SwitchPreference>("system.enableTetherOffload")!!.apply {
if (Build.VERSION.SDK_INT >= 27) {
isChecked = TetherOffloadManager.enabled
setOnPreferenceChangeListener { _, newValue ->
try {
TetherOffloadManager.enabled = newValue as Boolean
TetherOffloadManager.enabled == newValue
} catch (e: Exception) {
Timber.d(e)
SmartSnackbar.make(e).show()
false
}
}
} else parent!!.removePreference(this)
}
val boot = findPreference<SwitchPreference>("service.repeater.startOnBoot")!!
if (RepeaterService.supported) {
boot.setOnPreferenceChangeListener { _, value ->

View File

@@ -3,14 +3,13 @@ package be.mygod.vpnhotspot.manage
import android.content.Context
import android.content.Intent
import android.os.Build
import android.provider.Settings
import android.view.View
import androidx.core.os.bundleOf
import androidx.databinding.BaseObservable
import androidx.recyclerview.widget.RecyclerView
import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.DebugHelper
import be.mygod.vpnhotspot.databinding.ListitemManageBinding
import be.mygod.vpnhotspot.net.TetherOffloadManager
object ManageBar : Manager() {
private const val TAG = "ManageBar"
@@ -19,16 +18,7 @@ object ManageBar : Manager() {
private const val SETTINGS_2 = "com.android.settings.TetherSettings"
object Data : BaseObservable() {
/**
* It's hard to change tethering rules with Tethering hardware acceleration enabled for now.
*
* See also:
* android.provider.Settings.Global.TETHER_OFFLOAD_DISABLED
* 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
*/
val offloadEnabled get() = Build.VERSION.SDK_INT >= 27 && Settings.Global.getInt(app.contentResolver,
"tether_offload_disabled", 0) == 0
val offloadEnabled get() = Build.VERSION.SDK_INT >= 27 && TetherOffloadManager.enabled
}
class ViewHolder(binding: ListitemManageBinding) : RecyclerView.ViewHolder(binding.root), View.OnClickListener {
init {

View File

@@ -0,0 +1,27 @@
package be.mygod.vpnhotspot.net
import android.provider.Settings
import androidx.annotation.RequiresApi
import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.util.RootSession
/**
* It's hard to change tethering rules with Tethering hardware acceleration enabled for now.
*
* See also:
* android.provider.Settings.Global.TETHER_OFFLOAD_DISABLED
* 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 {
private const val TETHER_OFFLOAD_DISABLED = "tether_offload_disabled"
@JvmStatic
var enabled: Boolean
get() = Settings.Global.getInt(app.contentResolver, TETHER_OFFLOAD_DISABLED, 0) == 0
set(value) {
RootSession.use {
it.exec("settings put global $TETHER_OFFLOAD_DISABLED ${if (value) 0 else 1}")
}
}
}

View File

@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#FF000000"
android:pathData="M15.67,4H14V2h-4v2H8.33C7.6,4 7,4.6 7,5.33v15.33C7,21.4 7.6,22 8.33,22h7.33c0.74,0 1.34,-0.6 1.34,-1.33V5.33C17,4.6 16.4,4 15.67,4zM11,20v-5.5H9L13,7v5.5h2L11,20z"/>
</vector>

View File

@@ -103,6 +103,8 @@
<string name="settings_service_clean_summary">将修改的设置应用到当前启用的服务上。也可用于修复偶尔会发生的竞态条件。</string>
<string name="settings_service_dhcp_workaround">尝试修复 DHCP</string>
<string name="settings_service_dhcp_workaround_summary">如果设备无法获取 IP 地址,尝试打开这个选项。</string>
<string name="settings_system_tether_offload">网络共享硬件加速</string>
<string name="settings_system_tether_offload_summary">系统“开发者选项”的快捷方式</string>
<string name="settings_misc">杂项</string>
<string name="settings_help">帮助</string>
<string name="settings_misc_logcat">导出调试信息</string>

View File

@@ -109,6 +109,8 @@
<string name="settings_service_clean">Clean/reapply routing rules</string>
<string name="settings_service_clean_summary">Update changed settings to current active services. Can also fix rare
race conditions.</string>
<string name="settings_system_tether_offload">Tethering hardware acceleration</string>
<string name="settings_system_tether_offload_summary">Shortcut to system developer options</string>
<string name="settings_misc">Misc</string>
<string name="settings_help">Help</string>
<string name="settings_misc_logcat">Export debug information</string>

View File

@@ -28,6 +28,12 @@
app:title="@string/settings_service_disable_ipv6"
app:summary="@string/settings_service_disable_ipv6_summary"
app:defaultValue="true"/>
<SwitchPreference
app:key="system.enableTetherOffload"
app:persistent="false"
app:icon="@drawable/ic_device_battery_charging_full"
app:title="@string/settings_system_tether_offload"
app:summary="@string/settings_system_tether_offload_summary"/>
<SwitchPreference
app:key="service.dhcpWorkaround"
app:icon="@drawable/ic_action_build"