Merge branch 'wifi-related-crashes' into 'master'

ignore mystery NoClassDefFoundError, etc. crashes in WifiApControl

Closes acra-crash-reports#39, acra-crash-reports#31, acra-crash-reports#12, and #2477

See merge request fdroid/fdroidclient!1158
This commit is contained in:
Hans-Christoph Steiner
2022-12-19 11:39:05 +00:00
2 changed files with 33 additions and 35 deletions

View File

@@ -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;
}
@@ -144,15 +157,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);

View File

@@ -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();