Fix bug #15001610 Java crash in settings is observed while adding Google account on wiped device

- make WifiPickerActivity a SettingsActivity (as it was long overdue)
- move code from the overide of PreferenceActivity.startWithFragment() to
SettingsActivity.startPreferencePanel(...)

Change-Id: Ibc42056fdc84e01004e15c3779073e5451fd02a1
This commit is contained in:
Fabrice Di Meglio
2014-05-16 11:00:13 -07:00
parent 08190bbb75
commit 18d271c73b
2 changed files with 14 additions and 21 deletions

View File

@@ -518,7 +518,7 @@ public class Utils {
* entire activity. * entire activity.
* *
* @param context The context. * @param context The context.
* @param fragmentName The name of the fragment to display. * @param fragmentClass The class name of the fragment to display.
* @param args Optional arguments to supply to the fragment. * @param args Optional arguments to supply to the fragment.
* @param resultTo Option fragment that should receive the result of * @param resultTo Option fragment that should receive the result of
* the activity launch. * the activity launch.
@@ -526,9 +526,9 @@ public class Utils {
* code in which to report the result. * code in which to report the result.
* @param title String to display for the title of this set of preferences. * @param title String to display for the title of this set of preferences.
*/ */
public static void startWithFragment(Context context, String fragmentName, Bundle args, public static void startWithFragment(Context context, String fragmentClass, Bundle args,
Fragment resultTo, int resultRequestCode, CharSequence title) { Fragment resultTo, int resultRequestCode, CharSequence title) {
Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, title); Intent intent = onBuildStartFragmentIntent(context, fragmentClass, args, title);
if (resultTo == null) { if (resultTo == null) {
context.startActivity(intent); context.startActivity(intent);
} else { } else {
@@ -542,17 +542,17 @@ public class Utils {
* appropriate arguments to display the fragment. * appropriate arguments to display the fragment.
* *
* @param context The Context. * @param context The Context.
* @param fragmentName The name of the fragment to display. * @param fragmentClass The class name of the fragment to display.
* @param args Optional arguments to supply to the fragment. * @param args Optional arguments to supply to the fragment.
* @param title Optional title to show for this item. * @param title Optional title to show for this item.
* @return Returns an Intent that can be launched to display the given * @return Returns an Intent that can be launched to display the given
* fragment. * fragment.
*/ */
public static Intent onBuildStartFragmentIntent(Context context, String fragmentName, public static Intent onBuildStartFragmentIntent(Context context, String fragmentClass,
Bundle args, CharSequence title) { Bundle args, CharSequence title) {
Intent intent = new Intent(Intent.ACTION_MAIN); Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(context, SubSettings.class); intent.setClass(context, SubSettings.class);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, fragmentName); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, fragmentClass);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, title); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, title);
return intent; return intent;

View File

@@ -16,6 +16,7 @@
package com.android.settings.wifi; package com.android.settings.wifi;
import com.android.settings.ButtonBarHandler; import com.android.settings.ButtonBarHandler;
import com.android.settings.SettingsActivity;
import com.android.settings.wifi.p2p.WifiP2pSettings; import com.android.settings.wifi.p2p.WifiP2pSettings;
import android.app.Fragment; import android.app.Fragment;
@@ -24,7 +25,7 @@ import android.os.Bundle;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.widget.Button; import android.widget.Button;
public class WifiPickerActivity extends PreferenceActivity implements ButtonBarHandler { public class WifiPickerActivity extends SettingsActivity implements ButtonBarHandler {
// Same as what are in PreferenceActivity as private. // Same as what are in PreferenceActivity as private.
private static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar"; private static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
@@ -39,7 +40,6 @@ public class WifiPickerActivity extends PreferenceActivity implements ButtonBarH
if (!modIntent.hasExtra(EXTRA_SHOW_FRAGMENT)) { if (!modIntent.hasExtra(EXTRA_SHOW_FRAGMENT)) {
modIntent.putExtra(EXTRA_SHOW_FRAGMENT, WifiSettings.class.getName()); modIntent.putExtra(EXTRA_SHOW_FRAGMENT, WifiSettings.class.getName());
} }
modIntent.putExtra(EXTRA_NO_HEADERS, true);
return modIntent; return modIntent;
} }
@@ -52,18 +52,14 @@ public class WifiPickerActivity extends PreferenceActivity implements ButtonBarH
} }
/** /**
* Almost dead copy of * Add additional codes for button bar handling.
* {@link PreferenceActivity#startWithFragment(String, Bundle, Fragment, int)}, except this has
* additional codes for button bar handling.
*/ */
@Override public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
public void startWithFragment(String fragmentName, Bundle args, CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fragment resultTo, int resultRequestCode) {
Intent intent = new Intent(Intent.ACTION_MAIN); Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(this, getClass()); intent.setClass(this, getClass());
intent.putExtra(EXTRA_SHOW_FRAGMENT, fragmentName); intent.putExtra(EXTRA_SHOW_FRAGMENT, fragmentClass);
intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
intent.putExtra(EXTRA_NO_HEADERS, true);
final Intent orgIntent = getIntent(); final Intent orgIntent = getIntent();
if (orgIntent.hasExtra(EXTRA_PREFS_SHOW_BUTTON_BAR)) { if (orgIntent.hasExtra(EXTRA_PREFS_SHOW_BUTTON_BAR)) {
@@ -87,11 +83,8 @@ public class WifiPickerActivity extends PreferenceActivity implements ButtonBarH
orgIntent.getBooleanExtra(EXTRA_WIFI_SHOW_MENUS, true)); orgIntent.getBooleanExtra(EXTRA_WIFI_SHOW_MENUS, true));
} }
if (resultTo == null) { super.startPreferencePanel(fragmentClass, args, titleRes, titleText, resultTo,
startActivity(intent); resultRequestCode);
} else {
resultTo.startActivityForResult(intent, resultRequestCode);
}
} }
@Override @Override