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

Commit 12ef6537 authored by Sarah Chin's avatar Sarah Chin
Browse files

Fix toString in RILUtils

Test: manually verify logs
Bug: 224782706
Change-Id: I4727f284ac4349ddd174a33bd72f4f9a874e50a4
Merged-In: I4727f284ac4349ddd174a33bd72f4f9a874e50a4
parent 1ef32bad
Loading
Loading
Loading
Loading
+18 −8
Original line number Original line Diff line number Diff line
@@ -349,6 +349,7 @@ import com.android.telephony.Rlog;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Method;
@@ -5174,10 +5175,17 @@ public class RILUtils {
            // Special handling for arrays
            // Special handling for arrays
            StringBuilder sb = new StringBuilder("[");
            StringBuilder sb = new StringBuilder("[");
            boolean added = false;
            boolean added = false;
            if (isPrimitiveOrWrapper(o.getClass().getComponentType())) {
                for (int i = 0; i < Array.getLength(o); i++) {
                    sb.append(convertToString(Array.get(o, i))).append(", ");
                    added = true;
                }
            } else {
                for (Object element : (Object[]) o) {
                for (Object element : (Object[]) o) {
                    sb.append(convertToString(element)).append(", ");
                    sb.append(convertToString(element)).append(", ");
                    added = true;
                    added = true;
                }
                }
            }
            if (added) {
            if (added) {
                // Remove extra ,
                // Remove extra ,
                sb.delete(sb.length() - 2, sb.length());
                sb.delete(sb.length() - 2, sb.length());
@@ -5191,8 +5199,10 @@ public class RILUtils {
        int tag = -1;
        int tag = -1;
        try {
        try {
            tag = (int) o.getClass().getDeclaredMethod("getTag").invoke(o);
            tag = (int) o.getClass().getDeclaredMethod("getTag").invoke(o);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        } catch (IllegalAccessException | InvocationTargetException e) {
            loge(e.getMessage());
            loge(e.toString());
        } catch (NoSuchMethodException ignored) {
            // Ignored since only unions have the getTag method
        }
        }
        if (tag != -1) {
        if (tag != -1) {
            // Special handling for unions
            // Special handling for unions
@@ -5202,7 +5212,7 @@ public class RILUtils {
                method.setAccessible(true);
                method.setAccessible(true);
                tagName = (String) method.invoke(o, tag);
                tagName = (String) method.invoke(o, tag);
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
                loge(e.getMessage());
                loge(e.toString());
            }
            }
            if (tagName != null) {
            if (tagName != null) {
                sb.append(tagName);
                sb.append(tagName);
@@ -5215,7 +5225,7 @@ public class RILUtils {
                    val = o.getClass().getDeclaredMethod(getTagMethod).invoke(o);
                    val = o.getClass().getDeclaredMethod(getTagMethod).invoke(o);
                } catch (NoSuchMethodException | IllegalAccessException
                } catch (NoSuchMethodException | IllegalAccessException
                        | InvocationTargetException e) {
                        | InvocationTargetException e) {
                    loge(e.getMessage());
                    loge(e.toString());
                }
                }
                if (val != null) {
                if (val != null) {
                    sb.append(convertToString(val));
                    sb.append(convertToString(val));
@@ -5231,7 +5241,7 @@ public class RILUtils {
                try {
                try {
                    val = field.get(o);
                    val = field.get(o);
                } catch (IllegalAccessException e) {
                } catch (IllegalAccessException e) {
                    loge(e.getMessage());
                    loge(e.toString());
                }
                }
                if (val == null) continue;
                if (val == null) continue;
                sb.append(convertToString(val)).append(", ");
                sb.append(convertToString(val)).append(", ");