Commit 8c6ff416 authored by Peter E Conn's avatar Peter E Conn Committed by Commit Bot

🍱 Remove dependency from ExternalAuthUtils to AppHooks.

This will allow ExternalAuthUtils to be moved to a separate module.

Change-Id: I03c3217ca22ad4a0aa6e0dbd33cbe56032aca48d
Bug: 1104817
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2400622Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Peter Conn <peconn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805659}
parent 055b2ac2
......@@ -139,14 +139,12 @@ public abstract class AppHooks {
/**
* @return An instance of ExternalAuthUtils to be installed as a singleton.
*/
public ExternalAuthUtils createExternalAuthUtils() {
protected ExternalAuthUtils createExternalAuthUtils() {
return new ExternalAuthUtils();
}
/**
* @return The singleton instance of ExternalAuthUtils.
*
* TODO(https://crbug.com/1104817): Make createExternalAuthUtils protected.
*/
public ExternalAuthUtils getExternalAuthUtils() {
if (mExternalAuthUtils == null) {
......
......@@ -28,7 +28,7 @@ public class AppHooksModule {
@Provides
public ExternalAuthUtils provideExternalAuthUtils() {
return ExternalAuthUtils.getInstance();
return AppHooks.get().getExternalAuthUtils();
}
@Provides
......
......@@ -99,9 +99,10 @@ public class ChromeVersionInfo {
final long installedGmsVersion = getPlayServicesApkVersionNumber(context);
final String accessType;
if (ExternalAuthUtils.canUseFirstPartyGooglePlayServices()) {
ExternalAuthUtils externalAuthUtils = AppHooks.get().getExternalAuthUtils();
if (externalAuthUtils.canUseFirstPartyGooglePlayServices()) {
accessType = "1p";
} else if (ExternalAuthUtils.canUseGooglePlayServices()) {
} else if (externalAuthUtils.canUseGooglePlayServices()) {
accessType = "3p";
} else {
accessType = "none";
......
......@@ -39,7 +39,6 @@ import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.browser.customtabs.CustomTabsConnection;
import org.chromium.chrome.browser.document.ChromeLauncherActivity;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.chrome.browser.externalnav.ExternalNavigationDelegateImpl;
import org.chromium.chrome.browser.externalnav.IntentWithRequestMetadataHandler;
import org.chromium.chrome.browser.externalnav.IntentWithRequestMetadataHandler.RequestMetadata;
......@@ -1038,7 +1037,7 @@ public class IntentHandler {
if (isChromeToken(token)) {
return true;
}
if (ExternalAuthUtils.getInstance().isGoogleSigned(token.getCreatorPackage())) {
if (AppHooks.get().getExternalAuthUtils().isGoogleSigned(token.getCreatorPackage())) {
return true;
}
return false;
......
......@@ -10,7 +10,6 @@ import org.chromium.chrome.browser.app.tab_activity_glue.ActivityTabWebContentsD
import org.chromium.chrome.browser.compositor.bottombar.ephemeraltab.EphemeralTabCoordinator;
import org.chromium.chrome.browser.contextmenu.ChromeContextMenuPopulator;
import org.chromium.chrome.browser.contextmenu.ContextMenuPopulator;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.chrome.browser.externalnav.ExternalNavigationDelegateImpl;
import org.chromium.chrome.browser.native_page.NativePageFactory;
import org.chromium.chrome.browser.share.ShareDelegate;
......@@ -65,7 +64,7 @@ public class TabbedModeTabDelegateFactory implements TabDelegateFactory {
new TabContextMenuItemDelegate(
tab, mActivity.getTabModelSelector(), mEphemeralTabCoordinatorSupplier),
mShareDelegateSupplier, ChromeContextMenuPopulator.ContextMenuMode.NORMAL,
ExternalAuthUtils.getInstance());
AppHooks.get().getExternalAuthUtils());
}
@Override
......
......@@ -9,7 +9,7 @@ import androidx.annotation.VisibleForTesting;
import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.chrome.browser.AppHooks;
/**
* Used to check whether Google Play Services version on the device is as
......@@ -29,7 +29,7 @@ final class GooglePlayServicesChecker {
@VisibleForTesting
protected static boolean shouldDisableBackgroundSync() {
boolean isAvailable = true;
if (!ExternalAuthUtils.canUseGooglePlayServices()) {
if (!AppHooks.get().getExternalAuthUtils().canUseGooglePlayServices()) {
Log.i(TAG, "Disabling Background Sync because Play Services is not up to date.");
isAvailable = false;
}
......
......@@ -20,6 +20,7 @@ import org.chromium.base.IntentUtils;
import org.chromium.base.Log;
import org.chromium.base.PackageManagerUtils;
import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.app.ChromeActivity;
......@@ -475,7 +476,7 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
new TabContextMenuItemDelegate(tab, tabModelSelector,
EphemeralTabCoordinator.isSupported() ? mEphemeralTabCoordinator::get
: () -> null),
shareDelegateSupplier, contextMenuMode, ExternalAuthUtils.getInstance());
shareDelegateSupplier, contextMenuMode, AppHooks.get().getExternalAuthUtils());
}
@Override
......
......@@ -59,7 +59,6 @@ import org.chromium.chrome.browser.browserservices.PostMessageHandler;
import org.chromium.chrome.browser.browserservices.SessionDataHolder;
import org.chromium.chrome.browser.browserservices.SessionHandler;
import org.chromium.chrome.browser.device.DeviceClassManager;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.init.ChainedTasks;
import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
......@@ -1082,7 +1081,7 @@ public class CustomTabsConnection {
public boolean isSessionFirstParty(CustomTabsSessionToken session) {
String packageName = getClientPackageNameForSession(session);
if (packageName == null) return false;
return ExternalAuthUtils.getInstance().isGoogleSigned(packageName);
return AppHooks.get().getExternalAuthUtils().isGoogleSigned(packageName);
}
void setIgnoreUrlFragmentsForSession(CustomTabsSessionToken session, boolean value) {
......
......@@ -23,7 +23,6 @@ import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.StrictModeContext;
import org.chromium.base.task.PostTask;
import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.components.embedder_support.util.Origin;
import org.chromium.content_public.browser.UiThreadTaskTraits;
......@@ -38,15 +37,6 @@ public class ExternalAuthUtils {
public static final int FLAG_SHOULD_BE_SYSTEM = 1 << 1;
private static final String TAG = "ExternalAuthUtils";
private static final ExternalAuthUtils sInstance = AppHooks.get().createExternalAuthUtils();
/**
* Returns the singleton instance of ExternalAuthUtils, creating it if needed.
*/
public static ExternalAuthUtils getInstance() {
return sInstance;
}
/**
* Gets the calling package names for the current transaction.
* @param context The context to use for accessing the package manager.
......@@ -212,8 +202,8 @@ public class ExternalAuthUtils {
*
* @return true if and only if Google Play Services can be used
*/
public static boolean canUseGooglePlayServices() {
return sInstance.canUseGooglePlayServices(new UserRecoverableErrorHandler.Silent());
public boolean canUseGooglePlayServices() {
return canUseGooglePlayServices(new UserRecoverableErrorHandler.Silent());
}
/**
......@@ -247,9 +237,8 @@ public class ExternalAuthUtils {
*
* @return true if and only if first-party Google Play Services can be used
*/
public static boolean canUseFirstPartyGooglePlayServices() {
return sInstance.canUseFirstPartyGooglePlayServices(
new UserRecoverableErrorHandler.Silent());
public boolean canUseFirstPartyGooglePlayServices() {
return canUseFirstPartyGooglePlayServices(new UserRecoverableErrorHandler.Silent());
}
/**
......
......@@ -10,6 +10,8 @@ import android.os.Message;
import android.os.Messenger;
import android.text.TextUtils;
import org.chromium.chrome.browser.AppHooks;
import java.util.HashMap;
import java.util.Map;
......@@ -57,9 +59,10 @@ public class VerifiedHandler extends Handler {
* set during construction.
*/
public boolean checkCallerIsValid() {
ExternalAuthUtils externalAuthUtils = AppHooks.get().getExternalAuthUtils();
return TextUtils.isEmpty(mCallerPackageToMatch)
? ExternalAuthUtils.getInstance().isCallerValid(mContext, mAuthRequirements)
: ExternalAuthUtils.getInstance().isCallerValidForPackage(
mContext, mAuthRequirements, mCallerPackageToMatch);
? externalAuthUtils.isCallerValid(mContext, mAuthRequirements)
: externalAuthUtils.isCallerValidForPackage(
mContext, mAuthRequirements, mCallerPackageToMatch);
}
}
......@@ -7,9 +7,9 @@ package org.chromium.chrome.browser.firstrun;
import androidx.annotation.Nullable;
import org.chromium.base.Log;
import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.SyncFirstSetupCompleteSource;
import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.chrome.browser.externalauth.UserRecoverableErrorHandler;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.services.AndroidChildAccountHelper;
......@@ -118,7 +118,7 @@ public final class ForcedSigninProcessor {
if (IdentityServicesProvider.get()
.getSigninManager(Profile.getLastUsedRegularProfile())
.isForceSigninEnabled()) {
ExternalAuthUtils.getInstance().canUseGooglePlayServices(
AppHooks.get().getExternalAuthUtils().canUseGooglePlayServices(
new UserRecoverableErrorHandler.ModalDialog(activity, false));
}
}
......
......@@ -11,6 +11,7 @@ import com.google.android.gms.common.api.GoogleApiClient;
import org.chromium.base.Log;
import org.chromium.base.TraceEvent;
import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import java.util.concurrent.TimeUnit;
......@@ -23,6 +24,7 @@ public class ChromeGoogleApiClientImpl implements ChromeGoogleApiClient {
private final Context mApplicationContext;
private final GoogleApiClient mClient;
private final ExternalAuthUtils mExternalAuthUtils;
/**
* @param context its application context will be exposed through
......@@ -35,7 +37,8 @@ public class ChromeGoogleApiClientImpl implements ChromeGoogleApiClient {
boolean requireFirstPartyBuild) {
mApplicationContext = context.getApplicationContext();
mClient = client;
if (requireFirstPartyBuild && !ExternalAuthUtils.getInstance().isChromeGoogleSigned()) {
mExternalAuthUtils = AppHooks.get().getExternalAuthUtils();
if (requireFirstPartyBuild && !mExternalAuthUtils.isChromeGoogleSigned()) {
throw new IllegalStateException("GoogleApiClient requires first-party build");
}
}
......@@ -49,7 +52,7 @@ public class ChromeGoogleApiClientImpl implements ChromeGoogleApiClient {
public boolean isGooglePlayServicesAvailable() {
TraceEvent.begin("ChromeGoogleApiClientImpl:isGooglePlayServicesAvailable");
try {
return ExternalAuthUtils.canUseGooglePlayServices();
return mExternalAuthUtils.canUseGooglePlayServices();
} finally {
TraceEvent.end("ChromeGoogleApiClientImpl:isGooglePlayServicesAvailable");
}
......
......@@ -16,7 +16,7 @@ import android.view.ViewGroup;
import androidx.annotation.ColorInt;
import androidx.core.graphics.drawable.RoundedBitmapDrawable;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.gsa.GSAState;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.lifecycle.Destroyable;
......@@ -80,7 +80,7 @@ class SearchBoxMediator
@Override
public void onFinishNativeInitialization() {
mAssistantVoiceSearchService =
new AssistantVoiceSearchService(mContext, ExternalAuthUtils.getInstance(),
new AssistantVoiceSearchService(mContext, AppHooks.get().getExternalAuthUtils(),
TemplateUrlServiceFactory.get(), GSAState.getInstance(mContext), this);
onAssistantVoiceSearchServiceChanged();
}
......
......@@ -16,8 +16,8 @@ import com.google.android.gms.gcm.Task;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.ChromeBackgroundService;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
......@@ -83,7 +83,7 @@ public class SnippetsLauncher {
private void checkGCM() {
// Check to see if Play Services is up to date, and disable GCM if not.
if (!ExternalAuthUtils.canUseGooglePlayServices()) {
if (!AppHooks.get().getExternalAuthUtils().canUseGooglePlayServices()) {
mGCMEnabled = false;
Log.i(TAG, "Disabling SnippetsLauncher because Play Services is not up to date.");
}
......
......@@ -37,8 +37,8 @@ import org.chromium.base.metrics.RecordUserAction;
import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ActivityTabProvider;
import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.WindowDelegate;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.gsa.GSAState;
import org.chromium.chrome.browser.locale.LocaleManager;
......@@ -358,7 +358,7 @@ public class LocationBarLayout extends FrameLayout
updateMicButtonVisibility();
mAssistantVoiceSearchService =
new AssistantVoiceSearchService(getContext(), ExternalAuthUtils.getInstance(),
new AssistantVoiceSearchService(getContext(), AppHooks.get().getExternalAuthUtils(),
TemplateUrlServiceFactory.get(), GSAState.getInstance(getContext()), this);
mVoiceRecognitionHandler.setAssistantVoiceSearchService(mAssistantVoiceSearchService);
onAssistantVoiceSearchServiceChanged();
......
......@@ -33,6 +33,7 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.task.PostTask;
import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.database.SQLiteCursor;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
......@@ -1154,9 +1155,10 @@ public class ChromeBrowserProvider extends ContentProvider {
}
private boolean hasPermission(String permission) {
boolean isSystemOrGoogleCaller = ExternalAuthUtils.getInstance().isCallerValid(
getContext(), ExternalAuthUtils.FLAG_SHOULD_BE_GOOGLE_SIGNED
| ExternalAuthUtils.FLAG_SHOULD_BE_SYSTEM);
boolean isSystemOrGoogleCaller =
AppHooks.get().getExternalAuthUtils().isCallerValid(getContext(),
ExternalAuthUtils.FLAG_SHOULD_BE_GOOGLE_SIGNED
| ExternalAuthUtils.FLAG_SHOULD_BE_SYSTEM);
if (isSystemOrGoogleCaller) {
recordPermissionWasGranted("SignaturePassed", permission);
......
......@@ -21,6 +21,7 @@ import org.chromium.base.annotations.NativeMethods;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.base.task.PostTask;
import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.chrome.browser.sync.AndroidSyncSettings;
import org.chromium.components.signin.AccountTrackerService;
......@@ -247,7 +248,7 @@ public class SigninManager
assert identityManager != null;
assert identityMutator != null;
return new SigninManager(nativeSigninManagerAndroid, accountTrackerService, identityManager,
identityMutator, AndroidSyncSettings.get(), ExternalAuthUtils.getInstance());
identityMutator, AndroidSyncSettings.get(), AppHooks.get().getExternalAuthUtils());
}
@VisibleForTesting
......
......@@ -32,8 +32,8 @@ import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.blink.mojom.AuthenticatorStatus;
import org.chromium.blink.mojom.PublicKeyCredentialRequestOptions;
import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.chrome.browser.externalauth.UserRecoverableErrorHandler;
import org.chromium.content_public.browser.RenderFrameHost;
import org.chromium.content_public.browser.WebContents;
......@@ -254,7 +254,7 @@ public class Fido2CredentialRequest implements WindowAndroid.IntentCallback {
return true;
}
if (!ExternalAuthUtils.getInstance().canUseGooglePlayServices(
if (!AppHooks.get().getExternalAuthUtils().canUseGooglePlayServices(
new UserRecoverableErrorHandler.Silent())) {
return false;
}
......
......@@ -19,9 +19,9 @@ import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.background_sync.BackgroundSyncBackgroundTaskScheduler.BackgroundSyncTask;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeActivityTestRule;
......@@ -74,7 +74,7 @@ public final class BackgroundSyncTest {
// fixed.
// Note that this should be done before the startMainActivityOnBlankPage(), because Chrome
// will otherwise run this check on startup and disable BackgroundSync code.
if (!ExternalAuthUtils.canUseGooglePlayServices()) {
if (!AppHooks.get().getExternalAuthUtils().canUseGooglePlayServices()) {
NativeLibraryTestUtils.loadNativeLibraryNoBrowserProcess();
disableGooglePlayServicesVersionCheck();
}
......
......@@ -19,10 +19,10 @@ import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.background_sync.BackgroundSyncBackgroundTaskScheduler.BackgroundSyncTask;
import org.chromium.chrome.browser.engagement.SiteEngagementService;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.Tab;
......@@ -83,7 +83,7 @@ public final class PeriodicBackgroundSyncTest {
// been fixed.
// Note that this should be done before the startMainActivityOnBlankPage(), because Chrome
// will otherwise run this check on startup and disable Periodic Background Sync code.
if (!ExternalAuthUtils.canUseGooglePlayServices()) {
if (!AppHooks.get().getExternalAuthUtils().canUseGooglePlayServices()) {
NativeLibraryTestUtils.loadNativeLibraryNoBrowserProcess();
disableGooglePlayServicesVersionCheck();
}
......
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