auto import from //branches/cupcake/...@132276
diff --git a/src/com/android/settings/GadgetPickActivity.java b/src/com/android/settings/GadgetPickActivity.java
index 408039a..840a6a5 100644
--- a/src/com/android/settings/GadgetPickActivity.java
+++ b/src/com/android/settings/GadgetPickActivity.java
@@ -59,8 +59,19 @@
public void onListItemClick(ListView l, View v, int position, long id)
{
Intent intent = intentForPosition(position);
- mGadgetManager.bindGadgetId(mGadgetId, intent.getComponent());
- setResultData(RESULT_OK);
+ int result;
+ try {
+ mGadgetManager.bindGadgetId(mGadgetId, intent.getComponent());
+ result = RESULT_OK;
+ } catch (IllegalArgumentException e) {
+ // This is thrown if they're already bound, or otherwise somehow
+ // bogus. Set the result to canceled, and exit. The app *should*
+ // clean up at this point. We could pass the error along, but
+ // it's not clear that that's useful -- the gadget will simply not
+ // appear.
+ result = RESULT_CANCELED;
+ }
+ setResultData(result);
finish();
}