blob: 9851188b4682124a656dacd308d3517ea226221c [file] [log] [blame]
Vishnu Nair33fd3be2017-09-27 11:06:37 -07001/*
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
Vishnu Nair35798872017-10-06 16:00:36 -070017#include "include/serviceutils/PriorityDumper.h"
Vishnu Nair33fd3be2017-09-27 11:06:37 -070018
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
Vishnu Nair35798872017-10-06 16:00:36 -070028status_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;
Vishnu Nair33fd3be2017-09-27 11:06:37 -070041 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) {
Vishnu Nair35798872017-10-06 16:00:36 -070046 status = dumpCritical(fd, strippedArgs);
Vishnu Nair33fd3be2017-09-27 11:06:37 -070047 } else if (priority == PRIORITY_ARG_HIGH) {
Vishnu Nair35798872017-10-06 16:00:36 -070048 status = dumpHigh(fd, strippedArgs);
Vishnu Nair33fd3be2017-09-27 11:06:37 -070049 } else if (priority == PRIORITY_ARG_NORMAL) {
Vishnu Nair35798872017-10-06 16:00:36 -070050 status = dumpNormal(fd, strippedArgs);
Vishnu Nair33fd3be2017-09-27 11:06:37 -070051 } else {
Vishnu Nair35798872017-10-06 16:00:36 -070052 status = dumpAll(fd, args);
Vishnu Nair33fd3be2017-09-27 11:06:37 -070053 }
54 } else {
Vishnu Nair35798872017-10-06 16:00:36 -070055 status = dumpAll(fd, args);
Vishnu Nair33fd3be2017-09-27 11:06:37 -070056 }
Vishnu Nair35798872017-10-06 16:00:36 -070057 return status;
Vishnu Nair33fd3be2017-09-27 11:06:37 -070058}
Vishnu Nair35798872017-10-06 16:00:36 -070059} // namespace android