1 /* 2 * Copyright (C) 2010 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; 17 18 import com.android.ddmlib.IDevice.DeviceState; 19 20 /** 21 * A more fully featured representation of device state than {@link DeviceState}. 22 * <p/> 23 * Logically this should extend {@link DeviceState} to just add the FASTBOOT and NOT_AVAILABLE 24 * states, but extending enums is not allowed. 25 */ 26 public enum TestDeviceState { 27 FASTBOOT, 28 /** Fastbootd mode with is-userspace = true though `adb reboot fastboot` */ 29 FASTBOOTD, 30 ONLINE, 31 RECOVERY, 32 SIDELOAD, 33 NOT_AVAILABLE; 34 35 /** 36 * Converts from {@link TestDeviceState} to {@link DeviceState} 37 * @return the {@link DeviceState} or <code>null</code> 38 */ getDdmsState()39 DeviceState getDdmsState() { 40 switch (this) { 41 case ONLINE: 42 return DeviceState.ONLINE; 43 case RECOVERY: 44 return DeviceState.RECOVERY; 45 case SIDELOAD: 46 return DeviceState.SIDELOAD; 47 default: 48 return null; 49 } 50 } 51 52 /** 53 * Returns the {@link TestDeviceState} corresponding to the {@link DeviceState}. 54 */ getStateByDdms(DeviceState ddmsState)55 static TestDeviceState getStateByDdms(DeviceState ddmsState) { 56 if (ddmsState == null) { 57 return TestDeviceState.NOT_AVAILABLE; 58 } 59 60 switch (ddmsState) { 61 case ONLINE: 62 return TestDeviceState.ONLINE; 63 case OFFLINE: 64 return TestDeviceState.NOT_AVAILABLE; 65 case RECOVERY: 66 return TestDeviceState.RECOVERY; 67 case SIDELOAD: 68 return TestDeviceState.SIDELOAD; 69 case UNAUTHORIZED: 70 return TestDeviceState.NOT_AVAILABLE; 71 case BOOTLOADER: 72 return TestDeviceState.FASTBOOT; 73 case FASTBOOTD: 74 return TestDeviceState.FASTBOOTD; 75 default: 76 return TestDeviceState.NOT_AVAILABLE; 77 } 78 } 79 } 80