OSDN Git Service

Preventing a Runtime widget crash from crashing the Launcher
authorSunny Goyal <sunnygoyal@google.com>
Tue, 26 Jan 2016 01:28:37 +0000 (17:28 -0800)
committerSunny Goyal <sunnygoyal@google.com>
Tue, 26 Jan 2016 01:30:25 +0000 (17:30 -0800)
Bug: 26750103
Change-Id: I31f120bb0c4d64b903b3dd5dae0ae46f95bcdf59

src/com/android/launcher3/LauncherAppWidgetHostView.java

index c49d43f..18ae753 100644 (file)
@@ -267,4 +267,19 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView implements Touc
             getOnFocusChangeListener().onFocusChange(this, focused || isFocused());
         }
     }
+
+    @Override
+    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+        try {
+            super.onLayout(changed, left, top, right, bottom);
+        } catch (final RuntimeException e) {
+            post(new Runnable() {
+                @Override
+                public void run() {
+                    // Update the widget with 0 Layout id, to reset the view to error view.
+                    updateAppWidget(new RemoteViews(getAppWidgetInfo().provider.getPackageName(), 0));
+                }
+            });
+        }
+    }
 }