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.Log.LogLevel; 20 21 /** 22 * Preferences for the ddm library. 23 * <p/>This class does not handle storing the preferences. It is merely a central point for 24 * applications using the ddmlib to override the default values. 25 * <p/>Various components of the ddmlib query this class to get their values. 26 * <p/>Calls to some <code>set##()</code> methods will update the components using the values 27 * right away, while other methods will have no effect once {@link AndroidDebugBridge#init(boolean)} 28 * has been called. 29 * <p/>Check the documentation of each method. 30 */ 31 public final class DdmPreferences { 32 33 /** Default value for thread update flag upon client connection. */ 34 public final static boolean DEFAULT_INITIAL_THREAD_UPDATE = false; 35 /** Default value for heap update flag upon client connection. */ 36 public final static boolean DEFAULT_INITIAL_HEAP_UPDATE = false; 37 /** Default value for the selected client debug port */ 38 public final static int DEFAULT_SELECTED_DEBUG_PORT = 8700; 39 /** Default value for the debug port base */ 40 public final static int DEFAULT_DEBUG_PORT_BASE = 8600; 41 /** Default value for the logcat {@link LogLevel} */ 42 public final static LogLevel DEFAULT_LOG_LEVEL = LogLevel.ERROR; 43 /** Default timeout values for adb connection (milliseconds) */ 44 public static final int DEFAULT_TIMEOUT = 5000; // standard delay, in ms 45 /** Default profiler buffer size (megabytes) */ 46 public static final int DEFAULT_PROFILER_BUFFER_SIZE_MB = 8; 47 /** Default values for the use of the ADBHOST environment variable. */ 48 public final static boolean DEFAULT_USE_ADBHOST = false; 49 public final static String DEFAULT_ADBHOST_VALUE = "127.0.0.1"; 50 51 private static boolean sThreadUpdate = DEFAULT_INITIAL_THREAD_UPDATE; 52 private static boolean sInitialHeapUpdate = DEFAULT_INITIAL_HEAP_UPDATE; 53 54 private static int sSelectedDebugPort = DEFAULT_SELECTED_DEBUG_PORT; 55 private static int sDebugPortBase = DEFAULT_DEBUG_PORT_BASE; 56 private static LogLevel sLogLevel = DEFAULT_LOG_LEVEL; 57 private static int sTimeOut = DEFAULT_TIMEOUT; 58 private static int sProfilerBufferSizeMb = DEFAULT_PROFILER_BUFFER_SIZE_MB; 59 60 private static boolean sUseAdbHost = DEFAULT_USE_ADBHOST; 61 private static String sAdbHostValue = DEFAULT_ADBHOST_VALUE; 62 63 /** 64 * Returns the initial {@link Client} flag for thread updates. 65 * @see #setInitialThreadUpdate(boolean) 66 */ getInitialThreadUpdate()67 public static boolean getInitialThreadUpdate() { 68 return sThreadUpdate; 69 } 70 71 /** 72 * Sets the initial {@link Client} flag for thread updates. 73 * <p/>This change takes effect right away, for newly created {@link Client} objects. 74 */ setInitialThreadUpdate(boolean state)75 public static void setInitialThreadUpdate(boolean state) { 76 sThreadUpdate = state; 77 } 78 79 /** 80 * Returns the initial {@link Client} flag for heap updates. 81 * @see #setInitialHeapUpdate(boolean) 82 */ getInitialHeapUpdate()83 public static boolean getInitialHeapUpdate() { 84 return sInitialHeapUpdate; 85 } 86 87 /** 88 * Sets the initial {@link Client} flag for heap updates. 89 * <p/>If <code>true</code>, the {@link ClientData} will automatically be updated with 90 * the VM heap information whenever a GC happens. 91 * <p/>This change takes effect right away, for newly created {@link Client} objects. 92 */ setInitialHeapUpdate(boolean state)93 public static void setInitialHeapUpdate(boolean state) { 94 sInitialHeapUpdate = state; 95 } 96 97 /** 98 * Returns the debug port used by the selected {@link Client}. 99 */ getSelectedDebugPort()100 public static int getSelectedDebugPort() { 101 return sSelectedDebugPort; 102 } 103 104 /** 105 * Sets the debug port used by the selected {@link Client}. 106 * <p/>This change takes effect right away. 107 * @param port the new port to use. 108 */ setSelectedDebugPort(int port)109 public static void setSelectedDebugPort(int port) { 110 sSelectedDebugPort = port; 111 112 MonitorThread monitorThread = MonitorThread.getInstance(); 113 if (monitorThread != null) { 114 monitorThread.setDebugSelectedPort(port); 115 } 116 } 117 118 /** 119 * Returns the debug port used by the first {@link Client}. Following clients, will use the 120 * next port. 121 */ getDebugPortBase()122 public static int getDebugPortBase() { 123 return sDebugPortBase; 124 } 125 126 /** 127 * Sets the debug port used by the first {@link Client}. 128 * <p/>Once a port is used, the next Client will use port + 1. Quitting applications will 129 * release their debug port, and new clients will be able to reuse them. 130 * <p/>This must be called before {@link AndroidDebugBridge#init(boolean)}. 131 */ setDebugPortBase(int port)132 public static void setDebugPortBase(int port) { 133 sDebugPortBase = port; 134 } 135 136 /** 137 * Returns the minimum {@link LogLevel} being displayed. 138 */ getLogLevel()139 public static LogLevel getLogLevel() { 140 return sLogLevel; 141 } 142 143 /** 144 * Sets the minimum {@link LogLevel} to display. 145 * <p/>This change takes effect right away. 146 */ setLogLevel(String value)147 public static void setLogLevel(String value) { 148 sLogLevel = LogLevel.getByString(value); 149 150 Log.setLevel(sLogLevel); 151 } 152 153 /** 154 * Returns the timeout to be used in adb connections (milliseconds). 155 */ getTimeOut()156 public static int getTimeOut() { 157 return sTimeOut; 158 } 159 160 /** 161 * Sets the timeout value for adb connection. 162 * <p/>This change takes effect for newly created connections only. 163 * @param timeOut the timeout value (milliseconds). 164 */ setTimeOut(int timeOut)165 public static void setTimeOut(int timeOut) { 166 sTimeOut = timeOut; 167 } 168 169 /** 170 * Returns the profiler buffer size (megabytes). 171 */ getProfilerBufferSizeMb()172 public static int getProfilerBufferSizeMb() { 173 return sProfilerBufferSizeMb; 174 } 175 176 /** 177 * Sets the profiler buffer size value. 178 * @param bufferSizeMb the buffer size (megabytes). 179 */ setProfilerBufferSizeMb(int bufferSizeMb)180 public static void setProfilerBufferSizeMb(int bufferSizeMb) { 181 sProfilerBufferSizeMb = bufferSizeMb; 182 } 183 184 /** 185 * Returns a boolean indicating that the user uses or not the variable ADBHOST. 186 */ getUseAdbHost()187 public static boolean getUseAdbHost() { 188 return sUseAdbHost; 189 } 190 191 /** 192 * Sets the value of the boolean indicating that the user uses or not the variable ADBHOST. 193 * @param useAdbHost true if the user uses ADBHOST 194 */ setUseAdbHost(boolean useAdbHost)195 public static void setUseAdbHost(boolean useAdbHost) { 196 sUseAdbHost = useAdbHost; 197 } 198 199 /** 200 * Returns the value of the ADBHOST variable set by the user. 201 */ getAdbHostValue()202 public static String getAdbHostValue() { 203 return sAdbHostValue; 204 } 205 206 /** 207 * Sets the value of the ADBHOST variable. 208 * @param adbHostValue 209 */ setAdbHostValue(String adbHostValue)210 public static void setAdbHostValue(String adbHostValue) { 211 sAdbHostValue = adbHostValue; 212 } 213 214 /** 215 * Non accessible constructor. 216 */ DdmPreferences()217 private DdmPreferences() { 218 // pass, only static methods in the class. 219 } 220 } 221