Fix InstantiationException on fragment

Since we overrided the empty constructor,
it can't find a empty constructor when
Fragment tries to instantiate a fragment
in framework.

So, we can't override this constructor,
and then just use newInstance() to initialize
and setup a new Fragment.

Test: robotest
Change-Id: Ifcd1c1771bc69d947caeee5c5bc055c4f94365c2
Fixes: 115676209
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index 87a3511..5cfe218 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -454,7 +454,7 @@
         if (mDialogFragment != null) {
             Log.e(TAG, "Old dialog fragment not null!");
         }
-        mDialogFragment = new SettingsDialogFragment(this, dialogId);
+        mDialogFragment = SettingsDialogFragment.newInstance(this, dialogId);
         mDialogFragment.show(getChildFragmentManager(), Integer.toString(dialogId));
     }
 
@@ -541,22 +541,26 @@
         private DialogInterface.OnCancelListener mOnCancelListener;
         private DialogInterface.OnDismissListener mOnDismissListener;
 
-        public SettingsDialogFragment(DialogCreatable fragment, int dialogId) {
-            super(fragment, dialogId);
+        public static SettingsDialogFragment newInstance(DialogCreatable fragment, int dialogId) {
             if (!(fragment instanceof Fragment)) {
                 throw new IllegalArgumentException("fragment argument must be an instance of "
                         + Fragment.class.getName());
             }
-            mParentFragment = (Fragment) fragment;
-        }
 
+            final SettingsDialogFragment settingsDialogFragment = new SettingsDialogFragment();
+            settingsDialogFragment.setParentFragment(fragment);
+            settingsDialogFragment.setDialogId(dialogId);
+
+            return settingsDialogFragment;
+        }
 
         @Override
         public int getMetricsCategory() {
-            if (mDialogCreatable == null) {
+            if (mParentFragment == null) {
                 return Instrumentable.METRICS_CATEGORY_UNKNOWN;
             }
-            final int metricsCategory = mDialogCreatable.getDialogMetricsCategory(mDialogId);
+            final int metricsCategory =
+                    ((DialogCreatable) mParentFragment).getDialogMetricsCategory(mDialogId);
             if (metricsCategory <= 0) {
                 throw new IllegalStateException("Dialog must provide a metrics category");
             }
@@ -639,6 +643,14 @@
                 }
             }
         }
+
+        private void setParentFragment(DialogCreatable fragment) {
+            mParentFragment = (Fragment) fragment;
+        }
+
+        private void setDialogId(int dialogId) {
+            mDialogId = dialogId;
+        }
     }
 
     protected boolean hasNextButton() {