• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
46     private static boolean sThreadUpdate = DEFAULT_INITIAL_THREAD_UPDATE;
47     private static boolean sInitialHeapUpdate = DEFAULT_INITIAL_HEAP_UPDATE;
48 
49     private static int sSelectedDebugPort = DEFAULT_SELECTED_DEBUG_PORT;
50     private static int sDebugPortBase = DEFAULT_DEBUG_PORT_BASE;
51     private static LogLevel sLogLevel = DEFAULT_LOG_LEVEL;
52     private static int sTimeOut = DEFAULT_TIMEOUT;
53 
54     /**
55      * Returns the initial {@link Client} flag for thread updates.
56      * @see #setInitialThreadUpdate(boolean)
57      */
getInitialThreadUpdate()58     public static boolean getInitialThreadUpdate() {
59         return sThreadUpdate;
60     }
61 
62     /**
63      * Sets the initial {@link Client} flag for thread updates.
64      * <p/>This change takes effect right away, for newly created {@link Client} objects.
65      */
setInitialThreadUpdate(boolean state)66     public static void setInitialThreadUpdate(boolean state) {
67         sThreadUpdate = state;
68     }
69 
70     /**
71      * Returns the initial {@link Client} flag for heap updates.
72      * @see #setInitialHeapUpdate(boolean)
73      */
getInitialHeapUpdate()74     public static boolean getInitialHeapUpdate() {
75         return sInitialHeapUpdate;
76     }
77 
78     /**
79      * Sets the initial {@link Client} flag for heap updates.
80      * <p/>If <code>true</code>, the {@link ClientData} will automatically be updated with
81      * the VM heap information whenever a GC happens.
82      * <p/>This change takes effect right away, for newly created {@link Client} objects.
83      */
setInitialHeapUpdate(boolean state)84     public static void setInitialHeapUpdate(boolean state) {
85         sInitialHeapUpdate = state;
86     }
87 
88     /**
89      * Returns the debug port used by the selected {@link Client}.
90      */
getSelectedDebugPort()91     public static int getSelectedDebugPort() {
92         return sSelectedDebugPort;
93     }
94 
95     /**
96      * Sets the debug port used by the selected {@link Client}.
97      * <p/>This change takes effect right away.
98      * @param port the new port to use.
99      */
setSelectedDebugPort(int port)100     public static void setSelectedDebugPort(int port) {
101         sSelectedDebugPort = port;
102 
103         MonitorThread monitorThread = MonitorThread.getInstance();
104         if (monitorThread != null) {
105             monitorThread.setDebugSelectedPort(port);
106         }
107     }
108 
109     /**
110      * Returns the debug port used by the first {@link Client}. Following clients, will use the
111      * next port.
112      */
getDebugPortBase()113     public static int getDebugPortBase() {
114         return sDebugPortBase;
115     }
116 
117     /**
118      * Sets the debug port used by the first {@link Client}.
119      * <p/>Once a port is used, the next Client will use port + 1. Quitting applications will
120      * release their debug port, and new clients will be able to reuse them.
121      * <p/>This must be called before {@link AndroidDebugBridge#init(boolean)}.
122      */
setDebugPortBase(int port)123     public static void setDebugPortBase(int port) {
124         sDebugPortBase = port;
125     }
126 
127     /**
128      * Returns the minimum {@link LogLevel} being displayed.
129      */
getLogLevel()130     public static LogLevel getLogLevel() {
131         return sLogLevel;
132     }
133 
134     /**
135      * Sets the minimum {@link LogLevel} to display.
136      * <p/>This change takes effect right away.
137      */
setLogLevel(String value)138     public static void setLogLevel(String value) {
139         sLogLevel = LogLevel.getByString(value);
140 
141         Log.setLevel(sLogLevel);
142     }
143 
144     /**
145      * Returns the timeout to be used in adb connections (milliseconds).
146      */
getTimeOut()147     public static int getTimeOut() {
148         return sTimeOut;
149     }
150 
151     /**
152      * Sets the timeout value for adb connection.
153      * <p/>This change takes effect for newly created connections only.
154      * @param timeOut the timeout value (milliseconds).
155      */
setTimeOut(int timeOut)156     public static void setTimeOut(int timeOut) {
157         sTimeOut = timeOut;
158     }
159 
160     /**
161      * Non accessible constructor.
162      */
DdmPreferences()163     private DdmPreferences() {
164         // pass, only static methods in the class.
165     }
166 }
167