From dc200a44a92013d2d1fd2b22ae857389fa95d5ca Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Wed, 19 Jan 2011 14:21:35 -0800 Subject: [PATCH] Dump widget state to bugreport This might be helpful someday... Change-Id: I5a9e0a2948c7ea9fa5c9a7da61d143c10dda7d9a --- .../email/provider/WidgetProvider.java | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/com/android/email/provider/WidgetProvider.java b/src/com/android/email/provider/WidgetProvider.java index aff1ecee2..4df2df619 100644 --- a/src/com/android/email/provider/WidgetProvider.java +++ b/src/com/android/email/provider/WidgetProvider.java @@ -58,8 +58,11 @@ import android.view.View; import android.widget.RemoteViews; import android.widget.RemoteViewsService; -import java.util.HashMap; +import java.io.FileDescriptor; +import java.io.PrintWriter; import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; public class WidgetProvider extends AppWidgetProvider { private static final String TAG = "WidgetProvider"; @@ -105,7 +108,8 @@ public class WidgetProvider extends AppWidgetProvider { // Map holding our instantiated widgets, accessed by widget id - private static HashMap sWidgetMap = new HashMap(); + private final static Map sWidgetMap + = new ConcurrentHashMap(); private static AppWidgetManager sWidgetManager; private static Context sContext; private static ContentResolver sResolver; @@ -145,6 +149,24 @@ public class WidgetProvider extends AppWidgetProvider { } return title; } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("ViewType:selection="); + sb.append("\""); + sb.append(selection); + sb.append("\""); + if (selectionArgs != null && selectionArgs.length > 0) { + sb.append(",args=("); + for (String arg : selectionArgs) { + sb.append(arg); + sb.append(", "); + } + sb.append(")"); + } + + return sb.toString(); + } } static class EmailWidget implements RemoteViewsService.RemoteViewsFactory { @@ -741,5 +763,14 @@ public class WidgetProvider extends AppWidgetProvider { startActivity(Welcome.createOpenMessageIntent(this, mailbox.mAccountKey, mailboxId, messageId)); } + + @Override + protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { + int n = 0; + for (EmailWidget widget : sWidgetMap.values()) { + writer.println("Widget #" + (++n)); + writer.println(" ViewType=" + widget.mViewType); + } + } } }