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 HOSTLOG_ON_FAILURE(DebugHostLogOnFailureCollector.class), 24 LOGCAT_ON_FAILURE(LogcatOnFailureCollector.class), 25 SCREENSHOT_ON_FAILURE(ScreenshotOnFailureCollector.class); 26 27 private Class<?> mClass; 28 AutoLogCollector(Class<? extends BaseDeviceMetricCollector> className)29 private AutoLogCollector(Class<? extends BaseDeviceMetricCollector> className) { 30 mClass = className; 31 } 32 33 /** Returns the instance of collector associated with the {@link AutoLogCollector} value. */ getInstanceForValue()34 public BaseDeviceMetricCollector getInstanceForValue() { 35 try { 36 Object o = mClass.getDeclaredConstructor().newInstance(); 37 return (BaseDeviceMetricCollector) o; 38 } catch (InstantiationException 39 | IllegalAccessException 40 | InvocationTargetException 41 | NoSuchMethodException e) { 42 throw new RuntimeException(e); 43 } 44 } 45 } 46