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 */ run()33 public void run(); 34 35 /** A method that will be called when the Monitor need to be stopped. */ stop()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 { listDevices()44 public abstract List<DeviceDescriptor> listDevices(); 45 getDeviceDescriptor(String serial)46 public abstract DeviceDescriptor getDeviceDescriptor(String serial); 47 } 48 49 /** 50 * Allows the {@link DeviceLister} to be set. After a successful attempt to set the Lister, 51 * implementations may discard all subsequent attempts. 52 */ setDeviceLister(DeviceLister lister)53 public void setDeviceLister(DeviceLister lister); 54 55 /** 56 * Signals the {@link IDeviceMonitor} that a device state has been changed. 57 * Monitor implementations should limit the amount of processing and 58 * IDeviceManager/DeviceLister interaction they do in this method. 59 */ notifyDeviceStateChange(String serial, DeviceAllocationState oldState, DeviceAllocationState newState)60 public void notifyDeviceStateChange(String serial, DeviceAllocationState oldState, 61 DeviceAllocationState newState); 62 63 } 64 65