Worked around back button navigation issue

Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to
the intent starting the fragment could cause a native stack corruption. See
b/17523189. However, adding that flag and start the preference panel with the
same UserHandler will make it impossible to use back button to return to the
previous screen. See b/20042570.

We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while
doing another check here to call startPreferencePanel() instead of
startWithFragmentAsUser() when we're calling it as the same user.

Bug: 20042570
Change-Id: I26b269414f410912b77aaa553a3fccebfa148659
This commit is contained in:
Lifu Tang
2015-04-02 12:05:46 -07:00
parent 390910b333
commit d033285ca7
2 changed files with 25 additions and 17 deletions

View File

@@ -928,6 +928,19 @@ public class SettingsActivity extends Activity
*/ */
public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes, public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
CharSequence titleText, UserHandle userHandle) { CharSequence titleText, UserHandle userHandle) {
// This is a workaround.
//
// Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
// starting the fragment could cause a native stack corruption. See b/17523189. However,
// adding that flag and start the preference panel with the same UserHandler will make it
// impossible to use back button to return to the previous screen. See b/20042570.
//
// We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
// another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
// when we're calling it as the same user.
if (userHandle.getIdentifier() == UserHandle.myUserId()) {
startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
} else {
String title = null; String title = null;
if (titleRes < 0) { if (titleRes < 0) {
if (titleText != null) { if (titleText != null) {
@@ -940,6 +953,7 @@ public class SettingsActivity extends Activity
Utils.startWithFragmentAsUser(this, fragmentClass, args, Utils.startWithFragmentAsUser(this, fragmentClass, args,
titleRes, title, mIsShortcut, userHandle); titleRes, title, mIsShortcut, userHandle);
} }
}
/** /**
* Called by a preference panel fragment to finish itself. * Called by a preference panel fragment to finish itself.

View File

@@ -259,15 +259,9 @@ public class PowerUsageDetail extends Fragment implements Button.OnClickListener
args.putIntArray(PowerUsageDetail.EXTRA_DETAIL_TYPES, types); args.putIntArray(PowerUsageDetail.EXTRA_DETAIL_TYPES, types);
args.putDoubleArray(PowerUsageDetail.EXTRA_DETAIL_VALUES, values); args.putDoubleArray(PowerUsageDetail.EXTRA_DETAIL_VALUES, values);
// This is a workaround, see b/17523189
if (userId == UserHandle.myUserId()) {
caller.startPreferencePanel(PowerUsageDetail.class.getName(), args,
R.string.details_title, null, null, 0);
} else {
caller.startPreferencePanelAsUser(PowerUsageDetail.class.getName(), args, caller.startPreferencePanelAsUser(PowerUsageDetail.class.getName(), args,
R.string.details_title, null, new UserHandle(userId)); R.string.details_title, null, new UserHandle(userId));
} }
}
public static final int ACTION_DISPLAY_SETTINGS = 1; public static final int ACTION_DISPLAY_SETTINGS = 1;
public static final int ACTION_WIFI_SETTINGS = 2; public static final int ACTION_WIFI_SETTINGS = 2;