From 5eb54378cee403e131de22d14b54736157157d98 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 14 Dec 2022 11:07:46 +0100 Subject: [PATCH 1/2] WifiApControl: remove unused macAddressToByteArray method --- .../full/java/cc/mvdan/accesspoint/WifiApControl.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/src/full/java/cc/mvdan/accesspoint/WifiApControl.java b/app/src/full/java/cc/mvdan/accesspoint/WifiApControl.java index f2bee0a5e..cd8033b04 100644 --- a/app/src/full/java/cc/mvdan/accesspoint/WifiApControl.java +++ b/app/src/full/java/cc/mvdan/accesspoint/WifiApControl.java @@ -144,15 +144,6 @@ final public class WifiApControl { return FALLBACK_DEVICE; } - private static byte[] macAddressToByteArray(String macString) { - String[] mac = macString.split("[:\\s-]"); - byte[] macAddress = new byte[6]; - for (int i = 0; i < mac.length; i++) { - macAddress[i] = Integer.decode("0x" + mac[i]).byteValue(); - } - return macAddress; - } - private static Object invokeQuietly(Method method, Object receiver, Object... args) { try { return method.invoke(receiver, args); From ba22ec49d0e7569f2eff2f597f5eea2031a46666 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 13 Dec 2022 17:00:09 +0100 Subject: [PATCH 2/2] ignore mystery NoClassDefFoundError, etc. crashes in WifiApControl I looked into this and have no idea how it could be caused, or even how it is possible for it to happen. The WifiApControl is only for old Android releases anyway, so F-Droid should not crash even if this feature does not work. closes #2477 closes acra-crash-reports#12 closes acra-crash-reports#31 closes acra-crash-reports#39 --- .../cc/mvdan/accesspoint/WifiApControl.java | 51 ++++++++++++------- .../fdroid/nearby/WifiStateChangeService.java | 8 +-- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/app/src/full/java/cc/mvdan/accesspoint/WifiApControl.java b/app/src/full/java/cc/mvdan/accesspoint/WifiApControl.java index cd8033b04..07e746190 100644 --- a/app/src/full/java/cc/mvdan/accesspoint/WifiApControl.java +++ b/app/src/full/java/cc/mvdan/accesspoint/WifiApControl.java @@ -16,15 +16,14 @@ package cc.mvdan.accesspoint; -import android.annotation.SuppressLint; -import android.annotation.TargetApi; import android.content.Context; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; -import android.os.Build; import android.provider.Settings; import android.util.Log; +import org.fdroid.fdroid.BuildConfig; + import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; @@ -35,7 +34,6 @@ import java.net.Inet6Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.ArrayList; -import java.util.Arrays; import java.util.Enumeration; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -67,21 +65,28 @@ final public class WifiApControl { private static Method setWifiApEnabledMethod; static { - for (Method method : WifiManager.class.getDeclaredMethods()) { - switch (method.getName()) { - case "getWifiApConfiguration": - getWifiApConfigurationMethod = method; - break; - case "getWifiApState": - getWifiApStateMethod = method; - break; - case "isWifiApEnabled": - isWifiApEnabledMethod = method; - break; - case "setWifiApEnabled": - setWifiApEnabledMethod = method; - break; + try { + for (Method method : WifiManager.class.getDeclaredMethods()) { + switch (method.getName()) { + case "getWifiApConfiguration": + getWifiApConfigurationMethod = method; + break; + case "getWifiApState": + getWifiApStateMethod = method; + break; + case "isWifiApEnabled": + isWifiApEnabledMethod = method; + break; + case "setWifiApEnabled": + setWifiApEnabledMethod = method; + break; + } } + } catch (Exception e) { + if (BuildConfig.DEBUG) { + throw e; + } + Log.e(TAG, "WifiManager failed to init", e); } } @@ -134,7 +139,15 @@ final public class WifiApControl { Log.e(TAG, "6.0 or later, but haven't been granted WRITE_SETTINGS!"); return null; } - instance = new WifiApControl(context); + try { + instance = new WifiApControl(context); + instance.isEnabled(); // make sure this instance works + } catch (Exception e) { + if (BuildConfig.DEBUG) { + throw e; + } + Log.e(TAG, "WifiManager failed to init", e); + } } return instance; } diff --git a/app/src/full/java/org/fdroid/fdroid/nearby/WifiStateChangeService.java b/app/src/full/java/org/fdroid/fdroid/nearby/WifiStateChangeService.java index 11eeca152..e21ec99e5 100644 --- a/app/src/full/java/org/fdroid/fdroid/nearby/WifiStateChangeService.java +++ b/app/src/full/java/org/fdroid/fdroid/nearby/WifiStateChangeService.java @@ -261,13 +261,7 @@ public class WifiStateChangeService extends Worker { } FDroidApp.bssid = wifiInfo.getBSSID(); } else { - WifiApControl wifiApControl = null; - try { - wifiApControl = WifiApControl.getInstance(context); - wifiApControl.isEnabled(); - } catch (NullPointerException e) { - wifiApControl = null; - } + WifiApControl wifiApControl = WifiApControl.getInstance(context); Utils.debugLog(TAG, "WifiApControl: " + wifiApControl); if (wifiApControl == null && FDroidApp.ipAddressString != null) { wifiInfo = wifiManager.getConnectionInfo();