Commit d1932d1f authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Commit Bot

[Android FRE] Make lightweight FRE display the app which requested it pt 1/2

This CL makes FirstRunFlowSequencer#checkIfFirstRunIsNecessary() return a
boolean instead of an intent. This is in preparation for making generating
the lightweight FRE intent be more expensive to generate.
FirstRunFlowSequencer#checkIfFirstRunIsNecessary() is called each time that
Chrome is launched and thus must be fast.

BUG=787939

Change-Id: I3dc0651d0796435475f18d3bbe93fce8613262ef
Reviewed-on: https://chromium-review.googlesource.com/798895Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520769}
parent 66b393ed
......@@ -103,8 +103,7 @@ public class CustomTabsConnectionService extends CustomTabsService {
private boolean isFirstRunDone() {
if (mBindIntent == null) return true;
boolean firstRunNecessary = FirstRunFlowSequencer.checkIfFirstRunIsNecessary(
getApplicationContext(), mBindIntent, false)
!= null;
getApplicationContext(), mBindIntent, false);
if (!firstRunNecessary) {
mBindIntent = null;
return true;
......
......@@ -11,7 +11,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import org.chromium.base.ApiCompatibilityUtils;
......@@ -239,17 +238,14 @@ public abstract class FirstRunFlowSequencer {
* @param context The context.
* @param fromIntent The intent that was used to launch Chrome.
* @param preferLightweightFre Whether to prefer the Lightweight First Run Experience.
* @return The intent to launch the First Run Experience if it needs to be launched, or null.
* The intent is for the preferred (Lightweight or non-Lightweight) First Run
* Experience.
* @return Whether the First Run Experience needs to be launched.
*/
@Nullable
public static Intent checkIfFirstRunIsNecessary(
public static boolean checkIfFirstRunIsNecessary(
Context context, Intent fromIntent, boolean preferLightweightFre) {
// If FRE is disabled (e.g. in tests), proceed directly to the intent handling.
if (CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE)
|| ApiCompatibilityUtils.isDemoUser(context)) {
return null;
return false;
}
// If Chrome isn't opened via the Chrome icon, and the user accepted the ToS
......@@ -257,22 +253,15 @@ public abstract class FirstRunFlowSequencer {
// to the intent handling.
final boolean fromChromeIcon =
fromIntent != null && TextUtils.equals(fromIntent.getAction(), Intent.ACTION_MAIN);
if (!fromChromeIcon && ToSAckedReceiver.checkAnyUserHasSeenToS()) return null;
final boolean baseFreComplete = FirstRunStatus.getFirstRunFlowComplete();
if (!baseFreComplete) {
if (preferLightweightFre) {
if (!FirstRunStatus.shouldSkipWelcomePage()
&& !FirstRunStatus.getLightweightFirstRunFlowComplete()) {
return createLightweightFirstRunIntent(context);
}
} else {
return createGenericFirstRunIntent(context, fromChromeIcon);
}
}
if (!fromChromeIcon && ToSAckedReceiver.checkAnyUserHasSeenToS()) return false;
// Promo pages are removed, so there is nothing else to show in FRE.
return null;
if (FirstRunStatus.getFirstRunFlowComplete()) {
// Promo pages are removed, so there is nothing else to show in FRE.
return false;
}
return !preferLightweightFre
|| (!FirstRunStatus.shouldSkipWelcomePage()
&& !FirstRunStatus.getLightweightFirstRunFlowComplete());
}
/**
......@@ -340,11 +329,18 @@ public abstract class FirstRunFlowSequencer {
}
// Check if the user needs to go through First Run at all.
Intent freIntent = checkIfFirstRunIsNecessary(caller, intent, preferLightweightFre);
if (freIntent == null) return false;
if (!checkIfFirstRunIsNecessary(caller, intent, preferLightweightFre)) return false;
Log.d(TAG, "Redirecting user through FRE.");
if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
boolean isVrIntent = VrIntentUtils.isVrIntent(intent);
Intent freCallerIntent = null;
if (isVrIntent) {
// Modify the caller intent to handle FRE completion correctly for VR.
freCallerIntent = new Intent(intent);
VrIntentUtils.updateFreCallerIntent(caller, intent);
}
boolean isGenericFreActive = false;
List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities();
for (WeakReference<Activity> weakActivity : activities) {
......@@ -355,25 +351,20 @@ public abstract class FirstRunFlowSequencer {
}
}
if (isGenericFreActive) {
// Launch the Generic First Run Experience if it was previously active.
// Launch the Generic First Run Experience if it was previously active.
Intent freIntent = null;
if (preferLightweightFre && !isGenericFreActive) {
freIntent = createLightweightFirstRunIntent(caller);
} else {
freIntent = createGenericFirstRunIntent(
caller, TextUtils.equals(intent.getAction(), Intent.ACTION_MAIN));
}
boolean isVrIntent = VrIntentUtils.isVrIntent(intent);
Intent freCallerIntent = null;
if (isVrIntent) {
// Modify the caller intent to handle FRE completion correctly for VR.
freCallerIntent = new Intent(intent);
VrIntentUtils.updateFreCallerIntent(caller, intent);
}
if (maybeSwitchToTabbedMode(caller, freIntent)) {
// We switched to TabbedModeFRE. We need to disable animation on the original
// intent, to make transition seamless.
intent = new Intent(intent);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
if (maybeSwitchToTabbedMode(caller, freIntent)) {
// We switched to TabbedModeFRE. We need to disable animation on the original
// intent, to make transition seamless.
intent = new Intent(intent);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
}
}
// Add a PendingIntent so that the intent used to launch Chrome will be resent when
......@@ -422,11 +413,7 @@ public abstract class FirstRunFlowSequencer {
if (backgroundResourceId != R.drawable.window_background) return false;
// Switch FRE -> TabbedModeFRE.
if (FirstRunActivity.class.getName().equals(freIntent.getComponent().getClassName())) {
freIntent.setClass(caller, TabbedModeFirstRunActivity.class);
return true;
}
return false;
freIntent.setClass(caller, TabbedModeFirstRunActivity.class);
return true;
}
}
......@@ -78,9 +78,7 @@ class NativeInitializationController {
ThreadUtils.assertOnUiThread();
assert mBackgroundTasksComplete == null;
boolean fetchVariationsSeed = FirstRunFlowSequencer.checkIfFirstRunIsNecessary(
ContextUtils.getApplicationContext(),
mActivityDelegate.getInitialIntent(), false)
!= null;
ContextUtils.getApplicationContext(), mActivityDelegate.getInitialIntent(), false);
mBackgroundTasksComplete = false;
new AsyncInitTaskRunner() {
......
......@@ -398,9 +398,8 @@ public class SearchWidgetProvider extends AppWidgetProvider {
}
static boolean shouldShowFullString() {
boolean freIsNotNecessary = FirstRunFlowSequencer.checkIfFirstRunIsNecessary(
getDelegate().getContext(), null, false)
== null;
boolean freIsNotNecessary = !FirstRunFlowSequencer.checkIfFirstRunIsNecessary(
getDelegate().getContext(), null, false);
boolean noNeedToCheckForSearchDialog =
!LocaleManager.getInstance().needToCheckForSearchEnginePromo();
return freIsNotNecessary && noNeedToCheckForSearchDialog;
......
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