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.AndroidDebugBridge; 19 import com.android.ddmlib.AndroidDebugBridge.IDeviceChangeListener; 20 import com.android.ddmlib.IDevice; 21 22 /** 23 * A wrapper that directs {@link IAndroidDebugBridge} calls to the 'real' 24 * {@link AndroidDebugBridge}. 25 */ 26 class AndroidDebugBridgeWrapper implements IAndroidDebugBridge { 27 28 private AndroidDebugBridge mAdbBridge = null; 29 30 /** 31 * Creates a {@link AndroidDebugBridgeWrapper}. 32 */ 33 AndroidDebugBridgeWrapper() { 34 } 35 36 /** 37 * {@inheritDoc} 38 */ 39 @Override 40 public IDevice[] getDevices() { 41 if (mAdbBridge == null) { 42 throw new IllegalStateException("getDevices called before init"); 43 } 44 return mAdbBridge.getDevices(); 45 } 46 47 /** 48 * {@inheritDoc} 49 */ 50 @Override 51 public void addDeviceChangeListener(IDeviceChangeListener listener) { 52 AndroidDebugBridge.addDeviceChangeListener(listener); 53 } 54 55 /** 56 * {@inheritDoc} 57 */ 58 @Override 59 public void removeDeviceChangeListener(IDeviceChangeListener listener) { 60 AndroidDebugBridge.removeDeviceChangeListener(listener); 61 } 62 63 /** 64 * {@inheritDoc} 65 */ 66 @Override 67 public void init(boolean clientSupport, String adbOsLocation) { 68 AndroidDebugBridge.init(clientSupport); 69 mAdbBridge = AndroidDebugBridge.createBridge(adbOsLocation, false); 70 } 71 72 /** 73 * {@inheritDoc} 74 */ 75 @Override 76 public void terminate() { 77 AndroidDebugBridge.terminate(); 78 } 79 80 /** 81 * {@inheritDoc} 82 */ 83 @Override 84 public void disconnectBridge() { 85 AndroidDebugBridge.disconnectBridge(); 86 } 87 } 88