Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ad87d624 authored by Jon Haus's avatar Jon Haus
Browse files

PhoneFactory: fall back to default RIL if custom RIL Class fails

If the ro.telephony.ril_class property is set to an invalid class it will cause
Phone to repeatedly FC and make the device unuseable. This allows it to handle the
exceptions gracefully and fall back on the default RIL.

Change-Id: Ic9c309aff173de5267aa7ef633bfff87243f24fd
parent 8bb720fe
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -117,19 +117,18 @@ public class PhoneFactory {
                Rlog.i(LOG_TAG, "Cdma Subscription set to " + cdmaSubscription);

                //reads the system properties and makes commandsinterface
                String sRILClassname = SystemProperties.get("ro.telephony.ril_class", "RIL");
                String sRILClassname = SystemProperties.get("ro.telephony.ril_class", "RIL").trim();
                Rlog.i(LOG_TAG, "RILClassname is " + sRILClassname);

                // Use reflection to construct the RIL class (defaults to RIL)
                try {
                    Class<?> classDefinition = Class.forName("com.android.internal.telephony." + sRILClassname);
                    Constructor<?> constructor = classDefinition.getConstructor(new Class[] {Context.class, int.class, int.class});
                    sCommandsInterface = (RIL) constructor.newInstance(new Object[] {context, networkMode, cdmaSubscription});
                    sCommandsInterface = instantiateCustomRIL(
                                            sRILClassname, context, networkMode, cdmaSubscription);
                } catch (Exception e) {
                    // 6 different types of exceptions are thrown here that it's
                    // easier to just catch Exception as our "error handling" is the same.
                    Rlog.i(LOG_TAG, "Unable to construct command interface", e);
                    throw new RuntimeException(e);
                    Rlog.e(LOG_TAG, "Unable to construct custom RIL class", e);
                    sCommandsInterface = new RIL(context, networkMode, cdmaSubscription);
                }

                // Instantiate UiccController so that all other classes can just call getInstance()
@@ -174,6 +173,14 @@ public class PhoneFactory {
        }
    }

    private static <T> T instantiateCustomRIL(
                      String sRILClassname, Context context, int networkMode, int cdmaSubscription)
                      throws Exception {
        Class<?> clazz = Class.forName("com.android.internal.telephony." + sRILClassname);
        Constructor<?> constructor = clazz.getConstructor(Context.class, int.class, int.class);
        return (T) clazz.cast(constructor.newInstance(context, networkMode, cdmaSubscription));
    }

    public static Phone getDefaultPhone() {
        if (sLooper != Looper.myLooper()) {
            throw new RuntimeException(