Argh forget to include my final part of the change.

Change-Id: I1e2711e1ecde0350047f1edef9a59947ff5749eb
diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java
index 7365670..f4fa567 100644
--- a/core/java/android/app/Dialog.java
+++ b/core/java/android/app/Dialog.java
@@ -85,6 +85,7 @@
      */
     protected boolean mCancelable = true;
 
+    private String mCancelAndDismissTaken;
     private Message mCancelMessage;
     private Message mDismissMessage;
     private Message mShowMessage;
@@ -1029,6 +1030,11 @@
      * @param listener The {@link DialogInterface.OnCancelListener} to use.
      */
     public void setOnCancelListener(final OnCancelListener listener) {
+        if (mCancelAndDismissTaken != null) {
+            throw new IllegalStateException(
+                    "OnCancelListener is already taken by "
+                    + mCancelAndDismissTaken + " and can not be replaced.");
+        }
         if (listener != null) {
             mCancelMessage = mListenersHandler.obtainMessage(CANCEL, listener);
         } else {
@@ -1050,6 +1056,11 @@
      * @param listener The {@link DialogInterface.OnDismissListener} to use.
      */
     public void setOnDismissListener(final OnDismissListener listener) {
+        if (mCancelAndDismissTaken != null) {
+            throw new IllegalStateException(
+                    "OnDismissListener is already taken by "
+                    + mCancelAndDismissTaken + " and can not be replaced.");
+        }
         if (listener != null) {
             mDismissMessage = mListenersHandler.obtainMessage(DISMISS, listener);
         } else {
@@ -1077,6 +1088,22 @@
         mDismissMessage = msg;
     }
 
+    /** @hide */
+    public boolean takeCancelAndDismissListeners(String msg, final OnCancelListener cancel,
+            final OnDismissListener dismiss) {
+        if (mCancelAndDismissTaken != null) {
+            mCancelAndDismissTaken = null;
+        } else if (mCancelMessage != null || mDismissMessage != null) {
+            return false;
+        }
+        
+        setOnCancelListener(cancel);
+        setOnDismissListener(dismiss);
+        mCancelAndDismissTaken = msg;
+        
+        return true;
+    }
+    
     /**
      * By default, this will use the owner Activity's suggested stream type.
      * 
diff --git a/core/java/android/app/DialogFragment.java b/core/java/android/app/DialogFragment.java
index 8bdd086..50953d7 100644
--- a/core/java/android/app/DialogFragment.java
+++ b/core/java/android/app/DialogFragment.java
@@ -378,6 +378,12 @@
      * default implementation simply instantiates and returns a {@link Dialog}
      * class.
      * 
+     * <p><em>Note: DialogFragment own the {@link Dialog#setOnCancelListener
+     * Dialog.setOnCancelListener} and {@link Dialog#setOnDismissListener
+     * Dialog.setOnDismissListener} callbacks.  You must not set them yourself.</em>
+     * To find out about these events, override {@link #onCancel(DialogInterface)}
+     * and {@link #onDismiss(DialogInterface)}.</p>
+     * 
      * @param savedInstanceState The last saved instance state of the Fragment,
      * or null if this is a freshly created Fragment.
      * 
@@ -417,8 +423,10 @@
         }
         mDialog.setOwnerActivity(getActivity());
         mDialog.setCancelable(mCancelable);
-        mDialog.setOnCancelListener(this);
-        mDialog.setOnDismissListener(this);
+        if (!mDialog.takeCancelAndDismissListeners("DialogFragment", this, this)) {
+            throw new IllegalStateException(
+                    "You can not set Dialog's OnCancelListener or OnDismissListener");
+        }
         if (savedInstanceState != null) {
             Bundle dialogState = savedInstanceState.getBundle(SAVED_DIALOG_STATE_TAG);
             if (dialogState != null) {