1 /* 2 * Copyright (C) 2007 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.ddmlib; 18 19 import com.android.ddmlib.Device; 20 21 /** 22 * Centralized point to provide a {@link IDebugPortProvider} to ddmlib. 23 * 24 * <p/>When {@link Client} objects are created, they start listening for debuggers on a specific 25 * port. The default behavior is to start with {@link DdmPreferences#getDebugPortBase()} and 26 * increment this value for each new <code>Client</code>. 27 * 28 * <p/>This {@link DebugPortManager} allows applications using ddmlib to provide a custom 29 * port provider on a per-<code>Client</code> basis, depending on the device/emulator they are 30 * running on, and/or their names. 31 */ 32 public class DebugPortManager { 33 34 /** 35 * Classes which implement this interface provide a method that provides a non random 36 * debugger port for a newly created {@link Client}. 37 */ 38 public interface IDebugPortProvider { 39 40 public static final int NO_STATIC_PORT = -1; 41 42 /** 43 * Returns a non-random debugger port for the specified application running on the 44 * specified {@link Device}. 45 * @param device The device the application is running on. 46 * @param appName The application name, as defined in the <code>AndroidManifest.xml</code> 47 * <var>package</var> attribute of the <var>manifest</var> node. 48 * @return The non-random debugger port or {@link #NO_STATIC_PORT} if the {@link Client} 49 * should use the automatic debugger port provider. 50 */ getPort(IDevice device, String appName)51 public int getPort(IDevice device, String appName); 52 } 53 54 private static IDebugPortProvider sProvider = null; 55 56 /** 57 * Sets the {@link IDebugPortProvider} that will be used when a new {@link Client} requests 58 * a debugger port. 59 * @param provider the <code>IDebugPortProvider</code> to use. 60 */ setProvider(IDebugPortProvider provider)61 public static void setProvider(IDebugPortProvider provider) { 62 sProvider = provider; 63 } 64 65 /** 66 * Returns the 67 * @return 68 */ getProvider()69 static IDebugPortProvider getProvider() { 70 return sProvider; 71 } 72 } 73