From e799fcf9ffa9999447d9c94aa6771e9f99ef8f26 Mon Sep 17 00:00:00 2001 From: Mygod Date: Fri, 5 Apr 2019 09:34:23 +0800 Subject: [PATCH] Prevent tempering with persistent groups in Android Q This seems to cause improper persistent group deletions, but either way, I cannot seem to find where persistent groups are persisted now on Android Q. --- README.md | 4 ++-- .../main/java/be/mygod/vpnhotspot/RepeaterService.kt | 10 ++++++++-- .../mygod/vpnhotspot/net/wifi/WifiP2pManagerHelper.kt | 3 +++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6b54d09a..493fd150 100644 --- a/README.md +++ b/README.md @@ -133,8 +133,8 @@ Undocumented API list: * (deprecated since API 26) `Landroid/net/wifi/WifiManager;->setWifiApEnabled(Landroid/net/wifi/WifiConfiguration;Z)Z` * [`Landroid/net/wifi/p2p/WifiP2pGroup;->getNetworkId()I,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/aa21a6e/appcompat/hiddenapi-flags.csv#123194) * [`Landroid/net/wifi/p2p/WifiP2pGroupList;->getGroupList()Ljava/util/Collection;,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/aa21a6e/appcompat/hiddenapi-flags.csv#123239) -* [`Landroid/net/wifi/p2p/WifiP2pManager;->deletePersistentGroup(Landroid/net/wifi/p2p/WifiP2pManager$Channel;ILandroid/net/wifi/p2p/WifiP2pManager$ActionListener;)V,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/aa21a6e/appcompat/hiddenapi-flags.csv#123431) -* [`Landroid/net/wifi/p2p/WifiP2pManager;->requestPersistentGroupInfo(Landroid/net/wifi/p2p/WifiP2pManager$Channel;Landroid/net/wifi/p2p/WifiP2pManager$PersistentGroupInfoListener;)V,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/aa21a6e/appcompat/hiddenapi-flags.csv#123450) +* (prior to API Q) [`Landroid/net/wifi/p2p/WifiP2pManager;->deletePersistentGroup(Landroid/net/wifi/p2p/WifiP2pManager$Channel;ILandroid/net/wifi/p2p/WifiP2pManager$ActionListener;)V,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/aa21a6e/appcompat/hiddenapi-flags.csv#123431) +* (prior to API Q) [`Landroid/net/wifi/p2p/WifiP2pManager;->requestPersistentGroupInfo(Landroid/net/wifi/p2p/WifiP2pManager$Channel;Landroid/net/wifi/p2p/WifiP2pManager$PersistentGroupInfoListener;)V,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/aa21a6e/appcompat/hiddenapi-flags.csv#123450) * [`Landroid/net/wifi/p2p/WifiP2pManager;->setWifiP2pChannels(Landroid/net/wifi/p2p/WifiP2pManager$Channel;IILandroid/net/wifi/p2p/WifiP2pManager$ActionListener;)V,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/aa21a6e/appcompat/hiddenapi-flags.csv#123458) * [`Landroid/net/wifi/p2p/WifiP2pManager;->startWps(Landroid/net/wifi/p2p/WifiP2pManager$Channel;Landroid/net/wifi/WpsInfo;Landroid/net/wifi/p2p/WifiP2pManager$ActionListener;)V,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/aa21a6e/appcompat/hiddenapi-flags.csv#123459) * [`Ljava/net/InetAddress;->parseNumericAddress(Ljava/lang/String;)Ljava/net/InetAddress;,greylist`](https://android.googlesource.com/platform/prebuilts/runtime/+/aa21a6e/appcompat/hiddenapi-flags.csv#299587) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt index a47f6928..01bb10e4 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt @@ -86,6 +86,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere groupChanged(value) } val groupChanged = StickyEvent1 { group } + @Deprecated("Not initialized and no use at all since Android Q") var thisDevice: WifiP2pDevice? = null @Deprecated("WPS was deprecated RIP") @@ -127,6 +128,8 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_GROUP)!!) } } + @Deprecated("No longer used since Android Q") + @Suppress("DEPRECATION") private val deviceListener = broadcastReceiver { _, intent -> when (intent.action) { WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION -> binder.thisDevice = @@ -158,7 +161,8 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere override fun onCreate() { super.onCreate() onChannelDisconnected() - registerReceiver(deviceListener, intentFilter(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION, + if (!BuildCompat.isAtLeastQ()) @Suppress("DEPRECATION") registerReceiver(deviceListener, intentFilter( + WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION, WifiP2pManagerHelper.WIFI_P2P_PERSISTENT_GROUPS_CHANGED_ACTION)) app.pref.registerOnSharedPreferenceChangeListener(this) } @@ -198,6 +202,8 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere if (key == KEY_OPERATING_CHANNEL) setOperatingChannel() } + @Deprecated("No longer used since Android Q") + @Suppress("DEPRECATION") private fun onPersistentGroupsChanged() { val channel = channel ?: return val device = binder.thisDevice ?: return @@ -377,7 +383,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere if (status != Status.IDLE) binder.shutdown() clean() // force clean to prevent leakage app.pref.unregisterOnSharedPreferenceChangeListener(this) - unregisterReceiver(deviceListener) + if (!BuildCompat.isAtLeastQ()) @Suppress("DEPRECATION") unregisterReceiver(deviceListener) status = Status.DESTROYED if (Build.VERSION.SDK_INT >= 27) channel?.close() super.onDestroy() diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pManagerHelper.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pManagerHelper.kt index 794ec602..23657929 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pManagerHelper.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pManagerHelper.kt @@ -12,6 +12,7 @@ import java.lang.reflect.Proxy object WifiP2pManagerHelper { const val UNSUPPORTED = -2 + @Deprecated("No longer used since Android Q") const val WIFI_P2P_PERSISTENT_GROUPS_CHANGED_ACTION = "android.net.wifi.p2p.PERSISTENT_GROUPS_CHANGED" /** @@ -61,6 +62,7 @@ object WifiP2pManagerHelper { WifiP2pManager::class.java.getDeclaredMethod("deletePersistentGroup", WifiP2pManager.Channel::class.java, Int::class.java, WifiP2pManager.ActionListener::class.java) } + @Deprecated("No longer used since Android Q") fun WifiP2pManager.deletePersistentGroup(c: WifiP2pManager.Channel, netId: Int, listener: WifiP2pManager.ActionListener) { try { @@ -87,6 +89,7 @@ object WifiP2pManagerHelper { * @param c is the channel created at {@link #initialize} * @param listener for callback when persistent group info list is available. Can be null. */ + @Deprecated("No longer used since Android Q") fun WifiP2pManager.requestPersistentGroupInfo(c: WifiP2pManager.Channel, listener: (Collection) -> Unit) { val proxy = Proxy.newProxyInstance(interfacePersistentGroupInfoListener.classLoader,