From f83f81120b59e39f4cf8665b615e51963353e3eb Mon Sep 17 00:00:00 2001 From: Mygod Date: Fri, 22 Mar 2019 12:06:55 +0800 Subject: [PATCH 1/6] Fix NPE --- .../main/java/be/mygod/vpnhotspot/client/ClientsFragment.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/client/ClientsFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/client/ClientsFragment.kt index 30d5bc68..209eab65 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/client/ClientsFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/client/ClientsFragment.kt @@ -67,11 +67,10 @@ class ClientsFragment : Fragment(), MainScope by MainScope.Supervisor() { override fun onClick(dialog: DialogInterface?, which: Int) { when (which) { DialogInterface.BUTTON_POSITIVE -> { + val newNickname = this@NicknameDialogFragment.dialog!!.findViewById(android.R.id.edit).text MacLookup.abort(arg.mac) GlobalScope.launch(Dispatchers.Unconfined) { - AppDatabase.instance.clientRecordDao.upsert(arg.mac) { - nickname = this@NicknameDialogFragment.dialog!!.findViewById(android.R.id.edit).text - } + AppDatabase.instance.clientRecordDao.upsert(arg.mac) { nickname = newNickname } } } DialogInterface.BUTTON_NEUTRAL -> MacLookup.perform(arg.mac, true) From e30a09a6cf5237fb859d7aa6d71f598876dc8f10 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sat, 23 Mar 2019 14:17:42 +0800 Subject: [PATCH 2/6] Refine code style --- .../src/main/java/be/mygod/vpnhotspot/client/ClientsFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/client/ClientsFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/client/ClientsFragment.kt index 209eab65..685439ef 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/client/ClientsFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/client/ClientsFragment.kt @@ -67,7 +67,7 @@ class ClientsFragment : Fragment(), MainScope by MainScope.Supervisor() { override fun onClick(dialog: DialogInterface?, which: Int) { when (which) { DialogInterface.BUTTON_POSITIVE -> { - val newNickname = this@NicknameDialogFragment.dialog!!.findViewById(android.R.id.edit).text + val newNickname = this.dialog!!.findViewById(android.R.id.edit).text MacLookup.abort(arg.mac) GlobalScope.launch(Dispatchers.Unconfined) { AppDatabase.instance.clientRecordDao.upsert(arg.mac) { nickname = newNickname } From 129fddb8f7af7b30d84d790c6bdfa2a576b797ab Mon Sep 17 00:00:00 2001 From: Mygod Date: Fri, 29 Mar 2019 12:40:38 +0800 Subject: [PATCH 3/6] Update Q & A --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c4e45603..a715049c 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,8 @@ 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? From 6934e2ea5288aaeeb5ed3ebf32a7e89fe7eb317b Mon Sep 17 00:00:00 2001 From: Mygod Date: Wed, 3 Apr 2019 10:40:39 +0800 Subject: [PATCH 4/6] Update dependencies --- build.gradle | 2 +- mobile/build.gradle | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 2ce3be2c..91299544 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ buildscript { classpath "com.android.tools.build:gradle:3.3.2" classpath 'com.github.ben-manes:gradle-versions-plugin:0.21.0' classpath 'com.google.gms:google-services:4.2.0' - classpath 'io.fabric.tools:gradle:1.28.0' + classpath 'io.fabric.tools:gradle:1.28.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" } } diff --git a/mobile/build.gradle b/mobile/build.gradle index c5b65bd0..fe9c170a 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -68,7 +68,7 @@ def aux = [ 'com.google.firebase:firebase-core:16.0.8', ] def lifecycleVersion = '2.0.0' -def roomVersion = '2.1.0-alpha05' +def roomVersion = '2.1.0-alpha06' dependencies { kapt "androidx.lifecycle:lifecycle-compiler:$lifecycleVersion" kapt "androidx.room:room-compiler:$roomVersion" @@ -82,10 +82,10 @@ dependencies { implementation "androidx.room:room-ktx:$roomVersion" implementation 'com.android.billingclient:billing:1.2.2' implementation 'com.github.luongvo:BadgeView:1.1.5' - implementation 'com.github.topjohnwu.libsu:core:2.3.1' + implementation 'com.github.topjohnwu.libsu:core:2.3.3' implementation 'com.google.android.material:material:1.0.0' implementation 'com.jakewharton.timber:timber:4.7.1' - implementation 'com.linkedin.dexmaker:dexmaker:2.21.0' + implementation 'com.linkedin.dexmaker:dexmaker:2.25.0' implementation 'com.takisoft.preferencex:preferencex-simplemenu:1.0.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1' From 10a2b777f254d38eb0afaf5b9c362942d1154cba Mon Sep 17 00:00:00 2001 From: Mygod Date: Wed, 3 Apr 2019 15:56:54 +0800 Subject: [PATCH 5/6] New icon for temp hotspot --- mobile/src/main/AndroidManifest.xml | 2 +- .../mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt | 5 +---- .../vpnhotspot/manage/LocalOnlyHotspotTileService.kt | 2 +- .../src/main/res/drawable/ic_action_perm_scan_wifi.xml | 9 +++++++++ 4 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 mobile/src/main/res/drawable/ic_action_perm_scan_wifi.xml diff --git a/mobile/src/main/AndroidManifest.xml b/mobile/src/main/AndroidManifest.xml index 293052ae..a1ef8945 100644 --- a/mobile/src/main/AndroidManifest.xml +++ b/mobile/src/main/AndroidManifest.xml @@ -91,7 +91,7 @@ android:name=".manage.LocalOnlyHotspotTileService" android:directBootAware="true" android:enabled="@bool/api_ge_26" - android:icon="@drawable/ic_device_wifi_tethering" + android:icon="@drawable/ic_action_perm_scan_wifi" android:label="@string/tethering_temp_hotspot" android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"> diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt index 45001b1d..219a8680 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt @@ -75,10 +75,7 @@ class LocalOnlyHotspotManager(private val parent: TetheringFragment) : Manager() private inner class Data : be.mygod.vpnhotspot.manage.Data() { private val lookup: Map get() = parent.ifaceLookup - override val icon: Int get() { - val iface = binder?.iface - return (if (iface.isNullOrBlank()) TetherType.WIFI else TetherType.ofInterface(iface)).icon - } + override val icon get() = R.drawable.ic_action_perm_scan_wifi override val title: CharSequence get() { val configuration = binder?.configuration ?: return parent.getString(R.string.tethering_temp_hotspot) return SpannableStringBuilder("${configuration.SSID} - ").apply { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotTileService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotTileService.kt index cabfe4bb..32c8fd79 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotTileService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotTileService.kt @@ -15,7 +15,7 @@ import be.mygod.vpnhotspot.util.stopAndUnbind @RequiresApi(26) class LocalOnlyHotspotTileService : KillableTileService() { - private val tile by lazy { Icon.createWithResource(application, R.drawable.ic_device_wifi_tethering) } + private val tile by lazy { Icon.createWithResource(application, R.drawable.ic_action_perm_scan_wifi) } private var binder: LocalOnlyHotspotService.Binder? = null diff --git a/mobile/src/main/res/drawable/ic_action_perm_scan_wifi.xml b/mobile/src/main/res/drawable/ic_action_perm_scan_wifi.xml new file mode 100644 index 00000000..a71c7496 --- /dev/null +++ b/mobile/src/main/res/drawable/ic_action_perm_scan_wifi.xml @@ -0,0 +1,9 @@ + + + From f97afdf8ae0f03693148f7f0597e8b0547b18cb0 Mon Sep 17 00:00:00 2001 From: Mygod Date: Wed, 3 Apr 2019 16:32:09 +0800 Subject: [PATCH 6/6] Prevent recreating monitor MenuItem --- .../vpnhotspot/manage/TetheringFragment.kt | 29 ++++++++----------- .../java/be/mygod/vpnhotspot/util/Utils.kt | 8 +++++ ...lbar_monitor.xml => toolbar_tethering.xml} | 2 ++ 3 files changed, 22 insertions(+), 17 deletions(-) rename mobile/src/main/res/menu/{toolbar_monitor.xml => toolbar_tethering.xml} (84%) 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 9f859cd7..a4911964 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt @@ -25,6 +25,7 @@ import be.mygod.vpnhotspot.net.TetheringManager.localOnlyTetheredIfaces import be.mygod.vpnhotspot.net.TetheringManager.tetheredIfaces import be.mygod.vpnhotspot.util.ServiceForegroundConnector import be.mygod.vpnhotspot.util.broadcastReceiver +import be.mygod.vpnhotspot.util.isNotGone import kotlinx.android.synthetic.main.activity_main.* import timber.log.Timber import java.net.NetworkInterface @@ -95,18 +96,11 @@ class TetheringFragment : Fragment(), ServiceConnection, MenuItem.OnMenuItemClic } private fun updateMonitorList(canMonitor: List = emptyList()) { - val toolbar = requireActivity().toolbar - val menu = toolbar.menu - if (canMonitor.isEmpty()) menu.removeItem(R.id.monitor) else { - var item = menu.findItem(R.id.monitor) - if (item == null) { - toolbar.inflateMenu(R.menu.toolbar_monitor) - item = menu.findItem(R.id.monitor)!! - } - item.subMenu.apply { - clear() - canMonitor.sorted().forEach { add(it).setOnMenuItemClickListener(this@TetheringFragment) } - } + val item = requireActivity().toolbar.menu.findItem(R.id.monitor) ?: return // assuming no longer foreground + item.isNotGone = canMonitor.isNotEmpty() + item.subMenu.apply { + clear() + canMonitor.sorted().forEach { add(it).setOnMenuItemClickListener(this@TetheringFragment) } } } override fun onMenuItemClick(item: MenuItem?): Boolean { @@ -123,9 +117,15 @@ class TetheringFragment : Fragment(), ServiceConnection, MenuItem.OnMenuItemClic binding.interfaces.adapter = adapter adapter.update(emptyList(), emptyList(), emptyList()) ServiceForegroundConnector(this, this, TetheringService::class) + requireActivity().toolbar.inflateMenu(R.menu.toolbar_tethering) return binding.root } + override fun onDestroyView() { + super.onDestroyView() + requireActivity().toolbar.menu.clear() + } + override fun onResume() { super.onResume() if (Build.VERSION.SDK_INT >= 27) ManageBar.Data.notifyChange() @@ -163,9 +163,4 @@ class TetheringFragment : Fragment(), ServiceConnection, MenuItem.OnMenuItemClic binder = null requireContext().unregisterReceiver(receiver) } - - override fun onDestroy() { - updateMonitorList() - super.onDestroy() - } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt b/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt index b3365485..42f174ef 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt @@ -5,6 +5,7 @@ import android.os.Build import android.text.Spannable import android.text.SpannableString import android.text.SpannableStringBuilder +import android.view.MenuItem import android.view.View import android.widget.ImageView import androidx.annotation.DrawableRes @@ -91,6 +92,13 @@ fun Context.stopAndUnbind(connection: ServiceConnection) { unbindService(connection) } +var MenuItem.isNotGone: Boolean + get() = isVisible || isEnabled + set(value) { + isVisible = value + isEnabled = value + } + fun MutableMap.computeIfAbsentCompat(key: K, value: () -> V) = if (Build.VERSION.SDK_INT >= 24) computeIfAbsent(key) { value() } else this[key] ?: value().also { put(key, it) } fun MutableMap.putIfAbsentCompat(key: K, value: V) = if (Build.VERSION.SDK_INT >= 24) diff --git a/mobile/src/main/res/menu/toolbar_monitor.xml b/mobile/src/main/res/menu/toolbar_tethering.xml similarity index 84% rename from mobile/src/main/res/menu/toolbar_monitor.xml rename to mobile/src/main/res/menu/toolbar_tethering.xml index 74c1b8d8..e1799d11 100644 --- a/mobile/src/main/res/menu/toolbar_monitor.xml +++ b/mobile/src/main/res/menu/toolbar_tethering.xml @@ -4,6 +4,8 @@