Home | History | Annotate | Download | only in device
      1 /*
      2  * Copyright (C) 2012 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 
     17 package com.android.tradefed.device;
     18 
     19 import com.android.tradefed.command.remote.DeviceDescriptor;
     20 
     21 import java.util.List;
     22 
     23 /**
     24  * Interface for monitoring state of devices.  Intended to be passed to an {@link IDeviceManager}
     25  * instance, at which point the {@link IDeviceManager} will invoke callbacks as the related events
     26  * are triggered.  Any caching or batching needs to be performed within the {@link IDeviceMonitor}
     27  * instance.
     28  */
     29 public interface IDeviceMonitor {
     30     /**
     31      * A method that will be called after all of the Monitor's @Option fields have been set.
     32      */
     33     public void run();
     34 
     35     /** A method that will be called when the Monitor need to be stopped. */
     36     public void stop();
     37 
     38     /**
     39      * A {@link Runnable}-like class that should return the known devices and their states. This
     40      * class allows the {@link IDeviceMonitor} to fetch device info from its own thread, which
     41      * should avoid deadlocks that may occur while listing devices.
     42      */
     43     public abstract static class DeviceLister {
     44         public abstract List<DeviceDescriptor> listDevices();
     45     }
     46 
     47     /**
     48      * Allows the {@link DeviceLister} to be set.  After a successful attempt to set the Lister,
     49      * implementations may discard all subsequent attempts.
     50      */
     51     public void setDeviceLister(DeviceLister lister);
     52 
     53     /**
     54      * Signals the {@link IDeviceMonitor} that a device state has been changed.
     55      * Monitor implementations should limit the amount of processing and
     56      * IDeviceManager/DeviceLister interaction they do in this method.
     57      */
     58     public void notifyDeviceStateChange(String serial, DeviceAllocationState oldState,
     59             DeviceAllocationState newState);
     60 
     61 }
     62 
     63