Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/firstrun/FirstRunFlowSequencer.java

Issue 2519853004: Allow fetching variations while FRE is showing on Android first run. (Closed)
Patch Set: Fix unit tests. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.firstrun; 5 package org.chromium.chrome.browser.firstrun;
6 6
7 import android.accounts.Account; 7 import android.accounts.Account;
8 import android.app.Activity; 8 import android.app.Activity;
9 import android.app.PendingIntent; 9 import android.app.PendingIntent;
10 import android.content.Context; 10 import android.content.Context;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 private static final int FIRST_RUN_EXPERIENCE_REQUEST_CODE = 101; 42 private static final int FIRST_RUN_EXPERIENCE_REQUEST_CODE = 101;
43 43
44 private final Activity mActivity; 44 private final Activity mActivity;
45 private final Bundle mLaunchProperties; 45 private final Bundle mLaunchProperties;
46 46
47 /** 47 /**
48 * Callback that is called once the flow is determined. 48 * Callback that is called once the flow is determined.
49 * If the properties is null, the First Run experience needs to finish and 49 * If the properties is null, the First Run experience needs to finish and
50 * restart the original intent if necessary. 50 * restart the original intent if necessary.
51 * @param freProperties Properties to be used in the First Run activity, or null. 51 * @param freProperties Properties to be used in the First Run activity, or null.
52 * @param setUpPropertiesPostNative Runnable that should be run to finish in itialization of
53 * freProperties after native initialization.
Ted C 2016/12/01 21:59:06 should be aligned with "Runnable that..."
Alexei Svitkine (slow) 2016/12/02 18:34:54 Removed param.
52 */ 54 */
53 public abstract void onFlowIsKnown(Bundle freProperties); 55 public abstract void onFlowIsKnown(Bundle freProperties, Runnable setUpPrope rtiesPostNative);
54 56
55 public FirstRunFlowSequencer(Activity activity, Bundle launcherProvidedPrope rties) { 57 public FirstRunFlowSequencer(Activity activity, Bundle launcherProvidedPrope rties) {
56 mActivity = activity; 58 mActivity = activity;
57 mLaunchProperties = launcherProvidedProperties; 59 mLaunchProperties = launcherProvidedProperties;
58 } 60 }
59 61
60 /** 62 /**
61 * Starts determining parameters for the First Run. 63 * Starts determining parameters for the First Run.
62 * Once finished, calls onFlowIsKnown(). 64 * Once finished, calls onFlowIsKnown().
63 */ 65 */
64 public void start() { 66 public void start() {
65 if (CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_FIRST_RUN _EXPERIENCE) 67 if (CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_FIRST_RUN _EXPERIENCE)
66 || ApiCompatibilityUtils.isDemoUser(mActivity)) { 68 || ApiCompatibilityUtils.isDemoUser(mActivity)) {
67 onFlowIsKnown(null); 69 onFlowIsKnown(null, null);
68 return; 70 return;
69 } 71 }
70 72
71 if (!mLaunchProperties.getBoolean(FirstRunActivity.EXTRA_USE_FRE_FLOW_SE QUENCER)) {
72 onFlowIsKnown(mLaunchProperties);
73 return;
74 }
75
76 new AndroidEduAndChildAccountHelper() { 73 new AndroidEduAndChildAccountHelper() {
77 @Override 74 @Override
78 public void onParametersReady() { 75 public void onParametersReady() {
79 processFreEnvironment(isAndroidEduDevice(), hasChildAccount()); 76 processFreEnvironment(isAndroidEduDevice(), hasChildAccount());
80 } 77 }
81 }.start(mActivity.getApplicationContext()); 78 }.start(mActivity.getApplicationContext());
82 } 79 }
83 80
84 @VisibleForTesting 81 @VisibleForTesting
85 protected boolean isFirstRunFlowComplete() { 82 protected boolean isFirstRunFlowComplete() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 PrivacyPreferencesManager.getInstance().setUsageAndCrashReporting( 125 PrivacyPreferencesManager.getInstance().setUsageAndCrashReporting(
129 FirstRunActivity.DEFAULT_METRICS_AND_CRASH_REPORTING); 126 FirstRunActivity.DEFAULT_METRICS_AND_CRASH_REPORTING);
130 } 127 }
131 128
132 @VisibleForTesting 129 @VisibleForTesting
133 protected void setFirstRunFlowSignInComplete() { 130 protected void setFirstRunFlowSignInComplete() {
134 FirstRunSignInProcessor.setFirstRunFlowSignInComplete( 131 FirstRunSignInProcessor.setFirstRunFlowSignInComplete(
135 mActivity.getApplicationContext(), true); 132 mActivity.getApplicationContext(), true);
136 } 133 }
137 134
138 void processFreEnvironment(boolean androidEduDevice, boolean hasChildAccount ) { 135 void processFreEnvironment(boolean androidEduDevice, final boolean hasChildA ccount) {
139 if (isFirstRunFlowComplete()) { 136 if (isFirstRunFlowComplete()) {
140 assert isFirstRunEulaAccepted(); 137 assert isFirstRunEulaAccepted();
141 // We do not need any interactive FRE. 138 // We do not need any interactive FRE.
142 onFlowIsKnown(null); 139 onFlowIsKnown(null, null);
143 return; 140 return;
144 } 141 }
145 142
146 Bundle freProperties = new Bundle(); 143 final Account[] googleAccounts = getGoogleAccounts();
147 freProperties.putAll(mLaunchProperties); 144 final boolean onlyOneAccount = googleAccounts.length == 1;
148 freProperties.remove(FirstRunActivity.EXTRA_USE_FRE_FLOW_SEQUENCER);
149
150 Account[] googleAccounts = getGoogleAccounts();
151 boolean onlyOneAccount = googleAccounts.length == 1;
152 145
153 // EDU devices should always have exactly 1 google account, which will b e automatically 146 // EDU devices should always have exactly 1 google account, which will b e automatically
154 // signed-in. All FRE screens are skipped in this case. 147 // signed-in. All FRE screens are skipped in this case.
155 boolean forceEduSignIn = androidEduDevice && onlyOneAccount && !isSigned In(); 148 final boolean forceEduSignIn = androidEduDevice && onlyOneAccount && !is SignedIn();
149
150 boolean useFlowSequencer =
151 mLaunchProperties.getBoolean(FirstRunActivity.EXTRA_USE_FRE_FLOW _SEQUENCER);
152 // Note: freProperties is bound to the Runnable below.
153 final Bundle freProperties = useFlowSequencer ? new Bundle() : mLaunchPr operties;
154
155 Runnable setUpPropertiesPostNative = new Runnable() {
Ted C 2016/12/01 21:59:06 instead of passing a Runnable, I think this should
Alexei Svitkine (slow) 2016/12/02 18:34:54 Done. Compared to the previous approach, this requ
156 @Override
157 public void run() {
158 // We show the sign-in page if sync is allowed, and not signed i n, and this is not
Ted C 2016/12/01 21:59:06 should this remove POST_NATIVE_SETUP_NEEDED?
Alexei Svitkine (slow) 2016/12/02 18:34:54 Done.
159 // an EDU device, and
160 // - no "skip the first use hints" is set, or
161 // - "skip the first use hints" is set, but there is at least on e account.
162 boolean offerSignInOk = isSyncAllowed() && !isSignedIn() && !for ceEduSignIn
163 && (!shouldSkipFirstUseHints() || googleAccounts.length > 0);
164 freProperties.putBoolean(FirstRunActivity.SHOW_SIGNIN_PAGE, offe rSignInOk);
165 if (offerSignInOk || forceEduSignIn) {
166 // If the user has accepted the ToS in the Setup Wizard and there is exactly
167 // one account, or if the device has a child account, or if the device is an
168 // Android EDU device and there is exactly one account, pres elect the sign-in
169 // account and force the selection if necessary.
170 if ((hasAnyUserSeenToS() && onlyOneAccount) || hasChildAccou nt
171 || forceEduSignIn) {
172 freProperties.putString(AccountFirstRunFragment.FORCE_SI GNIN_ACCOUNT_TO,
173 googleAccounts[0].name);
174 freProperties.putBoolean(
175 AccountFirstRunFragment.PRESELECT_BUT_ALLOW_TO_C HANGE,
176 !forceEduSignIn && !hasChildAccount);
177 }
178 }
179
180 freProperties.putBoolean(
181 FirstRunActivity.SHOW_DATA_REDUCTION_PAGE, shouldShowDat aReductionPage());
182 }
183 };
184
185 if (!useFlowSequencer) {
186 // If EXTRA_USE_FRE_FLOW_SEQUENCER is not set, it means we should us e the properties as
187 // provided instead of setting them up. However, the properties as p rovided may not yet
188 // have post-native properties computed, so the Runnable still needs to be passed.
189 onFlowIsKnown(mLaunchProperties, setUpPropertiesPostNative);
190 return;
191 }
192
193 freProperties.putAll(mLaunchProperties);
194 freProperties.remove(FirstRunActivity.EXTRA_USE_FRE_FLOW_SEQUENCER);
156 195
157 // In the full FRE we always show the Welcome page, except on EDU device s. 196 // In the full FRE we always show the Welcome page, except on EDU device s.
158 boolean showWelcomePage = !forceEduSignIn; 197 boolean showWelcomePage = !forceEduSignIn;
159 freProperties.putBoolean(FirstRunActivity.SHOW_WELCOME_PAGE, showWelcome Page); 198 freProperties.putBoolean(FirstRunActivity.SHOW_WELCOME_PAGE, showWelcome Page);
199 freProperties.putBoolean(AccountFirstRunFragment.IS_CHILD_ACCOUNT, hasCh ildAccount);
200
201 // Set a boolean to indicate we need to do post native setup via the run nable below.
202 freProperties.putBoolean(FirstRunActivity.POST_NATIVE_SETUP_NEEDED, true );
160 203
161 // Initialize usage and crash reporting according to the default value. 204 // Initialize usage and crash reporting according to the default value.
162 // The user can explicitly enable or disable the reporting on the Welcom e page. 205 // The user can explicitly enable or disable the reporting on the Welcom e page.
163 // This is controlled by the administrator via a policy on EDU devices. 206 // This is controlled by the administrator via a policy on EDU devices.
164 setDefaultMetricsAndCrashReporting(); 207 setDefaultMetricsAndCrashReporting();
165 208
166 // We show the sign-in page if sync is allowed, and not signed in, and t his is not an EDU 209 onFlowIsKnown(freProperties, setUpPropertiesPostNative);
167 // device, and
168 // - no "skip the first use hints" is set, or
169 // - "skip the first use hints" is set, but there is at least one accoun t.
170 final boolean offerSignInOk = isSyncAllowed()
171 && !isSignedIn()
172 && !forceEduSignIn
173 && (!shouldSkipFirstUseHints() || googleAccounts.length > 0);
174 freProperties.putBoolean(FirstRunActivity.SHOW_SIGNIN_PAGE, offerSignInO k);
175
176 if (offerSignInOk || forceEduSignIn) {
177 // If the user has accepted the ToS in the Setup Wizard and there is exactly
178 // one account, or if the device has a child account, or if the devi ce is an
179 // Android EDU device and there is exactly one account, preselect th e sign-in
180 // account and force the selection if necessary.
181 if ((hasAnyUserSeenToS() && onlyOneAccount) || hasChildAccount || fo rceEduSignIn) {
182 freProperties.putString(AccountFirstRunFragment.FORCE_SIGNIN_ACC OUNT_TO,
183 googleAccounts[0].name);
184 freProperties.putBoolean(AccountFirstRunFragment.PRESELECT_BUT_A LLOW_TO_CHANGE,
185 !forceEduSignIn && !hasChildAccount);
186 }
187 }
188
189 freProperties.putBoolean(AccountFirstRunFragment.IS_CHILD_ACCOUNT, hasCh ildAccount);
190
191 freProperties.putBoolean(FirstRunActivity.SHOW_DATA_REDUCTION_PAGE,
192 shouldShowDataReductionPage());
193
194 onFlowIsKnown(freProperties);
195 if (hasChildAccount || forceEduSignIn) { 210 if (hasChildAccount || forceEduSignIn) {
196 // Child and Edu forced signins are processed independently. 211 // Child and Edu forced signins are processed independently.
197 setFirstRunFlowSignInComplete(); 212 setFirstRunFlowSignInComplete();
198 } 213 }
199 } 214 }
200 215
201 /** 216 /**
202 * Marks a given flow as completed. 217 * Marks a given flow as completed.
203 * @param activity An activity. 218 * @param activity An activity.
204 * @param data Resulting FRE properties bundle. 219 * @param data Resulting FRE properties bundle.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 * @param fromIntent The intent that was used to launch Chrome. 303 * @param fromIntent The intent that was used to launch Chrome.
289 */ 304 */
290 public static void addPendingIntent(Context context, Intent firstRunIntent, Intent fromIntent) { 305 public static void addPendingIntent(Context context, Intent firstRunIntent, Intent fromIntent) {
291 PendingIntent pendingIntent = PendingIntent.getActivity(context, 306 PendingIntent pendingIntent = PendingIntent.getActivity(context,
292 FIRST_RUN_EXPERIENCE_REQUEST_CODE, 307 FIRST_RUN_EXPERIENCE_REQUEST_CODE,
293 fromIntent, 308 fromIntent,
294 fromIntent.getFlags()); 309 fromIntent.getFlags());
295 firstRunIntent.putExtra(FirstRunActivity.EXTRA_CHROME_LAUNCH_INTENT, pen dingIntent); 310 firstRunIntent.putExtra(FirstRunActivity.EXTRA_CHROME_LAUNCH_INTENT, pen dingIntent);
296 } 311 }
297 } 312 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698