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

Commit 74ee4a06 authored by Felipe Leme's avatar Felipe Leme Committed by android-build-merger
Browse files

Merge "Added test cases to dumpsys."

am: 5cfc1c05

Change-Id: I87917d89160271a635ac1a42728fb643e1df99ae
parents 83c87d49 5cfc1c05
Loading
Loading
Loading
Loading
+13 −0
Original line number Original line Diff line number Diff line
BasedOnStyle: Google
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: false

AccessModifierOffset: -2
ColumnLimit: 100
CommentPragmas: NOLINT:.*
DerivePointerAlignment: false
IndentWidth: 4
PointerAlignment: Left
TabWidth: 4
UseTab: Never
PenaltyExcessCharacter: 32
+40 −5
Original line number Original line Diff line number Diff line
cc_binary {
cc_defaults {
    name: "dumpsys",
    name: "dumpsys_defaults",


    srcs: ["dumpsys.cpp"],
    cflags: [
        "-Wall",
        "-Werror",
    ],

    srcs: [
        "dumpsys.cpp",
    ],


    shared_libs: [
    shared_libs: [
        "libbase",
        "libbase",
@@ -10,6 +17,34 @@ cc_binary {
        "libbinder",
        "libbinder",
    ],
    ],


    cflags: ["-DXP_UNIX"],
    clang: true,
    //shared_libs: ["librt"],
}

//
// Static library used in testing and executable
//

cc_library_static {
    name: "libdumpsys",

    defaults: ["dumpsys_defaults"],

    export_include_dirs: ["."],
}
}


//
// Executable
//

cc_binary {
    name: "dumpsys",

    defaults: ["dumpsys_defaults"],

    srcs: [
        "main.cpp",
    ],
}

subdirs = ["tests"]
+29 −22
Original line number Original line Diff line number Diff line
/*
/*
 * Command that dumps interesting system state to the log.
 * Copyright (C) 2009 The Android Open Source Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 */


#define LOG_TAG "dumpsys"

#include <algorithm>
#include <algorithm>
#include <chrono>
#include <chrono>
#include <thread>
#include <thread>
@@ -12,7 +21,6 @@
#include <android-base/file.h>
#include <android-base/file.h>
#include <android-base/stringprintf.h>
#include <android-base/stringprintf.h>
#include <android-base/unique_fd.h>
#include <android-base/unique_fd.h>
#include <binder/IServiceManager.h>
#include <binder/Parcel.h>
#include <binder/Parcel.h>
#include <binder/ProcessState.h>
#include <binder/ProcessState.h>
#include <binder/TextOutput.h>
#include <binder/TextOutput.h>
@@ -30,6 +38,8 @@
#include <sys/types.h>
#include <sys/types.h>
#include <unistd.h>
#include <unistd.h>


#include "dumpsys.h"

using namespace android;
using namespace android;
using android::base::StringPrintf;
using android::base::StringPrintf;
using android::base::unique_fd;
using android::base::unique_fd;
@@ -53,7 +63,7 @@ static void usage() {
            "         SERVICE [ARGS]: dumps only service SERVICE, optionally passing ARGS to it\n");
            "         SERVICE [ARGS]: dumps only service SERVICE, optionally passing ARGS to it\n");
}
}


bool IsSkipped(const Vector<String16>& skipped, const String16& service) {
static bool IsSkipped(const Vector<String16>& skipped, const String16& service) {
    for (const auto& candidate : skipped) {
    for (const auto& candidate : skipped) {
        if (candidate == service) {
        if (candidate == service) {
            return true;
            return true;
@@ -62,17 +72,7 @@ bool IsSkipped(const Vector<String16>& skipped, const String16& service) {
    return false;
    return false;
}
}


int main(int argc, char* const argv[])
int Dumpsys::main(int argc, char* const argv[]) {
{
    signal(SIGPIPE, SIG_IGN);
    sp<IServiceManager> sm = defaultServiceManager();
    fflush(stdout);
    if (sm == NULL) {
        ALOGE("Unable to get default service manager!");
        aerr << "dumpsys: Unable to get default service manager!" << endl;
        return 20;
    }

    Vector<String16> services;
    Vector<String16> services;
    Vector<String16> args;
    Vector<String16> args;
    Vector<String16> skippedServices;
    Vector<String16> skippedServices;
@@ -85,6 +85,9 @@ int main(int argc, char* const argv[])
        {     0,           0, 0,  0 }
        {     0,           0, 0,  0 }
    };
    };


    // Must reset optind, otherwise subsequent calls will fail (wouldn't happen on main.cpp, but
    // happens on test cases).
    optind = 1;
    while (1) {
    while (1) {
        int c;
        int c;
        int optionIndex = 0;
        int optionIndex = 0;
@@ -147,7 +150,7 @@ int main(int argc, char* const argv[])


    if (services.empty() || showListOnly) {
    if (services.empty() || showListOnly) {
        // gets all services
        // gets all services
        services = sm->listServices();
        services = sm_->listServices();
        services.sort(sort_func);
        services.sort(sort_func);
        args.add(String16("-a"));
        args.add(String16("-a"));
    }
    }
@@ -159,8 +162,9 @@ int main(int argc, char* const argv[])
        aout << "Currently running services:" << endl;
        aout << "Currently running services:" << endl;


        for (size_t i=0; i<N; i++) {
        for (size_t i=0; i<N; i++) {
            sp<IBinder> service = sm->checkService(services[i]);
            sp<IBinder> service = sm_->checkService(services[i]);
            if (service != NULL) {

            if (service != nullptr) {
                bool skipped = IsSkipped(skippedServices, services[i]);
                bool skipped = IsSkipped(skippedServices, services[i]);
                aout << "  " << services[i] << (skipped ? " (skipped)" : "") << endl;
                aout << "  " << services[i] << (skipped ? " (skipped)" : "") << endl;
            }
            }
@@ -175,8 +179,8 @@ int main(int argc, char* const argv[])
        String16 service_name = std::move(services[i]);
        String16 service_name = std::move(services[i]);
        if (IsSkipped(skippedServices, service_name)) continue;
        if (IsSkipped(skippedServices, service_name)) continue;


        sp<IBinder> service = sm->checkService(service_name);
        sp<IBinder> service = sm_->checkService(service_name);
        if (service != NULL) {
        if (service != nullptr) {
            int sfd[2];
            int sfd[2];


            if (pipe(sfd) != 0) {
            if (pipe(sfd) != 0) {
@@ -262,7 +266,10 @@ int main(int argc, char* const argv[])
            }
            }


            if (timed_out) {
            if (timed_out) {
                aout << endl << "*** SERVICE DUMP TIMEOUT EXPIRED ***" << endl << endl;
                aout << endl
                     << "*** SERVICE '" << service_name << "' DUMP TIMEOUT (" << timeoutArg
                     << "s) EXPIRED ***" << endl
                     << endl;
            }
            }


            if (timed_out || error) {
            if (timed_out || error) {

cmds/dumpsys/dumpsys.h

0 → 100644
+35 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef FRAMEWORK_NATIVE_CMD_DUMPSYS_H_
#define FRAMEWORK_NATIVE_CMD_DUMPSYS_H_

#include <binder/IServiceManager.h>

namespace android {

class Dumpsys {
  public:
    Dumpsys(android::IServiceManager* sm) : sm_(sm) {
    }
    int main(int argc, char* const argv[]);

  private:
    android::IServiceManager* sm_;
};
}

#endif  // FRAMEWORK_NATIVE_CMD_DUMPSYS_H_

cmds/dumpsys/main.cpp

0 → 100644
+43 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Command that dumps interesting system state to the log.
 */

#include "dumpsys.h"

#include <binder/IServiceManager.h>
#include <binder/TextOutput.h>

#include <signal.h>
#include <stdio.h>

using namespace android;

int main(int argc, char* const argv[]) {
    signal(SIGPIPE, SIG_IGN);
    sp<IServiceManager> sm = defaultServiceManager();
    fflush(stdout);
    if (sm == nullptr) {
        ALOGE("Unable to get default service manager!");
        aerr << "dumpsys: Unable to get default service manager!" << endl;
        return 20;
    }

    Dumpsys dumpsys(sm.get());
    return dumpsys.main(argc, argv);
}
Loading