| /* |
| * Copyright (C) 2019 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package com.android.compatibility.common.util; |
| |
| import android.app.UiAutomation; |
| |
| /** |
| * Utility class for proto dumps. |
| */ |
| public class ProtoUtils { |
| public static final String DUMPSYS_JOB_SCHEDULER = "dumpsys jobscheduler --proto"; |
| |
| /** |
| * Call onto the device with an adb shell command and get the results of |
| * that as a proto of the given type. |
| * |
| * @param clazz A protobuf message class. e.g. MyProto |
| * @param command The adb shell command to run. e.g. "dumpsys jobscheduler --proto" |
| */ |
| public static <T> T getProto(UiAutomation automation, Class<T> clazz, String command) |
| throws Exception { |
| return clazz.cast(clazz.getDeclaredMethod("parseFrom", byte[].class) |
| .invoke(null, SystemUtil.runShellCommandByteOutput(automation, command))); |
| } |
| } |