Home | History | Annotate | Download | only in device
      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     ONLINE,
     29     RECOVERY,
     30     NOT_AVAILABLE;
     31 
     32     /**
     33      * Converts from {@link TestDeviceState} to {@link DeviceState}
     34      * @return the {@link DeviceState} or <code>null</code>
     35      */
     36     DeviceState getDdmsState() {
     37         switch (this) {
     38             case ONLINE:
     39                 return DeviceState.ONLINE;
     40             case RECOVERY:
     41                 return DeviceState.RECOVERY;
     42             default:
     43                 return null;
     44         }
     45     }
     46 
     47     /**
     48      * Returns the {@link TestDeviceState} corresponding to the {@link DeviceState}.
     49      */
     50     static TestDeviceState getStateByDdms(DeviceState ddmsState) {
     51         if (ddmsState == null) {
     52             return TestDeviceState.NOT_AVAILABLE;
     53         }
     54 
     55         switch (ddmsState) {
     56             case ONLINE:
     57                 return TestDeviceState.ONLINE;
     58             case OFFLINE:
     59                 return TestDeviceState.NOT_AVAILABLE;
     60             case RECOVERY:
     61                 return TestDeviceState.RECOVERY;
     62             case UNAUTHORIZED:
     63                 return TestDeviceState.NOT_AVAILABLE;
     64             case BOOTLOADER:
     65                 return TestDeviceState.FASTBOOT;
     66             default:
     67                 return TestDeviceState.NOT_AVAILABLE;
     68         }
     69     }
     70 }
     71