Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevents a crash on Android when Activity is not foreground and there is an attempt to set a default browser dialog #17916

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.chromium.base.BravePreferenceKeys;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.onboarding.OnboardingPrefManager;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
Expand All @@ -33,6 +34,7 @@
import org.chromium.ui.widget.Toast;

public class BraveSetDefaultBrowserUtils {
private static final String TAG = "BSDBrowserUtils";
public static final String ANDROID_SETUPWIZARD_PACKAGE_NAME = "com.google.android.setupwizard";
public static final String ANDROID_PACKAGE_NAME = "android";
public static final String BRAVE_BLOG_URL = "https://brave.com/privacy-features/";
Expand Down Expand Up @@ -98,19 +100,25 @@ public static void showBraveSetDefaultBrowserDialog(
if (!isBottomSheetVisible) {
isBottomSheetVisible = true;

try {
SetDefaultBrowserBottomSheetFragment bottomSheetDialog =
SetDefaultBrowserBottomSheetFragment.newInstance(isFromMenu);

bottomSheetDialog.show(activity.getSupportFragmentManager(),
"SetDefaultBrowserBottomSheetFragment");
tapanmodh marked this conversation as resolved.
Show resolved Hide resolved
} catch (IllegalStateException e) {
// That exception could be thrown when Activity is not in the foreground.
Log.e(TAG, "showBraveSetDefaultBrowserDialog error: " + e.getMessage());
return;
}

if (!isFromMenu) {
int braveDefaultModalCount = SharedPreferencesManager.getInstance().readInt(
BravePreferenceKeys.BRAVE_SET_DEFAULT_BOTTOM_SHEET_COUNT);
SharedPreferencesManager.getInstance().writeInt(
BravePreferenceKeys.BRAVE_SET_DEFAULT_BOTTOM_SHEET_COUNT,
braveDefaultModalCount + 1);
}

SetDefaultBrowserBottomSheetFragment bottomSheetDialog =
SetDefaultBrowserBottomSheetFragment.newInstance(isFromMenu);

bottomSheetDialog.show(
activity.getSupportFragmentManager(), "SetDefaultBrowserBottomSheetFragment");
}
}

Expand Down