[Android] Show restart prompt on credential-refresh Origin purchase (#36904)
When an Origin purchase is first detected via credential refresh (e.g. linked from account.brave.com), open the Origin settings screen and show the existing restart snackbar. The shared first-purchase trigger in BraveOriginService::OnCredentialSummary calls the navigation delegate, whose Android branch was previously a no-op. It now routes through a JNI helper that opens BraveOriginPreferences with an explicit show-restart flag, where onViewCreated shows the restart snackbar. Play Store purchases are left to the existing Java subscription flow (which shows the "Disabling features" spinner while credentials are fetched, then transitions to the restart prompt). The helper skips opening when a Play Store purchase token is present so the screen isn't opened twice. Resolves: https://github.com/brave/brave-browser/issues/55991
This commit is contained in:
+35
@@ -0,0 +1,35 @@
|
||||
/* Copyright (c) 2026 The Brave Authors. All rights reserved.
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.chromium.chrome.browser.brave_origin;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.jni_zero.CalledByNative;
|
||||
|
||||
import org.chromium.base.ApplicationStatus;
|
||||
import org.chromium.build.annotations.NullMarked;
|
||||
import org.chromium.chrome.browser.settings.BraveOriginPreferences;
|
||||
import org.chromium.chrome.browser.settings.SettingsNavigationFactory;
|
||||
|
||||
/**
|
||||
* Opens the Brave Origin settings screen from native when a purchase is first detected, so the user
|
||||
* can restart to apply the newly enforced policies.
|
||||
*/
|
||||
@NullMarked
|
||||
public class BraveOriginSettingsLauncherHelper {
|
||||
@CalledByNative
|
||||
private static void showOriginSettingsForRestart() {
|
||||
Activity activity = ApplicationStatus.getLastTrackedFocusedActivity();
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
Bundle args = new Bundle();
|
||||
args.putBoolean(BraveOriginPreferences.EXTRA_SHOW_RESTART_PROMPT, true);
|
||||
SettingsNavigationFactory.createSettingsNavigation()
|
||||
.startSettings(activity, BraveOriginPreferences.class, args);
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,12 @@ public class BraveOriginPreferences extends BravePreferenceFragment
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
private static final String TAG = "BraveOriginPrefs";
|
||||
|
||||
/**
|
||||
* Fragment argument: when true, show the restart snackbar on open (set by native when a
|
||||
* purchase is first detected via credential refresh).
|
||||
*/
|
||||
public static final String EXTRA_SHOW_RESTART_PROMPT = "show_restart_prompt";
|
||||
|
||||
// Preference keys
|
||||
private static final String PREF_REWARDS_SWITCH = "rewards_switch";
|
||||
private static final String PREF_PRIVACY_PRESERVING_ANALYTICS_SWITCH =
|
||||
@@ -76,6 +82,12 @@ public class BraveOriginPreferences extends BravePreferenceFragment
|
||||
/** Whether we are in the post-purchase "fetching credentials" state. */
|
||||
private boolean mIsFetchingCredentials;
|
||||
|
||||
/**
|
||||
* Whether to show the restart snackbar on open. Set when the screen is opened by native after a
|
||||
* credential-refresh purchase, where credentials are already present (no fetching spinner).
|
||||
*/
|
||||
private boolean mShowRestartPrompt;
|
||||
|
||||
/** References to the fetching/restart containers in the snackbar for toggling visibility. */
|
||||
@Nullable private View mFetchingContainer;
|
||||
|
||||
@@ -149,6 +161,11 @@ public class BraveOriginPreferences extends BravePreferenceFragment
|
||||
});
|
||||
}
|
||||
|
||||
Bundle args = getArguments();
|
||||
if (args != null) {
|
||||
mShowRestartPrompt = args.getBoolean(EXTRA_SHOW_RESTART_PROMPT, false);
|
||||
}
|
||||
|
||||
// Check if we are in the post-purchase state (credentials being fetched)
|
||||
if (BraveOriginSubscriptionPrefs.isFetchingCredentials(profile)) {
|
||||
mIsFetchingCredentials = true;
|
||||
@@ -177,6 +194,8 @@ public class BraveOriginPreferences extends BravePreferenceFragment
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
if (mIsFetchingCredentials) {
|
||||
showFetchingSnackbar();
|
||||
} else if (mShowRestartPrompt) {
|
||||
showRestartSnackbar();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user