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

Commit a15caf85 authored by San Mehat's avatar San Mehat Committed by Android (Google) Code Review
Browse files

Merge "NativeDaemonConnector: Improve NativeDaemonException reporting to...

Merge "NativeDaemonConnector: Improve NativeDaemonException reporting to include the actual error response"
parents 70d10c01 ec4caa0f
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -219,19 +219,23 @@ final class NativeDaemonConnector implements Runnable {
                            String.format("Invalid response from daemon (%s)", line));
                }

                if ((code >= 200) && (code < 600))
                if ((code >= 200) && (code < 600)) {
                    complete = true;
                }
                response.add(line);
            } catch (InterruptedException ex) {
                Log.e(TAG, "InterruptedException");
                Log.e(TAG, "Failed to process response", ex);
            }
        }

        if (code >= ResponseCode.FailedRangeStart &&
                code <= ResponseCode.FailedRangeEnd) {
            throw new NativeDaemonConnectorException(code, String.format(
                                               "Command %s failed with code %d",
                                                cmd, code));
            /*
             * Note: The format of the last response in this case is
             *        "NNN <errmsg>"
             */
            throw new NativeDaemonConnectorException(
                    code, cmd, response.get(response.size()-1).substring(4));
        }
        return response;
    }
+8 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ package com.android.server;
public class NativeDaemonConnectorException extends RuntimeException
{
    private int mCode = -1;
    private String mCmd;

    public NativeDaemonConnectorException() {}

@@ -30,13 +31,18 @@ public class NativeDaemonConnectorException extends RuntimeException
        super(error);
    }

    public NativeDaemonConnectorException(int code, String error)
    public NativeDaemonConnectorException(int code, String cmd, String error)
    {
        super(error);
        super(String.format("Cmd {%s} failed with code %d : {%s}", cmd, code, error));
        mCode = code;
        mCmd = cmd;
    }

    public int getCode() {
        return mCode;
    }

    public String getCmd() {
        return mCmd;
    }
}