aboutsummaryrefslogtreecommitdiffstats
path: root/ddms/libs
diff options
context:
space:
mode:
authorSiva Velusamy <vsiva@google.com>2013-02-07 16:09:50 -0800
committerSiva Velusamy <vsiva@google.com>2013-02-07 16:54:23 -0800
commitd93ad48471e2cffc8d48f75725748a8f66dce064 (patch)
tree78b62d7262e5667ad8d87c60c77f92571ded9fc3 /ddms/libs
parentffa0dd1e8e59cb6573a45e8b841e174006d1f998 (diff)
downloadsdk-d93ad48471e2cffc8d48f75725748a8f66dce064.zip
sdk-d93ad48471e2cffc8d48f75725748a8f66dce064.tar.gz
sdk-d93ad48471e2cffc8d48f75725748a8f66dce064.tar.bz2
Move UI data in LogCatFilter to a separate class
There were a couple of pieces of UI data (unread count & flag indicating whether a filter is transient) associated with a filter. This CL moves both of them out into a separate class. The panel maintains a mapping from a filter to its associated UI data. The core filter class has been moved out into ddmlib. Change-Id: I325176c33094d583c0ef9abe890e5462aeeb4945
Diffstat (limited to 'ddms/libs')
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilter.java280
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterContentProvider.java2
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterData.java81
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterLabelProvider.java17
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterSettingsSerializer.java9
-rw-r--r--ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java64
-rw-r--r--ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatFilterSettingsSerializerTest.java13
-rw-r--r--ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatFilterTest.java164
8 files changed, 160 insertions, 470 deletions
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilter.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilter.java
deleted file mode 100644
index 3024978..0000000
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilter.java
+++ /dev/null
@@ -1,280 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.ddmuilib.logcat;
-
-import com.android.ddmlib.Log.LogLevel;
-import com.android.ddmlib.logcat.LogCatMessage;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
-
-/**
- * A Filter for logcat messages. A filter can be constructed to match
- * different fields of a logcat message. It can then be queried to see if
- * a message matches the filter's settings.
- */
-public final class LogCatFilter {
- private static final String PID_KEYWORD = "pid:"; //$NON-NLS-1$
- private static final String APP_KEYWORD = "app:"; //$NON-NLS-1$
- private static final String TAG_KEYWORD = "tag:"; //$NON-NLS-1$
- private static final String TEXT_KEYWORD = "text:"; //$NON-NLS-1$
-
- private final String mName;
- private final String mTag;
- private final String mText;
- private final String mPid;
- private final String mAppName;
- private final LogLevel mLogLevel;
-
- /** Indicates the number of messages that match this filter, but have not
- * yet been read by the user. This is really metadata about this filter
- * necessary for the UI. If we ever end up needing to store more metadata,
- * then it is probably better to move it out into a separate class. */
- private int mUnreadCount;
-
- /** Indicates that this filter is transient, and should not be persisted
- * across Eclipse sessions. */
- private boolean mTransient;
-
- private boolean mCheckPid;
- private boolean mCheckAppName;
- private boolean mCheckTag;
- private boolean mCheckText;
-
- private Pattern mAppNamePattern;
- private Pattern mTagPattern;
- private Pattern mTextPattern;
-
- /**
- * Construct a filter with the provided restrictions for the logcat message. All the text
- * fields accept Java regexes as input, but ignore invalid regexes. Filters are saved and
- * restored across Eclipse sessions unless explicitly marked transient using
- * {@link LogCatFilter#setTransient}.
- * @param name name for the filter
- * @param tag value for the logcat message's tag field.
- * @param text value for the logcat message's text field.
- * @param pid value for the logcat message's pid field.
- * @param appName value for the logcat message's app name field.
- * @param logLevel value for the logcat message's log level. Only messages of
- * higher priority will be accepted by the filter.
- */
- public LogCatFilter(String name, String tag, String text, String pid, String appName,
- LogLevel logLevel) {
- mName = name.trim();
- mTag = tag.trim();
- mText = text.trim();
- mPid = pid.trim();
- mAppName = appName.trim();
- mLogLevel = logLevel;
-
- mUnreadCount = 0;
-
- // By default, all filters are persistent. Transient filters should explicitly
- // mark it so by calling setTransient.
- mTransient = false;
-
- mCheckPid = mPid.length() != 0;
-
- if (mAppName.length() != 0) {
- try {
- mAppNamePattern = Pattern.compile(mAppName, getPatternCompileFlags(mAppName));
- mCheckAppName = true;
- } catch (PatternSyntaxException e) {
- mCheckAppName = false;
- }
- }
-
- if (mTag.length() != 0) {
- try {
- mTagPattern = Pattern.compile(mTag, getPatternCompileFlags(mTag));
- mCheckTag = true;
- } catch (PatternSyntaxException e) {
- mCheckTag = false;
- }
- }
-
- if (mText.length() != 0) {
- try {
- mTextPattern = Pattern.compile(mText, getPatternCompileFlags(mText));
- mCheckText = true;
- } catch (PatternSyntaxException e) {
- mCheckText = false;
- }
- }
- }
-
- /**
- * Obtain the flags to pass to {@link Pattern#compile(String, int)}. This method
- * tries to figure out whether case sensitive matching should be used. It is based on
- * the following heuristic: if the regex has an upper case character, then the match
- * will be case sensitive. Otherwise it will be case insensitive.
- */
- private int getPatternCompileFlags(String regex) {
- for (char c : regex.toCharArray()) {
- if (Character.isUpperCase(c)) {
- return 0;
- }
- }
-
- return Pattern.CASE_INSENSITIVE;
- }
-
- /**
- * Construct a list of {@link LogCatFilter} objects by decoding the query.
- * @param query encoded search string. The query is simply a list of words (can be regexes)
- * a user would type in a search bar. These words are searched for in the text field of
- * each collected logcat message. To search in a different field, the word could be prefixed
- * with a keyword corresponding to the field name. Currently, the following keywords are
- * supported: "pid:", "tag:" and "text:". Invalid regexes are ignored.
- * @param minLevel minimum log level to match
- * @return list of filter settings that fully match the given query
- */
- public static List<LogCatFilter> fromString(String query, LogLevel minLevel) {
- List<LogCatFilter> filterSettings = new ArrayList<LogCatFilter>();
-
- for (String s : query.trim().split(" ")) {
- String tag = "";
- String text = "";
- String pid = "";
- String app = "";
-
- if (s.startsWith(PID_KEYWORD)) {
- pid = s.substring(PID_KEYWORD.length());
- } else if (s.startsWith(APP_KEYWORD)) {
- app = s.substring(APP_KEYWORD.length());
- } else if (s.startsWith(TAG_KEYWORD)) {
- tag = s.substring(TAG_KEYWORD.length());
- } else {
- if (s.startsWith(TEXT_KEYWORD)) {
- text = s.substring(TEXT_KEYWORD.length());
- } else {
- text = s;
- }
- }
- filterSettings.add(new LogCatFilter("livefilter-" + s,
- tag, text, pid, app, minLevel));
- }
-
- return filterSettings;
- }
-
- public String getName() {
- return mName;
- }
-
- public String getTag() {
- return mTag;
- }
-
- public String getText() {
- return mText;
- }
-
- public String getPid() {
- return mPid;
- }
-
- public String getAppName() {
- return mAppName;
- }
-
- public LogLevel getLogLevel() {
- return mLogLevel;
- }
-
- /**
- * Check whether a given message will make it through this filter.
- * @param m message to check
- * @return true if the message matches the filter's conditions.
- */
- public boolean matches(LogCatMessage m) {
- /* filter out messages of a lower priority */
- if (m.getLogLevel().getPriority() < mLogLevel.getPriority()) {
- return false;
- }
-
- /* if pid filter is enabled, filter out messages whose pid does not match
- * the filter's pid */
- if (mCheckPid && !m.getPid().equals(mPid)) {
- return false;
- }
-
- /* if app name filter is enabled, filter out messages not matching the app name */
- if (mCheckAppName) {
- Matcher matcher = mAppNamePattern.matcher(m.getAppName());
- if (!matcher.find()) {
- return false;
- }
- }
-
- /* if tag filter is enabled, filter out messages not matching the tag */
- if (mCheckTag) {
- Matcher matcher = mTagPattern.matcher(m.getTag());
- if (!matcher.find()) {
- return false;
- }
- }
-
- if (mCheckText) {
- Matcher matcher = mTextPattern.matcher(m.getMessage());
- if (!matcher.find()) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * Update the unread count based on new messages received. The unread count
- * is incremented by the count of messages in the received list that will be
- * accepted by this filter.
- * @param newMessages list of new messages.
- */
- public void updateUnreadCount(List<LogCatMessage> newMessages) {
- for (LogCatMessage m : newMessages) {
- if (matches(m)) {
- mUnreadCount++;
- }
- }
- }
-
- /**
- * Reset count of unread messages.
- */
- public void resetUnreadCount() {
- mUnreadCount = 0;
- }
-
- /**
- * Get current value for the unread message counter.
- */
- public int getUnreadCount() {
- return mUnreadCount;
- }
-
- /** Make this filter transient: It will not be persisted across sessions. */
- public void setTransient() {
- mTransient = true;
- }
-
- public boolean isTransient() {
- return mTransient;
- }
-}
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterContentProvider.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterContentProvider.java
index 68c08d4..629b0e0 100644
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterContentProvider.java
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterContentProvider.java
@@ -15,6 +15,8 @@
*/
package com.android.ddmuilib.logcat;
+import com.android.ddmlib.logcat.LogCatFilter;
+
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterData.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterData.java
new file mode 100644
index 0000000..dbc34d8
--- /dev/null
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterData.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ddmuilib.logcat;
+
+import com.android.ddmlib.logcat.LogCatFilter;
+import com.android.ddmlib.logcat.LogCatMessage;
+
+import java.util.List;
+
+public class LogCatFilterData {
+ private final LogCatFilter mFilter;
+
+ /** Indicates the number of messages that match this filter, but have not
+ * yet been read by the user. This is really metadata about this filter
+ * necessary for the UI. If we ever end up needing to store more metadata,
+ * then it is probably better to move it out into a separate class. */
+ private int mUnreadCount;
+
+ /** Indicates that this filter is transient, and should not be persisted
+ * across Eclipse sessions. */
+ private boolean mTransient;
+
+ public LogCatFilterData(LogCatFilter f) {
+ mFilter = f;
+
+ // By default, all filters are persistent. Transient filters should explicitly
+ // mark it so by calling setTransient.
+ mTransient = false;
+ }
+
+ /**
+ * Update the unread count based on new messages received. The unread count
+ * is incremented by the count of messages in the received list that will be
+ * accepted by this filter.
+ * @param newMessages list of new messages.
+ */
+ public void updateUnreadCount(List<LogCatMessage> newMessages) {
+ for (LogCatMessage m : newMessages) {
+ if (mFilter.matches(m)) {
+ mUnreadCount++;
+ }
+ }
+ }
+
+ /**
+ * Reset count of unread messages.
+ */
+ public void resetUnreadCount() {
+ mUnreadCount = 0;
+ }
+
+ /**
+ * Get current value for the unread message counter.
+ */
+ public int getUnreadCount() {
+ return mUnreadCount;
+ }
+
+ /** Make this filter transient: It will not be persisted across sessions. */
+ public void setTransient() {
+ mTransient = true;
+ }
+
+ public boolean isTransient() {
+ return mTransient;
+ }
+}
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterLabelProvider.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterLabelProvider.java
index 59e236c..fe24ddd 100644
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterLabelProvider.java
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterLabelProvider.java
@@ -15,15 +15,25 @@
*/
package com.android.ddmuilib.logcat;
+import com.android.ddmlib.logcat.LogCatFilter;
+
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
+import java.util.Map;
+
/**
* A JFace label provider for the LogCat filters. It expects elements of type
* {@link LogCatFilter}.
*/
public final class LogCatFilterLabelProvider extends LabelProvider implements ITableLabelProvider {
+ private Map<LogCatFilter, LogCatFilterData> mFilterData;
+
+ public LogCatFilterLabelProvider(Map<LogCatFilter, LogCatFilterData> filterData) {
+ mFilterData = filterData;
+ }
+
@Override
public Image getColumnImage(Object arg0, int arg1) {
return null;
@@ -42,11 +52,12 @@ public final class LogCatFilterLabelProvider extends LabelProvider implements IT
}
LogCatFilter f = (LogCatFilter) element;
+ LogCatFilterData fd = mFilterData.get(f);
- if (f.getUnreadCount() == 0) {
- return f.getName();
+ if (fd != null && fd.getUnreadCount() > 0) {
+ return String.format("%s (%d)", f.getName(), fd.getUnreadCount());
} else {
- return String.format("%s (%d)", f.getName(), f.getUnreadCount());
+ return f.getName();
}
}
}
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterSettingsSerializer.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterSettingsSerializer.java
index 12fbdfa..de35162 100644
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterSettingsSerializer.java
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatFilterSettingsSerializer.java
@@ -16,9 +16,11 @@
package com.android.ddmuilib.logcat;
import com.android.ddmlib.Log.LogLevel;
+import com.android.ddmlib.logcat.LogCatFilter;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
/**
* Class to help save/restore user created filters.
@@ -49,14 +51,17 @@ public final class LogCatFilterSettingsSerializer {
* {@link LogCatFilterSettingsSerializer#decodeFromPreferenceString(String)} for the
* reverse operation.
* @param filters list of filters to save.
+ * @param filterData mapping from filter to per filter UI data
* @return an encoded string that can be saved in Eclipse preference store. The encoded string
* is of a list of key:'value' pairs.
*/
- public String encodeToPreferenceString(List<LogCatFilter> filters) {
+ public String encodeToPreferenceString(List<LogCatFilter> filters,
+ Map<LogCatFilter, LogCatFilterData> filterData) {
StringBuffer sb = new StringBuffer();
for (LogCatFilter f : filters) {
- if (f.isTransient()) {
+ LogCatFilterData fd = filterData.get(f);
+ if (fd != null && fd.isTransient()) {
// do not persist transient filters
continue;
}
diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java
index c978de7..bda742c 100644
--- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java
+++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/logcat/LogCatPanel.java
@@ -19,6 +19,7 @@ package com.android.ddmuilib.logcat;
import com.android.ddmlib.DdmConstants;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.Log.LogLevel;
+import com.android.ddmlib.logcat.LogCatFilter;
import com.android.ddmlib.logcat.LogCatMessage;
import com.android.ddmuilib.AbstractBufferFindTarget;
import com.android.ddmuilib.FindDialog;
@@ -86,6 +87,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
@@ -161,6 +164,7 @@ public final class LogCatPanel extends SelectionDependentPanel
private IPreferenceStore mPrefStore;
private List<LogCatFilter> mLogCatFilters;
+ private Map<LogCatFilter, LogCatFilterData> mLogCatFilterData;
private int mCurrentSelectedFilterIndex;
private ToolItem mNewFilterToolItem;
@@ -237,18 +241,25 @@ public final class LogCatPanel extends SelectionDependentPanel
private void initializeFilters() {
mLogCatFilters = new ArrayList<LogCatFilter>();
+ mLogCatFilterData = new ConcurrentHashMap<LogCatFilter, LogCatFilterData>();
/* add default filter matching all messages */
String tag = "";
String text = "";
String pid = "";
String app = "";
- mLogCatFilters.add(new LogCatFilter("All messages (no filters)",
- tag, text, pid, app, LogLevel.VERBOSE));
+ LogCatFilter defaultFilter = new LogCatFilter("All messages (no filters)",
+ tag, text, pid, app, LogLevel.VERBOSE);
+
+ mLogCatFilters.add(defaultFilter);
+ mLogCatFilterData.put(defaultFilter, new LogCatFilterData(defaultFilter));
/* restore saved filters from prefStore */
List<LogCatFilter> savedFilters = getSavedFilters();
- mLogCatFilters.addAll(savedFilters);
+ for (LogCatFilter f: savedFilters) {
+ mLogCatFilters.add(f);
+ mLogCatFilterData.put(f, new LogCatFilterData(f));
+ }
}
private void setupDefaultPreferences() {
@@ -324,7 +335,7 @@ public final class LogCatPanel extends SelectionDependentPanel
/* save all filter settings except the first one which is the default */
String e = serializer.encodeToPreferenceString(
- mLogCatFilters.subList(1, mLogCatFilters.size()));
+ mLogCatFilters.subList(1, mLogCatFilters.size()), mLogCatFilterData);
mPrefStore.setValue(LOGCAT_FILTERS_LIST, e);
}
@@ -349,7 +360,8 @@ public final class LogCatPanel extends SelectionDependentPanel
// When switching between devices, existing filter match count should be reset.
for (LogCatFilter f : mLogCatFilters) {
- f.resetUnreadCount();
+ LogCatFilterData fd = mLogCatFilterData.get(f);
+ fd.resetUnreadCount();
}
}
@@ -479,6 +491,7 @@ public final class LogCatPanel extends SelectionDependentPanel
LogLevel.getByString(d.getLogLevel()));
mLogCatFilters.add(f);
+ mLogCatFilterData.put(f, new LogCatFilterData(f));
mFiltersTableViewer.refresh();
/* select the newly added entry */
@@ -490,8 +503,7 @@ public final class LogCatPanel extends SelectionDependentPanel
}
private void addNewFilter() {
- addNewFilter("", "", "",
- "", LogLevel.VERBOSE);
+ addNewFilter("", "", "", "", LogLevel.VERBOSE);
}
private void deleteSelectedFilter() {
@@ -501,7 +513,10 @@ public final class LogCatPanel extends SelectionDependentPanel
return;
}
+ LogCatFilter f = mLogCatFilters.get(selectedIndex);
mLogCatFilters.remove(selectedIndex);
+ mLogCatFilterData.remove(f);
+
mFiltersTableViewer.refresh();
mFiltersTableViewer.getTable().setSelection(selectedIndex - 1);
@@ -552,6 +567,10 @@ public final class LogCatPanel extends SelectionDependentPanel
if (f == null) {
f = createTransientAppFilter(appName);
mLogCatFilters.add(f);
+
+ LogCatFilterData fd = new LogCatFilterData(f);
+ fd.setTransient();
+ mLogCatFilterData.put(f, fd);
}
selectFilterAt(mLogCatFilters.indexOf(f));
@@ -559,7 +578,8 @@ public final class LogCatPanel extends SelectionDependentPanel
private LogCatFilter findTransientAppFilter(String appName) {
for (LogCatFilter f : mLogCatFilters) {
- if (f.isTransient() && f.getAppName().equals(appName)) {
+ LogCatFilterData fd = mLogCatFilterData.get(f);
+ if (fd != null && fd.isTransient() && f.getAppName().equals(appName)) {
return f;
}
}
@@ -573,7 +593,6 @@ public final class LogCatPanel extends SelectionDependentPanel
"",
appName,
LogLevel.VERBOSE);
- f.setTransient();
return f;
}
@@ -595,7 +614,7 @@ public final class LogCatPanel extends SelectionDependentPanel
mFiltersTableViewer = new TableViewer(table);
mFiltersTableViewer.setContentProvider(new LogCatFilterContentProvider());
- mFiltersTableViewer.setLabelProvider(new LogCatFilterLabelProvider());
+ mFiltersTableViewer.setLabelProvider(new LogCatFilterLabelProvider(mLogCatFilterData));
mFiltersTableViewer.setInput(mLogCatFilters);
mFiltersTableViewer.getTable().addSelectionListener(new SelectionAdapter() {
@@ -672,6 +691,7 @@ public final class LogCatPanel extends SelectionDependentPanel
if (mReceiver != null) {
mReceiver.clearMessages();
refreshLogCatTable();
+ resetUnreadCountForAllFilters();
// the filters view is not cleared unless the filters are re-applied.
updateAppliedFilters();
@@ -1092,13 +1112,15 @@ public final class LogCatPanel extends SelectionDependentPanel
mCurrentSelectedFilterIndex = idx;
- resetUnreadCountForSelectedFilter();
+ resetUnreadCountForAllFilters();
updateFiltersToolBar();
updateAppliedFilters();
}
- private void resetUnreadCountForSelectedFilter() {
- mLogCatFilters.get(mCurrentSelectedFilterIndex).resetUnreadCount();
+ private void resetUnreadCountForAllFilters() {
+ for (LogCatFilterData fd: mLogCatFilterData.values()) {
+ fd.resetUnreadCount();
+ }
refreshFiltersTable();
}
@@ -1143,6 +1165,8 @@ public final class LogCatPanel extends SelectionDependentPanel
@Override
public void bufferChanged(List<LogCatMessage> addedMessages,
List<LogCatMessage> deletedMessages) {
+ updateUnreadCount(addedMessages);
+ refreshFiltersTable();
synchronized (mLogBuffer) {
addedMessages = applyCurrentFilters(addedMessages);
@@ -1153,8 +1177,6 @@ public final class LogCatPanel extends SelectionDependentPanel
}
refreshLogCatTable();
- updateUnreadCount(addedMessages);
- refreshFiltersTable();
}
private void reloadLogBuffer() {
@@ -1185,7 +1207,9 @@ public final class LogCatPanel extends SelectionDependentPanel
/* no need to update unread count for currently selected filter */
continue;
}
- mLogCatFilters.get(i).updateUnreadCount(receivedMessages);
+ LogCatFilter f = mLogCatFilters.get(i);
+ LogCatFilterData fd = mLogCatFilterData.get(f);
+ fd.updateUnreadCount(receivedMessages);
}
}
@@ -1329,7 +1353,9 @@ public final class LogCatPanel extends SelectionDependentPanel
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
- startScrollBarMonitor(mTable.getVerticalBar());
+ if (!mTable.isDisposed()) {
+ startScrollBarMonitor(mTable.getVerticalBar());
+ }
}
});
}
@@ -1373,7 +1399,9 @@ public final class LogCatPanel extends SelectionDependentPanel
/** Scroll to the last line. */
private void scrollToLatestLog() {
- mTable.setTopIndex(mTable.getItemCount() - 1);
+ if (!mTable.isDisposed()) {
+ mTable.setTopIndex(mTable.getItemCount() - 1);
+ }
}
/**
diff --git a/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatFilterSettingsSerializerTest.java b/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatFilterSettingsSerializerTest.java
index 0fc0c76..e6c0e76 100644
--- a/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatFilterSettingsSerializerTest.java
+++ b/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatFilterSettingsSerializerTest.java
@@ -16,8 +16,10 @@
package com.android.ddmuilib.logcat;
import com.android.ddmlib.Log.LogLevel;
+import com.android.ddmlib.logcat.LogCatFilter;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
import junit.framework.TestCase;
@@ -34,7 +36,8 @@ public class LogCatFilterSettingsSerializerTest extends TestCase {
LogLevel.ERROR);
LogCatFilterSettingsSerializer serializer = new LogCatFilterSettingsSerializer();
- String s = serializer.encodeToPreferenceString(Arrays.asList(fs));
+ String s = serializer.encodeToPreferenceString(Arrays.asList(fs),
+ new HashMap<LogCatFilter, LogCatFilterData>());
List<LogCatFilter> decodedFiltersList = serializer.decodeFromPreferenceString(s);
assertEquals(1, decodedFiltersList.size());
@@ -57,10 +60,14 @@ public class LogCatFilterSettingsSerializerTest extends TestCase {
"123", //$NON-NLS-1$
"TestAppName.*", //$NON-NLS-1$
LogLevel.ERROR);
- fs.setTransient();
+ LogCatFilterData fd = new LogCatFilterData(fs);
+ fd.setTransient();
+ HashMap<LogCatFilter, LogCatFilterData> fdMap =
+ new HashMap<LogCatFilter, LogCatFilterData>();
+ fdMap.put(fs, fd);
LogCatFilterSettingsSerializer serializer = new LogCatFilterSettingsSerializer();
- String s = serializer.encodeToPreferenceString(Arrays.asList(fs));
+ String s = serializer.encodeToPreferenceString(Arrays.asList(fs), fdMap);
List<LogCatFilter> decodedFiltersList = serializer.decodeFromPreferenceString(s);
assertEquals(0, decodedFiltersList.size());
diff --git a/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatFilterTest.java b/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatFilterTest.java
deleted file mode 100644
index 98b186e..0000000
--- a/ddms/libs/ddmuilib/tests/src/com/android/ddmuilib/logcat/LogCatFilterTest.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.ddmuilib.logcat;
-
-import com.android.ddmlib.Log.LogLevel;
-import com.android.ddmlib.logcat.LogCatMessage;
-
-import java.util.List;
-
-import junit.framework.TestCase;
-
-public class LogCatFilterTest extends TestCase {
- public void testFilterByLogLevel() {
- LogCatFilter filter = new LogCatFilter("",
- "", "", "", "", LogLevel.DEBUG);
-
- /* filter message below filter's log level */
- LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "", "", "", "");
- assertEquals(false, filter.matches(msg));
-
- /* do not filter message above filter's log level */
- msg = new LogCatMessage(LogLevel.ERROR,
- "", "", "", "", "", "");
- assertEquals(true, filter.matches(msg));
- }
-
- public void testFilterByPid() {
- LogCatFilter filter = new LogCatFilter("",
- "", "", "123", "", LogLevel.VERBOSE);
-
- /* show message with pid matching filter */
- LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "123", "", "", "", "", "");
- assertEquals(true, filter.matches(msg));
-
- /* don't show message with pid not matching filter */
- msg = new LogCatMessage(LogLevel.VERBOSE,
- "12", "", "", "", "", "");
- assertEquals(false, filter.matches(msg));
- }
-
- public void testFilterByAppNameRegex() {
- LogCatFilter filter = new LogCatFilter("",
- "", "", "", "dalvik.*", LogLevel.VERBOSE);
-
- /* show message with pid matching filter */
- LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "dalvikvm1", "", "", "");
- assertEquals(true, filter.matches(msg));
-
- /* don't show message with pid not matching filter */
- msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "system", "", "", "");
- assertEquals(false, filter.matches(msg));
- }
-
- public void testFilterByTagRegex() {
- LogCatFilter filter = new LogCatFilter("",
- "tag.*", "", "", "", LogLevel.VERBOSE);
-
- /* show message with tag matching filter */
- LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "", "tag123", "", "");
- assertEquals(true, filter.matches(msg));
-
- msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "", "ta123", "", "");
- assertEquals(false, filter.matches(msg));
- }
-
- public void testFilterByTextRegex() {
- LogCatFilter filter = new LogCatFilter("",
- "", "text.*", "", "", LogLevel.VERBOSE);
-
- /* show message with text matching filter */
- LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "", "", "", "text123");
- assertEquals(true, filter.matches(msg));
-
- msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "", "", "", "te123");
- assertEquals(false, filter.matches(msg));
- }
-
- public void testMatchingText() {
- LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "", "", "", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- "message with word1 and word2"); //$NON-NLS-1$
- assertEquals(true, search("word1 with", msg)); //$NON-NLS-1$
- assertEquals(true, search("text:w.* ", msg)); //$NON-NLS-1$
- assertEquals(false, search("absent", msg)); //$NON-NLS-1$
- }
-
- public void testTagKeyword() {
- LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "", "tag", "", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- "sample message"); //$NON-NLS-1$
- assertEquals(false, search("t.*", msg)); //$NON-NLS-1$
- assertEquals(true, search("tag:t.*", msg)); //$NON-NLS-1$
- }
-
- public void testPidKeyword() {
- LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "123", "", "", "", "", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- "sample message"); //$NON-NLS-1$
- assertEquals(false, search("123", msg)); //$NON-NLS-1$
- assertEquals(true, search("pid:123", msg)); //$NON-NLS-1$
- }
-
- public void testAppNameKeyword() {
- LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "dalvik", "", "", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- "sample message"); //$NON-NLS-1$
- assertEquals(false, search("dalv.*", msg)); //$NON-NLS-1$
- assertEquals(true, search("app:dal.*k", msg)); //$NON-NLS-1$
- }
-
- public void testCaseSensitivity() {
- LogCatMessage msg = new LogCatMessage(LogLevel.VERBOSE,
- "", "", "", "", "",
- "Sample message");
-
- // if regex has an upper case character, it should be
- // treated as a case sensitive search
- assertEquals(false, search("Message", msg));
-
- // if regex is all lower case, then it should be a
- // case insensitive search
- assertEquals(true, search("sample", msg));
- }
-
- /**
- * Helper method: search if the query string matches the message.
- * @param query words to search for
- * @param message text to search in
- * @return true if the encoded query is present in message
- */
- private boolean search(String query, LogCatMessage message) {
- List<LogCatFilter> filters = LogCatFilter.fromString(query,
- LogLevel.VERBOSE);
-
- /* all filters have to match for the query to match */
- for (LogCatFilter f : filters) {
- if (!f.matches(message)) {
- return false;
- }
- }
- return true;
- }
-}