diff --git a/README.md b/README.md index 2796e812..740807b5 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,10 @@ Private system configurations: 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; * 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. diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/ManageBar.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/ManageBar.kt index 03bd9d02..9aa39183 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/ManageBar.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/ManageBar.kt @@ -3,14 +3,32 @@ package be.mygod.vpnhotspot.manage import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent +import android.os.Build +import android.provider.Settings import android.view.View +import androidx.databinding.BaseObservable import androidx.recyclerview.widget.RecyclerView +import be.mygod.vpnhotspot.App.Companion.app +import be.mygod.vpnhotspot.databinding.ListitemManageBinding import com.crashlytics.android.Crashlytics 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 { - view.setOnClickListener(this) + binding.data = Data + binding.root.setOnClickListener(this) } override fun onClick(v: View?) = start(itemView.context) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/Manager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/Manager.kt index 843300ca..495d44d4 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/Manager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/Manager.kt @@ -5,8 +5,8 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView -import be.mygod.vpnhotspot.R import be.mygod.vpnhotspot.databinding.ListitemInterfaceBinding +import be.mygod.vpnhotspot.databinding.ListitemManageBinding import be.mygod.vpnhotspot.databinding.ListitemRepeaterBinding abstract class Manager { @@ -26,7 +26,7 @@ abstract class Manager { fun createViewHolder(inflater: LayoutInflater, parent: ViewGroup, type: Int) = when (type) { VIEW_TYPE_INTERFACE -> 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 -> TetherManager.ViewHolder(ListitemInterfaceBinding.inflate(inflater, parent, false)) VIEW_TYPE_LOCAL_ONLY_HOTSPOT -> @TargetApi(26) { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt index 3d6dafca..22322909 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt @@ -104,6 +104,11 @@ class TetheringFragment : Fragment(), ServiceConnection { return binding.root } + override fun onResume() { + super.onResume() + if (Build.VERSION.SDK_INT >= 27) ManageBar.Data.notifyChange() + } + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { if (requestCode == START_LOCAL_ONLY_HOTSPOT) @TargetApi(26) { if (grantResults.firstOrNull() == PackageManager.PERMISSION_GRANTED) { diff --git a/mobile/src/main/res/layout/listitem_manage.xml b/mobile/src/main/res/layout/listitem_manage.xml index 9b9b861c..277064e5 100644 --- a/mobile/src/main/res/layout/listitem_manage.xml +++ b/mobile/src/main/res/layout/listitem_manage.xml @@ -1,29 +1,50 @@ - - - + + + + + + android:focusable="true" + android:background="?android:attr/selectableItemBackground" + android:padding="16dp"> - + - + - + + + + + + + + + diff --git a/mobile/src/main/res/values-zh-rCN/strings.xml b/mobile/src/main/res/values-zh-rCN/strings.xml index 3bc4e63a..f1733c04 100644 --- a/mobile/src/main/res/values-zh-rCN/strings.xml +++ b/mobile/src/main/res/values-zh-rCN/strings.xml @@ -38,6 +38,7 @@ 共享被禁用 管理系统共享… + 若 VPN 共享无法使用,请尝试禁用“开发者选项”中的“网络共享硬件加速”。