PriorityDump.java revision e78b01ad2d7779ad3a6acfe5acd0068e4840665c
1f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme/** 2f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * Copyright (c) 2016, The Android Open Source Project 3f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * 4f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * Licensed under the Apache License, Version 2.0 (the "License"); 5f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * you may not use this file except in compliance with the License. 6f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * You may obtain a copy of the License at 7f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * 8f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * http://www.apache.org/licenses/LICENSE-2.0 9f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * 10f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * Unless required by applicable law or agreed to in writing, software 11f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * distributed under the License is distributed on an "AS IS" BASIS, 12f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * See the License for the specific language governing permissions and 14f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * limitations under the License. 15f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme */ 16f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 17f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Lemepackage com.android.server.utils; 18f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 19e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nairimport android.annotation.IntDef; 20e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair 21f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Lemeimport java.io.FileDescriptor; 22f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Lemeimport java.io.PrintWriter; 23e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nairimport java.lang.annotation.Retention; 24e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nairimport java.lang.annotation.RetentionPolicy; 25e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nairimport java.util.ArrayList; 26e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nairimport java.util.Arrays; 27e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nairimport java.util.Iterator; 28f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 29f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme/** 30f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * Helper for {@link android.os.Binder#dump(java.io.FileDescriptor, String[])} that supports the 31e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair * {@link #PRIORITY_ARG} and {@link #PROTO_ARG} arguments. 32f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * <p> 33f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * Typical usage: 34f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * 35f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * <pre><code> 36f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Lemepublic class SpringfieldNuclearPowerPlant extends Binder { 37f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 38f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme private final PriorityDump.PriorityDumper mPriorityDumper = new PriorityDump.PriorityDumper() { 39f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 40f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme @Override 41e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair public void dumpCritical(FileDescriptor fd, PrintWriter pw, String[] args, boolean asProto) { 42e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair if (asProto) { 43e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair ProtoOutputStream proto = new ProtoOutputStream(fd); 44e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair proto.write(SpringfieldProto.DONUTS, 1); 45e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair proto.flush(); 46e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair } else { 47e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair pw.println("Donuts in the box: 1"); 48e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair } 49f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme } 50f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 51f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme @Override 52f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme public void dumpNormal(FileDescriptor fd, PrintWriter pw, String[] args) { 53e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair if (asProto) { 54e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair ProtoOutputStream proto = new ProtoOutputStream(fd); 55e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair proto.write(SpringfieldProto.REACTOR_STATUS, DANGER_MELTDOWN_IMMINENT); 56e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair proto.flush(); 57e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair } else { 58e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair pw.println("Nuclear reactor status: DANGER - MELTDOWN IMMINENT"); 59e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair } 60f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme } 61f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme }; 62f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 63f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme @Override 64f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { 65f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme PriorityDump.dump(mPriorityDumper, fd, pw, args); 66f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme } 67f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme} 68f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 69f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * </code></pre> 70f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * 71f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * <strong>Disclaimer</strong>: a real-life service should prioritize core status over donuts :-) 72f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * 73f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * <p>Then to invoke it: 74f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * 75f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * <pre><code> 76f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * 77f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme $ adb shell dumpsys snpp 78f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme Donuts in the box: 1 79f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme Nuclear reactor status: DANGER - MELTDOWN IMMINENT 80f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 81f3648e04f431b39524b469c75fa2c77a3e771faeVishnu Nair $ adb shell dumpsys snpp --dump-priority CRITICAL 82f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme Donuts in the box: 1 83f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 84f3648e04f431b39524b469c75fa2c77a3e771faeVishnu Nair $ adb shell dumpsys snpp --dump-priority NORMAL 85f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme Nuclear reactor status: DANGER - MELTDOWN IMMINENT 86f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 87e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair $ adb shell dumpsys snpp --dump-priority CRITICAL --proto 88e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair //binary output 89e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair 90f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * </code></pre> 91f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * 92f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * 93f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * 94f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * <p>To run the unit tests: 95f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * <pre><code> 96f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * 97f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme mmm -j32 frameworks/base/services/tests/servicestests/ && \ 98f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme adb install -r -g ${ANDROID_PRODUCT_OUT}/data/app/FrameworksServicesTests/FrameworksServicesTests.apk && \ 99f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme adb shell am instrument -e class "com.android.server.utils.PriorityDumpTest" \ 100f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme -w "com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner" 101f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 102f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * </code></pre> 103f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * 104f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * 105f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * @hide 106f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme */ 107f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Lemepublic final class PriorityDump { 108f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 109f3648e04f431b39524b469c75fa2c77a3e771faeVishnu Nair public static final String PRIORITY_ARG = "--dump-priority"; 110e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair public static final String PROTO_ARG = "--proto"; 111f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 112f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme private PriorityDump() { 113f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme throw new UnsupportedOperationException(); 114f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme } 115f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 116e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair /** Enum to switch through supported priority types */ 117e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair @Retention(RetentionPolicy.SOURCE) 118e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair @IntDef({PRIORITY_TYPE_INVALID, PRIORITY_TYPE_CRITICAL, PRIORITY_TYPE_HIGH, 119e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair PRIORITY_TYPE_NORMAL}) 120e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair private @interface PriorityType { } 121e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair private static final int PRIORITY_TYPE_INVALID = 0; 122e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair private static final int PRIORITY_TYPE_CRITICAL = 1; 123e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair private static final int PRIORITY_TYPE_HIGH = 2; 124e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair private static final int PRIORITY_TYPE_NORMAL = 3; 125e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair 126f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme /** 127e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair * Parses {@code args} matching {@code --dump-priority} and/or {@code --proto}. The matching 128e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair * arguments are stripped. 129e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair * <p> 130e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair * If priority args are passed as an argument, it will call the appropriate method and if proto 131e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair * args are passed then the {@code asProto} flag is set. 132f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * <p> 133f3648e04f431b39524b469c75fa2c77a3e771faeVishnu Nair * For example, if called as {@code --dump-priority HIGH arg1 arg2 arg3}, it will call 134e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair * <code>dumper.dumpHigh(fd, pw, {"arg1", "arg2", "arg3"}, false) </code> 135f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * <p> 136f3648e04f431b39524b469c75fa2c77a3e771faeVishnu Nair * If the {@code --dump-priority} is not set, it calls 137e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair * {@link PriorityDumper#dump(FileDescriptor, PrintWriter, String[], boolean)} passing the whole 138f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * {@code args} instead. 139f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme */ 140f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme public static void dump(PriorityDumper dumper, FileDescriptor fd, PrintWriter pw, 141f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme String[] args) { 142e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair boolean asProto = false; 143e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair @PriorityType int priority = PRIORITY_TYPE_INVALID; 144e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair 145e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair if (args == null) { 146e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair dumper.dump(fd, pw, args, asProto); 147e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair return; 148e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair } 149e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair 150e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair String[] strippedArgs = new String[args.length]; 151e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair int strippedCount = 0; 152e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair for (int argIndex = 0; argIndex < args.length; argIndex++) { 153e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair if (args[argIndex].equals(PROTO_ARG)) { 154e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair asProto = true; 155e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair } else if (args[argIndex].equals(PRIORITY_ARG)) { 156e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair if (argIndex + 1 < args.length) { 157e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair argIndex++; 158e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair priority = getPriorityType(args[argIndex]); 159f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme } 160e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair } else { 161e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair strippedArgs[strippedCount++] = args[argIndex]; 162e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair } 163e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair } 164e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair 165e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair if (strippedCount < args.length) { 166e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair strippedArgs = Arrays.copyOf(strippedArgs, strippedCount); 167e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair } 168e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair 169e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair switch (priority) { 170e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair case PRIORITY_TYPE_CRITICAL: { 171e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair dumper.dumpCritical(fd, pw, strippedArgs, asProto); 172e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair return; 173e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair } 174e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair case PRIORITY_TYPE_HIGH: { 175e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair dumper.dumpHigh(fd, pw, strippedArgs, asProto); 176e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair return; 177e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair } 178e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair case PRIORITY_TYPE_NORMAL: { 179e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair dumper.dumpNormal(fd, pw, strippedArgs, asProto); 180e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair return; 181e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair } 182e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair default: { 183e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair dumper.dump(fd, pw, strippedArgs, asProto); 184e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair return; 185f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme } 186f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme } 187f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme } 188f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 189f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme /** 190e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair * Converts priority argument type to enum. 191f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme */ 192e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair private static @PriorityType int getPriorityType(String arg) { 193e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair switch (arg) { 194e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair case "CRITICAL": { 195e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair return PRIORITY_TYPE_CRITICAL; 196e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair } 197e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair case "HIGH": { 198e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair return PRIORITY_TYPE_HIGH; 199e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair } 200e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair case "NORMAL": { 201e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair return PRIORITY_TYPE_NORMAL; 202e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair } 203e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair } 204e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair return PRIORITY_TYPE_INVALID; 205f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme } 206f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 207f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme /** 208f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * Helper for {@link android.os.Binder#dump(java.io.FileDescriptor, String[])} that supports the 209e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair * {@link #PRIORITY_ARG} and {@link #PROTO_ARG} arguments. 210f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * 211f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * @hide 212f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme */ 213e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair public interface PriorityDumper { 214f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 215f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme /** 216f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * Dumps only the critical section. 217f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme */ 218f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme @SuppressWarnings("unused") 219e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair default void dumpCritical(FileDescriptor fd, PrintWriter pw, String[] args, 220e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair boolean asProto) { 221f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme } 222f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 223f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme /** 224f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * Dumps only the high-priority section. 225f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme */ 226f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme @SuppressWarnings("unused") 227e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair default void dumpHigh(FileDescriptor fd, PrintWriter pw, String[] args, boolean asProto) { 228f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme } 229f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 230f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme /** 231f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * Dumps only the normal section. 232f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme */ 233f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme @SuppressWarnings("unused") 234e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair default void dumpNormal(FileDescriptor fd, PrintWriter pw, String[] args, boolean asProto) { 235f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme } 236f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme 237f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme /** 238f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * Dumps all sections. 239f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * <p> 240f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme * This method is called when 241e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair * {@link PriorityDump#dump(PriorityDumper, FileDescriptor, PrintWriter, String[], boolean)} 242e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair * is called without priority arguments. By default, it calls the 3 {@code dumpTYPE} 243e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair * methods, so sub-classes just need to implement the priority types they support. 244f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme */ 245f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme @SuppressWarnings("unused") 246e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair default void dump(FileDescriptor fd, PrintWriter pw, String[] args, boolean asProto) { 247e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair dumpCritical(fd, pw, args, asProto); 248e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair dumpHigh(fd, pw, args, asProto); 249e78b01ad2d7779ad3a6acfe5acd0068e4840665cVishnu Nair dumpNormal(fd, pw, args, asProto); 250f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme } 251f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme } 252f4006d9b0be123b2a4e874b89eb4a431d3d49c8bFelipe Leme} 253