Merge pull request #26302 from brave/android_password_settings_fix

[Android] Fix for crash in Password settings
This commit is contained in:
samartnik
2024-10-30 17:23:44 -04:00
committed by GitHub
3 changed files with 19 additions and 24 deletions
@@ -5,32 +5,10 @@
package org.chromium.chrome.browser.password_manager.settings;
import android.view.Menu;
import org.chromium.chrome.browser.settings.BravePreferenceFragment;
public abstract class BravePasswordSettingsBase extends BravePreferenceFragment {
/*
* This variable will be used instead of upstream's `PasswordSettings#mMenu`.
*/
protected Menu mMenu;
public void createCheckPasswords() {
// Do nothing here as we don't have check passwords option in Brave.
}
@Override
public void onDestroy() {
super.onDestroy();
/*
* In `PasswordSettings` class `passwordListAvailable` method gets called before `onCreateOptionsMenu`.
* Now on pressing `back`, Seetings activity is not finished, but just returns 1 fragment back.
* This causes null pointer crash on returning to the password settings page, since `mMenu` is already not null,
* but not inflated yet by the time we call `passwordListAvailable` and we try to access `export_passwords`.
* This issue is not happening in the upstream since they use different password settings page that utilizes OS level password manager.
* So here we make sure `mMenu` is null every time we leave password settings page.
*/
mMenu = null;
}
}
@@ -12,7 +12,13 @@ import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
public class BraveSettingsIntentUtil {
private static String PASSWORD_SETTINGS_FRAGMENT =
"org.chromium.chrome.browser.password_manager.settings.PasswordSettings";
private static String CREDENTIAL_EDIT_FRAGMENT =
"org.chromium.chrome.browser.password_entry_edit.CredentialEditFragmentView";
public static Intent createIntent(
@NonNull Context context,
@@ -20,6 +26,19 @@ public class BraveSettingsIntentUtil {
@Nullable Bundle fragmentArgs) {
Intent intent = SettingsIntentUtil.createIntent(context, fragmentName, fragmentArgs);
intent.setClass(context, BraveSettingsActivity.class);
/*
* Password settings and credential edit fragments are not used in the upstream anymore and
* thus not adjusted to be used within single Settings activity. For now we just open them
* with a separate activity as it used to be.
* Going forward we should adjust them to be used within the single Settings activity
* https://github.com/brave/brave-browser/issues/41977
*/
if (ChromeFeatureList.sSettingsSingleActivity.isEnabled()
&& fragmentName != null
&& (fragmentName.equals(PASSWORD_SETTINGS_FRAGMENT)
|| fragmentName.equals(CREDENTIAL_EDIT_FRAGMENT))) {
intent.removeFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
}
return intent;
}
}