OLD | NEW |
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.content.Context; | 8 import android.content.Context; |
9 | 9 |
10 import org.chromium.base.Callback; | 10 import org.chromium.base.Callback; |
(...skipping 29 matching lines...) Expand all Loading... |
40 * Only for static usage. | 40 * Only for static usage. |
41 */ | 41 */ |
42 private ForcedSigninProcessor() {} | 42 private ForcedSigninProcessor() {} |
43 | 43 |
44 /** | 44 /** |
45 * Check whether a forced automatic signin is required and process it if it
is. | 45 * Check whether a forced automatic signin is required and process it if it
is. |
46 * This is triggered once per Chrome Application lifetime and everytime the
Account state | 46 * This is triggered once per Chrome Application lifetime and everytime the
Account state |
47 * changes with early exit if an account has already been signed in. | 47 * changes with early exit if an account has already been signed in. |
48 */ | 48 */ |
49 public static void start(final Context appContext, @Nullable final Runnable
onComplete) { | 49 public static void start(final Context appContext, @Nullable final Runnable
onComplete) { |
50 if (ChromeSigninController.get(appContext).isSignedIn()) return; | 50 if (ChromeSigninController.get().isSignedIn()) return; |
51 new AndroidEduAndChildAccountHelper() { | 51 new AndroidEduAndChildAccountHelper() { |
52 @Override | 52 @Override |
53 public void onParametersReady() { | 53 public void onParametersReady() { |
54 boolean isAndroidEduDevice = isAndroidEduDevice(); | 54 boolean isAndroidEduDevice = isAndroidEduDevice(); |
55 boolean hasChildAccount = hasChildAccount(); | 55 boolean hasChildAccount = hasChildAccount(); |
56 // If neither a child account or and EDU device, we return. | 56 // If neither a child account or and EDU device, we return. |
57 if (!isAndroidEduDevice && !hasChildAccount) return; | 57 if (!isAndroidEduDevice && !hasChildAccount) return; |
58 // Child account and EDU device at the same time is not supporte
d. | 58 // Child account and EDU device at the same time is not supporte
d. |
59 assert !(isAndroidEduDevice && hasChildAccount); | 59 assert !(isAndroidEduDevice && hasChildAccount); |
60 processForcedSignIn(appContext, onComplete); | 60 processForcedSignIn(appContext, onComplete); |
61 } | 61 } |
62 }.start(appContext); | 62 }.start(appContext); |
63 } | 63 } |
64 | 64 |
65 /** | 65 /** |
66 * Processes the fully automatic non-FRE-related forced sign-in. | 66 * Processes the fully automatic non-FRE-related forced sign-in. |
67 * This is used to enforce the environment for Android EDU and child account
s. | 67 * This is used to enforce the environment for Android EDU and child account
s. |
68 */ | 68 */ |
69 private static void processForcedSignIn( | 69 private static void processForcedSignIn( |
70 final Context appContext, @Nullable final Runnable onComplete) { | 70 final Context appContext, @Nullable final Runnable onComplete) { |
71 final SigninManager signinManager = SigninManager.get(appContext); | 71 final SigninManager signinManager = SigninManager.get(appContext); |
72 // By definition we have finished all the checks for first run. | 72 // By definition we have finished all the checks for first run. |
73 signinManager.onFirstRunCheckDone(); | 73 signinManager.onFirstRunCheckDone(); |
74 if (!FeatureUtilities.canAllowSync(appContext) || !signinManager.isSignI
nAllowed()) { | 74 if (!FeatureUtilities.canAllowSync(appContext) || !signinManager.isSignI
nAllowed()) { |
75 Log.d(TAG, "Sign in disallowed"); | 75 Log.d(TAG, "Sign in disallowed"); |
76 return; | 76 return; |
77 } | 77 } |
78 AccountManagerHelper.get(appContext).getGoogleAccounts(new Callback<Acco
unt[]>() { | 78 AccountManagerHelper.get().getGoogleAccounts(new Callback<Account[]>() { |
79 @Override | 79 @Override |
80 public void onResult(Account[] accounts) { | 80 public void onResult(Account[] accounts) { |
81 if (accounts.length != 1) { | 81 if (accounts.length != 1) { |
82 Log.d(TAG, "Incorrect number of accounts (%d)", accounts.len
gth); | 82 Log.d(TAG, "Incorrect number of accounts (%d)", accounts.len
gth); |
83 return; | 83 return; |
84 } | 84 } |
85 signinManager.signIn(accounts[0], null, new SigninManager.SignIn
Callback() { | 85 signinManager.signIn(accounts[0], null, new SigninManager.SignIn
Callback() { |
86 @Override | 86 @Override |
87 public void onSignInComplete() { | 87 public void onSignInComplete() { |
88 // Since this is a forced signin, signout is not allowed
. | 88 // Since this is a forced signin, signout is not allowed
. |
(...skipping 23 matching lines...) Expand all Loading... |
112 // TODO(bauerb): Once external dependencies reliably use policy to force sig
n-in, | 112 // TODO(bauerb): Once external dependencies reliably use policy to force sig
n-in, |
113 // consider removing the child account / EDU checks. | 113 // consider removing the child account / EDU checks. |
114 public static void checkCanSignIn(final ChromeActivity activity) { | 114 public static void checkCanSignIn(final ChromeActivity activity) { |
115 final Context appContext = activity.getApplicationContext(); | 115 final Context appContext = activity.getApplicationContext(); |
116 if (SigninManager.get(appContext).isForceSigninEnabled()) { | 116 if (SigninManager.get(appContext).isForceSigninEnabled()) { |
117 ExternalAuthUtils.getInstance().canUseGooglePlayServices(appContext, | 117 ExternalAuthUtils.getInstance().canUseGooglePlayServices(appContext, |
118 new UserRecoverableErrorHandler.ModalDialog(activity, false)
); | 118 new UserRecoverableErrorHandler.ModalDialog(activity, false)
); |
119 } | 119 } |
120 } | 120 } |
121 } | 121 } |
OLD | NEW |