PriorityDumper.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #include "include/serviceutils/PriorityDumper.h"
  17. namespace android {
  18. const char16_t PriorityDumper::PROTO_ARG[] = u"--proto";
  19. const char16_t PriorityDumper::PRIORITY_ARG[] = u"--dump-priority";
  20. const char16_t PriorityDumper::PRIORITY_ARG_CRITICAL[] = u"CRITICAL";
  21. const char16_t PriorityDumper::PRIORITY_ARG_HIGH[] = u"HIGH";
  22. const char16_t PriorityDumper::PRIORITY_ARG_NORMAL[] = u"NORMAL";
  23. enum class PriorityType { INVALID, CRITICAL, HIGH, NORMAL };
  24. static PriorityType getPriorityType(const String16& arg) {
  25. if (arg == PriorityDumper::PRIORITY_ARG_CRITICAL) {
  26. return PriorityType::CRITICAL;
  27. } else if (arg == PriorityDumper::PRIORITY_ARG_HIGH) {
  28. return PriorityType::HIGH;
  29. } else if (arg == PriorityDumper::PRIORITY_ARG_NORMAL) {
  30. return PriorityType::NORMAL;
  31. }
  32. return PriorityType::INVALID;
  33. }
  34. status_t PriorityDumper::dumpAll(int fd, const Vector<String16>& args, bool asProto) {
  35. status_t status;
  36. status = dumpCritical(fd, args, asProto);
  37. if (status != OK) return status;
  38. status = dumpHigh(fd, args, asProto);
  39. if (status != OK) return status;
  40. status = dumpNormal(fd, args, asProto);
  41. if (status != OK) return status;
  42. return status;
  43. }
  44. status_t PriorityDumper::priorityDump(int fd, const Vector<String16>& args) {
  45. status_t status;
  46. bool asProto = false;
  47. PriorityType priority = PriorityType::INVALID;
  48. Vector<String16> strippedArgs;
  49. for (uint32_t argIndex = 0; argIndex < args.size(); argIndex++) {
  50. if (args[argIndex] == PROTO_ARG) {
  51. asProto = true;
  52. } else if (args[argIndex] == PRIORITY_ARG) {
  53. if (argIndex + 1 < args.size()) {
  54. argIndex++;
  55. priority = getPriorityType(args[argIndex]);
  56. }
  57. } else {
  58. strippedArgs.add(args[argIndex]);
  59. }
  60. }
  61. switch (priority) {
  62. case PriorityType::CRITICAL:
  63. status = dumpCritical(fd, strippedArgs, asProto);
  64. break;
  65. case PriorityType::HIGH:
  66. status = dumpHigh(fd, strippedArgs, asProto);
  67. break;
  68. case PriorityType::NORMAL:
  69. status = dumpNormal(fd, strippedArgs, asProto);
  70. break;
  71. default:
  72. status = dumpAll(fd, strippedArgs, asProto);
  73. break;
  74. }
  75. return status;
  76. }
  77. } // namespace android