Merge "Add optional package filtering to notification dumpsys."

This commit is contained in:
John Spurlock
2014-06-27 22:10:52 +00:00
committed by Android (Google) Code Review
4 changed files with 85 additions and 36 deletions

View File

@@ -36,6 +36,7 @@ import android.util.ArraySet;
import android.util.Slog;
import com.android.internal.R;
import com.android.server.notification.NotificationManagerService.DumpFilter;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -74,16 +75,19 @@ public class ConditionProviders extends ManagedServices {
}
@Override
public void dump(PrintWriter pw) {
super.dump(pw);
public void dump(PrintWriter pw, DumpFilter filter) {
super.dump(pw, filter);
synchronized(mMutex) {
pw.print(" mListeners("); pw.print(mListeners.size()); pw.println("):");
for (int i = 0; i < mListeners.size(); i++) {
pw.print(" "); pw.println(mListeners.keyAt(i));
if (filter == null) {
pw.print(" mListeners("); pw.print(mListeners.size()); pw.println("):");
for (int i = 0; i < mListeners.size(); i++) {
pw.print(" "); pw.println(mListeners.keyAt(i));
}
}
pw.print(" mRecords("); pw.print(mRecords.size()); pw.println("):");
for (int i = 0; i < mRecords.size(); i++) {
final ConditionRecord r = mRecords.get(i);
if (filter != null && !filter.matches(r.component)) continue;
pw.print(" "); pw.println(r);
final String countdownDesc = CountdownConditionProvider.tryParseDescription(r.id);
if (countdownDesc != null) {

View File

@@ -44,6 +44,8 @@ import android.util.ArraySet;
import android.util.Slog;
import android.util.SparseArray;
import com.android.server.notification.NotificationManagerService.DumpFilter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
@@ -116,15 +118,17 @@ abstract public class ManagedServices {
mSettingsObserver.observe();
}
public void dump(PrintWriter pw) {
public void dump(PrintWriter pw, DumpFilter filter) {
pw.println(" All " + getCaption() + "s (" + mEnabledServicesForCurrentProfiles.size()
+ ") enabled for current profiles:");
for (ComponentName cmpt : mEnabledServicesForCurrentProfiles) {
if (filter != null && !filter.matches(cmpt)) continue;
pw.println(" " + cmpt);
}
pw.println(" Live " + getCaption() + "s (" + mServices.size() + "):");
for (ManagedServiceInfo info : mServices) {
if (filter != null && !filter.matches(info.component)) continue;
pw.println(" " + info.component
+ " (user " + info.userid + "): " + info.service
+ (info.isSystem?" SYSTEM":""));

View File

@@ -440,7 +440,8 @@ public class NotificationManagerService extends SystemService {
this.duration = duration;
}
void dump(PrintWriter pw, String prefix) {
void dump(PrintWriter pw, String prefix, DumpFilter filter) {
if (filter != null && !filter.matches(pkg)) return;
pw.println(prefix + this);
}
@@ -1313,7 +1314,7 @@ public class NotificationManagerService extends SystemService {
return;
}
dumpImpl(pw);
dumpImpl(pw, DumpFilter.parseFromArguments(args));
}
};
@@ -1334,9 +1335,12 @@ public class NotificationManagerService extends SystemService {
return keys.toArray(new String[keys.size()]);
}
void dumpImpl(PrintWriter pw) {
pw.println("Current Notification Manager state:");
void dumpImpl(PrintWriter pw, DumpFilter filter) {
pw.print("Current Notification Manager state");
if (filter != null) {
pw.print(" (filtered to '"); pw.print(filter.pkgFilter); pw.print("')");
}
pw.println(':');
int N;
synchronized (mToastQueue) {
@@ -1344,11 +1348,10 @@ public class NotificationManagerService extends SystemService {
if (N > 0) {
pw.println(" Toast Queue:");
for (int i=0; i<N; i++) {
mToastQueue.get(i).dump(pw, " ");
mToastQueue.get(i).dump(pw, " ", filter);
}
pw.println(" ");
}
}
synchronized (mNotificationList) {
@@ -1356,29 +1359,35 @@ public class NotificationManagerService extends SystemService {
if (N > 0) {
pw.println(" Notification List:");
for (int i=0; i<N; i++) {
mNotificationList.get(i).dump(pw, " ", getContext());
final NotificationRecord nr = mNotificationList.get(i);
if (filter != null && !filter.matches(nr.sbn)) continue;
nr.dump(pw, " ", getContext());
}
pw.println(" ");
}
N = mLights.size();
if (N > 0) {
pw.println(" Lights List:");
for (int i=0; i<N; i++) {
pw.println(" " + mLights.get(i));
if (filter == null) {
N = mLights.size();
if (N > 0) {
pw.println(" Lights List:");
for (int i=0; i<N; i++) {
pw.println(" " + mLights.get(i));
}
pw.println(" ");
}
pw.println(" ");
}
pw.println(" mSoundNotification=" + mSoundNotification);
pw.println(" mVibrateNotification=" + mVibrateNotification);
pw.println(" mDisableNotificationAlerts=" + mDisableNotificationAlerts);
pw.println(" mSystemReady=" + mSystemReady);
pw.println(" mSoundNotification=" + mSoundNotification);
pw.println(" mVibrateNotification=" + mVibrateNotification);
pw.println(" mDisableNotificationAlerts=" + mDisableNotificationAlerts);
pw.println(" mSystemReady=" + mSystemReady);
}
pw.println(" mArchive=" + mArchive.toString());
Iterator<StatusBarNotification> iter = mArchive.descendingIterator();
int i=0;
while (iter.hasNext()) {
pw.println(" " + iter.next());
final StatusBarNotification sbn = iter.next();
if (filter != null && !filter.matches(sbn)) continue;
pw.println(" " + sbn);
if (++i >= 5) {
if (iter.hasNext()) pw.println(" ...");
break;
@@ -1386,16 +1395,18 @@ public class NotificationManagerService extends SystemService {
}
pw.println("\n Usage Stats:");
mUsageStats.dump(pw, " ");
mUsageStats.dump(pw, " ", filter);
pw.println("\n Zen Mode:");
mZenModeHelper.dump(pw, " ");
if (filter == null) {
pw.println("\n Zen Mode:");
mZenModeHelper.dump(pw, " ");
}
pw.println("\n Notification listeners:");
mListeners.dump(pw);
mListeners.dump(pw, filter);
pw.println("\n Condition providers:");
mConditionProviders.dump(pw);
mConditionProviders.dump(pw, filter);
}
}
@@ -2447,4 +2458,30 @@ public class NotificationManagerService extends SystemService {
}
}
}
public static final class DumpFilter {
public String pkgFilter;
public static DumpFilter parseFromArguments(String[] args) {
if (args == null || args.length != 2 || !"p".equals(args[0])
|| args[1] == null || args[1].trim().isEmpty()) {
return null;
}
final DumpFilter filter = new DumpFilter();
filter.pkgFilter = args[1].trim().toLowerCase();
return filter;
}
public boolean matches(StatusBarNotification sbn) {
return sbn != null && (matches(sbn.getPackageName()) || matches(sbn.getOpPkg()));
}
public boolean matches(ComponentName component) {
return component != null && matches(component.getPackageName());
}
public boolean matches(String pkg) {
return pkg != null && pkg.toLowerCase().contains(pkgFilter);
}
}
}

View File

@@ -28,6 +28,8 @@ import android.os.SystemClock;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import com.android.server.notification.NotificationManagerService.DumpFilter;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
@@ -168,12 +170,13 @@ public class NotificationUsageStats {
return result;
}
public synchronized void dump(PrintWriter pw, String indent) {
public synchronized void dump(PrintWriter pw, String indent, DumpFilter filter) {
for (AggregatedStats as : mStats.values()) {
if (filter != null && !filter.matches(as.key)) continue;
as.dump(pw, indent);
}
if (ENABLE_SQLITE_LOG) {
mSQLiteLog.dump(pw, indent);
mSQLiteLog.dump(pw, indent, filter);
}
}
@@ -511,7 +514,7 @@ public class NotificationUsageStats {
mWriteHandler.sendMessage(mWriteHandler.obtainMessage(MSG_DISMISS, notification));
}
public void printPostFrequencies(PrintWriter pw, String indent) {
public void printPostFrequencies(PrintWriter pw, String indent, DumpFilter filter) {
SQLiteDatabase db = mHelper.getReadableDatabase();
long nowMs = System.currentTimeMillis();
String q = "SELECT " +
@@ -530,6 +533,7 @@ public class NotificationUsageStats {
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
int userId = cursor.getInt(0);
String pkg = cursor.getString(1);
if (filter != null && !filter.matches(pkg)) continue;
int day = cursor.getInt(2);
int count = cursor.getInt(3);
pw.println(indent + "post_frequency{user_id=" + userId + ",pkg=" + pkg +
@@ -598,8 +602,8 @@ public class NotificationUsageStats {
outCv.put(COL_AIRTIME_MS, r.stats.getCurrentAirtimeMs());
}
public void dump(PrintWriter pw, String indent) {
printPostFrequencies(pw, indent);
public void dump(PrintWriter pw, String indent, DumpFilter filter) {
printPostFrequencies(pw, indent, filter);
}
}
}