Ask to disable tethering hardware acceleration on Android 8.1+

This commit is contained in:
Mygod
2018-08-26 15:22:27 +08:00
parent a76fcf8cf7
commit 1c5d7c1109
7 changed files with 79 additions and 28 deletions

View File

@@ -92,6 +92,10 @@ Private system configurations:
Other: Other:
* (since API 27) `android.provider.Settings.Global.TETHER_OFFLOAD_DISABLED` is assumed to be
`"tether_offload_disabled"`.
* (since API 27) `com.android.server.connectivity.tethering.OffloadHardwareInterface.DEFAULT_TETHER_OFFLOAD_DISABLED`
is assumed to be 0.
* Activity `com.android.settings/.Settings$TetherSettingsActivity` is assumed to be exported; * Activity `com.android.settings/.Settings$TetherSettingsActivity` is assumed to be exported;
* Several constants in `ConnectivityManager` is assumed to be defined as in `TetheringManager.kt`; * Several constants in `ConnectivityManager` is assumed to be defined as in `TetheringManager.kt`;
* `android.net.conn.TETHER_STATE_CHANGED` is assumed to be a sticky broadcast. * `android.net.conn.TETHER_STATE_CHANGED` is assumed to be a sticky broadcast.

View File

@@ -3,14 +3,32 @@ package be.mygod.vpnhotspot.manage
import android.content.ActivityNotFoundException import android.content.ActivityNotFoundException
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build
import android.provider.Settings
import android.view.View import android.view.View
import androidx.databinding.BaseObservable
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.databinding.ListitemManageBinding
import com.crashlytics.android.Crashlytics import com.crashlytics.android.Crashlytics
object ManageBar : Manager() { object ManageBar : Manager() {
class ViewHolder(view: View) : RecyclerView.ViewHolder(view), View.OnClickListener { 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
}
class ViewHolder(binding: ListitemManageBinding) : RecyclerView.ViewHolder(binding.root), View.OnClickListener {
init { init {
view.setOnClickListener(this) binding.data = Data
binding.root.setOnClickListener(this)
} }
override fun onClick(v: View?) = start(itemView.context) override fun onClick(v: View?) = start(itemView.context)

View File

@@ -5,8 +5,8 @@ import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import be.mygod.vpnhotspot.R
import be.mygod.vpnhotspot.databinding.ListitemInterfaceBinding import be.mygod.vpnhotspot.databinding.ListitemInterfaceBinding
import be.mygod.vpnhotspot.databinding.ListitemManageBinding
import be.mygod.vpnhotspot.databinding.ListitemRepeaterBinding import be.mygod.vpnhotspot.databinding.ListitemRepeaterBinding
abstract class Manager { abstract class Manager {
@@ -26,7 +26,7 @@ abstract class Manager {
fun createViewHolder(inflater: LayoutInflater, parent: ViewGroup, type: Int) = when (type) { fun createViewHolder(inflater: LayoutInflater, parent: ViewGroup, type: Int) = when (type) {
VIEW_TYPE_INTERFACE -> VIEW_TYPE_INTERFACE ->
InterfaceManager.ViewHolder(ListitemInterfaceBinding.inflate(inflater, parent, false)) InterfaceManager.ViewHolder(ListitemInterfaceBinding.inflate(inflater, parent, false))
VIEW_TYPE_MANAGE -> ManageBar.ViewHolder(inflater.inflate(R.layout.listitem_manage, parent, false)) VIEW_TYPE_MANAGE -> ManageBar.ViewHolder(ListitemManageBinding.inflate(inflater, parent, false))
VIEW_TYPE_WIFI, VIEW_TYPE_USB, VIEW_TYPE_BLUETOOTH, VIEW_TYPE_WIFI_LEGACY -> VIEW_TYPE_WIFI, VIEW_TYPE_USB, VIEW_TYPE_BLUETOOTH, VIEW_TYPE_WIFI_LEGACY ->
TetherManager.ViewHolder(ListitemInterfaceBinding.inflate(inflater, parent, false)) TetherManager.ViewHolder(ListitemInterfaceBinding.inflate(inflater, parent, false))
VIEW_TYPE_LOCAL_ONLY_HOTSPOT -> @TargetApi(26) { VIEW_TYPE_LOCAL_ONLY_HOTSPOT -> @TargetApi(26) {

View File

@@ -104,6 +104,11 @@ class TetheringFragment : Fragment(), ServiceConnection {
return binding.root return binding.root
} }
override fun onResume() {
super.onResume()
if (Build.VERSION.SDK_INT >= 27) ManageBar.Data.notifyChange()
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) { override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
if (requestCode == START_LOCAL_ONLY_HOTSPOT) @TargetApi(26) { if (requestCode == START_LOCAL_ONLY_HOTSPOT) @TargetApi(26) {
if (grantResults.firstOrNull() == PackageManager.PERMISSION_GRANTED) { if (grantResults.firstOrNull() == PackageManager.PERMISSION_GRANTED) {

View File

@@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <layout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<import type="android.view.View"/>
<variable
name="data"
type="be.mygod.vpnhotspot.manage.ManageBar.Data"/>
</data>
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:focusable="true" android:focusable="true"
@@ -18,12 +25,26 @@
android:layout_width="16dp" android:layout_width="16dp"
android:layout_height="0dp"/> android:layout_height="0dp"/>
<TextView <LinearLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead" android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
android:text="@string/tethering_manage"/> android:text="@string/tethering_manage"/>
</LinearLayout> <TextView
android:id="@+id/offloadEnabled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="@{data.offloadEnabled ? View.VISIBLE : View.GONE}"
android:text="@string/tethering_manage_offload_enabled"/>
</LinearLayout>
</LinearLayout>
</layout>

View File

@@ -38,6 +38,7 @@
<string name="tethering_temp_hotspot_failure_tethering_disallowed">共享被禁用</string> <string name="tethering_temp_hotspot_failure_tethering_disallowed">共享被禁用</string>
<string name="tethering_manage">管理系统共享…</string> <string name="tethering_manage">管理系统共享…</string>
<string name="tethering_manage_offload_enabled">若 VPN 共享无法使用,请尝试禁用“开发者选项”中的“网络共享硬件加速”。</string>
<!-- <!--
Values copied from: Values copied from:
* https://android.googlesource.com/platform/packages/apps/Settings/+/7686ef8/res/xml/tether_prefs.xml * https://android.googlesource.com/platform/packages/apps/Settings/+/7686ef8/res/xml/tether_prefs.xml

View File

@@ -49,6 +49,8 @@
<string name="tethering_temp_hotspot_failure_tethering_disallowed">tethering disallowed</string> <string name="tethering_temp_hotspot_failure_tethering_disallowed">tethering disallowed</string>
<string name="tethering_manage">Manage system tethering…</string> <string name="tethering_manage">Manage system tethering…</string>
<string name="tethering_manage_offload_enabled">Please disable Tethering hardware acceleration in Developer options
if VPN tethering does not work.</string>
<string name="tethering_manage_usb">USB tethering</string> <string name="tethering_manage_usb">USB tethering</string>
<string name="tethering_manage_wifi">Wi\u2011Fi hotspot</string> <string name="tethering_manage_wifi">Wi\u2011Fi hotspot</string>
<string name="tethering_manage_wifi_legacy">Wi\u2011Fi hotspot (legacy)</string> <string name="tethering_manage_wifi_legacy">Wi\u2011Fi hotspot (legacy)</string>