1 /*
2  * Copyright (C) 2019 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 package com.android.tradefed.device.metric;
17 
18 import java.lang.reflect.InvocationTargetException;
19 
20 /** Enumeration describing which collector can automatically be handled by the harness. */
21 public enum AutoLogCollector {
22     BUGREPORTZ_ON_FAILURE(BugreportzOnFailureCollector.class),
23     BUGREPORTZ_ON_TESTCASE_FAILURE(BugreportzOnTestCaseFailureCollector.class),
24     CLANG_COVERAGE(ClangCodeCoverageCollector.class),
25     GCOV_COVERAGE(GcovCodeCoverageCollector.class),
26     GCOV_KERNEL_COVERAGE(GcovKernelCodeCoverageCollector.class),
27     HOSTLOG_ON_FAILURE(DebugHostLogOnFailureCollector.class),
28     JAVA_COVERAGE(JavaCodeCoverageCollector.class),
29     LOGCAT_ON_FAILURE(LogcatOnFailureCollector.class),
30     SCREENSHOT_ON_FAILURE(ScreenshotOnFailureCollector.class),
31     MODULE_LOGCAT(ModuleLogcatCollector.class),
32     DEVICE_TRACE(DeviceTraceCollector.class);
33 
34     private Class<?> mClass;
35 
AutoLogCollector(Class<? extends BaseDeviceMetricCollector> className)36     private AutoLogCollector(Class<? extends BaseDeviceMetricCollector> className) {
37         mClass = className;
38     }
39 
40     /** Returns the instance of collector associated with the {@link AutoLogCollector} value. */
getInstanceForValue()41     public BaseDeviceMetricCollector getInstanceForValue() {
42         try {
43             Object o = mClass.getDeclaredConstructor().newInstance();
44             return (BaseDeviceMetricCollector) o;
45         } catch (InstantiationException
46                 | IllegalAccessException
47                 | InvocationTargetException
48                 | NoSuchMethodException e) {
49             throw new RuntimeException(e);
50         }
51     }
52 }
53