blob: 967dee5d2964e74115d6dcf8d8c9cc08bbfd1704 [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
Vishnu Nair6a408532017-10-24 09:11:27 -070021const char16_t PriorityDumper::PROTO_ARG[] = u"--proto";
22const char16_t PriorityDumper::PRIORITY_ARG[] = u"--dump-priority";
23const char16_t PriorityDumper::PRIORITY_ARG_CRITICAL[] = u"CRITICAL";
24const char16_t PriorityDumper::PRIORITY_ARG_HIGH[] = u"HIGH";
25const char16_t PriorityDumper::PRIORITY_ARG_NORMAL[] = u"NORMAL";
26
27enum class PriorityType { INVALID, CRITICAL, HIGH, NORMAL };
28
29static PriorityType getPriorityType(const String16& arg) {
30 if (arg == PriorityDumper::PRIORITY_ARG_CRITICAL) {
31 return PriorityType::CRITICAL;
32 } else if (arg == PriorityDumper::PRIORITY_ARG_HIGH) {
33 return PriorityType::HIGH;
34 } else if (arg == PriorityDumper::PRIORITY_ARG_NORMAL) {
35 return PriorityType::NORMAL;
Vishnu Nair33fd3be2017-09-27 11:06:37 -070036 }
Vishnu Nair6a408532017-10-24 09:11:27 -070037 return PriorityType::INVALID;
Vishnu Nair33fd3be2017-09-27 11:06:37 -070038}
39
Vishnu Nair6a408532017-10-24 09:11:27 -070040status_t PriorityDumper::dumpAll(int fd, const Vector<String16>& args, bool asProto) {
Vishnu Nair35798872017-10-06 16:00:36 -070041 status_t status;
Vishnu Nair6a408532017-10-24 09:11:27 -070042 status = dumpCritical(fd, args, asProto);
Vishnu Nair35798872017-10-06 16:00:36 -070043 if (status != OK) return status;
Vishnu Nair6a408532017-10-24 09:11:27 -070044 status = dumpHigh(fd, args, asProto);
Vishnu Nair35798872017-10-06 16:00:36 -070045 if (status != OK) return status;
Vishnu Nair6a408532017-10-24 09:11:27 -070046 status = dumpNormal(fd, args, asProto);
Vishnu Nair35798872017-10-06 16:00:36 -070047 if (status != OK) return status;
48 return status;
49}
50
51status_t PriorityDumper::priorityDump(int fd, const Vector<String16>& args) {
52 status_t status;
Vishnu Nair6a408532017-10-24 09:11:27 -070053 bool asProto = false;
54 PriorityType priority = PriorityType::INVALID;
55
56 Vector<String16> strippedArgs;
57 for (uint32_t argIndex = 0; argIndex < args.size(); argIndex++) {
58 if (args[argIndex] == PROTO_ARG) {
59 asProto = true;
60 } else if (args[argIndex] == PRIORITY_ARG) {
61 if (argIndex + 1 < args.size()) {
62 argIndex++;
63 priority = getPriorityType(args[argIndex]);
64 }
Vishnu Nair33fd3be2017-09-27 11:06:37 -070065 } else {
Vishnu Nair6a408532017-10-24 09:11:27 -070066 strippedArgs.add(args[argIndex]);
Vishnu Nair33fd3be2017-09-27 11:06:37 -070067 }
Vishnu Nair6a408532017-10-24 09:11:27 -070068 }
69
70 switch (priority) {
71 case PriorityType::CRITICAL:
72 status = dumpCritical(fd, strippedArgs, asProto);
73 break;
74 case PriorityType::HIGH:
75 status = dumpHigh(fd, strippedArgs, asProto);
76 break;
77 case PriorityType::NORMAL:
78 status = dumpNormal(fd, strippedArgs, asProto);
79 break;
80 default:
81 status = dumpAll(fd, strippedArgs, asProto);
82 break;
Vishnu Nair33fd3be2017-09-27 11:06:37 -070083 }
Vishnu Nair35798872017-10-06 16:00:36 -070084 return status;
Vishnu Nair33fd3be2017-09-27 11:06:37 -070085}
Vishnu Nair35798872017-10-06 16:00:36 -070086} // namespace android