log: replace Throwable.printStackTrace by LOG.warn to reliably pinpoint where this exception handling is happening

This commit is contained in:
Thomas Kuehne
2025-06-05 00:26:18 +02:00
parent 85f01ee6ca
commit ad08df3f96
13 changed files with 21 additions and 42 deletions

View File

@@ -16,22 +16,14 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. */ along with this program. If not, see <https://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.devices.banglejs; package nodomain.freeyourgadget.gadgetbridge.devices.banglejs;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_INTERNET_ACCESS;
import android.app.Activity; import android.app.Activity;
import android.app.DownloadManager;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import android.util.Base64; import android.util.Base64;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.DownloadListener; import android.webkit.DownloadListener;
import android.webkit.JavascriptInterface; import android.webkit.JavascriptInterface;
import android.webkit.PermissionRequest; import android.webkit.PermissionRequest;
@@ -41,19 +33,11 @@ import android.webkit.WebResourceRequest;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -65,11 +49,7 @@ import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity; import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.banglejs.BangleJSDeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.banglejs.BangleJSDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport;
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs; import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BANGLEJS_WEBVIEW_URL; import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BANGLEJS_WEBVIEW_URL;
@@ -332,7 +312,7 @@ public class AppsManagementActivity extends AbstractGBActivity {
os.write(fileSaveData); os.write(fileSaveData);
os.close(); os.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.warn("exception in onActivityResult", e);
} finally { } finally {
try { try {
os.close(); os.close();

View File

@@ -160,7 +160,7 @@ public class PBWReader {
} catch (JSONException e) { } catch (JSONException e) {
// no JSON at all that is a problem // no JSON at all that is a problem
isValid = false; isValid = false;
e.printStackTrace(); LOG.warn("exception 1 in constructor", e);
break; break;
} }
@@ -190,7 +190,7 @@ public class PBWReader {
} }
} catch (JSONException e) { } catch (JSONException e) {
isValid = false; isValid = false;
e.printStackTrace(); LOG.warn("exception 2 in constructor", e);
break; break;
} }
} else if (fileName.equals(platformDir + "pebble-app.bin")) { } else if (fileName.equals(platformDir + "pebble-app.bin")) {
@@ -320,7 +320,7 @@ public class PBWReader {
} catch (IOException e1) { } catch (IOException e1) {
// ignore // ignore
} }
e.printStackTrace(); LOG.warn("exception in getInputStreamFile", e);
} }
return null; return null;
} }

View File

@@ -65,7 +65,7 @@ public class BluetoothPairingRequestReceiver extends BroadcastReceiver {
LOG.warn("Could not abort pairing request process"); LOG.warn("Could not abort pairing request process");
} }
} catch (DeviceCommunicationService.DeviceNotFoundException e) { } catch (DeviceCommunicationService.DeviceNotFoundException e) {
e.printStackTrace(); LOG.warn("exception in onReceive", e);
} }
} }
} }

View File

@@ -69,7 +69,7 @@ public class PebbleReceiver extends BroadcastReceiver {
notificationSpec.title = notificationJSON.getJSONObject(0).getString("title"); notificationSpec.title = notificationJSON.getJSONObject(0).getString("title");
notificationSpec.body = notificationJSON.getJSONObject(0).getString("body"); notificationSpec.body = notificationJSON.getJSONObject(0).getString("body");
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); LOG.warn("exception in onReceive", e);
return; return;
} }

View File

@@ -768,7 +768,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
try { try {
handleAction(intent, action, device1); handleAction(intent, action, device1);
} catch (DeviceNotFoundException e) { } catch (DeviceNotFoundException e) {
e.printStackTrace(); LOG.warn("exception in onStartCommand", e);
} catch (Exception e) { } catch (Exception e) {
LOG.error("An exception was raised while handling the action {} for the device {}: ", action, device1, e); LOG.error("An exception was raised while handling the action {} for the device {}: ", action, device1, e);
} }
@@ -1187,7 +1187,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
try { try {
deviceStruct = getDeviceStruct(device); deviceStruct = getDeviceStruct(device);
} catch (DeviceNotFoundException e) { } catch (DeviceNotFoundException e) {
e.printStackTrace(); LOG.warn("exception in getDeviceStructOrNull", e);
} }
return deviceStruct; return deviceStruct;
} }
@@ -1221,7 +1221,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
try { try {
device = getDeviceByAddress(deviceAddress); device = getDeviceByAddress(deviceAddress);
} catch (DeviceNotFoundException e) { } catch (DeviceNotFoundException e) {
e.printStackTrace(); LOG.warn("exception in getDeviceByAddressOrNull", e);
} }
return device; return device;
} }
@@ -1571,7 +1571,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
try { try {
removeDeviceSupport(device); removeDeviceSupport(device);
} catch (DeviceNotFoundException e) { } catch (DeviceNotFoundException e) {
e.printStackTrace(); LOG.warn("exception in onDestroy", e);
} }
} }
GB.removeNotification(GB.NOTIFICATION_ID, this); // need to do this because the updated notification won't be cancelled when service stops GB.removeNotification(GB.NOTIFICATION_ID, this); // need to do this because the updated notification won't be cancelled when service stops

View File

@@ -56,7 +56,7 @@ public class CasioGB6900HandlerThread extends GBDeviceIoThread {
try { try {
waitObject.wait(waitTime); waitObject.wait(waitTime);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); LOG.warn("exception in run", e);
} }
} }
} }

View File

@@ -229,7 +229,7 @@ public class FemometerVinca2DeviceSupport extends AbstractBTLEDeviceSupport {
} }
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.warn("exception in onSendConfiguration", e);
} }
} }

View File

@@ -37,7 +37,6 @@ import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper; import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusConstants; import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusConstants;
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusHealthSampleProvider; import nodomain.freeyourgadget.gadgetbridge.devices.hplus.HPlusHealthSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.HPlusHealthActivityOverlay; import nodomain.freeyourgadget.gadgetbridge.entities.HPlusHealthActivityOverlay;
@@ -98,7 +97,7 @@ class HPlusHandlerThread extends GBDeviceIoThread {
try { try {
waitObject.wait(waitTime); waitObject.wait(waitTime);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); LOG.warn("exception in run", e);
} }
} }
} }

View File

@@ -46,7 +46,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.Send
public class HuaweiWatchfaceManager public class HuaweiWatchfaceManager
{ {
Logger LOG = LoggerFactory.getLogger(HuaweiCoordinator.class); static Logger LOG = LoggerFactory.getLogger(HuaweiCoordinator.class);
public static class Resolution { public static class Resolution {
@@ -142,7 +142,7 @@ public class HuaweiWatchfaceManager
this.font_cn = parseElement(doc,"font-cn"); this.font_cn = parseElement(doc,"font-cn");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); LOG.warn("exception in constructor", e);
} }
} }
} }

View File

@@ -147,7 +147,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport {
needsAuth = false; needsAuth = false;
new InitOperation(auth, this, builder).perform(); new InitOperation(auth, this, builder).perform();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.warn("exception in initializeDevice", e);
} }
return builder; return builder;
} }

View File

@@ -387,7 +387,7 @@ class PebbleIoThread extends GBDeviceIoThread {
try { try {
Thread.sleep(100); Thread.sleep(100);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); LOG.warn("exception 1 in run", e);
} }
} catch (IOException e) { } catch (IOException e) {
if (e.getMessage() != null && (e.getMessage().equals("broken pipe") || e.getMessage().contains("socket closed"))) { //FIXME: this does not feel right if (e.getMessage() != null && (e.getMessage().equals("broken pipe") || e.getMessage().contains("socket closed"))) { //FIXME: this does not feel right
@@ -404,7 +404,7 @@ class PebbleIoThread extends GBDeviceIoThread {
try { try {
mBtSocket.close(); mBtSocket.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.warn("exception 2 in run", e);
} }
mBtSocket = null; mBtSocket = null;
} }

View File

@@ -114,7 +114,7 @@ public class Watch9DeviceSupport extends AbstractBTLEDeviceSupport {
needsAuth = false; needsAuth = false;
new InitOperation(auth, this, builder).perform(); new InitOperation(auth, this, builder).perform();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.warn("exception in initializeDevice", e);
} }
return builder; return builder;
@@ -389,7 +389,7 @@ public class Watch9DeviceSupport extends AbstractBTLEDeviceSupport {
} }
builder.queue(getQueue()); builder.queue(getQueue());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); LOG.warn("exception in onSendConfiguration", e);
} }
} }

View File

@@ -666,7 +666,7 @@ public class WithingsSteelHRDeviceSupport extends AbstractBTLEDeviceSupport {
} }
addSimpleConversationToQueue(message); addSimpleConversationToQueue(message);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.warn("exception in setWorkoutActivityTypes", e);
} }
} }