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

Commit 17fe8de6 authored by Bookatz's avatar Bookatz
Browse files

Allow statsd_testdrive to work in root

LocalDrive needs to handle the situation whereby the caller does 'adb
root' in between calls, and therefore runs everything as shell.

TestDrive is a single-call, so it can just run as the caller. That's
what it used to do, but a recent refactoring made some of its calls via
shell, causes an error. This fixes that.

Test: manual confirmation that it worked for both shell and root
Change-Id: I5e31cdd59d61290a480cb6fae107170616daabc0
parent 7d97bf04
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -70,9 +70,16 @@ public class Utils {
    /**
     * Dumps the report from the device and converts it to a ConfigMetricsReportList.
     * Erases the data if clearData is true.
     * @param configId id of the config
     * @param clearData whether to erase the report data from statsd after getting the report.
     * @param useShellUid Pulls data for the {@link SHELL_UID} instead of the caller's uid.
     * @param logger Logger to log error messages
     * @return
     * @throws IOException
     * @throws InterruptedException
     */
    public static ConfigMetricsReportList getReportList(long configId, boolean clearData,
            Logger logger) throws IOException, InterruptedException {
            boolean useShellUid, Logger logger) throws IOException, InterruptedException {
        try {
            File outputFile = File.createTempFile("statsdret", ".bin");
            outputFile.deleteOnExit();
@@ -82,7 +89,7 @@ public class Utils {
                    "adb",
                    "shell",
                    CMD_DUMP_REPORT,
                    SHELL_UID,
                    useShellUid ? SHELL_UID : "",
                    String.valueOf(configId),
                    clearData ? "" : "--keep_data",
                    "--include_current_bucket",
@@ -93,8 +100,8 @@ public class Utils {
        } catch (com.google.protobuf.InvalidProtocolBufferException e) {
            logger.severe("Failed to fetch and parse the statsd output report. "
                            + "Perhaps there is not a valid statsd config for the requested "
                            + "uid=" + SHELL_UID
                            + ", configId=" + configId
                            + (useShellUid ? ("uid=" + SHELL_UID + ", ") : "")
                            + "configId=" + configId
                            + ".");
            throw (e);
        }
+3 −3
Original line number Diff line number Diff line
@@ -165,7 +165,7 @@ public class LocalDrive {
            try {
                Utils.runCommand(null, sLogger, "adb", "shell", Utils.CMD_REMOVE_CONFIG,
                        Utils.SHELL_UID, String.valueOf(configId));
                Utils.getReportList(configId, true /* clearData */, sLogger);
                Utils.getReportList(configId, true /* clearData */, true /* SHELL_UID */, sLogger);
            } catch (InterruptedException | IOException e) {
                sLogger.severe("Failed to remove config: " + e.getMessage());
                return false;
@@ -234,7 +234,7 @@ public class LocalDrive {
        // Even if the args request no modifications, we still parse it to make sure it's valid.
        ConfigMetricsReportList reportList;
        try {
            reportList = Utils.getReportList(configId, clearData, sLogger);
            reportList = Utils.getReportList(configId, clearData, true /* SHELL_UID */, sLogger);
        } catch (IOException | InterruptedException e) {
            sLogger.severe("Failed to get report list: " + e.getMessage());
            return false;
@@ -278,7 +278,7 @@ public class LocalDrive {
        sLogger.fine(String.format("cmdClear with %d", configId));

        try {
            Utils.getReportList(configId, true /* clearData */, sLogger);
            Utils.getReportList(configId, true /* clearData */, true /* SHELL_UID */, sLogger);
        } catch (IOException | InterruptedException e) {
            sLogger.severe("Failed to get report list: " + e.getMessage());
            return false;
+1 −1
Original line number Diff line number Diff line
@@ -165,7 +165,7 @@ public class TestDrive {
    }

    private void dumpMetrics() throws Exception {
        ConfigMetricsReportList reportList = Utils.getReportList(CONFIG_ID, true, logger);
        ConfigMetricsReportList reportList = Utils.getReportList(CONFIG_ID, true, false, logger);
        // We may get multiple reports. Take the last one.
        ConfigMetricsReport report = reportList.getReports(reportList.getReportsCount() - 1);
        // Really should be only one metric.