summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoey Hewitt <joey@joeyhewitt.com>2017-09-01 23:19:39 -0700
committerJoey Hewitt <joey@joeyhewitt.com>2017-09-02 01:51:50 -0700
commit9fc5a8093936a20b75d5a83ce39f7a57747cdece (patch)
tree397f0de36ffb517b801e9940e2daf55e08f2f0ef
parent479f5c50e2f4c45615b01e771eb687ac3f75c6bc (diff)
downloadframeworks_opt_telephony_ril_ofono-9fc5a8093936a20b75d5a83ce39f7a57747cdece.tar.gz
frameworks_opt_telephony_ril_ofono-9fc5a8093936a20b75d5a83ce39f7a57747cdece.tar.bz2
frameworks_opt_telephony_ril_ofono-9fc5a8093936a20b75d5a83ce39f7a57747cdece.zip
make exception handling hopefully cleaner
Such as: * Let catch-alls stop us from crashing unnecessarily * Log and drop things that aren't severe
-rw-r--r--src/java/net/scintill/ril_ofono/ModemModule.java11
-rw-r--r--src/java/net/scintill/ril_ofono/PropManager.java16
-rw-r--r--src/java/net/scintill/ril_ofono/RilOfono.java26
-rw-r--r--src/java/net/scintill/ril_ofono/SmsModule.java41
4 files changed, 44 insertions, 50 deletions
diff --git a/src/java/net/scintill/ril_ofono/ModemModule.java b/src/java/net/scintill/ril_ofono/ModemModule.java
index 2b0b7d4..22591d7 100644
--- a/src/java/net/scintill/ril_ofono/ModemModule.java
+++ b/src/java/net/scintill/ril_ofono/ModemModule.java
@@ -217,8 +217,6 @@ import static net.scintill.ril_ofono.RilOfono.runOnMainThreadDebounced;
} else {
// ignore
}
- } catch (Throwable t) {
- RilOfono.logException("onModemChange", t);
}
}
@@ -264,13 +262,8 @@ import static net.scintill.ril_ofono.RilOfono.runOnMainThreadDebounced;
private Object getVoiceRadioTechnologyAsyncResult() {
// TODO is this really the right value?
- try {
- OfonoNetworkTechnology tech = getProp(mNetRegProps, "Technology", OfonoNetworkTechnology._unknown);
- return new int[]{ tech.serviceStateInt };
- } catch (Throwable t) {
- Rlog.e(TAG, "Error getting voice radio tech", t);
- return new int[] { OfonoNetworkTechnology._unknown.serviceStateInt };
- }
+ OfonoNetworkTechnology tech = getProp(mNetRegProps, "Technology", OfonoNetworkTechnology._unknown);
+ return new int[]{ tech.serviceStateInt };
}
}
diff --git a/src/java/net/scintill/ril_ofono/PropManager.java b/src/java/net/scintill/ril_ofono/PropManager.java
index 59ca597..a48fcc3 100644
--- a/src/java/net/scintill/ril_ofono/PropManager.java
+++ b/src/java/net/scintill/ril_ofono/PropManager.java
@@ -26,8 +26,6 @@ import org.freedesktop.DBus;
import org.freedesktop.dbus.DBusInterface;
import org.freedesktop.dbus.DBusSigHandler;
import org.freedesktop.dbus.DBusSignal;
-import org.freedesktop.dbus.UInt16;
-import org.freedesktop.dbus.UInt32;
import org.freedesktop.dbus.Variant;
import org.freedesktop.dbus.exceptions.DBusExecutionException;
@@ -38,6 +36,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import static net.scintill.ril_ofono.RilOfono.privExc;
import static net.scintill.ril_ofono.RilOfono.privStr;
/*package*/ class PropManager {
@@ -83,15 +82,13 @@ import static net.scintill.ril_ofono.RilOfono.privStr;
throw new RuntimeException("unable to find GetProperties method", e);
} catch (InvocationTargetException e) {
try {
- if (e.getCause() instanceof DBusExecutionException) {
- throw (DBusExecutionException) e.getCause();
- } else {
- throw new RuntimeException("error calling GetProperties() on " + sourceObIface.getSimpleName(), e.getCause());
- }
+ throw e.getCause();
} catch (DBus.Error.UnknownMethod unknownMethod) {
Rlog.w(TAG, "unable to GetProperties() on " + sourceObIface.getSimpleName());
// probably just isn't loaded yet, so give empty props
props = new HashMap<>();
+ } catch (Throwable t) {
+ throw new RuntimeException("error calling GetProperties() on " + sourceObIface.getSimpleName(), t);
}
}
@@ -107,7 +104,8 @@ import static net.scintill.ril_ofono.RilOfono.privStr;
} catch (NoSuchMethodException | IllegalAccessException e) {
throw new RuntimeException("unable to find onPropChange method", e);
} catch (InvocationTargetException e) {
- throw new RuntimeException(e.getCause());
+ Rlog.e(TAG, "exception in onPropChange()", e.getCause());
+ // do not re-throw
}
}
}
@@ -132,7 +130,7 @@ import static net.scintill.ril_ofono.RilOfono.privStr;
} catch (IllegalAccessException e) {
throw new RuntimeException("unable to handle propchange signal", e);
} catch (InvocationTargetException e) {
- Rlog.e(TAG, "error handling propchange signal", e.getCause());
+ Rlog.e(TAG, "exception in onPropChange()", privExc(e.getCause()));
// do not re-throw
}
}
diff --git a/src/java/net/scintill/ril_ofono/RilOfono.java b/src/java/net/scintill/ril_ofono/RilOfono.java
index 8004762..63c96e8 100644
--- a/src/java/net/scintill/ril_ofono/RilOfono.java
+++ b/src/java/net/scintill/ril_ofono/RilOfono.java
@@ -110,9 +110,8 @@ public class RilOfono implements RilInterface {
mDataConnModule = new DataConnModule(mRilWrapper.mDataNetworkStateRegistrants);
mSupplSvcsModule = new SupplementaryServicesModule(mRilWrapper.mUSSDRegistrants);
mModemModule.onModemChange(false); // initialize starting state
- } catch (DBusException e) {
- logException("RilOfono", e);
- System.exit(-1); // XXX how to better react to this?
+ } catch (Throwable t) {
+ throw new RuntimeException("exception while loading", t);
}
}
});
@@ -134,7 +133,7 @@ public class RilOfono implements RilInterface {
setRadioState(RadioState.RADIO_OFF);
} else {
setRadioState(RadioState.RADIO_UNAVAILABLE);
- logException("onModemAvail setRadioPower", ar.exception);
+ Rlog.e(TAG, "onModemAvail: setRadioPower(false) returned an exception", ar.exception);
}
return true;
}
@@ -811,10 +810,6 @@ public class RilOfono implements RilInterface {
mRilWrapper.setRadioStateHelper(newState);
}
- /*package*/ static void logException(String m, Throwable t) {
- Rlog.e(TAG, "Uncaught exception in "+m, t);
- }
-
// TODO
// things I noticed BaseCommands overrides but has an empty implementation we might need to override:
// getModemCapability(),
@@ -832,20 +827,21 @@ public class RilOfono implements RilInterface {
/*package*/ <T extends DBusInterface> T getOfonoInterface(Class<T> tClass, String path) {
try {
return mDbus.getRemoteObject(OFONO_BUS_NAME, path, tClass);
- } catch (Throwable t) {
- Rlog.e(TAG, "Exception getting "+tClass.getSimpleName(), t);
- return null;
+ } catch (DBusException e) {
+ throw new RuntimeException("Exception getting "+ tClass.getSimpleName(), e);
}
}
+ // no exception catch-all will be provided
/*package*/ <T extends DBusSignal> void registerDbusSignal(Class<T> signalClass, DBusSigHandler<T> handler) {
try {
mDbus.addSigHandler(signalClass, handler);
} catch (DBusException e) {
- throw new RuntimeException(e);
+ throw new RuntimeException("Unable to register dbus signal handler", e);
}
}
+ // an exception catch-all (that logs exceptions with privExc()) will be provided
/*package*/ <T extends DBusSignal> void registerDbusSignal(Class<T> signalClass, final Object handler) {
try {
final Method m = handler.getClass().getMethod("handle", signalClass);
@@ -857,14 +853,14 @@ public class RilOfono implements RilInterface {
} catch (IllegalAccessException e) {
throw new RuntimeException("Unexpected exception while delegating dbus signal", e);
} catch (InvocationTargetException e) {
- Rlog.e(TAG, "Unexpected exception while delegating dbus signal", e.getCause());
+ Rlog.e(TAG, "Unexpected exception while dispatching dbus signal", privExc(e.getCause()));
// do not re-throw
}
}
});
- } catch (DBusException e) {
- throw new RuntimeException(e);
} catch (NoSuchMethodException e) {
+ throw new RuntimeException("Unable to find dbus signal handler", e);
+ } catch (DBusException e) {
throw new RuntimeException("Unable to register dbus signal handler", e);
}
}
diff --git a/src/java/net/scintill/ril_ofono/SmsModule.java b/src/java/net/scintill/ril_ofono/SmsModule.java
index 692590a..8857407 100644
--- a/src/java/net/scintill/ril_ofono/SmsModule.java
+++ b/src/java/net/scintill/ril_ofono/SmsModule.java
@@ -36,6 +36,7 @@ import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import static com.android.internal.telephony.CommandException.Error.GENERIC_FAILURE;
+import static net.scintill.ril_ofono.RilOfono.privExc;
import static net.scintill.ril_ofono.RilOfono.privStr;
import static net.scintill.ril_ofono.RilOfono.respondExc;
import static net.scintill.ril_ofono.RilOfono.respondOk;
@@ -100,24 +101,30 @@ import static net.scintill.ril_ofono.RilOfono.runOnMainThread;
}
public void handle(final MessageManager.IncomingPdu s) {
- runOnMainThread(new Runnable() {
- @Override
- public void run() {
- try {
- SmsMessage msg = SmsMessage.createFromPdu(normalizePdu(s.pdu, s.tpdu_len), SmsConstants.FORMAT_3GPP);
- try {
- // someone decided to swallow exceptions and return null as the wrapped object, so check it
- if (msg != null) msg.getTimestampMillis();
- } catch (NullPointerException e) {
- // SmsMessage probably logged more information about the cause, but I want to know what the PDU was
- Rlog.e(TAG, "Null returned from parsing incoming PDU "+privStr(IccUtils.bytesToHexString(s.pdu)+" tpdu_len="+s.tpdu_len));
- }
- mSmsRegistrants.notifyResult(msg);
- } catch (Throwable t) {
- Rlog.e(TAG, "Error handling incoming PDU "+privStr(IccUtils.bytesToHexString(s.pdu)+" tpdu_len="+s.tpdu_len));
- }
+ try {
+ SmsMessage msg = SmsMessage.createFromPdu(normalizePdu(s.pdu, s.tpdu_len), SmsConstants.FORMAT_3GPP);
+ try {
+ // someone decided to swallow exceptions and return null as the wrapped object, so check it
+ if (msg != null) msg.getTimestampMillis();
+ } catch (NullPointerException e) {
+ // SmsMessage probably logged more information about the cause
+ msg = null;
+ }
+ if (msg == null) {
+ throw new IllegalArgumentException("Null returned from parser");
}
- });
+
+ final SmsMessage fmsg = msg;
+ runOnMainThread(new Runnable() {
+ @Override
+ public void run() {
+ mSmsRegistrants.notifyResult(fmsg);
+ }
+ });
+ } catch (Throwable t) {
+ Rlog.e(TAG, "Error handling incoming PDU "+privStr(IccUtils.bytesToHexString(s.pdu)+" tpdu_len="+s.tpdu_len), privExc(t));
+ }
+
}
private static byte[] normalizePdu(byte[] pdu, int tpdu_len) {