• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     // TODO: Remove this temporary value after the new collector is verified to work as expected.
26     CODE_COVERAGE(CodeCoverageCollector.class),
27     GCOV_COVERAGE(GcovCodeCoverageCollector.class),
28     GCOV_KERNEL_COVERAGE(GcovKernelCodeCoverageCollector.class),
29     HOSTLOG_ON_FAILURE(DebugHostLogOnFailureCollector.class),
30     JAVA_COVERAGE(JavaCodeCoverageCollector.class),
31     LOGCAT_ON_FAILURE(LogcatOnFailureCollector.class),
32     SCREENSHOT_ON_FAILURE(ScreenshotOnFailureCollector.class),
33     MODULE_LOGCAT(ModuleLogcatCollector.class),
34     DEVICE_TRACE(DeviceTraceCollector.class);
35 
36     private Class<?> mClass;
37 
AutoLogCollector(Class<? extends BaseDeviceMetricCollector> className)38     private AutoLogCollector(Class<? extends BaseDeviceMetricCollector> className) {
39         mClass = className;
40     }
41 
42     /** Returns the instance of collector associated with the {@link AutoLogCollector} value. */
getInstanceForValue()43     public BaseDeviceMetricCollector getInstanceForValue() {
44         try {
45             Object o = mClass.getDeclaredConstructor().newInstance();
46             return (BaseDeviceMetricCollector) o;
47         } catch (InstantiationException
48                 | IllegalAccessException
49                 | InvocationTargetException
50                 | NoSuchMethodException e) {
51             throw new RuntimeException(e);
52         }
53     }
54 }
55