PriorityDumper.cpp revision 357988777218502ed68a56a0c8b247ba64b74721
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "include/serviceutils/PriorityDumper.h"
18
19namespace android {
20
21static void getStrippedArgs(Vector<String16>& dest, const Vector<String16>& source,
22                            std::size_t numArgsToStrip) {
23    for (auto it = source.begin() + numArgsToStrip; it != source.end(); it++) {
24        dest.add(*it);
25    }
26}
27
28status_t PriorityDumper::dumpAll(int fd, const Vector<String16>& args) {
29    status_t status;
30    status = dumpCritical(fd, args);
31    if (status != OK) return status;
32    status = dumpHigh(fd, args);
33    if (status != OK) return status;
34    status = dumpNormal(fd, args);
35    if (status != OK) return status;
36    return status;
37}
38
39status_t PriorityDumper::priorityDump(int fd, const Vector<String16>& args) {
40    status_t status;
41    if (args.size() >= 2 && args[0] == PRIORITY_ARG) {
42        String16 priority = args[1];
43        Vector<String16> strippedArgs;
44        getStrippedArgs(strippedArgs, args, 2);
45        if (priority == PRIORITY_ARG_CRITICAL) {
46            status = dumpCritical(fd, strippedArgs);
47        } else if (priority == PRIORITY_ARG_HIGH) {
48            status = dumpHigh(fd, strippedArgs);
49        } else if (priority == PRIORITY_ARG_NORMAL) {
50            status = dumpNormal(fd, strippedArgs);
51        } else {
52            status = dumpAll(fd, args);
53        }
54    } else {
55        status = dumpAll(fd, args);
56    }
57    return status;
58}
59} // namespace android
60