Commit f50de5ce authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android] Clean up how arguments are passed to Preference fragments

1. Revised how Preferences activity gets argument bundle to pass to
   a subpage fragment. PreferencesLauncher methods got Bundle argument,
   so EXTRA_SHOW_FRAGMENT and EXTRA_SHOW_FRAGMENT_ARGUMENTS are
   package-private now.
2. The type of PreferencesLauncher.launchSettingsPage fragment parameter
   is changed to Class<? extends Fragment> to get compile-time checks.
3. A bunch of callers are changed to use launchSettingsPage instead of
   createIntentForSettingsPage followed by startActivity.
4. DataReductionPreferences and PasswordEntryEditor now get their
   parameters using fragment arguments instead of intent extras.

Bug: None
Change-Id: Ic0ae700149d721ab9194ed36c311c8f8b47bea1e
Reviewed-on: https://chromium-review.googlesource.com/c/1323071Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606404}
parent 859f6471
......@@ -30,7 +30,6 @@ import org.chromium.chrome.browser.lifecycle.Destroyable;
import org.chromium.chrome.browser.lifecycle.StartStopWithNativeObserver;
import org.chromium.chrome.browser.notifications.NotificationBuilderFactory;
import org.chromium.chrome.browser.notifications.channels.ChannelDefinitions;
import org.chromium.chrome.browser.preferences.Preferences;
import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences;
......@@ -188,9 +187,8 @@ public class PersistentNotificationController implements StartStopWithNativeObse
}
private PendingIntent makeManageDataIntent() {
Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage(
mAppContext, SingleWebsitePreferences.class.getName());
settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS,
Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage(mAppContext,
SingleWebsitePreferences.class.getName(),
SingleWebsitePreferences.createFragmentArgsForSite(mOrigin.toString()));
return PendingIntent.getActivity(mAppContext, 0, settingsIntent, FLAG_UPDATE_CURRENT);
}
......
......@@ -397,8 +397,8 @@ public class ContextualSearchPromoControl extends OverlayPanelInflater {
new Handler().post(new Runnable() {
@Override
public void run() {
PreferencesLauncher.launchSettingsPage(getContext(),
ContextualSearchPreferenceFragment.class.getName());
PreferencesLauncher.launchSettingsPage(
getContext(), ContextualSearchPreferenceFragment.class);
}
});
}
......
......@@ -4,7 +4,6 @@
package org.chromium.chrome.browser.contextual_suggestions;
import android.content.Intent;
import android.support.annotation.Nullable;
import org.chromium.base.VisibleForTesting;
......@@ -20,7 +19,6 @@ import org.chromium.chrome.browser.suggestions.SuggestionsNavigationDelegate;
import org.chromium.chrome.browser.suggestions.SuggestionsUiDelegateImpl;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetObserver;
......@@ -170,9 +168,7 @@ public class ContextualSuggestionsCoordinator implements Destroyable {
/** Show the settings page for contextual suggestions. */
void showSettings() {
Intent intent = PreferencesLauncher.createIntentForSettingsPage(
mActivity, ContextualSuggestionsPreference.class.getName());
IntentUtils.safeStartActivity(mActivity, intent);
PreferencesLauncher.launchSettingsPage(mActivity, ContextualSuggestionsPreference.class);
}
/** Show the feedback page. */
......
......@@ -5,7 +5,6 @@
package org.chromium.chrome.browser.download.home;
import android.app.Activity;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
......@@ -156,9 +155,7 @@ class DownloadManagerCoordinatorImpl
@Override
public void openSettings() {
RecordUserAction.record("Android.DownloadManager.Settings");
Intent intent = PreferencesLauncher.createIntentForSettingsPage(
mActivity, DownloadPreferences.class.getName());
mActivity.startActivity(intent);
PreferencesLauncher.launchSettingsPage(mActivity, DownloadPreferences.class);
}
private void notifyFilterChanged(@FilterType int filter) {
......
......@@ -385,9 +385,7 @@ public class DownloadManagerUi implements OnMenuItemClickListener, SearchDelegat
mToolbar.showSearchView();
return true;
} else if (item.getItemId() == R.id.settings_menu_id) {
Intent intent = PreferencesLauncher.createIntentForSettingsPage(
mActivity, DownloadPreferences.class.getName());
mActivity.startActivity(intent);
PreferencesLauncher.launchSettingsPage(mActivity, DownloadPreferences.class);
return true;
}
return false;
......
......@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.firstrun;
import android.app.Activity;
import android.app.Fragment;
import android.text.TextUtils;
import org.chromium.base.ApiCompatibilityUtils;
......@@ -110,13 +111,13 @@ public final class FirstRunSignInProcessor {
* Opens sign in settings as requested in the FRE sign-in dialog.
*/
private static void openSignInSettings(Activity activity) {
final String fragmentName;
final Class<? extends Fragment> fragment;
if (ChromeFeatureList.isEnabled(ChromeFeatureList.UNIFIED_CONSENT)) {
fragmentName = SyncAndServicesPreferences.class.getName();
fragment = SyncAndServicesPreferences.class;
} else {
fragmentName = AccountManagementFragment.class.getName();
fragment = AccountManagementFragment.class;
}
PreferencesLauncher.launchSettingsPage(activity, fragmentName);
PreferencesLauncher.launchSettingsPage(activity, fragment);
}
/**
......
......@@ -35,6 +35,7 @@ import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefChangeRegistrar;
import org.chromium.chrome.browser.preferences.PrefChangeRegistrar.PrefObserver;
import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.preferences.privacy.ClearBrowsingDataTabsFragment;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.SigninManager;
import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver;
......@@ -356,8 +357,7 @@ public class HistoryManager implements OnMenuItemClickListener, SignInStateObser
*/
public void openClearBrowsingDataPreference() {
recordUserAction("ClearBrowsingData");
Intent intent = PreferencesLauncher.createIntentForClearBrowsingDataPage(mActivity);
IntentUtils.safeStartActivity(mActivity, intent);
PreferencesLauncher.launchSettingsPage(mActivity, ClearBrowsingDataTabsFragment.class);
}
@Override
......
......@@ -4,7 +4,7 @@
package org.chromium.chrome.browser.infobar;
import android.content.Intent;
import android.os.Bundle;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.browser.ResourceId;
......@@ -31,9 +31,9 @@ public class PreviewsLitePageInfoBar extends ConfirmInfoBar {
public void onLinkClicked() {
super.onLinkClicked();
final Intent intent = PreferencesLauncher.createIntentForSettingsPage(
getContext(), DataReductionPreferences.class.getName());
intent.putExtra(FROM_INFOBAR, true);
getContext().startActivity(intent);
Bundle fragmentArgs = new Bundle();
fragmentArgs.putBoolean(FROM_INFOBAR, true);
PreferencesLauncher.launchSettingsPage(
getContext(), DataReductionPreferences.class, fragmentArgs);
}
}
......@@ -5,16 +5,12 @@
package org.chromium.chrome.browser.infobar;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.browser.ResourceId;
import org.chromium.chrome.browser.preferences.Preferences;
import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences;
import org.chromium.chrome.browser.util.IntentUtils;
/**
* An infobar to disclose to the user that the default search engine has geolocation access by
......@@ -60,10 +56,7 @@ public class SearchGeolocationDisclosureInfoBar extends InfoBar {
@CalledByNative
private static void showSettingsPage(String searchUrl) {
Context context = ContextUtils.getApplicationContext();
Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage(
context, SingleWebsitePreferences.class.getName());
Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsForSite(searchUrl);
settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs);
IntentUtils.safeStartActivity(context, settingsIntent);
PreferencesLauncher.launchSettingsPage(context, SingleWebsitePreferences.class,
SingleWebsitePreferences.createFragmentArgsForSite(searchUrl));
}
}
......@@ -6,7 +6,6 @@ package org.chromium.chrome.browser.locale;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.StrictMode;
import android.support.annotation.IntDef;
......@@ -95,9 +94,7 @@ public class LocaleManager {
@Override
public void onAction(Object actionData) {
Context context = ContextUtils.getApplicationContext();
Intent intent = PreferencesLauncher.createIntentForSettingsPage(context,
SearchEnginePreference.class.getName());
context.startActivity(intent);
PreferencesLauncher.launchSettingsPage(context, SearchEnginePreference.class);
}
};
......
......@@ -6,7 +6,6 @@ package org.chromium.chrome.browser.locale;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
......@@ -54,9 +53,7 @@ public class SogouPromoDialog extends PromoDialog {
private final LocaleManager mLocaleManager;
private final ClickableSpan mSpan = new NoUnderlineClickableSpan((widget) -> {
mChoice = UserChoice.SETTINGS;
Intent intent = PreferencesLauncher.createIntentForSettingsPage(
getContext(), SearchEnginePreference.class.getName());
getContext().startActivity(intent);
PreferencesLauncher.launchSettingsPage(getContext(), SearchEnginePreference.class);
dismiss();
});
......
......@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.notifications;
import android.app.Fragment;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.RemoteInput;
......@@ -33,7 +34,6 @@ import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
import org.chromium.chrome.browser.notifications.channels.ChannelDefinitions;
import org.chromium.chrome.browser.notifications.channels.SiteChannelsManager;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.preferences.Preferences;
import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences;
import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences;
......@@ -264,11 +264,9 @@ public class NotificationPlatformBridge {
String origin = getOriginFromIntent(incomingIntent);
boolean launchSingleWebsitePreferences = origin != null;
String fragmentName = launchSingleWebsitePreferences
? SingleWebsitePreferences.class.getName()
: SingleCategoryPreferences.class.getName();
Intent preferencesIntent =
PreferencesLauncher.createIntentForSettingsPage(applicationContext, fragmentName);
Class<? extends Fragment> fragment = launchSingleWebsitePreferences
? SingleWebsitePreferences.class
: SingleCategoryPreferences.class;
Bundle fragmentArguments;
if (launchSingleWebsitePreferences) {
......@@ -286,9 +284,8 @@ public class NotificationPlatformBridge {
applicationContext.getResources().getString(
R.string.push_notifications_permission_title));
}
preferencesIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArguments);
applicationContext.startActivity(preferencesIntent);
PreferencesLauncher.launchSettingsPage(applicationContext, fragment, fragmentArguments);
}
/**
......@@ -598,12 +595,10 @@ public class NotificationPlatformBridge {
notificationBuilder);
} else {
// Set up a pending intent for going to the settings screen for |origin|.
Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage(
context, SingleWebsitePreferences.class.getName());
settingsIntent.setData(makeIntentData(notificationId, origin, -1 /* actionIndex */));
settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS,
Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage(context,
SingleWebsitePreferences.class.getName(),
SingleWebsitePreferences.createFragmentArgsForSite(origin));
settingsIntent.setData(makeIntentData(notificationId, origin, -1 /* actionIndex */));
PendingIntent pendingSettingsIntent = PendingIntent.getActivity(context,
PENDING_INTENT_REQUEST_CODE, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
......
......@@ -12,7 +12,6 @@ import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.IntDef;
import android.text.Spannable;
......@@ -40,7 +39,6 @@ import org.chromium.chrome.browser.offlinepages.OfflinePageUtils;
import org.chromium.chrome.browser.omnibox.OmniboxUrlEmphasizer;
import org.chromium.chrome.browser.page_info.PageInfoView.ConnectionInfoParams;
import org.chromium.chrome.browser.page_info.PageInfoView.PageInfoViewParams;
import org.chromium.chrome.browser.preferences.Preferences;
import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.preferences.website.ContentSetting;
import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences;
......@@ -232,12 +230,9 @@ public class PageInfoController
// Delay while the dialog closes.
runAfterDismiss(() -> {
recordAction(PageInfoAction.PAGE_INFO_SITE_SETTINGS_OPENED);
Bundle fragmentArguments =
SingleWebsitePreferences.createFragmentArgsForSite(mFullUrl);
Intent preferencesIntent = PreferencesLauncher.createIntentForSettingsPage(
mContext, SingleWebsitePreferences.class.getName());
preferencesIntent.putExtra(
Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArguments);
mContext, SingleWebsitePreferences.class.getName(),
SingleWebsitePreferences.createFragmentArgsForSite(mFullUrl));
// Disabling StrictMode to avoid violations (https://crbug.com/819410).
try (StrictModeContext unused = StrictModeContext.allowDiskReads()) {
mContext.startActivity(preferencesIntent);
......
......@@ -6,7 +6,6 @@ package org.chromium.chrome.browser.payments;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.support.v4.util.ArrayMap;
import android.text.TextUtils;
......@@ -1434,9 +1433,7 @@ public class PaymentRequestImpl
return;
}
Intent intent = PreferencesLauncher.createIntentForSettingsPage(
context, MainPreferences.class.getName());
context.startActivity(intent);
PreferencesLauncher.launchSettingsPage(context, MainPreferences.class);
}
@Override
......
......@@ -5,7 +5,6 @@
package org.chromium.chrome.browser.preferences;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.support.annotation.Nullable;
......@@ -24,7 +23,6 @@ import org.chromium.chrome.browser.signin.SigninAccessPoint;
import org.chromium.chrome.browser.signin.SigninActivity;
import org.chromium.chrome.browser.sync.ProfileSyncService;
import org.chromium.chrome.browser.sync.ui.SyncCustomizationFragment;
import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.chrome.browser.widget.TintedDrawable;
import org.chromium.components.signin.ChromeSigninController;
import org.chromium.ui.text.NoUnderlineClickableSpan;
......@@ -95,18 +93,16 @@ public class ContextualSuggestionsPreference
final NoUnderlineClickableSpan span = new NoUnderlineClickableSpan((widget) -> {
if (isUnifiedConsentEnabled) {
if (isSignedIn) {
Intent intent = PreferencesLauncher.createIntentForSettingsPage(
context, SyncAndServicesPreferences.class.getName());
IntentUtils.safeStartActivity(context, intent);
PreferencesLauncher.launchSettingsPage(
context, SyncAndServicesPreferences.class);
} else {
startActivity(SigninActivity.createIntentForPromoChooseAccountFlow(
context, SigninAccessPoint.SETTINGS, null));
}
} else {
if (isSignedIn) {
Intent intent = PreferencesLauncher.createIntentForSettingsPage(
context, SyncCustomizationFragment.class.getName());
IntentUtils.safeStartActivity(context, intent);
PreferencesLauncher.launchSettingsPage(
context, SyncCustomizationFragment.class);
} else {
startActivity(AccountSigninActivity.createIntentForDefaultSigninFlow(
context, SigninAccessPoint.SETTINGS, false));
......
......@@ -53,8 +53,8 @@ import org.chromium.chrome.browser.profiles.ProfileManagerUtils;
* PreferenceUtils.getShowShadowOnScrollListener(...).
*/
public class Preferences extends AppCompatActivity implements OnPreferenceStartFragmentCallback {
public static final String EXTRA_SHOW_FRAGMENT = "show_fragment";
public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = "show_fragment_args";
static final String EXTRA_SHOW_FRAGMENT = "show_fragment";
static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = "show_fragment_args";
private static final String TAG = "Preferences";
......
......@@ -5,15 +5,18 @@
package org.chromium.chrome.browser.preferences;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.browser.preferences.autofill.AutofillPaymentMethodsFragment;
import org.chromium.chrome.browser.preferences.autofill.AutofillProfilesFragment;
import org.chromium.chrome.browser.preferences.password.SavePasswordsPreferences;
import org.chromium.chrome.browser.preferences.privacy.ClearBrowsingDataTabsFragment;
import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.content_public.browser.WebContents;
import java.lang.ref.WeakReference;
......@@ -28,11 +31,37 @@ public class PreferencesLauncher {
* Launches settings, either on the top-level page or on a subpage.
*
* @param context The current Activity, or an application context if no Activity is available.
* @param fragment The fragment to show, or null to show the top-level page.
*/
public static void launchSettingsPage(
Context context, @Nullable Class<? extends Fragment> fragment) {
launchSettingsPage(context, fragment, null);
}
/**
* Launches settings, either on the top-level page or on a subpage.
*
* @param context The current Activity, or an application context if no Activity is available.
* @param fragment The name of the fragment to show, or null to show the top-level page.
* @param fragmentArgs The arguments bundle to initialize the instance of subpage fragment.
*/
public static void launchSettingsPage(Context context,
@Nullable Class<? extends Fragment> fragment, @Nullable Bundle fragmentArgs) {
String fragmentName = fragment != null ? fragment.getName() : null;
Intent intent = createIntentForSettingsPage(context, fragmentName, fragmentArgs);
IntentUtils.safeStartActivity(context, intent);
}
/**
* Creates an intent for launching settings, either on the top-level settings page or a specific
* subpage.
*
* @param context The current Activity, or an application context if no Activity is available.
* @param fragmentName The name of the fragment to show, or null to show the top-level page.
*/
public static void launchSettingsPage(Context context, String fragmentName) {
Intent intent = createIntentForSettingsPage(context, fragmentName);
context.startActivity(intent);
public static Intent createIntentForSettingsPage(
Context context, @Nullable String fragmentName) {
return createIntentForSettingsPage(context, fragmentName, null);
}
/**
......@@ -41,8 +70,10 @@ public class PreferencesLauncher {
*
* @param context The current Activity, or an application context if no Activity is available.
* @param fragmentName The name of the fragment to show, or null to show the top-level page.
* @param fragmentArgs The arguments bundle to initialize the instance of subpage fragment.
*/
public static Intent createIntentForSettingsPage(Context context, String fragmentName) {
public static Intent createIntentForSettingsPage(
Context context, @Nullable String fragmentName, @Nullable Bundle fragmentArgs) {
Intent intent = new Intent();
intent.setClass(context, Preferences.class);
if (!(context instanceof Activity)) {
......@@ -52,38 +83,31 @@ public class PreferencesLauncher {
if (fragmentName != null) {
intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT, fragmentName);
}
if (fragmentArgs != null) {
intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs);
}
return intent;
}
/**
* Creates an intent for launching clear browsing data, either on the top-level settings page or
* a specific subpage.
*
* @param context The current Activity, or an application context if no Activity is available.
*/
public static Intent createIntentForClearBrowsingDataPage(Context context) {
return createIntentForSettingsPage(context, ClearBrowsingDataTabsFragment.class.getName());
}
@CalledByNative
private static void showAutofillProfileSettings(WebContents webContents) {
showSettingSubpage(webContents, AutofillProfilesFragment.class.getName());
showSettingSubpage(webContents, AutofillProfilesFragment.class);
}
@CalledByNative
private static void showAutofillCreditCardSettings(WebContents webContents) {
showSettingSubpage(webContents, AutofillPaymentMethodsFragment.class.getName());
showSettingSubpage(webContents, AutofillPaymentMethodsFragment.class);
}
@CalledByNative
private static void showPasswordSettings() {
launchSettingsPage(
ContextUtils.getApplicationContext(), SavePasswordsPreferences.class.getName());
launchSettingsPage(ContextUtils.getApplicationContext(), SavePasswordsPreferences.class);
}
private static void showSettingSubpage(WebContents webContents, String className) {
private static void showSettingSubpage(
WebContents webContents, Class<? extends Fragment> fragment) {
WeakReference<Activity> currentActivity =
webContents.getTopLevelNativeWindow().getActivity();
launchSettingsPage(currentActivity.get(), className);
launchSettingsPage(currentActivity.get(), fragment);
}
}
......@@ -5,10 +5,8 @@
package org.chromium.chrome.browser.preferences;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.IntDef;
import android.support.annotation.StringRes;
import android.text.SpannableString;
......@@ -475,11 +473,8 @@ public class SearchEngineAdapter extends BaseAdapter
if (linkBeingShown == R.string.search_engine_system_location_disabled) {
mContext.startActivity(LocationUtils.getInstance().getSystemLocationSettingsIntent());
} else {
Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage(
mContext, SingleWebsitePreferences.class.getName());
Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsForSite(url);
settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs);
mContext.startActivity(settingsIntent);
PreferencesLauncher.launchSettingsPage(mContext, SingleWebsitePreferences.class,
SingleWebsitePreferences.createFragmentArgsForSite(url));
}
}
......
......@@ -5,11 +5,11 @@
package org.chromium.chrome.browser.preferences.datareduction;
import android.content.Context;
import android.content.Intent;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Bundle;
import android.text.format.DateUtils;
import android.text.format.Formatter;
import android.util.AttributeSet;
......@@ -101,11 +101,11 @@ public class DataReductionMainMenuItem extends FrameLayout implements View.OnCli
@Override
public void onClick(View v) {
Intent intent = PreferencesLauncher.createIntentForSettingsPage(
getContext(), DataReductionPreferences.class.getName());
RecordUserAction.record("MobileMenuDataSaverOpened");
intent.putExtra(DataReductionPreferences.FROM_MAIN_MENU, true);
getContext().startActivity(intent);
Bundle fragmentArgs = new Bundle();
fragmentArgs.putBoolean(DataReductionPreferences.FROM_MAIN_MENU, true);
PreferencesLauncher.launchSettingsPage(
getContext(), DataReductionPreferences.class, fragmentArgs);
Tracker tracker = TrackerFactory.getTrackerForProfile(Profile.getLastUsedProfile());
tracker.notifyEvent(EventConstants.DATA_SAVER_DETAIL_OPENED);
......
......@@ -57,14 +57,11 @@ public class DataReductionPreferences extends PreferenceFragment {
setHasOptionsMenu(true);
if (getActivity() != null) {
mFromPromo = IntentUtils.safeGetBooleanExtra(getActivity().getIntent(),
DataReductionPromoSnackbarController.FROM_PROMO, false);
mFromMainMenu = IntentUtils.safeGetBooleanExtra(
getActivity().getIntent(), FROM_MAIN_MENU, false);
mFromInfobar = IntentUtils.safeGetBooleanExtra(
getActivity().getIntent(), PreviewsLitePageInfoBar.FROM_INFOBAR, false);
}
mFromPromo = IntentUtils.safeGetBoolean(
getArguments(), DataReductionPromoSnackbarController.FROM_PROMO, false);
mFromMainMenu = IntentUtils.safeGetBoolean(getArguments(), FROM_MAIN_MENU, false);
mFromInfobar = IntentUtils.safeGetBoolean(
getArguments(), PreviewsLitePageInfoBar.FROM_INFOBAR, false);
}
@Override
......
......@@ -102,8 +102,8 @@ public class PasswordEntryEditor extends Fragment {
mExtras = getArguments();
assert mExtras != null;
mID = mExtras.getInt(SavePasswordsPreferences.PASSWORD_LIST_ID);
mFoundViaSearch = getActivity().getIntent().getBooleanExtra(
SavePasswordsPreferences.EXTRA_FOUND_VIA_SEARCH, false);
mFoundViaSearch =
mExtras.getBoolean(SavePasswordsPreferences.EXTRA_FOUND_VIA_SEARCH, false);
final String name = mExtras.containsKey(SavePasswordsPreferences.PASSWORD_LIST_NAME)
? mExtras.getString(SavePasswordsPreferences.PASSWORD_LIST_NAME)
: null;
......
......@@ -31,7 +31,6 @@ import org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference;
import org.chromium.chrome.browser.preferences.ChromeBasePreference;
import org.chromium.chrome.browser.preferences.ChromeSwitchPreference;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.preferences.Preferences;
import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.preferences.SearchUtils;
import org.chromium.chrome.browser.preferences.TextMessagePreference;
......@@ -385,11 +384,11 @@ public class SavePasswordsPreferences
} else {
// Launch preference activity with PasswordEntryEditor fragment with
// intent extras specifying the object.
Intent intent = PreferencesLauncher.createIntentForSettingsPage(
getActivity(), PasswordEntryEditor.class.getName());
intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, preference.getExtras());
intent.putExtra(SavePasswordsPreferences.EXTRA_FOUND_VIA_SEARCH, mSearchQuery != null);
startActivity(intent);
Bundle fragmentAgs = new Bundle(preference.getExtras());
fragmentAgs.putBoolean(
SavePasswordsPreferences.EXTRA_FOUND_VIA_SEARCH, mSearchQuery != null);
PreferencesLauncher.launchSettingsPage(
getActivity(), PasswordEntryEditor.class, fragmentAgs);
}
return true;
}
......
......@@ -83,7 +83,7 @@ public class PrivacyPreferences extends PreferenceFragment
Preference syncAndServicesLink = findPreference(PREF_SYNC_AND_SERVICES_LINK);
NoUnderlineClickableSpan linkSpan = new NoUnderlineClickableSpan(view -> {
PreferencesLauncher.launchSettingsPage(
getActivity(), SyncAndServicesPreferences.class.getName());
getActivity(), SyncAndServicesPreferences.class);
});
syncAndServicesLink.setSummary(
SpanApplier.applySpans(getString(R.string.privacy_sync_and_services_link),
......
......@@ -9,7 +9,6 @@ import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
......@@ -36,7 +35,6 @@ import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
import org.chromium.chrome.browser.init.EmptyBrowserParts;
import org.chromium.chrome.browser.notifications.channels.SiteChannelsManager;
import org.chromium.chrome.browser.preferences.AboutChromePreferences;
import org.chromium.chrome.browser.preferences.Preferences;
import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.preferences.website.Website.StoredDataClearedCallback;
import org.chromium.chrome.browser.searchwidget.SearchWidgetProvider;
......@@ -236,17 +234,15 @@ public class ManageSpaceActivity extends AppCompatActivity implements View.OnCli
}
mUnimportantDialog.show();
} else if (view == mManageSiteDataButton) {
Intent intent = PreferencesLauncher.createIntentForSettingsPage(
this, SingleCategoryPreferences.class.getName());
Bundle initialArguments = new Bundle();
initialArguments.putString(SingleCategoryPreferences.EXTRA_CATEGORY,
SiteSettingsCategory.preferenceKey(SiteSettingsCategory.Type.USE_STORAGE));
initialArguments.putString(SingleCategoryPreferences.EXTRA_TITLE,
getString(R.string.website_settings_storage));
intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, initialArguments);
RecordHistogram.recordEnumeratedHistogram(
"Android.ManageSpace.ActionTaken", OPTION_MANAGE_STORAGE, OPTION_MAX);
startActivity(intent);
PreferencesLauncher.launchSettingsPage(
this, SingleCategoryPreferences.class, initialArguments);
} else if (view == mClearAllDataButton) {
final ActivityManager activityManager =
(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
......
......@@ -11,7 +11,6 @@ import android.app.Dialog;
import android.app.DialogFragment;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
......@@ -68,8 +67,7 @@ public class AccountManagementFragment extends PreferenceFragment
private static final String CLEAR_DATA_PROGRESS_DIALOG_TAG = "clear_data_progress";
/**
* The key for an integer value in
* {@link Preferences#EXTRA_SHOW_FRAGMENT_ARGUMENTS} bundle to
* The key for an integer value in arguments bundle to
* specify the correct GAIA service that has triggered the dialog.
* If the argument is not set, GAIA_SERVICE_TYPE_NONE is used as the origin of the dialog.
*/
......@@ -510,12 +508,10 @@ public class AccountManagementFragment extends PreferenceFragment
* @param serviceType A signin::GAIAServiceType that triggered the dialog.
*/
public static void openAccountManagementScreen(int serviceType) {
Intent intent = PreferencesLauncher.createIntentForSettingsPage(
ContextUtils.getApplicationContext(), AccountManagementFragment.class.getName());
Bundle arguments = new Bundle();
arguments.putInt(SHOW_GAIA_SERVICE_TYPE_EXTRA, serviceType);
intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, arguments);
ContextUtils.getApplicationContext().startActivity(intent);
PreferencesLauncher.launchSettingsPage(
ContextUtils.getApplicationContext(), AccountManagementFragment.class, arguments);
}
/**
......
......@@ -191,9 +191,8 @@ public class AccountSigninActivity extends SynchronousInitializationActivity
@Override
public void onSignInComplete() {
if (settingsClicked) {
Intent intent = PreferencesLauncher.createIntentForSettingsPage(
context, AccountManagementFragment.class.getName());
startActivity(intent);
PreferencesLauncher.launchSettingsPage(
context, AccountManagementFragment.class);
}
recordSigninCompletedHistogramAccountInfo();
......
......@@ -55,8 +55,7 @@ public class ConsentBumpFragment extends SigninFragmentBase {
boolean settingsClicked, Runnable callback) {
UnifiedConsentServiceBridge.setUnifiedConsentGiven(true);
if (settingsClicked) {
PreferencesLauncher.launchSettingsPage(
getActivity(), SyncAndServicesPreferences.class.getName());
PreferencesLauncher.launchSettingsPage(getActivity(), SyncAndServicesPreferences.class);
}
getActivity().finish();
callback.run();
......
......@@ -137,7 +137,7 @@ public class SigninFragment extends SigninFragmentBase {
UnifiedConsentServiceBridge.setUnifiedConsentGiven(true);
if (settingsClicked) {
PreferencesLauncher.launchSettingsPage(
getActivity(), SyncAndServicesPreferences.class.getName());
getActivity(), SyncAndServicesPreferences.class);
}
recordSigninCompletedHistogramAccountInfo();
......
......@@ -174,7 +174,7 @@ public class SyncPromoView extends LinearLayout implements AndroidSyncSettingsOb
ButtonState positiveButton = new ButtonPresent(R.string.enable_sync_button,
view -> PreferencesLauncher.launchSettingsPage(
getContext(), SyncCustomizationFragment.class.getName()));
getContext(), SyncCustomizationFragment.class));
return new ViewState(descId, positiveButton);
}
......
......@@ -5,7 +5,7 @@
package org.chromium.chrome.browser.snackbar;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import org.chromium.base.CommandLine;
import org.chromium.chrome.R;
......@@ -130,10 +130,10 @@ public class DataReductionPromoSnackbarController implements SnackbarManager.Sna
@Override
public void onAction(Object actionData) {
assert mContext != null;
Intent intent = PreferencesLauncher.createIntentForSettingsPage(
mContext, DataReductionPreferences.class.getName());
intent.putExtra(FROM_PROMO, true);
mContext.startActivity(intent);
Bundle fragmentArgs = new Bundle();
fragmentArgs.putBoolean(FROM_PROMO, true);
PreferencesLauncher.launchSettingsPage(
mContext, DataReductionPreferences.class, fragmentArgs);
}
@Override
......
......@@ -149,9 +149,8 @@ public class SiteSettingsPreferencesTest {
Bundle fragmentArgs = new Bundle();
fragmentArgs.putString(SingleCategoryPreferences.EXTRA_CATEGORY, category);
Intent intent = PreferencesLauncher.createIntentForSettingsPage(
InstrumentationRegistry.getTargetContext(),
SiteSettingsPreferences.class.getName());
intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs);
InstrumentationRegistry.getTargetContext(), SiteSettingsPreferences.class.getName(),
fragmentArgs);
return (Preferences) InstrumentationRegistry.getInstrumentation().startActivitySync(intent);
}
......@@ -161,8 +160,7 @@ public class SiteSettingsPreferencesTest {
SingleCategoryPreferences.EXTRA_CATEGORY, SiteSettingsCategory.preferenceKey(type));
Intent intent = PreferencesLauncher.createIntentForSettingsPage(
InstrumentationRegistry.getTargetContext(),
SingleCategoryPreferences.class.getName());
intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs);
SingleCategoryPreferences.class.getName(), fragmentArgs);
return (Preferences) InstrumentationRegistry.getInstrumentation().startActivitySync(intent);
}
......@@ -171,8 +169,7 @@ public class SiteSettingsPreferencesTest {
fragmentArgs.putSerializable(SingleWebsitePreferences.EXTRA_SITE, site);
Intent intent = PreferencesLauncher.createIntentForSettingsPage(
InstrumentationRegistry.getTargetContext(),
SingleWebsitePreferences.class.getName());
intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs);
SingleWebsitePreferences.class.getName(), fragmentArgs);
return (Preferences) InstrumentationRegistry.getInstrumentation().startActivitySync(intent);
}
......
......@@ -392,9 +392,7 @@ public class VrBrowserTransitionTest {
NativeUiUtils.enableMockedInput();
NativeUiUtils.performActionAndWaitForUiQuiescence(() -> {
ThreadUtils.runOnUiThreadBlocking(() -> {
Intent preferencesIntent = PreferencesLauncher.createIntentForSettingsPage(
context, SingleWebsitePreferences.class.getName());
context.startActivity(preferencesIntent);
PreferencesLauncher.launchSettingsPage(context, SingleWebsitePreferences.class);
});
});
ThreadUtils.runOnUiThreadBlocking(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment